@rushstack/set-webpack-public-path-plugin 5.1.0 → 5.1.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetPublicPathCurrentScriptPlugin.d.ts","sourceRoot":"","sources":["../src/SetPublicPathCurrentScriptPlugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAcpE;;;;;GAKG;AACH,qBAAa,gCAAiC,SAAQ,uBAAuB;;IAK3E,SAAS,CAAC,iBAAiB,CAAC,WAAW,EAAE,OAAO,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"SetPublicPathCurrentScriptPlugin.d.ts","sourceRoot":"","sources":["../src/SetPublicPathCurrentScriptPlugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAcpE;;;;;GAKG;AACH,qBAAa,gCAAiC,SAAQ,uBAAuB;;IAK3E,SAAS,CAAC,iBAAiB,CAAC,WAAW,EAAE,OAAO,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,GAAG,IAAI;CAmFjG"}
|
|
@@ -20,13 +20,6 @@ class SetPublicPathCurrentScriptPlugin extends SetPublicPathPluginBase_1.SetPubl
|
|
|
20
20
|
_applyCompilation(thisWebpack, compilation) {
|
|
21
21
|
var _a;
|
|
22
22
|
const outputLibraryType = (_a = compilation.options.output.library) === null || _a === void 0 ? void 0 : _a.type;
|
|
23
|
-
switch (outputLibraryType) {
|
|
24
|
-
case 'var':
|
|
25
|
-
case 'module':
|
|
26
|
-
compilation.errors.push(new thisWebpack.WebpackError(`The "${outputLibraryType}" output.library.type is not supported by the ${SetPublicPathCurrentScriptPlugin.name}` +
|
|
27
|
-
' plugin. Including this plugin with produce unexpected or invalid results.'));
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
23
|
class SetPublicPathRuntimeModule extends thisWebpack.RuntimeModule {
|
|
31
24
|
constructor() {
|
|
32
25
|
super('publicPath', thisWebpack.RuntimeModule.STAGE_BASIC);
|
|
@@ -62,6 +55,29 @@ class SetPublicPathCurrentScriptPlugin extends SetPublicPathPluginBase_1.SetPubl
|
|
|
62
55
|
hash.update('set-public-path');
|
|
63
56
|
}
|
|
64
57
|
});
|
|
58
|
+
compilation.hooks.afterSeal.tap(PLUGIN_NAME, () => {
|
|
59
|
+
let hasProblematicLibraryType = false;
|
|
60
|
+
switch (outputLibraryType) {
|
|
61
|
+
case 'var':
|
|
62
|
+
case 'module':
|
|
63
|
+
hasProblematicLibraryType = true;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
if (hasProblematicLibraryType) {
|
|
67
|
+
const codeGenerationResults = compilation.codeGenerationResults;
|
|
68
|
+
let appliesToAnyChunk = false;
|
|
69
|
+
for (const chunk of compilation.chunks) {
|
|
70
|
+
if (appliesToChunk(chunk, codeGenerationResults)) {
|
|
71
|
+
appliesToAnyChunk = true;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (appliesToAnyChunk) {
|
|
76
|
+
compilation.errors.push(new thisWebpack.WebpackError(`The "${outputLibraryType}" output.library.type is not supported by the ${SetPublicPathCurrentScriptPlugin.name}` +
|
|
77
|
+
' plugin. Including this plugin with produce unexpected or invalid results.'));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
65
81
|
}
|
|
66
82
|
}
|
|
67
83
|
exports.SetPublicPathCurrentScriptPlugin = SetPublicPathCurrentScriptPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetPublicPathCurrentScriptPlugin.js","sourceRoot":"","sources":["../src/SetPublicPathCurrentScriptPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,uEAAoE;AAEpE,MAAM,WAAW,GAAW,+CAA+C,CAAC;AAE5E,MAAM,4BAA4B,GAAW,8BAA8B,CAAC;AAC5E,MAAM,yBAAyB,GAAW,aAAa,CAAC;AASxD;;;;;GAKG;AACH,MAAa,gCAAiC,SAAQ,iDAAuB;IAC3E;QACE,KAAK,CAAC,WAAW,CAAC,CAAC;IACrB,CAAC;IAES,iBAAiB,CAAC,WAA2B,EAAE,WAAgC;;QACvF,MAAM,iBAAiB,GAAuB,MAAA,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,0CAAE,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"SetPublicPathCurrentScriptPlugin.js","sourceRoot":"","sources":["../src/SetPublicPathCurrentScriptPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,uEAAoE;AAEpE,MAAM,WAAW,GAAW,+CAA+C,CAAC;AAE5E,MAAM,4BAA4B,GAAW,8BAA8B,CAAC;AAC5E,MAAM,yBAAyB,GAAW,aAAa,CAAC;AASxD;;;;;GAKG;AACH,MAAa,gCAAiC,SAAQ,iDAAuB;IAC3E;QACE,KAAK,CAAC,WAAW,CAAC,CAAC;IACrB,CAAC;IAES,iBAAiB,CAAC,WAA2B,EAAE,WAAgC;;QACvF,MAAM,iBAAiB,GAAuB,MAAA,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,0CAAE,IAAI,CAAC;QAEvF,MAAM,0BAA2B,SAAQ,WAAW,CAAC,aAAa;YAChE;gBACE,KAAK,CAAC,YAAY,EAAE,WAAW,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;YAC7D,CAAC;YAEM,QAAQ;gBACb,OAAO;oBACL,OAAO,yBAAyB,MAAM,4BAA4B,MAAM,4BAA4B,YAAY;oBAChH,GAAG,WAAW,CAAC,cAAc,CAAC,UAAU,MAAM,yBAA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AM,CAAC,WAAW,CAAC,CAAC;YACzB,IAAI,cAAc,CAAC,KAAK,EAAE,qBAAqB,CAAC,EAAE,CAAC;gBACjD,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;YACjC,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,WAAW,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,EAAE;YAChD,IAAI,yBAAyB,GAAY,KAAK,CAAC;YAC/C,QAAQ,iBAAiB,EAAE,CAAC;gBAC1B,KAAK,KAAK,CAAC;gBACX,KAAK,QAAQ;oBACX,yBAAyB,GAAG,IAAI,CAAC;oBACjC,MAAM;YACV,CAAC;YAED,IAAI,yBAAyB,EAAE,CAAC;gBAC9B,MAAM,qBAAqB,GAA0B,WAAW,CAAC,qBAAqB,CAAC;gBACvF,IAAI,iBAAiB,GAAY,KAAK,CAAC;gBACvC,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;oBACvC,IAAI,cAAc,CAAC,KAAK,EAAE,qBAAqB,CAAC,EAAE,CAAC;wBACjD,iBAAiB,GAAG,IAAI,CAAC;wBACzB,MAAM;oBACR,CAAC;gBACH,CAAC;gBAED,IAAI,iBAAiB,EAAE,CAAC;oBACtB,WAAW,CAAC,MAAM,CAAC,IAAI,CACrB,IAAI,WAAW,CAAC,YAAY,CAC1B,QAAQ,iBAAiB,iDAAiD,gCAAgC,CAAC,IAAI,EAAE;wBAC/G,4EAA4E,CAC/E,CACF,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAxFD,4EAwFC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type webpack from 'webpack';\nimport { SetPublicPathPluginBase } from './SetPublicPathPluginBase';\n\nconst PLUGIN_NAME: string = 'set-webpack-public-path-current-script-plugin';\n\nconst CURRENT_SCRIPT_VARIABLE_NAME: string = '__RUSHSTACK_CURRENT_SCRIPT__';\nconst PUBLIC_PATH_VARIABLE_NAME: string = '_publicPath';\n\ntype JavascriptModulesPluginHooks = ReturnType<\n typeof webpack.javascript.JavascriptModulesPlugin.getCompilationHooks\n>;\ntype CodeGenerationResults = Parameters<\n Parameters<JavascriptModulesPluginHooks['render']['tap']>[1]\n>[1]['codeGenerationResults'];\n\n/**\n * This simple plugin wraps the webpack bundle in an IIFE that sets a the `document.currentScript` value to a variable\n * that is then used to populate the `__webpack_public_path__` variable.\n *\n * @public\n */\nexport class SetPublicPathCurrentScriptPlugin extends SetPublicPathPluginBase {\n public constructor() {\n super(PLUGIN_NAME);\n }\n\n protected _applyCompilation(thisWebpack: typeof webpack, compilation: webpack.Compilation): void {\n const outputLibraryType: string | undefined = compilation.options.output.library?.type;\n\n class SetPublicPathRuntimeModule extends thisWebpack.RuntimeModule {\n public constructor() {\n super('publicPath', thisWebpack.RuntimeModule.STAGE_BASIC);\n }\n\n public generate(): string {\n return [\n `var ${PUBLIC_PATH_VARIABLE_NAME} = ${CURRENT_SCRIPT_VARIABLE_NAME} ? ${CURRENT_SCRIPT_VARIABLE_NAME}.src : '';`,\n `${thisWebpack.RuntimeGlobals.publicPath} = ${PUBLIC_PATH_VARIABLE_NAME}.slice(0, ${PUBLIC_PATH_VARIABLE_NAME}.lastIndexOf('/') + 1);`\n ].join('\\n');\n }\n }\n\n const runtimeModule: SetPublicPathRuntimeModule = new SetPublicPathRuntimeModule();\n\n function appliesToChunk(chunk: webpack.Chunk, codeGenerationResults: CodeGenerationResults): boolean {\n return chunk.hasRuntime() && codeGenerationResults.has(runtimeModule, chunk.runtime);\n }\n\n compilation.hooks.runtimeRequirementInTree\n .for(thisWebpack.RuntimeGlobals.publicPath)\n .tap(PLUGIN_NAME, (chunk: webpack.Chunk, set: Set<string>) => {\n compilation.addRuntimeModule(chunk, runtimeModule);\n });\n\n const javascriptModulesPluginHooks: JavascriptModulesPluginHooks =\n thisWebpack.javascript.JavascriptModulesPlugin.getCompilationHooks(compilation);\n\n javascriptModulesPluginHooks.render.tap(\n { name: PLUGIN_NAME, stage: Number.MAX_SAFE_INTEGER },\n (source, { codeGenerationResults, chunk }) => {\n if (appliesToChunk(chunk, codeGenerationResults)) {\n return new thisWebpack.sources.ConcatSource(\n `(()=>{ var ${CURRENT_SCRIPT_VARIABLE_NAME} = document.currentScript; `,\n source,\n '})();'\n );\n } else {\n return source;\n }\n }\n );\n\n javascriptModulesPluginHooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash, { codeGenerationResults }) => {\n hash.update(PLUGIN_NAME);\n if (appliesToChunk(chunk, codeGenerationResults)) {\n hash.update('set-public-path');\n }\n });\n\n compilation.hooks.afterSeal.tap(PLUGIN_NAME, () => {\n let hasProblematicLibraryType: boolean = false;\n switch (outputLibraryType) {\n case 'var':\n case 'module':\n hasProblematicLibraryType = true;\n break;\n }\n\n if (hasProblematicLibraryType) {\n const codeGenerationResults: CodeGenerationResults = compilation.codeGenerationResults;\n let appliesToAnyChunk: boolean = false;\n for (const chunk of compilation.chunks) {\n if (appliesToChunk(chunk, codeGenerationResults)) {\n appliesToAnyChunk = true;\n break;\n }\n }\n\n if (appliesToAnyChunk) {\n compilation.errors.push(\n new thisWebpack.WebpackError(\n `The \"${outputLibraryType}\" output.library.type is not supported by the ${SetPublicPathCurrentScriptPlugin.name}` +\n ' plugin. Including this plugin with produce unexpected or invalid results.'\n )\n );\n }\n }\n });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/set-webpack-public-path-plugin",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.2",
|
|
4
4
|
"description": "This plugin sets the webpack public path at runtime.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "dist/set-webpack-public-path-plugin.d.ts",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@rushstack/
|
|
24
|
-
"@rushstack/
|
|
23
|
+
"@rushstack/node-core-library": "3.64.0",
|
|
24
|
+
"@rushstack/webpack-plugin-utilities": "0.4.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"webpack": "~5.82.1",
|
|
28
28
|
"memfs": "3.4.3",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
29
|
+
"local-node-rig": "1.0.0",
|
|
30
|
+
"@rushstack/heft": "0.64.1"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "heft build --clean",
|