@rushstack/webpack-preserve-dynamic-require-plugin 0.9.0
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/README.md +11 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/webpack-preserve-dynamic-require-plugin.d.ts +10 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +31 -0
- package/lib/index.js.map +1 -0
- package/lib/index.test.d.ts +2 -0
- package/lib/index.test.d.ts.map +1 -0
- package/lib/index.test.js.map +1 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @rushstack/webpack-preserve-dynamic-require-plugin
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This Webpack plugin instructs webpack to leave dynamic usage of `require` as-is in the bundled code. For example, if your code contains:
|
|
6
|
+
```js
|
|
7
|
+
function requireSomeUserThing(path) {
|
|
8
|
+
return require(path);
|
|
9
|
+
}
|
|
10
|
+
```
|
|
11
|
+
The emitted bundle will preserve the call to `require(path)` instead of trying to process it.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.23.0"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AAIxC;;GAEG;AACH,qBAAa,mCAAmC;IACvC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI;CAwB/C"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PreserveDynamicRequireWebpackPlugin = void 0;
|
|
4
|
+
const PLUGIN_NAME = 'PreserveDynamicRequireWebpackPlugin';
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
class PreserveDynamicRequireWebpackPlugin {
|
|
9
|
+
apply(compiler) {
|
|
10
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
11
|
+
function processDependencies(block) {
|
|
12
|
+
const { dependencies } = block;
|
|
13
|
+
for (let i = dependencies.length - 1; i >= 0; i--) {
|
|
14
|
+
const dep = dependencies[i];
|
|
15
|
+
// Disable processing of dynamic require
|
|
16
|
+
if (dep.constructor.name === 'CommonJsRequireContextDependency') {
|
|
17
|
+
dependencies.splice(i, 1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
for (const child of block.blocks) {
|
|
21
|
+
processDependencies(child);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
compilation.hooks.succeedModule.tap(PLUGIN_NAME, (mod) => {
|
|
25
|
+
processDependencies(mod);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.PreserveDynamicRequireWebpackPlugin = PreserveDynamicRequireWebpackPlugin;
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,MAAM,WAAW,GAA0C,qCAAqC,CAAC;AAEjG;;GAEG;AACH,MAAa,mCAAmC;IACvC,KAAK,CAAC,QAA0B;QACrC,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,WAAgC,EAAE,EAAE;YACnF,SAAS,mBAAmB,CAC1B,KAAsE;gBAEtE,MAAM,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;gBAC/B,KAAK,IAAI,CAAC,GAAW,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;oBACzD,MAAM,GAAG,GAAuB,YAAY,CAAC,CAAC,CAAC,CAAC;oBAChD,wCAAwC;oBACxC,IAAI,GAAG,CAAC,WAAW,CAAC,IAAI,KAAK,kCAAkC,EAAE;wBAC/D,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;qBAC3B;iBACF;gBAED,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE;oBAChC,mBAAmB,CAAC,KAAK,CAAC,CAAC;iBAC5B;YACH,CAAC;YAED,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAmB,EAAE,EAAE;gBACvE,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAzBD,kFAyBC","sourcesContent":["import type * as webpack from 'webpack';\n\nconst PLUGIN_NAME: 'PreserveDynamicRequireWebpackPlugin' = 'PreserveDynamicRequireWebpackPlugin';\n\n/**\n * @public\n */\nexport class PreserveDynamicRequireWebpackPlugin {\n public apply(compiler: webpack.Compiler): void {\n compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation: webpack.Compilation) => {\n function processDependencies(\n block: Pick<webpack.AsyncDependenciesBlock, 'dependencies' | 'blocks'>\n ): void {\n const { dependencies } = block;\n for (let i: number = dependencies.length - 1; i >= 0; i--) {\n const dep: webpack.Dependency = dependencies[i];\n // Disable processing of dynamic require\n if (dep.constructor.name === 'CommonJsRequireContextDependency') {\n dependencies.splice(i, 1);\n }\n }\n\n for (const child of block.blocks) {\n processDependencies(child);\n }\n }\n\n compilation.hooks.succeedModule.tap(PLUGIN_NAME, (mod: webpack.Module) => {\n processDependencies(mod);\n });\n });\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":";;;;;AAAA,IAAI,CAAC,eAAe,EAAE,CAAC;AACvB,sDAA8B;AAE9B,mCAA8D;AAE9D,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAErB,QAAQ,CAAC,2CAAmC,CAAC,IAAI,EAAE,GAAG,EAAE;IACtD,EAAE,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;QAC/C,MAAM,OAAO,GAAwB,IAAI,GAAG,EAAE,CAAC;QAC/C,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QACjD,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,iCAAiC,CAAC,CAAC;QAE3D,MAAM,QAAQ,GAAqB,IAAA,iBAAO,EAAC;YACzC,KAAK,EAAE;gBACL,IAAI,EAAE,UAAU;aACjB;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE,WAAW;aACtB;YACD,OAAO,EAAE,GAAG;YACZ,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,CAAC,IAAI,2CAAmC,EAAE,CAAC;SACrD,CAAC,CAAC;QAEH,MAAM,OAAO,GAAoC;YAC/C,QAAQ,CAAC,IAAY,EAAE,EAAuE;gBAC5F,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;YACnC,CAAC;YACD,OAAO,CAA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AAO,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;gBAC5C,EAAE,EAAE,CAAC;YACP,CAAC;SAC6C,CAAC;QAEjD,QAAQ,CAAC,eAAe,GAAG,OAAO,CAAC;QACnC,QAAQ,CAAC,gBAAgB,GAAG,QAAQ,CAAC;QAErC,MAAM,IAAI,OAAO,CAAO,CAAC,OAAmB,EAAE,MAA4B,EAAE,EAAE,CAC5E,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAkB,EAAE,EAAE;YAClC,IAAI,GAAG,EAAE;gBACP,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;aACpB;YACD,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CACH,CAAC;QAEF,MAAM,CAAC,OAAO,CAAC,CAAC,eAAe,EAAE,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["jest.disableAutomock();\nimport webpack from 'webpack';\n\nimport { PreserveDynamicRequireWebpackPlugin } from './index';\n\njest.setTimeout(1e9);\n\ndescribe(PreserveDynamicRequireWebpackPlugin.name, () => {\n it('Preserves dynamic require usage', async () => {\n const sources: Map<string, string> = new Map();\n sources.set('/package.json', JSON.stringify({}));\n sources.set('/file.js', 'require(process.env.SOME_PATH);');\n\n const compiler: webpack.Compiler = webpack({\n entry: {\n main: '/file.js'\n },\n output: {\n path: '/release',\n filename: '[name].js'\n },\n context: '/',\n mode: 'none',\n plugins: [new PreserveDynamicRequireWebpackPlugin()]\n });\n\n const inputFs: typeof compiler.inputFileSystem = {\n readFile(path: string, cb: (err?: NodeJS.ErrnoException | undefined, content?: string) => void): void {\n cb(undefined, sources.get(path));\n },\n readdir(path: string, cb: (err?: NodeJS.ErrnoException | undefined, files?: string[]) => void): void {\n cb(\n undefined,\n Array.from(sources.keys(), (key: string) => key.slice(1))\n );\n },\n readlink(path: string, cb: (err?: NodeJS.ErrnoException | undefined, dest?: string) => void): void {\n cb();\n },\n stat(path: string, cb: (err?: NodeJS.ErrnoException, stat?: unknown) => void): void {\n if (sources.has(path)) {\n return cb(undefined, {\n isFile() {\n return true;\n },\n isDirectory() {\n return false;\n }\n });\n } else if (path === '/') {\n return cb(undefined, {\n isFile() {\n return false;\n },\n isDirectory() {\n return true;\n }\n });\n }\n cb(new Error(`Unexpected stat call for ${path}`));\n }\n } as unknown as typeof compiler.inputFileSystem;\n\n const results: Map<string, string> = new Map();\n\n const outputFs: typeof compiler.outputFileSystem = {\n mkdir(path: string, cb: (err?: NodeJS.ErrnoException) => void): void {\n cb();\n },\n stat(path: string, cb: (err?: NodeJS.ErrnoException) => void): void {\n const err: NodeJS.ErrnoException = new Error(`No such file`);\n err.code = 'ENOENT';\n cb(err);\n },\n writeFile(path: string, content: Buffer, cb: (err?: NodeJS.ErrnoException) => void): void {\n results.set(path, content.toString('utf8'));\n cb();\n }\n } as unknown as typeof compiler.outputFileSystem;\n\n compiler.inputFileSystem = inputFs;\n compiler.outputFileSystem = outputFs;\n\n await new Promise<void>((resolve: () => void, reject: (err: Error) => void) =>\n compiler.run((err?: Error | null) => {\n if (err) {\n return reject(err);\n }\n resolve();\n })\n );\n\n expect(results).toMatchSnapshot();\n });\n});\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rushstack/webpack-preserve-dynamic-require-plugin",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "This plugin tells webpack to leave dynamic calls to \"require\" as-is instead of trying to bundle them.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "dist/webpack-preserve-dynamic-require-plugin.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/microsoft/rushstack.git",
|
|
11
|
+
"directory": "webpack/preserve-dynamic-require-plugin"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=10.17.1"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@rushstack/eslint-config": "2.6.0",
|
|
19
|
+
"@rushstack/heft": "0.45.0",
|
|
20
|
+
"@rushstack/heft-node-rig": "1.9.1",
|
|
21
|
+
"@types/heft-jest": "1.0.1",
|
|
22
|
+
"@types/node": "12.20.24",
|
|
23
|
+
"webpack": "~5.68.0"
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "heft build --clean",
|
|
28
|
+
"_phase:build": "heft build --clean",
|
|
29
|
+
"_phase:test": "heft test --no-build"
|
|
30
|
+
},
|
|
31
|
+
"readme": "# @rushstack/webpack-preserve-dynamic-require-plugin\n\n## Overview\n\nThis Webpack plugin instructs webpack to leave dynamic usage of `require` as-is in the bundled code. For example, if your code contains:\n```js\nfunction requireSomeUserThing(path) {\n return require(path);\n}\n```\nThe emitted bundle will preserve the call to `require(path)` instead of trying to process it.\n"
|
|
32
|
+
}
|