@metamask/snaps-cli 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -1
- package/dist/cjs/cli.js +36 -3
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/webpack/config.js +11 -0
- package/dist/cjs/webpack/config.js.map +1 -1
- package/dist/cjs/webpack/utils.js +1 -1
- package/dist/cjs/webpack/utils.js.map +1 -1
- package/dist/esm/cli.js +30 -0
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/webpack/config.js +11 -0
- package/dist/esm/webpack/config.js.map +1 -1
- package/dist/esm/webpack/utils.js +1 -1
- package/dist/esm/webpack/utils.js.map +1 -1
- package/dist/types/cli.d.ts +7 -0
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [2.0.2]
|
|
10
|
+
### Fixed
|
|
11
|
+
- Fix Webpack being unable to find `swc-loader` in some cases ([#1798](https://github.com/MetaMask/snaps/pull/1798))
|
|
12
|
+
- Check minimum Node version in CLI ([#1797](https://github.com/MetaMask/snaps/pull/1797))
|
|
13
|
+
|
|
14
|
+
## [2.0.1]
|
|
15
|
+
### Fixed
|
|
16
|
+
- Disable the `fullySpecified` rule for `.js` imports in the default Webpack config ([#1780](https://github.com/MetaMask/snaps/pull/1780))
|
|
17
|
+
|
|
9
18
|
## [2.0.0]
|
|
10
19
|
### Changed
|
|
11
20
|
- Initial stable release from main branch ([#1757](https://github.com/MetaMask/snaps/pull/1757))
|
|
@@ -47,7 +56,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
47
56
|
- The version of the package no longer needs to match the version of all other
|
|
48
57
|
MetaMask Snaps packages.
|
|
49
58
|
|
|
50
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@2.0.
|
|
59
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@2.0.2...HEAD
|
|
60
|
+
[2.0.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@2.0.1...@metamask/snaps-cli@2.0.2
|
|
61
|
+
[2.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@2.0.0...@metamask/snaps-cli@2.0.1
|
|
51
62
|
[2.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@0.38.4-flask.1...@metamask/snaps-cli@2.0.0
|
|
52
63
|
[0.38.4-flask.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@0.38.3-flask.1...@metamask/snaps-cli@0.38.4-flask.1
|
|
53
64
|
[0.38.3-flask.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@0.38.2-flask.1...@metamask/snaps-cli@0.38.3-flask.1
|
package/dist/cjs/cli.js
CHANGED
|
@@ -2,12 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
checkNodeVersion: function() {
|
|
13
|
+
return checkNodeVersion;
|
|
14
|
+
},
|
|
15
|
+
cli: function() {
|
|
8
16
|
return cli;
|
|
9
17
|
}
|
|
10
18
|
});
|
|
19
|
+
const _semver = /*#__PURE__*/ _interop_require_default(require("semver"));
|
|
11
20
|
const _yargs = /*#__PURE__*/ _interop_require_default(require("yargs"));
|
|
12
21
|
const _helpers = require("yargs/helpers");
|
|
13
22
|
const _builders = /*#__PURE__*/ _interop_require_default(require("./builders"));
|
|
@@ -18,7 +27,31 @@ function _interop_require_default(obj) {
|
|
|
18
27
|
default: obj
|
|
19
28
|
};
|
|
20
29
|
}
|
|
30
|
+
const MINIMUM_NODE_16_VERSION = '16.17.0';
|
|
31
|
+
const MINIMUM_NODE_18_VERSION = '18.6.0';
|
|
32
|
+
function checkNodeVersion(nodeVersion = process.version.slice(1)) {
|
|
33
|
+
const majorVersion = _semver.default.major(nodeVersion);
|
|
34
|
+
const message = `Node version ${nodeVersion} is not supported. Please use Node ${MINIMUM_NODE_16_VERSION} or later.`;
|
|
35
|
+
if (majorVersion < 16) {
|
|
36
|
+
(0, _utils.error)(message);
|
|
37
|
+
// eslint-disable-next-line n/no-process-exit
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
// Node 16 and 18 have a different minimum version requirement, so we need to
|
|
41
|
+
// check for both.
|
|
42
|
+
if (majorVersion === 16 && _semver.default.lt(nodeVersion, MINIMUM_NODE_16_VERSION)) {
|
|
43
|
+
(0, _utils.error)(message);
|
|
44
|
+
// eslint-disable-next-line n/no-process-exit
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
if (majorVersion === 18 && _semver.default.lt(nodeVersion, MINIMUM_NODE_18_VERSION)) {
|
|
48
|
+
(0, _utils.error)(`Node version ${nodeVersion} is not supported. Please use Node ${MINIMUM_NODE_18_VERSION} or later.`);
|
|
49
|
+
// eslint-disable-next-line n/no-process-exit
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
21
53
|
async function cli(argv, commands) {
|
|
54
|
+
checkNodeVersion();
|
|
22
55
|
await (0, _yargs.default)((0, _helpers.hideBin)(argv)).scriptName('mm-snap').usage('Usage: $0 <command> [options]').example('$0 build', `Build './src/index.js' as './dist/bundle.js'`).example('$0 build --config ./snap.config.build.ts', `Build './src/index.js' as './dist/bundle.js' using the config in './snap.config.build.ts'`).example('$0 manifest --fix', `Check the snap manifest, and fix any errors`).example('$0 watch --port 8000', `The snap input file for changes, and serve it on port 8000`).example('$0 serve --port 8000', `Serve the snap bundle on port 8000`).command(commands).option('config', _builders.default.config).option('verboseErrors', _builders.default.verboseErrors).option('suppressWarnings', _builders.default.suppressWarnings).strict().middleware(async (args)=>{
|
|
23
56
|
// eslint-disable-next-line require-atomic-updates
|
|
24
57
|
args.context = {
|
package/dist/cjs/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\n\nimport builders from './builders';\nimport { getConfigByArgv } from './config';\nimport { error, getYargsErrorMessage, sanitizeInputs } from './utils';\n\n/**\n * The main CLI entry point function. This processes the command line args, and\n * runs the appropriate function.\n *\n * @param argv - The raw command line arguments, i.e., `process.argv`.\n * @param commands - The list of commands to use.\n */\nexport async function cli(argv: string[], commands: any) {\n await yargs(hideBin(argv))\n .scriptName('mm-snap')\n .usage('Usage: $0 <command> [options]')\n\n .example('$0 build', `Build './src/index.js' as './dist/bundle.js'`)\n .example(\n '$0 build --config ./snap.config.build.ts',\n `Build './src/index.js' as './dist/bundle.js' using the config in './snap.config.build.ts'`,\n )\n .example('$0 manifest --fix', `Check the snap manifest, and fix any errors`)\n .example(\n '$0 watch --port 8000',\n `The snap input file for changes, and serve it on port 8000`,\n )\n .example('$0 serve --port 8000', `Serve the snap bundle on port 8000`)\n\n .command(commands)\n\n .option('config', builders.config)\n .option('verboseErrors', builders.verboseErrors)\n .option('suppressWarnings', builders.suppressWarnings)\n\n .strict()\n\n .middleware(async (args: any) => {\n // eslint-disable-next-line require-atomic-updates\n args.context = {\n config: await getConfigByArgv(args),\n };\n\n sanitizeInputs(args);\n }, false)\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .fail((message, failure) => {\n error(getYargsErrorMessage(message, failure));\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n })\n\n .help()\n .alias('help', 'h')\n .parseAsync();\n}\n"],"names":["cli","argv","commands","yargs","hideBin","scriptName","usage","example","command","option","builders","config","verboseErrors","suppressWarnings","strict","middleware","args","context","getConfigByArgv","sanitizeInputs","demandCommand","fail","
|
|
1
|
+
{"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import semver from 'semver';\nimport yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\n\nimport builders from './builders';\nimport { getConfigByArgv } from './config';\nimport { error, getYargsErrorMessage, sanitizeInputs } from './utils';\n\nconst MINIMUM_NODE_16_VERSION = '16.17.0';\nconst MINIMUM_NODE_18_VERSION = '18.6.0';\n\n/**\n * Check the Node version. If the Node version is less than the minimum required\n * version, this logs an error and exits the process.\n *\n * @param nodeVersion - The Node version to check.\n */\nexport function checkNodeVersion(\n nodeVersion: string = process.version.slice(1),\n) {\n const majorVersion = semver.major(nodeVersion);\n const message = `Node version ${nodeVersion} is not supported. Please use Node ${MINIMUM_NODE_16_VERSION} or later.`;\n\n if (majorVersion < 16) {\n error(message);\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n\n // Node 16 and 18 have a different minimum version requirement, so we need to\n // check for both.\n if (majorVersion === 16 && semver.lt(nodeVersion, MINIMUM_NODE_16_VERSION)) {\n error(message);\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n\n if (majorVersion === 18 && semver.lt(nodeVersion, MINIMUM_NODE_18_VERSION)) {\n error(\n `Node version ${nodeVersion} is not supported. Please use Node ${MINIMUM_NODE_18_VERSION} or later.`,\n );\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n}\n\n/**\n * The main CLI entry point function. This processes the command line args, and\n * runs the appropriate function.\n *\n * @param argv - The raw command line arguments, i.e., `process.argv`.\n * @param commands - The list of commands to use.\n */\nexport async function cli(argv: string[], commands: any) {\n checkNodeVersion();\n\n await yargs(hideBin(argv))\n .scriptName('mm-snap')\n .usage('Usage: $0 <command> [options]')\n\n .example('$0 build', `Build './src/index.js' as './dist/bundle.js'`)\n .example(\n '$0 build --config ./snap.config.build.ts',\n `Build './src/index.js' as './dist/bundle.js' using the config in './snap.config.build.ts'`,\n )\n .example('$0 manifest --fix', `Check the snap manifest, and fix any errors`)\n .example(\n '$0 watch --port 8000',\n `The snap input file for changes, and serve it on port 8000`,\n )\n .example('$0 serve --port 8000', `Serve the snap bundle on port 8000`)\n\n .command(commands)\n\n .option('config', builders.config)\n .option('verboseErrors', builders.verboseErrors)\n .option('suppressWarnings', builders.suppressWarnings)\n\n .strict()\n\n .middleware(async (args: any) => {\n // eslint-disable-next-line require-atomic-updates\n args.context = {\n config: await getConfigByArgv(args),\n };\n\n sanitizeInputs(args);\n }, false)\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .fail((message, failure) => {\n error(getYargsErrorMessage(message, failure));\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n })\n\n .help()\n .alias('help', 'h')\n .parseAsync();\n}\n"],"names":["checkNodeVersion","cli","MINIMUM_NODE_16_VERSION","MINIMUM_NODE_18_VERSION","nodeVersion","process","version","slice","majorVersion","semver","major","message","error","exit","lt","argv","commands","yargs","hideBin","scriptName","usage","example","command","option","builders","config","verboseErrors","suppressWarnings","strict","middleware","args","context","getConfigByArgv","sanitizeInputs","demandCommand","fail","failure","getYargsErrorMessage","help","alias","parseAsync"],"mappings":";;;;;;;;;;;IAiBgBA,gBAAgB;eAAhBA;;IAoCMC,GAAG;eAAHA;;;+DArDH;8DACD;yBACM;iEAEH;wBACW;uBAC4B;;;;;;AAE5D,MAAMC,0BAA0B;AAChC,MAAMC,0BAA0B;AAQzB,SAASH,iBACdI,cAAsBC,QAAQC,OAAO,CAACC,KAAK,CAAC,EAAE;IAE9C,MAAMC,eAAeC,eAAM,CAACC,KAAK,CAACN;IAClC,MAAMO,UAAU,CAAC,aAAa,EAAEP,YAAY,mCAAmC,EAAEF,wBAAwB,UAAU,CAAC;IAEpH,IAAIM,eAAe,IAAI;QACrBI,IAAAA,YAAK,EAACD;QACN,6CAA6C;QAC7CN,QAAQQ,IAAI,CAAC;IACf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C/B,QAAQQ,IAAI,CAAC;IACf,GAECyB,IAAI,GACJC,KAAK,CAAC,QAAQ,KACdC,UAAU;AACf"}
|
|
@@ -113,6 +113,17 @@ async function getDefaultConfiguration(config, options = {
|
|
|
113
113
|
exclude: /node_modules/u,
|
|
114
114
|
use: await (0, _utils.getDefaultLoader)(config)
|
|
115
115
|
},
|
|
116
|
+
/**
|
|
117
|
+
* This allows importing modules that uses `.js` and not `.mjs` for the
|
|
118
|
+
* ES build.
|
|
119
|
+
*
|
|
120
|
+
* @see https://webpack.js.org/configuration/module/#resolvefullyspecified
|
|
121
|
+
*/ {
|
|
122
|
+
test: /\.m?js/u,
|
|
123
|
+
resolve: {
|
|
124
|
+
fullySpecified: false
|
|
125
|
+
}
|
|
126
|
+
},
|
|
116
127
|
config.experimental.wasm && {
|
|
117
128
|
test: /\.wasm$/u,
|
|
118
129
|
use: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/webpack/config.ts"],"sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { EnvironmentPlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getFallbacks,\n getProgressHandler,\n} from './utils';\n\nexport type WebpackOptions = {\n /**\n * Whether to watch for changes.\n */\n watch?: boolean;\n\n /**\n * Whether to evaluate the bundle. If this is set, it will override the\n * `evaluate` option in the config object.\n */\n evaluate?: boolean;\n\n /**\n * The spinner to use for logging.\n */\n spinner?: Ora;\n};\n\n/**\n * Get the default Webpack configuration. This is the configuration that will\n * be used if the user doesn't provide a custom Webpack configuration. The\n * configuration is based on the snap config.\n *\n * The default configuration includes:\n *\n * - `SWC` to transpile TypeScript and JavaScript files.\n * - `TerserPlugin` to minify the bundle.\n * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.\n *\n * It can be customized through the `customizeWebpackConfig` function in the\n * snap config, but in most cases, you shouldn't need to do that.\n *\n * @param config - The processed snap Webpack config.\n * @param options - The Webpack options.\n * @returns The default Webpack configuration.\n */\nexport async function getDefaultConfiguration(\n config: ProcessedWebpackConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns &&\n new SnapsBuiltInResolver(config.stats.builtIns, options.spinner);\n\n return {\n /**\n * The target is set to `browserslist` so that Webpack will compile the\n * bundle to support the browsers specified in the `.browserslistrc` file.\n * This Browserslist file contains the browsers that are supported by\n * MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/target/\n */\n target: `browserslist:${BROWSERSLIST_FILE}`,\n\n /**\n * The mode is set to `production` by default, so that Webpack will minify\n * and optimize the bundle.\n *\n * @see https://webpack.js.org/configuration/mode/\n */\n mode: 'production',\n\n /**\n * The entry point is set to the `input` value from the config object.\n *\n * @see https://webpack.js.org/configuration/entry-context/\n */\n entry: config.input,\n\n /**\n * The devtool option controls how source maps are generated. We set it to\n * the `sourceMap` value from the config object.\n *\n * @see https://webpack.js.org/configuration/devtool/\n */\n devtool: getDevTool(config.sourceMap),\n\n /**\n * The stats option controls how much information is printed to the console\n * when Webpack is running. We set it to `none` so that we can control the\n * output ourselves.\n *\n * @see https://webpack.js.org/configuration/stats/\n */\n stats: 'none',\n\n /**\n * The output options.\n *\n * @see https://webpack.js.org/configuration/output/\n */\n output: {\n /**\n * This indicates whether Webpack should clear the output directory\n * before building. We set it to the `clean` value from the config\n * object.\n *\n * @see https://webpack.js.org/configuration/output/#outputclean\n */\n clean: config.output.clean,\n\n /**\n * The filename of the bundle. We set it to the `filename` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputfilename\n */\n filename: config.output.filename,\n\n /**\n * The path to the output directory. We set it to the `path` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputpath\n */\n path: config.output.path,\n\n /**\n * The public path of the bundle. We set it to `/` by default, so that\n * the bundle can be loaded from the root of the server.\n *\n * @see https://webpack.js.org/configuration/output/#outputpublicpath\n */\n publicPath: '/',\n\n /**\n * The library configuration. This tells Webpack how to export the\n * bundle.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrary\n */\n library: {\n /**\n * This tells Webpack to export the bundle as a CommonJS module. This\n * is necessary for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'commonjs',\n },\n },\n\n /**\n * The module configuration. This is where we tell Webpack how to handle\n * different types of files.\n *\n * @see https://webpack.js.org/configuration/module/\n */\n module: {\n rules: [\n {\n test: /\\.[tj]sx?$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: {\n loader: resolve(__dirname, 'loaders', 'wasm'),\n },\n },\n ],\n },\n\n /**\n * The resolve configuration. This tells Webpack how to resolve imports.\n * We set it to resolve `.js` and `.ts` files.\n *\n * @see https://webpack.js.org/configuration/resolve/\n */\n resolve: {\n /**\n * The extensions to resolve. We set it to resolve `.js` and `.ts`\n * files.\n */\n extensions: ['.js', '.ts'],\n\n /**\n * The fallback options. This tells Webpack how to handle imports that\n * aren't resolved. By default, we set Node.js built-ins to `false`, so\n * that they are ignored.\n */\n fallback: getFallbacks(config.polyfills),\n\n /**\n * The plugins to use. We use the {@link SnapsBuiltInResolver} to show\n * warnings about using Node.js built-ins, when no fallback is specified.\n */\n plugins: [builtInResolver],\n },\n\n /**\n * The plugins to use.\n *\n * @see https://webpack.js.org/configuration/plugins/\n */\n plugins: [\n /**\n * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates\n * the manifest file, and evaluates the bundle in SES. While not strictly\n * required, it's highly recommended to use this plugin.\n */\n new SnapsWebpackPlugin({\n manifestPath: config.manifest.path,\n writeManifest: config.manifest.update,\n eval: !options.watch && options.evaluate,\n }),\n\n /**\n * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats\n * output. It's used to show the stats in the terminal, in a format that\n * is easy to read.\n */\n new SnapsStatsPlugin({ verbose: config.stats.verbose }, options.spinner),\n\n /**\n * The `EnvironmentPlugin` is a Webpack plugin that adds environment\n * variables to the bundle. We use it to add the `NODE_ENV` and `DEBUG`\n * environment variables.\n */\n new EnvironmentPlugin(config.environment),\n\n /**\n * The `ProgressPlugin` is a Webpack plugin that logs the progress of\n * the build. We set it to log the progress to the spinner.\n */\n new ProgressPlugin({\n handler: getProgressHandler(options.spinner, spinnerText),\n }),\n\n /**\n * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a\n * warning when the bundle is potentially incompatible with MetaMask\n * Snaps.\n */\n new SnapsBundleWarningsPlugin(\n {\n builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\n },\n options.spinner,\n ),\n\n /**\n * The `WatchPlugin` is a Webpack plugin that adds extra files to watch\n * for changes. This is useful for rebuilding the bundle when the\n * manifest file changes.\n */\n options.watch &&\n new SnapsWatchPlugin(\n {\n bundle: resolve(config.output.path, config.output.filename),\n evaluate: options.evaluate,\n files: [config.manifest.path],\n },\n options.spinner,\n ),\n\n /**\n * The `ProviderPlugin` is a Webpack plugin that automatically load\n * modules instead of having to import or require them everywhere.\n */\n (config.polyfills === true ||\n (config.polyfills !== false && config.polyfills.buffer)) &&\n new ProvidePlugin({\n Buffer: ['buffer', 'Buffer'],\n }),\n ].filter(Boolean),\n\n /**\n * The optimization configuration. This tells Webpack how to optimize the\n * bundle. Most of the time, you won't need to change this, as the default\n * options set by the `mode` option are sufficient.\n */\n optimization: {\n minimize: config.output.minimize,\n\n /**\n * The minimizer to use. We set it to use the `TerserPlugin`.\n */\n minimizer: [\n new TerserPlugin({\n parallel: true,\n }),\n ],\n },\n\n /**\n * The infrastructure logging configuration. This tells Webpack how to\n * log messages.\n *\n * @see https://webpack.js.org/configuration/infrastructure-logging\n */\n infrastructureLogging: {\n /**\n * The level of logging to use. We set it to `none`, so that we can\n * control the output ourselves.\n */\n level: 'none',\n },\n };\n}\n"],"names":["getDefaultConfiguration","config","options","evaluate","spinnerText","spinner","text","builtInResolver","stats","builtIns","SnapsBuiltInResolver","target","BROWSERSLIST_FILE","mode","entry","input","devtool","getDevTool","sourceMap","output","clean","filename","path","publicPath","library","type","module","rules","test","exclude","use","getDefaultLoader","experimental","wasm","loader","resolve","__dirname","extensions","fallback","getFallbacks","polyfills","plugins","SnapsWebpackPlugin","manifestPath","manifest","writeManifest","update","eval","watch","SnapsStatsPlugin","verbose","EnvironmentPlugin","environment","ProgressPlugin","handler","getProgressHandler","SnapsBundleWarningsPlugin","Boolean","buffer","SnapsWatchPlugin","bundle","files","ProvidePlugin","Buffer","filter","optimization","minimize","minimizer","TerserPlugin","parallel","infrastructureLogging","level"],"mappings":";;;;+BA0DsBA;;;eAAAA;;;2EA1DS;sBAEP;4EACC;yBAEwC;yBAQ1D;uBAOA;;;;;;AAsCA,eAAeA,wBACpBC,MAA8B,EAC9BC,UAA0B;IACxBC,UAAUF,OAAOE,QAAQ;AAC3B,CAAC;IAED,MAAMC,cAAcF,QAAQG,OAAO,EAAEC;IACrC,MAAMC,kBACJN,OAAOO,KAAK,CAACC,QAAQ,IACrB,IAAIC,6BAAoB,CAACT,OAAOO,KAAK,CAACC,QAAQ,EAAEP,QAAQG,OAAO;IAEjE,OAAO;QACL;;;;;;;KAOC,GACDM,QAAQ,CAAC,aAAa,EAAEC,wBAAiB,CAAC,CAAC;QAE3C;;;;;KAKC,GACDC,MAAM;QAEN;;;;KAIC,GACDC,OAAOb,OAAOc,KAAK;QAEnB;;;;;KAKC,GACDC,SAASC,IAAAA,iBAAU,EAAChB,OAAOiB,SAAS;QAEpC;;;;;;KAMC,GACDV,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yBAAkB,EAACrD,QAAQG,OAAO,EAAED;YAC/C;YAEA;;;;OAIC,GACD,IAAIoD,kCAAyB,CAC3B;gBACEjD;gBACAE,UAAUgD,QAAQxD,OAAOO,KAAK,CAACC,QAAQ;gBACvCiD,QAAQzD,OAAOO,KAAK,CAACkD,MAAM;YAC7B,GACAxD,QAAQG,OAAO;YAGjB;;;;OAIC,GACDH,QAAQ8C,KAAK,IACX,IAAIW,yBAAgB,CAClB;gBACEC,QAAQzB,IAAAA,aAAO,EAAClC,OAAOkB,MAAM,CAACG,IAAI,EAAErB,OAAOkB,MAAM,CAACE,QAAQ;gBAC1DlB,UAAUD,QAAQC,QAAQ;gBAC1B0D,OAAO;oBAAC5D,OAAO2C,QAAQ,CAACtB,IAAI;iBAAC;YAC/B,GACApB,QAAQG,OAAO;YAGnB;;;OAGC,GACAJ,CAAAA,OAAOuC,SAAS,KAAK,QACnBvC,OAAOuC,SAAS,KAAK,SAASvC,OAAOuC,SAAS,CAACkB,MAAM,KACtD,IAAII,sBAAa,CAAC;gBAChBC,QAAQ;oBAAC;oBAAU;iBAAS;YAC9B;SACH,CAACC,MAAM,CAACP;QAET;;;;KAIC,GACDQ,cAAc;YACZC,UAAUjE,OAAOkB,MAAM,CAAC+C,QAAQ;YAEhC;;OAEC,GACDC,WAAW;gBACT,IAAIC,4BAAY,CAAC;oBACfC,UAAU;gBACZ;aACD;QACH;QAEA;;;;;KAKC,GACDC,uBAAuB;YACrB;;;OAGC,GACDC,OAAO;QACT;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/webpack/config.ts"],"sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { EnvironmentPlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getFallbacks,\n getProgressHandler,\n} from './utils';\n\nexport type WebpackOptions = {\n /**\n * Whether to watch for changes.\n */\n watch?: boolean;\n\n /**\n * Whether to evaluate the bundle. If this is set, it will override the\n * `evaluate` option in the config object.\n */\n evaluate?: boolean;\n\n /**\n * The spinner to use for logging.\n */\n spinner?: Ora;\n};\n\n/**\n * Get the default Webpack configuration. This is the configuration that will\n * be used if the user doesn't provide a custom Webpack configuration. The\n * configuration is based on the snap config.\n *\n * The default configuration includes:\n *\n * - `SWC` to transpile TypeScript and JavaScript files.\n * - `TerserPlugin` to minify the bundle.\n * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.\n *\n * It can be customized through the `customizeWebpackConfig` function in the\n * snap config, but in most cases, you shouldn't need to do that.\n *\n * @param config - The processed snap Webpack config.\n * @param options - The Webpack options.\n * @returns The default Webpack configuration.\n */\nexport async function getDefaultConfiguration(\n config: ProcessedWebpackConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns &&\n new SnapsBuiltInResolver(config.stats.builtIns, options.spinner);\n\n return {\n /**\n * The target is set to `browserslist` so that Webpack will compile the\n * bundle to support the browsers specified in the `.browserslistrc` file.\n * This Browserslist file contains the browsers that are supported by\n * MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/target/\n */\n target: `browserslist:${BROWSERSLIST_FILE}`,\n\n /**\n * The mode is set to `production` by default, so that Webpack will minify\n * and optimize the bundle.\n *\n * @see https://webpack.js.org/configuration/mode/\n */\n mode: 'production',\n\n /**\n * The entry point is set to the `input` value from the config object.\n *\n * @see https://webpack.js.org/configuration/entry-context/\n */\n entry: config.input,\n\n /**\n * The devtool option controls how source maps are generated. We set it to\n * the `sourceMap` value from the config object.\n *\n * @see https://webpack.js.org/configuration/devtool/\n */\n devtool: getDevTool(config.sourceMap),\n\n /**\n * The stats option controls how much information is printed to the console\n * when Webpack is running. We set it to `none` so that we can control the\n * output ourselves.\n *\n * @see https://webpack.js.org/configuration/stats/\n */\n stats: 'none',\n\n /**\n * The output options.\n *\n * @see https://webpack.js.org/configuration/output/\n */\n output: {\n /**\n * This indicates whether Webpack should clear the output directory\n * before building. We set it to the `clean` value from the config\n * object.\n *\n * @see https://webpack.js.org/configuration/output/#outputclean\n */\n clean: config.output.clean,\n\n /**\n * The filename of the bundle. We set it to the `filename` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputfilename\n */\n filename: config.output.filename,\n\n /**\n * The path to the output directory. We set it to the `path` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputpath\n */\n path: config.output.path,\n\n /**\n * The public path of the bundle. We set it to `/` by default, so that\n * the bundle can be loaded from the root of the server.\n *\n * @see https://webpack.js.org/configuration/output/#outputpublicpath\n */\n publicPath: '/',\n\n /**\n * The library configuration. This tells Webpack how to export the\n * bundle.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrary\n */\n library: {\n /**\n * This tells Webpack to export the bundle as a CommonJS module. This\n * is necessary for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'commonjs',\n },\n },\n\n /**\n * The module configuration. This is where we tell Webpack how to handle\n * different types of files.\n *\n * @see https://webpack.js.org/configuration/module/\n */\n module: {\n rules: [\n {\n test: /\\.[tj]sx?$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n /**\n * This allows importing modules that uses `.js` and not `.mjs` for the\n * ES build.\n *\n * @see https://webpack.js.org/configuration/module/#resolvefullyspecified\n */\n {\n test: /\\.m?js/u,\n resolve: {\n fullySpecified: false,\n },\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: {\n loader: resolve(__dirname, 'loaders', 'wasm'),\n },\n },\n ],\n },\n\n /**\n * The resolve configuration. This tells Webpack how to resolve imports.\n * We set it to resolve `.js` and `.ts` files.\n *\n * @see https://webpack.js.org/configuration/resolve/\n */\n resolve: {\n /**\n * The extensions to resolve. We set it to resolve `.js` and `.ts`\n * files.\n */\n extensions: ['.js', '.ts'],\n\n /**\n * The fallback options. This tells Webpack how to handle imports that\n * aren't resolved. By default, we set Node.js built-ins to `false`, so\n * that they are ignored.\n */\n fallback: getFallbacks(config.polyfills),\n\n /**\n * The plugins to use. We use the {@link SnapsBuiltInResolver} to show\n * warnings about using Node.js built-ins, when no fallback is specified.\n */\n plugins: [builtInResolver],\n },\n\n /**\n * The plugins to use.\n *\n * @see https://webpack.js.org/configuration/plugins/\n */\n plugins: [\n /**\n * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates\n * the manifest file, and evaluates the bundle in SES. While not strictly\n * required, it's highly recommended to use this plugin.\n */\n new SnapsWebpackPlugin({\n manifestPath: config.manifest.path,\n writeManifest: config.manifest.update,\n eval: !options.watch && options.evaluate,\n }),\n\n /**\n * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats\n * output. It's used to show the stats in the terminal, in a format that\n * is easy to read.\n */\n new SnapsStatsPlugin({ verbose: config.stats.verbose }, options.spinner),\n\n /**\n * The `EnvironmentPlugin` is a Webpack plugin that adds environment\n * variables to the bundle. We use it to add the `NODE_ENV` and `DEBUG`\n * environment variables.\n */\n new EnvironmentPlugin(config.environment),\n\n /**\n * The `ProgressPlugin` is a Webpack plugin that logs the progress of\n * the build. We set it to log the progress to the spinner.\n */\n new ProgressPlugin({\n handler: getProgressHandler(options.spinner, spinnerText),\n }),\n\n /**\n * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a\n * warning when the bundle is potentially incompatible with MetaMask\n * Snaps.\n */\n new SnapsBundleWarningsPlugin(\n {\n builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\n },\n options.spinner,\n ),\n\n /**\n * The `WatchPlugin` is a Webpack plugin that adds extra files to watch\n * for changes. This is useful for rebuilding the bundle when the\n * manifest file changes.\n */\n options.watch &&\n new SnapsWatchPlugin(\n {\n bundle: resolve(config.output.path, config.output.filename),\n evaluate: options.evaluate,\n files: [config.manifest.path],\n },\n options.spinner,\n ),\n\n /**\n * The `ProviderPlugin` is a Webpack plugin that automatically load\n * modules instead of having to import or require them everywhere.\n */\n (config.polyfills === true ||\n (config.polyfills !== false && config.polyfills.buffer)) &&\n new ProvidePlugin({\n Buffer: ['buffer', 'Buffer'],\n }),\n ].filter(Boolean),\n\n /**\n * The optimization configuration. This tells Webpack how to optimize the\n * bundle. Most of the time, you won't need to change this, as the default\n * options set by the `mode` option are sufficient.\n */\n optimization: {\n minimize: config.output.minimize,\n\n /**\n * The minimizer to use. We set it to use the `TerserPlugin`.\n */\n minimizer: [\n new TerserPlugin({\n parallel: true,\n }),\n ],\n },\n\n /**\n * The infrastructure logging configuration. This tells Webpack how to\n * log messages.\n *\n * @see https://webpack.js.org/configuration/infrastructure-logging\n */\n infrastructureLogging: {\n /**\n * The level of logging to use. We set it to `none`, so that we can\n * control the output ourselves.\n */\n level: 'none',\n },\n };\n}\n"],"names":["getDefaultConfiguration","config","options","evaluate","spinnerText","spinner","text","builtInResolver","stats","builtIns","SnapsBuiltInResolver","target","BROWSERSLIST_FILE","mode","entry","input","devtool","getDevTool","sourceMap","output","clean","filename","path","publicPath","library","type","module","rules","test","exclude","use","getDefaultLoader","resolve","fullySpecified","experimental","wasm","loader","__dirname","extensions","fallback","getFallbacks","polyfills","plugins","SnapsWebpackPlugin","manifestPath","manifest","writeManifest","update","eval","watch","SnapsStatsPlugin","verbose","EnvironmentPlugin","environment","ProgressPlugin","handler","getProgressHandler","SnapsBundleWarningsPlugin","Boolean","buffer","SnapsWatchPlugin","bundle","files","ProvidePlugin","Buffer","filter","optimization","minimize","minimizer","TerserPlugin","parallel","infrastructureLogging","level"],"mappings":";;;;+BA0DsBA;;;eAAAA;;;2EA1DS;sBAEP;4EACC;yBAEwC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,sBAAa,CAAC;gBAChBC,QAAQ;oBAAC;oBAAU;iBAAS;YAC9B;SACH,CAACC,MAAM,CAACP;QAET;;;;KAIC,GACDQ,cAAc;YACZC,UAAUlE,OAAOkB,MAAM,CAACgD,QAAQ;YAEhC;;OAEC,GACDC,WAAW;gBACT,IAAIC,4BAAY,CAAC;oBACfC,UAAU;gBACZ;aACD;QACH;QAEA;;;;;KAKC,GACDC,uBAAuB;YACrB;;;OAGC,GACDC,OAAO;QACT;IACF;AACF"}
|
|
@@ -91,7 +91,7 @@ async function getDefaultLoader({ legacy, sourceMap }) {
|
|
|
91
91
|
* We use the `swc-loader` to transpile TypeScript and JavaScript files.
|
|
92
92
|
* This is a Webpack loader that uses the `SWC` compiler, which is a much
|
|
93
93
|
* faster alternative to Babel and TypeScript's own compiler.
|
|
94
|
-
*/ loader: 'swc-loader',
|
|
94
|
+
*/ loader: require.resolve('swc-loader'),
|
|
95
95
|
/**
|
|
96
96
|
* The options for the `swc-loader`. These can be overridden in the
|
|
97
97
|
* `.swcrc` file.
|
|
@@ -1 +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":["BROWSERSLIST_FILE","WEBPACK_FALLBACKS","getDefaultLoader","getDevTool","getProgressHandler","getBrowserslistTargets","pluralize","getFallbacks","resolve","dirname","require","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","legacy","sourceMap","loader","__dirname","options","targets","sync","sourceMaps","Boolean","jsc","parser","syntax","module","type","env","join","spinner","spinnerText","percentage","text","dim","Math","round","contents","fs","readFile","split","map","line","trim","filter","startsWith","count","singular","plural","polyfills","Object","fromEntries","builtinModules","name"],"mappings":";;;;;;;;;;;IASaA,iBAAiB;eAAjBA;;IAQAC,iBAAiB;eAAjBA;;IAmDSC,gBAAgB;eAAhBA;;IA+FNC,UAAU;eAAVA;;IAyBAC,kBAAkB;eAAlBA;;IAeMC,sBAAsB;eAAtBA;;IA4BNC,SAAS;eAATA;;IAeAC,YAAY;eAAZA;;;uBAtPI;oBACW;wBACA;sBAEE;AAK1B,MAAMP,oBAAoBQ,IAAAA,aAAO,EACtCC,IAAAA,aAAO,EACL,mDAAmD;AACnDC,QAAQF,OAAO,CAAC,sCAElB;AAGK,MAAMP,oBAAoB;IAC/BU,QAAQD,QAAQF,OAAO,CAAC;IACxBI,QAAQF,QAAQF,OAAO,CAAC;IACxBK,SAASH,QAAQF,OAAO,CAAC;IACzBM,WAAWJ,QAAQF,OAAO,CAAC;IAC3BO,QAAQL,QAAQF,OAAO,CAAC;IACxBQ,QAAQN,QAAQF,OAAO,CAAC;IACxBS,QAAQP,QAAQF,OAAO,CAAC;IACxBU,MAAMR,QAAQF,OAAO,CAAC;IACtBW,OAAOT,QAAQF,OAAO,CAAC;IACvBY,IAAIV,QAAQF,OAAO,CAAC;IACpBa,MAAMX,QAAQF,OAAO,CAAC;IACtBc,UAAUZ,QAAQF,OAAO,CAAC;IAC1Be,SAASb,QAAQF,OAAO,CAAC;IACzBgB,aAAad,QAAQF,OAAO,CAAC;IAC7BiB,QAAQf,QA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D,OAAa,EAAEC,WAAoB;IACpE,OAAO,CAACC;QACN,IAAIF,WAAWC,aAAa;YAC1BD,QAAQG,IAAI,GAAG,CAAC,EAAEF,YAAY,CAAC,EAAEG,IAAAA,UAAG,EAClC,CAAC,CAAC,EAAEC,KAAKC,KAAK,CAACJ,aAAa,KAAK,EAAE,CAAC,EACpC,CAAC;QACL;IACF;AACF;AAOO,eAAepD;IACpB,MAAMyD,WAAW,MAAMC,YAAE,CAACC,QAAQ,CAAChE,mBAAmB;IACtD,OAAO8D,SACJG,KAAK,CAAC,MACNC,GAAG,CAAC,CAACC,OAASA,KAAKC,IAAI,IACvBC,MAAM,CAAC,CAACF,OAASA,QAAQ,CAACA,KAAKG,UAAU,CAAC;AAC/C;AAsBO,SAAShE,UACdiE,KAAa,EACbC,QAAgB,EAChBC,SAAS,CAAC,EAAED,SAAS,CAAC,CAAC;IAEvB,OAAOD,UAAU,IAAIC,WAAWC;AAClC;AASO,SAASlE,aAAamE,SAA8C;IAGzE,IAAIA,cAAc,MAAM;QACtB,OAAOC,OAAOC,WAAW,CACvBC,sBAAc,CAACX,GAAG,CAAC,CAACY,OAAS;gBAC3BA;gBACA7E,iBAAiB,CAAC6E,KAAuC,IAAI;aAC9D;IAEL;IAEA,IAAIJ,cAAc,OAAO;QACvB,OAAOC,OAAOC,WAAW,CAACC,sBAAc,CAACX,GAAG,CAAC,CAACY,OAAS;gBAACA;gBAAM;aAAM;IACtE;IAEA,OAAOH,OAAOC,WAAW,CACvBC,sBAAc,CAACX,GAAG,CAAC,CAACY,OAAS;YAC3BA;YACAJ,SAAS,CAACI,KAAkD,GACxD7E,iBAAiB,CAAC6E,KAAuC,GACzD;SACL;AAEL"}
|
|
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: require.resolve('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":["BROWSERSLIST_FILE","WEBPACK_FALLBACKS","getDefaultLoader","getDevTool","getProgressHandler","getBrowserslistTargets","pluralize","getFallbacks","resolve","dirname","require","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","legacy","sourceMap","loader","__dirname","options","targets","sync","sourceMaps","Boolean","jsc","parser","syntax","module","type","env","join","spinner","spinnerText","percentage","text","dim","Math","round","contents","fs","readFile","split","map","line","trim","filter","startsWith","count","singular","plural","polyfills","Object","fromEntries","builtinModules","name"],"mappings":";;;;;;;;;;;IASaA,iBAAiB;eAAjBA;;IAQAC,iBAAiB;eAAjBA;;IAmDSC,gBAAgB;eAAhBA;;IA+FNC,UAAU;eAAVA;;IAyBAC,kBAAkB;eAAlBA;;IAeMC,sBAAsB;eAAtBA;;IA4BNC,SAAS;eAATA;;IAeAC,YAAY;eAAZA;;;uBAtPI;oBACW;wBACA;sBAEE;AAK1B,MAAMP,oBAAoBQ,IAAAA,aAAO,EACtCC,IAAAA,aAAO,EACL,mDAAmD;AACnDC,QAAQF,OAAO,CAAC,sCAElB;AAGK,MAAMP,oBAAoB;IAC/BU,QAAQD,QAAQF,OAAO,CAAC;IACxBI,QAAQF,QAAQF,OAAO,CAAC;IACxBK,SAASH,QAAQF,OAAO,CAAC;IACzBM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W,CAACC,sBAAc,CAACX,GAAG,CAAC,CAACY,OAAS;gBAACA;gBAAM;aAAM;IACtE;IAEA,OAAOH,OAAOC,WAAW,CACvBC,sBAAc,CAACX,GAAG,CAAC,CAACY,OAAS;YAC3BA;YACAJ,SAAS,CAACI,KAAkD,GACxD7E,iBAAiB,CAAC6E,KAAuC,GACzD;SACL;AAEL"}
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,8 +1,37 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
1
2
|
import yargs from 'yargs';
|
|
2
3
|
import { hideBin } from 'yargs/helpers';
|
|
3
4
|
import builders from './builders';
|
|
4
5
|
import { getConfigByArgv } from './config';
|
|
5
6
|
import { error, getYargsErrorMessage, sanitizeInputs } from './utils';
|
|
7
|
+
const MINIMUM_NODE_16_VERSION = '16.17.0';
|
|
8
|
+
const MINIMUM_NODE_18_VERSION = '18.6.0';
|
|
9
|
+
/**
|
|
10
|
+
* Check the Node version. If the Node version is less than the minimum required
|
|
11
|
+
* version, this logs an error and exits the process.
|
|
12
|
+
*
|
|
13
|
+
* @param nodeVersion - The Node version to check.
|
|
14
|
+
*/ export function checkNodeVersion(nodeVersion = process.version.slice(1)) {
|
|
15
|
+
const majorVersion = semver.major(nodeVersion);
|
|
16
|
+
const message = `Node version ${nodeVersion} is not supported. Please use Node ${MINIMUM_NODE_16_VERSION} or later.`;
|
|
17
|
+
if (majorVersion < 16) {
|
|
18
|
+
error(message);
|
|
19
|
+
// eslint-disable-next-line n/no-process-exit
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
// Node 16 and 18 have a different minimum version requirement, so we need to
|
|
23
|
+
// check for both.
|
|
24
|
+
if (majorVersion === 16 && semver.lt(nodeVersion, MINIMUM_NODE_16_VERSION)) {
|
|
25
|
+
error(message);
|
|
26
|
+
// eslint-disable-next-line n/no-process-exit
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
if (majorVersion === 18 && semver.lt(nodeVersion, MINIMUM_NODE_18_VERSION)) {
|
|
30
|
+
error(`Node version ${nodeVersion} is not supported. Please use Node ${MINIMUM_NODE_18_VERSION} or later.`);
|
|
31
|
+
// eslint-disable-next-line n/no-process-exit
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
6
35
|
/**
|
|
7
36
|
* The main CLI entry point function. This processes the command line args, and
|
|
8
37
|
* runs the appropriate function.
|
|
@@ -10,6 +39,7 @@ import { error, getYargsErrorMessage, sanitizeInputs } from './utils';
|
|
|
10
39
|
* @param argv - The raw command line arguments, i.e., `process.argv`.
|
|
11
40
|
* @param commands - The list of commands to use.
|
|
12
41
|
*/ export async function cli(argv, commands) {
|
|
42
|
+
checkNodeVersion();
|
|
13
43
|
await yargs(hideBin(argv)).scriptName('mm-snap').usage('Usage: $0 <command> [options]').example('$0 build', `Build './src/index.js' as './dist/bundle.js'`).example('$0 build --config ./snap.config.build.ts', `Build './src/index.js' as './dist/bundle.js' using the config in './snap.config.build.ts'`).example('$0 manifest --fix', `Check the snap manifest, and fix any errors`).example('$0 watch --port 8000', `The snap input file for changes, and serve it on port 8000`).example('$0 serve --port 8000', `Serve the snap bundle on port 8000`).command(commands).option('config', builders.config).option('verboseErrors', builders.verboseErrors).option('suppressWarnings', builders.suppressWarnings).strict().middleware(async (args)=>{
|
|
14
44
|
// eslint-disable-next-line require-atomic-updates
|
|
15
45
|
args.context = {
|
package/dist/esm/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\n\nimport builders from './builders';\nimport { getConfigByArgv } from './config';\nimport { error, getYargsErrorMessage, sanitizeInputs } from './utils';\n\n/**\n * The main CLI entry point function. This processes the command line args, and\n * runs the appropriate function.\n *\n * @param argv - The raw command line arguments, i.e., `process.argv`.\n * @param commands - The list of commands to use.\n */\nexport async function cli(argv: string[], commands: any) {\n await yargs(hideBin(argv))\n .scriptName('mm-snap')\n .usage('Usage: $0 <command> [options]')\n\n .example('$0 build', `Build './src/index.js' as './dist/bundle.js'`)\n .example(\n '$0 build --config ./snap.config.build.ts',\n `Build './src/index.js' as './dist/bundle.js' using the config in './snap.config.build.ts'`,\n )\n .example('$0 manifest --fix', `Check the snap manifest, and fix any errors`)\n .example(\n '$0 watch --port 8000',\n `The snap input file for changes, and serve it on port 8000`,\n )\n .example('$0 serve --port 8000', `Serve the snap bundle on port 8000`)\n\n .command(commands)\n\n .option('config', builders.config)\n .option('verboseErrors', builders.verboseErrors)\n .option('suppressWarnings', builders.suppressWarnings)\n\n .strict()\n\n .middleware(async (args: any) => {\n // eslint-disable-next-line require-atomic-updates\n args.context = {\n config: await getConfigByArgv(args),\n };\n\n sanitizeInputs(args);\n }, false)\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .fail((message, failure) => {\n error(getYargsErrorMessage(message, failure));\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n })\n\n .help()\n .alias('help', 'h')\n .parseAsync();\n}\n"],"names":["yargs","hideBin","builders","getConfigByArgv","error","getYargsErrorMessage","sanitizeInputs","cli","argv","commands","scriptName","usage","example","command","option","config","verboseErrors","suppressWarnings","strict","middleware","args","context","demandCommand","fail","
|
|
1
|
+
{"version":3,"sources":["../../src/cli.ts"],"sourcesContent":["import semver from 'semver';\nimport yargs from 'yargs';\nimport { hideBin } from 'yargs/helpers';\n\nimport builders from './builders';\nimport { getConfigByArgv } from './config';\nimport { error, getYargsErrorMessage, sanitizeInputs } from './utils';\n\nconst MINIMUM_NODE_16_VERSION = '16.17.0';\nconst MINIMUM_NODE_18_VERSION = '18.6.0';\n\n/**\n * Check the Node version. If the Node version is less than the minimum required\n * version, this logs an error and exits the process.\n *\n * @param nodeVersion - The Node version to check.\n */\nexport function checkNodeVersion(\n nodeVersion: string = process.version.slice(1),\n) {\n const majorVersion = semver.major(nodeVersion);\n const message = `Node version ${nodeVersion} is not supported. Please use Node ${MINIMUM_NODE_16_VERSION} or later.`;\n\n if (majorVersion < 16) {\n error(message);\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n\n // Node 16 and 18 have a different minimum version requirement, so we need to\n // check for both.\n if (majorVersion === 16 && semver.lt(nodeVersion, MINIMUM_NODE_16_VERSION)) {\n error(message);\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n\n if (majorVersion === 18 && semver.lt(nodeVersion, MINIMUM_NODE_18_VERSION)) {\n error(\n `Node version ${nodeVersion} is not supported. Please use Node ${MINIMUM_NODE_18_VERSION} or later.`,\n );\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n }\n}\n\n/**\n * The main CLI entry point function. This processes the command line args, and\n * runs the appropriate function.\n *\n * @param argv - The raw command line arguments, i.e., `process.argv`.\n * @param commands - The list of commands to use.\n */\nexport async function cli(argv: string[], commands: any) {\n checkNodeVersion();\n\n await yargs(hideBin(argv))\n .scriptName('mm-snap')\n .usage('Usage: $0 <command> [options]')\n\n .example('$0 build', `Build './src/index.js' as './dist/bundle.js'`)\n .example(\n '$0 build --config ./snap.config.build.ts',\n `Build './src/index.js' as './dist/bundle.js' using the config in './snap.config.build.ts'`,\n )\n .example('$0 manifest --fix', `Check the snap manifest, and fix any errors`)\n .example(\n '$0 watch --port 8000',\n `The snap input file for changes, and serve it on port 8000`,\n )\n .example('$0 serve --port 8000', `Serve the snap bundle on port 8000`)\n\n .command(commands)\n\n .option('config', builders.config)\n .option('verboseErrors', builders.verboseErrors)\n .option('suppressWarnings', builders.suppressWarnings)\n\n .strict()\n\n .middleware(async (args: any) => {\n // eslint-disable-next-line require-atomic-updates\n args.context = {\n config: await getConfigByArgv(args),\n };\n\n sanitizeInputs(args);\n }, false)\n\n .demandCommand(1, 'You must specify at least one command.')\n\n .fail((message, failure) => {\n error(getYargsErrorMessage(message, failure));\n // eslint-disable-next-line n/no-process-exit\n process.exit(1);\n })\n\n .help()\n .alias('help', 'h')\n .parseAsync();\n}\n"],"names":["semver","yargs","hideBin","builders","getConfigByArgv","error","getYargsErrorMessage","sanitizeInputs","MINIMUM_NODE_16_VERSION","MINIMUM_NODE_18_VERSION","checkNodeVersion","nodeVersion","process","version","slice","majorVersion","major","message","exit","lt","cli","argv","commands","scriptName","usage","example","command","option","config","verboseErrors","suppressWarnings","strict","middleware","args","context","demandCommand","fail","failure","help","alias","parseAsync"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,OAAOC,WAAW,QAAQ;AAC1B,SAASC,OAAO,QAAQ,gBAAgB;AAExC,OAAOC,cAAc,aAAa;AAClC,SAASC,eAAe,QAAQ,WAAW;AAC3C,SAASC,KAAK,EAAEC,oBAAoB,EAAEC,cAAc,QAAQ,UAAU;AAEtE,MAAMC,0BAA0B;AAChC,MAAMC,0BAA0B;AAEhC;;;;;CAKC,GACD,OAAO,SAASC,iBACdC,cAAsBC,QAAQC,OAAO,CAACC,KAAK,CAAC,EAAE;IAE9C,MAAMC,eAAef,OAAOgB,KAAK,CAACL;IAClC,MAAMM,UAAU,CAAC,aAAa,EAAEN,YAAY,mCAAmC,EAAEH,wBAAwB,UAAU,CAAC;IAEpH,IAAIO,eAAe,IAAI;QACrBV,MAAMY;QACN,6CAA6C;QAC7CL,QAAQM,IAAI,CAAC;IACf;IAEA,6EAA6E;IAC7E,kBAAkB;IAClB,IAAIH,iBAAiB,MAAMf,OAAOmB,EAAE,CAACR,aAAaH,0BAA0B;QAC1EH,MAAMY;QACN,6CAA6C;QAC7CL,QAAQM,IAAI,CAAC;IACf;IAEA,IAAIH,iBAAiB,MAAMf,OAAOmB,EAAE,CAACR,aAAaF,0BAA0B;QAC1EJ,MACE,CAAC,aAAa,EAAEM,YAAY,mCAAmC,EAAEF,wBAAwB,UAAU,CAAC;QAEtG,6CAA6C;QAC7CG,QAAQM,IAAI,CAAC;IACf;AACF;AAEA;;;;;;CAMC,GACD,OAAO,eAAeE,IAAIC,IAAc,EAAEC,QAAa;IACrDZ;IAEA,MAAMT,MAAMC,QAAQmB,OACjBE,UAAU,CAAC,WACXC,KAAK,CAAC,iCAENC,OAAO,CAAC,YAAY,CAAC,4CAA4C,CAAC,EAClEA,OAAO,CACN,4CACA,CAAC,yFAAyF,CAAC,EAE5FA,OAAO,CAAC,qBAAqB,CAAC,2CAA2C,CAAC,EAC1EA,OAAO,CACN,wBACA,CAAC,0DAA0D,CAAC,EAE7DA,OAAO,CAAC,wBAAwB,CAAC,kCAAkC,CAAC,EAEpEC,OAAO,CAACJ,UAERK,MAAM,CAAC,UAAUxB,SAASyB,MAAM,EAChCD,MAAM,CAAC,iBAAiBxB,SAAS0B,aAAa,EAC9CF,MAAM,CAAC,oBAAoBxB,SAAS2B,gBAAgB,EAEpDC,MAAM,GAENC,UAAU,CAAC,OAAOC;QACjB,kDAAkD;QAClDA,KAAKC,OAAO,GAAG;YACbN,QAAQ,MAAMxB,gBAAgB6B;QAChC;QAEA1B,eAAe0B;IACjB,GAAG,OAEFE,aAAa,CAAC,GAAG,0CAEjBC,IAAI,CAAC,CAACnB,SAASoB;QACdhC,MAAMC,qBAAqBW,SAASoB;QACpC,6CAA6C;QAC7CzB,QAAQM,IAAI,CAAC;IACf,GAECoB,IAAI,GACJC,KAAK,CAAC,QAAQ,KACdC,UAAU;AACf"}
|
|
@@ -115,6 +115,17 @@ import { BROWSERSLIST_FILE, getDefaultLoader, getDevTool, getFallbacks, getProgr
|
|
|
115
115
|
exclude: /node_modules/u,
|
|
116
116
|
use: await getDefaultLoader(config)
|
|
117
117
|
},
|
|
118
|
+
/**
|
|
119
|
+
* This allows importing modules that uses `.js` and not `.mjs` for the
|
|
120
|
+
* ES build.
|
|
121
|
+
*
|
|
122
|
+
* @see https://webpack.js.org/configuration/module/#resolvefullyspecified
|
|
123
|
+
*/ {
|
|
124
|
+
test: /\.m?js/u,
|
|
125
|
+
resolve: {
|
|
126
|
+
fullySpecified: false
|
|
127
|
+
}
|
|
128
|
+
},
|
|
118
129
|
config.experimental.wasm && {
|
|
119
130
|
test: /\.wasm$/u,
|
|
120
131
|
use: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/webpack/config.ts"],"sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { EnvironmentPlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getFallbacks,\n getProgressHandler,\n} from './utils';\n\nexport type WebpackOptions = {\n /**\n * Whether to watch for changes.\n */\n watch?: boolean;\n\n /**\n * Whether to evaluate the bundle. If this is set, it will override the\n * `evaluate` option in the config object.\n */\n evaluate?: boolean;\n\n /**\n * The spinner to use for logging.\n */\n spinner?: Ora;\n};\n\n/**\n * Get the default Webpack configuration. This is the configuration that will\n * be used if the user doesn't provide a custom Webpack configuration. The\n * configuration is based on the snap config.\n *\n * The default configuration includes:\n *\n * - `SWC` to transpile TypeScript and JavaScript files.\n * - `TerserPlugin` to minify the bundle.\n * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.\n *\n * It can be customized through the `customizeWebpackConfig` function in the\n * snap config, but in most cases, you shouldn't need to do that.\n *\n * @param config - The processed snap Webpack config.\n * @param options - The Webpack options.\n * @returns The default Webpack configuration.\n */\nexport async function getDefaultConfiguration(\n config: ProcessedWebpackConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns &&\n new SnapsBuiltInResolver(config.stats.builtIns, options.spinner);\n\n return {\n /**\n * The target is set to `browserslist` so that Webpack will compile the\n * bundle to support the browsers specified in the `.browserslistrc` file.\n * This Browserslist file contains the browsers that are supported by\n * MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/target/\n */\n target: `browserslist:${BROWSERSLIST_FILE}`,\n\n /**\n * The mode is set to `production` by default, so that Webpack will minify\n * and optimize the bundle.\n *\n * @see https://webpack.js.org/configuration/mode/\n */\n mode: 'production',\n\n /**\n * The entry point is set to the `input` value from the config object.\n *\n * @see https://webpack.js.org/configuration/entry-context/\n */\n entry: config.input,\n\n /**\n * The devtool option controls how source maps are generated. We set it to\n * the `sourceMap` value from the config object.\n *\n * @see https://webpack.js.org/configuration/devtool/\n */\n devtool: getDevTool(config.sourceMap),\n\n /**\n * The stats option controls how much information is printed to the console\n * when Webpack is running. We set it to `none` so that we can control the\n * output ourselves.\n *\n * @see https://webpack.js.org/configuration/stats/\n */\n stats: 'none',\n\n /**\n * The output options.\n *\n * @see https://webpack.js.org/configuration/output/\n */\n output: {\n /**\n * This indicates whether Webpack should clear the output directory\n * before building. We set it to the `clean` value from the config\n * object.\n *\n * @see https://webpack.js.org/configuration/output/#outputclean\n */\n clean: config.output.clean,\n\n /**\n * The filename of the bundle. We set it to the `filename` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputfilename\n */\n filename: config.output.filename,\n\n /**\n * The path to the output directory. We set it to the `path` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputpath\n */\n path: config.output.path,\n\n /**\n * The public path of the bundle. We set it to `/` by default, so that\n * the bundle can be loaded from the root of the server.\n *\n * @see https://webpack.js.org/configuration/output/#outputpublicpath\n */\n publicPath: '/',\n\n /**\n * The library configuration. This tells Webpack how to export the\n * bundle.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrary\n */\n library: {\n /**\n * This tells Webpack to export the bundle as a CommonJS module. This\n * is necessary for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'commonjs',\n },\n },\n\n /**\n * The module configuration. This is where we tell Webpack how to handle\n * different types of files.\n *\n * @see https://webpack.js.org/configuration/module/\n */\n module: {\n rules: [\n {\n test: /\\.[tj]sx?$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: {\n loader: resolve(__dirname, 'loaders', 'wasm'),\n },\n },\n ],\n },\n\n /**\n * The resolve configuration. This tells Webpack how to resolve imports.\n * We set it to resolve `.js` and `.ts` files.\n *\n * @see https://webpack.js.org/configuration/resolve/\n */\n resolve: {\n /**\n * The extensions to resolve. We set it to resolve `.js` and `.ts`\n * files.\n */\n extensions: ['.js', '.ts'],\n\n /**\n * The fallback options. This tells Webpack how to handle imports that\n * aren't resolved. By default, we set Node.js built-ins to `false`, so\n * that they are ignored.\n */\n fallback: getFallbacks(config.polyfills),\n\n /**\n * The plugins to use. We use the {@link SnapsBuiltInResolver} to show\n * warnings about using Node.js built-ins, when no fallback is specified.\n */\n plugins: [builtInResolver],\n },\n\n /**\n * The plugins to use.\n *\n * @see https://webpack.js.org/configuration/plugins/\n */\n plugins: [\n /**\n * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates\n * the manifest file, and evaluates the bundle in SES. While not strictly\n * required, it's highly recommended to use this plugin.\n */\n new SnapsWebpackPlugin({\n manifestPath: config.manifest.path,\n writeManifest: config.manifest.update,\n eval: !options.watch && options.evaluate,\n }),\n\n /**\n * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats\n * output. It's used to show the stats in the terminal, in a format that\n * is easy to read.\n */\n new SnapsStatsPlugin({ verbose: config.stats.verbose }, options.spinner),\n\n /**\n * The `EnvironmentPlugin` is a Webpack plugin that adds environment\n * variables to the bundle. We use it to add the `NODE_ENV` and `DEBUG`\n * environment variables.\n */\n new EnvironmentPlugin(config.environment),\n\n /**\n * The `ProgressPlugin` is a Webpack plugin that logs the progress of\n * the build. We set it to log the progress to the spinner.\n */\n new ProgressPlugin({\n handler: getProgressHandler(options.spinner, spinnerText),\n }),\n\n /**\n * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a\n * warning when the bundle is potentially incompatible with MetaMask\n * Snaps.\n */\n new SnapsBundleWarningsPlugin(\n {\n builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\n },\n options.spinner,\n ),\n\n /**\n * The `WatchPlugin` is a Webpack plugin that adds extra files to watch\n * for changes. This is useful for rebuilding the bundle when the\n * manifest file changes.\n */\n options.watch &&\n new SnapsWatchPlugin(\n {\n bundle: resolve(config.output.path, config.output.filename),\n evaluate: options.evaluate,\n files: [config.manifest.path],\n },\n options.spinner,\n ),\n\n /**\n * The `ProviderPlugin` is a Webpack plugin that automatically load\n * modules instead of having to import or require them everywhere.\n */\n (config.polyfills === true ||\n (config.polyfills !== false && config.polyfills.buffer)) &&\n new ProvidePlugin({\n Buffer: ['buffer', 'Buffer'],\n }),\n ].filter(Boolean),\n\n /**\n * The optimization configuration. This tells Webpack how to optimize the\n * bundle. Most of the time, you won't need to change this, as the default\n * options set by the `mode` option are sufficient.\n */\n optimization: {\n minimize: config.output.minimize,\n\n /**\n * The minimizer to use. We set it to use the `TerserPlugin`.\n */\n minimizer: [\n new TerserPlugin({\n parallel: true,\n }),\n ],\n },\n\n /**\n * The infrastructure logging configuration. This tells Webpack how to\n * log messages.\n *\n * @see https://webpack.js.org/configuration/infrastructure-logging\n */\n infrastructureLogging: {\n /**\n * The level of logging to use. We set it to `none`, so that we can\n * control the output ourselves.\n */\n level: 'none',\n },\n };\n}\n"],"names":["SnapsWebpackPlugin","resolve","TerserPlugin","EnvironmentPlugin","ProgressPlugin","ProvidePlugin","SnapsBuiltInResolver","SnapsBundleWarningsPlugin","SnapsStatsPlugin","SnapsWatchPlugin","BROWSERSLIST_FILE","getDefaultLoader","getDevTool","getFallbacks","getProgressHandler","getDefaultConfiguration","config","options","evaluate","spinnerText","spinner","text","builtInResolver","stats","builtIns","target","mode","entry","input","devtool","sourceMap","output","clean","filename","path","publicPath","library","type","module","rules","test","exclude","use","experimental","wasm","loader","__dirname","extensions","fallback","polyfills","plugins","manifestPath","manifest","writeManifest","update","eval","watch","verbose","environment","handler","Boolean","buffer","bundle","files","Buffer","filter","optimization","minimize","minimizer","parallel","infrastructureLogging","level"],"mappings":"AAAA,OAAOA,wBAAwB,iCAAiC;AAEhE,SAASC,OAAO,QAAQ,OAAO;AAC/B,OAAOC,kBAAkB,wBAAwB;AAEjD,SAASC,iBAAiB,EAAEC,cAAc,EAAEC,aAAa,QAAQ,UAAU;AAG3E,SACEC,oBAAoB,EACpBC,yBAAyB,EACzBC,gBAAgB,EAChBC,gBAAgB,QACX,YAAY;AACnB,SACEC,iBAAiB,EACjBC,gBAAgB,EAChBC,UAAU,EACVC,YAAY,EACZC,kBAAkB,QACb,UAAU;AAoBjB;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,eAAeC,wBACpBC,MAA8B,EAC9BC,UAA0B;IACxBC,UAAUF,OAAOE,QAAQ;AAC3B,CAAC;IAED,MAAMC,cAAcF,QAAQG,OAAO,EAAEC;IACrC,MAAMC,kBACJN,OAAOO,KAAK,CAACC,QAAQ,IACrB,IAAIlB,qBAAqBU,OAAOO,KAAK,CAACC,QAAQ,EAAEP,QAAQG,OAAO;IAEjE,OAAO;QACL;;;;;;;KAOC,GACDK,QAAQ,CAAC,aAAa,EAAEf,kBAAkB,CAAC;QAE3C;;;;;KAKC,GACDgB,MAAM;QAEN;;;;KAIC,GACDC,OAAOX,OAAOY,KAAK;QAEnB;;;;;KAKC,GACDC,SAASjB,WAAWI,OAAOc,SAAS;QAEpC;;;;;;KAMC,GACDP,OAAO;QAEP;;;;KAIC,GACDQ,QAAQ;YACN;;;;;;OAMC,GACDC,OAAOhB,OAAOe,MAAM,CAACC,KAAK;YAE1B;;;;;OAKC,GACDC,UAAUjB,OAAOe,MAAM,CAACE,QAAQ;YAEhC;;;;;OAKC,GACDC,MAAMlB,OAAOe,MAAM,CAACG,IAAI;YAExB;;;;;OAKC,GACDC,YAAY;YAEZ;;;;;OAKC,GACDC,SAAS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,CAACE,QAAQ;gBAC1Df,UAAUD,QAAQC,QAAQ;gBAC1B6C,OAAO;oBAAC/C,OAAOoC,QAAQ,CAAClB,IAAI;iBAAC;YAC/B,GACAjB,QAAQG,OAAO;YAGnB;;;OAGC,GACAJ,CAAAA,OAAOiC,SAAS,KAAK,QACnBjC,OAAOiC,SAAS,KAAK,SAASjC,OAAOiC,SAAS,CAACY,MAAM,KACtD,IAAIxD,cAAc;gBAChB2D,QAAQ;oBAAC;oBAAU;iBAAS;YAC9B;SACH,CAACC,MAAM,CAACL;QAET;;;;KAIC,GACDM,cAAc;YACZC,UAAUnD,OAAOe,MAAM,CAACoC,QAAQ;YAEhC;;OAEC,GACDC,WAAW;gBACT,IAAIlE,aAAa;oBACfmE,UAAU;gBACZ;aACD;QACH;QAEA;;;;;KAKC,GACDC,uBAAuB;YACrB;;;OAGC,GACDC,OAAO;QACT;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/webpack/config.ts"],"sourcesContent":["import SnapsWebpackPlugin from '@metamask/snaps-webpack-plugin';\nimport type { Ora } from 'ora';\nimport { resolve } from 'path';\nimport TerserPlugin from 'terser-webpack-plugin';\nimport type { Configuration } from 'webpack';\nimport { EnvironmentPlugin, ProgressPlugin, ProvidePlugin } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\nimport {\n SnapsBuiltInResolver,\n SnapsBundleWarningsPlugin,\n SnapsStatsPlugin,\n SnapsWatchPlugin,\n} from './plugins';\nimport {\n BROWSERSLIST_FILE,\n getDefaultLoader,\n getDevTool,\n getFallbacks,\n getProgressHandler,\n} from './utils';\n\nexport type WebpackOptions = {\n /**\n * Whether to watch for changes.\n */\n watch?: boolean;\n\n /**\n * Whether to evaluate the bundle. If this is set, it will override the\n * `evaluate` option in the config object.\n */\n evaluate?: boolean;\n\n /**\n * The spinner to use for logging.\n */\n spinner?: Ora;\n};\n\n/**\n * Get the default Webpack configuration. This is the configuration that will\n * be used if the user doesn't provide a custom Webpack configuration. The\n * configuration is based on the snap config.\n *\n * The default configuration includes:\n *\n * - `SWC` to transpile TypeScript and JavaScript files.\n * - `TerserPlugin` to minify the bundle.\n * - `SnapsWebpackPlugin` to validate the bundle and update the manifest.\n *\n * It can be customized through the `customizeWebpackConfig` function in the\n * snap config, but in most cases, you shouldn't need to do that.\n *\n * @param config - The processed snap Webpack config.\n * @param options - The Webpack options.\n * @returns The default Webpack configuration.\n */\nexport async function getDefaultConfiguration(\n config: ProcessedWebpackConfig,\n options: WebpackOptions = {\n evaluate: config.evaluate,\n },\n): Promise<Configuration> {\n const spinnerText = options.spinner?.text;\n const builtInResolver =\n config.stats.builtIns &&\n new SnapsBuiltInResolver(config.stats.builtIns, options.spinner);\n\n return {\n /**\n * The target is set to `browserslist` so that Webpack will compile the\n * bundle to support the browsers specified in the `.browserslistrc` file.\n * This Browserslist file contains the browsers that are supported by\n * MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/target/\n */\n target: `browserslist:${BROWSERSLIST_FILE}`,\n\n /**\n * The mode is set to `production` by default, so that Webpack will minify\n * and optimize the bundle.\n *\n * @see https://webpack.js.org/configuration/mode/\n */\n mode: 'production',\n\n /**\n * The entry point is set to the `input` value from the config object.\n *\n * @see https://webpack.js.org/configuration/entry-context/\n */\n entry: config.input,\n\n /**\n * The devtool option controls how source maps are generated. We set it to\n * the `sourceMap` value from the config object.\n *\n * @see https://webpack.js.org/configuration/devtool/\n */\n devtool: getDevTool(config.sourceMap),\n\n /**\n * The stats option controls how much information is printed to the console\n * when Webpack is running. We set it to `none` so that we can control the\n * output ourselves.\n *\n * @see https://webpack.js.org/configuration/stats/\n */\n stats: 'none',\n\n /**\n * The output options.\n *\n * @see https://webpack.js.org/configuration/output/\n */\n output: {\n /**\n * This indicates whether Webpack should clear the output directory\n * before building. We set it to the `clean` value from the config\n * object.\n *\n * @see https://webpack.js.org/configuration/output/#outputclean\n */\n clean: config.output.clean,\n\n /**\n * The filename of the bundle. We set it to the `filename` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputfilename\n */\n filename: config.output.filename,\n\n /**\n * The path to the output directory. We set it to the `path` value from\n * the config object.\n *\n * @see https://webpack.js.org/configuration/output/#outputpath\n */\n path: config.output.path,\n\n /**\n * The public path of the bundle. We set it to `/` by default, so that\n * the bundle can be loaded from the root of the server.\n *\n * @see https://webpack.js.org/configuration/output/#outputpublicpath\n */\n publicPath: '/',\n\n /**\n * The library configuration. This tells Webpack how to export the\n * bundle.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrary\n */\n library: {\n /**\n * This tells Webpack to export the bundle as a CommonJS module. This\n * is necessary for MetaMask Snaps.\n *\n * @see https://webpack.js.org/configuration/output/#outputlibrarytarget\n */\n type: 'commonjs',\n },\n },\n\n /**\n * The module configuration. This is where we tell Webpack how to handle\n * different types of files.\n *\n * @see https://webpack.js.org/configuration/module/\n */\n module: {\n rules: [\n {\n test: /\\.[tj]sx?$/u,\n exclude: /node_modules/u,\n use: await getDefaultLoader(config),\n },\n\n /**\n * This allows importing modules that uses `.js` and not `.mjs` for the\n * ES build.\n *\n * @see https://webpack.js.org/configuration/module/#resolvefullyspecified\n */\n {\n test: /\\.m?js/u,\n resolve: {\n fullySpecified: false,\n },\n },\n\n config.experimental.wasm && {\n test: /\\.wasm$/u,\n use: {\n loader: resolve(__dirname, 'loaders', 'wasm'),\n },\n },\n ],\n },\n\n /**\n * The resolve configuration. This tells Webpack how to resolve imports.\n * We set it to resolve `.js` and `.ts` files.\n *\n * @see https://webpack.js.org/configuration/resolve/\n */\n resolve: {\n /**\n * The extensions to resolve. We set it to resolve `.js` and `.ts`\n * files.\n */\n extensions: ['.js', '.ts'],\n\n /**\n * The fallback options. This tells Webpack how to handle imports that\n * aren't resolved. By default, we set Node.js built-ins to `false`, so\n * that they are ignored.\n */\n fallback: getFallbacks(config.polyfills),\n\n /**\n * The plugins to use. We use the {@link SnapsBuiltInResolver} to show\n * warnings about using Node.js built-ins, when no fallback is specified.\n */\n plugins: [builtInResolver],\n },\n\n /**\n * The plugins to use.\n *\n * @see https://webpack.js.org/configuration/plugins/\n */\n plugins: [\n /**\n * The `SnapsWebpackPlugin` is a Webpack plugin that checks and updates\n * the manifest file, and evaluates the bundle in SES. While not strictly\n * required, it's highly recommended to use this plugin.\n */\n new SnapsWebpackPlugin({\n manifestPath: config.manifest.path,\n writeManifest: config.manifest.update,\n eval: !options.watch && options.evaluate,\n }),\n\n /**\n * The `SnapsStatsPlugin` is a Webpack plugin that handles the stats\n * output. It's used to show the stats in the terminal, in a format that\n * is easy to read.\n */\n new SnapsStatsPlugin({ verbose: config.stats.verbose }, options.spinner),\n\n /**\n * The `EnvironmentPlugin` is a Webpack plugin that adds environment\n * variables to the bundle. We use it to add the `NODE_ENV` and `DEBUG`\n * environment variables.\n */\n new EnvironmentPlugin(config.environment),\n\n /**\n * The `ProgressPlugin` is a Webpack plugin that logs the progress of\n * the build. We set it to log the progress to the spinner.\n */\n new ProgressPlugin({\n handler: getProgressHandler(options.spinner, spinnerText),\n }),\n\n /**\n * The `SnapsBundleWarningPlugin` is a Webpack plugin that shows a\n * warning when the bundle is potentially incompatible with MetaMask\n * Snaps.\n */\n new SnapsBundleWarningsPlugin(\n {\n builtInResolver,\n builtIns: Boolean(config.stats.builtIns),\n buffer: config.stats.buffer,\n },\n options.spinner,\n ),\n\n /**\n * The `WatchPlugin` is a Webpack plugin that adds extra files to watch\n * for changes. This is useful for rebuilding the bundle when the\n * manifest file changes.\n */\n options.watch &&\n new SnapsWatchPlugin(\n {\n bundle: resolve(config.output.path, config.output.filename),\n evaluate: options.evaluate,\n files: [config.manifest.path],\n },\n options.spinner,\n ),\n\n /**\n * The `ProviderPlugin` is a Webpack plugin that automatically load\n * modules instead of having to import or require them everywhere.\n */\n (config.polyfills === true ||\n (config.polyfills !== false && config.polyfills.buffer)) &&\n new ProvidePlugin({\n Buffer: ['buffer', 'Buffer'],\n }),\n ].filter(Boolean),\n\n /**\n * The optimization configuration. This tells Webpack how to optimize the\n * bundle. Most of the time, you won't need to change this, as the default\n * options set by the `mode` option are sufficient.\n */\n optimization: {\n minimize: config.output.minimize,\n\n /**\n * The minimizer to use. We set it to use the `TerserPlugin`.\n */\n minimizer: [\n new TerserPlugin({\n parallel: true,\n }),\n ],\n },\n\n /**\n * The infrastructure logging configuration. This tells Webpack how to\n * log messages.\n *\n * @see https://webpack.js.org/configuration/infrastructure-logging\n */\n infrastructureLogging: {\n /**\n * The level of logging to use. We set it to `none`, so that we can\n * control the output ourselves.\n */\n level: 'none',\n },\n };\n}\n"],"names":["SnapsWebpackPlugin","resolve","TerserPlugin","EnvironmentPlugin","ProgressPlugin","ProvidePlugin","SnapsBuiltInResolver","SnapsBundleWarningsPlugin","SnapsStatsPlugin","SnapsWatchPlugin","BROWSERSLIST_FILE","getDefaultLoader","getDevTool","getFallbacks","getProgressHandler","getDefaultConfiguration","config","options","evaluate","spinnerText","spinner","text","builtInResolver","stats","builtIns","target","mode","entry","input","devtool","sourceMap","output","clean","filename","path","publicPath","library","type","module","rules","test","exclude","use","fullySpecified","experimental","wasm","loader","__dirname","extensions","fallback","polyfills","plugins","manifestPath","manifest","writeManifest","update","eval","watch","verbose","environment","handler","Boolean","buffer","bundle","files","Buffer","filter","optimization","minimize","minimizer","parallel","infrastructureLogging","level"],"mappings":"AAAA,OAAOA,wBAAwB,iCAAiC;AAEhE,SAASC,OAAO,QAAQ,OAAO;AAC/B,OAAOC,kBAAkB,wBAAwB;AAEjD,SAASC,iBAAiB,EAAEC,cAAc,EAAEC,aAAa,QAAQ,UAAU;AAG3E,SACEC,oBAAoB,EACpBC,yBAAyB,EACzBC,gBAAgB,EAChBC,gBAAgB,QACX,YAAY;AACnB,SACEC,iBAAiB,EACjBC,gBAAgB,EAChBC,UAAU,EACVC,YAAY,EACZC,kBAAkB,QACb,UAAU;AAoBjB;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,eAAeC,wBACpBC,MAA8B,EAC9BC,UAA0B;IACxBC,UAAUF,OAAOE,QAAQ;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QAEA;;;;;KAKC,GACDC,uBAAuB;YACrB;;;OAGC,GACDC,OAAO;QACT;IACF;AACF"}
|
|
@@ -70,7 +70,7 @@ export const WEBPACK_FALLBACKS = {
|
|
|
70
70
|
* We use the `swc-loader` to transpile TypeScript and JavaScript files.
|
|
71
71
|
* This is a Webpack loader that uses the `SWC` compiler, which is a much
|
|
72
72
|
* faster alternative to Babel and TypeScript's own compiler.
|
|
73
|
-
*/ loader: 'swc-loader',
|
|
73
|
+
*/ loader: require.resolve('swc-loader'),
|
|
74
74
|
/**
|
|
75
75
|
* The options for the `swc-loader`. These can be overridden in the
|
|
76
76
|
* `.swcrc` file.
|
|
@@ -1 +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":"AAAA,SAASA,GAAG,QAAQ,QAAQ;AAC5B,SAASC,YAAYC,EAAE,QAAQ,KAAK;AACpC,SAASC,cAAc,QAAQ,SAAS;AAExC,SAASC,OAAO,EAAEC,OAAO,QAAQ,OAAO;AAKxC,OAAO,MAAMC,oBAAoBD,QAC/BD,QACE,mDAAmD;AACnDG,QAAQF,OAAO,CAAC,sCAElB,mBACA;AAEF,OAAO,MAAMG,oBAAoB;IAC/BC,QAAQF,QAAQF,OAAO,CAAC;IACxBK,QAAQH,QAAQF,OAAO,CAAC;IACxBM,SAASJ,QAAQF,OAAO,CAAC;IACzBO,WAAWL,QAAQF,OAAO,CAAC;IAC3BQ,QAAQN,QAAQF,OAAO,CAAC;IACxBS,QAAQP,QAAQF,OAAO,CAAC;IACxBU,QAAQR,QAAQF,OAAO,CAAC;IACxBW,MAAMT,QAAQF,OAAO,CAAC;IACtBY,OAAOV,QAAQF,OAAO,CAAC;IACvBa,IAAIX,QAAQF,OAAO,CAAC;IACpBc,MAAMZ,QAAQF,OAAO,CAAC;IACtBe,UAAUb,QAAQF,OAAO,CAAC;IAC1BgB,SAASd,QAAQF,OAAO,CAAC;IACzBiB,aAAaf,QAAQF,OAAO,CAAC;IAC7BkB,QAAQhB,QAAQF,OAAO,CAAC;IACxB,wDAAwD,GACxDmB,gBAAgBjB,QAAQF,OAAO,CAAC;IAChCoB,qBAAqBlB,QAAQF,OAAO,CAClC;IAEFqB,kBAAkBnB,QAAQF,OAAO,CAAC;IAClCsB,mBAAmBpB,QAAQF,OAAO,CAAC;IACnCuB,kBAAkBrB,QAAQF,OAAO,CAAC;IAClCwB,gBAAgBtB,QAAQF,OAAO,CAAC;IAChC,uDAAuD,GACvDyB,KAAKvB,QAAQF,OAAO,CAAC;IACrB0B,QAAQxB,Q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O,eAAef;IACpB,MAAMmB,WAAW,MAAM7D,GAAG8D,QAAQ,CAAC1D,mBAAmB;IACtD,OAAOyD,SACJE,KAAK,CAAC,MACNC,GAAG,CAAC,CAACC,OAASA,KAAKC,IAAI,IACvBC,MAAM,CAAC,CAACF,OAASA,QAAQ,CAACA,KAAKG,UAAU,CAAC;AAC/C;AAEA;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,SAASC,UACdC,KAAa,EACbC,QAAgB,EAChBC,SAAS,CAAC,EAAED,SAAS,CAAC,CAAC;IAEvB,OAAOD,UAAU,IAAIC,WAAWC;AAClC;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,aAAaC,SAA8C;IAGzE,IAAIA,cAAc,MAAM;QACtB,OAAOC,OAAOC,WAAW,CACvB3E,eAAe+D,GAAG,CAAC,CAACa,OAAS;gBAC3BA;gBACAvE,iBAAiB,CAACuE,KAAuC,IAAI;aAC9D;IAEL;IAEA,IAAIH,cAAc,OAAO;QACvB,OAAOC,OAAOC,WAAW,CAAC3E,eAAe+D,GAAG,CAAC,CAACa,OAAS;gBAACA;gBAAM;aAAM;IACtE;IAEA,OAAOF,OAAOC,WAAW,CACvB3E,eAAe+D,GAAG,CAAC,CAACa,OAAS;YAC3BA;YACAH,SAAS,CAACG,KAAkD,GACxDvE,iBAAiB,CAACuE,KAAuC,GACzD;SACL;AAEL"}
|
|
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: require.resolve('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":"AAAA,SAASA,GAAG,QAAQ,QAAQ;AAC5B,SAASC,YAAYC,EAAE,QAAQ,KAAK;AACpC,SAASC,cAAc,QAAQ,SAAS;AAExC,SAASC,OAAO,EAAEC,OAAO,QAAQ,OAAO;AAKxC,OAAO,MAAMC,oBAAoBD,QAC/BD,QACE,mDAAmD;AACnDG,QAAQF,OAAO,CAAC,sCAElB,mBACA;AAEF,OAAO,MAAMG,oBAAoB;IAC/BC,QAAQF,QAAQF,OAAO,CAAC;IACxBK,QAAQH,QAAQF,OAAO,CAAC;IACxBM,SAASJ,QAAQF,OAAO,CAAC;IACzBO,WAAWL,QAAQF,OAAO,CAAC;IAC3BQ,QAAQN,QAAQF,OAAO,CAAC;IACxBS,QAAQP,QAAQF,OAAO,CAAC;IACxBU,QAAQR,QAAQF,OAAO,CAAC;IACxBW,MAAMT,QAAQF,OAAO,CAAC;IACtBY,OAAOV,QAAQF,OAAO,CAAC;IACvBa,IAAIX,QAAQF,OAAO,CAAC;IACpBc,MAAMZ,QAAQF,OAAO,CAAC;IACtBe,UAAUb,QAAQF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;YACAH,SAAS,CAACG,KAAkD,GACxDvE,iBAAiB,CAACuE,KAAuC,GACzD;SACL;AAEL"}
|
package/dist/types/cli.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check the Node version. If the Node version is less than the minimum required
|
|
3
|
+
* version, this logs an error and exits the process.
|
|
4
|
+
*
|
|
5
|
+
* @param nodeVersion - The Node version to check.
|
|
6
|
+
*/
|
|
7
|
+
export declare function checkNodeVersion(nodeVersion?: string): void;
|
|
1
8
|
/**
|
|
2
9
|
* The main CLI entry point function. This processes the command line args, and
|
|
3
10
|
* runs the appropriate function.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"@babel/plugin-transform-runtime": "^7.16.7",
|
|
56
56
|
"@babel/preset-env": "^7.20.12",
|
|
57
57
|
"@babel/preset-typescript": "^7.20.12",
|
|
58
|
-
"@metamask/snaps-utils": "^2.0.
|
|
59
|
-
"@metamask/snaps-webpack-plugin": "^2.0.
|
|
58
|
+
"@metamask/snaps-utils": "^2.0.1",
|
|
59
|
+
"@metamask/snaps-webpack-plugin": "^2.0.1",
|
|
60
60
|
"@metamask/utils": "^8.1.0",
|
|
61
61
|
"@swc/core": "1.3.78",
|
|
62
62
|
"assert": "^2.0.0",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"punycode": "^2.3.0",
|
|
80
80
|
"querystring-es3": "^0.2.1",
|
|
81
81
|
"readable-stream": "^3.6.2",
|
|
82
|
+
"semver": "^7.5.4",
|
|
82
83
|
"serve-handler": "^6.1.5",
|
|
83
84
|
"stream-browserify": "^3.0.0",
|
|
84
85
|
"stream-http": "^3.2.0",
|
|
@@ -96,7 +97,7 @@
|
|
|
96
97
|
"yargs": "^17.7.1"
|
|
97
98
|
},
|
|
98
99
|
"devDependencies": {
|
|
99
|
-
"@lavamoat/allow-scripts": "^2.
|
|
100
|
+
"@lavamoat/allow-scripts": "^2.5.1",
|
|
100
101
|
"@metamask/auto-changelog": "^3.1.0",
|
|
101
102
|
"@metamask/eslint-config": "^12.1.0",
|
|
102
103
|
"@metamask/eslint-config-jest": "^12.1.0",
|