@rushstack/set-webpack-public-path-plugin 3.3.115 → 4.0.1

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.
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.35.2"
8
+ "packageVersion": "7.35.3"
9
9
  }
10
10
  ]
11
11
  }
@@ -32,7 +32,7 @@ class SetPublicPathPlugin {
32
32
  apply(compiler) {
33
33
  // Casting here because VersionDetection refers to webpack 5 typings
34
34
  if (webpack_plugin_utilities_1.VersionDetection.isWebpack3OrEarlier(compiler)) {
35
- throw new Error(`The ${SetPublicPathPlugin.name} plugin requires Webpack 4 or Webpack 5`);
35
+ throw new Error(`The ${SetPublicPathPlugin.name} plugin requires Webpack 4`);
36
36
  }
37
37
  // Casting here because VersionDetection refers to webpack 5 typings
38
38
  const isWebpack4 = webpack_plugin_utilities_1.VersionDetection.isWebpack4(compiler);
@@ -60,10 +60,10 @@ class SetPublicPathPlugin {
60
60
  // Webpack 5 has its own automatic public path code, so only apply for Webpack 4
61
61
  const Webpack5Error = compiler
62
62
  .webpack.WebpackError;
63
- // Don't bother importing node-core-library for this
64
- const thisPackageJson = require('../package.json');
65
- compilation.warnings.push(new Webpack5Error(`Webpack 5 supports its own automatic public path detection, ` +
66
- `so ${thisPackageJson.name} won't do anything in this compilation.`));
63
+ const thisPackageJson = node_core_library_1.PackageJsonLookup.loadOwnPackageJson(__dirname);
64
+ compilation.errors.push(new Webpack5Error('Webpack 5 supports its own automatic public path detection, ' +
65
+ `so ${thisPackageJson.name} is unnecessary. Remove the ${SetPublicPathPlugin.name} plugin ` +
66
+ 'from the Webpack configuration.'));
67
67
  }
68
68
  });
69
69
  // Webpack 5 has its own automatic public path code, so only apply for Webpack 4
