@metamask/snaps-cli 1.0.2 → 2.0.1
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/.browserslistrc +3 -0
- package/CHANGELOG.md +35 -375
- package/README.md +548 -69
- package/dist/cjs/builders.js +148 -0
- package/dist/cjs/builders.js.map +1 -0
- package/dist/cjs/cli.js +35 -0
- package/dist/cjs/cli.js.map +1 -0
- package/dist/cjs/commands/build/build.js +54 -0
- package/dist/cjs/commands/build/build.js.map +1 -0
- package/dist/cjs/commands/build/implementation.js +31 -0
- package/dist/cjs/commands/build/implementation.js.map +1 -0
- package/dist/cjs/commands/build/index.js +45 -0
- package/dist/cjs/commands/build/index.js.map +1 -0
- package/dist/cjs/commands/eval/eval.js +57 -0
- package/dist/cjs/commands/eval/eval.js.map +1 -0
- package/dist/cjs/commands/eval/implementation.js +27 -0
- package/dist/cjs/commands/eval/implementation.js.map +1 -0
- package/dist/cjs/commands/eval/index.js +50 -0
- package/dist/cjs/commands/eval/index.js.map +1 -0
- package/dist/cjs/commands/index.js +30 -0
- package/dist/cjs/commands/index.js.map +1 -0
- package/dist/cjs/commands/manifest/implementation.js +34 -0
- package/dist/cjs/commands/manifest/implementation.js.map +1 -0
- package/dist/cjs/commands/manifest/index.js +50 -0
- package/dist/cjs/commands/manifest/index.js.map +1 -0
- package/dist/cjs/commands/manifest/manifest.js +55 -0
- package/dist/cjs/commands/manifest/manifest.js.map +1 -0
- package/dist/cjs/commands/serve/index.js +33 -0
- package/dist/cjs/commands/serve/index.js.map +1 -0
- package/dist/cjs/commands/serve/serve.js +21 -0
- package/dist/cjs/commands/serve/serve.js.map +1 -0
- package/dist/cjs/commands/watch/implementation.js +35 -0
- package/dist/cjs/commands/watch/implementation.js.map +1 -0
- package/dist/cjs/commands/watch/index.js +47 -0
- package/dist/cjs/commands/watch/index.js.map +1 -0
- package/dist/cjs/commands/watch/watch.js +51 -0
- package/dist/cjs/commands/watch/watch.js.map +1 -0
- package/dist/cjs/config.js +323 -0
- package/dist/cjs/config.js.map +1 -0
- package/dist/cjs/errors.js +37 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.js +77 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/main.js +19 -0
- package/dist/cjs/main.js.map +1 -0
- package/dist/cjs/utils/cli.js +61 -0
- package/dist/cjs/utils/cli.js.map +1 -0
- package/dist/cjs/utils/errors.js +42 -0
- package/dist/cjs/utils/errors.js.map +1 -0
- package/dist/cjs/utils/index.js +25 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/legacy.js +48 -0
- package/dist/cjs/utils/legacy.js.map +1 -0
- package/dist/cjs/utils/logging.js +46 -0
- package/dist/cjs/utils/logging.js.map +1 -0
- package/dist/cjs/utils/path.js +16 -0
- package/dist/cjs/utils/path.js.map +1 -0
- package/dist/cjs/utils/steps.js +52 -0
- package/dist/cjs/utils/steps.js.map +1 -0
- package/dist/cjs/webpack/compiler.js +96 -0
- package/dist/cjs/webpack/compiler.js.map +1 -0
- package/dist/cjs/webpack/config.js +250 -0
- package/dist/cjs/webpack/config.js.map +1 -0
- package/dist/cjs/webpack/index.js +22 -0
- package/dist/cjs/webpack/index.js.map +1 -0
- package/dist/cjs/webpack/loaders/browserify.js +97 -0
- package/dist/cjs/webpack/loaders/browserify.js.map +1 -0
- package/dist/cjs/webpack/loaders/wasm.js +36 -0
- package/dist/cjs/webpack/loaders/wasm.js.map +1 -0
- package/dist/cjs/webpack/plugins.js +340 -0
- package/dist/cjs/webpack/plugins.js.map +1 -0
- package/dist/cjs/webpack/utils.js +181 -0
- package/dist/cjs/webpack/utils.js.map +1 -0
- package/dist/{builders.js → esm/builders.js} +48 -51
- package/dist/esm/builders.js.map +1 -0
- package/dist/esm/cli.js +26 -0
- package/dist/esm/cli.js.map +1 -0
- package/dist/esm/commands/build/build.js +51 -0
- package/dist/esm/commands/build/build.js.map +1 -0
- package/dist/esm/commands/build/implementation.js +27 -0
- package/dist/esm/commands/build/implementation.js.map +1 -0
- package/dist/esm/commands/build/index.js +17 -0
- package/dist/esm/commands/build/index.js.map +1 -0
- package/dist/esm/commands/eval/eval.js +54 -0
- package/dist/esm/commands/eval/eval.js.map +1 -0
- package/dist/esm/commands/eval/implementation.js +24 -0
- package/dist/esm/commands/eval/implementation.js.map +1 -0
- package/dist/esm/commands/eval/index.js +22 -0
- package/dist/esm/commands/eval/index.js.map +1 -0
- package/dist/esm/commands/index.js +15 -0
- package/dist/esm/commands/index.js.map +1 -0
- package/dist/esm/commands/manifest/implementation.js +33 -0
- package/dist/esm/commands/manifest/implementation.js.map +1 -0
- package/dist/esm/commands/manifest/index.js +22 -0
- package/dist/esm/commands/manifest/index.js.map +1 -0
- package/dist/esm/commands/manifest/manifest.js +52 -0
- package/dist/esm/commands/manifest/manifest.js.map +1 -0
- package/dist/esm/commands/serve/index.js +18 -0
- package/dist/esm/commands/serve/index.js.map +1 -0
- package/dist/esm/commands/serve/serve.js +17 -0
- package/dist/esm/commands/serve/serve.js.map +1 -0
- package/dist/esm/commands/watch/implementation.js +34 -0
- package/dist/esm/commands/watch/implementation.js.map +1 -0
- package/dist/esm/commands/watch/index.js +19 -0
- package/dist/esm/commands/watch/index.js.map +1 -0
- package/dist/esm/commands/watch/watch.js +50 -0
- package/dist/esm/commands/watch/watch.js.map +1 -0
- package/dist/esm/config.js +327 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/errors.js +30 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/main.js +10 -0
- package/dist/esm/main.js.map +1 -0
- package/dist/esm/utils/cli.js +43 -0
- package/dist/esm/utils/cli.js.map +1 -0
- package/dist/esm/utils/errors.js +43 -0
- package/dist/esm/utils/errors.js.map +1 -0
- package/dist/esm/utils/index.js +8 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/legacy.js +47 -0
- package/dist/esm/utils/legacy.js.map +1 -0
- package/dist/esm/utils/logging.js +40 -0
- package/dist/esm/utils/logging.js.map +1 -0
- package/dist/esm/utils/path.js +13 -0
- package/dist/esm/utils/path.js.map +1 -0
- package/dist/esm/utils/steps.js +43 -0
- package/dist/esm/utils/steps.js.map +1 -0
- package/dist/esm/webpack/compiler.js +89 -0
- package/dist/esm/webpack/compiler.js.map +1 -0
- package/dist/esm/webpack/config.js +252 -0
- package/dist/esm/webpack/config.js.map +1 -0
- package/dist/esm/webpack/index.js +5 -0
- package/dist/esm/webpack/index.js.map +1 -0
- package/dist/esm/webpack/loaders/browserify.js +82 -0
- package/dist/esm/webpack/loaders/browserify.js.map +1 -0
- package/dist/esm/webpack/loaders/wasm.js +26 -0
- package/dist/esm/webpack/loaders/wasm.js.map +1 -0
- package/dist/esm/webpack/plugins.js +343 -0
- package/dist/esm/webpack/plugins.js.map +1 -0
- package/dist/esm/webpack/utils.js +208 -0
- package/dist/esm/webpack/utils.js.map +1 -0
- package/dist/types/__fixtures__/configs/cjs.d.ts +1 -0
- package/dist/types/__fixtures__/configs/esm.d.ts +3 -0
- package/dist/types/__fixtures__/configs/invalid.d.ts +3 -0
- package/dist/types/__fixtures__/configs/javascript/snap.config.d.ts +0 -0
- package/dist/types/__fixtures__/configs/typescript/snap.config.d.ts +3 -0
- package/dist/types/builders.d.ts +8 -0
- package/dist/{cli.d.ts → types/cli.d.ts} +1 -1
- package/dist/types/commands/build/build.d.ts +10 -0
- package/dist/types/commands/build/implementation.d.ts +10 -0
- package/dist/types/commands/build/index.d.ts +10 -0
- package/dist/types/commands/eval/__test__/browserify/bad/snap.config.d.ts +3 -0
- package/dist/types/commands/eval/__test__/browserify/good/snap.config.d.ts +3 -0
- package/dist/types/commands/eval/__test__/webpack/bad/snap.config.d.ts +3 -0
- package/dist/types/commands/eval/__test__/webpack/good/snap.config.d.ts +3 -0
- package/dist/types/commands/eval/__test__/webpack/snap.config.d.ts +3 -0
- package/dist/types/commands/eval/eval.d.ts +14 -0
- package/dist/types/commands/eval/implementation.d.ts +9 -0
- package/dist/types/commands/eval/index.d.ts +10 -0
- package/dist/types/commands/manifest/implementation.d.ts +12 -0
- package/dist/types/commands/manifest/index.d.ts +10 -0
- package/dist/types/commands/manifest/manifest.d.ts +14 -0
- package/dist/{cmds/build → types/commands/serve}/index.d.ts +4 -4
- package/dist/types/commands/serve/serve.d.ts +16 -0
- package/dist/types/commands/watch/implementation.d.ts +14 -0
- package/dist/types/commands/watch/index.d.ts +10 -0
- package/dist/types/commands/watch/watch.d.ts +19 -0
- package/dist/types/config.d.ts +792 -0
- package/dist/types/errors.d.ts +25 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/utils/cli.d.ts +17 -0
- package/dist/types/utils/errors.d.ts +23 -0
- package/dist/types/utils/index.d.ts +6 -0
- package/dist/types/utils/legacy.d.ts +27 -0
- package/dist/types/utils/logging.d.ts +22 -0
- package/dist/types/utils/path.d.ts +9 -0
- package/dist/types/utils/steps.d.ts +17 -0
- package/dist/types/webpack/compiler.d.ts +29 -0
- package/dist/types/webpack/config.d.ts +37 -0
- package/dist/types/webpack/index.d.ts +3 -0
- package/dist/types/webpack/loaders/browserify.d.ts +16 -0
- package/dist/types/webpack/loaders/wasm.d.ts +20 -0
- package/dist/types/webpack/plugins.d.ts +147 -0
- package/dist/types/webpack/utils.d.ts +188 -0
- package/package.json +83 -43
- package/dist/builders.d.ts +0 -27
- package/dist/builders.js.map +0 -1
- package/dist/cli.js +0 -51
- package/dist/cli.js.map +0 -1
- package/dist/cmds/build/buildHandler.d.ts +0 -13
- package/dist/cmds/build/buildHandler.js +0 -37
- package/dist/cmds/build/buildHandler.js.map +0 -1
- package/dist/cmds/build/bundle.d.ts +0 -15
- package/dist/cmds/build/bundle.js +0 -80
- package/dist/cmds/build/bundle.js.map +0 -1
- package/dist/cmds/build/index.js +0 -29
- package/dist/cmds/build/index.js.map +0 -1
- package/dist/cmds/build/utils.d.ts +0 -56
- package/dist/cmds/build/utils.js +0 -100
- package/dist/cmds/build/utils.js.map +0 -1
- package/dist/cmds/eval/evalHandler.d.ts +0 -9
- package/dist/cmds/eval/evalHandler.js +0 -25
- package/dist/cmds/eval/evalHandler.js.map +0 -1
- package/dist/cmds/eval/index.d.ts +0 -9
- package/dist/cmds/eval/index.js +0 -15
- package/dist/cmds/eval/index.js.map +0 -1
- package/dist/cmds/index.js +0 -14
- package/dist/cmds/index.js.map +0 -1
- package/dist/cmds/init/index.d.ts +0 -9
- package/dist/cmds/init/index.js +0 -34
- package/dist/cmds/init/index.js.map +0 -1
- package/dist/cmds/init/initHandler.d.ts +0 -26
- package/dist/cmds/init/initHandler.js +0 -69
- package/dist/cmds/init/initHandler.js.map +0 -1
- package/dist/cmds/init/initUtils.d.ts +0 -39
- package/dist/cmds/init/initUtils.js +0 -122
- package/dist/cmds/init/initUtils.js.map +0 -1
- package/dist/cmds/manifest/index.d.ts +0 -9
- package/dist/cmds/manifest/index.js +0 -24
- package/dist/cmds/manifest/index.js.map +0 -1
- package/dist/cmds/manifest/manifestHandler.d.ts +0 -10
- package/dist/cmds/manifest/manifestHandler.js +0 -50
- package/dist/cmds/manifest/manifestHandler.js.map +0 -1
- package/dist/cmds/serve/index.d.ts +0 -9
- package/dist/cmds/serve/index.js +0 -15
- package/dist/cmds/serve/index.js.map +0 -1
- package/dist/cmds/serve/serveHandler.d.ts +0 -10
- package/dist/cmds/serve/serveHandler.js +0 -59
- package/dist/cmds/serve/serveHandler.js.map +0 -1
- package/dist/cmds/serve/serveUtils.d.ts +0 -22
- package/dist/cmds/serve/serveUtils.js +0 -39
- package/dist/cmds/serve/serveUtils.js.map +0 -1
- package/dist/cmds/watch/index.d.ts +0 -9
- package/dist/cmds/watch/index.js +0 -32
- package/dist/cmds/watch/index.js.map +0 -1
- package/dist/cmds/watch/watchHandler.d.ts +0 -14
- package/dist/cmds/watch/watchHandler.js +0 -100
- package/dist/cmds/watch/watchHandler.js.map +0 -1
- package/dist/main.js +0 -15
- package/dist/main.js.map +0 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -19
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/misc.d.ts +0 -53
- package/dist/utils/misc.js +0 -156
- package/dist/utils/misc.js.map +0 -1
- package/dist/utils/snap-config.d.ts +0 -48
- package/dist/utils/snap-config.js +0 -117
- package/dist/utils/snap-config.js.map +0 -1
- /package/dist/{cmds → types/commands}/index.d.ts +0 -0
- /package/dist/{main.d.ts → types/main.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/commands/manifest/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { manifestHandler } from './manifest';\n\nconst command = {\n command: ['manifest', 'm'],\n desc: 'Validate the snap.manifest.json file',\n builder: (yarg: yargs.Argv) => {\n // Browserify options. These are merged into the config object.\n yarg.option('writeManifest', builders.writeManifest);\n\n // Webpack options.\n yarg.option('fix', builders.fix);\n },\n handler: async (argv: YargsArgs) =>\n manifestHandler(argv.context.config, { fix: argv.fix }),\n};\n\nexport * from './implementation';\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","writeManifest","fix","handler","argv","manifestHandler","context","config"],"mappings":";;;;+BAqBA;;;eAAA;;;iEAnBqB;0BAEW;qBAgBlB;;;;;;;;;;;;;;;;;;;AAdd,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAY;KAAI;IAC1BC,MAAM;IACNC,SAAS,CAACC;QACR,+DAA+D;QAC/DA,KAAKC,MAAM,CAAC,iBAAiBC,iBAAQ,CAACC,aAAa;QAEnD,mBAAmB;QACnBH,KAAKC,MAAM,CAAC,OAAOC,iBAAQ,CAACE,GAAG;IACjC;IACAC,SAAS,OAAOC,OACdC,IAAAA,yBAAe,EAACD,KAAKE,OAAO,CAACC,MAAM,EAAE;YAAEL,KAAKE,KAAKF,GAAG;QAAC;AACzD;MAGA,WAAeP"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "manifestHandler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return manifestHandler;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _snapsutils = require("@metamask/snaps-utils");
|
|
12
|
+
const _errors = require("../../errors");
|
|
13
|
+
const _utils = require("../../utils");
|
|
14
|
+
const _implementation = require("./implementation");
|
|
15
|
+
const steps = [
|
|
16
|
+
{
|
|
17
|
+
name: 'Checking the input file.',
|
|
18
|
+
task: async ({ input })=>{
|
|
19
|
+
if (!await (0, _snapsutils.isFile)(input)) {
|
|
20
|
+
throw new _errors.CommandError(`Manifest file not found: "${input}". Make sure that the \`snap.manifest.json\` file exists.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'Validating the snap manifest.',
|
|
26
|
+
task: async ({ input, config, options, spinner })=>{
|
|
27
|
+
const write = getWriteManifest(config, options);
|
|
28
|
+
const valid = await (0, _implementation.manifest)(input, write, spinner);
|
|
29
|
+
if (valid) {
|
|
30
|
+
spinner.succeed('The snap manifest file is valid.');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
];
|
|
35
|
+
/**
|
|
36
|
+
* Get whether to write the manifest to disk.
|
|
37
|
+
*
|
|
38
|
+
* @param config - The config object.
|
|
39
|
+
* @param options - The options object.
|
|
40
|
+
* @returns Whether to write the manifest to disk.
|
|
41
|
+
*/ function getWriteManifest(config, options) {
|
|
42
|
+
if (typeof options.fix === 'boolean') {
|
|
43
|
+
return options.fix;
|
|
44
|
+
}
|
|
45
|
+
return config.legacy?.writeManifest ?? false;
|
|
46
|
+
}
|
|
47
|
+
async function manifestHandler(config, options) {
|
|
48
|
+
await (0, _utils.executeSteps)(steps, {
|
|
49
|
+
input: config.manifest.path,
|
|
50
|
+
config,
|
|
51
|
+
options
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/commands/manifest/manifest.ts"],"sourcesContent":["import { isFile } from '@metamask/snaps-utils';\n\nimport type { ProcessedConfig } from '../../config';\nimport { CommandError } from '../../errors';\nimport type { Steps } from '../../utils';\nimport { executeSteps } from '../../utils';\nimport { manifest } from './implementation';\n\ntype ManifestOptions = {\n fix?: boolean;\n};\n\ntype ManifestContext = {\n input: string;\n config: ProcessedConfig;\n options: ManifestOptions;\n};\n\nconst steps: Steps<ManifestContext> = [\n {\n name: 'Checking the input file.',\n task: async ({ input }) => {\n if (!(await isFile(input))) {\n throw new CommandError(\n `Manifest file not found: \"${input}\". Make sure that the \\`snap.manifest.json\\` file exists.`,\n );\n }\n },\n },\n {\n name: 'Validating the snap manifest.',\n task: async ({ input, config, options, spinner }) => {\n const write = getWriteManifest(config, options);\n const valid = await manifest(input, write, spinner);\n\n if (valid) {\n spinner.succeed('The snap manifest file is valid.');\n }\n },\n },\n];\n\n/**\n * Get whether to write the manifest to disk.\n *\n * @param config - The config object.\n * @param options - The options object.\n * @returns Whether to write the manifest to disk.\n */\nfunction getWriteManifest(config: ProcessedConfig, options: ManifestOptions) {\n if (typeof options.fix === 'boolean') {\n return options.fix;\n }\n\n return config.legacy?.writeManifest ?? false;\n}\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param config - The config object.\n * @param options - The options object.\n */\nexport async function manifestHandler(\n config: ProcessedConfig,\n options: ManifestOptions,\n) {\n await executeSteps(steps, {\n input: config.manifest.path,\n config,\n options,\n });\n}\n"],"names":["manifestHandler","steps","name","task","input","isFile","CommandError","config","options","spinner","write","getWriteManifest","valid","manifest","succeed","fix","legacy","writeManifest","executeSteps","path"],"mappings":";;;;+BAiEsBA;;;eAAAA;;;4BAjEC;wBAGM;uBAEA;gCACJ;AAYzB,MAAMC,QAAgC;IACpC;QACEC,MAAM;QACNC,MAAM,OAAO,EAAEC,KAAK,EAAE;YACpB,IAAI,CAAE,MAAMC,IAAAA,kBAAM,EAACD,QAAS;gBAC1B,MAAM,IAAIE,oBAAY,CACpB,CAAC,0BAA0B,EAAEF,MAAM,yDAAyD,CAAC;YAEjG;QACF;IACF;IACA;QACEF,MAAM;QACNC,MAAM,OAAO,EAAEC,KAAK,EAAEG,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE;YAC9C,MAAMC,QAAQC,iBAAiBJ,QAAQC;YACvC,MAAMI,QAAQ,MAAMC,IAAAA,wBAAQ,EAACT,OAAOM,OAAOD;YAE3C,IAAIG,OAAO;gBACTH,QAAQK,OAAO,CAAC;YAClB;QACF;IACF;CACD;AAED;;;;;;CAMC,GACD,SAASH,iBAAiBJ,MAAuB,EAAEC,OAAwB;IACzE,IAAI,OAAOA,QAAQO,GAAG,KAAK,WAAW;QACpC,OAAOP,QAAQO,GAAG;IACpB;IAEA,OAAOR,OAAOS,MAAM,EAAEC,iBAAiB;AACzC;AAUO,eAAejB,gBACpBO,MAAuB,EACvBC,OAAwB;IAExB,MAAMU,IAAAA,mBAAY,EAACjB,OAAO;QACxBG,OAAOG,OAAOM,QAAQ,CAACM,IAAI;QAC3BZ;QACAC;IACF;AACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _builders = /*#__PURE__*/ _interop_require_default(require("../../builders"));
|
|
12
|
+
const _serve = require("./serve");
|
|
13
|
+
function _interop_require_default(obj) {
|
|
14
|
+
return obj && obj.__esModule ? obj : {
|
|
15
|
+
default: obj
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const command = {
|
|
19
|
+
command: [
|
|
20
|
+
'serve',
|
|
21
|
+
's'
|
|
22
|
+
],
|
|
23
|
+
desc: 'Locally serve Snap file(s) for testing',
|
|
24
|
+
builder: (yarg)=>{
|
|
25
|
+
yarg.option('root', _builders.default.root).option('port', _builders.default.port);
|
|
26
|
+
},
|
|
27
|
+
handler: async (argv)=>(0, _serve.serveHandler)(argv.context.config, {
|
|
28
|
+
port: argv.port ?? argv.context.config.server.port
|
|
29
|
+
})
|
|
30
|
+
};
|
|
31
|
+
const _default = command;
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/commands/serve/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { serveHandler } from './serve';\n\nconst command = {\n command: ['serve', 's'],\n desc: 'Locally serve Snap file(s) for testing',\n builder: (yarg: yargs.Argv) => {\n yarg.option('root', builders.root).option('port', builders.port);\n },\n handler: async (argv: YargsArgs) =>\n serveHandler(argv.context.config, {\n port: argv.port ?? argv.context.config.server.port,\n }),\n};\n\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","root","port","handler","argv","serveHandler","context","config","server"],"mappings":";;;;+BAkBA;;;eAAA;;;iEAhBqB;uBAEQ;;;;;;AAE7B,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KAAKC,MAAM,CAAC,QAAQC,iBAAQ,CAACC,IAAI,EAAEF,MAAM,CAAC,QAAQC,iBAAQ,CAACE,IAAI;IACjE;IACAC,SAAS,OAAOC,OACdC,IAAAA,mBAAY,EAACD,KAAKE,OAAO,CAACC,MAAM,EAAE;YAChCL,MAAME,KAAKF,IAAI,IAAIE,KAAKE,OAAO,CAACC,MAAM,CAACC,MAAM,CAACN,IAAI;QACpD;AACJ;MAEA,WAAeP"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "serveHandler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return serveHandler;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _utils = require("../../utils");
|
|
12
|
+
const _webpack = require("../../webpack");
|
|
13
|
+
async function serveHandler(config, options) {
|
|
14
|
+
const server = (0, _webpack.getServer)(config);
|
|
15
|
+
// If the `configPort` is `0`, the OS will choose a random port for us, so we
|
|
16
|
+
// need to get the port from the server after it starts.
|
|
17
|
+
const { port } = await server.listen(options.port);
|
|
18
|
+
(0, _utils.info)(`The server is listening on http://localhost:${port}.`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=serve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/commands/serve/serve.ts"],"sourcesContent":["import type { ProcessedConfig } from '../../config';\nimport { info } from '../../utils';\nimport { getServer } from '../../webpack';\n\ntype ServeOptions = {\n /**\n * The port to listen on.\n */\n port: number;\n};\n\n/**\n * Starts a local, static HTTP server on the given port with the given root\n * directory.\n *\n * @param config - The config object.\n * @param options - The options object.\n */\nexport async function serveHandler(\n config: ProcessedConfig,\n options: ServeOptions,\n): Promise<void> {\n const server = getServer(config);\n\n // If the `configPort` is `0`, the OS will choose a random port for us, so we\n // need to get the port from the server after it starts.\n const { port } = await server.listen(options.port);\n\n info(`The server is listening on http://localhost:${port}.`);\n}\n"],"names":["serveHandler","config","options","server","getServer","port","listen","info"],"mappings":";;;;+BAkBsBA;;;eAAAA;;;uBAjBD;yBACK;AAgBnB,eAAeA,aACpBC,MAAuB,EACvBC,OAAqB;IAErB,MAAMC,SAASC,IAAAA,kBAAS,EAACH;IAEzB,6EAA6E;IAC7E,wDAAwD;IACxD,MAAM,EAAEI,IAAI,EAAE,GAAG,MAAMF,OAAOG,MAAM,CAACJ,QAAQG,IAAI;IAEjDE,IAAAA,WAAI,EAAC,CAAC,4CAA4C,EAAEF,KAAK,CAAC,CAAC;AAC7D"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "watch", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return watch;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _path = require("path");
|
|
12
|
+
const _webpack = require("../../webpack");
|
|
13
|
+
async function watch(config, options) {
|
|
14
|
+
const compiler = await (0, _webpack.getCompiler)(config, {
|
|
15
|
+
evaluate: config.evaluate,
|
|
16
|
+
watch: true,
|
|
17
|
+
spinner: options?.spinner
|
|
18
|
+
});
|
|
19
|
+
return new Promise((resolve, reject)=>{
|
|
20
|
+
compiler.watch({
|
|
21
|
+
ignored: [
|
|
22
|
+
'**/node_modules/**/*',
|
|
23
|
+
`**/${(0, _path.basename)(config.output.path)}/**/*`
|
|
24
|
+
]
|
|
25
|
+
}, (watchError)=>{
|
|
26
|
+
if (watchError) {
|
|
27
|
+
reject(watchError);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
resolve(compiler.watching);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=implementation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/commands/watch/implementation.ts"],"sourcesContent":["import { basename } from 'path';\nimport type { Watching } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../../config';\nimport type { WebpackOptions } from '../../webpack';\nimport { getCompiler } from '../../webpack';\n\n/**\n * Build the snap bundle and watch for changes. This uses Webpack to build the\n * bundle.\n *\n * @param config - The config object.\n * @param options - The Webpack options.\n * @returns A promise that resolves when the bundle is built for the first time.\n * The promise resolves with a Webpack watching instance that can be used to\n * close the watcher.\n */\nexport async function watch(\n config: ProcessedWebpackConfig,\n options?: WebpackOptions,\n) {\n const compiler = await getCompiler(config, {\n evaluate: config.evaluate,\n watch: true,\n spinner: options?.spinner,\n });\n\n return new Promise<Watching>((resolve, reject) => {\n compiler.watch(\n {\n ignored: [\n '**/node_modules/**/*',\n `**/${basename(config.output.path)}/**/*`,\n ],\n },\n (watchError) => {\n if (watchError) {\n reject(watchError);\n return;\n }\n\n resolve(compiler.watching);\n },\n );\n });\n}\n"],"names":["watch","config","options","compiler","getCompiler","evaluate","spinner","Promise","resolve","reject","ignored","basename","output","path","watchError","watching"],"mappings":";;;;+BAiBsBA;;;eAAAA;;;sBAjBG;yBAKG;AAYrB,eAAeA,MACpBC,MAA8B,EAC9BC,OAAwB;IAExB,MAAMC,WAAW,MAAMC,IAAAA,oBAAW,EAACH,QAAQ;QACzCI,UAAUJ,OAAOI,QAAQ;QACzBL,OAAO;QACPM,SAASJ,SAASI;IACpB;IAEA,OAAO,IAAIC,QAAkB,CAACC,SAASC;QACrCN,SAASH,KAAK,CACZ;YACEU,SAAS;gBACP;gBACA,CAAC,GAAG,EAAEC,IAAAA,cAAQ,EAACV,OAAOW,MAAM,CAACC,IAAI,EAAE,KAAK,CAAC;aAC1C;QACH,GACA,CAACC;YACC,IAAIA,YAAY;gBACdL,OAAOK;gBACP;YACF;YAEAN,QAAQL,SAASY,QAAQ;QAC3B;IAEJ;AACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _builders = /*#__PURE__*/ _interop_require_default(require("../../builders"));
|
|
12
|
+
const _watch = require("./watch");
|
|
13
|
+
_export_star(require("./implementation"), exports);
|
|
14
|
+
function _export_star(from, to) {
|
|
15
|
+
Object.keys(from).forEach(function(k) {
|
|
16
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
17
|
+
Object.defineProperty(to, k, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return from[k];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return from;
|
|
26
|
+
}
|
|
27
|
+
function _interop_require_default(obj) {
|
|
28
|
+
return obj && obj.__esModule ? obj : {
|
|
29
|
+
default: obj
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const command = {
|
|
33
|
+
command: [
|
|
34
|
+
'watch',
|
|
35
|
+
'w'
|
|
36
|
+
],
|
|
37
|
+
desc: 'Build Snap on change',
|
|
38
|
+
builder: (yarg)=>{
|
|
39
|
+
yarg.option('src', _builders.default.src).option('eval', _builders.default.eval).option('dist', _builders.default.dist).option('outfileName', _builders.default.outfileName).option('sourceMaps', _builders.default.sourceMaps).option('stripComments', _builders.default.stripComments).option('transpilationMode', _builders.default.transpilationMode).option('depsToTranspile', _builders.default.depsToTranspile).option('manifest', _builders.default.manifest).option('writeManifest', _builders.default.writeManifest).option('serve', _builders.default.serve).option('root', _builders.default.root).option('port', _builders.default.port).implies('writeManifest', 'manifest').implies('depsToTranspile', 'transpilationMode');
|
|
40
|
+
},
|
|
41
|
+
handler: async (argv)=>(0, _watch.watchHandler)(argv.context.config, {
|
|
42
|
+
port: argv.port
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
const _default = command;
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/commands/watch/index.ts"],"sourcesContent":["import type yargs from 'yargs';\n\nimport builders from '../../builders';\nimport type { YargsArgs } from '../../types/yargs';\nimport { watchHandler } from './watch';\n\nconst command = {\n command: ['watch', 'w'],\n desc: 'Build Snap on change',\n builder: (yarg: yargs.Argv) => {\n yarg\n .option('src', builders.src)\n .option('eval', builders.eval)\n .option('dist', builders.dist)\n .option('outfileName', builders.outfileName)\n .option('sourceMaps', builders.sourceMaps)\n .option('stripComments', builders.stripComments)\n .option('transpilationMode', builders.transpilationMode)\n .option('depsToTranspile', builders.depsToTranspile)\n .option('manifest', builders.manifest)\n .option('writeManifest', builders.writeManifest)\n .option('serve', builders.serve)\n .option('root', builders.root)\n .option('port', builders.port)\n .implies('writeManifest', 'manifest')\n .implies('depsToTranspile', 'transpilationMode');\n },\n handler: async (argv: YargsArgs) =>\n watchHandler(argv.context.config, {\n port: argv.port,\n }),\n};\n\nexport * from './implementation';\nexport default command;\n"],"names":["command","desc","builder","yarg","option","builders","src","eval","dist","outfileName","sourceMaps","stripComments","transpilationMode","depsToTranspile","manifest","writeManifest","serve","root","port","implies","handler","argv","watchHandler","context","config"],"mappings":";;;;+BAkCA;;;eAAA;;;iEAhCqB;uBAEQ;qBA6Bf;;;;;;;;;;;;;;;;;;;AA3Bd,MAAMA,UAAU;IACdA,SAAS;QAAC;QAAS;KAAI;IACvBC,MAAM;IACNC,SAAS,CAACC;QACRA,KACGC,MAAM,CAAC,OAAOC,iBAAQ,CAACC,GAAG,EAC1BF,MAAM,CAAC,QAAQC,iBAAQ,CAACE,IAAI,EAC5BH,MAAM,CAAC,QAAQC,iBAAQ,CAACG,IAAI,EAC5BJ,MAAM,CAAC,eAAeC,iBAAQ,CAACI,WAAW,EAC1CL,MAAM,CAAC,cAAcC,iBAAQ,CAACK,UAAU,EACxCN,MAAM,CAAC,iBAAiBC,iBAAQ,CAACM,aAAa,EAC9CP,MAAM,CAAC,qBAAqBC,iBAAQ,CAACO,iBAAiB,EACtDR,MAAM,CAAC,mBAAmBC,iBAAQ,CAACQ,eAAe,EAClDT,MAAM,CAAC,YAAYC,iBAAQ,CAACS,QAAQ,EACpCV,MAAM,CAAC,iBAAiBC,iBAAQ,CAACU,aAAa,EAC9CX,MAAM,CAAC,SAASC,iBAAQ,CAACW,KAAK,EAC9BZ,MAAM,CAAC,QAAQC,iBAAQ,CAACY,IAAI,EAC5Bb,MAAM,CAAC,QAAQC,iBAAQ,CAACa,IAAI,EAC5BC,OAAO,CAAC,iBAAiB,YACzBA,OAAO,CAAC,mBAAmB;IAChC;IACAC,SAAS,OAAOC,OACdC,IAAAA,mBAAY,EAACD,KAAKE,OAAO,CAACC,MAAM,EAAE;YAChCN,MAAMG,KAAKH,IAAI;QACjB;AACJ;MAGA,WAAelB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "watchHandler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return watchHandler;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _snapsutils = require("@metamask/snaps-utils");
|
|
12
|
+
const _errors = require("../../errors");
|
|
13
|
+
const _utils = require("../../utils");
|
|
14
|
+
const _webpack = require("../../webpack");
|
|
15
|
+
const _implementation = require("./implementation");
|
|
16
|
+
const steps = [
|
|
17
|
+
{
|
|
18
|
+
name: 'Checking the input file.',
|
|
19
|
+
task: async ({ config })=>{
|
|
20
|
+
const { input } = config;
|
|
21
|
+
if (!await (0, _snapsutils.isFile)(input)) {
|
|
22
|
+
throw new _errors.CommandError(`Input file not found: "${input}". Make sure that the "input" field in your snap config is correct.`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'Starting the development server.',
|
|
28
|
+
condition: ({ config })=>config.server.enabled,
|
|
29
|
+
task: async ({ config, options, spinner })=>{
|
|
30
|
+
const server = (0, _webpack.getServer)(config);
|
|
31
|
+
const { port } = await server.listen(options.port ?? config.server.port);
|
|
32
|
+
(0, _utils.info)(`The server is listening on http://localhost:${port}.`, spinner);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'Building the snap bundle.',
|
|
37
|
+
task: async ({ config, spinner })=>{
|
|
38
|
+
await (0, _implementation.watch)(config, {
|
|
39
|
+
spinner
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
async function watchHandler(config, options) {
|
|
45
|
+
await (0, _utils.executeSteps)(steps, {
|
|
46
|
+
config,
|
|
47
|
+
options
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=watch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/commands/watch/watch.ts"],"sourcesContent":["import { isFile } from '@metamask/snaps-utils';\n\nimport type { ProcessedConfig, ProcessedWebpackConfig } from '../../config';\nimport { CommandError } from '../../errors';\nimport type { Steps } from '../../utils';\nimport { executeSteps, info } from '../../utils';\nimport { getServer } from '../../webpack';\nimport { watch } from './implementation';\n\ntype WatchOptions = {\n /**\n * The port to listen on.\n */\n port?: number;\n};\n\ntype WatchContext = {\n config: ProcessedWebpackConfig;\n options: WatchOptions;\n};\n\nconst steps: Steps<WatchContext> = [\n {\n name: 'Checking the input file.',\n task: async ({ config }) => {\n const { input } = config;\n\n if (!(await isFile(input))) {\n throw new CommandError(\n `Input file not found: \"${input}\". Make sure that the \"input\" field in your snap config is correct.`,\n );\n }\n },\n },\n {\n name: 'Starting the development server.',\n condition: ({ config }) => config.server.enabled,\n task: async ({ config, options, spinner }) => {\n const server = getServer(config);\n const { port } = await server.listen(options.port ?? config.server.port);\n\n info(`The server is listening on http://localhost:${port}.`, spinner);\n },\n },\n {\n name: 'Building the snap bundle.',\n task: async ({ config, spinner }) => {\n await watch(config, { spinner });\n },\n },\n];\n\n/**\n * Watch a directory and its subdirectories for changes, and build when files\n * are added or changed.\n *\n * Ignores 'node_modules' and dotfiles.\n * Creates destination directory if it doesn't exist.\n *\n * @param config - The config object.\n * @param options - The options object.\n */\nexport async function watchHandler(\n config: ProcessedConfig,\n options: WatchOptions,\n): Promise<void> {\n await executeSteps(steps, { config, options });\n}\n"],"names":["watchHandler","steps","name","task","config","input","isFile","CommandError","condition","server","enabled","options","spinner","getServer","port","listen","info","watch","executeSteps"],"mappings":";;;;+BA8DsBA;;;eAAAA;;;4BA9DC;wBAGM;uBAEM;yBACT;gCACJ;AActB,MAAMC,QAA6B;IACjC;QACEC,MAAM;QACNC,MAAM,OAAO,EAAEC,MAAM,EAAE;YACrB,MAAM,EAAEC,KAAK,EAAE,GAAGD;YAElB,IAAI,CAAE,MAAME,IAAAA,kBAAM,EAACD,QAAS;gBAC1B,MAAM,IAAIE,oBAAY,CACpB,CAAC,uBAAuB,EAAEF,MAAM,mEAAmE,CAAC;YAExG;QACF;IACF;IACA;QACEH,MAAM;QACNM,WAAW,CAAC,EAAEJ,MAAM,EAAE,GAAKA,OAAOK,MAAM,CAACC,OAAO;QAChDP,MAAM,OAAO,EAAEC,MAAM,EAAEO,OAAO,EAAEC,OAAO,EAAE;YACvC,MAAMH,SAASI,IAAAA,kBAAS,EAACT;YACzB,MAAM,EAAEU,IAAI,EAAE,GAAG,MAAML,OAAOM,MAAM,CAACJ,QAAQG,IAAI,IAAIV,OAAOK,MAAM,CAACK,IAAI;YAEvEE,IAAAA,WAAI,EAAC,CAAC,4CAA4C,EAAEF,KAAK,CAAC,CAAC,EAAEF;QAC/D;IACF;IACA;QACEV,MAAM;QACNC,MAAM,OAAO,EAAEC,MAAM,EAAEQ,OAAO,EAAE;YAC9B,MAAMK,IAAAA,qBAAK,EAACb,QAAQ;gBAAEQ;YAAQ;QAChC;IACF;CACD;AAYM,eAAeZ,aACpBI,MAAuB,EACvBO,OAAqB;IAErB,MAAMO,IAAAA,mBAAY,EAACjB,OAAO;QAAEG;QAAQO;IAAQ;AAC9C"}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
SnapsBrowserifyConfigStruct: function() {
|
|
13
|
+
return SnapsBrowserifyConfigStruct;
|
|
14
|
+
},
|
|
15
|
+
SnapsWebpackConfigStruct: function() {
|
|
16
|
+
return SnapsWebpackConfigStruct;
|
|
17
|
+
},
|
|
18
|
+
SnapsConfigStruct: function() {
|
|
19
|
+
return SnapsConfigStruct;
|
|
20
|
+
},
|
|
21
|
+
LegacyOptionsStruct: function() {
|
|
22
|
+
return LegacyOptionsStruct;
|
|
23
|
+
},
|
|
24
|
+
getConfig: function() {
|
|
25
|
+
return getConfig;
|
|
26
|
+
},
|
|
27
|
+
loadConfig: function() {
|
|
28
|
+
return loadConfig;
|
|
29
|
+
},
|
|
30
|
+
resolveConfig: function() {
|
|
31
|
+
return resolveConfig;
|
|
32
|
+
},
|
|
33
|
+
getConfigByArgv: function() {
|
|
34
|
+
return getConfigByArgv;
|
|
35
|
+
},
|
|
36
|
+
mergeLegacyOptions: function() {
|
|
37
|
+
return mergeLegacyOptions;
|
|
38
|
+
},
|
|
39
|
+
getWebpackConfig: function() {
|
|
40
|
+
return getWebpackConfig;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const _snapsutils = require("@metamask/snaps-utils");
|
|
44
|
+
const _utils = require("@metamask/utils");
|
|
45
|
+
const _core = require("@swc/core");
|
|
46
|
+
const _chalk = require("chalk");
|
|
47
|
+
const _promises = require("fs/promises");
|
|
48
|
+
const _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
49
|
+
const _path = require("path");
|
|
50
|
+
const _superstruct = require("superstruct");
|
|
51
|
+
const _builders = require("./builders");
|
|
52
|
+
const _errors = require("./errors");
|
|
53
|
+
const _utils1 = require("./utils");
|
|
54
|
+
function _interop_require_default(obj) {
|
|
55
|
+
return obj && obj.__esModule ? obj : {
|
|
56
|
+
default: obj
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const CONFIG_FILES = [
|
|
60
|
+
_utils1.CONFIG_FILE,
|
|
61
|
+
_utils1.TS_CONFIG_FILE
|
|
62
|
+
];
|
|
63
|
+
// This struct is essentially the same as the `func` struct, but it's defined
|
|
64
|
+
// separately so that we include the function type in the inferred TypeScript
|
|
65
|
+
// type definitions.
|
|
66
|
+
const SnapsBrowserifyBundlerCustomizerFunctionStruct = (0, _superstruct.define)('function', (0, _superstruct.func)().validator);
|
|
67
|
+
const SnapsBrowserifyConfigStruct = (0, _superstruct.object)({
|
|
68
|
+
bundler: (0, _superstruct.defaulted)((0, _snapsutils.literal)('browserify'), 'browserify'),
|
|
69
|
+
cliOptions: (0, _superstruct.defaulted)((0, _superstruct.object)({
|
|
70
|
+
bundle: (0, _superstruct.optional)((0, _snapsutils.file)()),
|
|
71
|
+
dist: (0, _superstruct.defaulted)((0, _snapsutils.file)(), 'dist'),
|
|
72
|
+
eval: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true),
|
|
73
|
+
manifest: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true),
|
|
74
|
+
port: (0, _superstruct.defaulted)((0, _superstruct.number)(), 8081),
|
|
75
|
+
outfileName: (0, _superstruct.defaulted)((0, _superstruct.string)(), 'bundle.js'),
|
|
76
|
+
root: (0, _superstruct.defaulted)((0, _snapsutils.file)(), process.cwd()),
|
|
77
|
+
sourceMaps: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
78
|
+
src: (0, _superstruct.defaulted)((0, _snapsutils.file)(), 'src/index.js'),
|
|
79
|
+
stripComments: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true),
|
|
80
|
+
suppressWarnings: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
81
|
+
transpilationMode: (0, _superstruct.defaulted)((0, _snapsutils.union)([
|
|
82
|
+
(0, _snapsutils.literal)('localAndDeps'),
|
|
83
|
+
(0, _snapsutils.literal)('localOnly'),
|
|
84
|
+
(0, _snapsutils.literal)('none')
|
|
85
|
+
]), 'localOnly'),
|
|
86
|
+
depsToTranspile: (0, _superstruct.defaulted)((0, _superstruct.array)((0, _superstruct.string)()), []),
|
|
87
|
+
verboseErrors: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true),
|
|
88
|
+
writeManifest: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true),
|
|
89
|
+
serve: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true)
|
|
90
|
+
}), {}),
|
|
91
|
+
bundlerCustomizer: (0, _superstruct.optional)(SnapsBrowserifyBundlerCustomizerFunctionStruct)
|
|
92
|
+
});
|
|
93
|
+
// This struct is essentially the same as the `func` struct, but it's defined
|
|
94
|
+
// separately so that we include the function type in the inferred TypeScript
|
|
95
|
+
// type definitions.
|
|
96
|
+
const SnapsWebpackCustomizeWebpackConfigFunctionStruct = (0, _superstruct.define)('function', (0, _superstruct.func)().validator);
|
|
97
|
+
const SnapsWebpackConfigStruct = (0, _superstruct.object)({
|
|
98
|
+
bundler: (0, _snapsutils.literal)('webpack'),
|
|
99
|
+
input: (0, _superstruct.defaulted)((0, _snapsutils.file)(), (0, _path.resolve)(process.cwd(), 'src/index.js')),
|
|
100
|
+
sourceMap: (0, _superstruct.defaulted)((0, _snapsutils.union)([
|
|
101
|
+
(0, _superstruct.boolean)(),
|
|
102
|
+
(0, _snapsutils.literal)('inline')
|
|
103
|
+
]), true),
|
|
104
|
+
evaluate: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true),
|
|
105
|
+
output: (0, _superstruct.defaulted)((0, _superstruct.object)({
|
|
106
|
+
path: (0, _superstruct.defaulted)((0, _snapsutils.file)(), (0, _path.resolve)(process.cwd(), 'dist')),
|
|
107
|
+
filename: (0, _superstruct.defaulted)((0, _superstruct.string)(), 'bundle.js'),
|
|
108
|
+
clean: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
109
|
+
minimize: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true)
|
|
110
|
+
}), {}),
|
|
111
|
+
manifest: (0, _superstruct.defaulted)((0, _superstruct.object)({
|
|
112
|
+
path: (0, _superstruct.defaulted)((0, _snapsutils.file)(), (0, _path.resolve)(process.cwd(), 'snap.manifest.json')),
|
|
113
|
+
update: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true)
|
|
114
|
+
}), {}),
|
|
115
|
+
server: (0, _superstruct.defaulted)((0, _superstruct.object)({
|
|
116
|
+
enabled: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true),
|
|
117
|
+
root: (0, _superstruct.defaulted)((0, _snapsutils.file)(), process.cwd()),
|
|
118
|
+
port: (0, _superstruct.defaulted)((0, _superstruct.number)(), 8081)
|
|
119
|
+
}), {}),
|
|
120
|
+
environment: (0, _superstruct.defaulted)((0, _superstruct.record)((0, _superstruct.string)(), (0, _superstruct.unknown)()), {
|
|
121
|
+
NODE_DEBUG: false,
|
|
122
|
+
NODE_ENV: 'production',
|
|
123
|
+
DEBUG: false
|
|
124
|
+
}),
|
|
125
|
+
stats: (0, _superstruct.defaulted)((0, _superstruct.object)({
|
|
126
|
+
verbose: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
127
|
+
builtIns: (0, _superstruct.defaulted)((0, _snapsutils.union)([
|
|
128
|
+
(0, _superstruct.object)({
|
|
129
|
+
ignore: (0, _superstruct.defaulted)((0, _superstruct.array)((0, _superstruct.string)()), [])
|
|
130
|
+
}),
|
|
131
|
+
(0, _snapsutils.literal)(false)
|
|
132
|
+
]), {}),
|
|
133
|
+
buffer: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true)
|
|
134
|
+
}), {}),
|
|
135
|
+
polyfills: (0, _superstruct.defaulted)((0, _snapsutils.union)([
|
|
136
|
+
(0, _superstruct.boolean)(),
|
|
137
|
+
(0, _superstruct.object)({
|
|
138
|
+
assert: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
139
|
+
buffer: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
140
|
+
console: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
141
|
+
constants: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
142
|
+
crypto: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
143
|
+
domain: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
144
|
+
events: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
145
|
+
http: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
146
|
+
https: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
147
|
+
os: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
148
|
+
path: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
149
|
+
punycode: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
150
|
+
process: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
151
|
+
querystring: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
152
|
+
stream: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
153
|
+
/* eslint-disable @typescript-eslint/naming-convention */ _stream_duplex: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
154
|
+
_stream_passthrough: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
155
|
+
_stream_readable: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
156
|
+
_stream_transform: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
157
|
+
_stream_writable: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
158
|
+
string_decoder: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
159
|
+
/* eslint-enable @typescript-eslint/naming-convention */ sys: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
160
|
+
timers: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
161
|
+
tty: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
162
|
+
url: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
163
|
+
util: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
164
|
+
vm: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
|
|
165
|
+
zlib: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false)
|
|
166
|
+
})
|
|
167
|
+
]), false),
|
|
168
|
+
customizeWebpackConfig: (0, _superstruct.optional)(SnapsWebpackCustomizeWebpackConfigFunctionStruct),
|
|
169
|
+
experimental: (0, _superstruct.defaulted)((0, _superstruct.object)({
|
|
170
|
+
wasm: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false)
|
|
171
|
+
}), {})
|
|
172
|
+
});
|
|
173
|
+
const SnapsConfigStruct = (0, _superstruct.type)({
|
|
174
|
+
bundler: (0, _superstruct.defaulted)((0, _snapsutils.union)([
|
|
175
|
+
(0, _snapsutils.literal)('browserify'),
|
|
176
|
+
(0, _snapsutils.literal)('webpack')
|
|
177
|
+
]), 'browserify')
|
|
178
|
+
});
|
|
179
|
+
const LegacyOptionsStruct = (0, _snapsutils.union)([
|
|
180
|
+
(0, _snapsutils.named)('object with `transpilationMode` set to `localAndDeps` and `depsToTranspile` set to an array of strings', (0, _superstruct.type)({
|
|
181
|
+
depsToTranspile: (0, _superstruct.array)((0, _superstruct.string)()),
|
|
182
|
+
transpilationMode: (0, _snapsutils.literal)(_builders.TranspilationModes.LocalAndDeps),
|
|
183
|
+
writeManifest: (0, _superstruct.boolean)(),
|
|
184
|
+
bundlerCustomizer: (0, _superstruct.optional)(SnapsBrowserifyBundlerCustomizerFunctionStruct)
|
|
185
|
+
})),
|
|
186
|
+
(0, _snapsutils.named)('object without `depsToTranspile`', (0, _superstruct.type)({
|
|
187
|
+
depsToTranspile: (0, _snapsutils.named)('empty array', (0, _superstruct.empty)((0, _superstruct.array)())),
|
|
188
|
+
transpilationMode: (0, _snapsutils.union)([
|
|
189
|
+
(0, _snapsutils.literal)(_builders.TranspilationModes.LocalOnly),
|
|
190
|
+
(0, _snapsutils.literal)(_builders.TranspilationModes.None)
|
|
191
|
+
]),
|
|
192
|
+
writeManifest: (0, _superstruct.boolean)(),
|
|
193
|
+
bundlerCustomizer: (0, _superstruct.optional)(SnapsBrowserifyBundlerCustomizerFunctionStruct)
|
|
194
|
+
}))
|
|
195
|
+
]);
|
|
196
|
+
function getConfig(config, argv) {
|
|
197
|
+
const prefix = 'The snap config file is invalid';
|
|
198
|
+
const suffix = (0, _chalk.dim)(// TODO: Link to `docs.metamask.io` once the docs are published.
|
|
199
|
+
'Refer to the documentation for more information: https://github.com/MetaMask/snaps/tree/main/packages/snaps-cli/');
|
|
200
|
+
const { bundler } = (0, _snapsutils.createFromStruct)(config, SnapsConfigStruct, prefix, suffix);
|
|
201
|
+
if (bundler === 'browserify') {
|
|
202
|
+
const legacyConfig = (0, _snapsutils.createFromStruct)(config, SnapsBrowserifyConfigStruct, prefix, suffix);
|
|
203
|
+
return getWebpackConfig(mergeLegacyOptions(argv, legacyConfig));
|
|
204
|
+
}
|
|
205
|
+
return (0, _snapsutils.createFromStruct)(config, SnapsWebpackConfigStruct, prefix, suffix);
|
|
206
|
+
}
|
|
207
|
+
async function loadConfig(path, argv) {
|
|
208
|
+
try {
|
|
209
|
+
const contents = await (0, _promises.readFile)(path, 'utf8');
|
|
210
|
+
const source = await (0, _core.transform)(contents, {
|
|
211
|
+
swcrc: false,
|
|
212
|
+
jsc: {
|
|
213
|
+
parser: {
|
|
214
|
+
syntax: 'typescript'
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
module: {
|
|
218
|
+
type: 'commonjs'
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
const config = new _module.default(path);
|
|
222
|
+
// @ts-expect-error - This function is not typed.
|
|
223
|
+
config.paths = _module.default._nodeModulePaths((0, _path.dirname)(path));
|
|
224
|
+
// @ts-expect-error - This function is not typed.
|
|
225
|
+
config._compile(source.code, path);
|
|
226
|
+
if (!(0, _utils.hasProperty)(config.exports, 'default')) {
|
|
227
|
+
return getConfig(config.exports, argv);
|
|
228
|
+
}
|
|
229
|
+
return getConfig(config.exports.default, argv);
|
|
230
|
+
} catch (error) {
|
|
231
|
+
if (error instanceof _snapsutils.SnapsStructError) {
|
|
232
|
+
throw new _errors.ConfigError(error.message);
|
|
233
|
+
}
|
|
234
|
+
throw new _errors.ConfigError(`Unable to load snap config file at "${path}".\n\n${(0, _snapsutils.indent)(error.message)}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async function resolveConfig(path, argv) {
|
|
238
|
+
for (const configFile of CONFIG_FILES){
|
|
239
|
+
const filePath = (0, _path.resolve)(path, configFile);
|
|
240
|
+
if (await (0, _snapsutils.isFile)(filePath)) {
|
|
241
|
+
return await loadConfig(filePath, argv);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
throw new _errors.ConfigError(`Could not find a "snap.config.js" or "snap.config.ts" file in the current or specified directory ("${path}").`);
|
|
245
|
+
}
|
|
246
|
+
async function getConfigByArgv(argv, cwd = process.cwd()) {
|
|
247
|
+
if (argv.config) {
|
|
248
|
+
if (!await (0, _snapsutils.isFile)(argv.config)) {
|
|
249
|
+
throw new _errors.ConfigError(`Could not find a config file at "${argv.config}". Make sure that the path is correct.`);
|
|
250
|
+
}
|
|
251
|
+
return await loadConfig(argv.config, argv);
|
|
252
|
+
}
|
|
253
|
+
return await resolveConfig(cwd, argv);
|
|
254
|
+
}
|
|
255
|
+
function mergeLegacyOptions(argv, config) {
|
|
256
|
+
const cliOptions = Object.keys(config.cliOptions).reduce((accumulator, key)=>{
|
|
257
|
+
if (argv[key] !== undefined) {
|
|
258
|
+
return {
|
|
259
|
+
...accumulator,
|
|
260
|
+
[key]: argv[key]
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
return accumulator;
|
|
264
|
+
}, config.cliOptions);
|
|
265
|
+
return {
|
|
266
|
+
...config,
|
|
267
|
+
cliOptions
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
function getWebpackConfig(legacyConfig) {
|
|
271
|
+
const defaultConfig = (0, _superstruct.create)({
|
|
272
|
+
bundler: 'webpack'
|
|
273
|
+
}, SnapsWebpackConfigStruct);
|
|
274
|
+
// The legacy config has two options for specifying the output path and
|
|
275
|
+
// filename: `bundle`, and `dist` + `outfileName`. If `bundle` is specified,
|
|
276
|
+
// we use that as the output path and filename. Otherwise, we use `dist` and
|
|
277
|
+
// `outfileName`.
|
|
278
|
+
const path = legacyConfig.cliOptions.bundle ? (0, _path.dirname)(legacyConfig.cliOptions.bundle) : legacyConfig.cliOptions.dist;
|
|
279
|
+
const filename = legacyConfig.cliOptions.bundle ? (0, _path.basename)(legacyConfig.cliOptions.bundle) : legacyConfig.cliOptions.outfileName;
|
|
280
|
+
return {
|
|
281
|
+
...defaultConfig,
|
|
282
|
+
input: legacyConfig.cliOptions.src,
|
|
283
|
+
evaluate: legacyConfig.cliOptions.eval,
|
|
284
|
+
sourceMap: legacyConfig.cliOptions.sourceMaps,
|
|
285
|
+
output: {
|
|
286
|
+
path,
|
|
287
|
+
filename,
|
|
288
|
+
// The legacy config has an option to remove comments from the bundle, but
|
|
289
|
+
// the terser plugin does this by default, so we only enable the terser if
|
|
290
|
+
// the legacy config has `stripComments` set to `true`. This is not a
|
|
291
|
+
// perfect solution, but it's the best we can do without breaking the
|
|
292
|
+
// legacy config.
|
|
293
|
+
minimize: legacyConfig.cliOptions.stripComments,
|
|
294
|
+
// The legacy config does not have a `clean` option, so we default to
|
|
295
|
+
// `false` here.
|
|
296
|
+
clean: false
|
|
297
|
+
},
|
|
298
|
+
manifest: {
|
|
299
|
+
// The legacy config does not have a `manifest` option, so we default to
|
|
300
|
+
// `process.cwd()/snap.manifest.json`.
|
|
301
|
+
path: (0, _path.resolve)(process.cwd(), 'snap.manifest.json'),
|
|
302
|
+
update: legacyConfig.cliOptions.writeManifest
|
|
303
|
+
},
|
|
304
|
+
server: {
|
|
305
|
+
enabled: legacyConfig.cliOptions.serve,
|
|
306
|
+
port: legacyConfig.cliOptions.port,
|
|
307
|
+
root: legacyConfig.cliOptions.root
|
|
308
|
+
},
|
|
309
|
+
stats: {
|
|
310
|
+
verbose: false,
|
|
311
|
+
// These plugins are designed to be used with the modern config format, so
|
|
312
|
+
// we disable them for the legacy config format.
|
|
313
|
+
builtIns: false,
|
|
314
|
+
buffer: false
|
|
315
|
+
},
|
|
316
|
+
legacy: (0, _snapsutils.createFromStruct)({
|
|
317
|
+
...legacyConfig.cliOptions,
|
|
318
|
+
bundlerCustomizer: legacyConfig.bundlerCustomizer
|
|
319
|
+
}, LegacyOptionsStruct, 'Invalid Browserify CLI options')
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
//# sourceMappingURL=config.js.map
|