@runtime-type-inspector/plugin-webpack5 1.0.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/index.cjs +56 -0
- package/loader.cjs +11 -0
- package/package.json +17 -0
- package/types.d.ts +1 -0
package/index.cjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const {Compilation, Compiler} = require('webpack');
|
|
2
|
+
/**
|
|
3
|
+
* @typedef RuntimeTypeInspectorPluginOptions
|
|
4
|
+
* @property {RegExp} [test] - Test for file extensions.
|
|
5
|
+
* @property {RegExp} [exclude] - Test for exclusion.
|
|
6
|
+
*/
|
|
7
|
+
class RuntimeTypeInspectorPlugin {
|
|
8
|
+
static pluginName = 'RuntimeTypeInspectorPlugin';
|
|
9
|
+
// Default options
|
|
10
|
+
options = {
|
|
11
|
+
// These file extensions are transpiled by default.
|
|
12
|
+
test: /\.[cm]?js(\?.*)?$/i,
|
|
13
|
+
// By default, files under node_modules are not processed.
|
|
14
|
+
exclude: /node_modules/
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* @param {RuntimeTypeInspectorPluginOptions} options - The options.
|
|
18
|
+
*/
|
|
19
|
+
constructor(options) {
|
|
20
|
+
Object.assign(this.options, options);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @param {Compiler} compiler - The compiler.
|
|
24
|
+
*/
|
|
25
|
+
apply(compiler) {
|
|
26
|
+
compiler.hooks.thisCompilation.tap(
|
|
27
|
+
RuntimeTypeInspectorPlugin.pluginName,
|
|
28
|
+
/**
|
|
29
|
+
* @param {Compilation} compilation - The compilation.
|
|
30
|
+
*/
|
|
31
|
+
(compilation) => {
|
|
32
|
+
compiler.webpack.NormalModule.getCompilationHooks(compilation).loader.tap(
|
|
33
|
+
RuntimeTypeInspectorPlugin.pluginName,
|
|
34
|
+
/**
|
|
35
|
+
* @param {object} loaderContext - The loader context.
|
|
36
|
+
* @param {import('webpack').NormalModule} module - The module.
|
|
37
|
+
*/
|
|
38
|
+
(loaderContext, module) => {
|
|
39
|
+
const {userRequest} = module;
|
|
40
|
+
const {test, exclude} = this.options;
|
|
41
|
+
const retTest = test.test(userRequest);
|
|
42
|
+
const retExclude = exclude.test(userRequest);
|
|
43
|
+
// console.log('userRequest', userRequest, {retTest, retExclude});
|
|
44
|
+
if (!retTest || retExclude) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const {options} = this;
|
|
48
|
+
const loader = require.resolve(__dirname + '/loader.cjs');
|
|
49
|
+
module.loaders.push({options, loader});
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
module.exports = {RuntimeTypeInspectorPlugin};
|
package/loader.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const {addTypeChecks} = require('@runtime-type-inspector/transpiler');
|
|
2
|
+
const loaderUtils = require('loader-utils');
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} source - The source.
|
|
5
|
+
*/
|
|
6
|
+
module.exports = function (source) {
|
|
7
|
+
/** @type {import('@runtime-type-inspector/transpiler').Options} */
|
|
8
|
+
const options = loaderUtils.getOptions(this);
|
|
9
|
+
source = addTypeChecks(source, options);
|
|
10
|
+
this.callback(null, source);
|
|
11
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@runtime-type-inspector/plugin-webpack5",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.cjs",
|
|
6
|
+
"types": "types.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"author": "Hermann Rolfes (kungfooman)",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@runtime-type-inspector/transpiler": "^2.0.15",
|
|
14
|
+
"loader-utils": "^2.0.4",
|
|
15
|
+
"webpack": "^5.89.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type RuntimeTypeInspectorPluginOptions = import("./index.cjs").RuntimeTypeInspectorPluginOptions;
|