Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .babel-register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require('@babel/register')({
presets: [
[
'@babel/preset-env',
{
modules: 'commonjs',
loose: true,
targets: {
node: 'current'
}
}
]
],
plugins: ['babel-plugin-transform-globalthis', 'babel-plugin-istanbul'],
extensions: ['.js'],
only: [
/index\.js$/,
/proxy/,
/mock/,
/test/
],
ignore: [/node_modules/],
sourceType: 'unambiguous',
cache: false
});
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"stdLibBrowser": true
}
}
]
],
"jsdoc/newline-after-description": 0,
"jsdoc/check-examples": 0
},
"ignorePatterns": ["helpers/esbuild/shim.js", "example/**/*"],
"overrides": [
Expand Down
26 changes: 23 additions & 3 deletions helpers/rollup/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,30 @@ function handleCircularDependancyWarning(warning, warningHandler) {
!(
warning.code === 'CIRCULAR_DEPENDENCY' &&
packagesWithCircularDependencies.some((modulePath) => {
if (typeof warning.importer !== 'string') {
return false;
// Handle both Rollup 3 (warning.importer) and Rollup 4 (warning.ids/message) APIs
const importer = /** @type {any} */ (warning).importer;
const ids = /** @type {any} */ (warning).ids;
const message = warning.message || '';

if (
typeof importer === 'string' &&
importer.includes(modulePath)
) {
return true;
}
if (
Array.isArray(ids) &&
ids.some(
(id) =>
typeof id === 'string' && id.includes(modulePath)
)
) {
return true;
}
if (message.includes(modulePath)) {
return true;
}
return warning.importer.includes(modulePath);
return false;
})
)
) {
Expand Down
64 changes: 33 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,84 +44,85 @@
"postpublish": "GITHUB_TOKEN=$GITHUB_RELEASE_TOKEN github-release-from-changelog",
"prerelease": "npm run lint && npm run lint:types && npm run build && npm run module-check",
"release": "np --no-release-draft",
"test": "BABEL_ENV=test nyc mocha --require @babel/register --require esm 'test/**/*.js' && nyc check-coverage",
"test": "BABEL_ENV=test nyc mocha --require ./.babel-register.js 'test/**/*.js' && nyc check-coverage",
"test:watch": "nodemon --exec npm test",
"version": "if [ $(git rev-parse --abbrev-ref HEAD) == 'master' ]; then sed -i '' '/\\[unreleased\\]:/d' CHANGELOG.md && version-changelog CHANGELOG.md && changelog-verify CHANGELOG.md && git add CHANGELOG.md; else echo; fi"
},
"dependencies": {
"assert": "^2.0.0",
"assert": "^2.1.0",
"browser-resolve": "^2.0.0",
"browserify-zlib": "^0.2.0",
"buffer": "^5.7.1",
"console-browserify": "^1.1.0",
"buffer": "^6.0.3",
"console-browserify": "^1.2.0",
"constants-browserify": "^1.0.0",
"create-require": "^1.1.1",
"crypto-browserify": "^3.12.1",
"domain-browser": "4.22.0",
"events": "^3.0.0",
"domain-browser": "^5.7.0",
"events": "^3.3.0",
"https-browserify": "^1.0.0",
"isomorphic-timers-promises": "^1.0.1",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"pkg-dir": "^5.0.0",
"process": "^0.11.10",
"punycode": "^1.4.1",
"punycode": "^2.3.1",
"querystring-es3": "^0.2.1",
"readable-stream": "^3.6.0",
"readable-stream": "^4.7.0",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"string_decoder": "^1.0.0",
"timers-browserify": "^2.0.4",
"string_decoder": "^1.3.0",
"timers-browserify": "^2.0.12",
"tty-browserify": "0.0.1",
"url": "^0.11.4",
"util": "^0.12.4",
"vm-browserify": "^1.0.1"
"util": "^0.12.5",
"vm-browserify": "^1.1.2"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.12.1",
"@babel/register": "^7.0.0",
"@rollup/plugin-babel": "^5.2.1",
"@rollup/plugin-commonjs": "^20.0.0",
"@rollup/plugin-babel": "^6.1.0",
"@rollup/plugin-commonjs": "^28.0.9",
"@types/browser-resolve": "^2.0.1",
"@types/minimatch": "^5.1.2",
"@types/mocha": "^8.2.3",
"@types/node": "^16.3.0",
"@types/parse-node-version": "^1.0.0",
"babel-plugin-istanbul": "^6.0.0",
"babel-plugin-transform-globalthis": "^1.0.0",
"changelog-verify": "^1.1.2",
"core-js": "^2.6.5",
"cpy": "^8.1.2",
"cpy": "^12.1.0",
"del": "^6.0.0",
"del-cli": "^3.0.1",
"esbuild": "^0.13.14",
"eslint": "^7.31.0",
"esbuild": "^0.25.11",
"eslint": "^8.57.1",
"eslint-config-niksy": "^10.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsdoc": "^33.3.0",
"eslint-plugin-mocha": "^8.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsdoc": "^46.10.1",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-unicorn": "^31.0.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^6.6.0",
"eslint-plugin-unicorn": "^48.0.1",
"esm": "^3.0.51",
"execa": "^5.1.1",
"github-release-from-changelog": "^2.1.1",
"husky": "^4.3.0",
"lint-staged": "^10.4.2",
"mocha": "^8.2.0",
"nodemon": "^2.0.6",
"np": "^7.6.0",
"mocha": "^8.4.0",
"nodemon": "^3.1.10",
"np": "^10.2.0",
"nyc": "^15.1.0",
"parse-node-version": "^1.0.1",
"prettier": "^2.4.0",
"rollup": "^2.32.1",
"prettier": "^3.6.2",
"rollup": "^4.52.5",
"rollup-plugin-node-builtins": "^2.1.2",
"typescript": "^4.3.5",
"typescript": "^5.9.3",
"version-changelog": "^3.1.1",
"webpack": "^5.65.0"
"webpack": "^5.102.1"
},
"engines": {
"node": ">=10"
Expand All @@ -139,5 +140,6 @@
"bugs": {
"url": "https://github.com/niksy/node-stdlib-browser/issues"
},
"homepage": "https://github.com/niksy/node-stdlib-browser#readme"
"homepage": "https://github.com/niksy/node-stdlib-browser#readme",
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yarn added this. Happy to remove

}
67 changes: 35 additions & 32 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const { promises: fs } = require('fs');
const { default: babel } = require('@rollup/plugin-babel');
const commonjs = require('@rollup/plugin-commonjs');
const execa = require('execa');
const cpy = require('cpy');
const del = require('del');

function getConfig(filename, options = {}) {
async function getConfig(filename, options = {}) {
const cpy = (await import(/* webpackChunkName: "cpy" */ 'cpy')).default;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint error without this line

const { cjsOutro = '', cjsExports = 'auto' } = options;
return {
input: filename,
Expand Down Expand Up @@ -65,6 +65,7 @@ function getConfig(filename, options = {}) {
exclude: [
'test/**/*.js',
'types/**/*-test*',
'types/**/*.d.ts',
'helpers/**/*.js'
],
compilerOptions: {
Expand Down Expand Up @@ -148,34 +149,36 @@ function getConfig(filename, options = {}) {
};
}

module.exports = [
'index.js',
'mock/buffer.js',
'mock/console.js',
'mock/dns.js',
'mock/empty.js',
'mock/net.js',
'mock/process.js',
'mock/punycode.js',
'mock/tls.js',
'mock/tty.js',
module.exports = Promise.all(
[
'proxy/url.js',
{ cjsOutro: 'exports = module.exports = api;', cjsExports: 'named' }
],
[
'proxy/querystring.js',
{ cjsOutro: 'exports = module.exports = api;', cjsExports: 'named' }
],
[
'proxy/process.js',
{ cjsOutro: 'exports = module.exports = api;', cjsExports: 'named' }
],
[
'proxy/process/browser.js',
{ cjsOutro: 'exports = module.exports = api;', cjsExports: 'named' }
]
].map((entry) => {
const [filename, options = {}] = [].concat(entry);
return getConfig(filename, options);
});
'index.js',
'mock/buffer.js',
'mock/console.js',
'mock/dns.js',
'mock/empty.js',
'mock/net.js',
'mock/process.js',
'mock/punycode.js',
'mock/tls.js',
'mock/tty.js',
[
'proxy/url.js',
{ cjsOutro: 'exports = module.exports = api;', cjsExports: 'named' }
],
[
'proxy/querystring.js',
{ cjsOutro: 'exports = module.exports = api;', cjsExports: 'named' }
],
[
'proxy/process.js',
{ cjsOutro: 'exports = module.exports = api;', cjsExports: 'named' }
],
[
'proxy/process/browser.js',
{ cjsOutro: 'exports = module.exports = api;', cjsExports: 'named' }
]
].map(async (entry) => {
const [filename, options = {}] = [].concat(entry);
return getConfig(filename, options);
})
);
38 changes: 19 additions & 19 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import assert from 'assert';
import path from 'path';
import execa from 'execa';
import parseNodeVersion from 'parse-node-version';
import api from '../index';
import url from '../proxy/url';
import qs from '../proxy/querystring';
import _process from '../proxy/process';
import api from '../cjs/index';
import url from '../cjs/proxy/url';
import qs from '../cjs/proxy/querystring';
import _process from '../cjs/proxy/process';

/** @typedef {import('../index').PackageNames} PackageNames */
/** @typedef {import('../cjs/index').PackageNames} PackageNames */

const context = path.resolve(__dirname, '../');

Expand All @@ -21,36 +21,36 @@ const packages = {
_stream_writable: 'node_modules/readable-stream',
assert: 'node_modules/assert',
buffer: 'node_modules/buffer',
child_process: 'mock/empty.js',
cluster: 'mock/empty.js',
child_process: 'cjs/mock/empty.js',
cluster: 'cjs/mock/empty.js',
console: 'node_modules/console-browserify',
constants: 'node_modules/constants-browserify',
crypto: 'node_modules/crypto-browserify',
dgram: 'mock/empty.js',
dns: 'mock/empty.js',
dgram: 'cjs/mock/empty.js',
dns: 'cjs/mock/empty.js',
domain: 'node_modules/domain-browser',
events: 'node_modules/events',
fs: 'mock/empty.js',
fs: 'cjs/mock/empty.js',
http: 'node_modules/stream-http',
https: 'node_modules/https-browserify',
http2: 'mock/empty.js',
module: 'mock/empty.js',
net: 'mock/empty.js',
http2: 'cjs/mock/empty.js',
module: 'cjs/mock/empty.js',
net: 'cjs/mock/empty.js',
os: 'node_modules/os-browserify',
path: 'node_modules/path-browserify',
process: 'proxy/process',
process: 'cjs/proxy/process',
punycode: 'node_modules/punycode',
querystring: 'proxy/querystring.js',
readline: 'mock/empty.js',
repl: 'mock/empty.js',
querystring: 'cjs/proxy/querystring.js',
readline: 'cjs/mock/empty.js',
repl: 'cjs/mock/empty.js',
stream: 'node_modules/stream-browserify',
string_decoder: 'node_modules/string_decoder',
sys: 'node_modules/util',
timers: 'node_modules/timers-browserify',
'timers/promises': 'node_modules/isomorphic-timers-promises/cjs',
tls: 'mock/empty.js',
tls: 'cjs/mock/empty.js',
tty: 'node_modules/tty-browserify',
url: 'proxy/url.js',
url: 'cjs/proxy/url.js',
util: 'node_modules/util',
vm: 'node_modules/vm-browserify',
zlib: 'node_modules/browserify-zlib'
Expand Down
10 changes: 6 additions & 4 deletions types/lib.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
declare module 'querystring-es3' {
import { decode, encode, parse, stringify } from 'querystring';
export { decode, encode, parse, stringify };
export function decode(str: string, sep?: string, eq?: string, options?: { decodeURIComponent?: (str: string) => string, maxKeys?: number }): Record<string, string | string[]>;
export function encode(obj: Record<string, any>, sep?: string, eq?: string, options?: { encodeURIComponent?: (str: string) => string }): string;
export function parse(str: string, sep?: string, eq?: string, options?: { decodeURIComponent?: (str: string) => string, maxKeys?: number }): Record<string, string | string[]>;
export function stringify(obj: Record<string, any>, sep?: string, eq?: string, options?: { encodeURIComponent?: (str: string) => string }): string;
};

declare module 'process/browser.js' {
const process: NodeJS.Process;
export = process;
const processExport: NodeJS.Process;
export = processExport;
};