File tree

8 files changed

+828
-0
lines changed

8 files changed

+828
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import node from './node.mjs';
2+
import npm from './npm.mjs';
3+
4+
// Use modules as usual
5+
6+
node.fs.readFile('./application.mjs', (error, data) => {
7+
if (error) {
8+
console.log({ error });
9+
} else {
10+
console.log({ data });
11+
}
12+
});
13+
14+
// Show what we have
15+
16+
console.log({ node, npm });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import * as _util from 'node:util';
2+
import * as _buffer from 'node:buffer';
3+
import * as _cp from 'node:child_process';
4+
import * as _os from 'node:os';
5+
import * as _v8 from 'node:v8';
6+
import * as _vm from 'node:vm';
7+
import * as _path from 'node:path';
8+
import * as _url from 'node:url';
9+
import * as _sd from 'node:string_decoder';
10+
import * as _qs from 'node:querystring';
11+
import * as _querystring from 'node:querystring';
12+
import * as _assert from 'node:assert';
13+
import * as _stream from 'node:stream';
14+
import * as _fs from 'node:fs';
15+
import * as _crypto from 'node:crypto';
16+
import * as _zlib from 'node:zlib';
17+
import * as _readline from 'node:readline';
18+
import * as _ph from 'node:perf_hooks';
19+
import * as _ah from 'node:async_hooks';
20+
import * as _timers from 'node:timers';
21+
import * as _events from 'node:events';
22+
import * as _dns from 'node:dns';
23+
import * as _net from 'node:net';
24+
import * as _tls from 'node:tls';
25+
import * as _http from 'node:http';
26+
import * as _https from 'node:https';
27+
import * as _http2 from 'node:http2';
28+
import * as _dgram from 'node:dgram';
29+
30+
import * as _ws from 'ws';
31+
32+
import * as _config from 'metaconfiguration';
33+
import * as _metautil from 'metautil';
34+
import * as _metavm from 'metavm';
35+
import * as _metacom from 'metacom';
36+
import * as _metalog from 'metalog';
37+
import * as _metawatch from 'metawatch';
38+
import * as _metaschema from 'metaschema';
39+
40+
declare global {
41+
namespace node {
42+
const util: typeof _util;
43+
const buffer: typeof _buffer;
44+
const child_process: typeof _cp;
45+
const childProcess: typeof _cp;
46+
const os: typeof _os;
47+
const v8: typeof _v8;
48+
const vm: typeof _vm;
49+
const path: typeof _path;
50+
const url: typeof _url;
51+
const StringDecoder: typeof _sd;
52+
const querystring: typeof _qs;
53+
const assert: typeof _assert;
54+
const stream: typeof _stream;
55+
const fs: typeof _fs;
56+
const fsp: typeof _fs.promises;
57+
const crypto: typeof _crypto;
58+
const zlib: typeof _zlib;
59+
const readline: typeof _readline;
60+
const perf_hooks: typeof _ph;
61+
const perfHooks: typeof _ph;
62+
const async_hooks: typeof _ah;
63+
const asyncHooks: typeof _ah;
64+
const timers: typeof _timers;
65+
const events: typeof _events;
66+
const dns: typeof _dns;
67+
const net: typeof _net;
68+
const tls: typeof _tls;
69+
const http: typeof _http;
70+
const https: typeof _https;
71+
const http2: typeof _http2;
72+
const dgram: typeof _dgram;
73+
}
74+
75+
namespace npm {
76+
const ws: typeof _ws;
77+
const config: typeof _config;
78+
const metautil: typeof _metautil;
79+
const metavm: typeof _metavm;
80+
const metacom: typeof _metacom;
81+
const metalog: typeof _metalog;
82+
const metawatch: typeof _metawatch;
83+
const metaschema: typeof _metaschema;
84+
}
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const node = {};
2+
const tools = ['util', 'path', 'buffer', 'os', 'v8', 'vm'];
3+
const multi = ['child_process', 'worker_threads'];
4+
const streams = ['stream', 'fs', 'crypto', 'zlib', 'readline'];
5+
const async = ['perf_hooks', 'async_hooks', 'timers', 'events'];
6+
const network = ['dns', 'net', 'tls', 'http', 'https', 'http2', 'dgram'];
7+
const internals = [...tools, ...multi, ...streams, ...async, ...network];
8+
9+
for (const name of internals) node[name] = await import(`node:${name}`);
10+
node.process = process;
11+
node.fsp = node.fs.promises;
12+
13+
Object.freeze(node);
14+
export default node;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import node from './node.mjs';
2+
3+
const npm = {};
4+
5+
const pkgPath = node.path.join(node.process.cwd(), 'package.json');
6+
const pkg = JSON.parse(await node.fsp.readFile(pkgPath));
7+
8+
if (pkg.dependencies) {
9+
const modules = Object.keys(pkg.dependencies);
10+
for (const dependency of modules) {
11+
npm[dependency] = await import(dependency);
12+
}
13+
}
14+
15+
Object.freeze(npm);
16+
export default npm;

0 commit comments

Comments
 (0)