@metamask/snaps-cli 6.3.0 → 6.3.2
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 +14 -1
- package/dist/__fixtures__/configs/cjs.cjs +9 -0
- package/dist/__fixtures__/configs/cjs.cjs.map +1 -0
- package/dist/__fixtures__/configs/cjs.d.cts +2 -0
- package/dist/__fixtures__/configs/cjs.d.cts.map +1 -0
- package/dist/__fixtures__/configs/cjs.d.mts +2 -0
- package/dist/__fixtures__/configs/cjs.d.mts.map +1 -0
- package/dist/__fixtures__/configs/cjs.mjs +8 -0
- package/dist/__fixtures__/configs/cjs.mjs.map +1 -0
- package/dist/__fixtures__/configs/esm.cjs +7 -0
- package/dist/__fixtures__/configs/esm.cjs.map +1 -0
- package/dist/__fixtures__/configs/esm.d.cts +4 -0
- package/dist/__fixtures__/configs/esm.d.cts.map +1 -0
- package/dist/__fixtures__/configs/esm.d.mts +4 -0
- package/dist/__fixtures__/configs/esm.d.mts.map +1 -0
- package/dist/__fixtures__/configs/esm.mjs +5 -0
- package/dist/__fixtures__/configs/esm.mjs.map +1 -0
- package/dist/__fixtures__/configs/invalid.cjs +8 -0
- package/dist/__fixtures__/configs/invalid.cjs.map +1 -0
- package/dist/__fixtures__/configs/invalid.d.cts +4 -0
- package/dist/__fixtures__/configs/invalid.d.cts.map +1 -0
- package/dist/__fixtures__/configs/invalid.d.mts +4 -0
- package/dist/__fixtures__/configs/invalid.d.mts.map +1 -0
- package/dist/__fixtures__/configs/invalid.mjs +6 -0
- package/dist/__fixtures__/configs/invalid.mjs.map +1 -0
- package/dist/__fixtures__/configs/javascript/snap.config.cjs +6 -0
- package/dist/__fixtures__/configs/javascript/snap.config.cjs.map +1 -0
- package/dist/__fixtures__/configs/javascript/snap.config.d.cts +2 -0
- package/dist/__fixtures__/configs/javascript/snap.config.d.cts.map +1 -0
- package/dist/__fixtures__/configs/javascript/snap.config.d.mts +2 -0
- package/dist/__fixtures__/configs/javascript/snap.config.d.mts.map +1 -0
- package/dist/__fixtures__/configs/javascript/snap.config.mjs +5 -0
- package/dist/__fixtures__/configs/javascript/snap.config.mjs.map +1 -0
- package/dist/__fixtures__/configs/typescript/snap.config.cjs +7 -0
- package/dist/__fixtures__/configs/typescript/snap.config.cjs.map +1 -0
- package/dist/__fixtures__/configs/typescript/snap.config.d.cts +4 -0
- package/dist/__fixtures__/configs/typescript/snap.config.d.cts.map +1 -0
- package/dist/__fixtures__/configs/typescript/snap.config.d.mts +4 -0
- package/dist/__fixtures__/configs/typescript/snap.config.d.mts.map +1 -0
- package/dist/__fixtures__/configs/typescript/snap.config.mjs +5 -0
- package/dist/__fixtures__/configs/typescript/snap.config.mjs.map +1 -0
- package/dist/builders.cjs +132 -0
- package/dist/builders.cjs.map +1 -0
- package/dist/{types/builders.d.ts → builders.d.cts} +2 -1
- package/dist/builders.d.cts.map +1 -0
- package/dist/builders.d.mts +9 -0
- package/dist/builders.d.mts.map +1 -0
- package/dist/builders.mjs +127 -8
- package/dist/builders.mjs.map +1 -1
- package/dist/cli.cjs +71 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/{types/cli.d.ts → cli.d.cts} +1 -0
- package/dist/cli.d.cts.map +1 -0
- package/dist/cli.d.mts +16 -0
- package/dist/cli.d.mts.map +1 -0
- package/dist/cli.mjs +69 -20
- package/dist/cli.mjs.map +1 -1
- package/dist/commands/build/build.cjs +53 -0
- package/dist/commands/build/build.cjs.map +1 -0
- package/dist/{types/commands/build/build.d.ts → commands/build/build.d.cts} +3 -1
- package/dist/commands/build/build.d.cts.map +1 -0
- package/dist/commands/build/build.d.mts +12 -0
- package/dist/commands/build/build.d.mts.map +1 -0
- package/dist/commands/build/build.mjs +48 -28
- package/dist/commands/build/build.mjs.map +1 -1
- package/dist/commands/build/implementation.cjs +31 -0
- package/dist/commands/build/implementation.cjs.map +1 -0
- package/dist/{types/commands/build/implementation.d.ts → commands/build/implementation.d.cts} +3 -2
- package/dist/commands/build/implementation.d.cts.map +1 -0
- package/dist/commands/build/implementation.d.mts +11 -0
- package/dist/commands/build/implementation.d.mts.map +1 -0
- package/dist/commands/build/implementation.mjs +26 -27
- package/dist/commands/build/implementation.mjs.map +1 -1
- package/dist/commands/build/index.cjs +44 -0
- package/dist/commands/build/index.cjs.map +1 -0
- package/dist/{types/commands/eval/index.d.ts → commands/build/index.d.cts} +4 -3
- package/dist/commands/build/index.d.cts.map +1 -0
- package/dist/{types/commands/manifest/index.d.ts → commands/build/index.d.mts} +4 -3
- package/dist/commands/build/index.d.mts.map +1 -0
- package/dist/commands/build/index.mjs +23 -31
- package/dist/commands/build/index.mjs.map +1 -1
- package/dist/commands/eval/__test__/browserify/bad/snap.config.cjs +10 -0
- package/dist/commands/eval/__test__/browserify/bad/snap.config.cjs.map +1 -0
- package/dist/commands/eval/__test__/browserify/bad/snap.config.d.cts +4 -0
- package/dist/commands/eval/__test__/browserify/bad/snap.config.d.cts.map +1 -0
- package/dist/commands/eval/__test__/browserify/bad/snap.config.d.mts +4 -0
- package/dist/commands/eval/__test__/browserify/bad/snap.config.d.mts.map +1 -0
- package/dist/commands/eval/__test__/browserify/bad/snap.config.mjs +8 -0
- package/dist/commands/eval/__test__/browserify/bad/snap.config.mjs.map +1 -0
- package/dist/commands/eval/__test__/browserify/good/snap.config.cjs +10 -0
- package/dist/commands/eval/__test__/browserify/good/snap.config.cjs.map +1 -0
- package/dist/commands/eval/__test__/browserify/good/snap.config.d.cts +4 -0
- package/dist/commands/eval/__test__/browserify/good/snap.config.d.cts.map +1 -0
- package/dist/commands/eval/__test__/browserify/good/snap.config.d.mts +4 -0
- package/dist/commands/eval/__test__/browserify/good/snap.config.d.mts.map +1 -0
- package/dist/commands/eval/__test__/browserify/good/snap.config.mjs +8 -0
- package/dist/commands/eval/__test__/browserify/good/snap.config.mjs.map +1 -0
- package/dist/commands/eval/__test__/webpack/bad/snap.config.cjs +12 -0
- package/dist/commands/eval/__test__/webpack/bad/snap.config.cjs.map +1 -0
- package/dist/commands/eval/__test__/webpack/bad/snap.config.d.cts +4 -0
- package/dist/commands/eval/__test__/webpack/bad/snap.config.d.cts.map +1 -0
- package/dist/commands/eval/__test__/webpack/bad/snap.config.d.mts +4 -0
- package/dist/commands/eval/__test__/webpack/bad/snap.config.d.mts.map +1 -0
- package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs +10 -0
- package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs.map +1 -0
- package/dist/commands/eval/__test__/webpack/good/snap.config.cjs +12 -0
- package/dist/commands/eval/__test__/webpack/good/snap.config.cjs.map +1 -0
- package/dist/commands/eval/__test__/webpack/good/snap.config.d.cts +4 -0
- package/dist/commands/eval/__test__/webpack/good/snap.config.d.cts.map +1 -0
- package/dist/commands/eval/__test__/webpack/good/snap.config.d.mts +4 -0
- package/dist/commands/eval/__test__/webpack/good/snap.config.d.mts.map +1 -0
- package/dist/commands/eval/__test__/webpack/good/snap.config.mjs +10 -0
- package/dist/commands/eval/__test__/webpack/good/snap.config.mjs.map +1 -0
- package/dist/commands/eval/__test__/webpack/snap.config.cjs +8 -0
- package/dist/commands/eval/__test__/webpack/snap.config.cjs.map +1 -0
- package/dist/commands/eval/__test__/webpack/snap.config.d.cts +4 -0
- package/dist/commands/eval/__test__/webpack/snap.config.d.cts.map +1 -0
- package/dist/commands/eval/__test__/webpack/snap.config.d.mts +4 -0
- package/dist/commands/eval/__test__/webpack/snap.config.d.mts.map +1 -0
- package/dist/commands/eval/__test__/webpack/snap.config.mjs +6 -0
- package/dist/commands/eval/__test__/webpack/snap.config.mjs.map +1 -0
- package/dist/commands/eval/eval.cjs +57 -0
- package/dist/commands/eval/eval.cjs.map +1 -0
- package/dist/{types/commands/eval/eval.d.ts → commands/eval/eval.d.cts} +2 -1
- package/dist/commands/eval/eval.d.cts.map +1 -0
- package/dist/commands/eval/eval.d.mts +15 -0
- package/dist/commands/eval/eval.d.mts.map +1 -0
- package/dist/commands/eval/eval.mjs +52 -17
- package/dist/commands/eval/eval.mjs.map +1 -1
- package/dist/commands/eval/implementation.cjs +30 -0
- package/dist/commands/eval/implementation.cjs.map +1 -0
- package/dist/{types/commands/eval/implementation.d.ts → commands/eval/implementation.d.cts} +2 -0
- package/dist/commands/eval/implementation.d.cts.map +1 -0
- package/dist/commands/eval/implementation.d.mts +11 -0
- package/dist/commands/eval/implementation.d.mts.map +1 -0
- package/dist/commands/eval/implementation.mjs +26 -8
- package/dist/commands/eval/implementation.mjs.map +1 -1
- package/dist/commands/eval/index.cjs +35 -0
- package/dist/commands/eval/index.cjs.map +1 -0
- package/dist/commands/eval/index.d.cts +11 -0
- package/dist/commands/eval/index.d.cts.map +1 -0
- package/dist/commands/eval/index.d.mts +11 -0
- package/dist/commands/eval/index.d.mts.map +1 -0
- package/dist/commands/eval/index.mjs +14 -20
- package/dist/commands/eval/index.mjs.map +1 -1
- package/dist/commands/index.cjs +19 -0
- package/dist/commands/index.cjs.map +1 -0
- package/dist/{types/commands/index.d.ts → commands/index.d.cts} +1 -0
- package/dist/commands/index.d.cts.map +1 -0
- package/dist/commands/index.d.mts +9 -0
- package/dist/commands/index.d.mts.map +1 -0
- package/dist/commands/index.mjs +13 -38
- package/dist/commands/index.mjs.map +1 -1
- package/dist/commands/manifest/implementation.cjs +64 -0
- package/dist/commands/manifest/implementation.cjs.map +1 -0
- package/dist/{types/commands/manifest/implementation.d.ts → commands/manifest/implementation.d.cts} +3 -1
- package/dist/commands/manifest/implementation.d.cts.map +1 -0
- package/dist/commands/manifest/implementation.d.mts +14 -0
- package/dist/commands/manifest/implementation.d.mts.map +1 -0
- package/dist/commands/manifest/implementation.mjs +60 -16
- package/dist/commands/manifest/implementation.mjs.map +1 -1
- package/dist/commands/manifest/index.cjs +35 -0
- package/dist/commands/manifest/index.cjs.map +1 -0
- package/dist/commands/manifest/index.d.cts +11 -0
- package/dist/commands/manifest/index.d.cts.map +1 -0
- package/dist/commands/manifest/index.d.mts +11 -0
- package/dist/commands/manifest/index.d.mts.map +1 -0
- package/dist/commands/manifest/index.mjs +14 -20
- package/dist/commands/manifest/index.mjs.map +1 -1
- package/dist/commands/manifest/manifest.cjs +57 -0
- package/dist/commands/manifest/manifest.cjs.map +1 -0
- package/dist/{types/commands/manifest/manifest.d.ts → commands/manifest/manifest.d.cts} +2 -1
- package/dist/commands/manifest/manifest.d.cts.map +1 -0
- package/dist/commands/manifest/manifest.d.mts +15 -0
- package/dist/commands/manifest/manifest.d.mts.map +1 -0
- package/dist/commands/manifest/manifest.mjs +52 -17
- package/dist/commands/manifest/manifest.mjs.map +1 -1
- package/dist/commands/serve/index.cjs +19 -0
- package/dist/commands/serve/index.cjs.map +1 -0
- package/dist/{types/commands/serve/index.d.ts → commands/serve/index.d.cts} +3 -2
- package/dist/commands/serve/index.d.cts.map +1 -0
- package/dist/{types/commands/build/index.d.ts → commands/serve/index.d.mts} +3 -3
- package/dist/commands/serve/index.d.mts.map +1 -0
- package/dist/commands/serve/index.mjs +12 -27
- package/dist/commands/serve/index.mjs.map +1 -1
- package/dist/commands/serve/serve.cjs +21 -0
- package/dist/commands/serve/serve.cjs.map +1 -0
- package/dist/{types/commands/serve/serve.d.ts → commands/serve/serve.d.cts} +2 -1
- package/dist/commands/serve/serve.d.cts.map +1 -0
- package/dist/commands/serve/serve.d.mts +17 -0
- package/dist/commands/serve/serve.d.mts.map +1 -0
- package/dist/commands/serve/serve.mjs +16 -27
- package/dist/commands/serve/serve.mjs.map +1 -1
- package/dist/commands/watch/implementation.cjs +38 -0
- package/dist/{chunk-BAEGXYL7.mjs.map → commands/watch/implementation.cjs.map} +1 -1
- package/dist/{types/commands/watch/implementation.d.ts → commands/watch/implementation.d.cts} +4 -3
- package/dist/commands/watch/implementation.d.cts.map +1 -0
- package/dist/commands/watch/implementation.d.mts +15 -0
- package/dist/commands/watch/implementation.d.mts.map +1 -0
- package/dist/commands/watch/implementation.mjs +33 -27
- package/dist/commands/watch/implementation.mjs.map +1 -1
- package/dist/commands/watch/index.cjs +49 -0
- package/dist/commands/watch/index.cjs.map +1 -0
- package/dist/commands/watch/index.d.cts +11 -0
- package/dist/commands/watch/index.d.cts.map +1 -0
- package/dist/commands/watch/index.d.mts +11 -0
- package/dist/commands/watch/index.d.mts.map +1 -0
- package/dist/commands/watch/index.mjs +28 -31
- package/dist/commands/watch/index.mjs.map +1 -1
- package/dist/commands/watch/watch.cjs +49 -0
- package/dist/commands/watch/watch.cjs.map +1 -0
- package/dist/{types/commands/watch/watch.d.ts → commands/watch/watch.d.cts} +2 -1
- package/dist/commands/watch/watch.d.cts.map +1 -0
- package/dist/commands/watch/watch.d.mts +20 -0
- package/dist/commands/watch/watch.d.mts.map +1 -0
- package/dist/commands/watch/watch.mjs +44 -28
- package/dist/commands/watch/watch.mjs.map +1 -1
- package/dist/config.cjs +334 -0
- package/dist/config.cjs.map +1 -0
- package/dist/{types/config.d.ts → config.d.cts} +44 -43
- package/dist/config.d.cts.map +1 -0
- package/dist/config.d.mts +821 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +322 -35
- package/dist/config.mjs.map +1 -1
- package/dist/errors.cjs +38 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/{types/errors.d.ts → errors.d.cts} +1 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +26 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +32 -11
- package/dist/errors.mjs.map +1 -1
- package/dist/index.cjs +39 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4 -44
- package/dist/index.mjs.map +1 -1
- package/dist/main.cjs +24 -0
- package/dist/main.cjs.map +1 -0
- package/dist/main.d.cts +3 -0
- package/dist/main.d.cts.map +1 -0
- package/dist/main.d.mts +3 -0
- package/dist/main.d.mts.map +1 -0
- package/dist/main.mjs +15 -45
- package/dist/main.mjs.map +1 -1
- package/dist/structs.cjs +31 -0
- package/dist/structs.cjs.map +1 -0
- package/dist/{types/structs.d.ts → structs.d.cts} +1 -0
- package/dist/structs.d.cts.map +1 -0
- package/dist/structs.d.mts +21 -0
- package/dist/structs.d.mts.map +1 -0
- package/dist/structs.mjs +26 -7
- package/dist/structs.mjs.map +1 -1
- package/dist/utils/cli.cjs +52 -0
- package/dist/utils/cli.cjs.map +1 -0
- package/dist/{types/utils/cli.d.ts → utils/cli.d.cts} +1 -0
- package/dist/utils/cli.d.cts.map +1 -0
- package/dist/utils/cli.d.mts +18 -0
- package/dist/utils/cli.d.mts.map +1 -0
- package/dist/utils/cli.mjs +43 -13
- package/dist/utils/cli.mjs.map +1 -1
- package/dist/utils/errors.cjs +49 -0
- package/dist/utils/errors.cjs.map +1 -0
- package/dist/{types/utils/errors.d.ts → utils/errors.d.cts} +1 -0
- package/dist/utils/errors.d.cts.map +1 -0
- package/dist/utils/errors.d.mts +24 -0
- package/dist/utils/errors.d.mts.map +1 -0
- package/dist/utils/errors.mjs +43 -10
- package/dist/utils/errors.mjs.map +1 -1
- package/dist/utils/index.cjs +23 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +7 -0
- package/dist/utils/index.d.cts.map +1 -0
- package/dist/utils/index.d.mts +7 -0
- package/dist/utils/index.d.mts.map +1 -0
- package/dist/utils/index.mjs +6 -46
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/legacy.cjs +53 -0
- package/dist/utils/legacy.cjs.map +1 -0
- package/dist/{types/utils/legacy.d.ts → utils/legacy.d.cts} +2 -1
- package/dist/utils/legacy.d.cts.map +1 -0
- package/dist/utils/legacy.d.mts +28 -0
- package/dist/utils/legacy.d.mts.map +1 -0
- package/dist/utils/legacy.mjs +46 -12
- package/dist/utils/legacy.mjs.map +1 -1
- package/dist/utils/logging.cjs +48 -0
- package/dist/utils/logging.cjs.map +1 -0
- package/dist/{types/utils/logging.d.ts → utils/logging.d.cts} +2 -1
- package/dist/utils/logging.d.cts.map +1 -0
- package/dist/utils/logging.d.mts +23 -0
- package/dist/utils/logging.d.mts.map +1 -0
- package/dist/utils/logging.mjs +42 -11
- package/dist/utils/logging.mjs.map +1 -1
- package/dist/utils/path.cjs +17 -0
- package/dist/utils/path.cjs.map +1 -0
- package/dist/{types/utils/path.d.ts → utils/path.d.cts} +1 -0
- package/dist/utils/path.d.cts.map +1 -0
- package/dist/utils/path.d.mts +10 -0
- package/dist/utils/path.d.mts.map +1 -0
- package/dist/utils/path.mjs +12 -7
- package/dist/utils/path.mjs.map +1 -1
- package/dist/utils/steps.cjs +51 -0
- package/dist/utils/steps.cjs.map +1 -0
- package/dist/{types/utils/steps.d.ts → utils/steps.d.cts} +2 -1
- package/dist/utils/steps.d.cts.map +1 -0
- package/dist/utils/steps.d.mts +18 -0
- package/dist/utils/steps.d.mts.map +1 -0
- package/dist/utils/steps.mjs +51 -10
- package/dist/utils/steps.mjs.map +1 -1
- package/dist/webpack/compiler.cjs +19 -0
- package/dist/webpack/compiler.cjs.map +1 -0
- package/dist/{types/webpack/compiler.d.ts → webpack/compiler.d.cts} +3 -2
- package/dist/webpack/compiler.d.cts.map +1 -0
- package/dist/webpack/compiler.d.mts +11 -0
- package/dist/webpack/compiler.d.mts.map +1 -0
- package/dist/webpack/compiler.mjs +15 -24
- package/dist/webpack/compiler.mjs.map +1 -1
- package/dist/webpack/config.cjs +349 -0
- package/dist/webpack/config.cjs.map +1 -0
- package/dist/{types/webpack/config.d.ts → webpack/config.d.cts} +4 -3
- package/dist/webpack/config.d.cts.map +1 -0
- package/dist/webpack/config.d.mts +38 -0
- package/dist/webpack/config.d.mts.map +1 -0
- package/dist/webpack/config.mjs +349 -23
- package/dist/webpack/config.mjs.map +1 -1
- package/dist/webpack/index.cjs +21 -0
- package/dist/webpack/index.cjs.map +1 -0
- package/dist/webpack/index.d.cts +5 -0
- package/dist/webpack/index.d.cts.map +1 -0
- package/dist/webpack/index.d.mts +5 -0
- package/dist/webpack/index.d.mts.map +1 -0
- package/dist/webpack/index.mjs +4 -43
- package/dist/webpack/index.mjs.map +1 -1
- package/dist/webpack/loaders/browserify.cjs +84 -0
- package/dist/webpack/loaders/browserify.cjs.map +1 -0
- package/dist/{types/webpack/loaders/browserify.d.ts → webpack/loaders/browserify.d.cts} +4 -2
- package/dist/webpack/loaders/browserify.d.cts.map +1 -0
- package/dist/webpack/loaders/browserify.d.mts +18 -0
- package/dist/webpack/loaders/browserify.d.mts.map +1 -0
- package/dist/webpack/loaders/browserify.mjs +84 -17
- package/dist/webpack/loaders/browserify.mjs.map +1 -1
- package/dist/webpack/loaders/function.cjs +45 -0
- package/dist/webpack/loaders/function.cjs.map +1 -0
- package/dist/{types/webpack/loaders/function.d.ts → webpack/loaders/function.d.cts} +2 -1
- package/dist/webpack/loaders/function.d.cts.map +1 -0
- package/dist/webpack/loaders/function.d.mts +35 -0
- package/dist/webpack/loaders/function.d.mts.map +1 -0
- package/dist/webpack/loaders/function.mjs +39 -8
- package/dist/webpack/loaders/function.mjs.map +1 -1
- package/dist/webpack/loaders/index.cjs +26 -0
- package/dist/webpack/loaders/index.cjs.map +1 -0
- package/dist/webpack/loaders/index.d.cts +4 -0
- package/dist/webpack/loaders/index.d.cts.map +1 -0
- package/dist/webpack/loaders/index.d.mts +4 -0
- package/dist/webpack/loaders/index.d.mts.map +1 -0
- package/dist/webpack/loaders/index.mjs +3 -24
- package/dist/webpack/loaders/index.mjs.map +1 -1
- package/dist/webpack/loaders/wasm.cjs +103 -0
- package/dist/webpack/loaders/wasm.cjs.map +1 -0
- package/dist/{types/webpack/loaders/wasm.d.ts → webpack/loaders/wasm.d.cts} +2 -1
- package/dist/webpack/loaders/wasm.d.cts.map +1 -0
- package/dist/webpack/loaders/wasm.d.mts +43 -0
- package/dist/webpack/loaders/wasm.d.mts.map +1 -0
- package/dist/webpack/loaders/wasm.mjs +95 -14
- package/dist/webpack/loaders/wasm.mjs.map +1 -1
- package/dist/webpack/plugins.cjs +277 -0
- package/dist/webpack/plugins.cjs.map +1 -0
- package/dist/{types/webpack/plugins.d.ts → webpack/plugins.d.cts} +3 -2
- package/dist/webpack/plugins.d.cts.map +1 -0
- package/dist/webpack/plugins.d.mts +148 -0
- package/dist/webpack/plugins.d.mts.map +1 -0
- package/dist/webpack/plugins.mjs +270 -27
- package/dist/webpack/plugins.mjs.map +1 -1
- package/dist/webpack/server.cjs +144 -0
- package/dist/webpack/server.cjs.map +1 -0
- package/dist/{types/webpack/server.d.ts → webpack/server.d.cts} +5 -3
- package/dist/webpack/server.d.cts.map +1 -0
- package/dist/webpack/server.d.mts +32 -0
- package/dist/webpack/server.d.mts.map +1 -0
- package/dist/webpack/server.mjs +142 -9
- package/dist/webpack/server.mjs.map +1 -1
- package/dist/webpack/utils.cjs +359 -0
- package/dist/webpack/utils.cjs.map +1 -0
- package/dist/{types/webpack/utils.d.ts → webpack/utils.d.cts} +4 -3
- package/dist/webpack/utils.d.cts.map +1 -0
- package/dist/webpack/utils.d.mts +259 -0
- package/dist/webpack/utils.d.mts.map +1 -0
- package/dist/webpack/utils.mjs +350 -37
- package/dist/webpack/utils.mjs.map +1 -1
- package/package.json +22 -22
- package/dist/builders.js +0 -10
- package/dist/builders.js.map +0 -1
- package/dist/chunk-24QJ2ZUZ.mjs +0 -55
- package/dist/chunk-24QJ2ZUZ.mjs.map +0 -1
- package/dist/chunk-2P3D6FNV.mjs +0 -23
- package/dist/chunk-2P3D6FNV.mjs.map +0 -1
- package/dist/chunk-2ZBAKBVW.js +0 -28
- package/dist/chunk-2ZBAKBVW.js.map +0 -1
- package/dist/chunk-3WWFQLH4.mjs +0 -30
- package/dist/chunk-3WWFQLH4.mjs.map +0 -1
- package/dist/chunk-45LOTCC4.mjs +0 -1
- package/dist/chunk-45LOTCC4.mjs.map +0 -1
- package/dist/chunk-4A5QZUC7.mjs +0 -68
- package/dist/chunk-4A5QZUC7.mjs.map +0 -1
- package/dist/chunk-4JEJ7WKR.js +0 -61
- package/dist/chunk-4JEJ7WKR.js.map +0 -1
- package/dist/chunk-4QUVE3EK.js +0 -53
- package/dist/chunk-4QUVE3EK.js.map +0 -1
- package/dist/chunk-5IN3GGMV.js +0 -68
- package/dist/chunk-5IN3GGMV.js.map +0 -1
- package/dist/chunk-6ABGZTV7.mjs +0 -16
- package/dist/chunk-6ABGZTV7.mjs.map +0 -1
- package/dist/chunk-6EEZHGF5.js +0 -23
- package/dist/chunk-6EEZHGF5.js.map +0 -1
- package/dist/chunk-7H5FH7RY.js +0 -22
- package/dist/chunk-7H5FH7RY.js.map +0 -1
- package/dist/chunk-7RHK2YTB.mjs +0 -32
- package/dist/chunk-7RHK2YTB.mjs.map +0 -1
- package/dist/chunk-AQSQ7YYP.mjs +0 -24
- package/dist/chunk-AQSQ7YYP.mjs.map +0 -1
- package/dist/chunk-AZMQTZXZ.mjs +0 -28
- package/dist/chunk-AZMQTZXZ.mjs.map +0 -1
- package/dist/chunk-B3NNVTA6.js +0 -32
- package/dist/chunk-B3NNVTA6.js.map +0 -1
- package/dist/chunk-BAEGXYL7.mjs +0 -35
- package/dist/chunk-BALQOCUO.js +0 -22
- package/dist/chunk-BALQOCUO.js.map +0 -1
- package/dist/chunk-BYNQODL3.mjs +0 -23
- package/dist/chunk-BYNQODL3.mjs.map +0 -1
- package/dist/chunk-C44RRX3H.js +0 -18
- package/dist/chunk-C44RRX3H.js.map +0 -1
- package/dist/chunk-C46KEPAC.js +0 -37
- package/dist/chunk-C46KEPAC.js.map +0 -1
- package/dist/chunk-CB77QR32.js +0 -52
- package/dist/chunk-CB77QR32.js.map +0 -1
- package/dist/chunk-CZRGAFVI.mjs +0 -28
- package/dist/chunk-CZRGAFVI.mjs.map +0 -1
- package/dist/chunk-D2ZIM5W2.js +0 -370
- package/dist/chunk-D2ZIM5W2.js.map +0 -1
- package/dist/chunk-DBLADLQ4.js +0 -10
- package/dist/chunk-DBLADLQ4.js.map +0 -1
- package/dist/chunk-ERSRIVYH.mjs +0 -64
- package/dist/chunk-ERSRIVYH.mjs.map +0 -1
- package/dist/chunk-G62Q4YO5.js +0 -30
- package/dist/chunk-G62Q4YO5.js.map +0 -1
- package/dist/chunk-HAYK73YO.js +0 -23
- package/dist/chunk-HAYK73YO.js.map +0 -1
- package/dist/chunk-HLQEI6DV.js +0 -54
- package/dist/chunk-HLQEI6DV.js.map +0 -1
- package/dist/chunk-HLSCFGA7.mjs +0 -13
- package/dist/chunk-HLSCFGA7.mjs.map +0 -1
- package/dist/chunk-HOVEQTF3.mjs +0 -346
- package/dist/chunk-HOVEQTF3.mjs.map +0 -1
- package/dist/chunk-JAHNVVLT.mjs +0 -18
- package/dist/chunk-JAHNVVLT.mjs.map +0 -1
- package/dist/chunk-JCVSYVPD.mjs +0 -24
- package/dist/chunk-JCVSYVPD.mjs.map +0 -1
- package/dist/chunk-JL3URCHO.mjs +0 -53
- package/dist/chunk-JL3URCHO.mjs.map +0 -1
- package/dist/chunk-K26BOY6Z.mjs +0 -51
- package/dist/chunk-K26BOY6Z.mjs.map +0 -1
- package/dist/chunk-KLOPX6DO.js +0 -51
- package/dist/chunk-KLOPX6DO.js.map +0 -1
- package/dist/chunk-KWHAT6UJ.mjs +0 -22
- package/dist/chunk-KWHAT6UJ.mjs.map +0 -1
- package/dist/chunk-L72RLBV5.mjs +0 -37
- package/dist/chunk-L72RLBV5.mjs.map +0 -1
- package/dist/chunk-MECBOP7G.js +0 -35
- package/dist/chunk-MECBOP7G.js.map +0 -1
- package/dist/chunk-MR44GPM3.mjs +0 -135
- package/dist/chunk-MR44GPM3.mjs.map +0 -1
- package/dist/chunk-MR5TAGOG.mjs +0 -54
- package/dist/chunk-MR5TAGOG.mjs.map +0 -1
- package/dist/chunk-MUYXNION.js +0 -30
- package/dist/chunk-MUYXNION.js.map +0 -1
- package/dist/chunk-MXOKUCLH.js +0 -347
- package/dist/chunk-MXOKUCLH.js.map +0 -1
- package/dist/chunk-NGS23BTR.js +0 -13
- package/dist/chunk-NGS23BTR.js.map +0 -1
- package/dist/chunk-NOBUMOYX.mjs +0 -61
- package/dist/chunk-NOBUMOYX.mjs.map +0 -1
- package/dist/chunk-NR4OJOGX.mjs +0 -370
- package/dist/chunk-NR4OJOGX.mjs.map +0 -1
- package/dist/chunk-OIFTFHZ4.mjs +0 -30
- package/dist/chunk-OIFTFHZ4.mjs.map +0 -1
- package/dist/chunk-PDYQXXLP.js +0 -30
- package/dist/chunk-PDYQXXLP.js.map +0 -1
- package/dist/chunk-QAM2JJRA.mjs +0 -52
- package/dist/chunk-QAM2JJRA.mjs.map +0 -1
- package/dist/chunk-QHCKVO3P.js +0 -28
- package/dist/chunk-QHCKVO3P.js.map +0 -1
- package/dist/chunk-QMB2ZRWW.js +0 -16
- package/dist/chunk-QMB2ZRWW.js.map +0 -1
- package/dist/chunk-QMD3VO6R.mjs +0 -30
- package/dist/chunk-QMD3VO6R.mjs.map +0 -1
- package/dist/chunk-QRW2GKA3.mjs +0 -347
- package/dist/chunk-QRW2GKA3.mjs.map +0 -1
- package/dist/chunk-R77RJHC5.mjs +0 -44
- package/dist/chunk-R77RJHC5.mjs.map +0 -1
- package/dist/chunk-RANTKN66.js +0 -24
- package/dist/chunk-RANTKN66.js.map +0 -1
- package/dist/chunk-S7UP2YYF.js +0 -135
- package/dist/chunk-S7UP2YYF.js.map +0 -1
- package/dist/chunk-SQXMNT7M.js +0 -326
- package/dist/chunk-SQXMNT7M.js.map +0 -1
- package/dist/chunk-SYRWT2KT.mjs +0 -124
- package/dist/chunk-SYRWT2KT.mjs.map +0 -1
- package/dist/chunk-TDSL55B3.mjs +0 -10
- package/dist/chunk-TDSL55B3.mjs.map +0 -1
- package/dist/chunk-TJ2F3J6X.js +0 -31
- package/dist/chunk-TJ2F3J6X.js.map +0 -1
- package/dist/chunk-U4VFMIGO.js +0 -24
- package/dist/chunk-U4VFMIGO.js.map +0 -1
- package/dist/chunk-V6SYDSWM.mjs +0 -326
- package/dist/chunk-V6SYDSWM.mjs.map +0 -1
- package/dist/chunk-VXOV3ZCB.js +0 -1
- package/dist/chunk-VXOV3ZCB.js.map +0 -1
- package/dist/chunk-X3D3MHWF.js +0 -44
- package/dist/chunk-X3D3MHWF.js.map +0 -1
- package/dist/chunk-X7TESUC7.mjs +0 -22
- package/dist/chunk-X7TESUC7.mjs.map +0 -1
- package/dist/chunk-XGWLFH7Y.js +0 -41
- package/dist/chunk-XGWLFH7Y.js.map +0 -1
- package/dist/chunk-YCOC4VEP.js +0 -346
- package/dist/chunk-YCOC4VEP.js.map +0 -1
- package/dist/chunk-YCYGKEXF.mjs +0 -41
- package/dist/chunk-YCYGKEXF.mjs.map +0 -1
- package/dist/chunk-YGEAZQSC.js +0 -124
- package/dist/chunk-YGEAZQSC.js.map +0 -1
- package/dist/chunk-YQ2E7NEA.js +0 -64
- package/dist/chunk-YQ2E7NEA.js.map +0 -1
- package/dist/chunk-ZAW4ZWQX.mjs +0 -31
- package/dist/chunk-ZAW4ZWQX.mjs.map +0 -1
- package/dist/chunk-ZVUF6JDJ.js +0 -55
- package/dist/chunk-ZVUF6JDJ.js.map +0 -1
- package/dist/cli.js +0 -21
- package/dist/cli.js.map +0 -1
- package/dist/commands/build/build.js +0 -29
- package/dist/commands/build/build.js.map +0 -1
- package/dist/commands/build/implementation.js +0 -28
- package/dist/commands/build/implementation.js.map +0 -1
- package/dist/commands/build/index.js +0 -33
- package/dist/commands/build/index.js.map +0 -1
- package/dist/commands/eval/eval.js +0 -18
- package/dist/commands/eval/eval.js.map +0 -1
- package/dist/commands/eval/implementation.js +0 -9
- package/dist/commands/eval/implementation.js.map +0 -1
- package/dist/commands/eval/index.js +0 -22
- package/dist/commands/eval/index.js.map +0 -1
- package/dist/commands/index.js +0 -39
- package/dist/commands/index.js.map +0 -1
- package/dist/commands/manifest/implementation.js +0 -17
- package/dist/commands/manifest/implementation.js.map +0 -1
- package/dist/commands/manifest/index.js +0 -22
- package/dist/commands/manifest/index.js.map +0 -1
- package/dist/commands/manifest/manifest.js +0 -18
- package/dist/commands/manifest/manifest.js.map +0 -1
- package/dist/commands/serve/index.js +0 -29
- package/dist/commands/serve/index.js.map +0 -1
- package/dist/commands/serve/serve.js +0 -28
- package/dist/commands/serve/serve.js.map +0 -1
- package/dist/commands/watch/implementation.js +0 -28
- package/dist/commands/watch/implementation.js.map +0 -1
- package/dist/commands/watch/index.js +0 -33
- package/dist/commands/watch/index.js.map +0 -1
- package/dist/commands/watch/watch.js +0 -29
- package/dist/commands/watch/watch.js.map +0 -1
- package/dist/config.js +0 -36
- package/dist/config.js.map +0 -1
- package/dist/errors.js +0 -12
- package/dist/errors.js.map +0 -1
- package/dist/index.js +0 -45
- package/dist/index.js.map +0 -1
- package/dist/main.js +0 -49
- package/dist/main.js.map +0 -1
- package/dist/structs.js +0 -8
- package/dist/structs.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/__fixtures__/configs/cjs.d.ts +0 -1
- package/dist/types/__fixtures__/configs/esm.d.ts +0 -3
- package/dist/types/__fixtures__/configs/invalid.d.ts +0 -3
- package/dist/types/__fixtures__/configs/javascript/snap.config.d.ts +0 -0
- package/dist/types/__fixtures__/configs/typescript/snap.config.d.ts +0 -3
- package/dist/types/commands/eval/__test__/browserify/bad/snap.config.d.ts +0 -3
- package/dist/types/commands/eval/__test__/browserify/good/snap.config.d.ts +0 -3
- package/dist/types/commands/eval/__test__/webpack/bad/snap.config.d.ts +0 -3
- package/dist/types/commands/eval/__test__/webpack/good/snap.config.d.ts +0 -3
- package/dist/types/commands/eval/__test__/webpack/snap.config.d.ts +0 -3
- package/dist/types/commands/watch/index.d.ts +0 -10
- package/dist/types/index.d.ts +0 -5
- package/dist/types/main.d.ts +0 -2
- package/dist/types/utils/index.d.ts +0 -6
- package/dist/types/webpack/index.d.ts +0 -4
- package/dist/types/webpack/loaders/index.d.ts +0 -3
- package/dist/types/yargs.d.js +0 -1
- package/dist/types/yargs.d.js.map +0 -1
- package/dist/types/yargs.d.mjs +0 -1
- package/dist/types/yargs.d.mjs.map +0 -1
- package/dist/utils/cli.js +0 -14
- package/dist/utils/cli.js.map +0 -1
- package/dist/utils/errors.js +0 -11
- package/dist/utils/errors.js.map +0 -1
- package/dist/utils/index.js +0 -47
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/legacy.js +0 -13
- package/dist/utils/legacy.js.map +0 -1
- package/dist/utils/logging.js +0 -12
- package/dist/utils/logging.js.map +0 -1
- package/dist/utils/path.js +0 -8
- package/dist/utils/path.js.map +0 -1
- package/dist/utils/steps.js +0 -11
- package/dist/utils/steps.js.map +0 -1
- package/dist/webpack/compiler.js +0 -25
- package/dist/webpack/compiler.js.map +0 -1
- package/dist/webpack/config.js +0 -24
- package/dist/webpack/config.js.map +0 -1
- package/dist/webpack/index.js +0 -44
- package/dist/webpack/index.js.map +0 -1
- package/dist/webpack/loaders/browserify.js +0 -19
- package/dist/webpack/loaders/browserify.js.map +0 -1
- package/dist/webpack/loaders/function.js +0 -10
- package/dist/webpack/loaders/function.js.map +0 -1
- package/dist/webpack/loaders/index.js +0 -25
- package/dist/webpack/loaders/index.js.map +0 -1
- package/dist/webpack/loaders/wasm.js +0 -16
- package/dist/webpack/loaders/wasm.js.map +0 -1
- package/dist/webpack/plugins.js +0 -29
- package/dist/webpack/plugins.js.map +0 -1
- package/dist/webpack/server.js +0 -10
- package/dist/webpack/server.js.map +0 -1
- package/dist/webpack/utils.js +0 -39
- package/dist/webpack/utils.js.map +0 -1
package/dist/webpack/plugins.mjs
CHANGED
|
@@ -1,29 +1,272 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import "
|
|
14
|
-
import "
|
|
15
|
-
|
|
16
|
-
import "
|
|
17
|
-
import "
|
|
18
|
-
|
|
19
|
-
import "../
|
|
20
|
-
import "../
|
|
21
|
-
import "
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
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
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _SnapsStatsPlugin_instances, _SnapsStatsPlugin_spinner, _SnapsStatsPlugin_getStatsErrorMessage, _SnapsWatchPlugin_instances, _SnapsWatchPlugin_spinner, _SnapsWatchPlugin_safeEvaluate, _SnapsBuiltInResolver_source, _SnapsBuiltInResolver_spinner, _SnapsBundleWarningsPlugin_instances, _SnapsBundleWarningsPlugin_checkBuiltIns, _SnapsBundleWarningsPlugin_isProvidePlugin, _SnapsBundleWarningsPlugin_checkBuffer;
|
|
13
|
+
import { assert, hasProperty, isObject } from "@metamask/utils";
|
|
14
|
+
import $chalk from "chalk";
|
|
15
|
+
const { bold, dim, red, yellow } = $chalk;
|
|
16
|
+
import { isBuiltin } from "module";
|
|
17
|
+
import $webpack from "webpack";
|
|
18
|
+
const { WebpackError } = $webpack;
|
|
19
|
+
import { evaluate } from "../commands/eval/index.mjs";
|
|
20
|
+
import { error, getErrorMessage, info, warn } from "../utils/index.mjs";
|
|
21
|
+
import { formatText, pluralize } from "./utils.mjs";
|
|
22
|
+
/**
|
|
23
|
+
* A plugin that logs the stats after compilation. This is useful for logging
|
|
24
|
+
* the number of files compiled, and the time taken to compile them.
|
|
25
|
+
*/
|
|
26
|
+
export class SnapsStatsPlugin {
|
|
27
|
+
constructor(options = {
|
|
28
|
+
verbose: false,
|
|
29
|
+
}, spinner) {
|
|
30
|
+
_SnapsStatsPlugin_instances.add(this);
|
|
31
|
+
/**
|
|
32
|
+
* The spinner to use for logging.
|
|
33
|
+
*/
|
|
34
|
+
_SnapsStatsPlugin_spinner.set(this, void 0);
|
|
35
|
+
this.options = options;
|
|
36
|
+
__classPrivateFieldSet(this, _SnapsStatsPlugin_spinner, spinner, "f");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Apply the plugin to the Webpack compiler.
|
|
40
|
+
*
|
|
41
|
+
* @param compiler - The Webpack compiler.
|
|
42
|
+
*/
|
|
43
|
+
apply(compiler) {
|
|
44
|
+
compiler.hooks.afterDone.tap(this.constructor.name, (stats) => {
|
|
45
|
+
if (!stats) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const { modules, time, errors, warnings } = stats.toJson();
|
|
49
|
+
assert(modules, 'Modules must be defined in stats.');
|
|
50
|
+
assert(time, 'Time must be defined in stats.');
|
|
51
|
+
if (errors?.length) {
|
|
52
|
+
const formattedErrors = errors
|
|
53
|
+
.map((statsError) => __classPrivateFieldGet(this, _SnapsStatsPlugin_instances, "m", _SnapsStatsPlugin_getStatsErrorMessage).call(this, statsError))
|
|
54
|
+
.join('\n\n');
|
|
55
|
+
error(`Compiled ${modules.length} ${pluralize(modules.length, 'file')} in ${time}ms with ${errors.length} ${pluralize(errors.length, 'error')}.\n\n${formattedErrors}\n`, __classPrivateFieldGet(this, _SnapsStatsPlugin_spinner, "f"));
|
|
56
|
+
__classPrivateFieldGet(this, _SnapsStatsPlugin_spinner, "f")?.stop();
|
|
57
|
+
process.exitCode = 1;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (warnings?.length) {
|
|
61
|
+
const formattedWarnings = warnings
|
|
62
|
+
.map((statsWarning) => __classPrivateFieldGet(this, _SnapsStatsPlugin_instances, "m", _SnapsStatsPlugin_getStatsErrorMessage).call(this, statsWarning, yellow))
|
|
63
|
+
.join('\n\n');
|
|
64
|
+
warn(`Compiled ${modules.length} ${pluralize(modules.length, 'file')} in ${time}ms with ${warnings.length} ${pluralize(warnings.length, 'warning')}.\n\n${formattedWarnings}\n`, __classPrivateFieldGet(this, _SnapsStatsPlugin_spinner, "f"));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
info(`Compiled ${modules.length} ${pluralize(modules.length, 'file')} in ${time}ms.`, __classPrivateFieldGet(this, _SnapsStatsPlugin_spinner, "f"));
|
|
68
|
+
}
|
|
69
|
+
if (compiler.watchMode) {
|
|
70
|
+
// The spinner may be restarted by the watch plugin, outside of the
|
|
71
|
+
// `executeSteps` flow, so we stop it here just in case.
|
|
72
|
+
__classPrivateFieldGet(this, _SnapsStatsPlugin_spinner, "f")?.succeed('Done!');
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
_SnapsStatsPlugin_spinner = new WeakMap(), _SnapsStatsPlugin_instances = new WeakSet(), _SnapsStatsPlugin_getStatsErrorMessage = function _SnapsStatsPlugin_getStatsErrorMessage(statsError, color = red) {
|
|
78
|
+
const baseMessage = this.options.verbose
|
|
79
|
+
? getErrorMessage(statsError)
|
|
80
|
+
: statsError.message;
|
|
81
|
+
const [first, ...rest] = baseMessage.split('\n');
|
|
82
|
+
return [
|
|
83
|
+
color(formatText(`• ${first}`, 4, 2)),
|
|
84
|
+
...rest.map((message) => formatText(color(message), 4)),
|
|
85
|
+
statsError.details && `\n${formatText(dim(statsError.details), 6)}`,
|
|
86
|
+
]
|
|
87
|
+
.filter(Boolean)
|
|
88
|
+
.join('\n');
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* A plugin that adds extra files to watch. This is useful for watching files
|
|
92
|
+
* that are not imported by the entry point, such as the `snap.manifest.json`
|
|
93
|
+
* file.
|
|
94
|
+
*/
|
|
95
|
+
export class SnapsWatchPlugin {
|
|
96
|
+
constructor(options, spinner) {
|
|
97
|
+
_SnapsWatchPlugin_instances.add(this);
|
|
98
|
+
/**
|
|
99
|
+
* The spinner to use for logging.
|
|
100
|
+
*/
|
|
101
|
+
_SnapsWatchPlugin_spinner.set(this, void 0);
|
|
102
|
+
this.options = options;
|
|
103
|
+
__classPrivateFieldSet(this, _SnapsWatchPlugin_spinner, spinner, "f");
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Apply the plugin to the Webpack compiler.
|
|
107
|
+
*
|
|
108
|
+
* @param compiler - The Webpack compiler.
|
|
109
|
+
*/
|
|
110
|
+
apply(compiler) {
|
|
111
|
+
compiler.hooks.invalid.tap(this.constructor.name, (file) => {
|
|
112
|
+
__classPrivateFieldGet(this, _SnapsWatchPlugin_spinner, "f")?.start();
|
|
113
|
+
info(`Changes detected in ${yellow(file)}, recompiling.`, __classPrivateFieldGet(this, _SnapsWatchPlugin_spinner, "f"));
|
|
114
|
+
});
|
|
115
|
+
compiler.hooks.afterEmit.tapPromise(this.constructor.name, async ({ fileDependencies }) => {
|
|
116
|
+
this.options.files?.forEach(fileDependencies.add.bind(fileDependencies));
|
|
117
|
+
if (this.options.bundle && this.options.evaluate) {
|
|
118
|
+
await __classPrivateFieldGet(this, _SnapsWatchPlugin_instances, "m", _SnapsWatchPlugin_safeEvaluate).call(this, this.options.bundle);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
_SnapsWatchPlugin_spinner = new WeakMap(), _SnapsWatchPlugin_instances = new WeakSet(), _SnapsWatchPlugin_safeEvaluate =
|
|
124
|
+
/**
|
|
125
|
+
* Safely evaluate the bundle at the given path. If an error occurs, it will
|
|
126
|
+
* be logged to the console, rather than throwing an error.
|
|
127
|
+
*
|
|
128
|
+
* This function should never throw an error.
|
|
129
|
+
*
|
|
130
|
+
* @param bundlePath - The path to the bundle.
|
|
131
|
+
*/
|
|
132
|
+
async function _SnapsWatchPlugin_safeEvaluate(bundlePath) {
|
|
133
|
+
try {
|
|
134
|
+
await evaluate(bundlePath);
|
|
135
|
+
info(`Snap bundle evaluated successfully.`, __classPrivateFieldGet(this, _SnapsWatchPlugin_spinner, "f"));
|
|
136
|
+
}
|
|
137
|
+
catch (evaluateError) {
|
|
138
|
+
error(evaluateError.message, __classPrivateFieldGet(this, _SnapsWatchPlugin_spinner, "f"));
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* A plugin that logs a message when a built-in module is not resolved. The
|
|
143
|
+
* MetaMask Snaps CLI does not support built-in modules by default, and this
|
|
144
|
+
* plugin is used to warn the user when they try to import a built-in module,
|
|
145
|
+
* when no fallback is configured.
|
|
146
|
+
*/
|
|
147
|
+
export class SnapsBuiltInResolver {
|
|
148
|
+
constructor(options = {
|
|
149
|
+
ignore: [],
|
|
150
|
+
}, spinner) {
|
|
151
|
+
/**
|
|
152
|
+
* The built-in modules that have been imported, but not resolved.
|
|
153
|
+
*/
|
|
154
|
+
this.unresolvedModules = new Set();
|
|
155
|
+
/**
|
|
156
|
+
* The name of the resolver hook to tap into.
|
|
157
|
+
*/
|
|
158
|
+
_SnapsBuiltInResolver_source.set(this, 'described-resolve');
|
|
159
|
+
/**
|
|
160
|
+
* The spinner to use for logging.
|
|
161
|
+
*/
|
|
162
|
+
_SnapsBuiltInResolver_spinner.set(this, void 0);
|
|
163
|
+
this.options = options;
|
|
164
|
+
__classPrivateFieldSet(this, _SnapsBuiltInResolver_spinner, spinner, "f");
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Apply the plugin to the Webpack resolver.
|
|
168
|
+
*
|
|
169
|
+
* @param resolver - The Webpack resolver.
|
|
170
|
+
*/
|
|
171
|
+
apply(resolver) {
|
|
172
|
+
resolver
|
|
173
|
+
.getHook(__classPrivateFieldGet(this, _SnapsBuiltInResolver_source, "f"))
|
|
174
|
+
.tapAsync(this.constructor.name, ({ module: isModule, request }, _, callback) => {
|
|
175
|
+
if (!isModule || !request) {
|
|
176
|
+
return callback();
|
|
177
|
+
}
|
|
178
|
+
const baseRequest = request.split('/')[0];
|
|
179
|
+
if (isBuiltin(baseRequest) &&
|
|
180
|
+
!this.options.ignore?.includes(baseRequest)) {
|
|
181
|
+
const fallback = resolver.options.fallback.find(({ name }) => name === baseRequest);
|
|
182
|
+
if (fallback && !fallback.alias) {
|
|
183
|
+
this.unresolvedModules.add(baseRequest);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return callback();
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
_SnapsBuiltInResolver_source = new WeakMap(), _SnapsBuiltInResolver_spinner = new WeakMap();
|
|
191
|
+
/**
|
|
192
|
+
* A plugin that logs a message when:
|
|
193
|
+
*
|
|
194
|
+
* - A built-in module is not resolved. The MetaMask Snaps CLI does not support
|
|
195
|
+
* built-in modules by default, and this plugin is used to warn the user when
|
|
196
|
+
* they try to import a built-in module, when no fallback is configured.
|
|
197
|
+
* - A snap uses the `Buffer` global. The MetaMask Snaps CLI does not support
|
|
198
|
+
* the `Buffer` global by default, and this plugin is used to warn the user when
|
|
199
|
+
* they try to use the `Buffer` global.
|
|
200
|
+
*
|
|
201
|
+
* We use both a resolver and a plugin, because the resolver is used to detect
|
|
202
|
+
* when a built-in module is imported, and the plugin is used to log a single
|
|
203
|
+
* message when the compilation is complete. We can't do everything in a single
|
|
204
|
+
* plugin, because the resolver doesn't have access to the compilation, and the
|
|
205
|
+
* plugin doesn't have access to the resolver.
|
|
206
|
+
*/
|
|
207
|
+
export class SnapsBundleWarningsPlugin {
|
|
208
|
+
constructor(options = {
|
|
209
|
+
buffer: true,
|
|
210
|
+
builtIns: true,
|
|
211
|
+
}) {
|
|
212
|
+
_SnapsBundleWarningsPlugin_instances.add(this);
|
|
213
|
+
this.options = options;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Apply the plugin to the Webpack compiler.
|
|
217
|
+
*
|
|
218
|
+
* @param compiler - The Webpack compiler.
|
|
219
|
+
*/
|
|
220
|
+
apply(compiler) {
|
|
221
|
+
if (this.options.builtIns) {
|
|
222
|
+
__classPrivateFieldGet(this, _SnapsBundleWarningsPlugin_instances, "m", _SnapsBundleWarningsPlugin_checkBuiltIns).call(this, compiler);
|
|
223
|
+
}
|
|
224
|
+
if (this.options.buffer) {
|
|
225
|
+
__classPrivateFieldGet(this, _SnapsBundleWarningsPlugin_instances, "m", _SnapsBundleWarningsPlugin_checkBuffer).call(this, compiler);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
_SnapsBundleWarningsPlugin_instances = new WeakSet(), _SnapsBundleWarningsPlugin_checkBuiltIns = function _SnapsBundleWarningsPlugin_checkBuiltIns(compiler) {
|
|
230
|
+
compiler.hooks.afterCompile.tap(this.constructor.name, (compilation) => {
|
|
231
|
+
if (!this.options.builtInResolver) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const { unresolvedModules } = this.options.builtInResolver;
|
|
235
|
+
if (unresolvedModules.size === 0) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const formattedModules = new Array(...unresolvedModules)
|
|
239
|
+
.map((name) => `• ${name}`)
|
|
240
|
+
.join('\n');
|
|
241
|
+
const webpackError = new WebpackError(`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('`polyfills`')} to ${bold('`true`')} or an object with the builtins to polyfill as the key and ${bold('`true`')} as the value. To disable this warning, set ${bold('`stats.builtIns`')} to ${bold('`false`')} in your snap config file, or add the module to the ${bold('`stats.builtIns.ignore`')} array.`);
|
|
242
|
+
webpackError.details = formattedModules;
|
|
243
|
+
compilation.warnings.push(webpackError);
|
|
244
|
+
});
|
|
245
|
+
}, _SnapsBundleWarningsPlugin_isProvidePlugin = function _SnapsBundleWarningsPlugin_isProvidePlugin(instance) {
|
|
246
|
+
return (isObject(instance) &&
|
|
247
|
+
instance.constructor.name === 'ProvidePlugin' &&
|
|
248
|
+
hasProperty(instance, 'definitions'));
|
|
249
|
+
}, _SnapsBundleWarningsPlugin_checkBuffer = function _SnapsBundleWarningsPlugin_checkBuffer(compiler) {
|
|
250
|
+
const plugin = compiler.options.plugins?.find((instance) => __classPrivateFieldGet(this, _SnapsBundleWarningsPlugin_instances, "m", _SnapsBundleWarningsPlugin_isProvidePlugin).call(this, instance));
|
|
251
|
+
// If the `ProvidePlugin` is configured to provide `Buffer`, then we don't
|
|
252
|
+
// need to warn the user.
|
|
253
|
+
if (plugin) {
|
|
254
|
+
const { definitions } = plugin;
|
|
255
|
+
if (definitions.Buffer) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
compiler.hooks.compilation.tap(this.constructor.name, (compilation) => {
|
|
260
|
+
compilation.hooks.afterProcessAssets.tap(this.constructor.name, (assets) => {
|
|
261
|
+
// Check if assets use `Buffer`.
|
|
262
|
+
const bufferAssets = Object.entries(assets)
|
|
263
|
+
.filter(([name]) => name.endsWith('.js'))
|
|
264
|
+
.filter(([, asset]) => asset.source().includes('Buffer'));
|
|
265
|
+
if (bufferAssets.length === 0) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
compilation.warnings.push(new WebpackError(`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('`buffer`')} to ${bold('`true`')} in the ${bold('`polyfills`')} config object in your snap config. To disable this warning, set ${bold('`stats.buffer`')} to ${bold('`false`')} in your snap config file.`));
|
|
269
|
+
});
|
|
270
|
+
});
|
|
28
271
|
};
|
|
29
272
|
//# sourceMappingURL=plugins.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"file":"plugins.mjs","sourceRoot":"","sources":["../../src/webpack/plugins.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,wBAAwB;;;AAEhE,OAAO,EAAE,SAAS,EAAE,eAAe;;;AAYnC,OAAO,EAAE,QAAQ,EAAE,mCAAyB;AAC5C,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,EAAE,2BAAiB;AAC9D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,oBAAgB;AAShD;;;GAGG;AACH,MAAM,OAAO,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,MAAM,CAAC,OAAO,EAAE,mCAAmC,CAAC,CAAC;YACrD,MAAM,CAAC,IAAI,EAAE,gCAAgC,CAAC,CAAC;YAE/C,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;gBACnB,MAAM,eAAe,GAAG,MAAM;qBAC3B,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,uBAAA,IAAI,2EAAsB,MAA1B,IAAI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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"]}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getServer = exports.getAllowedPaths = void 0;
|
|
7
|
+
const node_1 = require("@metamask/snaps-utils/node");
|
|
8
|
+
const http_1 = require("http");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const serve_handler_1 = __importDefault(require("serve-handler"));
|
|
11
|
+
/**
|
|
12
|
+
* Get the relative path from one path to another.
|
|
13
|
+
*
|
|
14
|
+
* Note: This is a modified version of `path.relative` that uses Posix
|
|
15
|
+
* separators for URL-compatibility.
|
|
16
|
+
*
|
|
17
|
+
* @param from - The path to start from.
|
|
18
|
+
* @param to - The path to end at.
|
|
19
|
+
* @returns The relative path.
|
|
20
|
+
*/
|
|
21
|
+
function getRelativePath(from, to) {
|
|
22
|
+
return (0, path_1.relative)(from, to).split(path_1.sep).join(path_1.posix.sep);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get the allowed paths for the static server. This includes the output file,
|
|
26
|
+
* the manifest file, and any auxiliary/localization files.
|
|
27
|
+
*
|
|
28
|
+
* @param config - The config object.
|
|
29
|
+
* @param manifest - The Snap manifest object.
|
|
30
|
+
* @returns An array of allowed paths.
|
|
31
|
+
*/
|
|
32
|
+
function getAllowedPaths(config, manifest) {
|
|
33
|
+
const auxiliaryFiles = manifest.source.files?.map((file) => getRelativePath(config.server.root, (0, path_1.resolve)(config.server.root, file))) ?? [];
|
|
34
|
+
const localizationFiles = manifest.source.locales?.map((localization) => getRelativePath(config.server.root, (0, path_1.resolve)(config.server.root, localization))) ?? [];
|
|
35
|
+
const otherFiles = manifest.source.location.npm.iconPath
|
|
36
|
+
? [
|
|
37
|
+
getRelativePath(config.server.root, (0, path_1.resolve)(config.server.root, manifest.source.location.npm.iconPath)),
|
|
38
|
+
]
|
|
39
|
+
: [];
|
|
40
|
+
return [
|
|
41
|
+
getRelativePath(config.server.root, (0, path_1.resolve)(config.server.root, config.output.path, config.output.filename)),
|
|
42
|
+
getRelativePath(config.server.root, (0, path_1.resolve)(config.server.root, node_1.NpmSnapFileNames.Manifest)),
|
|
43
|
+
...auxiliaryFiles,
|
|
44
|
+
...localizationFiles,
|
|
45
|
+
...otherFiles,
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
exports.getAllowedPaths = getAllowedPaths;
|
|
49
|
+
/**
|
|
50
|
+
* Get a static server for development purposes.
|
|
51
|
+
*
|
|
52
|
+
* Note: We're intentionally not using `webpack-dev-server` here because it
|
|
53
|
+
* adds a lot of extra stuff to the output that we don't need, and it's
|
|
54
|
+
* difficult to customize.
|
|
55
|
+
*
|
|
56
|
+
* @param config - The config object.
|
|
57
|
+
* @returns An object with a `listen` method that returns a promise that
|
|
58
|
+
* resolves when the server is listening.
|
|
59
|
+
*/
|
|
60
|
+
function getServer(config) {
|
|
61
|
+
/**
|
|
62
|
+
* Get the response for a request. This is extracted into a function so that
|
|
63
|
+
* we can easily catch errors and send a 500 response.
|
|
64
|
+
*
|
|
65
|
+
* @param request - The request.
|
|
66
|
+
* @param response - The response.
|
|
67
|
+
* @returns A promise that resolves when the response is sent.
|
|
68
|
+
*/
|
|
69
|
+
async function getResponse(request, response) {
|
|
70
|
+
const manifestPath = (0, path_1.join)(config.server.root, node_1.NpmSnapFileNames.Manifest);
|
|
71
|
+
const { result } = await (0, node_1.readJsonFile)(manifestPath);
|
|
72
|
+
const allowedPaths = getAllowedPaths(config, result);
|
|
73
|
+
const path = request.url?.slice(1);
|
|
74
|
+
const allowed = allowedPaths.some((allowedPath) => path === allowedPath);
|
|
75
|
+
if (!allowed) {
|
|
76
|
+
response.statusCode = 404;
|
|
77
|
+
response.end();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
await (0, serve_handler_1.default)(request, response, {
|
|
81
|
+
public: config.server.root,
|
|
82
|
+
directoryListing: false,
|
|
83
|
+
headers: [
|
|
84
|
+
{
|
|
85
|
+
source: '**/*',
|
|
86
|
+
headers: [
|
|
87
|
+
{
|
|
88
|
+
key: 'Cache-Control',
|
|
89
|
+
value: 'no-cache',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
key: 'Access-Control-Allow-Origin',
|
|
93
|
+
value: '*',
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const server = (0, http_1.createServer)((request, response) => {
|
|
101
|
+
getResponse(request, response).catch(
|
|
102
|
+
/* istanbul ignore next */
|
|
103
|
+
(error) => {
|
|
104
|
+
(0, node_1.logError)(error);
|
|
105
|
+
response.statusCode = 500;
|
|
106
|
+
response.end();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
/**
|
|
110
|
+
* Start the server on the port specified in the config.
|
|
111
|
+
*
|
|
112
|
+
* @param port - The port to listen on.
|
|
113
|
+
* @returns A promise that resolves when the server is listening. The promise
|
|
114
|
+
* resolves to an object with the port and the server instance. Note that if
|
|
115
|
+
* the `config.server.port` is `0`, the OS will choose a random port for us,
|
|
116
|
+
* so we need to get the port from the server after it starts.
|
|
117
|
+
*/
|
|
118
|
+
const listen = async (port = config.server.port) => {
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
try {
|
|
121
|
+
server.listen(port, () => {
|
|
122
|
+
const close = async () => {
|
|
123
|
+
await new Promise((resolveClose, rejectClose) => {
|
|
124
|
+
server.close((closeError) => {
|
|
125
|
+
if (closeError) {
|
|
126
|
+
return rejectClose(closeError);
|
|
127
|
+
}
|
|
128
|
+
return resolveClose();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
const address = server.address();
|
|
133
|
+
resolve({ port: address.port, server, close });
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (listenError) {
|
|
137
|
+
reject(listenError);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
return { listen };
|
|
142
|
+
}
|
|
143
|
+
exports.getServer = getServer;
|
|
144
|
+
//# sourceMappingURL=server.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.cjs","sourceRoot":"","sources":["../../src/webpack/server.ts"],"names":[],"mappings":";;;;;;AACA,qDAIoC;AAEpC,+BAAoC;AAEpC,+BAA0E;AAC1E,kEAA4C;AAI5C;;;;;;;;;GASG;AACH,SAAS,eAAe,CAAC,IAAY,EAAE,EAAU;IAC/C,OAAO,IAAA,eAAQ,EAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,UAAG,CAAC,CAAC,IAAI,CAAC,YAAK,CAAC,GAAG,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,eAAe,CAC7B,MAAu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,\n NpmSnapFileNames,\n readJsonFile,\n} from '@metamask/snaps-utils/node';\nimport type { IncomingMessage, Server, ServerResponse } from 'http';\nimport { createServer } from 'http';\nimport type { AddressInfo } from 'net';\nimport { join, relative, resolve as resolvePath, sep, posix } from 'path';\nimport serveMiddleware from 'serve-handler';\n\nimport type { ProcessedConfig } from '../config';\n\n/**\n * Get the relative path from one path to another.\n *\n * Note: This is a modified version of `path.relative` that uses Posix\n * separators for URL-compatibility.\n *\n * @param from - The path to start from.\n * @param to - The path to end at.\n * @returns The relative path.\n */\nfunction getRelativePath(from: string, to: string) {\n return relative(from, to).split(sep).join(posix.sep);\n}\n\n/**\n * Get the allowed paths for the static server. This includes the output file,\n * the manifest file, and any auxiliary/localization files.\n *\n * @param config - The config object.\n * @param manifest - The Snap manifest object.\n * @returns An array of allowed paths.\n */\nexport function getAllowedPaths(\n config: ProcessedConfig,\n manifest: SnapManifest,\n) {\n const auxiliaryFiles =\n manifest.source.files?.map((file) =>\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, file),\n ),\n ) ?? [];\n\n const localizationFiles =\n manifest.source.locales?.map((localization) =>\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, localization),\n ),\n ) ?? [];\n\n const otherFiles = manifest.source.location.npm.iconPath\n ? [\n getRelativePath(\n config.server.root,\n resolvePath(\n config.server.root,\n manifest.source.location.npm.iconPath,\n ),\n ),\n ]\n : [];\n\n return [\n getRelativePath(\n config.server.root,\n resolvePath(\n config.server.root,\n config.output.path,\n config.output.filename,\n ),\n ),\n getRelativePath(\n config.server.root,\n resolvePath(config.server.root, NpmSnapFileNames.Manifest),\n ),\n ...auxiliaryFiles,\n ...localizationFiles,\n ...otherFiles,\n ];\n}\n\n/**\n * Get a static server for development purposes.\n *\n * Note: We're intentionally not using `webpack-dev-server` here because it\n * adds a lot of extra stuff to the output that we don't need, and it's\n * difficult to customize.\n *\n * @param config - The config object.\n * @returns An object with a `listen` method that returns a promise that\n * resolves when the server is listening.\n */\nexport function getServer(config: ProcessedConfig) {\n /**\n * Get the response for a request. This is extracted into a function so that\n * we can easily catch errors and send a 500 response.\n *\n * @param request - The request.\n * @param response - The response.\n * @returns A promise that resolves when the response is sent.\n */\n async function getResponse(\n request: IncomingMessage,\n response: ServerResponse,\n ) {\n const manifestPath = join(config.server.root, NpmSnapFileNames.Manifest);\n const { result } = await readJsonFile<SnapManifest>(manifestPath);\n const allowedPaths = getAllowedPaths(config, result);\n\n const path = request.url?.slice(1);\n const allowed = allowedPaths.some((allowedPath) => path === allowedPath);\n\n if (!allowed) {\n response.statusCode = 404;\n response.end();\n return;\n }\n\n await serveMiddleware(request, response, {\n public: config.server.root,\n directoryListing: false,\n headers: [\n {\n source: '**/*',\n headers: [\n {\n key: 'Cache-Control',\n value: 'no-cache',\n },\n {\n key: 'Access-Control-Allow-Origin',\n value: '*',\n },\n ],\n },\n ],\n });\n }\n\n const server = createServer((request, response) => {\n getResponse(request, response).catch(\n /* istanbul ignore next */\n (error) => {\n logError(error);\n response.statusCode = 500;\n response.end();\n },\n );\n });\n\n /**\n * Start the server on the port specified in the config.\n *\n * @param port - The port to listen on.\n * @returns A promise that resolves when the server is listening. The promise\n * resolves to an object with the port and the server instance. Note that if\n * the `config.server.port` is `0`, the OS will choose a random port for us,\n * so we need to get the port from the server after it starts.\n */\n const listen = async (port = config.server.port) => {\n return new Promise<{\n port: number;\n server: Server;\n close: () => Promise<void>;\n }>((resolve, reject) => {\n try {\n server.listen(port, () => {\n const close = async () => {\n await new Promise<void>((resolveClose, rejectClose) => {\n server.close((closeError) => {\n if (closeError) {\n return rejectClose(closeError);\n }\n\n return resolveClose();\n });\n });\n };\n\n const address = server.address() as AddressInfo;\n resolve({ port: address.port, server, close });\n });\n } catch (listenError) {\n reject(listenError);\n }\n });\n };\n\n return { listen };\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { SnapManifest } from "@metamask/snaps-utils";
|
|
3
|
+
import type { Server } from "http";
|
|
4
|
+
import type { ProcessedConfig } from "../config.cjs";
|
|
4
5
|
/**
|
|
5
6
|
* Get the allowed paths for the static server. This includes the output file,
|
|
6
7
|
* the manifest file, and any auxiliary/localization files.
|
|
@@ -28,3 +29,4 @@ export declare function getServer(config: ProcessedConfig): {
|
|
|
28
29
|
close: () => Promise<void>;
|
|
29
30
|
}>;
|
|
30
31
|
};
|
|
32
|
+
//# sourceMappingURL=server.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.cts","sourceRoot":"","sources":["../../src/webpack/server.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAM1D,OAAO,KAAK,EAAmB,MAAM,EAAkB,aAAa;AAMpE,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAgBjD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,YAAY,YA+CvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe;;cAqErC,MAAM;gBACJ,MAAM;eACP,MAAM,QAAQ,IAAI,CAAC;;EA0B/B"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { SnapManifest } from "@metamask/snaps-utils";
|
|
3
|
+
import type { Server } from "http";
|
|
4
|
+
import type { ProcessedConfig } from "../config.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* Get the allowed paths for the static server. This includes the output file,
|
|
7
|
+
* the manifest file, and any auxiliary/localization files.
|
|
8
|
+
*
|
|
9
|
+
* @param config - The config object.
|
|
10
|
+
* @param manifest - The Snap manifest object.
|
|
11
|
+
* @returns An array of allowed paths.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getAllowedPaths(config: ProcessedConfig, manifest: SnapManifest): string[];
|
|
14
|
+
/**
|
|
15
|
+
* Get a static server for development purposes.
|
|
16
|
+
*
|
|
17
|
+
* Note: We're intentionally not using `webpack-dev-server` here because it
|
|
18
|
+
* adds a lot of extra stuff to the output that we don't need, and it's
|
|
19
|
+
* difficult to customize.
|
|
20
|
+
*
|
|
21
|
+
* @param config - The config object.
|
|
22
|
+
* @returns An object with a `listen` method that returns a promise that
|
|
23
|
+
* resolves when the server is listening.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getServer(config: ProcessedConfig): {
|
|
26
|
+
listen: (port?: number) => Promise<{
|
|
27
|
+
port: number;
|
|
28
|
+
server: Server;
|
|
29
|
+
close: () => Promise<void>;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=server.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.mts","sourceRoot":"","sources":["../../src/webpack/server.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAM1D,OAAO,KAAK,EAAmB,MAAM,EAAkB,aAAa;AAMpE,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAgBjD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,YAAY,YA+CvB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe;;cAqErC,MAAM;gBACJ,MAAM;eACP,MAAM,QAAQ,IAAI,CAAC;;EA0B/B"}
|