-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
125 lines (119 loc) · 3.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import createRequire from 'create-require';
import pkgDir from 'pkg-dir';
/**
* @param {string} path
*/
const resolvePath = (path) => {
let resolvedPath;
try {
resolvedPath = require.resolve(path);
} catch {
resolvedPath = (
globalThis.require ?? createRequire(import.meta.url)
).resolve(path);
}
if (!path.includes('./')) {
const directory = pkgDir.sync(resolvedPath) ?? '';
return directory;
}
return resolvedPath;
};
const assert = resolvePath('assert/');
const buffer = resolvePath('buffer/');
const child_process = resolvePath('./mock/empty.js');
const cluster = resolvePath('./mock/empty.js');
const _console = resolvePath('console-browserify');
const constants = resolvePath('constants-browserify');
const crypto = resolvePath('crypto-browserify');
const dgram = resolvePath('./mock/empty.js');
const dns = resolvePath('./mock/empty.js');
const domain = resolvePath('domain-browser');
const events = resolvePath('events/');
const fs = resolvePath('./mock/empty.js');
const http = resolvePath('stream-http');
const https = resolvePath('https-browserify');
const http2 = resolvePath('./mock/empty.js');
const _module = resolvePath('./mock/empty.js');
const net = resolvePath('./mock/empty.js');
const os = resolvePath('os-browserify/browser.js');
const path = resolvePath('path-browserify');
const punycode = resolvePath('punycode/');
const _process = resolvePath('./proxy/process').replace('.js', '');
const querystring = resolvePath('./proxy/querystring.js');
const readline = resolvePath('./mock/empty.js');
const repl = resolvePath('./mock/empty.js');
const stream = resolvePath('stream-browserify');
const _stream_duplex = resolvePath('readable-stream/lib/_stream_duplex.js');
const _stream_passthrough = resolvePath(
'readable-stream/lib/_stream_passthrough.js'
);
const _stream_readable = resolvePath('readable-stream/lib/_stream_readable.js');
const _stream_transform = resolvePath(
'readable-stream/lib/_stream_transform.js'
);
const _stream_writable = resolvePath('readable-stream/lib/_stream_writable.js');
const string_decoder = resolvePath('string_decoder/');
const sys = resolvePath('util/util.js');
const timers = resolvePath('timers-browserify');
const timersPromises = resolvePath('isomorphic-timers-promises');
const tls = resolvePath('./mock/empty.js');
const tty = resolvePath('tty-browserify');
const url = resolvePath('./proxy/url.js');
const util = resolvePath('util/util.js');
const vm = resolvePath('vm-browserify');
const zlib = resolvePath('browserify-zlib');
const packages = {
assert,
buffer,
child_process,
cluster,
console: _console,
constants,
crypto,
dgram,
dns,
domain,
events,
fs,
http,
https,
http2,
module: _module,
net,
os,
path,
punycode,
process: _process,
querystring,
readline,
repl,
stream,
_stream_duplex,
_stream_passthrough,
_stream_readable,
_stream_transform,
_stream_writable,
string_decoder,
sys,
'timers/promises': timersPromises,
timers,
tls,
tty,
url,
util,
vm,
zlib
};
/** @typedef {typeof packages} Packages */
/** @typedef {keyof Packages} PackageNames */
/** @typedef {{ [Property in PackageNames as `node:${Property}`]: Packages[Property] }} NodeProtocolPackages */
const packagesWithNodeProtocol = /** @type NodeProtocolPackages */ ({});
for (const [packageName, packagePath] of Object.entries(packages)) {
packagesWithNodeProtocol[
`node:${/** @type PackageNames */ (packageName)}`
] = /** @type PackageNames */ packagePath;
}
export default {
...packages,
...packagesWithNodeProtocol
};