Skip to content

Commit 126aa2e

Browse files
committed
Proxy process with additional exports
Closes #33.
1 parent cfc2f22 commit 126aa2e

File tree

6 files changed

+130
-3
lines changed

6 files changed

+130
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ const b = browserify(
271271
| `net` | | [net](mock/net.js) |
272272
| `os` | [os-browserify](https://github.com/CoderPuppy/os-browserify) | |
273273
| `path` | [path-browserify](https://github.com/browserify/path-browserify) | |
274-
| `process` | [process](https://github.com/defunctzombie/node-process) | [process](mock/process.js) |
274+
| `process` | [process](https://github.com/defunctzombie/node-process) | [process](mock/process.js) | Contains additional exports from newer Node |
275275
| `punycode` | [punycode](https://github.com/bestiejs/punycode.js) | | `punycode@1` for browser support |
276276
| `querystring` | [querystring-es3](https://github.com/mike-spainhower/querystring) | | Contains additional exports from newer Node versions |
277277
| `readline` | | |

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const net = resolvePath('./mock/empty.js');
3535
const os = resolvePath('os-browserify/browser.js');
3636
const path = resolvePath('path-browserify');
3737
const punycode = resolvePath('punycode/');
38-
const _process = resolvePath('process/browser.js');
38+
const _process = resolvePath('./proxy/process.js');
3939
const querystring = resolvePath('./proxy/querystring.js');
4040
const readline = resolvePath('./mock/empty.js');
4141
const repl = resolvePath('./mock/empty.js');

proxy/process.js

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import _process from 'process/browser.js';
2+
3+
function noop() {}
4+
5+
const nextTick = _process.nextTick;
6+
const title = _process.title;
7+
// @ts-ignore
8+
const browser = /** @type {boolean} */ (_process.browser);
9+
const environment = _process.env;
10+
const argv = _process.argv;
11+
const version = _process.version;
12+
const versions = _process.versions;
13+
const on = _process.on;
14+
const addListener = _process.addListener;
15+
const once = _process.once;
16+
const off = _process.off;
17+
const removeListener = _process.removeListener;
18+
const removeAllListeners = _process.removeAllListeners;
19+
const emit = _process.emit;
20+
const emitWarning = noop;
21+
const prependListener = _process.prependListener;
22+
const prependOnceListener = _process.prependOnceListener;
23+
const listeners = _process.listeners;
24+
// @ts-ignore
25+
const binding = /** @type {Function} */ (_process.binding);
26+
const cwd = _process.cwd;
27+
const chdir = _process.chdir;
28+
const umask = _process.umask;
29+
const exit = noop;
30+
const pid = 1;
31+
const features = {};
32+
const kill = noop;
33+
const dlopen = noop;
34+
const uptime = noop;
35+
const memoryUsage = noop;
36+
const uvCounters = noop;
37+
const platform = 'browser';
38+
const arch = 'browser';
39+
const execPath = 'browser';
40+
const execArgv = /** @type {string[]} */ ([]);
41+
42+
const api = {
43+
nextTick,
44+
title,
45+
browser,
46+
env: environment,
47+
argv,
48+
version,
49+
versions,
50+
on,
51+
addListener,
52+
once,
53+
off,
54+
removeListener,
55+
removeAllListeners,
56+
emit,
57+
emitWarning,
58+
prependListener,
59+
prependOnceListener,
60+
listeners,
61+
binding,
62+
cwd,
63+
chdir,
64+
umask,
65+
exit,
66+
pid,
67+
features,
68+
kill,
69+
dlopen,
70+
uptime,
71+
memoryUsage,
72+
uvCounters,
73+
platform,
74+
arch,
75+
execPath,
76+
execArgv
77+
};
78+
79+
export default api;
80+
81+
export {
82+
nextTick,
83+
title,
84+
browser,
85+
environment as env,
86+
argv,
87+
version,
88+
versions,
89+
on,
90+
addListener,
91+
once,
92+
off,
93+
removeListener,
94+
removeAllListeners,
95+
emit,
96+
emitWarning,
97+
prependListener,
98+
prependOnceListener,
99+
listeners,
100+
binding,
101+
cwd,
102+
chdir,
103+
umask,
104+
exit,
105+
pid,
106+
features,
107+
kill,
108+
dlopen,
109+
uptime,
110+
memoryUsage,
111+
uvCounters,
112+
platform,
113+
arch,
114+
execPath,
115+
execArgv
116+
};

rollup.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ module.exports = [
163163
[
164164
'proxy/querystring.js',
165165
{ cjsOutro: 'exports = module.exports = api;', cjsExports: 'named' }
166+
],
167+
[
168+
'proxy/process.js',
169+
{ cjsOutro: 'exports = module.exports = api;', cjsExports: 'named' }
166170
]
167171
].map((entry) => {
168172
const [filename, options = {}] = [].concat(entry);

test/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const packages = {
3737
net: 'mock/empty.js',
3838
os: 'node_modules/os-browserify',
3939
path: 'node_modules/path-browserify',
40-
process: 'node_modules/process',
40+
process: 'proxy/process.js',
4141
punycode: 'node_modules/punycode',
4242
querystring: 'proxy/querystring.js',
4343
readline: 'mock/empty.js',
@@ -415,6 +415,8 @@ describe('`querystring` additional exports', function () {
415415
});
416416
});
417417

418+
describe('`process` additional exports', function () {});
419+
418420
const nodeVersion = parseNodeVersion(process.version);
419421
const shouldBundle = nodeVersion.major >= 12;
420422
const shouldBundleESM = nodeVersion.major >= 16;

types/lib.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ declare module 'querystring-es3' {
22
import { decode, encode, parse, stringify } from 'querystring';
33
export { decode, encode, parse, stringify };
44
};
5+
6+
declare module 'process/browser.js' {
7+
const process: NodeJS.Process;
8+
export = process;
9+
};

0 commit comments

Comments
 (0)