@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,208 @@
|
|
|
1
|
+
import { dim } from 'chalk';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import { builtinModules } from 'module';
|
|
4
|
+
import { dirname, resolve } from 'path';
|
|
5
|
+
export const BROWSERSLIST_FILE = resolve(dirname(// eslint-disable-next-line n/no-extraneous-require
|
|
6
|
+
require.resolve('@metamask/snaps-cli/package.json')), '.browserslistrc');
|
|
7
|
+
export const WEBPACK_FALLBACKS = {
|
|
8
|
+
assert: require.resolve('assert/'),
|
|
9
|
+
buffer: require.resolve('buffer/'),
|
|
10
|
+
console: require.resolve('console-browserify'),
|
|
11
|
+
constants: require.resolve('constants-browserify'),
|
|
12
|
+
crypto: require.resolve('crypto-browserify'),
|
|
13
|
+
domain: require.resolve('domain-browser'),
|
|
14
|
+
events: require.resolve('events/'),
|
|
15
|
+
http: require.resolve('stream-http'),
|
|
16
|
+
https: require.resolve('https-browserify'),
|
|
17
|
+
os: require.resolve('os-browserify/browser'),
|
|
18
|
+
path: require.resolve('path-browserify'),
|
|
19
|
+
punycode: require.resolve('punycode/'),
|
|
20
|
+
process: require.resolve('process/browser'),
|
|
21
|
+
querystring: require.resolve('querystring-es3'),
|
|
22
|
+
stream: require.resolve('stream-browserify'),
|
|
23
|
+
/* eslint-disable @typescript-eslint/naming-convention */ _stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),
|
|
24
|
+
_stream_passthrough: require.resolve('readable-stream/lib/_stream_passthrough'),
|
|
25
|
+
_stream_readable: require.resolve('readable-stream/lib/_stream_readable'),
|
|
26
|
+
_stream_transform: require.resolve('readable-stream/lib/_stream_transform'),
|
|
27
|
+
_stream_writable: require.resolve('readable-stream/lib/_stream_writable'),
|
|
28
|
+
string_decoder: require.resolve('string_decoder/'),
|
|
29
|
+
/* eslint-enable @typescript-eslint/naming-convention */ sys: require.resolve('util/'),
|
|
30
|
+
timers: require.resolve('timers-browserify'),
|
|
31
|
+
tty: require.resolve('tty-browserify'),
|
|
32
|
+
url: require.resolve('url/'),
|
|
33
|
+
util: require.resolve('util/'),
|
|
34
|
+
vm: require.resolve('vm-browserify'),
|
|
35
|
+
zlib: require.resolve('browserify-zlib')
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Get the default loader for JavaScript and TypeScript files, based on the
|
|
39
|
+
* config object.
|
|
40
|
+
*
|
|
41
|
+
* - If the `legacy` option is set, we use the custom `browserify` loader. This
|
|
42
|
+
* uses the legacy Browserify config to transpile the code.
|
|
43
|
+
* - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the
|
|
44
|
+
* `SWC` compiler, which is a much faster alternative to Babel and TypeScript's
|
|
45
|
+
* own compiler.
|
|
46
|
+
*
|
|
47
|
+
* @param config - The processed snap Webpack config.
|
|
48
|
+
* @param config.legacy - The legacy config object, if any.
|
|
49
|
+
* @param config.sourceMap - Whether to generate source maps.
|
|
50
|
+
* @see https://swc.rs/docs/usage/swc-loader
|
|
51
|
+
* @returns The default loader.
|
|
52
|
+
*/ export async function getDefaultLoader({ legacy, sourceMap }) {
|
|
53
|
+
if (legacy) {
|
|
54
|
+
return {
|
|
55
|
+
/**
|
|
56
|
+
* If the snap uses the legacy config, we use the custom `browserify`
|
|
57
|
+
* loader. This uses the legacy Browserify config to transpile the code.
|
|
58
|
+
* This is necessary for backwards compatibility with the
|
|
59
|
+
* `bundlerCustomizer` function.
|
|
60
|
+
*/ loader: resolve(__dirname, 'loaders', 'browserify'),
|
|
61
|
+
/**
|
|
62
|
+
* The options for the `browserify` loader. These can be overridden in the
|
|
63
|
+
* snap config.
|
|
64
|
+
*/ options: legacy
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const targets = await getBrowserslistTargets();
|
|
68
|
+
return {
|
|
69
|
+
/**
|
|
70
|
+
* We use the `swc-loader` to transpile TypeScript and JavaScript files.
|
|
71
|
+
* This is a Webpack loader that uses the `SWC` compiler, which is a much
|
|
72
|
+
* faster alternative to Babel and TypeScript's own compiler.
|
|
73
|
+
*/ loader: 'swc-loader',
|
|
74
|
+
/**
|
|
75
|
+
* The options for the `swc-loader`. These can be overridden in the
|
|
76
|
+
* `.swcrc` file.
|
|
77
|
+
*
|
|
78
|
+
* @see https://swc.rs/docs/configuration/swcrc
|
|
79
|
+
*/ options: {
|
|
80
|
+
sync: false,
|
|
81
|
+
/**
|
|
82
|
+
* This tells SWC to generate source maps. We set it to the
|
|
83
|
+
* `sourceMap` value from the config object.
|
|
84
|
+
*
|
|
85
|
+
* This must be enabled if source maps are enabled in the config.
|
|
86
|
+
*/ sourceMaps: Boolean(getDevTool(sourceMap)),
|
|
87
|
+
jsc: {
|
|
88
|
+
parser: {
|
|
89
|
+
/**
|
|
90
|
+
* This tells the parser to parse TypeScript files. If you
|
|
91
|
+
* don't need to support TypeScript, you can set this to
|
|
92
|
+
* `ecmascript` instead, but there's no harm in leaving it
|
|
93
|
+
* as `typescript`.
|
|
94
|
+
*
|
|
95
|
+
* @see https://swc.rs/docs/configuration/compilation#jscparser
|
|
96
|
+
*/ syntax: 'typescript'
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* The module configuration. This tells SWC how to output the
|
|
101
|
+
* transpiled code.
|
|
102
|
+
*
|
|
103
|
+
* @see https://swc.rs/docs/configuration/modules
|
|
104
|
+
*/ module: {
|
|
105
|
+
/**
|
|
106
|
+
* This tells SWC to output CommonJS modules. MetaMask Snaps
|
|
107
|
+
* doesn't support ES modules yet, so this is necessary.
|
|
108
|
+
*
|
|
109
|
+
* @see https://swc.rs/docs/configuration/modules#commonjs
|
|
110
|
+
*/ type: 'commonjs'
|
|
111
|
+
},
|
|
112
|
+
env: {
|
|
113
|
+
targets: targets.join(', ')
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get the Webpack devtool configuration based on the given snap config.
|
|
120
|
+
*
|
|
121
|
+
* - If `sourceMap` is `inline`, return `inline-source-map`.
|
|
122
|
+
* - If `sourceMap` is `true`, return `source-map`.
|
|
123
|
+
* - Otherwise, return `false`.
|
|
124
|
+
*
|
|
125
|
+
* @param sourceMap - The `sourceMap` value from the snap config.
|
|
126
|
+
* @returns The Webpack devtool configuration.
|
|
127
|
+
*/ export function getDevTool(sourceMap) {
|
|
128
|
+
if (sourceMap === 'inline') {
|
|
129
|
+
return 'inline-source-map';
|
|
130
|
+
}
|
|
131
|
+
if (sourceMap === true) {
|
|
132
|
+
return 'source-map';
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get a function that can be used as handler function for Webpack's
|
|
138
|
+
* `ProgressPlugin`.
|
|
139
|
+
*
|
|
140
|
+
* @param spinner - The spinner to update.
|
|
141
|
+
* @param spinnerText - The initial spinner text. This will be prepended to the
|
|
142
|
+
* percentage.
|
|
143
|
+
* @returns A function that can be used as handler function for Webpack's
|
|
144
|
+
* `ProgressPlugin`.
|
|
145
|
+
*/ // Note: This is extracted for testing purposes.
|
|
146
|
+
export function getProgressHandler(spinner, spinnerText) {
|
|
147
|
+
return (percentage)=>{
|
|
148
|
+
if (spinner && spinnerText) {
|
|
149
|
+
spinner.text = `${spinnerText} ${dim(`(${Math.round(percentage * 100)}%)`)}`;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Get the targets from the `.browserslistrc` file.
|
|
155
|
+
*
|
|
156
|
+
* @returns The browser targets as an array of strings.
|
|
157
|
+
*/ export async function getBrowserslistTargets() {
|
|
158
|
+
const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');
|
|
159
|
+
return contents.split('\n').map((line)=>line.trim()).filter((line)=>line && !line.startsWith('#'));
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get a singular or plural string based on the given count. This is useful for
|
|
163
|
+
* generating messages like "1 error" or "2 errors". By default, the plural
|
|
164
|
+
* string is the singular string with an "s" appended to it.
|
|
165
|
+
*
|
|
166
|
+
* This assumes that the text is in English, and likely won't work for some
|
|
167
|
+
* other languages.
|
|
168
|
+
*
|
|
169
|
+
* @param count - The count.
|
|
170
|
+
* @param singular - The singular string.
|
|
171
|
+
* @param plural - The plural string.
|
|
172
|
+
* @returns The singular or plural string.
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* pluralize(1, 'error'); // => 'error'
|
|
176
|
+
* pluralize(2, 'error'); // => 'errors'
|
|
177
|
+
* pluralize(1, 'error', 'problem'); // => 'error'
|
|
178
|
+
* pluralize(2, 'error', 'problems'); // => 'problems'
|
|
179
|
+
* ```
|
|
180
|
+
*/ export function pluralize(count, singular, plural = `${singular}s`) {
|
|
181
|
+
return count === 1 ? singular : plural;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get an object that can be used as fallback config for Webpack's
|
|
185
|
+
* `fallback` config.
|
|
186
|
+
*
|
|
187
|
+
* @param polyfills - The polyfill object from the snap config.
|
|
188
|
+
* @returns The webpack fallback config.
|
|
189
|
+
*/ export function getFallbacks(polyfills) {
|
|
190
|
+
if (polyfills === true) {
|
|
191
|
+
return Object.fromEntries(builtinModules.map((name)=>[
|
|
192
|
+
name,
|
|
193
|
+
WEBPACK_FALLBACKS[name] ?? false
|
|
194
|
+
]));
|
|
195
|
+
}
|
|
196
|
+
if (polyfills === false) {
|
|
197
|
+
return Object.fromEntries(builtinModules.map((name)=>[
|
|
198
|
+
name,
|
|
199
|
+
false
|
|
200
|
+
]));
|
|
201
|
+
}
|
|
202
|
+
return Object.fromEntries(builtinModules.map((name)=>[
|
|
203
|
+
name,
|
|
204
|
+
polyfills[name] ? WEBPACK_FALLBACKS[name] : false
|
|
205
|
+
]));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/webpack/utils.ts"],"sourcesContent":["import { dim } from 'chalk';\nimport { promises as fs } from 'fs';\nimport { builtinModules } from 'module';\nimport type { Ora } from 'ora';\nimport { dirname, resolve } from 'path';\nimport type { Configuration } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\n\nexport const BROWSERSLIST_FILE = resolve(\n dirname(\n // eslint-disable-next-line n/no-extraneous-require\n require.resolve('@metamask/snaps-cli/package.json'),\n ),\n '.browserslistrc',\n);\n\nexport const WEBPACK_FALLBACKS = {\n assert: require.resolve('assert/'),\n buffer: require.resolve('buffer/'),\n console: require.resolve('console-browserify'),\n constants: require.resolve('constants-browserify'),\n crypto: require.resolve('crypto-browserify'),\n domain: require.resolve('domain-browser'),\n events: require.resolve('events/'),\n http: require.resolve('stream-http'),\n https: require.resolve('https-browserify'),\n os: require.resolve('os-browserify/browser'),\n path: require.resolve('path-browserify'),\n punycode: require.resolve('punycode/'),\n process: require.resolve('process/browser'),\n querystring: require.resolve('querystring-es3'),\n stream: require.resolve('stream-browserify'),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),\n _stream_passthrough: require.resolve(\n 'readable-stream/lib/_stream_passthrough',\n ),\n _stream_readable: require.resolve('readable-stream/lib/_stream_readable'),\n _stream_transform: require.resolve('readable-stream/lib/_stream_transform'),\n _stream_writable: require.resolve('readable-stream/lib/_stream_writable'),\n string_decoder: require.resolve('string_decoder/'),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: require.resolve('util/'),\n timers: require.resolve('timers-browserify'),\n tty: require.resolve('tty-browserify'),\n url: require.resolve('url/'),\n util: require.resolve('util/'),\n vm: require.resolve('vm-browserify'),\n zlib: require.resolve('browserify-zlib'),\n};\n\n/**\n * Get the default loader for JavaScript and TypeScript files, based on the\n * config object.\n *\n * - If the `legacy` option is set, we use the custom `browserify` loader. This\n * uses the legacy Browserify config to transpile the code.\n * - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the\n * `SWC` compiler, which is a much faster alternative to Babel and TypeScript's\n * own compiler.\n *\n * @param config - The processed snap Webpack config.\n * @param config.legacy - The legacy config object, if any.\n * @param config.sourceMap - Whether to generate source maps.\n * @see https://swc.rs/docs/usage/swc-loader\n * @returns The default loader.\n */\nexport async function getDefaultLoader({\n legacy,\n sourceMap,\n}: ProcessedWebpackConfig) {\n if (legacy) {\n return {\n /**\n * If the snap uses the legacy config, we use the custom `browserify`\n * loader. This uses the legacy Browserify config to transpile the code.\n * This is necessary for backwards compatibility with the\n * `bundlerCustomizer` function.\n */\n loader: resolve(__dirname, 'loaders', 'browserify'),\n\n /**\n * The options for the `browserify` loader. These can be overridden in the\n * snap config.\n */\n options: legacy,\n };\n }\n\n const targets = await getBrowserslistTargets();\n return {\n /**\n * We use the `swc-loader` to transpile TypeScript and JavaScript files.\n * This is a Webpack loader that uses the `SWC` compiler, which is a much\n * faster alternative to Babel and TypeScript's own compiler.\n */\n loader: 'swc-loader',\n\n /**\n * The options for the `swc-loader`. These can be overridden in the\n * `.swcrc` file.\n *\n * @see https://swc.rs/docs/configuration/swcrc\n */\n options: {\n sync: false,\n\n /**\n * This tells SWC to generate source maps. We set it to the\n * `sourceMap` value from the config object.\n *\n * This must be enabled if source maps are enabled in the config.\n */\n sourceMaps: Boolean(getDevTool(sourceMap)),\n\n jsc: {\n parser: {\n /**\n * This tells the parser to parse TypeScript files. If you\n * don't need to support TypeScript, you can set this to\n * `ecmascript` instead, but there's no harm in leaving it\n * as `typescript`.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n */\n syntax: 'typescript',\n },\n },\n\n /**\n * The module configuration. This tells SWC how to output the\n * transpiled code.\n *\n * @see https://swc.rs/docs/configuration/modules\n */\n module: {\n /**\n * This tells SWC to output CommonJS modules. MetaMask Snaps\n * doesn't support ES modules yet, so this is necessary.\n *\n * @see https://swc.rs/docs/configuration/modules#commonjs\n */\n type: 'commonjs',\n },\n\n env: {\n targets: targets.join(', '),\n },\n },\n };\n}\n\n/**\n * Get the Webpack devtool configuration based on the given snap config.\n *\n * - If `sourceMap` is `inline`, return `inline-source-map`.\n * - If `sourceMap` is `true`, return `source-map`.\n * - Otherwise, return `false`.\n *\n * @param sourceMap - The `sourceMap` value from the snap config.\n * @returns The Webpack devtool configuration.\n */\nexport function getDevTool(\n sourceMap: ProcessedWebpackConfig['sourceMap'],\n): Configuration['devtool'] {\n if (sourceMap === 'inline') {\n return 'inline-source-map';\n }\n\n if (sourceMap === true) {\n return 'source-map';\n }\n\n return false;\n}\n\n/**\n * Get a function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n *\n * @param spinner - The spinner to update.\n * @param spinnerText - The initial spinner text. This will be prepended to the\n * percentage.\n * @returns A function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n */\n// Note: This is extracted for testing purposes.\nexport function getProgressHandler(spinner?: Ora, spinnerText?: string) {\n return (percentage: number) => {\n if (spinner && spinnerText) {\n spinner.text = `${spinnerText} ${dim(\n `(${Math.round(percentage * 100)}%)`,\n )}`;\n }\n };\n}\n\n/**\n * Get the targets from the `.browserslistrc` file.\n *\n * @returns The browser targets as an array of strings.\n */\nexport async function getBrowserslistTargets() {\n const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');\n return contents\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line && !line.startsWith('#'));\n}\n\n/**\n * Get a singular or plural string based on the given count. This is useful for\n * generating messages like \"1 error\" or \"2 errors\". By default, the plural\n * string is the singular string with an \"s\" appended to it.\n *\n * This assumes that the text is in English, and likely won't work for some\n * other languages.\n *\n * @param count - The count.\n * @param singular - The singular string.\n * @param plural - The plural string.\n * @returns The singular or plural string.\n * @example\n * ```typescript\n * pluralize(1, 'error'); // => 'error'\n * pluralize(2, 'error'); // => 'errors'\n * pluralize(1, 'error', 'problem'); // => 'error'\n * pluralize(2, 'error', 'problems'); // => 'problems'\n * ```\n */\nexport function pluralize(\n count: number,\n singular: string,\n plural = `${singular}s`,\n) {\n return count === 1 ? singular : plural;\n}\n\n/**\n * Get an object that can be used as fallback config for Webpack's\n * `fallback` config.\n *\n * @param polyfills - The polyfill object from the snap config.\n * @returns The webpack fallback config.\n */\nexport function getFallbacks(polyfills: ProcessedWebpackConfig['polyfills']): {\n [index: string]: string | false;\n} {\n if (polyfills === true) {\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS] ?? false,\n ]),\n );\n }\n\n if (polyfills === false) {\n return Object.fromEntries(builtinModules.map((name) => [name, false]));\n }\n\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n polyfills[name as keyof ProcessedWebpackConfig['polyfills']]\n ? WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS]\n : false,\n ]),\n );\n}\n"],"names":["dim","promises","fs","builtinModules","dirname","resolve","BROWSERSLIST_FILE","require","WEBPACK_FALLBACKS","assert","buffer","console","constants","crypto","domain","events","http","https","os","path","punycode","process","querystring","stream","_stream_duplex","_stream_passthrough","_stream_readable","_stream_transform","_stream_writable","string_decoder","sys","timers","tty","url","util","vm","zlib","getDefaultLoader","legacy","sourceMap","loader","__dirname","options","targets","getBrowserslistTargets","sync","sourceMaps","Boolean","getDevTool","jsc","parser","syntax","module","type","env","join","getProgressHandler","spinner","spinnerText","percentage","text","Math","round","contents","readFile","split","map","line","trim","filter","startsWith","pluralize","count","singular","plural","getFallbacks","polyfills","Object","fromEntries","name"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ProcessedConfig } from '../../config';
|
|
2
|
+
/**
|
|
3
|
+
* Build all files in the given source directory to the given destination
|
|
4
|
+
* directory.
|
|
5
|
+
*
|
|
6
|
+
* This creates the destination directory if it doesn't exist.
|
|
7
|
+
*
|
|
8
|
+
* @param config - The config object.
|
|
9
|
+
*/
|
|
10
|
+
export declare function buildHandler(config: ProcessedConfig): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ProcessedWebpackConfig } from '../../config';
|
|
2
|
+
import type { WebpackOptions } from '../../webpack';
|
|
3
|
+
/**
|
|
4
|
+
* Build the snap bundle. This uses Webpack to build the bundle.
|
|
5
|
+
*
|
|
6
|
+
* @param config - The config object.
|
|
7
|
+
* @param options - The Webpack options.
|
|
8
|
+
* @returns A promise that resolves when the bundle is built.
|
|
9
|
+
*/
|
|
10
|
+
export declare function build(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type yargs from 'yargs';
|
|
2
|
+
import type { YargsArgs } from '../../types/yargs';
|
|
3
|
+
declare const command: {
|
|
4
|
+
command: string[];
|
|
5
|
+
desc: string;
|
|
6
|
+
builder: (yarg: yargs.Argv) => void;
|
|
7
|
+
handler: (argv: YargsArgs) => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
export * from './implementation';
|
|
10
|
+
export default command;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ProcessedConfig } from '../../config';
|
|
2
|
+
export declare type EvalOptions = {
|
|
3
|
+
input?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare type EvalContext = Required<EvalOptions>;
|
|
6
|
+
/**
|
|
7
|
+
* Runs the snap in a worker, to ensure SES compatibility.
|
|
8
|
+
*
|
|
9
|
+
* @param config - The processed config object.
|
|
10
|
+
* @param options - The eval options.
|
|
11
|
+
* @returns A promise that resolves once the eval has finished.
|
|
12
|
+
* @throws If the eval failed.
|
|
13
|
+
*/
|
|
14
|
+
export declare function evaluateHandler(config: ProcessedConfig, options?: EvalOptions): Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluate the given bundle in the SES environment. This is a wrapper around
|
|
3
|
+
* {@link evalBundle} that throws a {@link CommandError} if the bundle cannot be
|
|
4
|
+
* evaluated.
|
|
5
|
+
*
|
|
6
|
+
* @param path - The path to the bundle.
|
|
7
|
+
* @throws If the bundle cannot be evaluated.
|
|
8
|
+
*/
|
|
9
|
+
export declare function evaluate(path: string): Promise<import("@metamask/snaps-utils").EvalOutput>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type yargs from 'yargs';
|
|
2
|
+
import type { YargsArgs } from '../../types/yargs';
|
|
3
|
+
declare const command: {
|
|
4
|
+
command: string[];
|
|
5
|
+
desc: string;
|
|
6
|
+
builder: (yarg: yargs.Argv) => void;
|
|
7
|
+
handler: (argv: YargsArgs) => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
export * from './implementation';
|
|
10
|
+
export default command;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Ora } from 'ora';
|
|
2
|
+
/**
|
|
3
|
+
* Check the snap manifest file at the given path. If `write` is `true`, the
|
|
4
|
+
* manifest will be written to disk if it is invalid. If `write` is `false`,
|
|
5
|
+
* the manifest will not be written to disk, and the function will log any
|
|
6
|
+
* errors and warnings to the console.
|
|
7
|
+
*
|
|
8
|
+
* @param path - The path to the manifest file.
|
|
9
|
+
* @param write - Whether to write the manifest to disk if it is invalid.
|
|
10
|
+
* @param spinner - An optional spinner to use for logging.
|
|
11
|
+
*/
|
|
12
|
+
export declare function manifest(path: string, write: boolean, spinner?: Ora): Promise<boolean>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type yargs from 'yargs';
|
|
2
|
+
import type { YargsArgs } from '../../types/yargs';
|
|
3
|
+
declare const command: {
|
|
4
|
+
command: string[];
|
|
5
|
+
desc: string;
|
|
6
|
+
builder: (yarg: yargs.Argv) => void;
|
|
7
|
+
handler: (argv: YargsArgs) => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
export * from './implementation';
|
|
10
|
+
export default command;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ProcessedConfig } from '../../config';
|
|
2
|
+
declare type ManifestOptions = {
|
|
3
|
+
fix?: boolean;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Validates a snap.manifest.json file. Attempts to fix the manifest and write
|
|
7
|
+
* the fixed version to disk if `writeManifest` is true. Throws if validation
|
|
8
|
+
* fails.
|
|
9
|
+
*
|
|
10
|
+
* @param config - The config object.
|
|
11
|
+
* @param options - The options object.
|
|
12
|
+
*/
|
|
13
|
+
export declare function manifestHandler(config: ProcessedConfig, options: ManifestOptions): Promise<void>;
|
|
14
|
+
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import yargs from 'yargs';
|
|
2
|
-
import { YargsArgs } from '../../types/yargs';
|
|
3
|
-
declare const
|
|
1
|
+
import type yargs from 'yargs';
|
|
2
|
+
import type { YargsArgs } from '../../types/yargs';
|
|
3
|
+
declare const command: {
|
|
4
4
|
command: string[];
|
|
5
5
|
desc: string;
|
|
6
6
|
builder: (yarg: yargs.Argv) => void;
|
|
7
7
|
handler: (argv: YargsArgs) => Promise<void>;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export default command;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ProcessedConfig } from '../../config';
|
|
2
|
+
declare type ServeOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* The port to listen on.
|
|
5
|
+
*/
|
|
6
|
+
port: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Starts a local, static HTTP server on the given port with the given root
|
|
10
|
+
* directory.
|
|
11
|
+
*
|
|
12
|
+
* @param config - The config object.
|
|
13
|
+
* @param options - The options object.
|
|
14
|
+
*/
|
|
15
|
+
export declare function serveHandler(config: ProcessedConfig, options: ServeOptions): Promise<void>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Watching } from 'webpack';
|
|
2
|
+
import type { ProcessedWebpackConfig } from '../../config';
|
|
3
|
+
import type { WebpackOptions } from '../../webpack';
|
|
4
|
+
/**
|
|
5
|
+
* Build the snap bundle and watch for changes. This uses Webpack to build the
|
|
6
|
+
* bundle.
|
|
7
|
+
*
|
|
8
|
+
* @param config - The config object.
|
|
9
|
+
* @param options - The Webpack options.
|
|
10
|
+
* @returns A promise that resolves when the bundle is built for the first time.
|
|
11
|
+
* The promise resolves with a Webpack watching instance that can be used to
|
|
12
|
+
* close the watcher.
|
|
13
|
+
*/
|
|
14
|
+
export declare function watch(config: ProcessedWebpackConfig, options?: WebpackOptions): Promise<Watching>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type yargs from 'yargs';
|
|
2
|
+
import type { YargsArgs } from '../../types/yargs';
|
|
3
|
+
declare const command: {
|
|
4
|
+
command: string[];
|
|
5
|
+
desc: string;
|
|
6
|
+
builder: (yarg: yargs.Argv) => void;
|
|
7
|
+
handler: (argv: YargsArgs) => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
export * from './implementation';
|
|
10
|
+
export default command;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ProcessedConfig } from '../../config';
|
|
2
|
+
declare type WatchOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* The port to listen on.
|
|
5
|
+
*/
|
|
6
|
+
port?: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Watch a directory and its subdirectories for changes, and build when files
|
|
10
|
+
* are added or changed.
|
|
11
|
+
*
|
|
12
|
+
* Ignores 'node_modules' and dotfiles.
|
|
13
|
+
* Creates destination directory if it doesn't exist.
|
|
14
|
+
*
|
|
15
|
+
* @param config - The config object.
|
|
16
|
+
* @param options - The options object.
|
|
17
|
+
*/
|
|
18
|
+
export declare function watchHandler(config: ProcessedConfig, options: WatchOptions): Promise<void>;
|
|
19
|
+
export {};
|