@rushstack/set-webpack-public-path-plugin 3.3.0 → 3.3.4

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 CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "@rushstack/set-webpack-public-path-plugin",
3
3
  "entries": [
4
+ {
5
+ "version": "3.3.4",
6
+ "tag": "@rushstack/set-webpack-public-path-plugin_v3.3.4",
7
+ "date": "Fri, 03 Dec 2021 03:05:22 GMT",
8
+ "comments": {
9
+ "dependency": [
10
+ {
11
+ "comment": "Updating dependency \"@rushstack/heft\" to `0.42.4`"
12
+ },
13
+ {
14
+ "comment": "Updating dependency \"@rushstack/heft-node-rig\" to `1.2.33`"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "version": "3.3.3",
21
+ "tag": "@rushstack/set-webpack-public-path-plugin_v3.3.3",
22
+ "date": "Tue, 30 Nov 2021 20:18:41 GMT",
23
+ "comments": {
24
+ "dependency": [
25
+ {
26
+ "comment": "Updating dependency \"@rushstack/heft-node-rig\" to `1.2.32`"
27
+ }
28
+ ]
29
+ }
30
+ },
31
+ {
32
+ "version": "3.3.2",
33
+ "tag": "@rushstack/set-webpack-public-path-plugin_v3.3.2",
34
+ "date": "Mon, 29 Nov 2021 07:26:16 GMT",
35
+ "comments": {
36
+ "dependency": [
37
+ {
38
+ "comment": "Updating dependency \"@rushstack/heft\" to `0.42.3`"
39
+ },
40
+ {
41
+ "comment": "Updating dependency \"@rushstack/heft-node-rig\" to `1.2.31`"
42
+ }
43
+ ]
44
+ }
45
+ },
46
+ {
47
+ "version": "3.3.1",
48
+ "tag": "@rushstack/set-webpack-public-path-plugin_v3.3.1",
49
+ "date": "Thu, 11 Nov 2021 01:17:02 GMT",
50
+ "comments": {
51
+ "patch": [
52
+ {
53
+ "comment": "Update typings to only import from \"webpack.\""
54
+ }
55
+ ]
56
+ }
57
+ },
4
58
  {
5
59
  "version": "3.3.0",
6
60
  "tag": "@rushstack/set-webpack-public-path-plugin_v3.3.0",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,28 @@
1
1
  # Change Log - @rushstack/set-webpack-public-path-plugin
2
2
 
3
- This log was last generated on Wed, 10 Nov 2021 16:09:47 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 03 Dec 2021 03:05:22 GMT and should not be manually modified.
4
+
5
+ ## 3.3.4
6
+ Fri, 03 Dec 2021 03:05:22 GMT
7
+
8
+ _Version update only_
9
+
10
+ ## 3.3.3
11
+ Tue, 30 Nov 2021 20:18:41 GMT
12
+
13
+ _Version update only_
14
+
15
+ ## 3.3.2
16
+ Mon, 29 Nov 2021 07:26:16 GMT
17
+
18
+ _Version update only_
19
+
20
+ ## 3.3.1
21
+ Thu, 11 Nov 2021 01:17:02 GMT
22
+
23
+ ### Patches
24
+
25
+ - Update typings to only import from "webpack."
4
26
 
5
27
  ## 3.3.0
6
28
  Wed, 10 Nov 2021 16:09:47 GMT
@@ -0,0 +1,114 @@
1
+ /**
2
+ * This simple plugin sets the `__webpack_public_path__` variable to
3
+ * a value specified in the arguments, optionally appended to the SystemJs baseURL
4
+ * property.
5
+ * @packageDocumentation
6
+ */
7
+
8
+ import type * as Webpack from 'webpack';
9
+
10
+ /**
11
+ * /**
12
+ * This function returns a block of JavaScript that maintains a global register of script tags.
13
+ *
14
+ * @param debug - If true, the code returned code is not minified. Defaults to false.
15
+ *
16
+ * @public
17
+ */
18
+ export declare function getGlobalRegisterCode(debug?: boolean): string;
19
+
20
+ /**
21
+ * The base options for setting the webpack public path at runtime.
22
+ *
23
+ * @public
24
+ */
25
+ export declare interface ISetWebpackPublicPathOptions {
26
+ /**
27
+ * Use the System.baseURL property if it is defined.
28
+ */
29
+ systemJs?: boolean;
30
+ /**
31
+ * Use the specified string as a URL prefix after the SystemJS path or the publicPath option.
32
+ * If neither systemJs nor publicPath is defined, this option will not apply and an exception will be thrown.
33
+ */
34
+ urlPrefix?: string;
35
+ /**
36
+ * Use the specified path as the base public path.
37
+ */
38
+ publicPath?: string;
39
+ /**
40
+ * Check for a variable with this name on the page and use its value as a regular expression against script paths to
41
+ * the bundle's script. If a value foo is passed into regexVariable, the produced bundle will look for a variable
42
+ * called foo during initialization, and if a foo variable is found, use its value as a regular expression to detect
43
+ * the bundle's script.
44
+ *
45
+ * See the README for more information.
46
+ */
47
+ regexVariable?: string;
48
+ /**
49
+ * A function that returns a snippet of code that manipulates the variable with the name that's specified in the
50
+ * parameter. If this parameter isn't provided, no post-processing code is included. The variable must be modified
51
+ * in-place - the processed value should not be returned.
52
+ *
53
+ * See the README for more information.
54
+ */
55
+ getPostProcessScript?: (varName: string) => string;
56
+ /**
57
+ * If true, find the last script matching the regexVariable (if it is set). If false, find the first matching script.
58
+ * This can be useful if there are multiple scripts loaded in the DOM that match the regexVariable.
59
+ */
60
+ preferLastFoundScript?: boolean;
61
+ /**
62
+ * If true, always include the public path-setting code. Don't try to detect if any chunks or assets are present.
63
+ */
64
+ skipDetection?: boolean;
65
+ }
66
+
67
+ /**
68
+ * Options for the set-webpack-public-path plugin.
69
+ *
70
+ * @public
71
+ */
72
+ export declare interface ISetWebpackPublicPathPluginOptions extends ISetWebpackPublicPathOptions {
73
+ /**
74
+ * An object that describes how the public path should be discovered.
75
+ */
76
+ scriptName?: {
77
+ /**
78
+ * If set to true, use the webpack generated asset's name. This option is not compatible with
79
+ * andy other scriptName options.
80
+ */
81
+ useAssetName?: boolean;
82
+ /**
83
+ * A regular expression expressed as a string to be applied to all script paths on the page.
84
+ */
85
+ name?: string;
86
+ /**
87
+ * If true, the name property is tokenized.
88
+ *
89
+ * See the README for more information.
90
+ */
91
+ isTokenized?: boolean;
92
+ };
93
+ }
94
+
95
+ /**
96
+ * @public
97
+ */
98
+ export declare const registryVariableName: string;
99
+
100
+ /**
101
+ * This simple plugin sets the __webpack_public_path__ variable to a value specified in the arguments,
102
+ * optionally appended to the SystemJs baseURL property.
103
+ *
104
+ * @public
105
+ */
106
+ export declare class SetPublicPathPlugin implements Webpack.Plugin {
107
+ options: ISetWebpackPublicPathPluginOptions;
108
+ constructor(options: ISetWebpackPublicPathPluginOptions);
109
+ apply(compiler: Webpack.Compiler): void;
110
+ private _detectAssetsOrChunks;
111
+ private _getStartupCode;
112
+ }
113
+
114
+ export { }
File without changes
@@ -1,5 +1,4 @@
1
- import type * as Webpack4 from 'webpack4';
2
- import type * as Webpack5 from 'webpack5';
1
+ import type * as Webpack from 'webpack';
3
2
  /**
4
3
  * The base options for setting the webpack public path at runtime.
5
4
  *
@@ -79,10 +78,10 @@ export interface ISetWebpackPublicPathPluginOptions extends ISetWebpackPublicPat
79
78
  *
80
79
  * @public
81
80
  */
82
- export declare class SetPublicPathPlugin implements Webpack4.Plugin {
81
+ export declare class SetPublicPathPlugin implements Webpack.Plugin {
83
82
  options: ISetWebpackPublicPathPluginOptions;
84
83
  constructor(options: ISetWebpackPublicPathPluginOptions);
85
- apply(compiler: Webpack4.Compiler | Webpack5.Compiler): void;
84
+ apply(compiler: Webpack.Compiler): void;
86
85
  private _detectAssetsOrChunks;
87
86
  private _getStartupCode;
88
87
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SetPublicPathPlugin.d.ts","sourceRoot":"","sources":["../src/SetPublicPathPlugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,QAAQ,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,KAAK,QAAQ,MAAM,UAAU,CAAC;AAK1C;;;;GAIG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;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;;;GAIG;AACH,MAAM,WAAW,kCAAmC,SAAQ,4BAA4B;IACtF;;OAEG;IACH,UAAU,CAAC,EAAE;QACX;;;WAGG;QACH,YAAY,CAAC,EAAE,OAAO,CAAC;QAEvB;;WAEG;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;QAEd;;;;WAIG;QACH,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,CAAC;CACH;AAwCD;;;;;GAKG;AACH,qBAAa,mBAAoB,YAAW,OAAO,CAAC,MAAM;IACjD,OAAO,EAAE,kCAAkC,CAAC;gBAEhC,OAAO,EAAE,kCAAkC;IAYvD,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI;IAqG9C,OAAO,CAAC,qBAAqB;IAgB7B,OAAO,CAAC,eAAe;CA+BxB"}
@@ -4,12 +4,14 @@
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.SetPublicPathPlugin = void 0;
6
6
  const os_1 = require("os");
7
- const lodash_1 = require("lodash");
8
7
  const codeGenerator_1 = require("./codeGenerator");
9
8
  const SHOULD_REPLACE_ASSET_NAME_TOKEN = Symbol('set-public-path-plugin-should-replace-asset-name');
10
9
  const PLUGIN_NAME = 'set-webpack-public-path';
11
10
  const ASSET_NAME_TOKEN = '-ASSET-NAME-c0ef4f86-b570-44d3-b210-4428c5b7825c';
12
11
  const ASSET_NAME_TOKEN_REGEX = new RegExp(ASSET_NAME_TOKEN);
12
+ function escapeRegExp(str) {
13
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
14
+ }
13
15
  /**
14
16
  * This simple plugin sets the __webpack_public_path__ variable to a value specified in the arguments,
15
17
  * optionally appended to the SystemJs baseURL property.
@@ -34,8 +36,7 @@ class SetPublicPathPlugin {
34
36
  if (isWebpack3OrEarlier) {
35
37
  throw new Error(`The ${SetPublicPathPlugin.name} plugin requires Webpack 4 or Webpack 5`);
36
38
  }
37
- const webpackVersion = (_a = compiler
38
- .webpack) === null || _a === void 0 ? void 0 : _a.version;
39
+ const webpackVersion = (_a = compiler.webpack) === null || _a === void 0 ? void 0 : _a.version;
39
40
  const webpackMajorVersion = webpackVersion
40
41
  ? Number(webpackVersion.substr(0, webpackVersion.indexOf('.')))
41
42
  : 4;
@@ -61,8 +62,8 @@ class SetPublicPathPlugin {
61
62
  }
62
63
  else {
63
64
  // Webpack 5 has its own automatic public path code, so only apply for Webpack 4
64
- const Webpack5Error = compiler.webpack
65
- .WebpackError;
65
+ const Webpack5Error = compiler
66
+ .webpack.WebpackError;
66
67
  // Don't bother importing node-core-library for this
67
68
  const thisPackageJson = require('../package.json');
68
69
  compilation.warnings.push(new Webpack5Error(`Webpack 5 supports its own automatic public path detection, ` +
@@ -80,14 +81,14 @@ class SetPublicPathPlugin {
80
81
  if (assetFilename.match(/\.map$/)) {
81
82
  // Trim the ".map" extension
82
83
  escapedAssetFilename = assetFilename.substr(0, assetFilename.length - 4 /* '.map'.length */);
83
- escapedAssetFilename = (0, lodash_1.escapeRegExp)(escapedAssetFilename);
84
+ escapedAssetFilename = escapeRegExp(escapedAssetFilename);
84
85
  // source in sourcemaps is JSON-encoded
85
86
  escapedAssetFilename = JSON.stringify(escapedAssetFilename);
86
87
  // Trim the quotes from the JSON encoding
87
88
  escapedAssetFilename = escapedAssetFilename.substring(1, escapedAssetFilename.length - 1);
88
89
  }
89
90
  else {
90
- escapedAssetFilename = (0, lodash_1.escapeRegExp)(assetFilename);
91
+ escapedAssetFilename = escapeRegExp(assetFilename);
91
92
  }
92
93
  const asset = compilation.assets[assetFilename];
93
94
  const originalAssetSource = asset.source();
@@ -117,7 +118,7 @@ class SetPublicPathPlugin {
117
118
  return false;
118
119
  }
119
120
  _getStartupCode(options) {
120
- const moduleOptions = (0, lodash_1.cloneDeep)(this.options);
121
+ const moduleOptions = Object.assign({}, this.options);
121
122
  // If this module has ownership over any chunks or assets, inject the public path code
122
123
  moduleOptions.webpackPublicPathVariable = `${options.requireFn}.p`;
123
124
  moduleOptions.linePrefix = ' ';
@@ -126,7 +127,7 @@ class SetPublicPathPlugin {
126
127
  moduleOptions.regexName = this.options.scriptName.name;
127
128
  if (this.options.scriptName.isTokenized) {
128
129
  moduleOptions.regexName = moduleOptions.regexName
129
- .replace(/\[name\]/g, (0, lodash_1.escapeRegExp)(options.chunk.name))
130
+ .replace(/\[name\]/g, escapeRegExp(options.chunk.name))
130
131
  .replace(/\[hash\]/g, options.chunk.renderedHash || '');
131
132
  }
132
133
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SetPublicPathPlugin.js","sourceRoot":"","sources":["../src/SetPublicPathPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2BAAyB;AACzB,mCAAiD;AAKjD,mDAAyE;AAqGzE,MAAM,+BAA+B,GAAkB,MAAM,CAC3D,kDAAkD,CACnD,CAAC;AAcF,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;IACH,CAAC;IAEM,KAAK,CAAC,QAA+C;;QAC1D,MAAM,mBAAmB,GAAY,CAAC,QAAQ,CAAC,KAAK,CAAC;QAErD,IAAI,mBAAmB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CAAC,UAAU,CAAC,IAAI,CAAC;gBACvD,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE;oBACvC,aAAa,CAAC,SAAS,GAAG,aAAa,CAAC,SAAS;yBAC9C,OAAO,CAAC,WAAW,EAAE,IAAA,qBAAY,EAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;yBACtD,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;AAlKD,kDAkKC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport { EOL } from 'os';\r\nimport { cloneDeep, escapeRegExp } from 'lodash';\r\nimport type * as Webpack4 from 'webpack4';\r\nimport type * as Webpack5 from 'webpack5';\r\nimport type * as Tapable from 'tapable';\r\n\r\nimport { IInternalOptions, getSetPublicPathCode } from './codeGenerator';\r\n\r\n/**\r\n * The base options for setting the webpack public path at runtime.\r\n *\r\n * @public\r\n */\r\nexport interface ISetWebpackPublicPathOptions {\r\n /**\r\n * Use the System.baseURL property if it is defined.\r\n */\r\n systemJs?: boolean;\r\n\r\n /**\r\n * Use the specified string as a URL prefix after the SystemJS path or the publicPath option.\r\n * If neither systemJs nor publicPath is defined, this option will not apply and an exception will be thrown.\r\n */\r\n urlPrefix?: string;\r\n\r\n /**\r\n * Use the specified path as the base public path.\r\n */\r\n publicPath?: string;\r\n\r\n /**\r\n * Check for a variable with this name on the page and use its value as a regular expression against script paths to\r\n * the bundle's script. If a value foo is passed into regexVariable, the produced bundle will look for a variable\r\n * called foo during initialization, and if a foo variable is found, use its value as a regular expression to detect\r\n * the bundle's script.\r\n *\r\n * See the README for more information.\r\n */\r\n regexVariable?: string;\r\n\r\n /**\r\n * A function that returns a snippet of code that manipulates the variable with the name that's specified in the\r\n * parameter. If this parameter isn't provided, no post-processing code is included. The variable must be modified\r\n * in-place - the processed value should not be returned.\r\n *\r\n * See the README for more information.\r\n */\r\n getPostProcessScript?: (varName: string) => string;\r\n\r\n /**\r\n * If true, find the last script matching the regexVariable (if it is set). If false, find the first matching script.\r\n * This can be useful if there are multiple scripts loaded in the DOM that match the regexVariable.\r\n */\r\n preferLastFoundScript?: boolean;\r\n\r\n /**\r\n * If true, always include the public path-setting code. Don't try to detect if any chunks or assets are present.\r\n */\r\n skipDetection?: boolean;\r\n}\r\n\r\n/**\r\n * Options for the set-webpack-public-path plugin.\r\n *\r\n * @public\r\n */\r\nexport interface ISetWebpackPublicPathPluginOptions extends ISetWebpackPublicPathOptions {\r\n /**\r\n * An object that describes how the public path should be discovered.\r\n */\r\n scriptName?: {\r\n /**\r\n * If set to true, use the webpack generated asset's name. This option is not compatible with\r\n * andy other scriptName options.\r\n */\r\n useAssetName?: boolean;\r\n\r\n /**\r\n * A regular expression expressed as a string to be applied to all script paths on the page.\r\n */\r\n name?: string;\r\n\r\n /**\r\n * If true, the name property is tokenized.\r\n *\r\n * See the README for more information.\r\n */\r\n isTokenized?: boolean;\r\n };\r\n}\r\n\r\ninterface IAsset {\r\n size(): number;\r\n source(): string;\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare const __dummyWebpack4MainTemplate: Webpack4.compilation.MainTemplate;\r\ninterface IWebpack4ExtendedMainTemplate extends Webpack4.compilation.MainTemplate {\r\n hooks: {\r\n jsonpScript?: Tapable.SyncWaterfallHook<string, Webpack4.compilation.Chunk, string>;\r\n requireExtensions: Tapable.SyncWaterfallHook<string, Webpack4.compilation.Chunk, string>;\r\n startup: Tapable.SyncHook<string, Webpack4.compilation.Chunk, string>;\r\n } & typeof __dummyWebpack4MainTemplate.hooks;\r\n requireFn: string;\r\n}\r\n\r\nconst SHOULD_REPLACE_ASSET_NAME_TOKEN: unique symbol = Symbol(\r\n 'set-public-path-plugin-should-replace-asset-name'\r\n);\r\n\r\ninterface IExtendedChunk extends Webpack4.compilation.Chunk {\r\n [SHOULD_REPLACE_ASSET_NAME_TOKEN]: boolean;\r\n forEachModule(callback: (module: Webpack4.compilation.Module) => void): void;\r\n}\r\n\r\ninterface IStartupCodeOptions {\r\n source: string;\r\n chunk: IExtendedChunk;\r\n hash: string;\r\n requireFn: string;\r\n}\r\n\r\nconst PLUGIN_NAME: string = 'set-webpack-public-path';\r\n\r\nconst ASSET_NAME_TOKEN: string = '-ASSET-NAME-c0ef4f86-b570-44d3-b210-4428c5b7825c';\r\n\r\nconst ASSET_NAME_TOKEN_REGEX: RegExp = new RegExp(ASSET_NAME_TOKEN);\r\n\r\n/**\r\n * This simple plugin sets the __webpack_public_path__ variable to a value specified in the arguments,\r\n * optionally appended to the SystemJs baseURL property.\r\n *\r\n * @public\r\n */\r\nexport class SetPublicPathPlugin implements Webpack4.Plugin {\r\n public options: ISetWebpackPublicPathPluginOptions;\r\n\r\n public constructor(options: ISetWebpackPublicPathPluginOptions) {\r\n this.options = options;\r\n\r\n if (options.scriptName) {\r\n if (options.scriptName.useAssetName && options.scriptName.name) {\r\n throw new Error('scriptName.userAssetName and scriptName.name must not be used together');\r\n } else if (options.scriptName.isTokenized && !options.scriptName.name) {\r\n throw new Error('scriptName.isTokenized is only valid if scriptName.name is set');\r\n }\r\n }\r\n }\r\n\r\n public apply(compiler: Webpack4.Compiler | Webpack5.Compiler): void {\r\n const isWebpack3OrEarlier: boolean = !compiler.hooks;\r\n\r\n if (isWebpack3OrEarlier) {\r\n throw new Error(`The ${SetPublicPathPlugin.name} plugin requires Webpack 4 or Webpack 5`);\r\n }\r\n\r\n const webpackVersion: string | undefined = (compiler as Webpack5.Compiler | { webpack: undefined })\r\n .webpack?.version;\r\n const webpackMajorVersion: number = webpackVersion\r\n ? Number(webpackVersion.substr(0, webpackVersion.indexOf('.')))\r\n : 4;\r\n\r\n compiler.hooks.compilation.tap(\r\n PLUGIN_NAME,\r\n (compilation: Webpack4.compilation.Compilation | Webpack5.Compilation) => {\r\n if (webpackMajorVersion === 4) {\r\n const webpack4Compilation: Webpack4.compilation.Compilation =\r\n compilation as Webpack4.compilation.Compilation;\r\n const mainTemplate: IWebpack4ExtendedMainTemplate =\r\n webpack4Compilation.mainTemplate as IWebpack4ExtendedMainTemplate;\r\n mainTemplate.hooks.startup.tap(\r\n PLUGIN_NAME,\r\n (source: string, chunk: Webpack4.compilation.Chunk, hash: string) => {\r\n const extendedChunk: IExtendedChunk = chunk as IExtendedChunk;\r\n const assetOrChunkFound: boolean =\r\n !!this.options.skipDetection || this._detectAssetsOrChunks(extendedChunk);\r\n if (assetOrChunkFound) {\r\n return this._getStartupCode({\r\n source,\r\n chunk: extendedChunk,\r\n hash,\r\n requireFn: mainTemplate.requireFn\r\n });\r\n } else {\r\n return source;\r\n }\r\n }\r\n );\r\n } else {\r\n // Webpack 5 has its own automatic public path code, so only apply for Webpack 4\r\n const Webpack5Error: typeof Webpack5.WebpackError = (compiler as Webpack5.Compiler).webpack\r\n .WebpackError;\r\n // Don't bother importing node-core-library for this\r\n const thisPackageJson: { name: string } = require('../package.json');\r\n compilation.warnings.push(\r\n new Webpack5Error(\r\n `Webpack 5 supports its own automatic public path detection, ` +\r\n `so ${thisPackageJson.name} won't do anything in this compilation.`\r\n )\r\n );\r\n }\r\n }\r\n );\r\n\r\n // Webpack 5 has its own automatic public path code, so only apply for Webpack 4\r\n if (webpackMajorVersion === 4) {\r\n compiler.hooks.emit.tap(\r\n PLUGIN_NAME,\r\n (compilation: Webpack4.compilation.Compilation | Webpack5.Compilation) => {\r\n for (const chunkGroup of compilation.chunkGroups) {\r\n for (const chunk of chunkGroup.chunks) {\r\n if (chunk[SHOULD_REPLACE_ASSET_NAME_TOKEN]) {\r\n for (const assetFilename of chunk.files) {\r\n let escapedAssetFilename: string;\r\n if (assetFilename.match(/\\.map$/)) {\r\n // Trim the \".map\" extension\r\n escapedAssetFilename = assetFilename.substr(\r\n 0,\r\n assetFilename.length - 4 /* '.map'.length */\r\n );\r\n escapedAssetFilename = escapeRegExp(escapedAssetFilename);\r\n // source in sourcemaps is JSON-encoded\r\n escapedAssetFilename = JSON.stringify(escapedAssetFilename);\r\n // Trim the quotes from the JSON encoding\r\n escapedAssetFilename = escapedAssetFilename.substring(1, escapedAssetFilename.length - 1);\r\n } else {\r\n escapedAssetFilename = escapeRegExp(assetFilename);\r\n }\r\n\r\n const asset: IAsset = compilation.assets[assetFilename];\r\n const originalAssetSource: string = asset.source();\r\n const originalAssetSize: number = asset.size();\r\n\r\n const newAssetSource: string = originalAssetSource.replace(\r\n ASSET_NAME_TOKEN_REGEX,\r\n escapedAssetFilename\r\n );\r\n const sizeDifference: number = assetFilename.length - ASSET_NAME_TOKEN.length;\r\n asset.source = () => newAssetSource;\r\n asset.size = () => originalAssetSize + sizeDifference;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n );\r\n }\r\n }\r\n\r\n private _detectAssetsOrChunks(chunk: IExtendedChunk): boolean {\r\n for (const chunkGroup of chunk.groupsIterable) {\r\n if (chunkGroup.childrenIterable.size > 0) {\r\n return true;\r\n }\r\n }\r\n\r\n for (const innerModule of chunk.modulesIterable) {\r\n if (innerModule.buildInfo.assets && Object.keys(innerModule.buildInfo.assets).length > 0) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n private _getStartupCode(options: IStartupCodeOptions): string {\r\n const moduleOptions: IInternalOptions = cloneDeep(this.options);\r\n\r\n // If this module has ownership over any chunks or assets, inject the public path code\r\n moduleOptions.webpackPublicPathVariable = `${options.requireFn}.p`;\r\n moduleOptions.linePrefix = ' ';\r\n\r\n if (this.options.scriptName) {\r\n if (this.options.scriptName.name) {\r\n moduleOptions.regexName = this.options.scriptName.name;\r\n if (this.options.scriptName.isTokenized) {\r\n moduleOptions.regexName = moduleOptions.regexName\r\n .replace(/\\[name\\]/g, escapeRegExp(options.chunk.name))\r\n .replace(/\\[hash\\]/g, options.chunk.renderedHash || '');\r\n }\r\n } else if (this.options.scriptName.useAssetName) {\r\n options.chunk[SHOULD_REPLACE_ASSET_NAME_TOKEN] = true;\r\n\r\n moduleOptions.regexName = ASSET_NAME_TOKEN;\r\n }\r\n }\r\n\r\n return [\r\n '// Set the webpack public path',\r\n '(function () {',\r\n getSetPublicPathCode(moduleOptions, console.error),\r\n '})();',\r\n '',\r\n options.source\r\n ].join(EOL);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"SetPublicPathPlugin.js","sourceRoot":"","sources":["../src/SetPublicPathPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2BAAyB;AAKzB,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,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACpD,CAAC;AAED;;;;;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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OAA4B;QAClD,MAAM,aAAa,qBAA0B,IAAI,CAAC,OAAO,CAAE,CAAC;QAE5D,sFAAsF;QACtF,aAAa,CAAC,yBAAyB,GAAG,GAAG,OAAO,CAAC,SAAS,IAAI,CAAC;QACnE,aAAa,CAAC,UAAU,GAAG,IAAI,CAAC;QAEhC,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;YAC3B,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE;gBAChC,aAAa,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC;gBACvD,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE;oBACvC,aAAa,CAAC,SAAS,GAAG,aAAa,CAAC,SAAS;yBAC9C,OAAO,CAAC,WAAW,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;yBACtD,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;AAnKD,kDAmKC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\r\n// See LICENSE in the project root for license information.\r\n\r\nimport { EOL } from 'os';\r\nimport type * as Webpack from 'webpack';\r\nimport type * as Webpack5 from 'webpack5';\r\nimport type * as Tapable from 'tapable';\r\n\r\nimport { IInternalOptions, getSetPublicPathCode } from './codeGenerator';\r\n\r\n/**\r\n * The base options for setting the webpack public path at runtime.\r\n *\r\n * @public\r\n */\r\nexport interface ISetWebpackPublicPathOptions {\r\n /**\r\n * Use the System.baseURL property if it is defined.\r\n */\r\n systemJs?: boolean;\r\n\r\n /**\r\n * Use the specified string as a URL prefix after the SystemJS path or the publicPath option.\r\n * If neither systemJs nor publicPath is defined, this option will not apply and an exception will be thrown.\r\n */\r\n urlPrefix?: string;\r\n\r\n /**\r\n * Use the specified path as the base public path.\r\n */\r\n publicPath?: string;\r\n\r\n /**\r\n * Check for a variable with this name on the page and use its value as a regular expression against script paths to\r\n * the bundle's script. If a value foo is passed into regexVariable, the produced bundle will look for a variable\r\n * called foo during initialization, and if a foo variable is found, use its value as a regular expression to detect\r\n * the bundle's script.\r\n *\r\n * See the README for more information.\r\n */\r\n regexVariable?: string;\r\n\r\n /**\r\n * A function that returns a snippet of code that manipulates the variable with the name that's specified in the\r\n * parameter. If this parameter isn't provided, no post-processing code is included. The variable must be modified\r\n * in-place - the processed value should not be returned.\r\n *\r\n * See the README for more information.\r\n */\r\n getPostProcessScript?: (varName: string) => string;\r\n\r\n /**\r\n * If true, find the last script matching the regexVariable (if it is set). If false, find the first matching script.\r\n * This can be useful if there are multiple scripts loaded in the DOM that match the regexVariable.\r\n */\r\n preferLastFoundScript?: boolean;\r\n\r\n /**\r\n * If true, always include the public path-setting code. Don't try to detect if any chunks or assets are present.\r\n */\r\n skipDetection?: boolean;\r\n}\r\n\r\n/**\r\n * Options for the set-webpack-public-path plugin.\r\n *\r\n * @public\r\n */\r\nexport interface ISetWebpackPublicPathPluginOptions extends ISetWebpackPublicPathOptions {\r\n /**\r\n * An object that describes how the public path should be discovered.\r\n */\r\n scriptName?: {\r\n /**\r\n * If set to true, use the webpack generated asset's name. This option is not compatible with\r\n * andy other scriptName options.\r\n */\r\n useAssetName?: boolean;\r\n\r\n /**\r\n * A regular expression expressed as a string to be applied to all script paths on the page.\r\n */\r\n name?: string;\r\n\r\n /**\r\n * If true, the name property is tokenized.\r\n *\r\n * See the README for more information.\r\n */\r\n isTokenized?: boolean;\r\n };\r\n}\r\n\r\ninterface IAsset {\r\n size(): number;\r\n source(): string;\r\n}\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare const __dummyWebpack4MainTemplate: Webpack.compilation.MainTemplate;\r\ninterface IWebpack4ExtendedMainTemplate extends Webpack.compilation.MainTemplate {\r\n hooks: {\r\n startup: Tapable.SyncHook<string, Webpack.compilation.Chunk, string>;\r\n } & typeof __dummyWebpack4MainTemplate.hooks;\r\n}\r\n\r\nconst SHOULD_REPLACE_ASSET_NAME_TOKEN: unique symbol = Symbol(\r\n 'set-public-path-plugin-should-replace-asset-name'\r\n);\r\n\r\ninterface IExtendedChunk extends Webpack.compilation.Chunk {\r\n [SHOULD_REPLACE_ASSET_NAME_TOKEN]: boolean;\r\n}\r\n\r\ninterface IStartupCodeOptions {\r\n source: string;\r\n chunk: IExtendedChunk;\r\n hash: string;\r\n requireFn: string;\r\n}\r\n\r\nconst PLUGIN_NAME: string = 'set-webpack-public-path';\r\n\r\nconst ASSET_NAME_TOKEN: string = '-ASSET-NAME-c0ef4f86-b570-44d3-b210-4428c5b7825c';\r\n\r\nconst ASSET_NAME_TOKEN_REGEX: RegExp = new RegExp(ASSET_NAME_TOKEN);\r\n\r\nfunction escapeRegExp(str: string): string {\r\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\r\n}\r\n\r\n/**\r\n * This simple plugin sets the __webpack_public_path__ variable to a value specified in the arguments,\r\n * optionally appended to the SystemJs baseURL property.\r\n *\r\n * @public\r\n */\r\nexport class SetPublicPathPlugin implements Webpack.Plugin {\r\n public options: ISetWebpackPublicPathPluginOptions;\r\n\r\n public constructor(options: ISetWebpackPublicPathPluginOptions) {\r\n this.options = options;\r\n\r\n if (options.scriptName) {\r\n if (options.scriptName.useAssetName && options.scriptName.name) {\r\n throw new Error('scriptName.userAssetName and scriptName.name must not be used together');\r\n } else if (options.scriptName.isTokenized && !options.scriptName.name) {\r\n throw new Error('scriptName.isTokenized is only valid if scriptName.name is set');\r\n }\r\n }\r\n }\r\n\r\n public apply(compiler: Webpack.Compiler): void {\r\n const isWebpack3OrEarlier: boolean = !compiler.hooks;\r\n\r\n if (isWebpack3OrEarlier) {\r\n throw new Error(`The ${SetPublicPathPlugin.name} plugin requires Webpack 4 or Webpack 5`);\r\n }\r\n\r\n const webpackVersion: string | undefined = (\r\n compiler as unknown as Webpack5.Compiler | { webpack: undefined }\r\n ).webpack?.version;\r\n const webpackMajorVersion: number = webpackVersion\r\n ? Number(webpackVersion.substr(0, webpackVersion.indexOf('.')))\r\n : 4;\r\n\r\n compiler.hooks.compilation.tap(\r\n PLUGIN_NAME,\r\n (compilation: Webpack.compilation.Compilation | Webpack5.Compilation) => {\r\n if (webpackMajorVersion === 4) {\r\n const webpack4Compilation: Webpack.compilation.Compilation =\r\n compilation as Webpack.compilation.Compilation;\r\n const mainTemplate: IWebpack4ExtendedMainTemplate =\r\n webpack4Compilation.mainTemplate as IWebpack4ExtendedMainTemplate;\r\n mainTemplate.hooks.startup.tap(\r\n PLUGIN_NAME,\r\n (source: string, chunk: Webpack.compilation.Chunk, hash: string) => {\r\n const extendedChunk: IExtendedChunk = chunk as IExtendedChunk;\r\n const assetOrChunkFound: boolean =\r\n !!this.options.skipDetection || this._detectAssetsOrChunks(extendedChunk);\r\n if (assetOrChunkFound) {\r\n return this._getStartupCode({\r\n source,\r\n chunk: extendedChunk,\r\n hash,\r\n requireFn: mainTemplate.requireFn\r\n });\r\n } else {\r\n return source;\r\n }\r\n }\r\n );\r\n } else {\r\n // Webpack 5 has its own automatic public path code, so only apply for Webpack 4\r\n const Webpack5Error: typeof Webpack5.WebpackError = (compiler as unknown as Webpack5.Compiler)\r\n .webpack.WebpackError;\r\n // Don't bother importing node-core-library for this\r\n const thisPackageJson: { name: string } = require('../package.json');\r\n compilation.warnings.push(\r\n new Webpack5Error(\r\n `Webpack 5 supports its own automatic public path detection, ` +\r\n `so ${thisPackageJson.name} won't do anything in this compilation.`\r\n )\r\n );\r\n }\r\n }\r\n );\r\n\r\n // Webpack 5 has its own automatic public path code, so only apply for Webpack 4\r\n if (webpackMajorVersion === 4) {\r\n compiler.hooks.emit.tap(\r\n PLUGIN_NAME,\r\n (compilation: Webpack.compilation.Compilation | Webpack5.Compilation) => {\r\n for (const chunkGroup of compilation.chunkGroups) {\r\n for (const chunk of chunkGroup.chunks) {\r\n if (chunk[SHOULD_REPLACE_ASSET_NAME_TOKEN]) {\r\n for (const assetFilename of chunk.files) {\r\n let escapedAssetFilename: string;\r\n if (assetFilename.match(/\\.map$/)) {\r\n // Trim the \".map\" extension\r\n escapedAssetFilename = assetFilename.substr(\r\n 0,\r\n assetFilename.length - 4 /* '.map'.length */\r\n );\r\n escapedAssetFilename = escapeRegExp(escapedAssetFilename);\r\n // source in sourcemaps is JSON-encoded\r\n escapedAssetFilename = JSON.stringify(escapedAssetFilename);\r\n // Trim the quotes from the JSON encoding\r\n escapedAssetFilename = escapedAssetFilename.substring(1, escapedAssetFilename.length - 1);\r\n } else {\r\n escapedAssetFilename = escapeRegExp(assetFilename);\r\n }\r\n\r\n const asset: IAsset = compilation.assets[assetFilename];\r\n const originalAssetSource: string = asset.source();\r\n const originalAssetSize: number = asset.size();\r\n\r\n const newAssetSource: string = originalAssetSource.replace(\r\n ASSET_NAME_TOKEN_REGEX,\r\n escapedAssetFilename\r\n );\r\n const sizeDifference: number = assetFilename.length - ASSET_NAME_TOKEN.length;\r\n asset.source = () => newAssetSource;\r\n asset.size = () => originalAssetSize + sizeDifference;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n );\r\n }\r\n }\r\n\r\n private _detectAssetsOrChunks(chunk: IExtendedChunk): boolean {\r\n for (const chunkGroup of chunk.groupsIterable) {\r\n if (chunkGroup.childrenIterable.size > 0) {\r\n return true;\r\n }\r\n }\r\n\r\n for (const innerModule of chunk.modulesIterable) {\r\n if (innerModule.buildInfo.assets && Object.keys(innerModule.buildInfo.assets).length > 0) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n private _getStartupCode(options: IStartupCodeOptions): string {\r\n const moduleOptions: IInternalOptions = { ...this.options };\r\n\r\n // If this module has ownership over any chunks or assets, inject the public path code\r\n moduleOptions.webpackPublicPathVariable = `${options.requireFn}.p`;\r\n moduleOptions.linePrefix = ' ';\r\n\r\n if (this.options.scriptName) {\r\n if (this.options.scriptName.name) {\r\n moduleOptions.regexName = this.options.scriptName.name;\r\n if (this.options.scriptName.isTokenized) {\r\n moduleOptions.regexName = moduleOptions.regexName\r\n .replace(/\\[name\\]/g, escapeRegExp(options.chunk.name))\r\n .replace(/\\[hash\\]/g, options.chunk.renderedHash || '');\r\n }\r\n } else if (this.options.scriptName.useAssetName) {\r\n options.chunk[SHOULD_REPLACE_ASSET_NAME_TOKEN] = true;\r\n\r\n moduleOptions.regexName = ASSET_NAME_TOKEN;\r\n }\r\n }\r\n\r\n return [\r\n '// Set the webpack public path',\r\n '(function () {',\r\n getSetPublicPathCode(moduleOptions, console.error),\r\n '})();',\r\n '',\r\n options.source\r\n ].join(EOL);\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,37 +1,36 @@
1
1
  {
2
2
  "name": "@rushstack/set-webpack-public-path-plugin",
3
- "version": "3.3.0",
3
+ "version": "3.3.4",
4
4
  "description": "This plugin sets the webpack public path at runtime.",
5
5
  "main": "lib/index.js",
6
- "typings": "lib/index.d.ts",
6
+ "typings": "dist/set-webpack-public-path-plugin.d.ts",
7
7
  "license": "MIT",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/microsoft/rushstack.git",
11
11
  "directory": "webpack/set-webpack-public-path-plugin"
12
12
  },
13
- "dependencies": {
14
- "lodash": "~4.17.15"
15
- },
16
13
  "peerDependencies": {
17
- "@types/webpack": "^4.39.8"
14
+ "@types/webpack": "^4.39.8",
15
+ "webpack": "^5.35.1"
18
16
  },
19
17
  "peerDependenciesMeta": {
20
18
  "@types/webpack": {
21
19
  "optional": true
20
+ },
21
+ "webpack": {
22
+ "optional": true
22
23
  }
23
24
  },
24
25
  "devDependencies": {
25
26
  "@rushstack/eslint-config": "2.4.5",
26
- "@rushstack/heft": "0.42.2",
27
- "@rushstack/heft-node-rig": "1.2.30",
27
+ "@rushstack/heft": "0.42.4",
28
+ "@rushstack/heft-node-rig": "1.2.33",
28
29
  "@types/heft-jest": "1.0.1",
29
- "@types/lodash": "4.14.116",
30
30
  "@types/node": "12.20.24",
31
31
  "@types/tapable": "1.0.6",
32
- "@types/uglify-js": "2.6.29",
33
- "webpack5": "npm:webpack@~5.35.1",
34
- "webpack4": "npm:@types/webpack@4.41.24"
32
+ "@types/webpack": "4.41.24",
33
+ "webpack5": "npm:webpack@~5.35.1"
35
34
  },
36
35
  "scripts": {
37
36
  "build": "heft build --clean"