node-stdlib-browser
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -5,2 +5,10 @@ # Changelog | ||
## [1.2.0][] - 2021-12-08 | ||
### Added | ||
- Support for `node:` protocol in Webpack | ||
([#12](https://github.com/niksy/node-stdlib-browser/)) | ||
- Rollup warning helper function | ||
## [1.1.0][] - 2021-11-16 | ||
@@ -28,5 +36,5 @@ | ||
[unreleased]: https://github.com/niksy/node-stdlib-browser/compare/v1.0.0...HEAD | ||
[1.0.0]: https://github.com/niksy/node-stdlib-browser/tree/v1.0.0 | ||
[unreleased]: https://github.com/niksy/node-stdlib-browser/compare/v1.1.0...HEAD | ||
[1.1.0]: https://github.com/niksy/node-stdlib-browser/tree/v1.1.0 | ||
[unreleased]: https://github.com/niksy/node-stdlib-browser/compare/v1.2.0...HEAD | ||
[1.2.0]: https://github.com/niksy/node-stdlib-browser/tree/v1.2.0 |
@@ -16,2 +16,3 @@ declare var _default: { | ||
"node:https": string; | ||
"node:http2": string; | ||
"node:module": string; | ||
@@ -56,2 +57,3 @@ "node:net": string; | ||
https: string; | ||
http2: string; | ||
module: string; | ||
@@ -101,2 +103,3 @@ net: string; | ||
"node:https": string; | ||
"node:http2": string; | ||
"node:module": string; | ||
@@ -143,2 +146,3 @@ "node:net": string; | ||
https: string; | ||
http2: string; | ||
module: string; | ||
@@ -145,0 +149,0 @@ net: string; |
@@ -69,2 +69,3 @@ 'use strict'; | ||
const https = resolvePath('https-browserify'); | ||
const http2 = resolvePath('./mock/empty.js'); | ||
@@ -120,2 +121,3 @@ const _module = resolvePath('./mock/empty.js'); | ||
https, | ||
http2, | ||
module: _module, | ||
@@ -122,0 +124,0 @@ net, |
@@ -27,9 +27,9 @@ /// <reference types="node" /> | ||
declare const formatImportWithOverloads: ((urlObject: URL, options?: import("url").URLFormatOptions | undefined) => string) & ((urlObject: UrlObject | string, options?: undefined) => string); | ||
declare const parseImport: parseImport; | ||
declare const resolveImport: resolveImport; | ||
declare const UrlImport: UrlImport; | ||
declare const parseImport: typeof parse; | ||
declare const resolveImport: typeof resolve; | ||
declare const UrlImport: Url; | ||
export const URL: { | ||
new (url: string | URL, base?: string | URL | undefined): URL; | ||
prototype: URL; | ||
createObjectURL(object: any): string; | ||
createObjectURL(obj: Blob | MediaSource): string; | ||
revokeObjectURL(url: string): void; | ||
@@ -49,3 +49,4 @@ }; | ||
import { resolve } from "url"; | ||
import { Url } from "url"; | ||
export { formatImportWithOverloads as format, parseImport as parse, resolveImport as resolve, resolveObject, UrlImport as Url }; | ||
//# sourceMappingURL=url.d.ts.map |
@@ -16,2 +16,3 @@ declare var _default: { | ||
"node:https": string; | ||
"node:http2": string; | ||
"node:module": string; | ||
@@ -56,2 +57,3 @@ "node:net": string; | ||
https: string; | ||
http2: string; | ||
module: string; | ||
@@ -101,2 +103,3 @@ net: string; | ||
"node:https": string; | ||
"node:http2": string; | ||
"node:module": string; | ||
@@ -143,2 +146,3 @@ "node:net": string; | ||
https: string; | ||
http2: string; | ||
module: string; | ||
@@ -145,0 +149,0 @@ net: string; |
@@ -62,2 +62,3 @@ import createRequire from 'create-require'; | ||
const https = resolvePath('https-browserify'); | ||
const http2 = resolvePath('./mock/empty.js'); | ||
@@ -113,2 +114,3 @@ const _module = resolvePath('./mock/empty.js'); | ||
https, | ||
http2, | ||
module: _module, | ||
@@ -115,0 +117,0 @@ net, |
@@ -27,9 +27,9 @@ /// <reference types="node" /> | ||
declare const formatImportWithOverloads: ((urlObject: URL, options?: import("url").URLFormatOptions | undefined) => string) & ((urlObject: UrlObject | string, options?: undefined) => string); | ||
declare const parseImport: parseImport; | ||
declare const resolveImport: resolveImport; | ||
declare const UrlImport: UrlImport; | ||
declare const parseImport: typeof parse; | ||
declare const resolveImport: typeof resolve; | ||
declare const UrlImport: Url; | ||
export const URL: { | ||
new (url: string | URL, base?: string | URL | undefined): URL; | ||
prototype: URL; | ||
createObjectURL(object: any): string; | ||
createObjectURL(obj: Blob | MediaSource): string; | ||
revokeObjectURL(url: string): void; | ||
@@ -49,3 +49,4 @@ }; | ||
import { resolve } from "url"; | ||
import { Url } from "url"; | ||
export { formatImportWithOverloads as format, parseImport as parse, resolveImport as resolve, resolveObject, UrlImport as Url }; | ||
//# sourceMappingURL=url.d.ts.map |
{ | ||
"name": "node-stdlib-browser", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Node standard library for browser.", | ||
@@ -18,2 +18,4 @@ "license": "MIT", | ||
"./helpers/esbuild/*": "./helpers/esbuild/*.js", | ||
"./helpers/webpack/*": "./helpers/webpack/*.js", | ||
"./helpers/rollup/*": "./helpers/rollup/*.js", | ||
"./package.json": "./package.json" | ||
@@ -31,2 +33,4 @@ }, | ||
"helpers/esbuild/{plugin,shim}.js", | ||
"helpers/webpack/plugin.js", | ||
"helpers/rollup/plugin.js", | ||
"CHANGELOG.md", | ||
@@ -38,3 +42,3 @@ "LICENSE.md", | ||
"build": "rollup --config rollup.config.js && babel helpers/esbuild/shim.src.js --out-file=helpers/esbuild/shim.js", | ||
"lint": "eslint '{index,lib/**/*,test/**/*}.js'", | ||
"lint": "eslint '{index,lib/**/*,test/**/*,helpers/**/*,example/**/*}.{js,mjs}'", | ||
"lint:types": "tsc", | ||
@@ -48,3 +52,3 @@ "module-check": "node -e 'require(\"node-stdlib-browser\"); require(\"node-stdlib-browser/helpers/esbuild/plugin\");' && node --input-type=module -e 'import \"node-stdlib-browser\"; import \"node-stdlib-browser/helpers/esbuild/plugin\";'", | ||
"test:watch": "nodemon --exec npm test", | ||
"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" | ||
"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" | ||
}, | ||
@@ -115,3 +119,3 @@ "dependencies": { | ||
"nodemon": "^2.0.6", | ||
"np": "^6.5.0", | ||
"np": "^7.6.0", | ||
"nyc": "^15.1.0", | ||
@@ -123,3 +127,4 @@ "parse-node-version": "^1.0.1", | ||
"typescript": "^4.3.5", | ||
"version-changelog": "^3.1.1" | ||
"version-changelog": "^3.1.1", | ||
"webpack": "^5.65.0" | ||
}, | ||
@@ -126,0 +131,0 @@ "engines": { |
@@ -12,6 +12,6 @@ # node-stdlib-browser | ||
- Maintained with newer versions and modern implementations | ||
- Works with Webpack, Rollup and esbuild, but should also work with other | ||
bundlers | ||
- Works with Webpack, Rollup, esbuild and Browserify, but should also work | ||
with other bundlers | ||
- Exports implementation with | ||
[`node:` protocol](https://nodejs.org/api/esm.html#esm_node_imports) which | ||
[`node:` protocol](https://nodejs.org/api/esm.html#node-imports) which | ||
allows for builtin modules to be referenced by valid absolute URL strings | ||
@@ -36,2 +36,5 @@ | ||
As of Webpack 5, aliases and globals provider need to be explicitly configured. | ||
If you want to handle | ||
[`node:` protocol](https://nodejs.org/api/esm.html#node-imports) imports, you | ||
need to provide helper plugin. | ||
@@ -41,2 +44,5 @@ ```js | ||
const stdLibBrowser = require('node-stdlib-browser'); | ||
const { | ||
NodeProtocolUrlPlugin | ||
} = require('node-stdlib-browser/helpers/webpack/plugin'); | ||
const webpack = require('webpack'); | ||
@@ -50,2 +56,3 @@ | ||
plugins: [ | ||
new NodeProtocolUrlPlugin(), | ||
new webpack.ProvidePlugin({ | ||
@@ -59,2 +66,22 @@ process: stdLibBrowser.process, | ||
If you’re using ESM config, additional configuration is needed to handle | ||
unspecified extensions: | ||
```js | ||
// webpack.config.js | ||
module.exports = { | ||
// ... | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.m?js$/, | ||
resolve: { | ||
fullySpecified: false | ||
} | ||
} | ||
] | ||
} | ||
}; | ||
``` | ||
</details> | ||
@@ -74,4 +101,4 @@ | ||
Some dependencies can have circular dependencies and Rollup will warn you about | ||
that. You can | ||
[ignore these warnings with `onwarn` function](https://github.com/rollup/rollup/issues/1089#issuecomment-635564942). | ||
that. You can ignore these warnings with helper function | ||
([reference](<(https://github.com/rollup/rollup/issues/1089#issuecomment-635564942)>)). | ||
@@ -81,2 +108,5 @@ ```js | ||
const stdLibBrowser = require('node-stdlib-browser'); | ||
const { | ||
handleCircularDependancyWarning | ||
} = require('node-stdlib-browser/helpers/rollup/plugin'); | ||
const { default: resolve } = require('@rollup/plugin-node-resolve'); | ||
@@ -105,18 +135,3 @@ const commonjs = require('@rollup/plugin-commonjs'); | ||
onwarn: (warning, rollupWarn) => { | ||
const packagesWithCircularDependencies = [ | ||
'util/', | ||
'assert/', | ||
'readable-stream/', | ||
'crypto-browserify/' | ||
]; | ||
if ( | ||
!( | ||
warning.code === 'CIRCULAR_DEPENDENCY' && | ||
packagesWithCircularDependencies.some((modulePath) => | ||
warning.importer.includes(modulePath) | ||
) | ||
) | ||
) { | ||
rollupWarn(warning); | ||
} | ||
handleCircularDependancyWarning(warning, rollupWarn); | ||
} | ||
@@ -158,2 +173,41 @@ }; | ||
### Browserify | ||
<details> | ||
<summary>Show me</summary> | ||
Bundling ES modules is currently not supported natively in Browserify, but you | ||
can try using [esmify](https://github.com/mattdesl/esmify) or | ||
[babelify](https://github.com/babel/babelify) for transforming to CommonJS | ||
first. | ||
```js | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const browserify = require('browserify'); | ||
const aliasify = require('aliasify'); | ||
const stdLibBrowser = require('node-stdlib-browser'); | ||
const b = browserify( | ||
[ | ||
/* ... */ | ||
], | ||
{ | ||
// ... | ||
transform: [[aliasify, { aliases: stdLibBrowser }]], | ||
insertGlobalVars: { | ||
process: () => { | ||
return `require('${stdLibBrowser.process}')`; | ||
}, | ||
Buffer: () => { | ||
return `require('${stdLibBrowser.buffer}').Buffer`; | ||
} | ||
} | ||
} | ||
); | ||
``` | ||
</details> | ||
## Package contents | ||
@@ -160,0 +214,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
331667
118
4309
304
43