@@ -1 +1 @@
1
- {"version":3,"file":"SetPublicPathPlugin.js","sourceRoot":"","sources":["../src/SetPublicPathPlugin.ts"],"names":[],"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,EAAC,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC;YAClD,OAAO;YACP,EAAE;YACF,OAAO,CAAC,MAAM;SACf,CAAC,IAAI,CAAC,QAAG,CAAC,CAAC;IACd,CAAC;CACF;AA9JD,kDA8JC","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 { EOL } from 'os';\nimport { VersionDetection } from '@rushstack/webpack-plugin-utilities';\nimport { Text } from '@rushstack/node-core-library';\n\nimport type * as Webpack from 'webpack';\nimport type * as Tapable from 'tapable';\n// Workaround for https://github.com/pnpm/pnpm/issues/4301\nimport type * as Webpack5 from '@rushstack/heft-webpack5-plugin/node_modules/webpack';\n\nimport { IInternalOptions, getSetPublicPathCode } from './codeGenerator';\n\n/**\n * The base options for setting the webpack public path at runtime.\n *\n * @public\n */\nexport interface ISetWebpackPublicPathOptions {\n /**\n * Use the System.baseURL property if it is defined.\n */\n systemJs?: boolean;\n\n /**\n * Use the specified string as a URL prefix after the SystemJS path or the publicPath option.\n * If neither systemJs nor publicPath is defined, this option will not apply and an exception will be thrown.\n */\n urlPrefix?: string;\n\n /**\n * Use the specified path as the base public path.\n */\n publicPath?: string;\n\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 * If true, always include the public path-setting code. Don't try to detect if any chunks or assets are present.\n */\n skipDetection?: boolean;\n}\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?: {\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?: boolean;\n\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\ninterface IAsset {\n size(): number;\n source(): string;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\ndeclare const __dummyWebpack4MainTemplate: Webpack.compilation.MainTemplate;\ninterface IWebpack4ExtendedMainTemplate extends Webpack.compilation.MainTemplate {\n hooks: {\n startup: Tapable.SyncHook<string, Webpack.compilation.Chunk, string>;\n } & typeof __dummyWebpack4MainTemplate.hooks;\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.compilation.Chunk {\n [SHOULD_REPLACE_ASSET_NAME_TOKEN]: boolean;\n}\n\ninterface IStartupCodeOptions {\n source: string;\n chunk: IExtendedChunk;\n hash: string;\n requireFn: string;\n}\n\nconst PLUGIN_NAME: string = 'set-webpack-public-path';\n\nconst ASSET_NAME_TOKEN: string = '-ASSET-NAME-c0ef4f86-b570-44d3-b210-4428c5b7825c';\n\nconst ASSET_NAME_TOKEN_REGEX: RegExp = new RegExp(ASSET_NAME_TOKEN);\n\n/**\n * This simple plugin sets the __webpack_public_path__ variable to a value specified in the arguments,\n * optionally appended to the SystemJs baseURL property.\n *\n * @public\n */\nexport class SetPublicPathPlugin implements Webpack.Plugin {\n public options: ISetWebpackPublicPathPluginOptions;\n\n public constructor(options: ISetWebpackPublicPathPluginOptions) {\n this.options = options;\n\n if (options.scriptName) {\n if (options.scriptName.useAssetName && options.scriptName.name) {\n throw new Error('scriptName.userAssetName and scriptName.name must not be used together');\n } else if (options.scriptName.isTokenized && !options.scriptName.name) {\n throw new Error('scriptName.isTokenized is only valid if scriptName.name is set');\n }\n }\n }\n\n public apply(compiler: Webpack.Compiler): void {\n // Casting here because VersionDetection refers to webpack 5 typings\n if (VersionDetection.isWebpack3OrEarlier(compiler as unknown as Webpack5.Compiler)) {\n throw new Error(`The ${SetPublicPathPlugin.name} plugin requires Webpack 4 or Webpack 5`);\n }\n\n // Casting here because VersionDetection refers to webpack 5 typings\n const isWebpack4: boolean = VersionDetection.isWebpack4(compiler as unknown as Webpack5.Compiler);\n\n compiler.hooks.compilation.tap(\n PLUGIN_NAME,\n (compilation: Webpack.compilation.Compilation | Webpack5.Compilation) => {\n if (isWebpack4) {\n const webpack4Compilation: Webpack.compilation.Compilation =\n compilation as Webpack.compilation.Compilation;\n const mainTemplate: IWebpack4ExtendedMainTemplate =\n webpack4Compilation.mainTemplate as IWebpack4ExtendedMainTemplate;\n mainTemplate.hooks.startup.tap(\n PLUGIN_NAME,\n (source: string, chunk: Webpack.compilation.Chunk, hash: string) => {\n const extendedChunk: IExtendedChunk = chunk as IExtendedChunk;\n const assetOrChunkFound: boolean =\n !!this.options.skipDetection || this._detectAssetsOrChunks(extendedChunk);\n if (assetOrChunkFound) {\n return this._getStartupCode({\n source,\n chunk: extendedChunk,\n hash,\n requireFn: mainTemplate.requireFn\n });\n } else {\n return source;\n }\n }\n );\n } else {\n // Webpack 5 has its own automatic public path code, so only apply for Webpack 4\n const Webpack5Error: typeof Webpack5.WebpackError = (compiler as unknown as Webpack5.Compiler)\n .webpack.WebpackError;\n // Don't bother importing node-core-library for this\n const thisPackageJson: { name: string } = require('../package.json');\n compilation.warnings.push(\n new Webpack5Error(\n `Webpack 5 supports its own automatic public path detection, ` +\n `so ${thisPackageJson.name} won't do anything in this compilation.`\n )\n );\n }\n }\n );\n\n // Webpack 5 has its own automatic public path code, so only apply for Webpack 4\n if (isWebpack4) {\n compiler.hooks.emit.tap(\n PLUGIN_NAME,\n (compilation: Webpack.compilation.Compilation | Webpack5.Compilation) => {\n for (const chunkGroup of compilation.chunkGroups) {\n for (const chunk of chunkGroup.chunks) {\n if (chunk[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.substr(\n 0,\n assetFilename.length - 4 /* '.map'.length */\n );\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.substring(1, escapedAssetFilename.length - 1);\n } else {\n escapedAssetFilename = Text.escapeRegExp(assetFilename);\n }\n\n const asset: IAsset = compilation.assets[assetFilename];\n const originalAssetSource: string = asset.source();\n const originalAssetSize: number = asset.size();\n\n const newAssetSource: string = originalAssetSource.replace(\n ASSET_NAME_TOKEN_REGEX,\n escapedAssetFilename\n );\n const sizeDifference: number = assetFilename.length - ASSET_NAME_TOKEN.length;\n asset.source = () => newAssetSource;\n asset.size = () => originalAssetSize + sizeDifference;\n }\n }\n }\n }\n }\n );\n }\n }\n\n private _detectAssetsOrChunks(chunk: IExtendedChunk): boolean {\n for (const chunkGroup of chunk.groupsIterable) {\n if (chunkGroup.childrenIterable.size > 0) {\n return true;\n }\n }\n\n for (const innerModule of chunk.modulesIterable) {\n if (innerModule.buildInfo.assets && Object.keys(innerModule.buildInfo.assets).length > 0) {\n return true;\n }\n }\n\n return false;\n }\n\n private _getStartupCode(options: IStartupCodeOptions): string {\n const moduleOptions: IInternalOptions = { ...this.options };\n\n // If this module has ownership over any chunks or assets, inject the public path code\n moduleOptions.webpackPublicPathVariable = `${options.requireFn}.p`;\n moduleOptions.linePrefix = ' ';\n\n if (this.options.scriptName) {\n if (this.options.scriptName.name) {\n moduleOptions.regexName = this.options.scriptName.name;\n if (this.options.scriptName.isTokenized) {\n moduleOptions.regexName = moduleOptions.regexName\n .replace(/\\[name\\]/g, Text.escapeRegExp(options.chunk.name))\n .replace(/\\[hash\\]/g, options.chunk.renderedHash || '');\n }\n } else if (this.options.scriptName.useAssetName) {\n options.chunk[SHOULD_REPLACE_ASSET_NAME_TOKEN] = true;\n\n moduleOptions.regexName = ASSET_NAME_TOKEN;\n }\n }\n\n return [\n '// Set the webpack public path',\n '(function () {',\n getSetPublicPathCode(moduleOptions, console.error),\n '})();',\n '',\n options.source\n ].join(EOL);\n }\n}\n"]}
1
+ {"version":3,"file":"SetPublicPathPlugin.js","sourceRoot":"","sources":["../src/SetPublicPathPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2BAAyB;AACzB,kFAAuE;AACvE,oEAAqF;AAOrF,mDAAyE;AAkGzE,MAAM,+BAA+B,GAAkB,MAAM,CAC3D,kDAAkD,CACnD,CAAC;AAaF,MAAM,WAAW,GAAW,yBAAyB,CAAC;AAEtD,MAAM,gBAAgB,GAAW,kDAAkD,CAAC;AAEpF,MAAM,sBAAsB,GAAW,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEpE;;;;;GAKG;AACH,MAAa,mBAAmB;IAG9B,YAAmB,OAA2C;QAC5D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,IAAI,OAAO,CAAC,UAAU,CAAC,YAAY,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE;gBAC9D,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;aAC3F;iBAAM,IAAI,OAAO,CAAC,UAAU,CAAC,WAAW,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE;gBACrE,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;aACnF;SACF;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AO,CAAC,UAAU,CAAC,WAAW,EAAE;oBACvC,aAAa,CAAC,SAAS,GAAG,aAAa,CAAC,SAAS;yBAC9C,OAAO,CAAC,WAAW,EAAE,wBAAI,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;yBAC3D,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;iBAC3D;aACF;iBAAM,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,EAAE;gBAC/C,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,GAAG,IAAI,CAAC;gBAEtD,aAAa,CAAC,SAAS,GAAG,gBAAgB,CAAC;aAC5C;SACF;QAED,OAAO;YACL,gCAAgC;YAChC,gBAAgB;YAChB,IAAA,oCAAoB,EAAC,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC;YAClD,OAAO;YACP,EAAE;YACF,OAAO,CAAC,MAAM;SACf,CAAC,IAAI,CAAC,QAAG,CAAC,CAAC;IACd,CAAC;CACF;AA9JD,kDA8JC","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 { EOL } from 'os';\nimport { VersionDetection } from '@rushstack/webpack-plugin-utilities';\nimport { Text, PackageJsonLookup, IPackageJson } from '@rushstack/node-core-library';\n\nimport type * as Webpack from 'webpack';\nimport type * as Tapable from 'tapable';\n// Workaround for https://github.com/pnpm/pnpm/issues/4301\nimport type * as Webpack5 from '@rushstack/heft-webpack5-plugin/node_modules/webpack';\n\nimport { IInternalOptions, getSetPublicPathCode } from './codeGenerator';\n\n/**\n * The base options for setting the webpack public path at runtime.\n *\n * @public\n */\nexport interface ISetWebpackPublicPathOptions {\n /**\n * Use the System.baseURL property if it is defined.\n */\n systemJs?: boolean;\n\n /**\n * Use the specified string as a URL prefix after the SystemJS path or the publicPath option.\n * If neither systemJs nor publicPath is defined, this option will not apply and an exception will be thrown.\n */\n urlPrefix?: string;\n\n /**\n * Use the specified path as the base public path.\n */\n publicPath?: string;\n\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 * If true, always include the public path-setting code. Don't try to detect if any chunks or assets are present.\n */\n skipDetection?: boolean;\n}\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?: {\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?: boolean;\n\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\ninterface IAsset {\n size(): number;\n source(): string;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\ndeclare const __dummyWebpack4MainTemplate: Webpack.compilation.MainTemplate;\ninterface IWebpack4ExtendedMainTemplate extends Webpack.compilation.MainTemplate {\n hooks: {\n startup: Tapable.SyncHook<string, Webpack.compilation.Chunk, string>;\n } & typeof __dummyWebpack4MainTemplate.hooks;\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.compilation.Chunk {\n [SHOULD_REPLACE_ASSET_NAME_TOKEN]: boolean;\n}\n\ninterface IStartupCodeOptions {\n source: string;\n chunk: IExtendedChunk;\n hash: string;\n requireFn: string;\n}\n\nconst PLUGIN_NAME: string = 'set-webpack-public-path';\n\nconst ASSET_NAME_TOKEN: string = '-ASSET-NAME-c0ef4f86-b570-44d3-b210-4428c5b7825c';\n\nconst ASSET_NAME_TOKEN_REGEX: RegExp = new RegExp(ASSET_NAME_TOKEN);\n\n/**\n * This simple plugin sets the __webpack_public_path__ variable to a value specified in the arguments,\n * optionally appended to the SystemJs baseURL property.\n *\n * @public\n */\nexport class SetPublicPathPlugin implements Webpack.Plugin {\n public options: ISetWebpackPublicPathPluginOptions;\n\n public constructor(options: ISetWebpackPublicPathPluginOptions) {\n this.options = options;\n\n if (options.scriptName) {\n if (options.scriptName.useAssetName && options.scriptName.name) {\n throw new Error('scriptName.userAssetName and scriptName.name must not be used together');\n } else if (options.scriptName.isTokenized && !options.scriptName.name) {\n throw new Error('scriptName.isTokenized is only valid if scriptName.name is set');\n }\n }\n }\n\n public apply(compiler: Webpack.Compiler): void {\n // Casting here because VersionDetection refers to webpack 5 typings\n if (VersionDetection.isWebpack3OrEarlier(compiler as unknown as Webpack5.Compiler)) {\n throw new Error(`The ${SetPublicPathPlugin.name} plugin requires Webpack 4`);\n }\n\n // Casting here because VersionDetection refers to webpack 5 typings\n const isWebpack4: boolean = VersionDetection.isWebpack4(compiler as unknown as Webpack5.Compiler);\n\n compiler.hooks.compilation.tap(\n PLUGIN_NAME,\n (compilation: Webpack.compilation.Compilation | Webpack5.Compilation) => {\n if (isWebpack4) {\n const webpack4Compilation: Webpack.compilation.Compilation =\n compilation as Webpack.compilation.Compilation;\n const mainTemplate: IWebpack4ExtendedMainTemplate =\n webpack4Compilation.mainTemplate as IWebpack4ExtendedMainTemplate;\n mainTemplate.hooks.startup.tap(\n PLUGIN_NAME,\n (source: string, chunk: Webpack.compilation.Chunk, hash: string) => {\n const extendedChunk: IExtendedChunk = chunk as IExtendedChunk;\n const assetOrChunkFound: boolean =\n !!this.options.skipDetection || this._detectAssetsOrChunks(extendedChunk);\n if (assetOrChunkFound) {\n return this._getStartupCode({\n source,\n chunk: extendedChunk,\n hash,\n requireFn: mainTemplate.requireFn\n });\n } else {\n return source;\n }\n }\n );\n } else {\n // Webpack 5 has its own automatic public path code, so only apply for Webpack 4\n const Webpack5Error: typeof Webpack5.WebpackError = (compiler as unknown as Webpack5.Compiler)\n .webpack.WebpackError;\n const thisPackageJson: IPackageJson = PackageJsonLookup.loadOwnPackageJson(__dirname);\n compilation.errors.push(\n new Webpack5Error(\n 'Webpack 5 supports its own automatic public path detection, ' +\n `so ${thisPackageJson.name} is unnecessary. Remove the ${SetPublicPathPlugin.name} plugin ` +\n 'from the Webpack configuration.'\n )\n );\n }\n }\n );\n\n // Webpack 5 has its own automatic public path code, so only apply for Webpack 4\n if (isWebpack4) {\n compiler.hooks.emit.tap(\n PLUGIN_NAME,\n (compilation: Webpack.compilation.Compilation | Webpack5.Compilation) => {\n for (const chunkGroup of compilation.chunkGroups) {\n for (const chunk of chunkGroup.chunks) {\n if (chunk[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.substr(\n 0,\n assetFilename.length - 4 /* '.map'.length */\n );\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.substring(1, escapedAssetFilename.length - 1);\n } else {\n escapedAssetFilename = Text.escapeRegExp(assetFilename);\n }\n\n const asset: IAsset = compilation.assets[assetFilename];\n const originalAssetSource: string = asset.source();\n const originalAssetSize: number = asset.size();\n\n const newAssetSource: string = originalAssetSource.replace(\n ASSET_NAME_TOKEN_REGEX,\n escapedAssetFilename\n );\n const sizeDifference: number = assetFilename.length - ASSET_NAME_TOKEN.length;\n asset.source = () => newAssetSource;\n asset.size = () => originalAssetSize + sizeDifference;\n }\n }\n }\n }\n }\n );\n }\n }\n\n private _detectAssetsOrChunks(chunk: IExtendedChunk): boolean {\n for (const chunkGroup of chunk.groupsIterable) {\n if (chunkGroup.childrenIterable.size > 0) {\n return true;\n }\n }\n\n for (const innerModule of chunk.modulesIterable) {\n if (innerModule.buildInfo.assets && Object.keys(innerModule.buildInfo.assets).length > 0) {\n return true;\n }\n }\n\n return false;\n }\n\n private _getStartupCode(options: IStartupCodeOptions): string {\n const moduleOptions: IInternalOptions = { ...this.options };\n\n // If this module has ownership over any chunks or assets, inject the public path code\n moduleOptions.webpackPublicPathVariable = `${options.requireFn}.p`;\n moduleOptions.linePrefix = ' ';\n\n if (this.options.scriptName) {\n if (this.options.scriptName.name) {\n moduleOptions.regexName = this.options.scriptName.name;\n if (this.options.scriptName.isTokenized) {\n moduleOptions.regexName = moduleOptions.regexName\n .replace(/\\[name\\]/g, Text.escapeRegExp(options.chunk.name))\n .replace(/\\[hash\\]/g, options.chunk.renderedHash || '');\n }\n } else if (this.options.scriptName.useAssetName) {\n options.chunk[SHOULD_REPLACE_ASSET_NAME_TOKEN] = true;\n\n moduleOptions.regexName = ASSET_NAME_TOKEN;\n }\n }\n\n return [\n '// Set the webpack public path',\n '(function () {',\n getSetPublicPathCode(moduleOptions, console.error),\n '})();',\n '',\n options.source\n ].join(EOL);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/set-webpack-public-path-plugin",
3
- "version": "3.3.115",
3
+ "version": "4.0.1",
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",
@@ -11,20 +11,16 @@
11
11
  "directory": "webpack/set-webpack-public-path-plugin"
12
12
  },
13
13
  "peerDependencies": {
14
- "@types/webpack": "^4.39.8",
15
- "webpack": "^5.35.1"
14
+ "@types/webpack": "^4.39.8"
16
15
  },
17
16
  "peerDependenciesMeta": {
18
17
  "@types/webpack": {
19
18
  "optional": true
20
- },
21
- "webpack": {
22
- "optional": true
23
19
  }
24
20
  },
25
21
  "dependencies": {
26
22
  "@rushstack/node-core-library": "3.59.3",
27
- "@rushstack/webpack-plugin-utilities": "0.2.20"
23
+ "@rushstack/webpack-plugin-utilities": "0.2.22"
28
24
  },
29
25
  "devDependencies": {
30
26
  "@types/heft-jest": "1.0.1",
@@ -32,9 +28,9 @@
32
28
  "@types/tapable": "1.0.6",
33
29
  "@types/webpack": "4.41.32",
34
30
  "@rushstack/eslint-config": "3.3.1",
35
- "@rushstack/heft": "0.53.1",
36
- "@rushstack/heft-node-rig": "2.2.5",
37
- "@rushstack/heft-webpack5-plugin": "0.7.8"
31
+ "@rushstack/heft": "0.55.0",
32
+ "@rushstack/heft-node-rig": "2.2.7",
33
+ "@rushstack/heft-webpack5-plugin": "0.7.10"
38
34
  },
39
35
  "scripts": {
40
36
  "build": "heft build --clean",