@metamask/snaps-cli 6.6.1 → 7.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/CHANGELOG.md +39 -1
- package/README.md +11 -244
- package/dist/builders.cjs +4 -98
- package/dist/builders.cjs.map +1 -1
- package/dist/builders.d.cts +28 -7
- package/dist/builders.d.cts.map +1 -1
- package/dist/builders.d.mts +28 -7
- package/dist/builders.d.mts.map +1 -1
- package/dist/builders.mjs +4 -97
- package/dist/builders.mjs.map +1 -1
- package/dist/cli.cjs +4 -9
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts.map +1 -1
- package/dist/cli.d.mts.map +1 -1
- package/dist/cli.mjs +4 -16
- package/dist/cli.mjs.map +1 -1
- package/dist/commands/build/build.cjs +33 -7
- package/dist/commands/build/build.cjs.map +1 -1
- package/dist/commands/build/build.d.cts +2 -1
- package/dist/commands/build/build.d.cts.map +1 -1
- package/dist/commands/build/build.d.mts +2 -1
- package/dist/commands/build/build.d.mts.map +1 -1
- package/dist/commands/build/build.mjs +31 -5
- package/dist/commands/build/build.mjs.map +1 -1
- package/dist/commands/build/implementation.cjs +1 -1
- package/dist/commands/build/implementation.cjs.map +1 -1
- package/dist/commands/build/implementation.d.cts +3 -2
- package/dist/commands/build/implementation.d.cts.map +1 -1
- package/dist/commands/build/implementation.d.mts +3 -2
- package/dist/commands/build/implementation.d.mts.map +1 -1
- package/dist/commands/build/implementation.mjs +1 -1
- package/dist/commands/build/implementation.mjs.map +1 -1
- package/dist/commands/build/index.cjs +3 -14
- package/dist/commands/build/index.cjs.map +1 -1
- package/dist/commands/build/index.d.cts.map +1 -1
- package/dist/commands/build/index.d.mts.map +1 -1
- package/dist/commands/build/index.mjs +3 -14
- package/dist/commands/build/index.mjs.map +1 -1
- package/dist/commands/build/utils.cjs +25 -0
- package/dist/commands/build/utils.cjs.map +1 -0
- package/dist/commands/build/utils.d.cts +9 -0
- package/dist/commands/build/utils.d.cts.map +1 -0
- package/dist/commands/build/utils.d.mts +9 -0
- package/dist/commands/build/utils.d.mts.map +1 -0
- package/dist/commands/build/utils.mjs +21 -0
- package/dist/commands/build/utils.mjs.map +1 -0
- package/dist/commands/eval/__test__/webpack/bad/snap.config.cjs +0 -1
- package/dist/commands/eval/__test__/webpack/bad/snap.config.cjs.map +1 -1
- package/dist/commands/eval/__test__/webpack/bad/snap.config.d.cts.map +1 -1
- package/dist/commands/eval/__test__/webpack/bad/snap.config.d.mts.map +1 -1
- package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs +0 -1
- package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs.map +1 -1
- package/dist/commands/eval/__test__/webpack/good/snap.config.cjs +0 -1
- package/dist/commands/eval/__test__/webpack/good/snap.config.cjs.map +1 -1
- package/dist/commands/eval/__test__/webpack/good/snap.config.d.cts.map +1 -1
- package/dist/commands/eval/__test__/webpack/good/snap.config.d.mts.map +1 -1
- package/dist/commands/eval/__test__/webpack/good/snap.config.mjs +0 -1
- package/dist/commands/eval/__test__/webpack/good/snap.config.mjs.map +1 -1
- package/dist/commands/eval/__test__/webpack/snap.config.cjs +0 -1
- package/dist/commands/eval/__test__/webpack/snap.config.cjs.map +1 -1
- package/dist/commands/eval/__test__/webpack/snap.config.d.cts.map +1 -1
- package/dist/commands/eval/__test__/webpack/snap.config.d.mts.map +1 -1
- package/dist/commands/eval/__test__/webpack/snap.config.mjs +0 -1
- package/dist/commands/eval/__test__/webpack/snap.config.mjs.map +1 -1
- package/dist/commands/eval/eval.cjs +1 -1
- package/dist/commands/eval/eval.cjs.map +1 -1
- package/dist/commands/eval/eval.d.cts.map +1 -1
- package/dist/commands/eval/eval.d.mts.map +1 -1
- package/dist/commands/eval/eval.mjs +1 -1
- package/dist/commands/eval/eval.mjs.map +1 -1
- package/dist/commands/eval/index.cjs +1 -4
- package/dist/commands/eval/index.cjs.map +1 -1
- package/dist/commands/eval/index.d.cts.map +1 -1
- package/dist/commands/eval/index.d.mts.map +1 -1
- package/dist/commands/eval/index.mjs +1 -4
- package/dist/commands/eval/index.mjs.map +1 -1
- package/dist/commands/manifest/index.cjs +1 -4
- package/dist/commands/manifest/index.cjs.map +1 -1
- package/dist/commands/manifest/index.d.cts.map +1 -1
- package/dist/commands/manifest/index.d.mts.map +1 -1
- package/dist/commands/manifest/index.mjs +1 -4
- package/dist/commands/manifest/index.mjs.map +1 -1
- package/dist/commands/manifest/manifest.cjs +5 -6
- package/dist/commands/manifest/manifest.cjs.map +1 -1
- package/dist/commands/manifest/manifest.d.cts.map +1 -1
- package/dist/commands/manifest/manifest.d.mts.map +1 -1
- package/dist/commands/manifest/manifest.mjs +5 -6
- package/dist/commands/manifest/manifest.mjs.map +1 -1
- package/dist/commands/serve/index.cjs +2 -2
- package/dist/commands/serve/index.cjs.map +1 -1
- package/dist/commands/serve/index.d.cts.map +1 -1
- package/dist/commands/serve/index.d.mts.map +1 -1
- package/dist/commands/serve/index.mjs +2 -2
- package/dist/commands/serve/index.mjs.map +1 -1
- package/dist/commands/watch/implementation.cjs +2 -0
- package/dist/commands/watch/implementation.cjs.map +1 -1
- package/dist/commands/watch/implementation.d.cts +2 -2
- package/dist/commands/watch/implementation.d.cts.map +1 -1
- package/dist/commands/watch/implementation.d.mts +2 -2
- package/dist/commands/watch/implementation.d.mts.map +1 -1
- package/dist/commands/watch/implementation.mjs +2 -0
- package/dist/commands/watch/implementation.mjs.map +1 -1
- package/dist/commands/watch/index.cjs +2 -17
- package/dist/commands/watch/index.cjs.map +1 -1
- package/dist/commands/watch/index.d.cts.map +1 -1
- package/dist/commands/watch/index.d.mts.map +1 -1
- package/dist/commands/watch/index.mjs +2 -17
- package/dist/commands/watch/index.mjs.map +1 -1
- package/dist/commands/watch/watch.cjs +1 -1
- package/dist/commands/watch/watch.cjs.map +1 -1
- package/dist/commands/watch/watch.d.cts.map +1 -1
- package/dist/commands/watch/watch.d.mts.map +1 -1
- package/dist/commands/watch/watch.mjs +1 -1
- package/dist/commands/watch/watch.mjs.map +1 -1
- package/dist/config.cjs +11 -155
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +216 -314
- package/dist/config.d.cts.map +1 -1
- package/dist/config.d.mts +216 -314
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs +13 -155
- package/dist/config.mjs.map +1 -1
- package/dist/main.cjs +0 -1
- package/dist/main.cjs.map +1 -1
- package/dist/main.mjs +0 -1
- package/dist/main.mjs.map +1 -1
- package/dist/utils/index.cjs +0 -1
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +0 -1
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.mts +0 -1
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +0 -1
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/logging.cjs +16 -2
- package/dist/utils/logging.cjs.map +1 -1
- package/dist/utils/logging.d.cts +8 -1
- package/dist/utils/logging.d.cts.map +1 -1
- package/dist/utils/logging.d.mts +8 -1
- package/dist/utils/logging.d.mts.map +1 -1
- package/dist/utils/logging.mjs +15 -2
- package/dist/utils/logging.mjs.map +1 -1
- package/dist/utils/steps.cjs +11 -6
- package/dist/utils/steps.cjs.map +1 -1
- package/dist/utils/steps.d.cts +2 -2
- package/dist/utils/steps.d.cts.map +1 -1
- package/dist/utils/steps.d.mts +2 -2
- package/dist/utils/steps.d.mts.map +1 -1
- package/dist/utils/steps.mjs +11 -6
- package/dist/utils/steps.mjs.map +1 -1
- package/dist/webpack/compiler.cjs.map +1 -1
- package/dist/webpack/compiler.d.cts +2 -2
- package/dist/webpack/compiler.d.cts.map +1 -1
- package/dist/webpack/compiler.d.mts +2 -2
- package/dist/webpack/compiler.d.mts.map +1 -1
- package/dist/webpack/compiler.mjs.map +1 -1
- package/dist/webpack/config.cjs +8 -2
- package/dist/webpack/config.cjs.map +1 -1
- package/dist/webpack/config.d.cts +6 -2
- package/dist/webpack/config.d.cts.map +1 -1
- package/dist/webpack/config.d.mts +6 -2
- package/dist/webpack/config.d.mts.map +1 -1
- package/dist/webpack/config.mjs +8 -2
- package/dist/webpack/config.mjs.map +1 -1
- package/dist/webpack/loaders/function.cjs +7 -10
- package/dist/webpack/loaders/function.cjs.map +1 -1
- package/dist/webpack/loaders/function.d.cts +1 -0
- package/dist/webpack/loaders/function.d.cts.map +1 -1
- package/dist/webpack/loaders/function.d.mts +1 -0
- package/dist/webpack/loaders/function.d.mts.map +1 -1
- package/dist/webpack/loaders/function.mjs +6 -9
- package/dist/webpack/loaders/function.mjs.map +1 -1
- package/dist/webpack/loaders/index.cjs +1 -3
- package/dist/webpack/loaders/index.cjs.map +1 -1
- package/dist/webpack/loaders/index.d.cts +0 -1
- package/dist/webpack/loaders/index.d.cts.map +1 -1
- package/dist/webpack/loaders/index.d.mts +0 -1
- package/dist/webpack/loaders/index.d.mts.map +1 -1
- package/dist/webpack/loaders/index.mjs +0 -1
- package/dist/webpack/loaders/index.mjs.map +1 -1
- package/dist/webpack/loaders/wasm.cjs +0 -2
- package/dist/webpack/loaders/wasm.cjs.map +1 -1
- package/dist/webpack/loaders/wasm.d.cts.map +1 -1
- package/dist/webpack/loaders/wasm.d.mts.map +1 -1
- package/dist/webpack/loaders/wasm.mjs +0 -2
- package/dist/webpack/loaders/wasm.mjs.map +1 -1
- package/dist/webpack/plugins.cjs +15 -20
- package/dist/webpack/plugins.cjs.map +1 -1
- package/dist/webpack/plugins.d.cts +13 -3
- package/dist/webpack/plugins.d.cts.map +1 -1
- package/dist/webpack/plugins.d.mts +13 -3
- package/dist/webpack/plugins.d.mts.map +1 -1
- package/dist/webpack/plugins.mjs +4 -9
- package/dist/webpack/plugins.mjs.map +1 -1
- package/dist/webpack/utils.cjs +5 -21
- package/dist/webpack/utils.cjs.map +1 -1
- package/dist/webpack/utils.d.cts +6 -36
- package/dist/webpack/utils.d.cts.map +1 -1
- package/dist/webpack/utils.d.mts +6 -36
- package/dist/webpack/utils.d.mts.map +1 -1
- package/dist/webpack/utils.mjs +4 -18
- package/dist/webpack/utils.mjs.map +1 -1
- package/package.json +14 -38
- package/dist/commands/eval/__test__/browserify/bad/snap.config.cjs +0 -10
- package/dist/commands/eval/__test__/browserify/bad/snap.config.cjs.map +0 -1
- package/dist/commands/eval/__test__/browserify/bad/snap.config.d.cts +0 -4
- package/dist/commands/eval/__test__/browserify/bad/snap.config.d.cts.map +0 -1
- package/dist/commands/eval/__test__/browserify/bad/snap.config.d.mts +0 -4
- package/dist/commands/eval/__test__/browserify/bad/snap.config.d.mts.map +0 -1
- package/dist/commands/eval/__test__/browserify/bad/snap.config.mjs +0 -8
- package/dist/commands/eval/__test__/browserify/bad/snap.config.mjs.map +0 -1
- package/dist/commands/eval/__test__/browserify/good/snap.config.cjs +0 -10
- package/dist/commands/eval/__test__/browserify/good/snap.config.cjs.map +0 -1
- package/dist/commands/eval/__test__/browserify/good/snap.config.d.cts +0 -4
- package/dist/commands/eval/__test__/browserify/good/snap.config.d.cts.map +0 -1
- package/dist/commands/eval/__test__/browserify/good/snap.config.d.mts +0 -4
- package/dist/commands/eval/__test__/browserify/good/snap.config.d.mts.map +0 -1
- package/dist/commands/eval/__test__/browserify/good/snap.config.mjs +0 -8
- package/dist/commands/eval/__test__/browserify/good/snap.config.mjs.map +0 -1
- package/dist/utils/legacy.cjs +0 -53
- package/dist/utils/legacy.cjs.map +0 -1
- package/dist/utils/legacy.d.cts +0 -28
- package/dist/utils/legacy.d.cts.map +0 -1
- package/dist/utils/legacy.d.mts +0 -28
- package/dist/utils/legacy.d.mts.map +0 -1
- package/dist/utils/legacy.mjs +0 -47
- package/dist/utils/legacy.mjs.map +0 -1
- package/dist/webpack/loaders/browserify.cjs +0 -84
- package/dist/webpack/loaders/browserify.cjs.map +0 -1
- package/dist/webpack/loaders/browserify.d.cts +0 -18
- package/dist/webpack/loaders/browserify.d.cts.map +0 -1
- package/dist/webpack/loaders/browserify.d.mts +0 -18
- package/dist/webpack/loaders/browserify.d.mts.map +0 -1
- package/dist/webpack/loaders/browserify.mjs +0 -88
- package/dist/webpack/loaders/browserify.mjs.map +0 -1
|
@@ -9,11 +9,17 @@ function $__filename(fileUrl) {
|
|
|
9
9
|
* @param content - The input file contents as a `Uint8Array`.
|
|
10
10
|
* @returns The output of the function.
|
|
11
11
|
*/
|
|
12
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
12
14
|
const loader = function (content) {
|
|
13
15
|
const { fn } = this.getOptions();
|
|
14
16
|
return fn.bind(this)(content);
|
|
15
17
|
};
|
|
16
18
|
export default loader;
|
|
19
|
+
// By setting `raw` to `true`, we are telling Webpack to provide the source as a
|
|
20
|
+
// `Uint8Array` instead of converting it to a string. This allows us to avoid
|
|
21
|
+
// having to convert the source back to a `Uint8Array` in the loader.
|
|
22
|
+
export const raw = true;
|
|
17
23
|
/**
|
|
18
24
|
* Get a loader that executes the given function. This is useful for executing
|
|
19
25
|
* loaders without needing to pass a file to Webpack.
|
|
@@ -33,13 +39,4 @@ export function getFunctionLoader(fn, options) {
|
|
|
33
39
|
},
|
|
34
40
|
};
|
|
35
41
|
}
|
|
36
|
-
// When running as CJS, we need to export the loader as a default export, since
|
|
37
|
-
// `tsup` exports it as `loader_default`.
|
|
38
|
-
// istanbul ignore next 3
|
|
39
|
-
// eslint-disable-next-line n/no-process-env
|
|
40
|
-
if (typeof module !== 'undefined' && process?.env?.NODE_ENV !== 'test') {
|
|
41
|
-
module.exports = loader;
|
|
42
|
-
module.exports.getFunctionLoader = getFunctionLoader;
|
|
43
|
-
module.exports.raw = true;
|
|
44
|
-
}
|
|
45
42
|
//# sourceMappingURL=function.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":";;;;AAaA;;;;;;GAMG;AACH,MAAM,MAAM,GAAoD,UAC9D,OAAO;IAEP,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IACjC,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,EAAqC,EACrC,OAAgB;IAEhB,OAAO;QACL,2EAA2E;QAC3E,sDAAsD;QACtD,MAAM,8BAAY;QAClB,OAAO,EAAE;YACP,EAAE;YACF,GAAG,OAAO;SACX;KACF,CAAC;AACJ,CAAC
|
|
1
|
+
{"version":3,"file":"function.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":";;;;AAaA;;;;;;GAMG;AACH,gFAAgF;AAChF,qEAAqE;AACrE,MAAM,MAAM,GAAoD,UAC9D,OAAO;IAEP,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IACjC,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACrE,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC;AAExB;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,EAAqC,EACrC,OAAgB;IAEhB,OAAO;QACL,2EAA2E;QAC3E,sDAAsD;QACtD,MAAM,8BAAY;QAClB,OAAO,EAAE;YACP,EAAE;YACF,GAAG,OAAO;SACX;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Options for the function loader.\n */\nexport type FunctionLoaderOptions = {\n /**\n * The function to execute. This is bound to the loader context, so it can\n * access the loader options and other properties.\n */\n fn: LoaderDefinitionFunction;\n};\n\n/**\n * A loader that executes a function. See {@link getFunctionLoader} for more\n * information.\n *\n * @param content - The input file contents as a `Uint8Array`.\n * @returns The output of the function.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/promise-function-async\nconst loader: LoaderDefinitionFunction<FunctionLoaderOptions> = function (\n content,\n) {\n const { fn } = this.getOptions();\n return fn.bind(this)(content);\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n\n/**\n * Get a loader that executes the given function. This is useful for executing\n * loaders without needing to pass a file to Webpack.\n *\n * @param fn - The function to execute.\n * @param options - The options to pass to the loader.\n * @returns The loader definition.\n */\nexport function getFunctionLoader<Options>(\n fn: LoaderDefinitionFunction<Options>,\n options: Options,\n) {\n return {\n // We use `__filename` as the loader, so Webpack will execute the loader in\n // this file, with the actual function in the options.\n loader: __filename,\n options: {\n fn,\n ...options,\n },\n };\n}\n"]}
|
|
@@ -17,10 +17,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.wasm =
|
|
20
|
+
exports.wasm = void 0;
|
|
21
21
|
__exportStar(require("./function.cjs"), exports);
|
|
22
|
-
var browserify_1 = require("./browserify.cjs");
|
|
23
|
-
Object.defineProperty(exports, "browserify", { enumerable: true, get: function () { return __importDefault(browserify_1).default; } });
|
|
24
22
|
var wasm_1 = require("./wasm.cjs");
|
|
25
23
|
Object.defineProperty(exports, "wasm", { enumerable: true, get: function () { return __importDefault(wasm_1).default; } });
|
|
26
24
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,iDAA2B;AAC3B
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,iDAA2B;AAC3B,mCAAyC;AAAhC,6GAAA,OAAO,OAAQ","sourcesContent":["export * from './function';\nexport { default as wasm } from './wasm';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,OAAO,EAAE,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,mBAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,OAAO,EAAE,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,mBAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,OAAO,EAAE,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,mBAAe","sourcesContent":["export * from './function';\nexport { default as wasm } from './wasm';\n"]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint-disable no-restricted-globals */
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.raw = exports.getExports = exports.getModuleImports = exports.getImports = void 0;
|
|
5
4
|
const utils_1 = require("@metamask/utils");
|
|
@@ -67,7 +66,6 @@ exports.getExports = getExports;
|
|
|
67
66
|
const loader = async function loader(source) {
|
|
68
67
|
(0, utils_1.assert)(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');
|
|
69
68
|
const wasmModule = await WebAssembly.compile(source);
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
71
69
|
const exports = WebAssembly.Module.exports(wasmModule);
|
|
72
70
|
const imports = WebAssembly.Module.imports(wasmModule).reduce((target, descriptor) => {
|
|
73
71
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wasm.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":";;;AAAA,2CAAwD;AACxD,+BAAwC;AAGxC;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,SAAmC;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,YAAY,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,SAAS,CACzD,UAAU,CACX,GAAG,CACP;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AATD,gCASC;AAED;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAAC,SAAmC;IAClE,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CA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C;IAEP,wEAAwE;IACxE,WAAW;IACX,MAAM,IAAI,GAAG,IAAA,cAAO,EAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,aAAa,CAAC,IAAA,cAAO,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;MACH,UAAU,CAAC,OAAO,CAAC;;kBAEP,IAAI,CAAC,SAAS,CAAC,IAAA,qBAAa,EAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;QAa/C,gBAAgB,CAAC,OAAO,CAAC;;;;MAI3B,UAAU,CAAC,OAAO,CAAC;GACtB,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACxD,QAAA,GAAG,GAAG,IAAI,CAAC","sourcesContent":["import { assert, bytesToBase64 } from '@metamask/utils';\nimport { dirname, resolve } from 'path';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Get the imports code for the WASM module. This code imports each of the\n * imports from the WASM module.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `import { ${exportNames.join(', ')} } from ${JSON.stringify(\n moduleName,\n )};`,\n )\n .join('\\n');\n}\n\n/**\n * Get the imports code to use in `WebAssembly.Instance`. This code adds each of\n * the imports to the `imports` object.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getModuleImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `${JSON.stringify(moduleName)}: { ${exportNames.join(', ')} },`,\n )\n .join('\\n');\n}\n\n/**\n * Get the exports code for the WASM module. This code exports each of the\n * exports from the WASM module as a variable. This function assumes that the\n * exports are available in a variable named `exports`.\n *\n * @param descriptors - The export descriptors from the WASM module.\n * @returns The exports code for the WASM module.\n */\nexport function getExports(descriptors: WebAssembly.ModuleExportDescriptor[]) {\n return descriptors\n .map((descriptor) => {\n if (descriptor.name === 'default') {\n return `export default exports[${JSON.stringify(descriptor.name)}];`;\n }\n\n return `export const ${descriptor.name} = exports[${JSON.stringify(\n descriptor.name,\n )}];`;\n })\n .join('\\n');\n}\n\n/**\n * A Webpack loader that synchronously loads the WASM module. This makes it\n * possible to import the WASM module directly.\n *\n * @param source - The WASM module as `Uint8Array`.\n * @returns The WASM module as a JavaScript string.\n * @example\n * ```ts\n * import * as wasm from './program.wasm';\n *\n * // Do something with the WASM module...\n * ```\n */\n// Note: This function needs to be defined like this, so that Webpack can bind\n// `this` to the loader context, and TypeScript can infer the type of `this`.\nconst loader: LoaderDefinitionFunction = async function loader(\n source: unknown,\n) {\n assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');\n\n const wasmModule = await WebAssembly.compile(source);\n\n const exports = WebAssembly.Module.exports(wasmModule);\n const imports = WebAssembly.Module.imports(wasmModule).reduce<\n Record<string, string[]>\n >((target, descriptor) => {\n target[descriptor.module] ??= [];\n target[descriptor.module].push(descriptor.name);\n\n return target;\n }, {});\n\n // Add the WASM import as a dependency so that Webpack will watch it for\n // changes.\n const path = dirname(this.resourcePath);\n for (const name of Object.keys(imports)) {\n this.addDependency(resolve(path, name));\n }\n\n return `\n ${getImports(imports)}\n\n const b64 = ${JSON.stringify(bytesToBase64(source))};\n\n function decode(encoded) {\n const str = atob(encoded);\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; i++) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n }\n\n const bytes = decode(b64);\n const { instance } = await WebAssembly.instantiate(bytes, {\n ${getModuleImports(imports)}\n });\n\n const exports = instance.exports;\n ${getExports(exports)}\n `;\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wasm.d.cts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAOnE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,sBAAsB,EAAE,UAY3E;AAED;;;;;;;;;;;;GAYG;AAGH,QAAA,MAAM,MAAM,EAAE,wBA8Cb,CAAC;AAEF,eAAe,MAAM,CAAC;AAKtB,eAAO,MAAM,GAAG,OAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wasm.d.mts","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,gBAAgB;AAExD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,UAOnE;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,sBAAsB,EAAE,UAY3E;AAED;;;;;;;;;;;;GAYG;AAGH,QAAA,MAAM,MAAM,EAAE,wBA8Cb,CAAC;AAEF,eAAe,MAAM,CAAC;AAKtB,eAAO,MAAM,GAAG,OAAO,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable no-restricted-globals */
|
|
2
1
|
import { assert, bytesToBase64 } from "@metamask/utils";
|
|
3
2
|
import { dirname, resolve } from "path";
|
|
4
3
|
/**
|
|
@@ -61,7 +60,6 @@ export function getExports(descriptors) {
|
|
|
61
60
|
const loader = async function loader(source) {
|
|
62
61
|
assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');
|
|
63
62
|
const wasmModule = await WebAssembly.compile(source);
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
65
63
|
const exports = WebAssembly.Module.exports(wasmModule);
|
|
66
64
|
const imports = WebAssembly.Module.imports(wasmModule).reduce((target, descriptor) => {
|
|
67
65
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"wasm.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/wasm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,wBAAwB;AACxD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa;AAGxC;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,SAAmC;IAC5D,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;SAC7B,GAAG,CACF,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,CAC5B,YAAY,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,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MAAM,CAE3D,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE;;QACvB,MAAM,MAAC,UAAU,CAAC,MAAM,MAAxB,MAAM,OAAwB,EAAE,EAAC;QACjC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAEhD,OAAO,MAAM,CAAC;IAChB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,wEAAwE;IACxE,WAAW;IACX,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;MACH,UAAU,CAAC,OAAO,CAAC;;kBAEP,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;;;;;;;;;;;;;QAa/C,gBAAgB,CAAC,OAAO,CAAC;;;;MAI3B,UAAU,CAAC,OAAO,CAAC;GACtB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB,gFAAgF;AAChF,6EAA6E;AAC7E,qEAAqE;AACrE,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC","sourcesContent":["import { assert, bytesToBase64 } from '@metamask/utils';\nimport { dirname, resolve } from 'path';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Get the imports code for the WASM module. This code imports each of the\n * imports from the WASM module.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `import { ${exportNames.join(', ')} } from ${JSON.stringify(\n moduleName,\n )};`,\n )\n .join('\\n');\n}\n\n/**\n * Get the imports code to use in `WebAssembly.Instance`. This code adds each of\n * the imports to the `imports` object.\n *\n * @param importMap - The import map for the WASM module.\n * @returns The imports code for the WASM module.\n */\nexport function getModuleImports(importMap: Record<string, string[]>) {\n return Object.entries(importMap)\n .map(\n ([moduleName, exportNames]) =>\n `${JSON.stringify(moduleName)}: { ${exportNames.join(', ')} },`,\n )\n .join('\\n');\n}\n\n/**\n * Get the exports code for the WASM module. This code exports each of the\n * exports from the WASM module as a variable. This function assumes that the\n * exports are available in a variable named `exports`.\n *\n * @param descriptors - The export descriptors from the WASM module.\n * @returns The exports code for the WASM module.\n */\nexport function getExports(descriptors: WebAssembly.ModuleExportDescriptor[]) {\n return descriptors\n .map((descriptor) => {\n if (descriptor.name === 'default') {\n return `export default exports[${JSON.stringify(descriptor.name)}];`;\n }\n\n return `export const ${descriptor.name} = exports[${JSON.stringify(\n descriptor.name,\n )}];`;\n })\n .join('\\n');\n}\n\n/**\n * A Webpack loader that synchronously loads the WASM module. This makes it\n * possible to import the WASM module directly.\n *\n * @param source - The WASM module as `Uint8Array`.\n * @returns The WASM module as a JavaScript string.\n * @example\n * ```ts\n * import * as wasm from './program.wasm';\n *\n * // Do something with the WASM module...\n * ```\n */\n// Note: This function needs to be defined like this, so that Webpack can bind\n// `this` to the loader context, and TypeScript can infer the type of `this`.\nconst loader: LoaderDefinitionFunction = async function loader(\n source: unknown,\n) {\n assert(source instanceof Uint8Array, 'Expected source to be a Uint8Array.');\n\n const wasmModule = await WebAssembly.compile(source);\n\n const exports = WebAssembly.Module.exports(wasmModule);\n const imports = WebAssembly.Module.imports(wasmModule).reduce<\n Record<string, string[]>\n >((target, descriptor) => {\n target[descriptor.module] ??= [];\n target[descriptor.module].push(descriptor.name);\n\n return target;\n }, {});\n\n // Add the WASM import as a dependency so that Webpack will watch it for\n // changes.\n const path = dirname(this.resourcePath);\n for (const name of Object.keys(imports)) {\n this.addDependency(resolve(path, name));\n }\n\n return `\n ${getImports(imports)}\n\n const b64 = ${JSON.stringify(bytesToBase64(source))};\n\n function decode(encoded) {\n const str = atob(encoded);\n const bytes = new Uint8Array(str.length);\n for (let i = 0; i < str.length; i++) {\n bytes[i] = str.charCodeAt(i);\n }\n return bytes;\n }\n\n const bytes = decode(b64);\n const { instance } = await WebAssembly.instantiate(bytes, {\n ${getModuleImports(imports)}\n });\n\n const exports = instance.exports;\n ${getExports(exports)}\n `;\n};\n\nexport default loader;\n\n// By setting `raw` to `true`, we are telling Webpack to provide the source as a\n// `Uint8Array` instead of converting it to a string. This allows us to avoid\n// having to convert the source back to a `Uint8Array` in the loader.\nexport const raw = true;\n"]}
|
package/dist/webpack/plugins.cjs
CHANGED
|
@@ -10,16 +10,16 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _SnapsStatsPlugin_instances, _SnapsStatsPlugin_spinner, _SnapsStatsPlugin_getStatsErrorMessage, _SnapsWatchPlugin_instances, _SnapsWatchPlugin_spinner, _SnapsWatchPlugin_safeEvaluate, _SnapsBuiltInResolver_source,
|
|
13
|
+
var _SnapsStatsPlugin_instances, _SnapsStatsPlugin_spinner, _SnapsStatsPlugin_getStatsErrorMessage, _SnapsWatchPlugin_instances, _SnapsWatchPlugin_spinner, _SnapsWatchPlugin_safeEvaluate, _SnapsBuiltInResolver_source, _SnapsBundleWarningsPlugin_instances, _SnapsBundleWarningsPlugin_checkBuiltIns, _SnapsBundleWarningsPlugin_isProvidePlugin, _SnapsBundleWarningsPlugin_checkBuffer;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.SnapsBundleWarningsPlugin = exports.SnapsBuiltInResolver = exports.SnapsWatchPlugin = exports.SnapsStatsPlugin = void 0;
|
|
16
16
|
const utils_1 = require("@metamask/utils");
|
|
17
17
|
const chalk_1 = require("chalk");
|
|
18
18
|
const module_1 = require("module");
|
|
19
19
|
const webpack_1 = require("webpack");
|
|
20
|
+
const utils_2 = require("./utils.cjs");
|
|
20
21
|
const eval_1 = require("../commands/eval/index.cjs");
|
|
21
|
-
const
|
|
22
|
-
const utils_3 = require("./utils.cjs");
|
|
22
|
+
const utils_3 = require("../utils/index.cjs");
|
|
23
23
|
/**
|
|
24
24
|
* A plugin that logs the stats after compilation. This is useful for logging
|
|
25
25
|
* the number of files compiled, and the time taken to compile them.
|
|
@@ -53,7 +53,7 @@ class SnapsStatsPlugin {
|
|
|
53
53
|
const formattedErrors = errors
|
|
54
54
|
.map((statsError) => __classPrivateFieldGet(this, _SnapsStatsPlugin_instances, "m", _SnapsStatsPlugin_getStatsErrorMessage).call(this, statsError))
|
|
55
55
|
.join('\n\n');
|
|
56
|
-
(0,
|
|
56
|
+
(0, utils_3.error)(`Compiled ${modules.length} ${(0, utils_2.pluralize)(modules.length, 'file')} in ${time}ms with ${errors.length} ${(0, utils_2.pluralize)(errors.length, 'error')}.\n\n${formattedErrors}\n`, __classPrivateFieldGet(this, _SnapsStatsPlugin_spinner, "f"));
|
|
57
57
|
__classPrivateFieldGet(this, _SnapsStatsPlugin_spinner, "f")?.stop();
|
|
58
58
|
process.exitCode = 1;
|
|
59
59
|
return;
|
|
@@ -62,10 +62,10 @@ class SnapsStatsPlugin {
|
|
|
62
62
|
const formattedWarnings = warnings
|
|
63
63
|
.map((statsWarning) => __classPrivateFieldGet(this, _SnapsStatsPlugin_instances, "m", _SnapsStatsPlugin_getStatsErrorMessage).call(this, statsWarning, chalk_1.yellow))
|
|
64
64
|
.join('\n\n');
|
|
65
|
-
(0,
|
|
65
|
+
(0, utils_3.warn)(`Compiled ${modules.length} ${(0, utils_2.pluralize)(modules.length, 'file')} in ${time}ms with ${warnings.length} ${(0, utils_2.pluralize)(warnings.length, 'warning')}.\n\n${formattedWarnings}\n`, __classPrivateFieldGet(this, _SnapsStatsPlugin_spinner, "f"));
|
|
66
66
|
}
|
|
67
67
|
else {
|
|
68
|
-
(0,
|
|
68
|
+
(0, utils_3.info)(`Compiled ${modules.length} ${(0, utils_2.pluralize)(modules.length, 'file')} in ${time}ms.`, __classPrivateFieldGet(this, _SnapsStatsPlugin_spinner, "f"));
|
|
69
69
|
}
|
|
70
70
|
if (compiler.watchMode) {
|
|
71
71
|
// The spinner may be restarted by the watch plugin, outside of the
|
|
@@ -78,13 +78,13 @@ class SnapsStatsPlugin {
|
|
|
78
78
|
exports.SnapsStatsPlugin = SnapsStatsPlugin;
|
|
79
79
|
_SnapsStatsPlugin_spinner = new WeakMap(), _SnapsStatsPlugin_instances = new WeakSet(), _SnapsStatsPlugin_getStatsErrorMessage = function _SnapsStatsPlugin_getStatsErrorMessage(statsError, color = chalk_1.red) {
|
|
80
80
|
const baseMessage = this.options.verbose
|
|
81
|
-
? (0,
|
|
81
|
+
? (0, utils_3.getErrorMessage)(statsError)
|
|
82
82
|
: statsError.message;
|
|
83
83
|
const [first, ...rest] = baseMessage.split('\n');
|
|
84
84
|
return [
|
|
85
|
-
color((0,
|
|
86
|
-
...rest.map((message) => (0,
|
|
87
|
-
statsError.details && `\n${(0,
|
|
85
|
+
color((0, utils_2.formatText)(`• ${first}`, 4, 2)),
|
|
86
|
+
...rest.map((message) => (0, utils_2.formatText)(color(message), 4)),
|
|
87
|
+
statsError.details && `\n${(0, utils_2.formatText)((0, chalk_1.dim)(statsError.details), 6)}`,
|
|
88
88
|
]
|
|
89
89
|
.filter(Boolean)
|
|
90
90
|
.join('\n');
|
|
@@ -112,7 +112,7 @@ class SnapsWatchPlugin {
|
|
|
112
112
|
apply(compiler) {
|
|
113
113
|
compiler.hooks.invalid.tap(this.constructor.name, (file) => {
|
|
114
114
|
__classPrivateFieldGet(this, _SnapsWatchPlugin_spinner, "f")?.start();
|
|
115
|
-
(0,
|
|
115
|
+
(0, utils_3.info)(`Changes detected in ${(0, chalk_1.yellow)(file)}, recompiling.`, __classPrivateFieldGet(this, _SnapsWatchPlugin_spinner, "f"));
|
|
116
116
|
});
|
|
117
117
|
compiler.hooks.afterEmit.tapPromise(this.constructor.name, async ({ fileDependencies }) => {
|
|
118
118
|
this.options.files?.forEach(fileDependencies.add.bind(fileDependencies));
|
|
@@ -135,10 +135,10 @@ _SnapsWatchPlugin_spinner = new WeakMap(), _SnapsWatchPlugin_instances = new Wea
|
|
|
135
135
|
async function _SnapsWatchPlugin_safeEvaluate(bundlePath) {
|
|
136
136
|
try {
|
|
137
137
|
await (0, eval_1.evaluate)(bundlePath);
|
|
138
|
-
(0,
|
|
138
|
+
(0, utils_3.info)(`Snap bundle evaluated successfully.`, __classPrivateFieldGet(this, _SnapsWatchPlugin_spinner, "f"));
|
|
139
139
|
}
|
|
140
140
|
catch (evaluateError) {
|
|
141
|
-
(0,
|
|
141
|
+
(0, utils_3.error)(evaluateError.message, __classPrivateFieldGet(this, _SnapsWatchPlugin_spinner, "f"));
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
144
|
/**
|
|
@@ -150,7 +150,7 @@ async function _SnapsWatchPlugin_safeEvaluate(bundlePath) {
|
|
|
150
150
|
class SnapsBuiltInResolver {
|
|
151
151
|
constructor(options = {
|
|
152
152
|
ignore: [],
|
|
153
|
-
}
|
|
153
|
+
}) {
|
|
154
154
|
/**
|
|
155
155
|
* The built-in modules that have been imported, but not resolved.
|
|
156
156
|
*/
|
|
@@ -159,12 +159,7 @@ class SnapsBuiltInResolver {
|
|
|
159
159
|
* The name of the resolver hook to tap into.
|
|
160
160
|
*/
|
|
161
161
|
_SnapsBuiltInResolver_source.set(this, 'described-resolve');
|
|
162
|
-
/**
|
|
163
|
-
* The spinner to use for logging.
|
|
164
|
-
*/
|
|
165
|
-
_SnapsBuiltInResolver_spinner.set(this, void 0);
|
|
166
162
|
this.options = options;
|
|
167
|
-
__classPrivateFieldSet(this, _SnapsBuiltInResolver_spinner, spinner, "f");
|
|
168
163
|
}
|
|
169
164
|
/**
|
|
170
165
|
* Apply the plugin to the Webpack resolver.
|
|
@@ -191,7 +186,7 @@ class SnapsBuiltInResolver {
|
|
|
191
186
|
}
|
|
192
187
|
}
|
|
193
188
|
exports.SnapsBuiltInResolver = SnapsBuiltInResolver;
|
|
194
|
-
_SnapsBuiltInResolver_source = new WeakMap()
|
|
189
|
+
_SnapsBuiltInResolver_source = new WeakMap();
|
|
195
190
|
/**
|
|
196
191
|
* A plugin that logs a message when:
|
|
197
192
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.cjs","sourceRoot":"","sources":["../../src/webpack/plugins.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAgE;AAChE,iCAA+C;AAC/C,mCAAmC;AAUnC,qCAAuC;AAEvC,qDAA4C;AAC5C,8CAA8D;AAC9D,uCAAgD;AAShD;;;GAGG;AACH,MAAa,gBAAgB;IAW3B,YACE,UAAmC;QACjC,OAAO,EAAE,KAAK;KACf,EACD,OAAa;;QATf;;WAEG;QACM,4CAAe;QAQtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,uBAAA,IAAI,6BAAY,OAAO,MAAA,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,QAAkB;QACtB,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;YAC5D,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO;YACT,CAAC;YAED,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;YAE3D,IAAA,cAAM,EAAC,OAAO,EAAE,mCAAmC,CAAC,CAAC;YACrD,IAAA,cAAM,EAAC,IAAI,EAAE,gCAAgC,CAAC,CAAC;YAE/C,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;gBACnB,MAAM,eAAe,G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QAAQ,CAAC,CAAC,CAAC;YAE5D,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC9B,OAAO;YACT,CAAC;YAED,WAAW,CAAC,QAAQ,CAAC,IAAI,CACvB,IAAI,sBAAY,CACd,mLAAmL,IAAA,YAAI,EACrL,UAAU,CACX,OAAO,IAAA,YAAI,EAAC,QAAQ,CAAC,WAAW,IAAA,YAAI,EACnC,aAAa,CACd,oEAAoE,IAAA,YAAI,EACvE,gBAAgB,CACjB,OAAO,IAAA,YAAI,EAAC,SAAS,CAAC,4BAA4B,CACpD,CACF,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { assert, hasProperty, isObject } from '@metamask/utils';\nimport { bold, dim, red, yellow } from 'chalk';\nimport { isBuiltin } from 'module';\nimport type { Ora } from 'ora';\nimport type {\n Compiler,\n ProvidePlugin,\n ResolvePluginInstance,\n Resolver,\n StatsError,\n WebpackPluginInstance,\n} from 'webpack';\nimport { WebpackError } from 'webpack';\n\nimport { evaluate } from '../commands/eval';\nimport { error, getErrorMessage, info, warn } from '../utils';\nimport { formatText, pluralize } from './utils';\n\nexport type SnapsStatsPluginOptions = {\n /**\n * Whether to log the verbose stats.\n */\n verbose?: boolean;\n};\n\n/**\n * A plugin that logs the stats after compilation. This is useful for logging\n * the number of files compiled, and the time taken to compile them.\n */\nexport class SnapsStatsPlugin implements WebpackPluginInstance {\n /**\n * The options for the plugin.\n */\n readonly options: SnapsStatsPluginOptions;\n\n /**\n * The spinner to use for logging.\n */\n readonly #spinner?: Ora;\n\n constructor(\n options: SnapsStatsPluginOptions = {\n verbose: false,\n },\n spinner?: Ora,\n ) {\n this.options = options;\n this.#spinner = spinner;\n }\n\n /**\n * Apply the plugin to the Webpack compiler.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n compiler.hooks.afterDone.tap(this.constructor.name, (stats) => {\n if (!stats) {\n return;\n }\n\n const { modules, time, errors, warnings } = stats.toJson();\n\n assert(modules, 'Modules must be defined in stats.');\n assert(time, 'Time must be defined in stats.');\n\n if (errors?.length) {\n const formattedErrors = errors\n .map((statsError) => this.#getStatsErrorMessage(statsError))\n .join('\\n\\n');\n\n error(\n `Compiled ${modules.length} ${pluralize(\n modules.length,\n 'file',\n )} in ${time}ms with ${errors.length} ${pluralize(\n errors.length,\n 'error',\n )}.\\n\\n${formattedErrors}\\n`,\n this.#spinner,\n );\n\n this.#spinner?.stop();\n\n process.exitCode = 1;\n return;\n }\n\n if (warnings?.length) {\n const formattedWarnings = warnings\n .map((statsWarning) =>\n this.#getStatsErrorMessage(statsWarning, yellow),\n )\n .join('\\n\\n');\n\n warn(\n `Compiled ${modules.length} ${pluralize(\n modules.length,\n 'file',\n )} in ${time}ms with ${warnings.length} ${pluralize(\n warnings.length,\n 'warning',\n )}.\\n\\n${formattedWarnings}\\n`,\n this.#spinner,\n );\n } else {\n info(\n `Compiled ${modules.length} ${pluralize(\n modules.length,\n 'file',\n )} in ${time}ms.`,\n this.#spinner,\n );\n }\n\n if (compiler.watchMode) {\n // The spinner may be restarted by the watch plugin, outside of the\n // `executeSteps` flow, so we stop it here just in case.\n this.#spinner?.succeed('Done!');\n }\n });\n }\n\n /**\n * Get the error message for the given stats error.\n *\n * @param statsError - The stats error.\n * @param color - The color to use for the error message.\n * @returns The error message.\n */\n #getStatsErrorMessage(statsError: StatsError, color = red) {\n const baseMessage = this.options.verbose\n ? getErrorMessage(statsError)\n : statsError.message;\n\n const [first, ...rest] = baseMessage.split('\\n');\n\n return [\n color(formatText(`• ${first}`, 4, 2)),\n ...rest.map((message) => formatText(color(message), 4)),\n statsError.details && `\\n${formatText(dim(statsError.details), 6)}`,\n ]\n .filter(Boolean)\n .join('\\n');\n }\n}\n\n/**\n * The options for the {@link SnapsWatchPlugin}.\n */\nexport type SnapsWatchPluginOptions = {\n /**\n * The bundle path. This is the file that will be evaluated, if the `evaluate`\n * option is set.\n */\n bundle?: string;\n\n /**\n * Whether to evaluate the bundle. This only applies if the `bundle` option is\n * set.\n */\n evaluate?: boolean;\n\n /**\n * The extra files to watch.\n */\n files?: string[];\n};\n\n/**\n * A plugin that adds extra files to watch. This is useful for watching files\n * that are not imported by the entry point, such as the `snap.manifest.json`\n * file.\n */\nexport class SnapsWatchPlugin implements WebpackPluginInstance {\n /**\n * The options for the plugin.\n */\n readonly options: SnapsWatchPluginOptions;\n\n /**\n * The spinner to use for logging.\n */\n readonly #spinner?: Ora;\n\n constructor(options: SnapsWatchPluginOptions, spinner?: Ora) {\n this.options = options;\n this.#spinner = spinner;\n }\n\n /**\n * Apply the plugin to the Webpack compiler.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n compiler.hooks.invalid.tap(this.constructor.name, (file) => {\n this.#spinner?.start();\n info(`Changes detected in ${yellow(file)}, recompiling.`, this.#spinner);\n });\n\n compiler.hooks.afterEmit.tapPromise(\n this.constructor.name,\n async ({ fileDependencies }) => {\n this.options.files?.forEach(\n fileDependencies.add.bind(fileDependencies),\n );\n\n if (this.options.bundle && this.options.evaluate) {\n await this.#safeEvaluate(this.options.bundle);\n }\n },\n );\n }\n\n /**\n * Safely evaluate the bundle at the given path. If an error occurs, it will\n * be logged to the console, rather than throwing an error.\n *\n * This function should never throw an error.\n *\n * @param bundlePath - The path to the bundle.\n */\n async #safeEvaluate(bundlePath: string) {\n try {\n await evaluate(bundlePath);\n info(`Snap bundle evaluated successfully.`, this.#spinner);\n } catch (evaluateError) {\n error(evaluateError.message, this.#spinner);\n }\n }\n}\n\n/**\n * The options for the {@link SnapsBuiltInResolver}.\n */\nexport type SnapsBuiltInResolverOptions = {\n /**\n * The built-in modules to ignore.\n */\n ignore?: string[];\n};\n\n/**\n * A plugin that logs a message when a built-in module is not resolved. The\n * MetaMask Snaps CLI does not support built-in modules by default, and this\n * plugin is used to warn the user when they try to import a built-in module,\n * when no fallback is configured.\n */\nexport class SnapsBuiltInResolver implements ResolvePluginInstance {\n /**\n * The built-in modules that have been imported, but not resolved.\n */\n readonly unresolvedModules = new Set<string>();\n\n /**\n * The name of the resolver hook to tap into.\n */\n readonly #source = 'described-resolve';\n\n /**\n * The options for the plugin.\n */\n readonly options: SnapsBuiltInResolverOptions;\n\n /**\n * The spinner to use for logging.\n */\n readonly #spinner?: Ora;\n\n constructor(\n options: SnapsBuiltInResolverOptions = {\n ignore: [],\n },\n spinner?: Ora,\n ) {\n this.options = options;\n this.#spinner = spinner;\n }\n\n /**\n * Apply the plugin to the Webpack resolver.\n *\n * @param resolver - The Webpack resolver.\n */\n apply(resolver: Resolver) {\n resolver\n .getHook(this.#source)\n .tapAsync(\n this.constructor.name,\n ({ module: isModule, request }, _, callback) => {\n if (!isModule || !request) {\n return callback();\n }\n\n const baseRequest = request.split('/')[0];\n if (\n isBuiltin(baseRequest) &&\n !this.options.ignore?.includes(baseRequest)\n ) {\n const fallback = resolver.options.fallback.find(\n ({ name }) => name === baseRequest,\n );\n\n if (fallback && !fallback.alias) {\n this.unresolvedModules.add(baseRequest);\n }\n }\n\n return callback();\n },\n );\n }\n}\n\n/**\n * The options for the {@link SnapsBundleWarningsPlugin}.\n */\nexport type SnapsBundleWarningsPluginOptions = {\n /**\n * The {@link SnapsBuiltInResolver} instance to use for detecting built-in\n * modules.\n */\n builtInResolver?: SnapsBuiltInResolver | false;\n\n /**\n * Whether to show warnings if built-in modules are used, but not provided by\n * Webpack's `fallback` configuration.\n */\n builtIns?: boolean;\n\n /**\n * Whether to show warnings if the `Buffer` global is used, but not provided\n * by Webpack's `DefinePlugin`.\n */\n buffer?: boolean;\n};\n\n/**\n * A plugin that logs a message when:\n *\n * - A built-in module is not resolved. The MetaMask Snaps CLI does not support\n * built-in modules by default, and this plugin is used to warn the user when\n * they try to import a built-in module, when no fallback is configured.\n * - A snap uses the `Buffer` global. The MetaMask Snaps CLI does not support\n * the `Buffer` global by default, and this plugin is used to warn the user when\n * they try to use the `Buffer` global.\n *\n * We use both a resolver and a plugin, because the resolver is used to detect\n * when a built-in module is imported, and the plugin is used to log a single\n * message when the compilation is complete. We can't do everything in a single\n * plugin, because the resolver doesn't have access to the compilation, and the\n * plugin doesn't have access to the resolver.\n */\n\nexport class SnapsBundleWarningsPlugin implements WebpackPluginInstance {\n /**\n * The options for the plugin.\n */\n readonly options: SnapsBundleWarningsPluginOptions;\n\n constructor(\n options: SnapsBundleWarningsPluginOptions = {\n buffer: true,\n builtIns: true,\n },\n ) {\n this.options = options;\n }\n\n /**\n * Apply the plugin to the Webpack compiler.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n if (this.options.builtIns) {\n this.#checkBuiltIns(compiler);\n }\n\n if (this.options.buffer) {\n this.#checkBuffer(compiler);\n }\n }\n\n /**\n * Check if a built-in module is used, but not provided by Webpack's\n * `fallback` configuration.\n *\n * @param compiler - The Webpack compiler.\n */\n #checkBuiltIns(compiler: Compiler) {\n compiler.hooks.afterCompile.tap(this.constructor.name, (compilation) => {\n if (!this.options.builtInResolver) {\n return;\n }\n\n const { unresolvedModules } = this.options.builtInResolver;\n if (unresolvedModules.size === 0) {\n return;\n }\n\n const formattedModules = new Array(...unresolvedModules)\n .map((name) => `• ${name}`)\n .join('\\n');\n\n const webpackError = new WebpackError(\n `The snap attempted to use one or more Node.js builtins, but no browser fallback has been provided. The MetaMask Snaps CLI does not support Node.js builtins by default. If you want to use this module, you must set ${bold(\n '`polyfills`',\n )} to ${bold(\n '`true`',\n )} or an object with the builtins to polyfill as the key and ${bold(\n '`true`',\n )} as the value. To disable this warning, set ${bold(\n '`stats.builtIns`',\n )} to ${bold(\n '`false`',\n )} in your snap config file, or add the module to the ${bold(\n '`stats.builtIns.ignore`',\n )} array.`,\n );\n\n webpackError.details = formattedModules;\n compilation.warnings.push(webpackError);\n });\n }\n\n /**\n * Check if the given instance is a `ProvidePlugin`. This is not guaranteed to\n * be accurate, but it's good enough for our purposes. If we were to use\n * `instanceof` instead, it might not work if multiple versions of Webpack are\n * installed.\n *\n * @param instance - The instance to check.\n * @returns Whether the instance is a `ProvidePlugin`, i.e., whether it's an\n * object with the name `ProvidePlugin` and a `definitions` property.\n */\n #isProvidePlugin(instance: unknown): instance is ProvidePlugin {\n return (\n isObject(instance) &&\n instance.constructor.name === 'ProvidePlugin' &&\n hasProperty(instance, 'definitions')\n );\n }\n\n /**\n * Check if the `Buffer` global is used, but not provided by Webpack's\n * `DefinePlugin`.\n *\n * @param compiler - The Webpack compiler.\n */\n #checkBuffer(compiler: Compiler) {\n const plugin = compiler.options.plugins?.find((instance) =>\n this.#isProvidePlugin(instance),\n ) as ProvidePlugin | undefined;\n\n // If the `ProvidePlugin` is configured to provide `Buffer`, then we don't\n // need to warn the user.\n if (plugin) {\n const { definitions } = plugin;\n if (definitions.Buffer) {\n return;\n }\n }\n\n compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {\n compilation.hooks.afterProcessAssets.tap(\n this.constructor.name,\n (assets) => {\n // Check if assets use `Buffer`.\n const bufferAssets = Object.entries(assets)\n .filter(([name]) => name.endsWith('.js'))\n .filter(([, asset]) => asset.source().includes('Buffer'));\n\n if (bufferAssets.length === 0) {\n return;\n }\n\n compilation.warnings.push(\n new WebpackError(\n `The snap attempted to use the Node.js Buffer global, which is not supported in the MetaMask Snaps CLI by default. To use the Buffer global, you must polyfill Buffer by setting ${bold(\n '`buffer`',\n )} to ${bold('`true`')} in the ${bold(\n '`polyfills`',\n )} config object in your snap config. To disable this warning, set ${bold(\n '`stats.buffer`',\n )} to ${bold('`false`')} in your snap config file.`,\n ),\n );\n },\n );\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"plugins.cjs","sourceRoot":"","sources":["../../src/webpack/plugins.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAgE;AAChE,iCAA+C;AAC/C,mCAAmC;AASnC,qCAAuC;AAEvC,uCAAgD;AAChD,qDAA4C;AAC5C,8CAA8D;AAS9D;;;GAGG;AACH,MAAa,gBAAgB;IAW3B,YAC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IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;YACvB,OAAO;QACT,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE;QACpE,WAAW,CAAC,KAAK,CAAC,kBAAkB,CAAC,GAAG,CACtC,IAAI,CAAC,WAAW,CAAC,IAAI,EACrB,CAAC,MAAM,EAAE,EAAE;YACT,gCAAgC;YAChC,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;iBACxC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;iBACxC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;YAE5D,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC9B,OAAO;YACT,CAAC;YAED,WAAW,CAAC,QAAQ,CAAC,IAAI,CACvB,IAAI,sBAAY,CACd,mLAAmL,IAAA,YAAI,EACrL,UAAU,CACX,OAAO,IAAA,YAAI,EAAC,QAAQ,CAAC,WAAW,IAAA,YAAI,EACnC,aAAa,CACd,oEAAoE,IAAA,YAAI,EACvE,gBAAgB,CACjB,OAAO,IAAA,YAAI,EAAC,SAAS,CAAC,4BAA4B,CACpD,CACF,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { assert, hasProperty, isObject } from '@metamask/utils';\nimport { bold, dim, red, yellow } from 'chalk';\nimport { isBuiltin } from 'module';\nimport type { Ora } from 'ora';\nimport type {\n Compiler,\n ProvidePlugin,\n Resolver,\n StatsError,\n WebpackPluginInstance,\n} from 'webpack';\nimport { WebpackError } from 'webpack';\n\nimport { formatText, pluralize } from './utils';\nimport { evaluate } from '../commands/eval';\nimport { error, getErrorMessage, info, warn } from '../utils';\n\nexport type SnapsStatsPluginOptions = {\n /**\n * Whether to log the verbose stats.\n */\n verbose?: boolean;\n};\n\n/**\n * A plugin that logs the stats after compilation. This is useful for logging\n * the number of files compiled, and the time taken to compile them.\n */\nexport class SnapsStatsPlugin implements WebpackPluginInstance {\n /**\n * The options for the plugin.\n */\n readonly options: SnapsStatsPluginOptions;\n\n /**\n * The spinner to use for logging.\n */\n readonly #spinner?: Ora;\n\n constructor(\n options: SnapsStatsPluginOptions = {\n verbose: false,\n },\n spinner?: Ora,\n ) {\n this.options = options;\n this.#spinner = spinner;\n }\n\n /**\n * Apply the plugin to the Webpack compiler.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n compiler.hooks.afterDone.tap(this.constructor.name, (stats) => {\n if (!stats) {\n return;\n }\n\n const { modules, time, errors, warnings } = stats.toJson();\n\n assert(modules, 'Modules must be defined in stats.');\n assert(time, 'Time must be defined in stats.');\n\n if (errors?.length) {\n const formattedErrors = errors\n .map((statsError) => this.#getStatsErrorMessage(statsError))\n .join('\\n\\n');\n\n error(\n `Compiled ${modules.length} ${pluralize(\n modules.length,\n 'file',\n )} in ${time}ms with ${errors.length} ${pluralize(\n errors.length,\n 'error',\n )}.\\n\\n${formattedErrors}\\n`,\n this.#spinner,\n );\n\n this.#spinner?.stop();\n\n process.exitCode = 1;\n return;\n }\n\n if (warnings?.length) {\n const formattedWarnings = warnings\n .map((statsWarning) =>\n this.#getStatsErrorMessage(statsWarning, yellow),\n )\n .join('\\n\\n');\n\n warn(\n `Compiled ${modules.length} ${pluralize(\n modules.length,\n 'file',\n )} in ${time}ms with ${warnings.length} ${pluralize(\n warnings.length,\n 'warning',\n )}.\\n\\n${formattedWarnings}\\n`,\n this.#spinner,\n );\n } else {\n info(\n `Compiled ${modules.length} ${pluralize(\n modules.length,\n 'file',\n )} in ${time}ms.`,\n this.#spinner,\n );\n }\n\n if (compiler.watchMode) {\n // The spinner may be restarted by the watch plugin, outside of the\n // `executeSteps` flow, so we stop it here just in case.\n this.#spinner?.succeed('Done!');\n }\n });\n }\n\n /**\n * Get the error message for the given stats error.\n *\n * @param statsError - The stats error.\n * @param color - The color to use for the error message.\n * @returns The error message.\n */\n #getStatsErrorMessage(statsError: StatsError, color = red) {\n const baseMessage = this.options.verbose\n ? getErrorMessage(statsError)\n : statsError.message;\n\n const [first, ...rest] = baseMessage.split('\\n');\n\n return [\n color(formatText(`• ${first}`, 4, 2)),\n ...rest.map((message) => formatText(color(message), 4)),\n statsError.details && `\\n${formatText(dim(statsError.details), 6)}`,\n ]\n .filter(Boolean)\n .join('\\n');\n }\n}\n\n/**\n * The options for the {@link SnapsWatchPlugin}.\n */\nexport type SnapsWatchPluginOptions = {\n /**\n * The bundle path. This is the file that will be evaluated, if the `evaluate`\n * option is set.\n */\n bundle?: string;\n\n /**\n * Whether to evaluate the bundle. This only applies if the `bundle` option is\n * set.\n */\n evaluate?: boolean;\n\n /**\n * The extra files to watch.\n */\n files?: string[];\n};\n\n/**\n * A plugin that adds extra files to watch. This is useful for watching files\n * that are not imported by the entry point, such as the `snap.manifest.json`\n * file.\n */\nexport class SnapsWatchPlugin implements WebpackPluginInstance {\n /**\n * The options for the plugin.\n */\n readonly options: SnapsWatchPluginOptions;\n\n /**\n * The spinner to use for logging.\n */\n readonly #spinner?: Ora;\n\n constructor(options: SnapsWatchPluginOptions, spinner?: Ora) {\n this.options = options;\n this.#spinner = spinner;\n }\n\n /**\n * Apply the plugin to the Webpack compiler.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n compiler.hooks.invalid.tap(this.constructor.name, (file) => {\n this.#spinner?.start();\n info(`Changes detected in ${yellow(file)}, recompiling.`, this.#spinner);\n });\n\n compiler.hooks.afterEmit.tapPromise(\n this.constructor.name,\n async ({ fileDependencies }) => {\n this.options.files?.forEach(\n fileDependencies.add.bind(fileDependencies),\n );\n\n if (this.options.bundle && this.options.evaluate) {\n await this.#safeEvaluate(this.options.bundle);\n }\n },\n );\n }\n\n /**\n * Safely evaluate the bundle at the given path. If an error occurs, it will\n * be logged to the console, rather than throwing an error.\n *\n * This function should never throw an error.\n *\n * @param bundlePath - The path to the bundle.\n */\n async #safeEvaluate(bundlePath: string) {\n try {\n await evaluate(bundlePath);\n info(`Snap bundle evaluated successfully.`, this.#spinner);\n } catch (evaluateError) {\n error(evaluateError.message, this.#spinner);\n }\n }\n}\n\n/**\n * The options for the {@link SnapsBuiltInResolver}.\n */\nexport type SnapsBuiltInResolverOptions = {\n /**\n * The built-in modules to ignore.\n */\n ignore?: string[];\n};\n\n/**\n * A Webpack resolve plugin.\n *\n * Copied from Webpack's own types, because the `ResolvePluginInstance` type is\n * a union, and can't be used as a type for a class.\n */\ntype ResolvePlugin = {\n apply: (resolver: Resolver) => void;\n};\n\n/**\n * A plugin that logs a message when a built-in module is not resolved. The\n * MetaMask Snaps CLI does not support built-in modules by default, and this\n * plugin is used to warn the user when they try to import a built-in module,\n * when no fallback is configured.\n */\nexport class SnapsBuiltInResolver implements ResolvePlugin {\n /**\n * The built-in modules that have been imported, but not resolved.\n */\n readonly unresolvedModules = new Set<string>();\n\n /**\n * The name of the resolver hook to tap into.\n */\n readonly #source = 'described-resolve';\n\n /**\n * The options for the plugin.\n */\n readonly options: SnapsBuiltInResolverOptions;\n\n constructor(\n options: SnapsBuiltInResolverOptions = {\n ignore: [],\n },\n ) {\n this.options = options;\n }\n\n /**\n * Apply the plugin to the Webpack resolver.\n *\n * @param resolver - The Webpack resolver.\n */\n apply(resolver: Resolver) {\n resolver\n .getHook(this.#source)\n .tapAsync(\n this.constructor.name,\n ({ module: isModule, request }, _, callback) => {\n if (!isModule || !request) {\n return callback();\n }\n\n const baseRequest = request.split('/')[0];\n if (\n isBuiltin(baseRequest) &&\n !this.options.ignore?.includes(baseRequest)\n ) {\n const fallback = resolver.options.fallback.find(\n ({ name }) => name === baseRequest,\n );\n\n if (fallback && !fallback.alias) {\n this.unresolvedModules.add(baseRequest);\n }\n }\n\n return callback();\n },\n );\n }\n}\n\n/**\n * The options for the {@link SnapsBundleWarningsPlugin}.\n */\nexport type SnapsBundleWarningsPluginOptions = {\n /**\n * The {@link SnapsBuiltInResolver} instance to use for detecting built-in\n * modules.\n */\n builtInResolver?: SnapsBuiltInResolver | false;\n\n /**\n * Whether to show warnings if built-in modules are used, but not provided by\n * Webpack's `fallback` configuration.\n */\n builtIns?: boolean;\n\n /**\n * Whether to show warnings if the `Buffer` global is used, but not provided\n * by Webpack's `DefinePlugin`.\n */\n buffer?: boolean;\n};\n\n/**\n * A plugin that logs a message when:\n *\n * - A built-in module is not resolved. The MetaMask Snaps CLI does not support\n * built-in modules by default, and this plugin is used to warn the user when\n * they try to import a built-in module, when no fallback is configured.\n * - A snap uses the `Buffer` global. The MetaMask Snaps CLI does not support\n * the `Buffer` global by default, and this plugin is used to warn the user when\n * they try to use the `Buffer` global.\n *\n * We use both a resolver and a plugin, because the resolver is used to detect\n * when a built-in module is imported, and the plugin is used to log a single\n * message when the compilation is complete. We can't do everything in a single\n * plugin, because the resolver doesn't have access to the compilation, and the\n * plugin doesn't have access to the resolver.\n */\n\nexport class SnapsBundleWarningsPlugin implements WebpackPluginInstance {\n /**\n * The options for the plugin.\n */\n readonly options: SnapsBundleWarningsPluginOptions;\n\n constructor(\n options: SnapsBundleWarningsPluginOptions = {\n buffer: true,\n builtIns: true,\n },\n ) {\n this.options = options;\n }\n\n /**\n * Apply the plugin to the Webpack compiler.\n *\n * @param compiler - The Webpack compiler.\n */\n apply(compiler: Compiler) {\n if (this.options.builtIns) {\n this.#checkBuiltIns(compiler);\n }\n\n if (this.options.buffer) {\n this.#checkBuffer(compiler);\n }\n }\n\n /**\n * Check if a built-in module is used, but not provided by Webpack's\n * `fallback` configuration.\n *\n * @param compiler - The Webpack compiler.\n */\n #checkBuiltIns(compiler: Compiler) {\n compiler.hooks.afterCompile.tap(this.constructor.name, (compilation) => {\n if (!this.options.builtInResolver) {\n return;\n }\n\n const { unresolvedModules } = this.options.builtInResolver;\n if (unresolvedModules.size === 0) {\n return;\n }\n\n const formattedModules = new Array(...unresolvedModules)\n .map((name) => `• ${name}`)\n .join('\\n');\n\n const webpackError = new WebpackError(\n `The snap attempted to use one or more Node.js builtins, but no browser fallback has been provided. The MetaMask Snaps CLI does not support Node.js builtins by default. If you want to use this module, you must set ${bold(\n '`polyfills`',\n )} to ${bold(\n '`true`',\n )} or an object with the builtins to polyfill as the key and ${bold(\n '`true`',\n )} as the value. To disable this warning, set ${bold(\n '`stats.builtIns`',\n )} to ${bold(\n '`false`',\n )} in your snap config file, or add the module to the ${bold(\n '`stats.builtIns.ignore`',\n )} array.`,\n );\n\n webpackError.details = formattedModules;\n compilation.warnings.push(webpackError);\n });\n }\n\n /**\n * Check if the given instance is a `ProvidePlugin`. This is not guaranteed to\n * be accurate, but it's good enough for our purposes. If we were to use\n * `instanceof` instead, it might not work if multiple versions of Webpack are\n * installed.\n *\n * @param instance - The instance to check.\n * @returns Whether the instance is a `ProvidePlugin`, i.e., whether it's an\n * object with the name `ProvidePlugin` and a `definitions` property.\n */\n #isProvidePlugin(instance: unknown): instance is ProvidePlugin {\n return (\n isObject(instance) &&\n instance.constructor.name === 'ProvidePlugin' &&\n hasProperty(instance, 'definitions')\n );\n }\n\n /**\n * Check if the `Buffer` global is used, but not provided by Webpack's\n * `DefinePlugin`.\n *\n * @param compiler - The Webpack compiler.\n */\n #checkBuffer(compiler: Compiler) {\n const plugin = compiler.options.plugins?.find((instance) =>\n this.#isProvidePlugin(instance),\n ) as ProvidePlugin | undefined;\n\n // If the `ProvidePlugin` is configured to provide `Buffer`, then we don't\n // need to warn the user.\n if (plugin) {\n const { definitions } = plugin;\n if (definitions.Buffer) {\n return;\n }\n }\n\n compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {\n compilation.hooks.afterProcessAssets.tap(\n this.constructor.name,\n (assets) => {\n // Check if assets use `Buffer`.\n const bufferAssets = Object.entries(assets)\n .filter(([name]) => name.endsWith('.js'))\n .filter(([, asset]) => asset.source().includes('Buffer'));\n\n if (bufferAssets.length === 0) {\n return;\n }\n\n compilation.warnings.push(\n new WebpackError(\n `The snap attempted to use the Node.js Buffer global, which is not supported in the MetaMask Snaps CLI by default. To use the Buffer global, you must polyfill Buffer by setting ${bold(\n '`buffer`',\n )} to ${bold('`true`')} in the ${bold(\n '`polyfills`',\n )} config object in your snap config. To disable this warning, set ${bold(\n '`stats.buffer`',\n )} to ${bold('`false`')} in your snap config file.`,\n ),\n );\n },\n );\n });\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Ora } from "ora/index.js";
|
|
2
|
-
import type { Compiler,
|
|
2
|
+
import type { Compiler, Resolver, WebpackPluginInstance } from "webpack";
|
|
3
3
|
export type SnapsStatsPluginOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* Whether to log the verbose stats.
|
|
@@ -71,13 +71,22 @@ export type SnapsBuiltInResolverOptions = {
|
|
|
71
71
|
*/
|
|
72
72
|
ignore?: string[];
|
|
73
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* A Webpack resolve plugin.
|
|
76
|
+
*
|
|
77
|
+
* Copied from Webpack's own types, because the `ResolvePluginInstance` type is
|
|
78
|
+
* a union, and can't be used as a type for a class.
|
|
79
|
+
*/
|
|
80
|
+
type ResolvePlugin = {
|
|
81
|
+
apply: (resolver: Resolver) => void;
|
|
82
|
+
};
|
|
74
83
|
/**
|
|
75
84
|
* A plugin that logs a message when a built-in module is not resolved. The
|
|
76
85
|
* MetaMask Snaps CLI does not support built-in modules by default, and this
|
|
77
86
|
* plugin is used to warn the user when they try to import a built-in module,
|
|
78
87
|
* when no fallback is configured.
|
|
79
88
|
*/
|
|
80
|
-
export declare class SnapsBuiltInResolver implements
|
|
89
|
+
export declare class SnapsBuiltInResolver implements ResolvePlugin {
|
|
81
90
|
#private;
|
|
82
91
|
/**
|
|
83
92
|
* The built-in modules that have been imported, but not resolved.
|
|
@@ -87,7 +96,7 @@ export declare class SnapsBuiltInResolver implements ResolvePluginInstance {
|
|
|
87
96
|
* The options for the plugin.
|
|
88
97
|
*/
|
|
89
98
|
readonly options: SnapsBuiltInResolverOptions;
|
|
90
|
-
constructor(options?: SnapsBuiltInResolverOptions
|
|
99
|
+
constructor(options?: SnapsBuiltInResolverOptions);
|
|
91
100
|
/**
|
|
92
101
|
* Apply the plugin to the Webpack resolver.
|
|
93
102
|
*
|
|
@@ -145,4 +154,5 @@ export declare class SnapsBundleWarningsPlugin implements WebpackPluginInstance
|
|
|
145
154
|
*/
|
|
146
155
|
apply(compiler: Compiler): void;
|
|
147
156
|
}
|
|
157
|
+
export {};
|
|
148
158
|
//# sourceMappingURL=plugins.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.d.cts","sourceRoot":"","sources":["../../src/webpack/plugins.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAC/B,OAAO,KAAK,EACV,QAAQ,EAER,
|
|
1
|
+
{"version":3,"file":"plugins.d.cts","sourceRoot":"","sources":["../../src/webpack/plugins.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAC/B,OAAO,KAAK,EACV,QAAQ,EAER,QAAQ,EAER,qBAAqB,EACtB,gBAAgB;AAOjB,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;GAGG;AACH,qBAAa,gBAAiB,YAAW,qBAAqB;;IAC5D;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,uBAAuB,CAAC;gBAQxC,OAAO,GAAE,uBAER,EACD,OAAO,CAAC,EAAE,GAAG;IAMf;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,QAAQ;CA0FzB;AAED;;GAEG;AACH,MAAM,MAAM,uBAAuB,G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O,GAAE,gCAGR;IAKH;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,QAAQ;CAsHzB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Ora } from "ora/index.js";
|
|
2
|
-
import type { Compiler,
|
|
2
|
+
import type { Compiler, Resolver, WebpackPluginInstance } from "webpack";
|
|
3
3
|
export type SnapsStatsPluginOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* Whether to log the verbose stats.
|
|
@@ -71,13 +71,22 @@ export type SnapsBuiltInResolverOptions = {
|
|
|
71
71
|
*/
|
|
72
72
|
ignore?: string[];
|
|
73
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* A Webpack resolve plugin.
|
|
76
|
+
*
|
|
77
|
+
* Copied from Webpack's own types, because the `ResolvePluginInstance` type is
|
|
78
|
+
* a union, and can't be used as a type for a class.
|
|
79
|
+
*/
|
|
80
|
+
type ResolvePlugin = {
|
|
81
|
+
apply: (resolver: Resolver) => void;
|
|
82
|
+
};
|
|
74
83
|
/**
|
|
75
84
|
* A plugin that logs a message when a built-in module is not resolved. The
|
|
76
85
|
* MetaMask Snaps CLI does not support built-in modules by default, and this
|
|
77
86
|
* plugin is used to warn the user when they try to import a built-in module,
|
|
78
87
|
* when no fallback is configured.
|
|
79
88
|
*/
|
|
80
|
-
export declare class SnapsBuiltInResolver implements
|
|
89
|
+
export declare class SnapsBuiltInResolver implements ResolvePlugin {
|
|
81
90
|
#private;
|
|
82
91
|
/**
|
|
83
92
|
* The built-in modules that have been imported, but not resolved.
|
|
@@ -87,7 +96,7 @@ export declare class SnapsBuiltInResolver implements ResolvePluginInstance {
|
|
|
87
96
|
* The options for the plugin.
|
|
88
97
|
*/
|
|
89
98
|
readonly options: SnapsBuiltInResolverOptions;
|
|
90
|
-
constructor(options?: SnapsBuiltInResolverOptions
|
|
99
|
+
constructor(options?: SnapsBuiltInResolverOptions);
|
|
91
100
|
/**
|
|
92
101
|
* Apply the plugin to the Webpack resolver.
|
|
93
102
|
*
|
|
@@ -145,4 +154,5 @@ export declare class SnapsBundleWarningsPlugin implements WebpackPluginInstance
|
|
|
145
154
|
*/
|
|
146
155
|
apply(compiler: Compiler): void;
|
|
147
156
|
}
|
|
157
|
+
export {};
|
|
148
158
|
//# sourceMappingURL=plugins.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.d.mts","sourceRoot":"","sources":["../../src/webpack/plugins.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAC/B,OAAO,KAAK,EACV,QAAQ,EAER,
|
|
1
|
+
{"version":3,"file":"plugins.d.mts","sourceRoot":"","sources":["../../src/webpack/plugins.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAC/B,OAAO,KAAK,EACV,QAAQ,EAER,QAAQ,EAER,qBAAqB,EACtB,gBAAgB;AAOjB,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;GAGG;AACH,qBAAa,gBAAiB,YAAW,qBAAqB;;IAC5D;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,uBAAuB,CAAC;gBAQxC,OAAO,GAAE,uBAER,EACD,OAAO,CAAC,EAAE,GAAG;IAMf;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,QAAQ;CA0FzB;AAED;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,qBAAa,gBAAiB,YAAW,qBAAqB;;IAC5D;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,uBAAuB,CAAC;gBAO9B,OAAO,EAAE,uBAAuB,EAAE,OAAO,CAAC,EAAE,GAAG;IAK3D;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,QAAQ;CAoCzB;AAED;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC;AAEF;;;;;GAKG;AACH,KAAK,aAAa,GAAG;IACnB,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;CACrC,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,aAAa;;IACxD;;OAEG;IACH,QAAQ,CAAC,iBAAiB,cAAqB;IAO/C;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,2BAA2B,CAAC;gBAG5C,OAAO,GAAE,2BAER;IAKH;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,QAAQ;CA4BzB;AAED;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C;;;OAGG;IACH,eAAe,CAAC,EAAE,oBAAoB,GAAG,KAAK,CAAC;IAE/C;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AAEH,qBAAa,yBAA0B,YAAW,qBAAqB;;IACrE;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,gCAAgC,CAAC;gBAGjD,OAAO,GAAE,gCAGR;IAKH;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,QAAQ;CAsHzB"}
|
package/dist/webpack/plugins.mjs
CHANGED
|
@@ -9,16 +9,16 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _SnapsStatsPlugin_instances, _SnapsStatsPlugin_spinner, _SnapsStatsPlugin_getStatsErrorMessage, _SnapsWatchPlugin_instances, _SnapsWatchPlugin_spinner, _SnapsWatchPlugin_safeEvaluate, _SnapsBuiltInResolver_source,
|
|
12
|
+
var _SnapsStatsPlugin_instances, _SnapsStatsPlugin_spinner, _SnapsStatsPlugin_getStatsErrorMessage, _SnapsWatchPlugin_instances, _SnapsWatchPlugin_spinner, _SnapsWatchPlugin_safeEvaluate, _SnapsBuiltInResolver_source, _SnapsBundleWarningsPlugin_instances, _SnapsBundleWarningsPlugin_checkBuiltIns, _SnapsBundleWarningsPlugin_isProvidePlugin, _SnapsBundleWarningsPlugin_checkBuffer;
|
|
13
13
|
import { assert, hasProperty, isObject } from "@metamask/utils";
|
|
14
14
|
import $chalk from "chalk";
|
|
15
15
|
const { bold, dim, red, yellow } = $chalk;
|
|
16
16
|
import { isBuiltin } from "module";
|
|
17
17
|
import $webpack from "webpack";
|
|
18
18
|
const { WebpackError } = $webpack;
|
|
19
|
+
import { formatText, pluralize } from "./utils.mjs";
|
|
19
20
|
import { evaluate } from "../commands/eval/index.mjs";
|
|
20
21
|
import { error, getErrorMessage, info, warn } from "../utils/index.mjs";
|
|
21
|
-
import { formatText, pluralize } from "./utils.mjs";
|
|
22
22
|
/**
|
|
23
23
|
* A plugin that logs the stats after compilation. This is useful for logging
|
|
24
24
|
* the number of files compiled, and the time taken to compile them.
|
|
@@ -147,7 +147,7 @@ async function _SnapsWatchPlugin_safeEvaluate(bundlePath) {
|
|
|
147
147
|
export class SnapsBuiltInResolver {
|
|
148
148
|
constructor(options = {
|
|
149
149
|
ignore: [],
|
|
150
|
-
}
|
|
150
|
+
}) {
|
|
151
151
|
/**
|
|
152
152
|
* The built-in modules that have been imported, but not resolved.
|
|
153
153
|
*/
|
|
@@ -156,12 +156,7 @@ export class SnapsBuiltInResolver {
|
|
|
156
156
|
* The name of the resolver hook to tap into.
|
|
157
157
|
*/
|
|
158
158
|
_SnapsBuiltInResolver_source.set(this, 'described-resolve');
|
|
159
|
-
/**
|
|
160
|
-
* The spinner to use for logging.
|
|
161
|
-
*/
|
|
162
|
-
_SnapsBuiltInResolver_spinner.set(this, void 0);
|
|
163
159
|
this.options = options;
|
|
164
|
-
__classPrivateFieldSet(this, _SnapsBuiltInResolver_spinner, spinner, "f");
|
|
165
160
|
}
|
|
166
161
|
/**
|
|
167
162
|
* Apply the plugin to the Webpack resolver.
|
|
@@ -187,7 +182,7 @@ export class SnapsBuiltInResolver {
|
|
|
187
182
|
});
|
|
188
183
|
}
|
|
189
184
|
}
|
|
190
|
-
_SnapsBuiltInResolver_source = new WeakMap()
|
|
185
|
+
_SnapsBuiltInResolver_source = new WeakMap();
|
|
191
186
|
/**
|
|
192
187
|
* A plugin that logs a message when:
|
|
193
188
|
*
|