rollup-packages-polyfill-core 0.13.1 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +26 -26
- package/dist/es/index.js +81 -0
- package/dist/es/modules.js +58 -0
- package/dist/es/polyfills.js +3 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +115 -0
- package/dist/modules.d.ts +1 -0
- package/dist/modules.js +60 -0
- package/dist/polyfills.d.ts +53 -0
- package/dist/polyfills.js +5 -0
- package/package.json +54 -10
- package/{ReadMe.md → readme.md} +85 -85
- package/browser-test/index.js +0 -20
- package/browser-test/main.js +0 -44
- package/polyfills/LICENSE-browserify-fs.txt +0 -472
- package/polyfills/LICENSE-buffer-es6.txt +0 -69
- package/polyfills/LICENSE-crypto-browserify.txt +0 -355
- package/polyfills/LICENSE-process-es6.txt +0 -32
- package/polyfills/__http-lib/capability.js +0 -52
- package/polyfills/__http-lib/request.js +0 -278
- package/polyfills/__http-lib/response.js +0 -185
- package/polyfills/__http-lib/to-arraybuffer.js +0 -30
- package/polyfills/__readable-stream/buffer-list.js +0 -59
- package/polyfills/__readable-stream/duplex.js +0 -45
- package/polyfills/__readable-stream/passthrough.js +0 -15
- package/polyfills/__readable-stream/readable.js +0 -896
- package/polyfills/__readable-stream/transform.js +0 -174
- package/polyfills/__readable-stream/writable.js +0 -483
- package/polyfills/__zlib-lib/LICENSE +0 -21
- package/polyfills/__zlib-lib/adler32.js +0 -31
- package/polyfills/__zlib-lib/binding.js +0 -290
- package/polyfills/__zlib-lib/crc32.js +0 -40
- package/polyfills/__zlib-lib/deflate.js +0 -1862
- package/polyfills/__zlib-lib/inffast.js +0 -325
- package/polyfills/__zlib-lib/inflate.js +0 -1650
- package/polyfills/__zlib-lib/inftrees.js +0 -329
- package/polyfills/__zlib-lib/messages.js +0 -11
- package/polyfills/__zlib-lib/trees.js +0 -1220
- package/polyfills/__zlib-lib/utils.js +0 -73
- package/polyfills/__zlib-lib/zstream.js +0 -28
- package/polyfills/assert.js +0 -488
- package/polyfills/buffer-es6.js +0 -1985
- package/polyfills/console.js +0 -13
- package/polyfills/constants.js +0 -498
- package/polyfills/domain.js +0 -100
- package/polyfills/empty.js +0 -1
- package/polyfills/events.js +0 -481
- package/polyfills/global.js +0 -3
- package/polyfills/http.js +0 -167
- package/polyfills/inherits.js +0 -25
- package/polyfills/os.js +0 -126
- package/polyfills/path.js +0 -234
- package/polyfills/process-es6.js +0 -223
- package/polyfills/punycode.js +0 -475
- package/polyfills/querystring.js +0 -147
- package/polyfills/setimmediate.js +0 -185
- package/polyfills/stream.js +0 -110
- package/polyfills/string-decoder.js +0 -220
- package/polyfills/timers.js +0 -76
- package/polyfills/tty.js +0 -20
- package/polyfills/url.js +0 -785
- package/polyfills/util.js +0 -716
- package/polyfills/vm.js +0 -202
- package/polyfills/zlib.js +0 -635
- package/rollup.config.mjs +0 -18
- package/scripts/build-constants.js +0 -18
- package/scripts/build-polyfills.js +0 -52
- package/scripts/collect-polyfills.js +0 -17
- package/src/index.ts +0 -92
- package/src/modules.ts +0 -61
- package/src/polyfills.ts +0 -1
- package/test/examples/assert.js +0 -12
- package/test/examples/constants.js +0 -7
- package/test/examples/crypto-broken.js +0 -2
- package/test/examples/crypto.js +0 -7
- package/test/examples/domain.js +0 -33
- package/test/examples/events.js +0 -7
- package/test/examples/os.js +0 -7
- package/test/examples/path.js +0 -11
- package/test/examples/stream.js +0 -31
- package/test/examples/string-decoder.js +0 -19
- package/test/examples/url-file-url-to-path.js +0 -11
- package/test/examples/url-format.js +0 -13
- package/test/examples/url-parse.js +0 -14
- package/test/examples/zlib.js +0 -24
- package/test/index.js +0 -77
- package/tsconfig.json +0 -14
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const rollup = require('rollup');
|
|
2
|
-
// const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const nodeResolve = require('@rollup/plugin-node-resolve');
|
|
5
|
-
const commonjs = require('@rollup/plugin-commonjs');
|
|
6
|
-
const json = require('@rollup/plugin-json');
|
|
7
|
-
|
|
8
|
-
async function main() {
|
|
9
|
-
await Promise.all([
|
|
10
|
-
bundleDependency('process-es6'),
|
|
11
|
-
bundleDependency('buffer-es6'),
|
|
12
|
-
// bundleDependency('browserify-fs'),
|
|
13
|
-
// bundleDependency('crypto-browserify'),
|
|
14
|
-
])
|
|
15
|
-
|
|
16
|
-
// quick and dirty find-replace
|
|
17
|
-
// const cryptoPolyfillLoc = path.join(__dirname, '../polyfills/crypto-browserify.js');
|
|
18
|
-
// let cryptoPolyfill = fs.readFileSync(cryptoPolyfillLoc, 'utf8');
|
|
19
|
-
// cryptoPolyfill = cryptoPolyfill.replace(`import buffer$1 from 'buffer';`, `import * as buffer$1 from 'buffer';`);
|
|
20
|
-
// console.log(cryptoPolyfill);
|
|
21
|
-
// fs.writeFileSync(cryptoPolyfillLoc, cryptoPolyfill`, 'utf8'`)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function bundleDependency(depName) {
|
|
25
|
-
const bundle = await rollup.rollup({
|
|
26
|
-
input: depName,
|
|
27
|
-
plugins: [
|
|
28
|
-
commonjs(),
|
|
29
|
-
nodeResolve({
|
|
30
|
-
browser: true,
|
|
31
|
-
preferBuiltins: true
|
|
32
|
-
}),
|
|
33
|
-
json(),
|
|
34
|
-
],
|
|
35
|
-
external: [
|
|
36
|
-
'crypto',
|
|
37
|
-
'vm',
|
|
38
|
-
'events',
|
|
39
|
-
'path',
|
|
40
|
-
'stream',
|
|
41
|
-
'util',
|
|
42
|
-
'buffer'
|
|
43
|
-
]
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
await bundle.write({
|
|
47
|
-
format: 'esm',
|
|
48
|
-
file: path.join('polyfills', depName + '.js')
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
main();
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const glob = require('glob');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
|
|
5
|
-
async function collect(depName) {
|
|
6
|
-
const allFiles = glob.sync('**/*', {
|
|
7
|
-
cwd: path.join(__dirname, '../polyfills'),
|
|
8
|
-
nodir: true,
|
|
9
|
-
});
|
|
10
|
-
const allFilesContents = {};
|
|
11
|
-
for (const f of allFiles) {
|
|
12
|
-
allFilesContents[f] = fs.readFileSync(path.join(__dirname, '../polyfills', f), 'utf8');
|
|
13
|
-
}
|
|
14
|
-
fs.writeFileSync(path.join(__dirname, '../src/polyfills.ts'), `export default ${JSON.stringify(allFilesContents)}`);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
collect();
|
package/src/index.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
import type { Plugin } from "rollup";
|
|
3
|
-
import inject, { RollupInjectOptions } from "@rollup/plugin-inject";
|
|
4
|
-
import { getModules } from "./modules";
|
|
5
|
-
import { posix, resolve } from "path";
|
|
6
|
-
import { randomBytes } from "crypto";
|
|
7
|
-
import POLYFILLS from './polyfills';
|
|
8
|
-
|
|
9
|
-
// Node import paths use POSIX separators
|
|
10
|
-
const { dirname, relative, join } = posix;
|
|
11
|
-
|
|
12
|
-
const PREFIX = `\0polyfill-node.`;
|
|
13
|
-
const PREFIX_LENGTH = PREFIX.length;
|
|
14
|
-
|
|
15
|
-
export interface NodePolyfillsOptions {
|
|
16
|
-
baseDir?: string;
|
|
17
|
-
sourceMap?: RollupInjectOptions['sourceMap'];
|
|
18
|
-
include?: Array<string | RegExp> | string | RegExp | null;
|
|
19
|
-
exclude?: Array<string | RegExp> | string | RegExp | null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default function (opts: NodePolyfillsOptions = {}): Plugin {
|
|
23
|
-
const mods = getModules();
|
|
24
|
-
const injectPlugin = inject({
|
|
25
|
-
include: opts.include === undefined ? ['node_modules/**/*.js'] : opts.include,
|
|
26
|
-
exclude: opts.exclude,
|
|
27
|
-
sourceMap: opts.sourceMap,
|
|
28
|
-
modules: {
|
|
29
|
-
process: PREFIX + "process",
|
|
30
|
-
Buffer: [PREFIX + "buffer", "Buffer"],
|
|
31
|
-
global: PREFIX + 'global',
|
|
32
|
-
__filename: FILENAME_PATH,
|
|
33
|
-
__dirname: DIRNAME_PATH,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
const basedir = opts.baseDir || "/";
|
|
37
|
-
const dirs = new Map<string, string>();
|
|
38
|
-
return {
|
|
39
|
-
name: "polyfill-node",
|
|
40
|
-
resolveId(importee: string, importer?: string) {
|
|
41
|
-
// Fixes commonjs compatability: https://github.com/FredKSchott/rollup-plugin-polyfill-node/pull/42
|
|
42
|
-
if (importee[0] == '\0' && /\?commonjs-\w+$/.test(importee)) {
|
|
43
|
-
importee = importee.slice(1).replace(/\?commonjs-\w+$/, '');
|
|
44
|
-
}
|
|
45
|
-
if (importee === DIRNAME_PATH) {
|
|
46
|
-
const id = getRandomId();
|
|
47
|
-
dirs.set(id, dirname("/" + relative(basedir, importer!)));
|
|
48
|
-
return { id, moduleSideEffects: false };
|
|
49
|
-
}
|
|
50
|
-
if (importee === FILENAME_PATH) {
|
|
51
|
-
const id = getRandomId();
|
|
52
|
-
dirs.set(id, dirname("/" + relative(basedir, importer!)));
|
|
53
|
-
return { id, moduleSideEffects: false };
|
|
54
|
-
}
|
|
55
|
-
if (importee && importee.slice(-1) === "/") {
|
|
56
|
-
importee = importee.slice(0, -1);
|
|
57
|
-
}
|
|
58
|
-
if (importer && importer.startsWith(PREFIX) && importee.startsWith('.')) {
|
|
59
|
-
importee = PREFIX + join(importer.substr(PREFIX_LENGTH).replace('.js', ''), '..', importee) + '.js';
|
|
60
|
-
}
|
|
61
|
-
if (importee.startsWith(PREFIX)) {
|
|
62
|
-
importee = importee.substr(PREFIX_LENGTH);
|
|
63
|
-
}
|
|
64
|
-
if (mods.has(importee) || (POLYFILLS as any)[importee.replace('.js', '') + '.js']) {
|
|
65
|
-
return { id: PREFIX + importee.replace('.js', '') + '.js', moduleSideEffects: false };
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
68
|
-
},
|
|
69
|
-
load(id: string) {
|
|
70
|
-
if (dirs.has(id)) {
|
|
71
|
-
return `export default '${dirs.get(id)}'`;
|
|
72
|
-
}
|
|
73
|
-
if (id.startsWith(PREFIX)) {
|
|
74
|
-
const importee = id.substr(PREFIX_LENGTH).replace('.js', '');
|
|
75
|
-
return mods.get(importee) || (POLYFILLS as any)[importee + '.js'];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
},
|
|
79
|
-
transform(code: string, id: string) {
|
|
80
|
-
if(id === PREFIX + 'global.js') return
|
|
81
|
-
// @ts-ignore
|
|
82
|
-
return injectPlugin.transform!.call(this, code, id.replace(PREFIX, resolve('node_modules', 'polyfill-node')));
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function getRandomId() {
|
|
88
|
-
return randomBytes(15).toString("hex");
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const DIRNAME_PATH = "\0node-polyfills:dirname";
|
|
92
|
-
const FILENAME_PATH = "\0node-polyfills:filename";
|
package/src/modules.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import POLYFILLS from './polyfills';
|
|
2
|
-
const EMPTY_PATH = POLYFILLS['empty.js'];
|
|
3
|
-
|
|
4
|
-
export function getModules() {
|
|
5
|
-
const libs = new Map<string, string>();
|
|
6
|
-
|
|
7
|
-
libs.set('process', POLYFILLS['process-es6.js']);
|
|
8
|
-
libs.set('global', POLYFILLS['global.js']);
|
|
9
|
-
libs.set('buffer', POLYFILLS['buffer-es6.js']);
|
|
10
|
-
libs.set('util', POLYFILLS['util.js']);
|
|
11
|
-
libs.set('sys', libs.get('util') as string);
|
|
12
|
-
libs.set('events', POLYFILLS['events.js']);
|
|
13
|
-
libs.set('stream', POLYFILLS['stream.js']);
|
|
14
|
-
libs.set('path', POLYFILLS['path.js']);
|
|
15
|
-
libs.set('querystring', POLYFILLS['querystring.js']);
|
|
16
|
-
libs.set('punycode', POLYFILLS['punycode.js']);
|
|
17
|
-
libs.set('url', POLYFILLS['url.js']);
|
|
18
|
-
libs.set('string_decoder', POLYFILLS['string-decoder.js']);
|
|
19
|
-
libs.set('http', POLYFILLS['http.js']);
|
|
20
|
-
libs.set('https', POLYFILLS['http.js']);
|
|
21
|
-
libs.set('os', POLYFILLS['os.js']);
|
|
22
|
-
libs.set('assert', POLYFILLS['assert.js']);
|
|
23
|
-
libs.set('constants', POLYFILLS['constants.js']);
|
|
24
|
-
libs.set('_stream_duplex', POLYFILLS['__readable-stream/duplex.js']);
|
|
25
|
-
libs.set('_stream_passthrough', POLYFILLS['__readable-stream/passthrough.js']);
|
|
26
|
-
libs.set('_stream_readable', POLYFILLS['__readable-stream/readable.js']);
|
|
27
|
-
libs.set('_stream_writable', POLYFILLS['__readable-stream/writable.js']);
|
|
28
|
-
libs.set('_stream_transform', POLYFILLS['__readable-stream/transform.js']);
|
|
29
|
-
libs.set('_inherits', POLYFILLS['inherits.js']);
|
|
30
|
-
libs.set('_buffer_list', POLYFILLS['__readable-stream/buffer-list.js']);
|
|
31
|
-
libs.set('timers', POLYFILLS['timers.js']);
|
|
32
|
-
libs.set('console', POLYFILLS['console.js']);
|
|
33
|
-
libs.set('vm', POLYFILLS['vm.js']);
|
|
34
|
-
libs.set('zlib', POLYFILLS['zlib.js']);
|
|
35
|
-
libs.set('tty', POLYFILLS['tty.js']);
|
|
36
|
-
libs.set('domain', POLYFILLS['domain.js']);
|
|
37
|
-
|
|
38
|
-
// TODO: Decide if we want to implement these or not
|
|
39
|
-
// currently causing trouble in tests
|
|
40
|
-
libs.set('fs', EMPTY_PATH);
|
|
41
|
-
libs.set('crypto', EMPTY_PATH);
|
|
42
|
-
// libs.set('fs', POLYFILLS['browserify-fs.js']);
|
|
43
|
-
// libs.set('crypto', POLYFILLS['crypto-browserify.js']);
|
|
44
|
-
|
|
45
|
-
// TODO: No good polyfill exists yet
|
|
46
|
-
libs.set('http2', EMPTY_PATH);
|
|
47
|
-
|
|
48
|
-
// not shimmed
|
|
49
|
-
libs.set('dns', EMPTY_PATH);
|
|
50
|
-
libs.set('dgram', EMPTY_PATH);
|
|
51
|
-
libs.set('child_process', EMPTY_PATH);
|
|
52
|
-
libs.set('cluster', EMPTY_PATH);
|
|
53
|
-
libs.set('module', EMPTY_PATH);
|
|
54
|
-
libs.set('net', EMPTY_PATH);
|
|
55
|
-
libs.set('readline', EMPTY_PATH);
|
|
56
|
-
libs.set('repl', EMPTY_PATH);
|
|
57
|
-
libs.set('tls', EMPTY_PATH);
|
|
58
|
-
libs.set('perf_hooks', EMPTY_PATH);
|
|
59
|
-
|
|
60
|
-
return libs;
|
|
61
|
-
}
|