@rushstack/set-webpack-public-path-plugin 5.1.72 → 5.1.74
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/CHANGELOG.json +33 -0
- package/CHANGELOG.md +11 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/SetPublicPathPlugin.js +5 -1
- package/lib/SetPublicPathPlugin.js.map +1 -1
- package/lib/SetPublicPathPluginBase.js +5 -2
- package/lib/SetPublicPathPluginBase.js.map +1 -1
- package/lib/codeGenerator.js +1 -2
- package/lib/codeGenerator.js.map +1 -1
- package/package.json +6 -5
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/set-webpack-public-path-plugin",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "5.1.74",
|
|
6
|
+
"tag": "@rushstack/set-webpack-public-path-plugin_v5.1.74",
|
|
7
|
+
"date": "Tue, 11 Mar 2025 02:12:34 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"dependency": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Updating dependency \"@rushstack/node-core-library\" to `5.12.0`"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"comment": "Updating dependency \"@rushstack/webpack-plugin-utilities\" to `0.4.74`"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"comment": "Updating dependency \"@rushstack/heft\" to `0.70.0`"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"version": "5.1.73",
|
|
24
|
+
"tag": "@rushstack/set-webpack-public-path-plugin_v5.1.73",
|
|
25
|
+
"date": "Tue, 11 Mar 2025 00:11:25 GMT",
|
|
26
|
+
"comments": {
|
|
27
|
+
"dependency": [
|
|
28
|
+
{
|
|
29
|
+
"comment": "Updating dependency \"@rushstack/webpack-plugin-utilities\" to `0.4.73`"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"comment": "Updating dependency \"@rushstack/heft\" to `0.69.3`"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
4
37
|
{
|
|
5
38
|
"version": "5.1.72",
|
|
6
39
|
"tag": "@rushstack/set-webpack-public-path-plugin_v5.1.72",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Change Log - @rushstack/set-webpack-public-path-plugin
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 11 Mar 2025 02:12:34 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 5.1.74
|
|
6
|
+
Tue, 11 Mar 2025 02:12:34 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 5.1.73
|
|
11
|
+
Tue, 11 Mar 2025 00:11:25 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
4
14
|
|
|
5
15
|
## 5.1.72
|
|
6
16
|
Sat, 01 Mar 2025 05:00:09 GMT
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -54,7 +54,11 @@ class SetPublicPathPlugin extends SetPublicPathPluginBase_1.SetPublicPathPluginB
|
|
|
54
54
|
else {
|
|
55
55
|
throw new Error('scriptName.name or scriptName.useAssetName must be set');
|
|
56
56
|
}
|
|
57
|
-
const moduleOptions =
|
|
57
|
+
const moduleOptions = {
|
|
58
|
+
webpackPublicPathVariable: thisWebpack.RuntimeGlobals.publicPath,
|
|
59
|
+
regexName,
|
|
60
|
+
...this._pluginOptions
|
|
61
|
+
};
|
|
58
62
|
return (0, codeGenerator_1.getSetPublicPathCode)(moduleOptions);
|
|
59
63
|
}
|
|
60
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetPublicPathPlugin.js","sourceRoot":"","sources":["../src/SetPublicPathPlugin.ts"],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ACrF,CAAC;4BAED,MAAM,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC;wBACnC,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAzGD,kDAyGC","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 { Text } from '@rushstack/node-core-library';\n\nimport type webpack from 'webpack';\n\nimport { type IInternalOptions, getSetPublicPathCode } from './codeGenerator';\nimport { SetPublicPathPluginBase } from './SetPublicPathPluginBase';\n\n/**\n * The base options for setting the webpack public path at runtime.\n *\n * @public\n */\nexport interface ISetWebpackPublicPathOptions {\n /**\n * Check for a variable with this name on the page and use its value as a regular expression against script paths to\n * the bundle's script. If a value foo is passed into regexVariable, the produced bundle will look for a variable\n * called foo during initialization, and if a foo variable is found, use its value as a regular expression to detect\n * the bundle's script.\n *\n * See the README for more information.\n */\n regexVariable?: string;\n\n /**\n * A function that returns a snippet of code that manipulates the variable with the name that's specified in the\n * parameter. If this parameter isn't provided, no post-processing code is included. The variable must be modified\n * in-place - the processed value should not be returned.\n *\n * See the README for more information.\n */\n getPostProcessScript?: (varName: string) => string;\n\n /**\n * If true, find the last script matching the regexVariable (if it is set). If false, find the first matching script.\n * This can be useful if there are multiple scripts loaded in the DOM that match the regexVariable.\n */\n preferLastFoundScript?: boolean;\n}\n\n/**\n * @public\n */\nexport interface IScriptNameAssetNameOptions {\n /**\n * If set to true, use the webpack generated asset's name. This option is not compatible with\n * andy other scriptName options.\n */\n useAssetName: true;\n}\n\n/**\n * @public\n */\nexport interface IScriptNameRegexOptions {\n /**\n * A regular expression expressed as a string to be applied to all script paths on the page.\n */\n name: string;\n\n /**\n * If true, the name property is tokenized.\n *\n * See the README for more information.\n */\n isTokenized?: boolean;\n}\n\n/**\n * @public\n */\nexport type IScriptNameOptions = IScriptNameAssetNameOptions | IScriptNameRegexOptions;\n\ntype IScriptNameInternalOptions =\n | (IScriptNameAssetNameOptions & { [key in keyof IScriptNameRegexOptions]?: never })\n | (IScriptNameRegexOptions & { [key in keyof IScriptNameAssetNameOptions]?: never });\n\n/**\n * Options for the set-webpack-public-path plugin.\n *\n * @public\n */\nexport interface ISetWebpackPublicPathPluginOptions extends ISetWebpackPublicPathOptions {\n /**\n * An object that describes how the public path should be discovered.\n */\n scriptName: IScriptNameOptions;\n}\n\nconst SHOULD_REPLACE_ASSET_NAME_TOKEN: unique symbol = Symbol(\n 'set-public-path-plugin-should-replace-asset-name'\n);\n\ninterface IExtendedChunk extends webpack.Chunk {\n [SHOULD_REPLACE_ASSET_NAME_TOKEN]?: boolean;\n}\n\nconst PLUGIN_NAME: string = 'set-webpack-public-path';\n\nconst ASSET_NAME_TOKEN: string = '-ASSET-NAME-c0ef4f86-b570-44d3-b210-4428c5b7825c';\n\n/**\n * This simple plugin sets the __webpack_public_path__ variable to a value specified in the arguments.\n *\n * @public\n */\nexport class SetPublicPathPlugin extends SetPublicPathPluginBase {\n public readonly options: ISetWebpackPublicPathPluginOptions;\n\n public constructor(options: ISetWebpackPublicPathPluginOptions) {\n super(PLUGIN_NAME);\n this.options = options;\n\n const scriptNameOptions: IScriptNameInternalOptions = options.scriptName;\n if (scriptNameOptions.useAssetName && scriptNameOptions.name) {\n throw new Error('scriptName.userAssetName and scriptName.name must not be used together');\n } else if (scriptNameOptions.isTokenized && !scriptNameOptions.name) {\n throw new Error('scriptName.isTokenized is only valid if scriptName.name is set');\n }\n }\n\n protected _applyCompilation(thisWebpack: typeof webpack, compilation: webpack.Compilation): void {\n class SetPublicPathRuntimeModule extends thisWebpack.RuntimeModule {\n private readonly _pluginOptions: ISetWebpackPublicPathPluginOptions;\n\n public constructor(pluginOptions: ISetWebpackPublicPathPluginOptions) {\n super('publicPath', thisWebpack.RuntimeModule.STAGE_BASIC);\n this._pluginOptions = pluginOptions;\n }\n\n public generate(): string {\n const {\n name: regexpName,\n isTokenized: regexpIsTokenized,\n useAssetName\n } = this._pluginOptions.scriptName as IScriptNameInternalOptions;\n\n const { chunk } = this;\n if (!chunk) {\n throw new Error(`Chunk is not defined`);\n }\n\n let regexName: string;\n if (regexpName) {\n regexName = regexpName;\n if (regexpIsTokenized) {\n regexName = regexName\n .replace(/\\[name\\]/g, Text.escapeRegExp(`${chunk.name}`))\n .replace(/\\[hash\\]/g, chunk.renderedHash || '');\n }\n } else if (useAssetName) {\n (chunk as IExtendedChunk)[SHOULD_REPLACE_ASSET_NAME_TOKEN] = true;\n\n regexName = ASSET_NAME_TOKEN;\n } else {\n throw new Error('scriptName.name or scriptName.useAssetName must be set');\n }\n\n const moduleOptions: IInternalOptions = {\n webpackPublicPathVariable: thisWebpack.RuntimeGlobals.publicPath,\n regexName,\n ...this._pluginOptions\n };\n\n return getSetPublicPathCode(moduleOptions);\n }\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, new SetPublicPathRuntimeModule(this.options));\n });\n\n compilation.hooks.processAssets.tap(PLUGIN_NAME, (assets) => {\n for (const chunkGroup of compilation.chunkGroups) {\n for (const chunk of chunkGroup.chunks) {\n if ((chunk as IExtendedChunk)[SHOULD_REPLACE_ASSET_NAME_TOKEN]) {\n for (const assetFilename of chunk.files) {\n let escapedAssetFilename: string;\n if (assetFilename.match(/\\.map$/)) {\n // Trim the \".map\" extension\n escapedAssetFilename = assetFilename.slice(0, -4 /* '.map'.length */);\n escapedAssetFilename = Text.escapeRegExp(escapedAssetFilename);\n // source in sourcemaps is JSON-encoded\n escapedAssetFilename = JSON.stringify(escapedAssetFilename);\n // Trim the quotes from the JSON encoding\n escapedAssetFilename = escapedAssetFilename.slice(1, -1);\n } else {\n escapedAssetFilename = Text.escapeRegExp(assetFilename);\n }\n\n const asset: webpack.sources.Source = assets[assetFilename];\n\n const newAsset: webpack.sources.ReplaceSource = new thisWebpack.sources.ReplaceSource(asset);\n const sourceString: string = asset.source().toString();\n for (\n let index: number = sourceString.lastIndexOf(ASSET_NAME_TOKEN);\n index >= 0;\n index = sourceString.lastIndexOf(ASSET_NAME_TOKEN, index - 1)\n ) {\n newAsset.replace(index, index + ASSET_NAME_TOKEN.length - 1, escapedAssetFilename);\n }\n\n assets[assetFilename] = newAsset;\n }\n }\n }\n }\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SetPublicPathPlugin.js","sourceRoot":"","sources":["../src/SetPublicPathPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,oEAAoD;AAIpD,mDAA8E;AAC9E,uEAAoE;AAmFpE,MAAM,+BAA+B,GAAkB,MAAM,CAC3D,kDAAkD,CACnD,CAAC;AAMF,MAAM,WAAW,GAAW,yBAAyB,CAAC;AAEtD,MAAM,gBAAgB,GAAW,kDAAkD,CAAC;AAEpF;;;;GAIG;AACH,MAAa,mBAAoB,SAAQ,iDAAuB;IAG9D,YAAmB,OAA2C;QAC5D,KAAK,CAAC,WAAW,CAAC,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,MAAM,iBAAiB,GAA+B,OAAO,CAAC,UAAU,CAAC;QACzE,IAAI,iBAAiB,CAAC,YAAY,IAAI,iBAAiB,CAAC,IAAI,EAAE,CAAC;YAC7D,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;QAC5F,CAAC;aAAM,IAAI,iBAAiB,CAAC,WAAW,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC;YACpE,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;QACpF,CAAC;IACH,CAAC;IAES,iBAAiB,CAAC,WAA2B,EAAE,WAAgC;QACvF,MAAM,0BAA2B,SAAQ,WAAW,CAAC,aAAa;YAGhE,YAAmB,aAAiD;gBAClE,KAAK,CAAC,YAAY,EAAE,WAAW,CAAC,aAAa,CAAC,WAAW,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AAK,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC;4BACvD,KACE,IAAI,KAAK,GAAW,YAAY,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAC9D,KAAK,IAAI,CAAC,EACV,KAAK,GAAG,YAAY,CAAC,WAAW,CAAC,gBAAgB,EAAE,KAAK,GAAG,CAAC,CAAC,EAC7D,CAAC;gCACD,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,oBAAoB,CAAC,CAAC;4BACrF,CAAC;4BAED,MAAM,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC;wBACnC,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAzGD,kDAyGC","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 { Text } from '@rushstack/node-core-library';\n\nimport type webpack from 'webpack';\n\nimport { type IInternalOptions, getSetPublicPathCode } from './codeGenerator';\nimport { SetPublicPathPluginBase } from './SetPublicPathPluginBase';\n\n/**\n * The base options for setting the webpack public path at runtime.\n *\n * @public\n */\nexport interface ISetWebpackPublicPathOptions {\n /**\n * Check for a variable with this name on the page and use its value as a regular expression against script paths to\n * the bundle's script. If a value foo is passed into regexVariable, the produced bundle will look for a variable\n * called foo during initialization, and if a foo variable is found, use its value as a regular expression to detect\n * the bundle's script.\n *\n * See the README for more information.\n */\n regexVariable?: string;\n\n /**\n * A function that returns a snippet of code that manipulates the variable with the name that's specified in the\n * parameter. If this parameter isn't provided, no post-processing code is included. The variable must be modified\n * in-place - the processed value should not be returned.\n *\n * See the README for more information.\n */\n getPostProcessScript?: (varName: string) => string;\n\n /**\n * If true, find the last script matching the regexVariable (if it is set). If false, find the first matching script.\n * This can be useful if there are multiple scripts loaded in the DOM that match the regexVariable.\n */\n preferLastFoundScript?: boolean;\n}\n\n/**\n * @public\n */\nexport interface IScriptNameAssetNameOptions {\n /**\n * If set to true, use the webpack generated asset's name. This option is not compatible with\n * andy other scriptName options.\n */\n useAssetName: true;\n}\n\n/**\n * @public\n */\nexport interface IScriptNameRegexOptions {\n /**\n * A regular expression expressed as a string to be applied to all script paths on the page.\n */\n name: string;\n\n /**\n * If true, the name property is tokenized.\n *\n * See the README for more information.\n */\n isTokenized?: boolean;\n}\n\n/**\n * @public\n */\nexport type IScriptNameOptions = IScriptNameAssetNameOptions | IScriptNameRegexOptions;\n\ntype IScriptNameInternalOptions =\n | (IScriptNameAssetNameOptions & { [key in keyof IScriptNameRegexOptions]?: never })\n | (IScriptNameRegexOptions & { [key in keyof IScriptNameAssetNameOptions]?: never });\n\n/**\n * Options for the set-webpack-public-path plugin.\n *\n * @public\n */\nexport interface ISetWebpackPublicPathPluginOptions extends ISetWebpackPublicPathOptions {\n /**\n * An object that describes how the public path should be discovered.\n */\n scriptName: IScriptNameOptions;\n}\n\nconst SHOULD_REPLACE_ASSET_NAME_TOKEN: unique symbol = Symbol(\n 'set-public-path-plugin-should-replace-asset-name'\n);\n\ninterface IExtendedChunk extends webpack.Chunk {\n [SHOULD_REPLACE_ASSET_NAME_TOKEN]?: boolean;\n}\n\nconst PLUGIN_NAME: string = 'set-webpack-public-path';\n\nconst ASSET_NAME_TOKEN: string = '-ASSET-NAME-c0ef4f86-b570-44d3-b210-4428c5b7825c';\n\n/**\n * This simple plugin sets the __webpack_public_path__ variable to a value specified in the arguments.\n *\n * @public\n */\nexport class SetPublicPathPlugin extends SetPublicPathPluginBase {\n public readonly options: ISetWebpackPublicPathPluginOptions;\n\n public constructor(options: ISetWebpackPublicPathPluginOptions) {\n super(PLUGIN_NAME);\n this.options = options;\n\n const scriptNameOptions: IScriptNameInternalOptions = options.scriptName;\n if (scriptNameOptions.useAssetName && scriptNameOptions.name) {\n throw new Error('scriptName.userAssetName and scriptName.name must not be used together');\n } else if (scriptNameOptions.isTokenized && !scriptNameOptions.name) {\n throw new Error('scriptName.isTokenized is only valid if scriptName.name is set');\n }\n }\n\n protected _applyCompilation(thisWebpack: typeof webpack, compilation: webpack.Compilation): void {\n class SetPublicPathRuntimeModule extends thisWebpack.RuntimeModule {\n private readonly _pluginOptions: ISetWebpackPublicPathPluginOptions;\n\n public constructor(pluginOptions: ISetWebpackPublicPathPluginOptions) {\n super('publicPath', thisWebpack.RuntimeModule.STAGE_BASIC);\n this._pluginOptions = pluginOptions;\n }\n\n public generate(): string {\n const {\n name: regexpName,\n isTokenized: regexpIsTokenized,\n useAssetName\n } = this._pluginOptions.scriptName as IScriptNameInternalOptions;\n\n const { chunk } = this;\n if (!chunk) {\n throw new Error(`Chunk is not defined`);\n }\n\n let regexName: string;\n if (regexpName) {\n regexName = regexpName;\n if (regexpIsTokenized) {\n regexName = regexName\n .replace(/\\[name\\]/g, Text.escapeRegExp(`${chunk.name}`))\n .replace(/\\[hash\\]/g, chunk.renderedHash || '');\n }\n } else if (useAssetName) {\n (chunk as IExtendedChunk)[SHOULD_REPLACE_ASSET_NAME_TOKEN] = true;\n\n regexName = ASSET_NAME_TOKEN;\n } else {\n throw new Error('scriptName.name or scriptName.useAssetName must be set');\n }\n\n const moduleOptions: IInternalOptions = {\n webpackPublicPathVariable: thisWebpack.RuntimeGlobals.publicPath,\n regexName,\n ...this._pluginOptions\n };\n\n return getSetPublicPathCode(moduleOptions);\n }\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, new SetPublicPathRuntimeModule(this.options));\n });\n\n compilation.hooks.processAssets.tap(PLUGIN_NAME, (assets) => {\n for (const chunkGroup of compilation.chunkGroups) {\n for (const chunk of chunkGroup.chunks) {\n if ((chunk as IExtendedChunk)[SHOULD_REPLACE_ASSET_NAME_TOKEN]) {\n for (const assetFilename of chunk.files) {\n let escapedAssetFilename: string;\n if (assetFilename.match(/\\.map$/)) {\n // Trim the \".map\" extension\n escapedAssetFilename = assetFilename.slice(0, -4 /* '.map'.length */);\n escapedAssetFilename = Text.escapeRegExp(escapedAssetFilename);\n // source in sourcemaps is JSON-encoded\n escapedAssetFilename = JSON.stringify(escapedAssetFilename);\n // Trim the quotes from the JSON encoding\n escapedAssetFilename = escapedAssetFilename.slice(1, -1);\n } else {\n escapedAssetFilename = Text.escapeRegExp(assetFilename);\n }\n\n const asset: webpack.sources.Source = assets[assetFilename];\n\n const newAsset: webpack.sources.ReplaceSource = new thisWebpack.sources.ReplaceSource(asset);\n const sourceString: string = asset.source().toString();\n for (\n let index: number = sourceString.lastIndexOf(ASSET_NAME_TOKEN);\n index >= 0;\n index = sourceString.lastIndexOf(ASSET_NAME_TOKEN, index - 1)\n ) {\n newAsset.replace(index, index + ASSET_NAME_TOKEN.length - 1, escapedAssetFilename);\n }\n\n assets[assetFilename] = newAsset;\n }\n }\n }\n }\n });\n }\n}\n"]}
|
|
@@ -32,9 +32,12 @@ class SetPublicPathPluginBase {
|
|
|
32
32
|
register: (tap) => {
|
|
33
33
|
if (tap.name === 'RuntimePlugin') {
|
|
34
34
|
// Disable the default public path runtime plugin
|
|
35
|
-
return
|
|
35
|
+
return {
|
|
36
|
+
...tap,
|
|
37
|
+
fn: () => {
|
|
36
38
|
/* noop */
|
|
37
|
-
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
38
41
|
}
|
|
39
42
|
else {
|
|
40
43
|
return tap;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetPublicPathPluginBase.js","sourceRoot":"","sources":["../src/SetPublicPathPluginBase.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,kFAAuE;AACvE,oEAAoF;AAIpF;;GAEG;AACH,MAAsB,uBAAuB;IAG3C,YAAmB,UAAkB;QACnC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAEM,KAAK,CAAC,QAA0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BACN,OAAO,GAAG,CAAC;wBACb,CAAC;oBACH,CAAC;iBACF,CAAC,CAAC;YACL,CAAC;YAED,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;IACL,CAAC;CAGF;AAtDD,0DAsDC","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 { VersionDetection } from '@rushstack/webpack-plugin-utilities';\nimport { PackageJsonLookup, type IPackageJson } from '@rushstack/node-core-library';\n\nimport type webpack from 'webpack';\n\n/**\n * @public\n */\nexport abstract class SetPublicPathPluginBase implements webpack.WebpackPluginInstance {\n private readonly _pluginName: string;\n\n public constructor(pluginName: string) {\n this._pluginName = pluginName;\n }\n\n public apply(compiler: webpack.Compiler): void {\n if (!VersionDetection.isWebpack5(compiler)) {\n const thisPackageJson: IPackageJson = PackageJsonLookup.loadOwnPackageJson(__dirname);\n throw new Error(\n `The ${this.constructor.name} plugin requires Webpack 5. Use major version 4 of ` +\n `${thisPackageJson.name} for Webpack 4 support.`\n );\n }\n\n const thisWebpack: typeof webpack = compiler.webpack;\n\n const initialOutputPublicPathSetting: typeof compiler.options.output.publicPath =\n compiler.options.output.publicPath;\n\n compiler.hooks.thisCompilation.tap(this._pluginName, (compilation: webpack.Compilation) => {\n if (initialOutputPublicPathSetting) {\n compilation.warnings.push(\n new compiler.webpack.WebpackError(\n `The \"output.publicPath\" option is set in the Webpack configuration. The ${this.constructor.name} ` +\n 'plugin may produce unexpected results. It is recommended that the \"output.publicPath\" configuration option ' +\n 'be unset when using this plugin.'\n )\n );\n } else {\n compilation.hooks.runtimeRequirementInTree.for(thisWebpack.RuntimeGlobals.publicPath).intercept({\n name: this._pluginName,\n register: (tap) => {\n if (tap.name === 'RuntimePlugin') {\n // Disable the default public path runtime plugin\n return {\n ...tap,\n fn: () => {\n /* noop */\n }\n };\n } else {\n return tap;\n }\n }\n });\n }\n\n this._applyCompilation(thisWebpack, compilation);\n });\n }\n\n protected abstract _applyCompilation(thisWebpack: typeof webpack, compilation: webpack.Compilation): void;\n}\n"]}
|
package/lib/codeGenerator.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
3
|
// See LICENSE in the project root for license information.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.getSetPublicPathCode =
|
|
5
|
+
exports.getSetPublicPathCode = getSetPublicPathCode;
|
|
6
6
|
const VAR_NAME = 'publicPath';
|
|
7
7
|
function joinLines(lines, linePrefix) {
|
|
8
8
|
return lines
|
|
@@ -51,5 +51,4 @@ function getSetPublicPathCode({ regexName, regexVariable, preferLastFoundScript,
|
|
|
51
51
|
lines.push(`${webpackPublicPathVariable} = ${VAR_NAME};`);
|
|
52
52
|
return joinLines(lines, linePrefix);
|
|
53
53
|
}
|
|
54
|
-
exports.getSetPublicPathCode = getSetPublicPathCode;
|
|
55
54
|
//# sourceMappingURL=codeGenerator.js.map
|
package/lib/codeGenerator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codeGenerator.js","sourceRoot":"","sources":["../src/codeGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D
|
|
1
|
+
{"version":3,"file":"codeGenerator.js","sourceRoot":"","sources":["../src/codeGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAyB3D,oDAgDC;AA/DD,MAAM,QAAQ,GAAW,YAAY,CAAC;AAEtC,SAAS,SAAS,CAAC,KAAe,EAAE,UAAmB;IACrD,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE;QACpB,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,GAAG,UAAU,IAAI,EAAE,GAAG,IAAI,EAAE,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,OAAO,IAA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AAM,QAAQ,GAAG,CAAC,CAAC;IAE1D,OAAO,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;AACtC,CAAC","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 { ISetWebpackPublicPathOptions } from './SetPublicPathPlugin';\n\nexport interface IInternalOptions extends ISetWebpackPublicPathOptions {\n webpackPublicPathVariable: string;\n regexName: string;\n linePrefix?: string;\n}\n\nconst VAR_NAME: string = 'publicPath';\n\nfunction joinLines(lines: string[], linePrefix?: string): string {\n return lines\n .map((line: string) => {\n if (line) {\n return `${linePrefix || ''}${line}`;\n } else {\n return line;\n }\n })\n .join('\\n')\n .replace(/\\n\\n+/g, '\\n\\n');\n}\n\nexport function getSetPublicPathCode({\n regexName,\n regexVariable,\n preferLastFoundScript,\n webpackPublicPathVariable,\n getPostProcessScript,\n linePrefix\n}: IInternalOptions): string {\n let lines: string[] = [];\n lines = [`var scripts = document.getElementsByTagName('script');`];\n\n const regexInitializationSnippet: string = `/${regexName}/i`;\n const regexVarName: string | undefined = regexVariable;\n if (regexVariable) {\n lines.push(\n ...[\n `var regex = (typeof ${regexVarName} !== 'undefined') ? ${regexVarName} : ${regexInitializationSnippet};`\n ]\n );\n } else {\n lines.push(...[`var regex = ${regexInitializationSnippet};`]);\n }\n\n lines.push(\n ...[\n `var ${VAR_NAME};`,\n '',\n 'if (scripts && scripts.length) {',\n ' for (var i = 0; i < scripts.length; i++) {',\n ' if (!scripts[i]) continue;',\n ` var path = scripts[i].getAttribute('src');`,\n ' if (path && path.match(regex)) {',\n ` ${VAR_NAME} = path.substring(0, path.lastIndexOf('/') + 1);`,\n ...(preferLastFoundScript ? [] : [' break;']),\n ' }',\n ' }',\n '}',\n ''\n ]\n );\n\n if (getPostProcessScript) {\n lines.push(...['', `if (${VAR_NAME}) {`, ` ${getPostProcessScript(VAR_NAME)};`, '}', '']);\n }\n\n lines.push(`${webpackPublicPathVariable} = ${VAR_NAME};`);\n\n return joinLines(lines, linePrefix);\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.74",
|
|
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,15 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@rushstack/node-core-library": "5.
|
|
24
|
-
"@rushstack/webpack-plugin-utilities": "0.4.
|
|
23
|
+
"@rushstack/node-core-library": "5.12.0",
|
|
24
|
+
"@rushstack/webpack-plugin-utilities": "0.4.74"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"
|
|
27
|
+
"@types/node": "20.17.19",
|
|
28
28
|
"memfs": "4.12.0",
|
|
29
|
+
"webpack": "~5.98.0",
|
|
29
30
|
"local-node-rig": "1.0.0",
|
|
30
|
-
"@rushstack/heft": "0.
|
|
31
|
+
"@rushstack/heft": "0.70.0"
|
|
31
32
|
},
|
|
32
33
|
"scripts": {
|
|
33
34
|
"build": "heft build --clean",
|