Skip to content

Commit 27ef309

Browse files
committed
Use better polyfill for process.nextTick
Closes #6.
1 parent 16e2570 commit 27ef309

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

Diff for: README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ module.exports = {
141141

142142
## Package contents
143143

144-
| Module | Browser implementation | Mock implementation | Notes |
145-
| --------------------- | --------------------------------------------------------------------------------- | -------------------------- | ---------------------------------------------------- |
144+
| Module | Browser implementation | Mock implementation | Notes |
145+
| --------------------- | --------------------------------------------------------------------------------- | -------------------------- | --------------------------------------------------------------------------------- |
146146
| `assert` | [assert](https://github.com/browserify/commonjs-assert) | |
147-
| `buffer` | [buffer](https://github.com/feross/buffer) | [buffer](mock/buffer.js) | `buffer@5` for IE 11 support |
147+
| `buffer` | [buffer](https://github.com/feross/buffer) | [buffer](mock/buffer.js) | `buffer@5` for IE 11 support |
148148
| `child_process` | | |
149149
| `cluster` | | |
150150
| `console` | [console-browserify](https://github.com/browserify/console-browserify) | [console](mock/console.js) |
@@ -161,8 +161,8 @@ module.exports = {
161161
| `net` | | [net](mock/net.js) |
162162
| `os` | [os-browserify](https://github.com/CoderPuppy/os-browserify) | |
163163
| `path` | [path-browserify](https://github.com/browserify/path-browserify) | |
164-
| `process` | [process](https://github.com/defunctzombie/node-process) | [process](mock/process.js) |
165-
| `punycode` | [punycode](https://github.com/bestiejs/punycode.js) | | `punycode@1` for browser support |
164+
| `process` | [process](https://github.com/defunctzombie/node-process) | [process](mock/process.js) | `process.nextTick` uses [`immediate`](https://github.com/calvinmetcalf/immediate) |
165+
| `punycode` | [punycode](https://github.com/bestiejs/punycode.js) | | `punycode@1` for browser support |
166166
| `querystring` | [native-querystring](https://github.com/niksy/native-querystring) | |
167167
| `readline` | | |
168168
| `repl` | | |
@@ -173,7 +173,7 @@ module.exports = {
173173
| `timers/promises` | [isomorphic-timers-promises](https://github.com/niksy/isomorphic-timers-promises) | |
174174
| `tls` | | [tls](mock/tls.js) |
175175
| `tty` | [tty-browserify](https://github.com/browserify/tty-browserify) | [tty](mock/tty.js) |
176-
| `url` | [native-url](https://github.com/GoogleChromeLabs/native-url) | | Contains additional exports from newer Node versions |
176+
| `url` | [native-url](https://github.com/GoogleChromeLabs/native-url) | | Contains additional exports from newer Node versions |
177177
| `util` | [util](https://github.com/browserify/node-util) | |
178178
| `vm` | [vm-browserify](https://github.com/browserify/vm-browserify) | |
179179
| `zlib` | [browserify-zlib](https://github.com/browserify/browserify-zlib) | |

Diff for: index.js

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

Diff for: package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"version": "if [ $(git rev-parse --abbrev-ref HEAD) == 'master' ]; then version-changelog CHANGELOG.md && changelog-verify CHANGELOG.md && git add CHANGELOG.md; else echo; fi"
4444
},
4545
"dependencies": {
46+
"@types/immediate": "^3.2.0",
4647
"assert": "^2.0.0",
4748
"browserify-zlib": "^0.2.0",
4849
"buffer": "^5.7.1",
@@ -53,6 +54,7 @@
5354
"domain-browser": "^4.22.0",
5455
"events": "^3.0.0",
5556
"https-browserify": "^1.0.0",
57+
"immediate": "^3.3.0",
5658
"isomorphic-timers-promises": "^1.0.1",
5759
"native-querystring": "^1.1.1",
5860
"native-url": "^0.3.4",
@@ -76,8 +78,9 @@
7678
"@babel/preset-env": "^7.12.1",
7779
"@babel/register": "^7.0.0",
7880
"@rollup/plugin-babel": "^5.2.1",
81+
"@rollup/plugin-commonjs": "^20.0.0",
7982
"@types/mocha": "^8.2.3",
80-
"@types/node": "^16.3.0",
83+
"@types/node": "^16.10.2",
8184
"babel-plugin-istanbul": "^6.0.0",
8285
"babel-plugin-transform-globalthis": "^1.0.0",
8386
"changelog-verify": "^1.1.2",

Diff for: proxy/process.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import immediate from 'immediate';
2+
// @ts-ignore
3+
import * as _process from 'process/browser.js';
4+
5+
export default { ..._process, nextTick: immediate };

Diff for: rollup.config.js

+14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const path = require('path');
44
const { promises: fs } = require('fs');
55
const { default: babel } = require('@rollup/plugin-babel');
6+
const commonjs = require('@rollup/plugin-commonjs');
67
const execa = require('execa');
78
const cpy = require('cpy');
89

@@ -25,6 +26,17 @@ function getConfig(filename, options = {}) {
2526
}
2627
],
2728
plugins: [
29+
(() => {
30+
return {
31+
name: 'process-browser-handling',
32+
resolveId(source) {
33+
if (source === 'process/browser.js') {
34+
return require.resolve('process/browser.js');
35+
}
36+
return null;
37+
}
38+
};
39+
})(),
2840
(() => {
2941
return {
3042
name: 'types',
@@ -102,6 +114,7 @@ function getConfig(filename, options = {}) {
102114
}
103115
};
104116
})(),
117+
commonjs(),
105118
babel({
106119
babelHelpers: 'bundled',
107120
exclude: 'node_modules/**'
@@ -121,6 +134,7 @@ module.exports = [
121134
'mock/punycode.js',
122135
'mock/tls.js',
123136
'mock/tty.js',
137+
'proxy/process.js',
124138
[
125139
'proxy/url.js',
126140
{ cjsOutro: 'exports = module.exports = api;', cjsExports: 'named' }

Diff for: test/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const packages = {
3333
net: 'mock/empty.js',
3434
os: 'node_modules/os-browserify',
3535
path: 'node_modules/path-browserify',
36-
process: 'node_modules/process',
36+
process: 'proxy/process.js',
3737
punycode: 'node_modules/punycode',
3838
querystring: 'proxy/querystring.js',
3939
readline: 'mock/empty.js',

0 commit comments

Comments
 (0)