@metamask/snaps-cli 0.38.1-flask.1 → 0.38.2-flask.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -1
- package/dist/cjs/config.js +33 -0
- package/dist/cjs/config.js.map +1 -1
- package/dist/cjs/webpack/config.js +11 -6
- package/dist/cjs/webpack/config.js.map +1 -1
- package/dist/cjs/webpack/plugins.js +2 -2
- package/dist/cjs/webpack/plugins.js.map +1 -1
- package/dist/cjs/webpack/utils.js +55 -7
- package/dist/cjs/webpack/utils.js.map +1 -1
- package/dist/esm/config.js +33 -0
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/webpack/config.js +13 -8
- package/dist/esm/webpack/config.js.map +1 -1
- package/dist/esm/webpack/plugins.js +2 -2
- package/dist/esm/webpack/plugins.js.map +1 -1
- package/dist/esm/webpack/utils.js +55 -7
- package/dist/esm/webpack/utils.js.map +1 -1
- package/dist/types/config.d.ts +166 -0
- package/dist/types/webpack/utils.d.ts +40 -8
- package/package.json +35 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/webpack/utils.ts"],"sourcesContent":["import { dim } from 'chalk';\nimport { promises as fs } from 'fs';\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\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 /**\n * MetaMask targets ES2020, so we set the target to ES2020. This\n * ensures that the code is transpiled to ES2020, and that the\n * necessary polyfills are added.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctarget\n */\n target: 'es2020',\n\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"],"names":["dim","promises","fs","dirname","resolve","BROWSERSLIST_FILE","require","getDefaultLoader","legacy","sourceMap","loader","__dirname","options","targets","getBrowserslistTargets","sync","sourceMaps","Boolean","getDevTool","jsc","target","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"],"mappings":"AAAA,SAASA,GAAG,QAAQ,QAAQ;AAC5B,SAASC,YAAYC,EAAE,QAAQ,KAAK;AAEpC,SAASC,OAAO,EAAEC,OAAO,QAAQ,OAAO;AAKxC,OAAO,MAAMC,oBAAoBD,QAC/BD,QACE,mDAAmD;AACnDG,QAAQF,OAAO,CAAC,sCAElB,mBACA;AAEF;;;;;;;;;;;;;;;CAeC,GACD,OAAO,eAAeG,iBAAiB,EACrCC,MAAM,EACNC,SAAS,EACc;IACvB,IAAID,QAAQ;QACV,OAAO;YACL;;;;;OAKC,GACDE,QAAQN,QAAQO,WAAW,WAAW;YAEtC;;;OAGC,GACDC,SAASJ;QACX;IACF;IAEA,MAAMK,UAAU,MAAMC;IACtB,OAAO;QACL;;;;KAIC,GACDJ,QAAQ;QAER;;;;;KAKC,GACDE,SAAS;YACPG,MAAM;YAEN;;;;;OAKC,GACDC,YAAYC,QAAQC,WAAWT;YAE/BU,KAAK;gBACH;;;;;;SAMC,GACDC,QAAQ;gBAERC,QAAQ;oBACN;;;;;;;WAOC,GACDC,QAAQ;gBACV;YACF;YAEA;;;;;OAKC,GACDC,QAAQ;gBACN;;;;;SAKC,GACDC,MAAM;YACR;YAEAC,KAAK;gBACHZ,SAASA,QAAQa,IAAI,CAAC;YACxB;QACF;IACF;AACF;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASR,WACdT,SAA8C;IAE9C,IAAIA,cAAc,UAAU;QAC1B,OAAO;IACT;IAEA,IAAIA,cAAc,MAAM;QACtB,OAAO;IACT;IAEA,OAAO;AACT;AAEA;;;;;;;;;CASC,GACD,gDAAgD;AAChD,OAAO,SAASkB,mBAAmBC,OAAa,EAAEC,WAAoB;IACpE,OAAO,CAACC;QACN,IAAIF,WAAWC,aAAa;YAC1BD,QAAQG,IAAI,GAAG,CAAC,EAAEF,YAAY,CAAC,EAAE7B,IAC/B,CAAC,CAAC,EAAEgC,KAAKC,KAAK,CAACH,aAAa,KAAK,EAAE,CAAC,EACpC,CAAC;QACL;IACF;AACF;AAEA;;;;CAIC,GACD,OAAO,eAAehB;IACpB,MAAMoB,WAAW,MAAMhC,GAAGiC,QAAQ,CAAC9B,mBAAmB;IACtD,OAAO6B,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"}
|
|
1
|
+
{"version":3,"sources":["../../../src/webpack/utils.ts"],"sourcesContent":["import { dim } from 'chalk';\nimport { promises as fs } from 'fs';\nimport { builtinModules } from 'module';\nimport type { Ora } from 'ora';\nimport { dirname, resolve } from 'path';\nimport type { Configuration } from 'webpack';\n\nimport type { ProcessedWebpackConfig } from '../config';\n\nexport const BROWSERSLIST_FILE = resolve(\n dirname(\n // eslint-disable-next-line n/no-extraneous-require\n require.resolve('@metamask/snaps-cli/package.json'),\n ),\n '.browserslistrc',\n);\n\nexport const WEBPACK_FALLBACKS = {\n assert: require.resolve('assert/'),\n buffer: require.resolve('buffer/'),\n console: require.resolve('console-browserify'),\n constants: require.resolve('constants-browserify'),\n crypto: require.resolve('crypto-browserify'),\n domain: require.resolve('domain-browser'),\n events: require.resolve('events/'),\n http: require.resolve('stream-http'),\n https: require.resolve('https-browserify'),\n os: require.resolve('os-browserify/browser'),\n path: require.resolve('path-browserify'),\n punycode: require.resolve('punycode/'),\n process: require.resolve('process/browser'),\n querystring: require.resolve('querystring-es3'),\n stream: require.resolve('stream-browserify'),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),\n _stream_passthrough: require.resolve(\n 'readable-stream/lib/_stream_passthrough',\n ),\n _stream_readable: require.resolve('readable-stream/lib/_stream_readable'),\n _stream_transform: require.resolve('readable-stream/lib/_stream_transform'),\n _stream_writable: require.resolve('readable-stream/lib/_stream_writable'),\n string_decoder: require.resolve('string_decoder/'),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: require.resolve('util/'),\n timers: require.resolve('timers-browserify'),\n tty: require.resolve('tty-browserify'),\n url: require.resolve('url/'),\n util: require.resolve('util/'),\n vm: require.resolve('vm-browserify'),\n zlib: require.resolve('browserify-zlib'),\n};\n\n/**\n * Get the default loader for JavaScript and TypeScript files, based on the\n * config object.\n *\n * - If the `legacy` option is set, we use the custom `browserify` loader. This\n * uses the legacy Browserify config to transpile the code.\n * - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the\n * `SWC` compiler, which is a much faster alternative to Babel and TypeScript's\n * own compiler.\n *\n * @param config - The processed snap Webpack config.\n * @param config.legacy - The legacy config object, if any.\n * @param config.sourceMap - Whether to generate source maps.\n * @see https://swc.rs/docs/usage/swc-loader\n * @returns The default loader.\n */\nexport async function getDefaultLoader({\n legacy,\n sourceMap,\n}: ProcessedWebpackConfig) {\n if (legacy) {\n return {\n /**\n * If the snap uses the legacy config, we use the custom `browserify`\n * loader. This uses the legacy Browserify config to transpile the code.\n * This is necessary for backwards compatibility with the\n * `bundlerCustomizer` function.\n */\n loader: resolve(__dirname, 'loaders', 'browserify'),\n\n /**\n * The options for the `browserify` loader. These can be overridden in the\n * snap config.\n */\n options: legacy,\n };\n }\n\n const targets = await getBrowserslistTargets();\n return {\n /**\n * We use the `swc-loader` to transpile TypeScript and JavaScript files.\n * This is a Webpack loader that uses the `SWC` compiler, which is a much\n * faster alternative to Babel and TypeScript's own compiler.\n */\n loader: 'swc-loader',\n\n /**\n * The options for the `swc-loader`. These can be overridden in the\n * `.swcrc` file.\n *\n * @see https://swc.rs/docs/configuration/swcrc\n */\n options: {\n sync: false,\n\n /**\n * This tells SWC to generate source maps. We set it to the\n * `sourceMap` value from the config object.\n *\n * This must be enabled if source maps are enabled in the config.\n */\n sourceMaps: Boolean(getDevTool(sourceMap)),\n\n jsc: {\n parser: {\n /**\n * This tells the parser to parse TypeScript files. If you\n * don't need to support TypeScript, you can set this to\n * `ecmascript` instead, but there's no harm in leaving it\n * as `typescript`.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n */\n syntax: 'typescript',\n },\n },\n\n /**\n * The module configuration. This tells SWC how to output the\n * transpiled code.\n *\n * @see https://swc.rs/docs/configuration/modules\n */\n module: {\n /**\n * This tells SWC to output CommonJS modules. MetaMask Snaps\n * doesn't support ES modules yet, so this is necessary.\n *\n * @see https://swc.rs/docs/configuration/modules#commonjs\n */\n type: 'commonjs',\n },\n\n env: {\n targets: targets.join(', '),\n },\n },\n };\n}\n\n/**\n * Get the Webpack devtool configuration based on the given snap config.\n *\n * - If `sourceMap` is `inline`, return `inline-source-map`.\n * - If `sourceMap` is `true`, return `source-map`.\n * - Otherwise, return `false`.\n *\n * @param sourceMap - The `sourceMap` value from the snap config.\n * @returns The Webpack devtool configuration.\n */\nexport function getDevTool(\n sourceMap: ProcessedWebpackConfig['sourceMap'],\n): Configuration['devtool'] {\n if (sourceMap === 'inline') {\n return 'inline-source-map';\n }\n\n if (sourceMap === true) {\n return 'source-map';\n }\n\n return false;\n}\n\n/**\n * Get a function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n *\n * @param spinner - The spinner to update.\n * @param spinnerText - The initial spinner text. This will be prepended to the\n * percentage.\n * @returns A function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n */\n// Note: This is extracted for testing purposes.\nexport function getProgressHandler(spinner?: Ora, spinnerText?: string) {\n return (percentage: number) => {\n if (spinner && spinnerText) {\n spinner.text = `${spinnerText} ${dim(\n `(${Math.round(percentage * 100)}%)`,\n )}`;\n }\n };\n}\n\n/**\n * Get the targets from the `.browserslistrc` file.\n *\n * @returns The browser targets as an array of strings.\n */\nexport async function getBrowserslistTargets() {\n const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');\n return contents\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line && !line.startsWith('#'));\n}\n\n/**\n * Get a singular or plural string based on the given count. This is useful for\n * generating messages like \"1 error\" or \"2 errors\". By default, the plural\n * string is the singular string with an \"s\" appended to it.\n *\n * This assumes that the text is in English, and likely won't work for some\n * other languages.\n *\n * @param count - The count.\n * @param singular - The singular string.\n * @param plural - The plural string.\n * @returns The singular or plural string.\n * @example\n * ```typescript\n * pluralize(1, 'error'); // => 'error'\n * pluralize(2, 'error'); // => 'errors'\n * pluralize(1, 'error', 'problem'); // => 'error'\n * pluralize(2, 'error', 'problems'); // => 'problems'\n * ```\n */\nexport function pluralize(\n count: number,\n singular: string,\n plural = `${singular}s`,\n) {\n return count === 1 ? singular : plural;\n}\n\n/**\n * Get an object that can be used as fallback config for Webpack's\n * `fallback` config.\n *\n * @param polyfills - The polyfill object from the snap config.\n * @returns The webpack fallback config.\n */\nexport function getFallbacks(polyfills: ProcessedWebpackConfig['polyfills']): {\n [index: string]: string | false;\n} {\n if (polyfills === true) {\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS] ?? false,\n ]),\n );\n }\n\n if (polyfills === false) {\n return Object.fromEntries(builtinModules.map((name) => [name, false]));\n }\n\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n polyfills[name as keyof ProcessedWebpackConfig['polyfills']]\n ? WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS]\n : false,\n ]),\n );\n}\n"],"names":["dim","promises","fs","builtinModules","dirname","resolve","BROWSERSLIST_FILE","require","WEBPACK_FALLBACKS","assert","buffer","console","constants","crypto","domain","events","http","https","os","path","punycode","process","querystring","stream","_stream_duplex","_stream_passthrough","_stream_readable","_stream_transform","_stream_writable","string_decoder","sys","timers","tty","url","util","vm","zlib","getDefaultLoader","legacy","sourceMap","loader","__dirname","options","targets","getBrowserslistTargets","sync","sourceMaps","Boolean","getDevTool","jsc","parser","syntax","module","type","env","join","getProgressHandler","spinner","spinnerText","percentage","text","Math","round","contents","readFile","split","map","line","trim","filter","startsWith","pluralize","count","singular","plural","getFallbacks","polyfills","Object","fromEntries","name"],"mappings":"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"}
|
package/dist/types/config.d.ts
CHANGED
|
@@ -288,6 +288,54 @@ export declare type SnapWebpackConfig = {
|
|
|
288
288
|
*/
|
|
289
289
|
buffer?: boolean;
|
|
290
290
|
};
|
|
291
|
+
/**
|
|
292
|
+
* Whether to provide polyfills for node builtins. If `true`, all the available
|
|
293
|
+
* polyfills will be provided. If `false` no polyfills will be provided. If a
|
|
294
|
+
* configuration object is passed only the polyfills set to `true` will be provided.
|
|
295
|
+
*
|
|
296
|
+
* @default false
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* polyfills: true
|
|
300
|
+
*
|
|
301
|
+
* // or
|
|
302
|
+
*
|
|
303
|
+
* polyfills: {
|
|
304
|
+
* assert: true,
|
|
305
|
+
* buffer: true
|
|
306
|
+
* }
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
polyfills?: boolean | {
|
|
310
|
+
assert?: boolean;
|
|
311
|
+
buffer?: boolean;
|
|
312
|
+
console?: boolean;
|
|
313
|
+
constants?: boolean;
|
|
314
|
+
crypto?: boolean;
|
|
315
|
+
domain?: boolean;
|
|
316
|
+
events?: boolean;
|
|
317
|
+
http?: boolean;
|
|
318
|
+
https?: boolean;
|
|
319
|
+
os?: boolean;
|
|
320
|
+
path?: boolean;
|
|
321
|
+
punycode?: boolean;
|
|
322
|
+
process?: boolean;
|
|
323
|
+
querystring?: boolean;
|
|
324
|
+
stream?: boolean;
|
|
325
|
+
_stream_duplex?: boolean;
|
|
326
|
+
_stream_passthrough?: boolean;
|
|
327
|
+
_stream_readable?: boolean;
|
|
328
|
+
_stream_transform?: boolean;
|
|
329
|
+
_stream_writable?: boolean;
|
|
330
|
+
string_decoder?: boolean;
|
|
331
|
+
sys?: boolean;
|
|
332
|
+
timers?: boolean;
|
|
333
|
+
tty?: boolean;
|
|
334
|
+
url?: boolean;
|
|
335
|
+
util?: boolean;
|
|
336
|
+
vm?: boolean;
|
|
337
|
+
zlib?: boolean;
|
|
338
|
+
};
|
|
291
339
|
/**
|
|
292
340
|
* A function to customize the Webpack configuration used to build the snap.
|
|
293
341
|
* This function will be called with the default Webpack configuration, and
|
|
@@ -432,6 +480,36 @@ export declare const SnapsWebpackConfigStruct: import("superstruct").Struct<{
|
|
|
432
480
|
ignore: string[];
|
|
433
481
|
};
|
|
434
482
|
};
|
|
483
|
+
polyfills: boolean | {
|
|
484
|
+
path: boolean;
|
|
485
|
+
assert: boolean;
|
|
486
|
+
buffer: boolean;
|
|
487
|
+
stream: boolean;
|
|
488
|
+
http: boolean;
|
|
489
|
+
zlib: boolean;
|
|
490
|
+
url: boolean;
|
|
491
|
+
https: boolean;
|
|
492
|
+
console: boolean;
|
|
493
|
+
constants: boolean;
|
|
494
|
+
crypto: boolean;
|
|
495
|
+
domain: boolean;
|
|
496
|
+
events: boolean;
|
|
497
|
+
os: boolean;
|
|
498
|
+
punycode: boolean;
|
|
499
|
+
process: boolean;
|
|
500
|
+
querystring: boolean;
|
|
501
|
+
_stream_duplex: boolean;
|
|
502
|
+
_stream_passthrough: boolean;
|
|
503
|
+
_stream_readable: boolean;
|
|
504
|
+
_stream_transform: boolean;
|
|
505
|
+
_stream_writable: boolean;
|
|
506
|
+
string_decoder: boolean;
|
|
507
|
+
sys: boolean;
|
|
508
|
+
timers: boolean;
|
|
509
|
+
tty: boolean;
|
|
510
|
+
util: boolean;
|
|
511
|
+
vm: boolean;
|
|
512
|
+
};
|
|
435
513
|
experimental: {
|
|
436
514
|
wasm: boolean;
|
|
437
515
|
};
|
|
@@ -486,6 +564,94 @@ export declare const SnapsWebpackConfigStruct: import("superstruct").Struct<{
|
|
|
486
564
|
}>, import("superstruct").Struct<false, null>]>;
|
|
487
565
|
buffer: import("superstruct").Struct<boolean, null>;
|
|
488
566
|
}>;
|
|
567
|
+
polyfills: import("superstruct").Struct<boolean | {
|
|
568
|
+
path: boolean;
|
|
569
|
+
assert: boolean;
|
|
570
|
+
buffer: boolean;
|
|
571
|
+
stream: boolean;
|
|
572
|
+
http: boolean;
|
|
573
|
+
zlib: boolean;
|
|
574
|
+
url: boolean;
|
|
575
|
+
https: boolean;
|
|
576
|
+
console: boolean;
|
|
577
|
+
constants: boolean;
|
|
578
|
+
crypto: boolean;
|
|
579
|
+
domain: boolean;
|
|
580
|
+
events: boolean;
|
|
581
|
+
os: boolean;
|
|
582
|
+
punycode: boolean;
|
|
583
|
+
process: boolean;
|
|
584
|
+
querystring: boolean;
|
|
585
|
+
_stream_duplex: boolean;
|
|
586
|
+
_stream_passthrough: boolean;
|
|
587
|
+
_stream_readable: boolean;
|
|
588
|
+
_stream_transform: boolean;
|
|
589
|
+
_stream_writable: boolean;
|
|
590
|
+
string_decoder: boolean;
|
|
591
|
+
sys: boolean;
|
|
592
|
+
timers: boolean;
|
|
593
|
+
tty: boolean;
|
|
594
|
+
util: boolean;
|
|
595
|
+
vm: boolean;
|
|
596
|
+
}, [import("superstruct").Struct<boolean, null>, import("superstruct").Struct<{
|
|
597
|
+
path: boolean;
|
|
598
|
+
assert: boolean;
|
|
599
|
+
buffer: boolean;
|
|
600
|
+
stream: boolean;
|
|
601
|
+
http: boolean;
|
|
602
|
+
zlib: boolean;
|
|
603
|
+
url: boolean;
|
|
604
|
+
https: boolean;
|
|
605
|
+
console: boolean;
|
|
606
|
+
constants: boolean;
|
|
607
|
+
crypto: boolean;
|
|
608
|
+
domain: boolean;
|
|
609
|
+
events: boolean;
|
|
610
|
+
os: boolean;
|
|
611
|
+
punycode: boolean;
|
|
612
|
+
process: boolean;
|
|
613
|
+
querystring: boolean;
|
|
614
|
+
_stream_duplex: boolean;
|
|
615
|
+
_stream_passthrough: boolean;
|
|
616
|
+
_stream_readable: boolean;
|
|
617
|
+
_stream_transform: boolean;
|
|
618
|
+
_stream_writable: boolean;
|
|
619
|
+
string_decoder: boolean;
|
|
620
|
+
sys: boolean;
|
|
621
|
+
timers: boolean;
|
|
622
|
+
tty: boolean;
|
|
623
|
+
util: boolean;
|
|
624
|
+
vm: boolean;
|
|
625
|
+
}, {
|
|
626
|
+
assert: import("superstruct").Struct<boolean, null>;
|
|
627
|
+
buffer: import("superstruct").Struct<boolean, null>;
|
|
628
|
+
console: import("superstruct").Struct<boolean, null>;
|
|
629
|
+
constants: import("superstruct").Struct<boolean, null>;
|
|
630
|
+
crypto: import("superstruct").Struct<boolean, null>;
|
|
631
|
+
domain: import("superstruct").Struct<boolean, null>;
|
|
632
|
+
events: import("superstruct").Struct<boolean, null>;
|
|
633
|
+
http: import("superstruct").Struct<boolean, null>;
|
|
634
|
+
https: import("superstruct").Struct<boolean, null>;
|
|
635
|
+
os: import("superstruct").Struct<boolean, null>;
|
|
636
|
+
path: import("superstruct").Struct<boolean, null>;
|
|
637
|
+
punycode: import("superstruct").Struct<boolean, null>;
|
|
638
|
+
process: import("superstruct").Struct<boolean, null>;
|
|
639
|
+
querystring: import("superstruct").Struct<boolean, null>;
|
|
640
|
+
stream: import("superstruct").Struct<boolean, null>;
|
|
641
|
+
_stream_duplex: import("superstruct").Struct<boolean, null>;
|
|
642
|
+
_stream_passthrough: import("superstruct").Struct<boolean, null>;
|
|
643
|
+
_stream_readable: import("superstruct").Struct<boolean, null>;
|
|
644
|
+
_stream_transform: import("superstruct").Struct<boolean, null>;
|
|
645
|
+
_stream_writable: import("superstruct").Struct<boolean, null>;
|
|
646
|
+
string_decoder: import("superstruct").Struct<boolean, null>;
|
|
647
|
+
sys: import("superstruct").Struct<boolean, null>;
|
|
648
|
+
timers: import("superstruct").Struct<boolean, null>;
|
|
649
|
+
tty: import("superstruct").Struct<boolean, null>;
|
|
650
|
+
url: import("superstruct").Struct<boolean, null>;
|
|
651
|
+
util: import("superstruct").Struct<boolean, null>;
|
|
652
|
+
vm: import("superstruct").Struct<boolean, null>;
|
|
653
|
+
zlib: import("superstruct").Struct<boolean, null>;
|
|
654
|
+
}>]>;
|
|
489
655
|
customizeWebpackConfig: import("superstruct").Struct<SnapsWebpackCustomizeWebpackConfigFunction | undefined, null>;
|
|
490
656
|
experimental: import("superstruct").Struct<{
|
|
491
657
|
wasm: boolean;
|
|
@@ -3,6 +3,36 @@ import type { Ora } from 'ora';
|
|
|
3
3
|
import type { Configuration } from 'webpack';
|
|
4
4
|
import type { ProcessedWebpackConfig } from '../config';
|
|
5
5
|
export declare const BROWSERSLIST_FILE: string;
|
|
6
|
+
export declare const WEBPACK_FALLBACKS: {
|
|
7
|
+
assert: string;
|
|
8
|
+
buffer: string;
|
|
9
|
+
console: string;
|
|
10
|
+
constants: string;
|
|
11
|
+
crypto: string;
|
|
12
|
+
domain: string;
|
|
13
|
+
events: string;
|
|
14
|
+
http: string;
|
|
15
|
+
https: string;
|
|
16
|
+
os: string;
|
|
17
|
+
path: string;
|
|
18
|
+
punycode: string;
|
|
19
|
+
process: string;
|
|
20
|
+
querystring: string;
|
|
21
|
+
stream: string;
|
|
22
|
+
_stream_duplex: string;
|
|
23
|
+
_stream_passthrough: string;
|
|
24
|
+
_stream_readable: string;
|
|
25
|
+
_stream_transform: string;
|
|
26
|
+
_stream_writable: string;
|
|
27
|
+
string_decoder: string;
|
|
28
|
+
sys: string;
|
|
29
|
+
timers: string;
|
|
30
|
+
tty: string;
|
|
31
|
+
url: string;
|
|
32
|
+
util: string;
|
|
33
|
+
vm: string;
|
|
34
|
+
zlib: string;
|
|
35
|
+
};
|
|
6
36
|
/**
|
|
7
37
|
* Get the default loader for JavaScript and TypeScript files, based on the
|
|
8
38
|
* config object.
|
|
@@ -65,14 +95,6 @@ export declare function getDefaultLoader({ legacy, sourceMap, }: ProcessedWebpac
|
|
|
65
95
|
*/
|
|
66
96
|
sourceMaps: boolean;
|
|
67
97
|
jsc: {
|
|
68
|
-
/**
|
|
69
|
-
* MetaMask targets ES2020, so we set the target to ES2020. This
|
|
70
|
-
* ensures that the code is transpiled to ES2020, and that the
|
|
71
|
-
* necessary polyfills are added.
|
|
72
|
-
*
|
|
73
|
-
* @see https://swc.rs/docs/configuration/compilation#jsctarget
|
|
74
|
-
*/
|
|
75
|
-
target: string;
|
|
76
98
|
parser: {
|
|
77
99
|
/**
|
|
78
100
|
* This tells the parser to parse TypeScript files. If you
|
|
@@ -154,3 +176,13 @@ export declare function getBrowserslistTargets(): Promise<string[]>;
|
|
|
154
176
|
* ```
|
|
155
177
|
*/
|
|
156
178
|
export declare function pluralize(count: number, singular: string, plural?: string): string;
|
|
179
|
+
/**
|
|
180
|
+
* Get an object that can be used as fallback config for Webpack's
|
|
181
|
+
* `fallback` config.
|
|
182
|
+
*
|
|
183
|
+
* @param polyfills - The polyfill object from the snap config.
|
|
184
|
+
* @returns The webpack fallback config.
|
|
185
|
+
*/
|
|
186
|
+
export declare function getFallbacks(polyfills: ProcessedWebpackConfig['polyfills']): {
|
|
187
|
+
[index: string]: string | false;
|
|
188
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.2-flask.1",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,11 +39,12 @@
|
|
|
39
39
|
"lint:changelog": "../../scripts/validate-changelog.sh @metamask/snaps-cli",
|
|
40
40
|
"lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
|
|
41
41
|
"lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ../../.gitignore",
|
|
42
|
-
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog",
|
|
42
|
+
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog && yarn lint:dependencies",
|
|
43
43
|
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
|
|
44
44
|
"prepare-manifest:preview": "../../scripts/prepare-preview-manifest.sh",
|
|
45
45
|
"publish:preview": "yarn npm publish --tag preview",
|
|
46
|
-
"lint:ci": "yarn lint"
|
|
46
|
+
"lint:ci": "yarn lint",
|
|
47
|
+
"lint:dependencies": "depcheck"
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
49
50
|
"@babel/core": "^7.20.12",
|
|
@@ -54,27 +55,45 @@
|
|
|
54
55
|
"@babel/plugin-transform-runtime": "^7.16.7",
|
|
55
56
|
"@babel/preset-env": "^7.20.12",
|
|
56
57
|
"@babel/preset-typescript": "^7.20.12",
|
|
57
|
-
"@metamask/snaps-
|
|
58
|
-
"@metamask/snaps-utils": "^0.38.0-flask.1",
|
|
58
|
+
"@metamask/snaps-utils": "^0.38.1-flask.1",
|
|
59
59
|
"@metamask/snaps-webpack-plugin": "^0.37.2-flask.1",
|
|
60
60
|
"@metamask/utils": "^6.0.1",
|
|
61
|
-
"@swc/core": "
|
|
61
|
+
"@swc/core": "1.3.78",
|
|
62
|
+
"assert": "^2.0.0",
|
|
62
63
|
"babelify": "^10.0.0",
|
|
63
64
|
"browserify": "^17.0.0",
|
|
65
|
+
"browserify-zlib": "^0.2.0",
|
|
66
|
+
"buffer": "^6.0.3",
|
|
64
67
|
"chalk": "^4.1.2",
|
|
65
68
|
"chokidar": "^3.5.2",
|
|
66
|
-
"
|
|
69
|
+
"console-browserify": "^1.2.0",
|
|
70
|
+
"constants-browserify": "^1.0.0",
|
|
71
|
+
"crypto-browserify": "^3.12.0",
|
|
72
|
+
"domain-browser": "^4.22.0",
|
|
73
|
+
"events": "^3.3.0",
|
|
74
|
+
"https-browserify": "^1.0.0",
|
|
67
75
|
"ora": "^5.4.1",
|
|
76
|
+
"os-browserify": "^0.3.0",
|
|
77
|
+
"path-browserify": "^1.0.1",
|
|
78
|
+
"process": "^0.11.10",
|
|
79
|
+
"punycode": "^2.3.0",
|
|
80
|
+
"querystring-es3": "^0.2.1",
|
|
81
|
+
"readable-stream": "^3.6.2",
|
|
68
82
|
"serve-handler": "^6.1.5",
|
|
69
|
-
"
|
|
83
|
+
"stream-browserify": "^3.0.0",
|
|
84
|
+
"stream-http": "^3.2.0",
|
|
85
|
+
"string_decoder": "^1.3.0",
|
|
70
86
|
"superstruct": "^1.0.3",
|
|
71
87
|
"swc-loader": "^0.2.3",
|
|
72
88
|
"terser-webpack-plugin": "^5.3.9",
|
|
89
|
+
"timers-browserify": "^2.0.12",
|
|
90
|
+
"tty-browserify": "^0.0.1",
|
|
91
|
+
"url": "^0.11.1",
|
|
92
|
+
"util": "^0.12.5",
|
|
93
|
+
"vm-browserify": "^1.1.2",
|
|
73
94
|
"webpack": "^5.88.0",
|
|
74
|
-
"webpack-dev-server": "^4.15.1",
|
|
75
95
|
"webpack-merge": "^5.9.0",
|
|
76
|
-
"yargs": "^17.7.1"
|
|
77
|
-
"yargs-parser": "^20.2.2"
|
|
96
|
+
"yargs": "^17.7.1"
|
|
78
97
|
},
|
|
79
98
|
"devDependencies": {
|
|
80
99
|
"@lavamoat/allow-scripts": "^2.3.1",
|
|
@@ -86,7 +105,6 @@
|
|
|
86
105
|
"@swc/cli": "^0.1.62",
|
|
87
106
|
"@swc/jest": "^0.2.26",
|
|
88
107
|
"@types/browserify": "^12.0.37",
|
|
89
|
-
"@types/is-url": "^1.2.28",
|
|
90
108
|
"@types/jest": "^27.5.1",
|
|
91
109
|
"@types/node": "^20.3.1",
|
|
92
110
|
"@types/rimraf": "^3.0.0",
|
|
@@ -94,9 +112,9 @@
|
|
|
94
112
|
"@types/yargs": "^17.0.24",
|
|
95
113
|
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
96
114
|
"@typescript-eslint/parser": "^5.42.1",
|
|
97
|
-
"babel-jest": "^29.5.0",
|
|
98
115
|
"cross-fetch": "^3.1.5",
|
|
99
116
|
"deepmerge": "^4.2.2",
|
|
117
|
+
"depcheck": "^1.4.5",
|
|
100
118
|
"eslint": "^8.27.0",
|
|
101
119
|
"eslint-config-prettier": "^8.5.0",
|
|
102
120
|
"eslint-plugin-import": "^2.26.0",
|
|
@@ -125,7 +143,10 @@
|
|
|
125
143
|
},
|
|
126
144
|
"lavamoat": {
|
|
127
145
|
"allowScripts": {
|
|
128
|
-
"@lavamoat/preinstall-always-fail": false
|
|
146
|
+
"@lavamoat/preinstall-always-fail": false,
|
|
147
|
+
"@metamask/snaps-utils>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>keccak": false,
|
|
148
|
+
"@metamask/snaps-utils>@metamask/permission-controller>@metamask/controller-utils>ethereumjs-util>ethereum-cryptography>secp256k1": false,
|
|
149
|
+
"@swc/core": false
|
|
129
150
|
}
|
|
130
151
|
}
|
|
131
152
|
}
|