@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
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/// <reference types="browserify" />
|
|
2
|
+
import type { Ora } from "ora/index.js";
|
|
3
|
+
import type { Configuration } from "webpack";
|
|
4
|
+
import type { ProcessedWebpackConfig } from "../config.mjs";
|
|
5
|
+
export declare const BROWSERSLIST_FILE: string;
|
|
6
|
+
export declare const WEBPACK_FALLBACKS: {
|
|
7
|
+
assert: string;
|
|
8
|
+
buffer: string;
|
|
9
|
+
console: string;
|
|
10
|
+
constants: string;
|
|
11
|
+
crypto: string;
|
|
12
|
+
domain: string;
|
|
13
|
+
events: string;
|
|
14
|
+
http: string;
|
|
15
|
+
https: string;
|
|
16
|
+
os: string;
|
|
17
|
+
path: string;
|
|
18
|
+
punycode: string;
|
|
19
|
+
process: string;
|
|
20
|
+
querystring: string;
|
|
21
|
+
stream: string;
|
|
22
|
+
_stream_duplex: string;
|
|
23
|
+
_stream_passthrough: string;
|
|
24
|
+
_stream_readable: string;
|
|
25
|
+
_stream_transform: string;
|
|
26
|
+
_stream_writable: string;
|
|
27
|
+
string_decoder: string;
|
|
28
|
+
sys: string;
|
|
29
|
+
timers: string;
|
|
30
|
+
tty: string;
|
|
31
|
+
url: string;
|
|
32
|
+
util: string;
|
|
33
|
+
vm: string;
|
|
34
|
+
zlib: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Get the default loader for JavaScript and TypeScript files, based on the
|
|
38
|
+
* config object.
|
|
39
|
+
*
|
|
40
|
+
* - If the `legacy` option is set, we use the custom `browserify` loader. This
|
|
41
|
+
* uses the legacy Browserify config to transpile the code.
|
|
42
|
+
* - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the
|
|
43
|
+
* `SWC` compiler, which is a much faster alternative to Babel and TypeScript's
|
|
44
|
+
* own compiler.
|
|
45
|
+
*
|
|
46
|
+
* @param config - The processed snap Webpack config.
|
|
47
|
+
* @param config.legacy - The legacy config object, if any.
|
|
48
|
+
* @param config.sourceMap - Whether to generate source maps.
|
|
49
|
+
* @see https://swc.rs/docs/usage/swc-loader
|
|
50
|
+
* @returns The default loader.
|
|
51
|
+
*/
|
|
52
|
+
export declare function getDefaultLoader({ legacy, sourceMap, }: ProcessedWebpackConfig): Promise<{
|
|
53
|
+
loader: string;
|
|
54
|
+
options: {
|
|
55
|
+
fn: import("webpack").LoaderDefinitionFunction<{
|
|
56
|
+
transpilationMode: import("../builders").TranspilationModes.LocalAndDeps;
|
|
57
|
+
depsToTranspile: string[];
|
|
58
|
+
writeManifest: boolean;
|
|
59
|
+
bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
|
|
60
|
+
} | {
|
|
61
|
+
transpilationMode: import("../builders").TranspilationModes.LocalOnly | import("../builders").TranspilationModes.None;
|
|
62
|
+
depsToTranspile: unknown[];
|
|
63
|
+
writeManifest: boolean;
|
|
64
|
+
bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
|
|
65
|
+
}, {}>;
|
|
66
|
+
} & ({
|
|
67
|
+
transpilationMode: import("../builders").TranspilationModes.LocalAndDeps;
|
|
68
|
+
depsToTranspile: string[];
|
|
69
|
+
writeManifest: boolean;
|
|
70
|
+
bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
|
|
71
|
+
} | {
|
|
72
|
+
transpilationMode: import("../builders").TranspilationModes.LocalOnly | import("../builders").TranspilationModes.None;
|
|
73
|
+
depsToTranspile: unknown[];
|
|
74
|
+
writeManifest: boolean;
|
|
75
|
+
bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
|
|
76
|
+
});
|
|
77
|
+
} | {
|
|
78
|
+
/**
|
|
79
|
+
* We use the `swc-loader` to transpile TypeScript and JavaScript files.
|
|
80
|
+
* This is a Webpack loader that uses the `SWC` compiler, which is a much
|
|
81
|
+
* faster alternative to Babel and TypeScript's own compiler.
|
|
82
|
+
*/
|
|
83
|
+
loader: string;
|
|
84
|
+
/**
|
|
85
|
+
* The options for the `swc-loader`. These can be overridden in the
|
|
86
|
+
* `.swcrc` file.
|
|
87
|
+
*
|
|
88
|
+
* @see https://swc.rs/docs/configuration/swcrc
|
|
89
|
+
*/
|
|
90
|
+
options: {
|
|
91
|
+
sync: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* This tells SWC to generate source maps. We set it to the
|
|
94
|
+
* `sourceMap` value from the config object.
|
|
95
|
+
*
|
|
96
|
+
* This must be enabled if source maps are enabled in the config.
|
|
97
|
+
*/
|
|
98
|
+
sourceMaps: boolean;
|
|
99
|
+
jsc: {
|
|
100
|
+
parser: {
|
|
101
|
+
/**
|
|
102
|
+
* This tells the parser to parse TypeScript files. If you
|
|
103
|
+
* don't need to support TypeScript, you can set this to
|
|
104
|
+
* `ecmascript` instead, but there's no harm in leaving it
|
|
105
|
+
* as `typescript`.
|
|
106
|
+
*
|
|
107
|
+
* @see https://swc.rs/docs/configuration/compilation#jscparser
|
|
108
|
+
*/
|
|
109
|
+
syntax: string;
|
|
110
|
+
/**
|
|
111
|
+
* This tells the parser to transpile JSX.
|
|
112
|
+
*
|
|
113
|
+
* @see https://swc.rs/docs/configuration/compilation#jscparser
|
|
114
|
+
* @see https://swc.rs/docs/configuration/compilation#jscparserjsx
|
|
115
|
+
*/
|
|
116
|
+
tsx: boolean;
|
|
117
|
+
};
|
|
118
|
+
transform: {
|
|
119
|
+
react: {
|
|
120
|
+
/**
|
|
121
|
+
* This tells SWC to use the JSX runtime, instead of the
|
|
122
|
+
* `createElement` function.
|
|
123
|
+
*
|
|
124
|
+
* @see https://swc.rs/docs/configuration/compilation#jsctransformreact
|
|
125
|
+
*/
|
|
126
|
+
runtime: string;
|
|
127
|
+
/**
|
|
128
|
+
* This tells SWC to import the JSX runtime from the
|
|
129
|
+
* `@metamask/snaps-sdk` package, instead of the default React
|
|
130
|
+
* package.
|
|
131
|
+
*
|
|
132
|
+
* @see https://swc.rs/docs/configuration/compilation#jsctransformreact
|
|
133
|
+
*/
|
|
134
|
+
importSource: string;
|
|
135
|
+
/**
|
|
136
|
+
* This tells SWC to use `Object.assign` and `Object.create` for
|
|
137
|
+
* JSX spread attributes, instead of the default behavior.
|
|
138
|
+
*
|
|
139
|
+
* @see https://swc.rs/docs/configuration/compilation#jsctransformreact
|
|
140
|
+
*/
|
|
141
|
+
useBuiltins: boolean;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* The module configuration. This tells SWC how to output the
|
|
147
|
+
* transpiled code.
|
|
148
|
+
*
|
|
149
|
+
* @see https://swc.rs/docs/configuration/modules
|
|
150
|
+
*/
|
|
151
|
+
module: {
|
|
152
|
+
/**
|
|
153
|
+
* This tells SWC to output ES6 modules. This will allow Webpack to
|
|
154
|
+
* optimize the output code better. Snaps don't support ES6 however, so
|
|
155
|
+
* the output code will be transpiled to CommonJS by Webpack later in
|
|
156
|
+
* the build process.
|
|
157
|
+
*
|
|
158
|
+
* @see https://swc.rs/docs/configuration/modules#es6
|
|
159
|
+
*/
|
|
160
|
+
type: string;
|
|
161
|
+
};
|
|
162
|
+
env: {
|
|
163
|
+
targets: string;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
}>;
|
|
167
|
+
/**
|
|
168
|
+
* Get the Webpack devtool configuration based on the given snap config.
|
|
169
|
+
*
|
|
170
|
+
* - If `sourceMap` is `inline`, return `inline-source-map`.
|
|
171
|
+
* - If `sourceMap` is `true`, return `source-map`.
|
|
172
|
+
* - Otherwise, return `false`.
|
|
173
|
+
*
|
|
174
|
+
* @param sourceMap - The `sourceMap` value from the snap config.
|
|
175
|
+
* @returns The Webpack devtool configuration.
|
|
176
|
+
*/
|
|
177
|
+
export declare function getDevTool(sourceMap: ProcessedWebpackConfig['sourceMap']): Configuration['devtool'];
|
|
178
|
+
/**
|
|
179
|
+
* Get a function that can be used as handler function for Webpack's
|
|
180
|
+
* `ProgressPlugin`.
|
|
181
|
+
*
|
|
182
|
+
* @param spinner - The spinner to update.
|
|
183
|
+
* @param spinnerText - The initial spinner text. This will be prepended to the
|
|
184
|
+
* percentage.
|
|
185
|
+
* @returns A function that can be used as handler function for Webpack's
|
|
186
|
+
* `ProgressPlugin`.
|
|
187
|
+
*/
|
|
188
|
+
export declare function getProgressHandler(spinner?: Ora, spinnerText?: string): (percentage: number) => void;
|
|
189
|
+
/**
|
|
190
|
+
* Get the targets from the `.browserslistrc` file.
|
|
191
|
+
*
|
|
192
|
+
* @returns The browser targets as an array of strings.
|
|
193
|
+
*/
|
|
194
|
+
export declare function getBrowserslistTargets(): Promise<string[]>;
|
|
195
|
+
/**
|
|
196
|
+
* Get a singular or plural string based on the given count. This is useful for
|
|
197
|
+
* generating messages like "1 error" or "2 errors". By default, the plural
|
|
198
|
+
* string is the singular string with an "s" appended to it.
|
|
199
|
+
*
|
|
200
|
+
* This assumes that the text is in English, and likely won't work for some
|
|
201
|
+
* other languages.
|
|
202
|
+
*
|
|
203
|
+
* @param count - The count.
|
|
204
|
+
* @param singular - The singular string.
|
|
205
|
+
* @param plural - The plural string.
|
|
206
|
+
* @returns The singular or plural string.
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* pluralize(1, 'error'); // => 'error'
|
|
210
|
+
* pluralize(2, 'error'); // => 'errors'
|
|
211
|
+
* pluralize(1, 'error', 'problem'); // => 'error'
|
|
212
|
+
* pluralize(2, 'error', 'problems'); // => 'problems'
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
export declare function pluralize(count: number, singular: string, plural?: string): string;
|
|
216
|
+
/**
|
|
217
|
+
* Get an object that can be used as fallback config for Webpack's
|
|
218
|
+
* `fallback` config.
|
|
219
|
+
*
|
|
220
|
+
* @param polyfills - The polyfill object from the snap config.
|
|
221
|
+
* @returns The webpack fallback config.
|
|
222
|
+
*/
|
|
223
|
+
export declare function getFallbacks(polyfills: ProcessedWebpackConfig['polyfills']): {
|
|
224
|
+
[index: string]: string | false;
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Get an object that can be used as environment variables for Webpack's
|
|
228
|
+
* `DefinePlugin`.
|
|
229
|
+
*
|
|
230
|
+
* @param environment - The environment object from the Snap config.
|
|
231
|
+
* @param defaults - The default environment variables.
|
|
232
|
+
* @returns The Webpack environment variables.
|
|
233
|
+
*/
|
|
234
|
+
export declare function getEnvironmentVariables(environment: Record<string, unknown>, defaults?: {
|
|
235
|
+
NODE_DEBUG: string;
|
|
236
|
+
NODE_ENV: string;
|
|
237
|
+
DEBUG: string;
|
|
238
|
+
}): {
|
|
239
|
+
[k: string]: string;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Format the given text to fit within the terminal width.
|
|
243
|
+
*
|
|
244
|
+
* @param text - The text to format.
|
|
245
|
+
* @param indent - The indentation to use.
|
|
246
|
+
* @param initialIndent - The initial indentation to use, i.e., the indentation
|
|
247
|
+
* for the first line.
|
|
248
|
+
* @returns The formatted text.
|
|
249
|
+
*/
|
|
250
|
+
export declare function formatText(text: string, indent: number, initialIndent?: number): string;
|
|
251
|
+
/**
|
|
252
|
+
* Get an SVG from the given bytes and mime type.
|
|
253
|
+
*
|
|
254
|
+
* @param mimeType - The mime type of the image.
|
|
255
|
+
* @param bytes - The image bytes.
|
|
256
|
+
* @returns The SVG.
|
|
257
|
+
*/
|
|
258
|
+
export declare function getImageSVG(mimeType: string, bytes: Uint8Array): string;
|
|
259
|
+
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/webpack/utils.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;AAE7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAkB;AAGxD,eAAO,MAAM,iBAAiB,QAM7B,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiC7B,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,MAAM,EACN,SAAS,GACV,EAAE,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;IAarB;;;;OAIG;;IAGH;;;;;OAKG;;;QAID;;;;;WAKG;;;;gBAKC;;;;;;;mBAOG;;gBAGH;;;;;mBAKG;;;;;oBAMD;;;;;uBAKG;;oBAGH;;;;;;uBAMG;;oBAGH;;;;;uBAKG;;;;;QAMT;;;;;WAKG;;YAED;;;;;;;eAOG;;;;;;;GASV;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,sBAAsB,CAAC,WAAW,CAAC,GAC7C,aAAa,CAAC,SAAS,CAAC,CAU1B;AAED;;;;;;;;;GASG;AAEH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,MAAM,gBAChD,MAAM,UAO3B;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,sBAM3C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,MAAM,SAAiB,UAGxB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,sBAAsB,CAAC,WAAW,CAAC,GAAG;IAC5E,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;CACjC,CAsBA;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,QAAQ;;;;CAIP;;EAQF;AAiDD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,aAAa,SAAS,UAWvB;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,UAG9D"}
|
package/dist/webpack/utils.mjs
CHANGED
|
@@ -1,39 +1,352 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import "
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
function $importDefault(module) {
|
|
2
|
+
if (module?.__esModule) {
|
|
3
|
+
return module.default;
|
|
4
|
+
}
|
|
5
|
+
return module;
|
|
6
|
+
}
|
|
7
|
+
import { bytesToBase64 } from "@metamask/utils";
|
|
8
|
+
import $chalk from "chalk";
|
|
9
|
+
const { dim } = $chalk;
|
|
10
|
+
import { promises as fs } from "fs";
|
|
11
|
+
import { builtinModules } from "module";
|
|
12
|
+
import { dirname, resolve } from "path";
|
|
13
|
+
import $stripAnsi from "strip-ansi/index.js";
|
|
14
|
+
const stripAnsi = $importDefault($stripAnsi);
|
|
15
|
+
import { browserify, getFunctionLoader } from "./loaders/index.mjs";
|
|
16
|
+
export const BROWSERSLIST_FILE = resolve(dirname(
|
|
17
|
+
// eslint-disable-next-line n/no-extraneous-require
|
|
18
|
+
require.resolve('@metamask/snaps-cli/package.json')), '.browserslistrc');
|
|
19
|
+
export const WEBPACK_FALLBACKS = {
|
|
20
|
+
assert: require.resolve('assert/'),
|
|
21
|
+
buffer: require.resolve('buffer/'),
|
|
22
|
+
console: require.resolve('console-browserify'),
|
|
23
|
+
constants: require.resolve('constants-browserify'),
|
|
24
|
+
crypto: require.resolve('crypto-browserify'),
|
|
25
|
+
domain: require.resolve('domain-browser'),
|
|
26
|
+
events: require.resolve('events/'),
|
|
27
|
+
http: require.resolve('stream-http'),
|
|
28
|
+
https: require.resolve('https-browserify'),
|
|
29
|
+
os: require.resolve('os-browserify/browser'),
|
|
30
|
+
path: require.resolve('path-browserify'),
|
|
31
|
+
punycode: require.resolve('punycode/'),
|
|
32
|
+
process: require.resolve('process/browser'),
|
|
33
|
+
querystring: require.resolve('querystring-es3'),
|
|
34
|
+
stream: require.resolve('stream-browserify'),
|
|
35
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
36
|
+
_stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),
|
|
37
|
+
_stream_passthrough: require.resolve('readable-stream/lib/_stream_passthrough'),
|
|
38
|
+
_stream_readable: require.resolve('readable-stream/lib/_stream_readable'),
|
|
39
|
+
_stream_transform: require.resolve('readable-stream/lib/_stream_transform'),
|
|
40
|
+
_stream_writable: require.resolve('readable-stream/lib/_stream_writable'),
|
|
41
|
+
string_decoder: require.resolve('string_decoder/'),
|
|
42
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
43
|
+
sys: require.resolve('util/'),
|
|
44
|
+
timers: require.resolve('timers-browserify'),
|
|
45
|
+
tty: require.resolve('tty-browserify'),
|
|
46
|
+
url: require.resolve('url/'),
|
|
47
|
+
util: require.resolve('util/'),
|
|
48
|
+
vm: require.resolve('vm-browserify'),
|
|
49
|
+
zlib: require.resolve('browserify-zlib'),
|
|
38
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Get the default loader for JavaScript and TypeScript files, based on the
|
|
53
|
+
* config object.
|
|
54
|
+
*
|
|
55
|
+
* - If the `legacy` option is set, we use the custom `browserify` loader. This
|
|
56
|
+
* uses the legacy Browserify config to transpile the code.
|
|
57
|
+
* - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the
|
|
58
|
+
* `SWC` compiler, which is a much faster alternative to Babel and TypeScript's
|
|
59
|
+
* own compiler.
|
|
60
|
+
*
|
|
61
|
+
* @param config - The processed snap Webpack config.
|
|
62
|
+
* @param config.legacy - The legacy config object, if any.
|
|
63
|
+
* @param config.sourceMap - Whether to generate source maps.
|
|
64
|
+
* @see https://swc.rs/docs/usage/swc-loader
|
|
65
|
+
* @returns The default loader.
|
|
66
|
+
*/
|
|
67
|
+
export async function getDefaultLoader({ legacy, sourceMap, }) {
|
|
68
|
+
if (legacy) {
|
|
69
|
+
/**
|
|
70
|
+
* If the snap uses the legacy config, we use the custom `browserify`
|
|
71
|
+
* loader. This uses the legacy Browserify config to transpile the code.
|
|
72
|
+
* This is necessary for backwards compatibility with the
|
|
73
|
+
* `bundlerCustomizer` function.
|
|
74
|
+
*/
|
|
75
|
+
return getFunctionLoader(browserify, legacy);
|
|
76
|
+
}
|
|
77
|
+
const targets = await getBrowserslistTargets();
|
|
78
|
+
return {
|
|
79
|
+
/**
|
|
80
|
+
* We use the `swc-loader` to transpile TypeScript and JavaScript files.
|
|
81
|
+
* This is a Webpack loader that uses the `SWC` compiler, which is a much
|
|
82
|
+
* faster alternative to Babel and TypeScript's own compiler.
|
|
83
|
+
*/
|
|
84
|
+
loader: require.resolve('swc-loader'),
|
|
85
|
+
/**
|
|
86
|
+
* The options for the `swc-loader`. These can be overridden in the
|
|
87
|
+
* `.swcrc` file.
|
|
88
|
+
*
|
|
89
|
+
* @see https://swc.rs/docs/configuration/swcrc
|
|
90
|
+
*/
|
|
91
|
+
options: {
|
|
92
|
+
sync: false,
|
|
93
|
+
/**
|
|
94
|
+
* This tells SWC to generate source maps. We set it to the
|
|
95
|
+
* `sourceMap` value from the config object.
|
|
96
|
+
*
|
|
97
|
+
* This must be enabled if source maps are enabled in the config.
|
|
98
|
+
*/
|
|
99
|
+
sourceMaps: Boolean(getDevTool(sourceMap)),
|
|
100
|
+
jsc: {
|
|
101
|
+
parser: {
|
|
102
|
+
/**
|
|
103
|
+
* This tells the parser to parse TypeScript files. If you
|
|
104
|
+
* don't need to support TypeScript, you can set this to
|
|
105
|
+
* `ecmascript` instead, but there's no harm in leaving it
|
|
106
|
+
* as `typescript`.
|
|
107
|
+
*
|
|
108
|
+
* @see https://swc.rs/docs/configuration/compilation#jscparser
|
|
109
|
+
*/
|
|
110
|
+
syntax: 'typescript',
|
|
111
|
+
/**
|
|
112
|
+
* This tells the parser to transpile JSX.
|
|
113
|
+
*
|
|
114
|
+
* @see https://swc.rs/docs/configuration/compilation#jscparser
|
|
115
|
+
* @see https://swc.rs/docs/configuration/compilation#jscparserjsx
|
|
116
|
+
*/
|
|
117
|
+
tsx: true,
|
|
118
|
+
},
|
|
119
|
+
transform: {
|
|
120
|
+
react: {
|
|
121
|
+
/**
|
|
122
|
+
* This tells SWC to use the JSX runtime, instead of the
|
|
123
|
+
* `createElement` function.
|
|
124
|
+
*
|
|
125
|
+
* @see https://swc.rs/docs/configuration/compilation#jsctransformreact
|
|
126
|
+
*/
|
|
127
|
+
runtime: 'automatic',
|
|
128
|
+
/**
|
|
129
|
+
* This tells SWC to import the JSX runtime from the
|
|
130
|
+
* `@metamask/snaps-sdk` package, instead of the default React
|
|
131
|
+
* package.
|
|
132
|
+
*
|
|
133
|
+
* @see https://swc.rs/docs/configuration/compilation#jsctransformreact
|
|
134
|
+
*/
|
|
135
|
+
importSource: '@metamask/snaps-sdk',
|
|
136
|
+
/**
|
|
137
|
+
* This tells SWC to use `Object.assign` and `Object.create` for
|
|
138
|
+
* JSX spread attributes, instead of the default behavior.
|
|
139
|
+
*
|
|
140
|
+
* @see https://swc.rs/docs/configuration/compilation#jsctransformreact
|
|
141
|
+
*/
|
|
142
|
+
useBuiltins: true,
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
/**
|
|
147
|
+
* The module configuration. This tells SWC how to output the
|
|
148
|
+
* transpiled code.
|
|
149
|
+
*
|
|
150
|
+
* @see https://swc.rs/docs/configuration/modules
|
|
151
|
+
*/
|
|
152
|
+
module: {
|
|
153
|
+
/**
|
|
154
|
+
* This tells SWC to output ES6 modules. This will allow Webpack to
|
|
155
|
+
* optimize the output code better. Snaps don't support ES6 however, so
|
|
156
|
+
* the output code will be transpiled to CommonJS by Webpack later in
|
|
157
|
+
* the build process.
|
|
158
|
+
*
|
|
159
|
+
* @see https://swc.rs/docs/configuration/modules#es6
|
|
160
|
+
*/
|
|
161
|
+
type: 'es6',
|
|
162
|
+
},
|
|
163
|
+
env: {
|
|
164
|
+
targets: targets.join(', '),
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Get the Webpack devtool configuration based on the given snap config.
|
|
171
|
+
*
|
|
172
|
+
* - If `sourceMap` is `inline`, return `inline-source-map`.
|
|
173
|
+
* - If `sourceMap` is `true`, return `source-map`.
|
|
174
|
+
* - Otherwise, return `false`.
|
|
175
|
+
*
|
|
176
|
+
* @param sourceMap - The `sourceMap` value from the snap config.
|
|
177
|
+
* @returns The Webpack devtool configuration.
|
|
178
|
+
*/
|
|
179
|
+
export function getDevTool(sourceMap) {
|
|
180
|
+
if (sourceMap === 'inline') {
|
|
181
|
+
return 'inline-source-map';
|
|
182
|
+
}
|
|
183
|
+
if (sourceMap === true) {
|
|
184
|
+
return 'source-map';
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get a function that can be used as handler function for Webpack's
|
|
190
|
+
* `ProgressPlugin`.
|
|
191
|
+
*
|
|
192
|
+
* @param spinner - The spinner to update.
|
|
193
|
+
* @param spinnerText - The initial spinner text. This will be prepended to the
|
|
194
|
+
* percentage.
|
|
195
|
+
* @returns A function that can be used as handler function for Webpack's
|
|
196
|
+
* `ProgressPlugin`.
|
|
197
|
+
*/
|
|
198
|
+
// Note: This is extracted for testing purposes.
|
|
199
|
+
export function getProgressHandler(spinner, spinnerText) {
|
|
200
|
+
return (percentage) => {
|
|
201
|
+
if (spinner && spinnerText) {
|
|
202
|
+
spinner.text = `${spinnerText} ${dim(`(${Math.round(percentage * 100)}%)`)}`;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get the targets from the `.browserslistrc` file.
|
|
208
|
+
*
|
|
209
|
+
* @returns The browser targets as an array of strings.
|
|
210
|
+
*/
|
|
211
|
+
export async function getBrowserslistTargets() {
|
|
212
|
+
const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');
|
|
213
|
+
return contents
|
|
214
|
+
.split('\n')
|
|
215
|
+
.map((line) => line.trim())
|
|
216
|
+
.filter((line) => line && !line.startsWith('#'));
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Get a singular or plural string based on the given count. This is useful for
|
|
220
|
+
* generating messages like "1 error" or "2 errors". By default, the plural
|
|
221
|
+
* string is the singular string with an "s" appended to it.
|
|
222
|
+
*
|
|
223
|
+
* This assumes that the text is in English, and likely won't work for some
|
|
224
|
+
* other languages.
|
|
225
|
+
*
|
|
226
|
+
* @param count - The count.
|
|
227
|
+
* @param singular - The singular string.
|
|
228
|
+
* @param plural - The plural string.
|
|
229
|
+
* @returns The singular or plural string.
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* pluralize(1, 'error'); // => 'error'
|
|
233
|
+
* pluralize(2, 'error'); // => 'errors'
|
|
234
|
+
* pluralize(1, 'error', 'problem'); // => 'error'
|
|
235
|
+
* pluralize(2, 'error', 'problems'); // => 'problems'
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
export function pluralize(count, singular, plural = `${singular}s`) {
|
|
239
|
+
return count === 1 ? singular : plural;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Get an object that can be used as fallback config for Webpack's
|
|
243
|
+
* `fallback` config.
|
|
244
|
+
*
|
|
245
|
+
* @param polyfills - The polyfill object from the snap config.
|
|
246
|
+
* @returns The webpack fallback config.
|
|
247
|
+
*/
|
|
248
|
+
export function getFallbacks(polyfills) {
|
|
249
|
+
if (polyfills === true) {
|
|
250
|
+
return Object.fromEntries(builtinModules.map((name) => [
|
|
251
|
+
name,
|
|
252
|
+
WEBPACK_FALLBACKS[name] ?? false,
|
|
253
|
+
]));
|
|
254
|
+
}
|
|
255
|
+
if (polyfills === false) {
|
|
256
|
+
return Object.fromEntries(builtinModules.map((name) => [name, false]));
|
|
257
|
+
}
|
|
258
|
+
return Object.fromEntries(builtinModules.map((name) => [
|
|
259
|
+
name,
|
|
260
|
+
polyfills[name]
|
|
261
|
+
? WEBPACK_FALLBACKS[name]
|
|
262
|
+
: false,
|
|
263
|
+
]));
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Get an object that can be used as environment variables for Webpack's
|
|
267
|
+
* `DefinePlugin`.
|
|
268
|
+
*
|
|
269
|
+
* @param environment - The environment object from the Snap config.
|
|
270
|
+
* @param defaults - The default environment variables.
|
|
271
|
+
* @returns The Webpack environment variables.
|
|
272
|
+
*/
|
|
273
|
+
export function getEnvironmentVariables(environment, defaults = {
|
|
274
|
+
NODE_DEBUG: 'false',
|
|
275
|
+
NODE_ENV: 'production',
|
|
276
|
+
DEBUG: 'false',
|
|
277
|
+
}) {
|
|
278
|
+
return Object.fromEntries(Object.entries({
|
|
279
|
+
...defaults,
|
|
280
|
+
...environment,
|
|
281
|
+
}).map(([key, value]) => [`process.env.${key}`, JSON.stringify(value)]));
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Format the given line to fit within the terminal width.
|
|
285
|
+
*
|
|
286
|
+
* @param line - The line to format.
|
|
287
|
+
* @param indent - The indentation to use.
|
|
288
|
+
* @param initialIndent - The initial indentation to use, i.e., the indentation
|
|
289
|
+
* for the first line.
|
|
290
|
+
* @returns The formatted line.
|
|
291
|
+
*/
|
|
292
|
+
function formatLine(line, indent, initialIndent) {
|
|
293
|
+
const terminalWidth = process.stdout.columns;
|
|
294
|
+
if (!terminalWidth) {
|
|
295
|
+
return `${' '.repeat(initialIndent)}${line}`;
|
|
296
|
+
}
|
|
297
|
+
return line.split(' ').reduce(({ formattedText, currentLineLength }, word, index) => {
|
|
298
|
+
// `chalk` adds ANSI escape codes to the text, which are not visible
|
|
299
|
+
// characters. We need to strip them to get the visible length of the
|
|
300
|
+
// text.
|
|
301
|
+
const visibleWord = stripAnsi(word);
|
|
302
|
+
// Determine if a space should be added before the word.
|
|
303
|
+
const spaceBeforeWord = index > 0 ? ' ' : '';
|
|
304
|
+
const wordLengthWithSpace = visibleWord.length + spaceBeforeWord.length;
|
|
305
|
+
// If the word would exceed the terminal width, start a new line.
|
|
306
|
+
if (currentLineLength + wordLengthWithSpace > terminalWidth) {
|
|
307
|
+
return {
|
|
308
|
+
formattedText: `${formattedText}\n${' '.repeat(indent)}${word}`,
|
|
309
|
+
currentLineLength: indent + visibleWord.length,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
// Otherwise, add the word to the current line.
|
|
313
|
+
return {
|
|
314
|
+
formattedText: formattedText + spaceBeforeWord + word,
|
|
315
|
+
currentLineLength: currentLineLength + wordLengthWithSpace,
|
|
316
|
+
};
|
|
317
|
+
}, {
|
|
318
|
+
formattedText: ' '.repeat(initialIndent),
|
|
319
|
+
currentLineLength: initialIndent,
|
|
320
|
+
}).formattedText;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Format the given text to fit within the terminal width.
|
|
324
|
+
*
|
|
325
|
+
* @param text - The text to format.
|
|
326
|
+
* @param indent - The indentation to use.
|
|
327
|
+
* @param initialIndent - The initial indentation to use, i.e., the indentation
|
|
328
|
+
* for the first line.
|
|
329
|
+
* @returns The formatted text.
|
|
330
|
+
*/
|
|
331
|
+
export function formatText(text, indent, initialIndent = indent) {
|
|
332
|
+
const lines = text.split('\n');
|
|
333
|
+
// Apply formatting to each line separately and then join them.
|
|
334
|
+
return lines
|
|
335
|
+
.map((line, index) => {
|
|
336
|
+
const lineIndent = index === 0 ? initialIndent : indent;
|
|
337
|
+
return formatLine(line, indent, lineIndent);
|
|
338
|
+
})
|
|
339
|
+
.join('\n');
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Get an SVG from the given bytes and mime type.
|
|
343
|
+
*
|
|
344
|
+
* @param mimeType - The mime type of the image.
|
|
345
|
+
* @param bytes - The image bytes.
|
|
346
|
+
* @returns The SVG.
|
|
347
|
+
*/
|
|
348
|
+
export function getImageSVG(mimeType, bytes) {
|
|
349
|
+
const dataUrl = `data:${mimeType};base64,${bytesToBase64(bytes)}`;
|
|
350
|
+
return `<svg xmlns="http://www.w3.org/2000/svg"><image href="${dataUrl}" /></svg>`;
|
|
351
|
+
}
|
|
39
352
|
//# sourceMappingURL=utils.mjs.map
|