Skip to content

Commit 3471747

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

File tree

6 files changed

+134
-3
lines changed

6 files changed

+134
-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

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

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

+11
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,14 @@ 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+
global {
8+
interface BrowserProcess extends NodeJS.Process {
9+
browser: string
10+
binding: Function
11+
}
12+
}
13+
const process: BrowserProcess;
14+
export = process;
15+
};

0 commit comments

Comments
 (0)