@rushstack/webpack-plugin-utilities 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/webpack-plugin-utilities.d.ts +40 -0
- package/lib/DetectWebpackVersion.d.ts +28 -0
- package/lib/DetectWebpackVersion.d.ts.map +1 -0
- package/lib/DetectWebpackVersion.js +42 -0
- package/lib/DetectWebpackVersion.js.map +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +36 -0
- package/lib/index.js.map +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# webpack-plugin-utilities
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
`npm install @rushstack/webpack-plugin-utilities --save`
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
This is a collection of utilities for writing webpack plugins
|
|
10
|
+
|
|
11
|
+
# Usage
|
|
12
|
+
|
|
13
|
+
```JavaScript
|
|
14
|
+
import { VersionDetection } from "@rushstack/webpack-plugin-utilities"
|
|
15
|
+
|
|
16
|
+
class MyExampleWebpackPlugin {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.pluginName = "MyExampleWebpackPlugin"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
apply(compiler) {
|
|
22
|
+
if (VersionDetection.isWebpack3OrEarlier(compiler)) {
|
|
23
|
+
throw new Error(`This plugin does not support webpack 3 or below.`)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const isWebpack4 = VersionDetection.isWebpack4(compiler);
|
|
27
|
+
|
|
28
|
+
if (isWebpack4) {
|
|
29
|
+
compiler.hooks.compilation.tap(this.pluginName, (compilation) => {
|
|
30
|
+
// ....
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
compiler.hooks.compilation.tap(this.pluginName, (compilation) => {
|
|
34
|
+
// ...
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Links
|
|
42
|
+
|
|
43
|
+
- [CHANGELOG.md](
|
|
44
|
+
https://github.com/microsoft/rushstack/blob/main/webpack/webpack-plugin-utilities/CHANGELOG.md) - Find
|
|
45
|
+
out what's new in the latest version
|
|
46
|
+
|
|
47
|
+
`@rushstack/webpack-plugin-utilities` is part of the [Rush Stack](https://rushstack.io/) family of projects.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.23.0"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility package which provides a set of tools for working in
|
|
3
|
+
* webpack plugins, loaders, and other integrations.
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type * as Webpack from 'webpack';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* We do not have quality API detection between webpack major versions 1-3.
|
|
11
|
+
* We can detect the absence of hooks which was a version 3 feature.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
declare function isWebpack3OrEarlier(compiler: Webpack.Compiler): boolean;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Detects whether or not we are using webpack 4
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
declare function isWebpack4(compiler: Webpack.Compiler): boolean;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Detects whether or not we are using webpack 5
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
declare function isWebpack5(compiler: Webpack.Compiler): boolean;
|
|
30
|
+
|
|
31
|
+
declare namespace VersionDetection {
|
|
32
|
+
export {
|
|
33
|
+
isWebpack3OrEarlier,
|
|
34
|
+
isWebpack4,
|
|
35
|
+
isWebpack5
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export { VersionDetection }
|
|
39
|
+
|
|
40
|
+
export { }
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* There is no `compiler.version` API available prior to webpack 5,
|
|
3
|
+
* therefore we will have to make some inferences about which major version of webpack we are on.
|
|
4
|
+
* Feature Request: https://github.com/webpack/webpack/issues/15679
|
|
5
|
+
* @description
|
|
6
|
+
*/
|
|
7
|
+
import type * as Webpack from 'webpack';
|
|
8
|
+
/**
|
|
9
|
+
* We do not have quality API detection between webpack major versions 1-3.
|
|
10
|
+
* We can detect the absence of hooks which was a version 3 feature.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
declare function isWebpack3OrEarlier(compiler: Webpack.Compiler): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Detects whether or not we are using webpack 4
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
declare function isWebpack4(compiler: Webpack.Compiler): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Detects whether or not we are using webpack 5
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
declare function isWebpack5(compiler: Webpack.Compiler): boolean;
|
|
27
|
+
export { isWebpack3OrEarlier, isWebpack4, isWebpack5 };
|
|
28
|
+
//# sourceMappingURL=DetectWebpackVersion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DetectWebpackVersion.d.ts","sourceRoot":"","sources":["../src/DetectWebpackVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AAExC;;;;;GAKG;AACH,iBAAS,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAEhE;AAED;;;;GAIG;AACH,iBAAS,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAGvD;AAED;;;;GAIG;AACH,iBAAS,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAIvD;AAED,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* There is no `compiler.version` API available prior to webpack 5,
|
|
4
|
+
* therefore we will have to make some inferences about which major version of webpack we are on.
|
|
5
|
+
* Feature Request: https://github.com/webpack/webpack/issues/15679
|
|
6
|
+
* @description
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.isWebpack5 = exports.isWebpack4 = exports.isWebpack3OrEarlier = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* We do not have quality API detection between webpack major versions 1-3.
|
|
12
|
+
* We can detect the absence of hooks which was a version 3 feature.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
function isWebpack3OrEarlier(compiler) {
|
|
17
|
+
return !compiler.hooks;
|
|
18
|
+
}
|
|
19
|
+
exports.isWebpack3OrEarlier = isWebpack3OrEarlier;
|
|
20
|
+
/**
|
|
21
|
+
* Detects whether or not we are using webpack 4
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
function isWebpack4(compiler) {
|
|
26
|
+
var _a;
|
|
27
|
+
const webpackVersion = (_a = compiler === null || compiler === void 0 ? void 0 : compiler.webpack) === null || _a === void 0 ? void 0 : _a.version;
|
|
28
|
+
return !webpackVersion;
|
|
29
|
+
}
|
|
30
|
+
exports.isWebpack4 = isWebpack4;
|
|
31
|
+
/**
|
|
32
|
+
* Detects whether or not we are using webpack 5
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
function isWebpack5(compiler) {
|
|
37
|
+
var _a;
|
|
38
|
+
const webpackVersion = (_a = compiler === null || compiler === void 0 ? void 0 : compiler.webpack) === null || _a === void 0 ? void 0 : _a.version;
|
|
39
|
+
return !!webpackVersion;
|
|
40
|
+
}
|
|
41
|
+
exports.isWebpack5 = isWebpack5;
|
|
42
|
+
//# sourceMappingURL=DetectWebpackVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DetectWebpackVersion.js","sourceRoot":"","sources":["../src/DetectWebpackVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAIH;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,QAA0B;IACrD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;AACzB,CAAC;AAuBQ,kDAAmB;AArB5B;;;;GAIG;AACH,SAAS,UAAU,CAAC,QAA0B;;IAC5C,MAAM,cAAc,GAAuB,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,0CAAE,OAAO,CAAC;IACtE,OAAO,CAAC,cAAc,CAAC;AACzB,CAAC;AAa6B,gCAAU;AAXxC;;;;GAIG;AACH,SAAS,UAAU,CAAC,QAA0B;;IAC5C,MAAM,cAAc,GAAuB,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,0CAAE,OAAO,CAAC;IAEtE,OAAO,CAAC,CAAC,cAAc,CAAC;AAC1B,CAAC;AAEyC,gCAAU","sourcesContent":["/**\n * There is no `compiler.version` API available prior to webpack 5,\n * therefore we will have to make some inferences about which major version of webpack we are on.\n * Feature Request: https://github.com/webpack/webpack/issues/15679\n * @description\n */\n\nimport type * as Webpack from 'webpack';\n\n/**\n * We do not have quality API detection between webpack major versions 1-3.\n * We can detect the absence of hooks which was a version 3 feature.\n *\n * @public\n */\nfunction isWebpack3OrEarlier(compiler: Webpack.Compiler): boolean {\n return !compiler.hooks;\n}\n\n/**\n * Detects whether or not we are using webpack 4\n *\n * @public\n */\nfunction isWebpack4(compiler: Webpack.Compiler): boolean {\n const webpackVersion: string | undefined = compiler?.webpack?.version;\n return !webpackVersion;\n}\n\n/**\n * Detects whether or not we are using webpack 5\n *\n * @public\n */\nfunction isWebpack5(compiler: Webpack.Compiler): boolean {\n const webpackVersion: string | undefined = compiler?.webpack?.version;\n\n return !!webpackVersion;\n}\n\nexport { isWebpack3OrEarlier, isWebpack4, isWebpack5 };\n"]}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility package which provides a set of tools for working in
|
|
3
|
+
* webpack plugins, loaders, and other integrations.
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import * as VersionDetection from './DetectWebpackVersion';
|
|
7
|
+
export { VersionDetection };
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,OAAO,KAAK,gBAAgB,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.VersionDetection = void 0;
|
|
29
|
+
/**
|
|
30
|
+
* Utility package which provides a set of tools for working in
|
|
31
|
+
* webpack plugins, loaders, and other integrations.
|
|
32
|
+
* @packageDocumentation
|
|
33
|
+
*/
|
|
34
|
+
const VersionDetection = __importStar(require("./DetectWebpackVersion"));
|
|
35
|
+
exports.VersionDetection = VersionDetection;
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D;;;;GAIG;AAEH,yEAA2D;AAClD,4CAAgB","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * Utility package which provides a set of tools for working in\n * webpack plugins, loaders, and other integrations.\n * @packageDocumentation\n */\n\nimport * as VersionDetection from './DetectWebpackVersion';\nexport { VersionDetection };\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rushstack/webpack-plugin-utilities",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "This plugin sets the webpack public path at runtime.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "dist/webpack-plugin-utilities.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/microsoft/rushstack.git",
|
|
11
|
+
"directory": "webpack/webpack-plugin-utilities"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@types/webpack": "^4.39.8",
|
|
15
|
+
"webpack": "^5.35.1"
|
|
16
|
+
},
|
|
17
|
+
"peerDependenciesMeta": {
|
|
18
|
+
"@types/webpack": {
|
|
19
|
+
"optional": true
|
|
20
|
+
},
|
|
21
|
+
"webpack": {
|
|
22
|
+
"optional": true
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@rushstack/eslint-config": "2.6.0",
|
|
27
|
+
"@rushstack/heft": "0.45.0",
|
|
28
|
+
"@rushstack/heft-node-rig": "1.9.1",
|
|
29
|
+
"@types/heft-jest": "1.0.1",
|
|
30
|
+
"@types/node": "12.20.24",
|
|
31
|
+
"@types/tapable": "1.0.6",
|
|
32
|
+
"webpack": "~5.68.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "heft build --clean",
|
|
36
|
+
"_phase:build": "heft build --clean"
|
|
37
|
+
},
|
|
38
|
+
"readme": "# webpack-plugin-utilities\n\n## Installation\n\n`npm install @rushstack/webpack-plugin-utilities --save`\n\n## Overview\n\nThis is a collection of utilities for writing webpack plugins\n\n# Usage\n\n```JavaScript\nimport { VersionDetection } from \"@rushstack/webpack-plugin-utilities\"\n\nclass MyExampleWebpackPlugin {\n constructor() {\n this.pluginName = \"MyExampleWebpackPlugin\"\n }\n\n apply(compiler) {\n if (VersionDetection.isWebpack3OrEarlier(compiler)) {\n throw new Error(`This plugin does not support webpack 3 or below.`)\n }\n\n const isWebpack4 = VersionDetection.isWebpack4(compiler);\n\n if (isWebpack4) {\n compiler.hooks.compilation.tap(this.pluginName, (compilation) => {\n // ....\n });\n } else {\n compiler.hooks.compilation.tap(this.pluginName, (compilation) => {\n // ...\n });\n }\n }\n}\n```\n\n## Links\n\n- [CHANGELOG.md](\n https://github.com/microsoft/rushstack/blob/main/webpack/webpack-plugin-utilities/CHANGELOG.md) - Find\n out what's new in the latest version\n\n`@rushstack/webpack-plugin-utilities` is part of the [Rush Stack](https://rushstack.io/) family of projects."
|
|
39
|
+
}
|