@metamask/snaps-cli 3.0.2 → 3.0.3

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 CHANGED
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [3.0.3]
10
+ ### Changed
11
+ - Bump several MetaMask dependencies ([#1964](https://github.com/MetaMask/snaps/pull/1964))
12
+
13
+ ### Fixed
14
+ - Fix issues generating checksum with binary auxiliary files ([#1975](https://github.com/MetaMask/snaps/pull/1975))
15
+
9
16
  ## [3.0.2]
10
17
  ### Changed
11
18
  - Use `@metamask/snaps-sdk` package ([#1951](https://github.com/MetaMask/snaps/pull/1951))
@@ -71,7 +78,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
71
78
  - The version of the package no longer needs to match the version of all other
72
79
  MetaMask Snaps packages.
73
80
 
74
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.2...HEAD
81
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.3...HEAD
82
+ [3.0.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.2...@metamask/snaps-cli@3.0.3
75
83
  [3.0.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.1...@metamask/snaps-cli@3.0.2
76
84
  [3.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@3.0.0...@metamask/snaps-cli@3.0.1
77
85
  [3.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@2.0.2...@metamask/snaps-cli@3.0.0
@@ -40,6 +40,7 @@ _export(exports, {
40
40
  return getWebpackConfig;
41
41
  }
42
42
  });
43
+ const _snapssdk = require("@metamask/snaps-sdk");
43
44
  const _snapsutils = require("@metamask/snaps-utils");
44
45
  const _utils = require("@metamask/utils");
45
46
  const _core = require("@swc/core");
@@ -65,7 +66,7 @@ const CONFIG_FILES = [
65
66
  // type definitions.
66
67
  const SnapsBrowserifyBundlerCustomizerFunctionStruct = (0, _superstruct.define)('function', (0, _superstruct.func)().validator);
67
68
  const SnapsBrowserifyConfigStruct = (0, _superstruct.object)({
68
- bundler: (0, _superstruct.defaulted)((0, _snapsutils.literal)('browserify'), 'browserify'),
69
+ bundler: (0, _superstruct.defaulted)((0, _snapssdk.literal)('browserify'), 'browserify'),
69
70
  cliOptions: (0, _superstruct.defaulted)((0, _superstruct.object)({
70
71
  bundle: (0, _superstruct.optional)((0, _snapsutils.file)()),
71
72
  dist: (0, _superstruct.defaulted)((0, _snapsutils.file)(), 'dist'),
@@ -78,10 +79,10 @@ const SnapsBrowserifyConfigStruct = (0, _superstruct.object)({
78
79
  src: (0, _superstruct.defaulted)((0, _snapsutils.file)(), 'src/index.js'),
79
80
  stripComments: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true),
80
81
  suppressWarnings: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
81
- transpilationMode: (0, _superstruct.defaulted)((0, _snapsutils.union)([
82
- (0, _snapsutils.literal)('localAndDeps'),
83
- (0, _snapsutils.literal)('localOnly'),
84
- (0, _snapsutils.literal)('none')
82
+ transpilationMode: (0, _superstruct.defaulted)((0, _snapssdk.union)([
83
+ (0, _snapssdk.literal)('localAndDeps'),
84
+ (0, _snapssdk.literal)('localOnly'),
85
+ (0, _snapssdk.literal)('none')
85
86
  ]), 'localOnly'),
86
87
  depsToTranspile: (0, _superstruct.defaulted)((0, _superstruct.array)((0, _superstruct.string)()), []),
87
88
  verboseErrors: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true),
@@ -95,11 +96,11 @@ const SnapsBrowserifyConfigStruct = (0, _superstruct.object)({
95
96
  // type definitions.
96
97
  const SnapsWebpackCustomizeWebpackConfigFunctionStruct = (0, _superstruct.define)('function', (0, _superstruct.func)().validator);
97
98
  const SnapsWebpackConfigStruct = (0, _superstruct.object)({
98
- bundler: (0, _snapsutils.literal)('webpack'),
99
+ bundler: (0, _snapssdk.literal)('webpack'),
99
100
  input: (0, _superstruct.defaulted)((0, _snapsutils.file)(), (0, _path.resolve)(process.cwd(), 'src/index.js')),
100
- sourceMap: (0, _superstruct.defaulted)((0, _snapsutils.union)([
101
+ sourceMap: (0, _superstruct.defaulted)((0, _snapssdk.union)([
101
102
  (0, _superstruct.boolean)(),
102
- (0, _snapsutils.literal)('inline')
103
+ (0, _snapssdk.literal)('inline')
103
104
  ]), true),
104
105
  evaluate: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true),
105
106
  output: (0, _superstruct.defaulted)((0, _superstruct.object)({
@@ -124,15 +125,15 @@ const SnapsWebpackConfigStruct = (0, _superstruct.object)({
124
125
  }),
125
126
  stats: (0, _superstruct.defaulted)((0, _superstruct.object)({
126
127
  verbose: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
127
- builtIns: (0, _superstruct.defaulted)((0, _snapsutils.union)([
128
+ builtIns: (0, _superstruct.defaulted)((0, _snapssdk.union)([
128
129
  (0, _superstruct.object)({
129
130
  ignore: (0, _superstruct.defaulted)((0, _superstruct.array)((0, _superstruct.string)()), [])
130
131
  }),
131
- (0, _snapsutils.literal)(false)
132
+ (0, _snapssdk.literal)(false)
132
133
  ]), {}),
133
134
  buffer: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), true)
134
135
  }), {}),
135
- polyfills: (0, _superstruct.defaulted)((0, _snapsutils.union)([
136
+ polyfills: (0, _superstruct.defaulted)((0, _snapssdk.union)([
136
137
  (0, _superstruct.boolean)(),
137
138
  (0, _superstruct.object)({
138
139
  assert: (0, _superstruct.defaulted)((0, _superstruct.boolean)(), false),
@@ -171,23 +172,23 @@ const SnapsWebpackConfigStruct = (0, _superstruct.object)({
171
172
  }), {})
172
173
  });
173
174
  const SnapsConfigStruct = (0, _superstruct.type)({
174
- bundler: (0, _superstruct.defaulted)((0, _snapsutils.union)([
175
- (0, _snapsutils.literal)('browserify'),
176
- (0, _snapsutils.literal)('webpack')
175
+ bundler: (0, _superstruct.defaulted)((0, _snapssdk.union)([
176
+ (0, _snapssdk.literal)('browserify'),
177
+ (0, _snapssdk.literal)('webpack')
177
178
  ]), 'browserify')
178
179
  });
179
- const LegacyOptionsStruct = (0, _snapsutils.union)([
180
+ const LegacyOptionsStruct = (0, _snapssdk.union)([
180
181
  (0, _snapsutils.named)('object with `transpilationMode` set to `localAndDeps` and `depsToTranspile` set to an array of strings', (0, _superstruct.type)({
181
182
  depsToTranspile: (0, _superstruct.array)((0, _superstruct.string)()),
182
- transpilationMode: (0, _snapsutils.literal)(_builders.TranspilationModes.LocalAndDeps),
183
+ transpilationMode: (0, _snapssdk.literal)(_builders.TranspilationModes.LocalAndDeps),
183
184
  writeManifest: (0, _superstruct.boolean)(),
184
185
  bundlerCustomizer: (0, _superstruct.optional)(SnapsBrowserifyBundlerCustomizerFunctionStruct)
185
186
  })),
186
187
  (0, _snapsutils.named)('object without `depsToTranspile`', (0, _superstruct.type)({
187
188
  depsToTranspile: (0, _snapsutils.named)('empty array', (0, _superstruct.empty)((0, _superstruct.array)())),
188
- transpilationMode: (0, _snapsutils.union)([
189
- (0, _snapsutils.literal)(_builders.TranspilationModes.LocalOnly),
190
- (0, _snapsutils.literal)(_builders.TranspilationModes.None)
189
+ transpilationMode: (0, _snapssdk.union)([
190
+ (0, _snapssdk.literal)(_builders.TranspilationModes.LocalOnly),
191
+ (0, _snapssdk.literal)(_builders.TranspilationModes.None)
191
192
  ]),
192
193
  writeManifest: (0, _superstruct.boolean)(),
193
194
  bundlerCustomizer: (0, _superstruct.optional)(SnapsBrowserifyBundlerCustomizerFunctionStruct)
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config.ts"],"sourcesContent":["import {\n createFromStruct,\n file,\n indent,\n isFile,\n literal,\n union,\n SnapsStructError,\n named,\n} from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\nimport { transform } from '@swc/core';\nimport type { BrowserifyObject } from 'browserify';\nimport { dim } from 'chalk';\nimport { readFile } from 'fs/promises';\nimport Module from 'module';\nimport { basename, dirname, resolve } from 'path';\nimport type { Infer } from 'superstruct';\nimport {\n array,\n boolean,\n create,\n defaulted,\n define,\n func,\n number,\n object,\n optional,\n record,\n string,\n type,\n unknown,\n empty,\n} from 'superstruct';\nimport type { Configuration as WebpackConfiguration } from 'webpack';\n\nimport { TranspilationModes } from './builders';\nimport { ConfigError } from './errors';\nimport type { YargsArgs } from './types/yargs';\nimport { CONFIG_FILE, TS_CONFIG_FILE } from './utils';\n\nconst CONFIG_FILES = [CONFIG_FILE, TS_CONFIG_FILE];\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n *\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\nexport type SnapBrowserifyConfig = {\n /**\n * The bundler to use to build the snap. For backwards compatibility, if not\n * specified, Browserify will be used. However, the Browserify bundler is\n * deprecated and will be removed in a future release, so it's recommended to\n * use the Webpack bundler instead.\n */\n bundler?: 'browserify';\n\n /**\n * The options for the Snaps CLI. These are merged with the options passed to\n * the CLI, with the CLI options taking precedence.\n *\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\n cliOptions?: {\n /**\n * The path to the snap bundle file.\n *\n * @default 'dist/bundle.js'\n */\n bundle?: string;\n\n /**\n * The directory to output the snap to. This is only used if `bundle` is\n * not specified.\n *\n * @default 'dist'\n */\n dist?: string;\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n eval?: boolean;\n\n /**\n * Whether to validate the snap manifest.\n *\n * @default true\n */\n manifest?: boolean;\n\n /**\n * The name of the bundle file. This is only used if `bundle` is not\n * specified.\n *\n * @default 'bundle.js'\n */\n outfileName?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n\n /**\n * The root directory to serve the snap from.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * Whether to generate source maps for the snap bundle.\n *\n * @default false\n */\n sourceMaps?: boolean;\n\n /**\n * The path to the snap entry point.\n *\n * @default 'src/index.js'\n */\n src?: string;\n\n /**\n * Whether to remove comments from the bundle.\n *\n * @default true\n */\n stripComments?: boolean;\n\n /**\n * Whether to suppress warnings.\n *\n * @default false\n */\n suppressWarnings?: boolean;\n\n /**\n * The transpilation mode to use, which determines which files are\n * transpiled.\n *\n * - `'localAndDeps'`: Transpile the snap entry point and all dependencies.\n * - `'localOnly'`: Transpile only the snap entry point.\n * - `'none'`: Don't transpile any files.\n *\n * @default 'localOnly'\n */\n transpilationMode?: 'localAndDeps' | 'localOnly' | 'none';\n\n /**\n * The dependencies to transpile when `transpilationMode` is set to\n * `'localAndDeps'`. If not specified, all dependencies will be transpiled.\n */\n depsToTranspile?: string[];\n\n /**\n * Whether to show original errors.\n *\n * @default true\n */\n verboseErrors?: boolean;\n\n /**\n * Whether to write the updated manifest to disk.\n *\n * @default true\n */\n writeManifest?: boolean;\n\n /**\n * Whether to serve the snap locally.\n *\n * @default true\n */\n serve?: boolean;\n };\n\n /**\n * A function that can be used to customize the Browserify instance used to\n * build the snap.\n *\n * @param bundler - The Browserify instance.\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\n bundlerCustomizer?: (bundler: BrowserifyObject) => void;\n};\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapWebpackConfig = {\n /**\n * The bundler to use to build the snap. For backwards compatibility, if not\n * specified, Browserify will be used. However, the Browserify bundler is\n * deprecated and will be removed in a future release, so it's recommended to\n * use the Webpack bundler instead.\n */\n bundler: 'webpack';\n\n /**\n * The path to the snap entry point. This should be a JavaScript or TypeScript\n * file.\n */\n input: string;\n\n /**\n * Whether to generate source maps for the snap. If `true`, source maps will\n * be generated as separate files. If `'inline'`, source maps will be\n * inlined in the generated JavaScript bundle.\n *\n * @default true\n */\n sourceMap?: boolean | 'inline';\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n evaluate?: boolean;\n\n output?: {\n /**\n * The path to the directory where the snap will be built. This directory\n * will be created if it doesn't exist.\n *\n * If the path is relative, it will be resolved relative to the current\n * working directory.\n *\n * @default 'dist'\n */\n path?: string;\n\n /**\n * The name of the JavaScript bundle file.\n *\n * @default 'bundle.js'\n */\n filename?: string;\n\n /**\n * Whether to clean the output directory before building the snap. If\n * `true`, the output directory will be deleted and recreated. Otherwise,\n * the output directory will be left as-is.\n *\n * @default false\n */\n clean?: boolean;\n\n /**\n * Whether to minimize the snap bundle. If `true`, the bundle will be\n * minified. Otherwise, the bundle will be left as-is.\n *\n * @default true\n */\n minimize?: boolean;\n };\n\n manifest?: {\n /**\n * The path to the snap manifest file. If the path is relative, it will be\n * resolved relative to the current working directory.\n *\n * @default 'snap.manifest.json'\n */\n path?: string;\n\n /**\n * Whether to automatically update the manifest. If `true`, the manifest\n * will be updated with the latest shasum of the snap bundle, and some\n * common fields will be updated if they are missing or incorrect. If\n * `false`, the manifest will be left as-is.\n *\n * @default true\n */\n update?: boolean;\n };\n\n server?: {\n /**\n * Whether to enable the local server. If `true`, the snap will be served\n * from a local server, when running the `watch` command. If `false`, the\n * snap will not be served.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * The root directory to serve the snap from. If the path is relative, it\n * will be resolved relative to the current working directory.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n };\n\n /**\n * The environment variables to set when building the snap. These will be\n * available in the snap as `process.env`. In addition to these environment\n * variables, the following environment variables will always be set:\n *\n * - `NODE_DEBUG`: `false`\n * - `NODE_ENV`: `'production'`\n * - `DEBUG`: `false`\n *\n * Any environment variables specified here will override these defaults. You\n * can also override any variables here by setting them in your shell when\n * running the CLI.\n */\n environment?: Record<string, unknown>;\n\n /**\n * Options that control the logging output of the CLI.\n */\n stats?: {\n /**\n * Whether to enable verbose logging.\n *\n * @default false\n */\n verbose?: boolean;\n\n /**\n * Whether to log warnings about unresolved built-in modules. If `false`,\n * warnings will not be logged.\n */\n builtIns?:\n | {\n /**\n * The built-in modules to ignore when resolving modules. If a module\n * is ignored, no warning will be logged if it is not resolved.\n */\n ignore?: string[];\n }\n | false;\n\n /**\n * Whether to log warnings about the use of the `Buffer` global. If `false`,\n * warnings will not be logged. If `true`, the CLI will warn if the `Buffer`\n * global is used, but not provided by Webpack's `DefinePlugin`.\n */\n buffer?: boolean;\n };\n\n /**\n * Whether to provide polyfills for node builtins. If `true`, all the available\n * polyfills will be provided. If `false` no polyfills will be provided. If a\n * configuration object is passed only the polyfills set to `true` will be provided.\n *\n * @default false\n * @example\n * ```ts\n * polyfills: true\n *\n * // or\n *\n * polyfills: {\n * assert: true,\n * buffer: true\n * }\n * ```\n */\n polyfills?:\n | boolean\n | {\n assert?: boolean;\n buffer?: boolean;\n console?: boolean;\n constants?: boolean;\n crypto?: boolean;\n domain?: boolean;\n events?: boolean;\n http?: boolean;\n https?: boolean;\n os?: boolean;\n path?: boolean;\n punycode?: boolean;\n process?: boolean;\n querystring?: boolean;\n stream?: boolean;\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex?: boolean;\n _stream_passthrough?: boolean;\n _stream_readable?: boolean;\n _stream_transform?: boolean;\n _stream_writable?: boolean;\n string_decoder?: boolean;\n /* eslint-enable @typescript-eslint/naming-convention */\n sys?: boolean;\n timers?: boolean;\n tty?: boolean;\n url?: boolean;\n util?: boolean;\n vm?: boolean;\n zlib?: boolean;\n };\n\n /**\n * A function to customize the Webpack configuration used to build the snap.\n * This function will be called with the default Webpack configuration, and\n * should return the modified configuration. If not specified, the default\n * configuration will be used.\n *\n * It's recommended to use the `webpack-merge` package to merge the default\n * configuration with your customizations. The merge function is exported as\n * `merge` from the `@metamask/snaps-cli` package.\n *\n * @example\n * ```ts\n * import type { SnapsConfig } from '@metamask/snaps-cli';\n * import { merge } from '@metamask/snaps-cli';\n *\n * const config: SnapsConfig = {\n * bundler: 'webpack',\n * entry: 'src/index.ts',\n * customizeWebpackConfig: (config) => merge(config, {\n * module: {\n * rules: [\n * {\n * test: /\\.wasm$/,\n * type: 'assets/resource',\n * },\n * ],\n * },\n * }),\n * };\n *\n * export default config;\n * ```\n */\n customizeWebpackConfig?: (\n config: WebpackConfiguration,\n ) => WebpackConfiguration;\n\n /**\n * Experimental features that can be enabled. These features are not\n * guaranteed to be stable, and may be removed or changed in a future release.\n */\n experimental?: {\n /**\n * Whether to enable WebAssembly support. If `true`, the Webpack\n * configuration will be modified to support WebAssembly. If `false`, the\n * Webpack configuration will not be modified.\n *\n * @default false\n */\n wasm?: boolean;\n };\n};\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapConfig = SnapBrowserifyConfig | SnapWebpackConfig;\n\ntype SnapsBrowserifyBundlerCustomizerFunction = (\n bundler: BrowserifyObject,\n) => void;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsBrowserifyBundlerCustomizerFunctionStruct =\n define<SnapsBrowserifyBundlerCustomizerFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsBrowserifyConfigStruct = object({\n bundler: defaulted(literal('browserify'), 'browserify'),\n cliOptions: defaulted(\n object({\n bundle: optional(file()),\n dist: defaulted(file(), 'dist'),\n eval: defaulted(boolean(), true),\n manifest: defaulted(boolean(), true),\n port: defaulted(number(), 8081),\n outfileName: defaulted(string(), 'bundle.js'),\n root: defaulted(file(), process.cwd()),\n sourceMaps: defaulted(boolean(), false),\n src: defaulted(file(), 'src/index.js'),\n stripComments: defaulted(boolean(), true),\n suppressWarnings: defaulted(boolean(), false),\n transpilationMode: defaulted(\n union([literal('localAndDeps'), literal('localOnly'), literal('none')]),\n 'localOnly',\n ),\n depsToTranspile: defaulted(array(string()), []),\n verboseErrors: defaulted(boolean(), true),\n writeManifest: defaulted(boolean(), true),\n serve: defaulted(boolean(), true),\n }),\n {},\n ),\n bundlerCustomizer: optional(SnapsBrowserifyBundlerCustomizerFunctionStruct),\n});\n\ntype SnapsWebpackCustomizeWebpackConfigFunction = (\n config: WebpackConfiguration,\n) => WebpackConfiguration;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsWebpackCustomizeWebpackConfigFunctionStruct =\n define<SnapsWebpackCustomizeWebpackConfigFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsWebpackConfigStruct = object({\n bundler: literal('webpack'),\n input: defaulted(file(), resolve(process.cwd(), 'src/index.js')),\n sourceMap: defaulted(union([boolean(), literal('inline')]), true),\n evaluate: defaulted(boolean(), true),\n\n output: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'dist')),\n filename: defaulted(string(), 'bundle.js'),\n clean: defaulted(boolean(), false),\n minimize: defaulted(boolean(), true),\n }),\n {},\n ),\n\n manifest: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'snap.manifest.json')),\n update: defaulted(boolean(), true),\n }),\n {},\n ),\n\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n root: defaulted(file(), process.cwd()),\n port: defaulted(number(), 8081),\n }),\n {},\n ),\n\n environment: defaulted(record(string(), unknown()), {\n NODE_DEBUG: false,\n NODE_ENV: 'production',\n DEBUG: false,\n }),\n\n stats: defaulted(\n object({\n verbose: defaulted(boolean(), false),\n builtIns: defaulted(\n union([\n object({ ignore: defaulted(array(string()), []) }),\n literal(false),\n ]),\n {},\n ),\n buffer: defaulted(boolean(), true),\n }),\n {},\n ),\n\n polyfills: defaulted(\n union([\n boolean(),\n object({\n assert: defaulted(boolean(), false),\n buffer: defaulted(boolean(), false),\n console: defaulted(boolean(), false),\n constants: defaulted(boolean(), false),\n crypto: defaulted(boolean(), false),\n domain: defaulted(boolean(), false),\n events: defaulted(boolean(), false),\n http: defaulted(boolean(), false),\n https: defaulted(boolean(), false),\n os: defaulted(boolean(), false),\n path: defaulted(boolean(), false),\n punycode: defaulted(boolean(), false),\n process: defaulted(boolean(), false),\n querystring: defaulted(boolean(), false),\n stream: defaulted(boolean(), false),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: defaulted(boolean(), false),\n _stream_passthrough: defaulted(boolean(), false),\n _stream_readable: defaulted(boolean(), false),\n _stream_transform: defaulted(boolean(), false),\n _stream_writable: defaulted(boolean(), false),\n string_decoder: defaulted(boolean(), false),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: defaulted(boolean(), false),\n timers: defaulted(boolean(), false),\n tty: defaulted(boolean(), false),\n url: defaulted(boolean(), false),\n util: defaulted(boolean(), false),\n vm: defaulted(boolean(), false),\n zlib: defaulted(boolean(), false),\n }),\n ]),\n false,\n ),\n\n customizeWebpackConfig: optional(\n SnapsWebpackCustomizeWebpackConfigFunctionStruct,\n ),\n\n experimental: defaulted(\n object({\n wasm: defaulted(boolean(), false),\n }),\n {},\n ),\n});\n\nexport const SnapsConfigStruct = type({\n bundler: defaulted(\n union([literal('browserify'), literal('webpack')]),\n 'browserify',\n ),\n});\n\nexport const LegacyOptionsStruct = union([\n named(\n 'object with `transpilationMode` set to `localAndDeps` and `depsToTranspile` set to an array of strings',\n type({\n depsToTranspile: array(string()),\n transpilationMode: literal(TranspilationModes.LocalAndDeps),\n writeManifest: boolean(),\n bundlerCustomizer: optional(\n SnapsBrowserifyBundlerCustomizerFunctionStruct,\n ),\n }),\n ),\n named(\n 'object without `depsToTranspile`',\n type({\n depsToTranspile: named('empty array', empty(array())),\n transpilationMode: union([\n literal(TranspilationModes.LocalOnly),\n literal(TranspilationModes.None),\n ]),\n writeManifest: boolean(),\n bundlerCustomizer: optional(\n SnapsBrowserifyBundlerCustomizerFunctionStruct,\n ),\n }),\n ),\n]);\n\nexport type LegacyOptions = Infer<typeof LegacyOptionsStruct>;\n\nexport type ProcessedBrowserifyConfig = Infer<\n typeof SnapsBrowserifyConfigStruct\n>;\n\nexport type ProcessedWebpackConfig = Infer<typeof SnapsWebpackConfigStruct> & {\n /**\n * The legacy Browserify config, if the bundler is Browserify. This is used\n * to support the legacy config format.\n */\n legacy?: LegacyOptions;\n};\n\nexport type ProcessedConfig = ProcessedWebpackConfig;\n\n/**\n * Get a validated snap config. This validates the config and adds default\n * values for any missing properties.\n *\n * @param config - The config to validate.\n * @param argv - The CLI arguments.\n * @returns The validated config.\n */\nexport function getConfig(config: unknown, argv: YargsArgs): ProcessedConfig {\n const prefix = 'The snap config file is invalid';\n const suffix = dim(\n // TODO: Link to `docs.metamask.io` once the docs are published.\n 'Refer to the documentation for more information: https://github.com/MetaMask/snaps/tree/main/packages/snaps-cli/',\n );\n\n const { bundler } = createFromStruct(\n config,\n SnapsConfigStruct,\n prefix,\n suffix,\n );\n\n if (bundler === 'browserify') {\n const legacyConfig = createFromStruct(\n config,\n SnapsBrowserifyConfigStruct,\n prefix,\n suffix,\n );\n\n return getWebpackConfig(mergeLegacyOptions(argv, legacyConfig));\n }\n\n return createFromStruct(config, SnapsWebpackConfigStruct, prefix, suffix);\n}\n\n/**\n * Load a snap config from a file. This supports both JavaScript and TypeScript\n * config files, in the CommonJS module format and the ES module format.\n *\n * This assumes that the config file exports a default object, either through\n * `module.exports` or `export default`.\n *\n * @param path - The full path to the config file.\n * @param argv - The CLI arguments.\n * @returns The validated config.\n * @throws If the config file is invalid, or if the config file does not have a\n * default export.\n */\nexport async function loadConfig(path: string, argv: YargsArgs) {\n try {\n const contents = await readFile(path, 'utf8');\n const source = await transform(contents, {\n swcrc: false,\n jsc: {\n parser: {\n syntax: 'typescript',\n },\n },\n module: {\n type: 'commonjs',\n },\n });\n\n const config = new Module(path);\n\n // @ts-expect-error - This function is not typed.\n config.paths = Module._nodeModulePaths(dirname(path));\n\n // @ts-expect-error - This function is not typed.\n config._compile(source.code, path);\n\n if (!hasProperty(config.exports, 'default')) {\n return getConfig(config.exports, argv);\n }\n\n return getConfig(config.exports.default, argv);\n } catch (error) {\n if (error instanceof SnapsStructError) {\n throw new ConfigError(error.message);\n }\n\n throw new ConfigError(\n `Unable to load snap config file at \"${path}\".\\n\\n${indent(\n error.message,\n )}`,\n );\n }\n}\n\n/**\n * Resolve a snap config. This function will look for a `snap.config.js` or\n * `snap.config.ts` file in the current or specified directory.\n *\n * @param path - The path to resolve the snap config from. Defaults to the\n * current working directory.\n * @param argv - The CLI arguments.\n * @returns The resolved and validated snap config.\n * @throws If a snap config could not be found.\n */\nexport async function resolveConfig(path: string, argv: YargsArgs) {\n for (const configFile of CONFIG_FILES) {\n const filePath = resolve(path, configFile);\n if (await isFile(filePath)) {\n return await loadConfig(filePath, argv);\n }\n }\n\n throw new ConfigError(\n `Could not find a \"snap.config.js\" or \"snap.config.ts\" file in the current or specified directory (\"${path}\").`,\n );\n}\n\n/**\n * Get a snap config from the CLI arguments. This will either load the config\n * from the specified config file, or resolve the config from the current\n * working directory.\n *\n * @param argv - The CLI arguments.\n * @param cwd - The current working directory. Defaults to `process.cwd()`.\n * @returns The resolved and validated snap config.\n */\nexport async function getConfigByArgv(\n argv: YargsArgs,\n cwd: string = process.cwd(),\n) {\n if (argv.config) {\n if (!(await isFile(argv.config))) {\n throw new ConfigError(\n `Could not find a config file at \"${argv.config}\". Make sure that the path is correct.`,\n );\n }\n\n return await loadConfig(argv.config, argv);\n }\n\n return await resolveConfig(cwd, argv);\n}\n\n/**\n * Merge legacy CLI options into the config. This is used to support the legacy\n * config format, where options can be specified both in the config file and\n * through CLI flags.\n *\n * @param argv - The CLI arguments.\n * @param config - The config to merge the CLI options into.\n * @returns The config with the CLI options merged in.\n * @deprecated This function is only used to support the legacy config format.\n */\nexport function mergeLegacyOptions(\n argv: YargsArgs,\n config: ProcessedBrowserifyConfig,\n) {\n const cliOptions = Object.keys(config.cliOptions).reduce<\n ProcessedBrowserifyConfig['cliOptions']\n >((accumulator, key) => {\n if (argv[key] !== undefined) {\n return {\n ...accumulator,\n [key]: argv[key],\n };\n }\n\n return accumulator;\n }, config.cliOptions);\n\n return {\n ...config,\n cliOptions,\n };\n}\n\n/**\n * Get a Webpack config from a legacy browserify config. This is used to\n * support the legacy config format, and convert it to the new format.\n *\n * @param legacyConfig - The legacy browserify config.\n * @returns The Webpack config.\n */\nexport function getWebpackConfig(\n legacyConfig: ProcessedBrowserifyConfig,\n): ProcessedWebpackConfig {\n const defaultConfig = create(\n { bundler: 'webpack' },\n SnapsWebpackConfigStruct,\n );\n\n // The legacy config has two options for specifying the output path and\n // filename: `bundle`, and `dist` + `outfileName`. If `bundle` is specified,\n // we use that as the output path and filename. Otherwise, we use `dist` and\n // `outfileName`.\n const path = legacyConfig.cliOptions.bundle\n ? dirname(legacyConfig.cliOptions.bundle)\n : legacyConfig.cliOptions.dist;\n\n const filename = legacyConfig.cliOptions.bundle\n ? basename(legacyConfig.cliOptions.bundle)\n : legacyConfig.cliOptions.outfileName;\n\n return {\n ...defaultConfig,\n input: legacyConfig.cliOptions.src,\n evaluate: legacyConfig.cliOptions.eval,\n sourceMap: legacyConfig.cliOptions.sourceMaps,\n output: {\n path,\n filename,\n\n // The legacy config has an option to remove comments from the bundle, but\n // the terser plugin does this by default, so we only enable the terser if\n // the legacy config has `stripComments` set to `true`. This is not a\n // perfect solution, but it's the best we can do without breaking the\n // legacy config.\n minimize: legacyConfig.cliOptions.stripComments,\n\n // The legacy config does not have a `clean` option, so we default to\n // `false` here.\n clean: false,\n },\n manifest: {\n // The legacy config does not have a `manifest` option, so we default to\n // `process.cwd()/snap.manifest.json`.\n path: resolve(process.cwd(), 'snap.manifest.json'),\n update: legacyConfig.cliOptions.writeManifest,\n },\n server: {\n enabled: legacyConfig.cliOptions.serve,\n port: legacyConfig.cliOptions.port,\n root: legacyConfig.cliOptions.root,\n },\n stats: {\n verbose: false,\n\n // These plugins are designed to be used with the modern config format, so\n // we disable them for the legacy config format.\n builtIns: false,\n buffer: false,\n },\n legacy: createFromStruct(\n {\n ...legacyConfig.cliOptions,\n bundlerCustomizer: legacyConfig.bundlerCustomizer,\n },\n LegacyOptionsStruct,\n 'Invalid Browserify CLI options',\n ),\n };\n}\n"],"names":["SnapsBrowserifyConfigStruct","SnapsWebpackConfigStruct","SnapsConfigStruct","LegacyOptionsStruct","getConfig","loadConfig","resolveConfig","getConfigByArgv","mergeLegacyOptions","getWebpackConfig","CONFIG_FILES","CONFIG_FILE","TS_CONFIG_FILE","SnapsBrowserifyBundlerCustomizerFunctionStruct","define","func","validator","object","bundler","defaulted","literal","cliOptions","bundle","optional","file","dist","eval","boolean","manifest","port","number","outfileName","string","root","process","cwd","sourceMaps","src","stripComments","suppressWarnings","transpilationMode","union","depsToTranspile","array","verboseErrors","writeManifest","serve","bundlerCustomizer","SnapsWebpackCustomizeWebpackConfigFunctionStruct","input","resolve","sourceMap","evaluate","output","path","filename","clean","minimize","update","server","enabled","environment","record","unknown","NODE_DEBUG","NODE_ENV","DEBUG","stats","verbose","builtIns","ignore","buffer","polyfills","assert","console","constants","crypto","domain","events","http","https","os","punycode","querystring","stream","_stream_duplex","_stream_passthrough","_stream_readable","_stream_transform","_stream_writable","string_decoder","sys","timers","tty","url","util","vm","zlib","customizeWebpackConfig","experimental","wasm","type","named","TranspilationModes","LocalAndDeps","empty","LocalOnly","None","config","argv","prefix","suffix","dim","createFromStruct","legacyConfig","contents","readFile","source","transform","swcrc","jsc","parser","syntax","module","Module","paths","_nodeModulePaths","dirname","_compile","code","hasProperty","exports","default","error","SnapsStructError","ConfigError","message","indent","configFile","filePath","isFile","Object","keys","reduce","accumulator","key","undefined","defaultConfig","create","basename","legacy"],"mappings":";;;;;;;;;;;IA0eaA,2BAA2B;eAA3BA;;IA0CAC,wBAAwB;eAAxBA;;IAyGAC,iBAAiB;eAAjBA;;IAOAC,mBAAmB;eAAnBA;;IAoDGC,SAAS;eAATA;;IAyC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AAO;YACLC,SAAS;YAET,0EAA0E;YAC1E,gDAAgD;YAChDC,UAAU;YACVE,QAAQ;QACV;QACA+E,QAAQrC,IAAAA,4BAAgB,EACtB;YACE,GAAGC,aAAa7F,UAAU;YAC1B0B,mBAAmBmE,aAAanE,iBAAiB;QACnD,GACA5C,qBACA;IAEJ;AACF"}
1
+ {"version":3,"sources":["../../src/config.ts"],"sourcesContent":["import { literal, union } from '@metamask/snaps-sdk';\nimport {\n createFromStruct,\n file,\n indent,\n isFile,\n SnapsStructError,\n named,\n} from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\nimport { transform } from '@swc/core';\nimport type { BrowserifyObject } from 'browserify';\nimport { dim } from 'chalk';\nimport { readFile } from 'fs/promises';\nimport Module from 'module';\nimport { basename, dirname, resolve } from 'path';\nimport type { Infer } from 'superstruct';\nimport {\n array,\n boolean,\n create,\n defaulted,\n define,\n func,\n number,\n object,\n optional,\n record,\n string,\n type,\n unknown,\n empty,\n} from 'superstruct';\nimport type { Configuration as WebpackConfiguration } from 'webpack';\n\nimport { TranspilationModes } from './builders';\nimport { ConfigError } from './errors';\nimport type { YargsArgs } from './types/yargs';\nimport { CONFIG_FILE, TS_CONFIG_FILE } from './utils';\n\nconst CONFIG_FILES = [CONFIG_FILE, TS_CONFIG_FILE];\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n *\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\nexport type SnapBrowserifyConfig = {\n /**\n * The bundler to use to build the snap. For backwards compatibility, if not\n * specified, Browserify will be used. However, the Browserify bundler is\n * deprecated and will be removed in a future release, so it's recommended to\n * use the Webpack bundler instead.\n */\n bundler?: 'browserify';\n\n /**\n * The options for the Snaps CLI. These are merged with the options passed to\n * the CLI, with the CLI options taking precedence.\n *\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\n cliOptions?: {\n /**\n * The path to the snap bundle file.\n *\n * @default 'dist/bundle.js'\n */\n bundle?: string;\n\n /**\n * The directory to output the snap to. This is only used if `bundle` is\n * not specified.\n *\n * @default 'dist'\n */\n dist?: string;\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n eval?: boolean;\n\n /**\n * Whether to validate the snap manifest.\n *\n * @default true\n */\n manifest?: boolean;\n\n /**\n * The name of the bundle file. This is only used if `bundle` is not\n * specified.\n *\n * @default 'bundle.js'\n */\n outfileName?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n\n /**\n * The root directory to serve the snap from.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * Whether to generate source maps for the snap bundle.\n *\n * @default false\n */\n sourceMaps?: boolean;\n\n /**\n * The path to the snap entry point.\n *\n * @default 'src/index.js'\n */\n src?: string;\n\n /**\n * Whether to remove comments from the bundle.\n *\n * @default true\n */\n stripComments?: boolean;\n\n /**\n * Whether to suppress warnings.\n *\n * @default false\n */\n suppressWarnings?: boolean;\n\n /**\n * The transpilation mode to use, which determines which files are\n * transpiled.\n *\n * - `'localAndDeps'`: Transpile the snap entry point and all dependencies.\n * - `'localOnly'`: Transpile only the snap entry point.\n * - `'none'`: Don't transpile any files.\n *\n * @default 'localOnly'\n */\n transpilationMode?: 'localAndDeps' | 'localOnly' | 'none';\n\n /**\n * The dependencies to transpile when `transpilationMode` is set to\n * `'localAndDeps'`. If not specified, all dependencies will be transpiled.\n */\n depsToTranspile?: string[];\n\n /**\n * Whether to show original errors.\n *\n * @default true\n */\n verboseErrors?: boolean;\n\n /**\n * Whether to write the updated manifest to disk.\n *\n * @default true\n */\n writeManifest?: boolean;\n\n /**\n * Whether to serve the snap locally.\n *\n * @default true\n */\n serve?: boolean;\n };\n\n /**\n * A function that can be used to customize the Browserify instance used to\n * build the snap.\n *\n * @param bundler - The Browserify instance.\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\n bundlerCustomizer?: (bundler: BrowserifyObject) => void;\n};\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapWebpackConfig = {\n /**\n * The bundler to use to build the snap. For backwards compatibility, if not\n * specified, Browserify will be used. However, the Browserify bundler is\n * deprecated and will be removed in a future release, so it's recommended to\n * use the Webpack bundler instead.\n */\n bundler: 'webpack';\n\n /**\n * The path to the snap entry point. This should be a JavaScript or TypeScript\n * file.\n */\n input: string;\n\n /**\n * Whether to generate source maps for the snap. If `true`, source maps will\n * be generated as separate files. If `'inline'`, source maps will be\n * inlined in the generated JavaScript bundle.\n *\n * @default true\n */\n sourceMap?: boolean | 'inline';\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n evaluate?: boolean;\n\n output?: {\n /**\n * The path to the directory where the snap will be built. This directory\n * will be created if it doesn't exist.\n *\n * If the path is relative, it will be resolved relative to the current\n * working directory.\n *\n * @default 'dist'\n */\n path?: string;\n\n /**\n * The name of the JavaScript bundle file.\n *\n * @default 'bundle.js'\n */\n filename?: string;\n\n /**\n * Whether to clean the output directory before building the snap. If\n * `true`, the output directory will be deleted and recreated. Otherwise,\n * the output directory will be left as-is.\n *\n * @default false\n */\n clean?: boolean;\n\n /**\n * Whether to minimize the snap bundle. If `true`, the bundle will be\n * minified. Otherwise, the bundle will be left as-is.\n *\n * @default true\n */\n minimize?: boolean;\n };\n\n manifest?: {\n /**\n * The path to the snap manifest file. If the path is relative, it will be\n * resolved relative to the current working directory.\n *\n * @default 'snap.manifest.json'\n */\n path?: string;\n\n /**\n * Whether to automatically update the manifest. If `true`, the manifest\n * will be updated with the latest shasum of the snap bundle, and some\n * common fields will be updated if they are missing or incorrect. If\n * `false`, the manifest will be left as-is.\n *\n * @default true\n */\n update?: boolean;\n };\n\n server?: {\n /**\n * Whether to enable the local server. If `true`, the snap will be served\n * from a local server, when running the `watch` command. If `false`, the\n * snap will not be served.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * The root directory to serve the snap from. If the path is relative, it\n * will be resolved relative to the current working directory.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n };\n\n /**\n * The environment variables to set when building the snap. These will be\n * available in the snap as `process.env`. In addition to these environment\n * variables, the following environment variables will always be set:\n *\n * - `NODE_DEBUG`: `false`\n * - `NODE_ENV`: `'production'`\n * - `DEBUG`: `false`\n *\n * Any environment variables specified here will override these defaults. You\n * can also override any variables here by setting them in your shell when\n * running the CLI.\n */\n environment?: Record<string, unknown>;\n\n /**\n * Options that control the logging output of the CLI.\n */\n stats?: {\n /**\n * Whether to enable verbose logging.\n *\n * @default false\n */\n verbose?: boolean;\n\n /**\n * Whether to log warnings about unresolved built-in modules. If `false`,\n * warnings will not be logged.\n */\n builtIns?:\n | {\n /**\n * The built-in modules to ignore when resolving modules. If a module\n * is ignored, no warning will be logged if it is not resolved.\n */\n ignore?: string[];\n }\n | false;\n\n /**\n * Whether to log warnings about the use of the `Buffer` global. If `false`,\n * warnings will not be logged. If `true`, the CLI will warn if the `Buffer`\n * global is used, but not provided by Webpack's `DefinePlugin`.\n */\n buffer?: boolean;\n };\n\n /**\n * Whether to provide polyfills for node builtins. If `true`, all the available\n * polyfills will be provided. If `false` no polyfills will be provided. If a\n * configuration object is passed only the polyfills set to `true` will be provided.\n *\n * @default false\n * @example\n * ```ts\n * polyfills: true\n *\n * // or\n *\n * polyfills: {\n * assert: true,\n * buffer: true\n * }\n * ```\n */\n polyfills?:\n | boolean\n | {\n assert?: boolean;\n buffer?: boolean;\n console?: boolean;\n constants?: boolean;\n crypto?: boolean;\n domain?: boolean;\n events?: boolean;\n http?: boolean;\n https?: boolean;\n os?: boolean;\n path?: boolean;\n punycode?: boolean;\n process?: boolean;\n querystring?: boolean;\n stream?: boolean;\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex?: boolean;\n _stream_passthrough?: boolean;\n _stream_readable?: boolean;\n _stream_transform?: boolean;\n _stream_writable?: boolean;\n string_decoder?: boolean;\n /* eslint-enable @typescript-eslint/naming-convention */\n sys?: boolean;\n timers?: boolean;\n tty?: boolean;\n url?: boolean;\n util?: boolean;\n vm?: boolean;\n zlib?: boolean;\n };\n\n /**\n * A function to customize the Webpack configuration used to build the snap.\n * This function will be called with the default Webpack configuration, and\n * should return the modified configuration. If not specified, the default\n * configuration will be used.\n *\n * It's recommended to use the `webpack-merge` package to merge the default\n * configuration with your customizations. The merge function is exported as\n * `merge` from the `@metamask/snaps-cli` package.\n *\n * @example\n * ```ts\n * import type { SnapsConfig } from '@metamask/snaps-cli';\n * import { merge } from '@metamask/snaps-cli';\n *\n * const config: SnapsConfig = {\n * bundler: 'webpack',\n * entry: 'src/index.ts',\n * customizeWebpackConfig: (config) => merge(config, {\n * module: {\n * rules: [\n * {\n * test: /\\.wasm$/,\n * type: 'assets/resource',\n * },\n * ],\n * },\n * }),\n * };\n *\n * export default config;\n * ```\n */\n customizeWebpackConfig?: (\n config: WebpackConfiguration,\n ) => WebpackConfiguration;\n\n /**\n * Experimental features that can be enabled. These features are not\n * guaranteed to be stable, and may be removed or changed in a future release.\n */\n experimental?: {\n /**\n * Whether to enable WebAssembly support. If `true`, the Webpack\n * configuration will be modified to support WebAssembly. If `false`, the\n * Webpack configuration will not be modified.\n *\n * @default false\n */\n wasm?: boolean;\n };\n};\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapConfig = SnapBrowserifyConfig | SnapWebpackConfig;\n\ntype SnapsBrowserifyBundlerCustomizerFunction = (\n bundler: BrowserifyObject,\n) => void;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsBrowserifyBundlerCustomizerFunctionStruct =\n define<SnapsBrowserifyBundlerCustomizerFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsBrowserifyConfigStruct = object({\n bundler: defaulted(literal('browserify'), 'browserify'),\n cliOptions: defaulted(\n object({\n bundle: optional(file()),\n dist: defaulted(file(), 'dist'),\n eval: defaulted(boolean(), true),\n manifest: defaulted(boolean(), true),\n port: defaulted(number(), 8081),\n outfileName: defaulted(string(), 'bundle.js'),\n root: defaulted(file(), process.cwd()),\n sourceMaps: defaulted(boolean(), false),\n src: defaulted(file(), 'src/index.js'),\n stripComments: defaulted(boolean(), true),\n suppressWarnings: defaulted(boolean(), false),\n transpilationMode: defaulted(\n union([literal('localAndDeps'), literal('localOnly'), literal('none')]),\n 'localOnly',\n ),\n depsToTranspile: defaulted(array(string()), []),\n verboseErrors: defaulted(boolean(), true),\n writeManifest: defaulted(boolean(), true),\n serve: defaulted(boolean(), true),\n }),\n {},\n ),\n bundlerCustomizer: optional(SnapsBrowserifyBundlerCustomizerFunctionStruct),\n});\n\ntype SnapsWebpackCustomizeWebpackConfigFunction = (\n config: WebpackConfiguration,\n) => WebpackConfiguration;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsWebpackCustomizeWebpackConfigFunctionStruct =\n define<SnapsWebpackCustomizeWebpackConfigFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsWebpackConfigStruct = object({\n bundler: literal('webpack'),\n input: defaulted(file(), resolve(process.cwd(), 'src/index.js')),\n sourceMap: defaulted(union([boolean(), literal('inline')]), true),\n evaluate: defaulted(boolean(), true),\n\n output: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'dist')),\n filename: defaulted(string(), 'bundle.js'),\n clean: defaulted(boolean(), false),\n minimize: defaulted(boolean(), true),\n }),\n {},\n ),\n\n manifest: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'snap.manifest.json')),\n update: defaulted(boolean(), true),\n }),\n {},\n ),\n\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n root: defaulted(file(), process.cwd()),\n port: defaulted(number(), 8081),\n }),\n {},\n ),\n\n environment: defaulted(record(string(), unknown()), {\n NODE_DEBUG: false,\n NODE_ENV: 'production',\n DEBUG: false,\n }),\n\n stats: defaulted(\n object({\n verbose: defaulted(boolean(), false),\n builtIns: defaulted(\n union([\n object({ ignore: defaulted(array(string()), []) }),\n literal(false),\n ]),\n {},\n ),\n buffer: defaulted(boolean(), true),\n }),\n {},\n ),\n\n polyfills: defaulted(\n union([\n boolean(),\n object({\n assert: defaulted(boolean(), false),\n buffer: defaulted(boolean(), false),\n console: defaulted(boolean(), false),\n constants: defaulted(boolean(), false),\n crypto: defaulted(boolean(), false),\n domain: defaulted(boolean(), false),\n events: defaulted(boolean(), false),\n http: defaulted(boolean(), false),\n https: defaulted(boolean(), false),\n os: defaulted(boolean(), false),\n path: defaulted(boolean(), false),\n punycode: defaulted(boolean(), false),\n process: defaulted(boolean(), false),\n querystring: defaulted(boolean(), false),\n stream: defaulted(boolean(), false),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: defaulted(boolean(), false),\n _stream_passthrough: defaulted(boolean(), false),\n _stream_readable: defaulted(boolean(), false),\n _stream_transform: defaulted(boolean(), false),\n _stream_writable: defaulted(boolean(), false),\n string_decoder: defaulted(boolean(), false),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: defaulted(boolean(), false),\n timers: defaulted(boolean(), false),\n tty: defaulted(boolean(), false),\n url: defaulted(boolean(), false),\n util: defaulted(boolean(), false),\n vm: defaulted(boolean(), false),\n zlib: defaulted(boolean(), false),\n }),\n ]),\n false,\n ),\n\n customizeWebpackConfig: optional(\n SnapsWebpackCustomizeWebpackConfigFunctionStruct,\n ),\n\n experimental: defaulted(\n object({\n wasm: defaulted(boolean(), false),\n }),\n {},\n ),\n});\n\nexport const SnapsConfigStruct = type({\n bundler: defaulted(\n union([literal('browserify'), literal('webpack')]),\n 'browserify',\n ),\n});\n\nexport const LegacyOptionsStruct = union([\n named(\n 'object with `transpilationMode` set to `localAndDeps` and `depsToTranspile` set to an array of strings',\n type({\n depsToTranspile: array(string()),\n transpilationMode: literal(TranspilationModes.LocalAndDeps),\n writeManifest: boolean(),\n bundlerCustomizer: optional(\n SnapsBrowserifyBundlerCustomizerFunctionStruct,\n ),\n }),\n ),\n named(\n 'object without `depsToTranspile`',\n type({\n depsToTranspile: named('empty array', empty(array())),\n transpilationMode: union([\n literal(TranspilationModes.LocalOnly),\n literal(TranspilationModes.None),\n ]),\n writeManifest: boolean(),\n bundlerCustomizer: optional(\n SnapsBrowserifyBundlerCustomizerFunctionStruct,\n ),\n }),\n ),\n]);\n\nexport type LegacyOptions = Infer<typeof LegacyOptionsStruct>;\n\nexport type ProcessedBrowserifyConfig = Infer<\n typeof SnapsBrowserifyConfigStruct\n>;\n\nexport type ProcessedWebpackConfig = Infer<typeof SnapsWebpackConfigStruct> & {\n /**\n * The legacy Browserify config, if the bundler is Browserify. This is used\n * to support the legacy config format.\n */\n legacy?: LegacyOptions;\n};\n\nexport type ProcessedConfig = ProcessedWebpackConfig;\n\n/**\n * Get a validated snap config. This validates the config and adds default\n * values for any missing properties.\n *\n * @param config - The config to validate.\n * @param argv - The CLI arguments.\n * @returns The validated config.\n */\nexport function getConfig(config: unknown, argv: YargsArgs): ProcessedConfig {\n const prefix = 'The snap config file is invalid';\n const suffix = dim(\n // TODO: Link to `docs.metamask.io` once the docs are published.\n 'Refer to the documentation for more information: https://github.com/MetaMask/snaps/tree/main/packages/snaps-cli/',\n );\n\n const { bundler } = createFromStruct(\n config,\n SnapsConfigStruct,\n prefix,\n suffix,\n );\n\n if (bundler === 'browserify') {\n const legacyConfig = createFromStruct(\n config,\n SnapsBrowserifyConfigStruct,\n prefix,\n suffix,\n );\n\n return getWebpackConfig(mergeLegacyOptions(argv, legacyConfig));\n }\n\n return createFromStruct(config, SnapsWebpackConfigStruct, prefix, suffix);\n}\n\n/**\n * Load a snap config from a file. This supports both JavaScript and TypeScript\n * config files, in the CommonJS module format and the ES module format.\n *\n * This assumes that the config file exports a default object, either through\n * `module.exports` or `export default`.\n *\n * @param path - The full path to the config file.\n * @param argv - The CLI arguments.\n * @returns The validated config.\n * @throws If the config file is invalid, or if the config file does not have a\n * default export.\n */\nexport async function loadConfig(path: string, argv: YargsArgs) {\n try {\n const contents = await readFile(path, 'utf8');\n const source = await transform(contents, {\n swcrc: false,\n jsc: {\n parser: {\n syntax: 'typescript',\n },\n },\n module: {\n type: 'commonjs',\n },\n });\n\n const config = new Module(path);\n\n // @ts-expect-error - This function is not typed.\n config.paths = Module._nodeModulePaths(dirname(path));\n\n // @ts-expect-error - This function is not typed.\n config._compile(source.code, path);\n\n if (!hasProperty(config.exports, 'default')) {\n return getConfig(config.exports, argv);\n }\n\n return getConfig(config.exports.default, argv);\n } catch (error) {\n if (error instanceof SnapsStructError) {\n throw new ConfigError(error.message);\n }\n\n throw new ConfigError(\n `Unable to load snap config file at \"${path}\".\\n\\n${indent(\n error.message,\n )}`,\n );\n }\n}\n\n/**\n * Resolve a snap config. This function will look for a `snap.config.js` or\n * `snap.config.ts` file in the current or specified directory.\n *\n * @param path - The path to resolve the snap config from. Defaults to the\n * current working directory.\n * @param argv - The CLI arguments.\n * @returns The resolved and validated snap config.\n * @throws If a snap config could not be found.\n */\nexport async function resolveConfig(path: string, argv: YargsArgs) {\n for (const configFile of CONFIG_FILES) {\n const filePath = resolve(path, configFile);\n if (await isFile(filePath)) {\n return await loadConfig(filePath, argv);\n }\n }\n\n throw new ConfigError(\n `Could not find a \"snap.config.js\" or \"snap.config.ts\" file in the current or specified directory (\"${path}\").`,\n );\n}\n\n/**\n * Get a snap config from the CLI arguments. This will either load the config\n * from the specified config file, or resolve the config from the current\n * working directory.\n *\n * @param argv - The CLI arguments.\n * @param cwd - The current working directory. Defaults to `process.cwd()`.\n * @returns The resolved and validated snap config.\n */\nexport async function getConfigByArgv(\n argv: YargsArgs,\n cwd: string = process.cwd(),\n) {\n if (argv.config) {\n if (!(await isFile(argv.config))) {\n throw new ConfigError(\n `Could not find a config file at \"${argv.config}\". Make sure that the path is correct.`,\n );\n }\n\n return await loadConfig(argv.config, argv);\n }\n\n return await resolveConfig(cwd, argv);\n}\n\n/**\n * Merge legacy CLI options into the config. This is used to support the legacy\n * config format, where options can be specified both in the config file and\n * through CLI flags.\n *\n * @param argv - The CLI arguments.\n * @param config - The config to merge the CLI options into.\n * @returns The config with the CLI options merged in.\n * @deprecated This function is only used to support the legacy config format.\n */\nexport function mergeLegacyOptions(\n argv: YargsArgs,\n config: ProcessedBrowserifyConfig,\n) {\n const cliOptions = Object.keys(config.cliOptions).reduce<\n ProcessedBrowserifyConfig['cliOptions']\n >((accumulator, key) => {\n if (argv[key] !== undefined) {\n return {\n ...accumulator,\n [key]: argv[key],\n };\n }\n\n return accumulator;\n }, config.cliOptions);\n\n return {\n ...config,\n cliOptions,\n };\n}\n\n/**\n * Get a Webpack config from a legacy browserify config. This is used to\n * support the legacy config format, and convert it to the new format.\n *\n * @param legacyConfig - The legacy browserify config.\n * @returns The Webpack config.\n */\nexport function getWebpackConfig(\n legacyConfig: ProcessedBrowserifyConfig,\n): ProcessedWebpackConfig {\n const defaultConfig = create(\n { bundler: 'webpack' },\n SnapsWebpackConfigStruct,\n );\n\n // The legacy config has two options for specifying the output path and\n // filename: `bundle`, and `dist` + `outfileName`. If `bundle` is specified,\n // we use that as the output path and filename. Otherwise, we use `dist` and\n // `outfileName`.\n const path = legacyConfig.cliOptions.bundle\n ? dirname(legacyConfig.cliOptions.bundle)\n : legacyConfig.cliOptions.dist;\n\n const filename = legacyConfig.cliOptions.bundle\n ? basename(legacyConfig.cliOptions.bundle)\n : legacyConfig.cliOptions.outfileName;\n\n return {\n ...defaultConfig,\n input: legacyConfig.cliOptions.src,\n evaluate: legacyConfig.cliOptions.eval,\n sourceMap: legacyConfig.cliOptions.sourceMaps,\n output: {\n path,\n filename,\n\n // The legacy config has an option to remove comments from the bundle, but\n // the terser plugin does this by default, so we only enable the terser if\n // the legacy config has `stripComments` set to `true`. This is not a\n // perfect solution, but it's the best we can do without breaking the\n // legacy config.\n minimize: legacyConfig.cliOptions.stripComments,\n\n // The legacy config does not have a `clean` option, so we default to\n // `false` here.\n clean: false,\n },\n manifest: {\n // The legacy config does not have a `manifest` option, so we default to\n // `process.cwd()/snap.manifest.json`.\n path: resolve(process.cwd(), 'snap.manifest.json'),\n update: legacyConfig.cliOptions.writeManifest,\n },\n server: {\n enabled: legacyConfig.cliOptions.serve,\n port: legacyConfig.cliOptions.port,\n root: legacyConfig.cliOptions.root,\n },\n stats: {\n verbose: false,\n\n // These plugins are designed to be used with the modern config format, so\n // we disable them for the legacy config format.\n builtIns: false,\n buffer: false,\n },\n legacy: createFromStruct(\n {\n ...legacyConfig.cliOptions,\n bundlerCustomizer: legacyConfig.bundlerCustomizer,\n },\n LegacyOptionsStruct,\n 'Invalid Browserify CLI options',\n ),\n };\n}\n"],"names":["SnapsBrowserifyConfigStruct","SnapsWebpackConfigStruct","SnapsConfigStruct","LegacyOptionsStruct","getConfig","loadConfig","resolveConfig","getConfigByArgv","mergeLegacyOptions","getWebpackConfig","CONFIG_FILES","CONFIG_FILE","TS_CONFIG_FILE","SnapsBrowserifyBundlerCustomizerFunctionStruct","define","func","validator","object","bundler","defaulted","literal","cliOptions","bundle","optional","file","dist","eval","boolean","manifest","port","number","outfileName","string","root","process","cwd","sourceMaps","src","stripComments","suppressWarnings","transpilationMode","union","depsToTranspile","array","verboseErrors","writeManifest","serve","bundlerCustomizer","SnapsWebpackCustomizeWebpackConfigFunctionStruct","input","resolve","sourceMap","evaluate","output","path","filename","clean","minimize","update","server","enabled","environment","record","unknown","NODE_DEBUG","NODE_ENV","DEBUG","stats","verbose","builtIns","ignore","buffer","polyfills","assert","console","constants","crypto","domain","events","http","https","os","punycode","querystring","stream","_stream_duplex","_stream_passthrough","_stream_readable","_stream_transform","_stream_writable","string_decoder","sys","timers","tty","url","util","vm","zlib","customizeWebpackConfig","experimental","wasm","type","named","TranspilationModes","LocalAndDeps","empty","LocalOnly","None","config","argv","prefix","suffix","dim","createFromStruct","legacyConfig","contents","readFile","source","transform","swcrc","jsc","parser","syntax","module","Module","paths","_nodeModulePaths","dirname","_compile","code","hasProperty","exports","default","error","SnapsStructError","ConfigError","message","indent","configFile","filePath","isFile","Object","keys","reduce","accumulator","key","undefined","defaultConfig","create","basename","legacy"],"mappings":";;;;;;;;;;;IAyeaA,2BAA2B;eAA3BA;;IA0CAC,wBAAwB;eAAxBA;;IAyGAC,iBAAiB;eAAjBA;;IAOAC,mBAAmB;eAAnBA;;IAoDGC,SAAS;eAATA;;IAyCMC,UAAU;eAAVA;;IAmDAC,aAAa;eAAbA;;IAsBAC,eAAe;eAAfA;;IA2BNC,kBAAkB;eAAlBA;;IA8BAC,gBAAgB;eAAhBA;;;0BAl2Be;4BAQxB;uBACqB;sBACF;uBAEN;0BACK;+DACN;sBACwB;6BAiBpC;0BAG4B;wBACP;wBAEgB;;;;;;AAE5C,MAAMC,eAAe;IAACC,mBAAW;IAAEC,sBAAc;CAAC;AAwblD,6EAA6E;AAC7E,6EAA6E;AAC7E,oBAAoB;AACpB,MAAMC,iDACJC,IAAAA,mBAAM,EACJ,YACAC,IAAAA,iBAAI,IAAGC,SAAS;AAGb,MAAMhB,8BAA8BiB,IAAAA,mBAAM,EAAC;IAChDC,SAASC,IAAAA,sBAAS,EAACC,IAAAA,iBAAO,EAAC,eAAe;IAC1CC,YAAYF,IAAAA,sBAAS,EACnBF,IAAAA,mBAAM,EAAC;QACLK,QAAQC,IAAAA,qBAAQ,EAACC,IAAAA,gBAAI;QACrBC,MAAMN,IAAAA,sBAAS,EAACK,IAAAA,gBAAI,KAAI;QACxBE,MAAMP,IAAAA,sBAAS,EAACQ,IAAAA,oBAAO,KAAI;QAC3BC,UAAUT,IAAAA,sBAAS,EAACQ,IAAAA,oBAAO,KAAI;QAC/BE,MAAMV,IAAAA,sBAAS,EAACW,IAAAA,mBAAM,KAAI;QAC1BC,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jBE,UAAUyD,aAAa7F,UAAU,CAACiB,aAAa;YAE/C,qEAAqE;YACrE,gBAAgB;YAChBkB,OAAO;QACT;QACA5B,UAAU;YACR,wEAAwE;YACxE,sCAAsC;YACtC0B,MAAMJ,IAAAA,aAAO,EAAChB,QAAQC,GAAG,IAAI;YAC7BuB,QAAQwD,aAAa7F,UAAU,CAACwB,aAAa;QAC/C;QACAc,QAAQ;YACNC,SAASsD,aAAa7F,UAAU,CAACyB,KAAK;YACtCjB,MAAMqF,aAAa7F,UAAU,CAACQ,IAAI;YAClCI,MAAMiF,aAAa7F,UAAU,CAACY,IAAI;QACpC;QACAkC,OAAO;YACLC,SAAS;YAET,0EAA0E;YAC1E,gDAAgD;YAChDC,UAAU;YACVE,QAAQ;QACV;QACA+E,QAAQrC,IAAAA,4BAAgB,EACtB;YACE,GAAGC,aAAa7F,UAAU;YAC1B0B,mBAAmBmE,aAAanE,iBAAiB;QACnD,GACA5C,qBACA;IAEJ;AACF"}
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "default", {
9
9
  }
10
10
  });
11
11
  const _browserify = /*#__PURE__*/ _interop_require_default(require("browserify"));
12
- const _stream = require("stream");
12
+ const _readablestream = require("readable-stream");
13
13
  const _builders = require("../../builders");
14
14
  const _utils = require("../../utils");
15
15
  const _utils1 = require("../utils");
@@ -74,7 +74,7 @@ function _interop_require_default(obj) {
74
74
  config.bundlerCustomizer?.(bundler);
75
75
  // Browserify doesn't accept a string as an entry point, so we need to convert
76
76
  // it to a stream.
77
- const stream = new _stream.Readable();
77
+ const stream = new _readablestream.Readable();
78
78
  stream.push(content);
79
79
  stream.push(null);
80
80
  bundler.add(stream, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/webpack/loaders/browserify.ts"],"sourcesContent":["import browserify from 'browserify';\nimport { Readable } from 'stream';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\nimport { TranspilationModes } from '../../builders';\nimport type { LegacyOptions } from '../../config';\nimport { processDependencies } from '../../utils';\nimport { getBrowserslistTargets } from '../utils';\n\n/**\n * A Browserify loader for Webpack. This exists for backwards compatibility with\n * the legacy configuration format, in order to support the `bundlerCustomizer`\n * function.\n *\n * When this loader is used, the input file will be processed by Browserify, and\n * written to disk by Webpack. Most processing will be handled by Browserify, so\n * there are no benefits like tree-shaking.\n *\n * @param content - The input file contents as a string.\n * @param sourceMap - The source map of the input file.\n */\nconst loader: LoaderDefinitionFunction<LegacyOptions> = async function (\n content,\n sourceMap,\n) {\n const config = this.getOptions();\n\n const { transpilationMode } = config;\n\n const bundler = browserify({\n extensions: ['.js', '.ts'],\n debug: Boolean(sourceMap),\n standalone: '<snap>',\n });\n\n if (transpilationMode !== TranspilationModes.None) {\n const babelifyOptions = processDependencies(config);\n\n // We need to statically import all Browserify transforms, and all Babel\n // presets and plugins, and calling `require` is the sanest way to do that.\n /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n bundler.transform(require('babelify'), {\n global: transpilationMode === TranspilationModes.LocalAndDeps,\n extensions: ['.js', '.ts'],\n presets: [\n require('@babel/preset-typescript'),\n [\n require('@babel/preset-env'),\n {\n targets: {\n browsers: await getBrowserslistTargets(),\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-transform-class-properties'),\n require('@babel/plugin-transform-private-methods'),\n require('@babel/plugin-transform-class-static-block'),\n require('@babel/plugin-transform-private-property-in-object'),\n ],\n ...(babelifyOptions as any),\n });\n /* eslint-enable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n }\n\n config.bundlerCustomizer?.(bundler);\n\n // Browserify doesn't accept a string as an entry point, so we need to convert\n // it to a stream.\n const stream = new Readable();\n stream.push(content);\n stream.push(null);\n\n bundler.add(stream, {\n file: this.resourcePath,\n });\n\n return new Promise<Buffer>((resolve, reject) => {\n bundler.bundle((bundleError, buffer: Buffer) => {\n if (bundleError) {\n reject(bundleError);\n return;\n }\n\n // Browserify inlines the source map, so we just pass the output buffer back\n // to Webpack.\n resolve(buffer);\n });\n });\n};\n\nexport default loader;\n"],"names":["loader","content","sourceMap","config","getOptions","transpilationMode","bundler","browserify","extensions","debug","Boolean","standalone","TranspilationModes","None","babelifyOptions","processDependencies","transform","require","global","LocalAndDeps","presets","targets","browsers","getBrowserslistTargets","plugins","bundlerCustomizer","stream","Readable","push","add","file","resourcePath","Promise","resolve","reject","bundle","bundleError","buffer"],"mappings":";;;;+BA6FA;;;eAAA;;;mEA7FuB;wBACE;0BAGU;uBAEC;wBACG;;;;;;AAEvC;;;;;;;;;;;CAWC,GACD,MAAMA,SAAkD,eACtDC,OAAO,EACPC,SAAS;IAET,MAAMC,SAAS,IAAI,CAACC,UAAU;IAE9B,MAAM,EAAEC,iBAAiB,EAAE,GAAGF;IAE9B,MAAMG,UAAUC,IAAAA,mBAAU,EAAC;QACzBC,YAAY;YAAC;YAAO;SAAM;QAC1BC,OAAOC,QAAQR;QACfS,YAAY;IACd;IAEA,IAAIN,sBAAsBO,4BAAkB,CAACC,IAAI,EAAE;QACjD,MAAMC,kBAAkBC,IAAAA,0BAAmB,EAACZ;QAE5C,wEAAwE;QACxE,2EAA2E;QAC3E,8GAA8G,GAC9GG,QAAQU,SAAS,CAACC,QAAQ,aAAa;YACrCC,QAAQb,sBAAsBO,4BAAkB,CAACO,YAAY;YAC7DX,YAAY;gBAAC;gBAAO;aAAM;YAC1BY,SAAS;gBACPH,QAAQ;gBACR;oBACEA,QAAQ;oBACR;wBACEI,SAAS;4BACPC,UAAU,MAAMC,IAAAA,8BAAsB;wBACxC;oBACF;iBACD;aACF;YACDC,SAAS;gBACPP,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;aACT;YACD,GAAIH,eAAe;QACrB;IACA,6GAA6G,GAC/G;IAEAX,OAAOsB,iBAAiB,GAAGnB;IAE3B,8EAA8E;IAC9E,kBAAkB;IAClB,MAAMoB,SAAS,IAAIC,gBAAQ;IAC3BD,OAAOE,IAAI,CAAC3B;IACZyB,OAAOE,IAAI,CAAC;IAEZtB,QAAQuB,GAAG,CAACH,QAAQ;QAClBI,MAAM,IAAI,CAACC,YAAY;IACzB;IAEA,OAAO,IAAIC,QAAgB,CAACC,SAASC;QACnC5B,QAAQ6B,MAAM,CAAC,CAACC,aAAaC;YAC3B,IAAID,aAAa;gBACfF,OAAOE;gBACP;YACF;YAEA,4EAA4E;YAC5E,cAAc;YACdH,QAAQI;QACV;IACF;AACF;MAEA,WAAerC"}
1
+ {"version":3,"sources":["../../../../src/webpack/loaders/browserify.ts"],"sourcesContent":["import browserify from 'browserify';\nimport { Readable } from 'readable-stream';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\nimport { TranspilationModes } from '../../builders';\nimport type { LegacyOptions } from '../../config';\nimport { processDependencies } from '../../utils';\nimport { getBrowserslistTargets } from '../utils';\n\n/**\n * A Browserify loader for Webpack. This exists for backwards compatibility with\n * the legacy configuration format, in order to support the `bundlerCustomizer`\n * function.\n *\n * When this loader is used, the input file will be processed by Browserify, and\n * written to disk by Webpack. Most processing will be handled by Browserify, so\n * there are no benefits like tree-shaking.\n *\n * @param content - The input file contents as a string.\n * @param sourceMap - The source map of the input file.\n */\nconst loader: LoaderDefinitionFunction<LegacyOptions> = async function (\n content,\n sourceMap,\n) {\n const config = this.getOptions();\n\n const { transpilationMode } = config;\n\n const bundler = browserify({\n extensions: ['.js', '.ts'],\n debug: Boolean(sourceMap),\n standalone: '<snap>',\n });\n\n if (transpilationMode !== TranspilationModes.None) {\n const babelifyOptions = processDependencies(config);\n\n // We need to statically import all Browserify transforms, and all Babel\n // presets and plugins, and calling `require` is the sanest way to do that.\n /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n bundler.transform(require('babelify'), {\n global: transpilationMode === TranspilationModes.LocalAndDeps,\n extensions: ['.js', '.ts'],\n presets: [\n require('@babel/preset-typescript'),\n [\n require('@babel/preset-env'),\n {\n targets: {\n browsers: await getBrowserslistTargets(),\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-transform-class-properties'),\n require('@babel/plugin-transform-private-methods'),\n require('@babel/plugin-transform-class-static-block'),\n require('@babel/plugin-transform-private-property-in-object'),\n ],\n ...(babelifyOptions as any),\n });\n /* eslint-enable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n }\n\n config.bundlerCustomizer?.(bundler);\n\n // Browserify doesn't accept a string as an entry point, so we need to convert\n // it to a stream.\n const stream = new Readable();\n stream.push(content);\n stream.push(null);\n\n bundler.add(stream, {\n file: this.resourcePath,\n });\n\n return new Promise<Buffer>((resolve, reject) => {\n bundler.bundle((bundleError, buffer: Buffer) => {\n if (bundleError) {\n reject(bundleError);\n return;\n }\n\n // Browserify inlines the source map, so we just pass the output buffer back\n // to Webpack.\n resolve(buffer);\n });\n });\n};\n\nexport default loader;\n"],"names":["loader","content","sourceMap","config","getOptions","transpilationMode","bundler","browserify","extensions","debug","Boolean","standalone","TranspilationModes","None","babelifyOptions","processDependencies","transform","require","global","LocalAndDeps","presets","targets","browsers","getBrowserslistTargets","plugins","bundlerCustomizer","stream","Readable","push","add","file","resourcePath","Promise","resolve","reject","bundle","bundleError","buffer"],"mappings":";;;;+BA6FA;;;eAAA;;;mEA7FuB;gCACE;0BAGU;uBAEC;wBACG;;;;;;AAEvC;;;;;;;;;;;CAWC,GACD,MAAMA,SAAkD,eACtDC,OAAO,EACPC,SAAS;IAET,MAAMC,SAAS,IAAI,CAACC,UAAU;IAE9B,MAAM,EAAEC,iBAAiB,EAAE,GAAGF;IAE9B,MAAMG,UAAUC,IAAAA,mBAAU,EAAC;QACzBC,YAAY;YAAC;YAAO;SAAM;QAC1BC,OAAOC,QAAQR;QACfS,YAAY;IACd;IAEA,IAAIN,sBAAsBO,4BAAkB,CAACC,IAAI,EAAE;QACjD,MAAMC,kBAAkBC,IAAAA,0BAAmB,EAACZ;QAE5C,wEAAwE;QACxE,2EAA2E;QAC3E,8GAA8G,GAC9GG,QAAQU,SAAS,CAACC,QAAQ,aAAa;YACrCC,QAAQb,sBAAsBO,4BAAkB,CAACO,YAAY;YAC7DX,YAAY;gBAAC;gBAAO;aAAM;YAC1BY,SAAS;gBACPH,QAAQ;gBACR;oBACEA,QAAQ;oBACR;wBACEI,SAAS;4BACPC,UAAU,MAAMC,IAAAA,8BAAsB;wBACxC;oBACF;iBACD;aACF;YACDC,SAAS;gBACPP,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;aACT;YACD,GAAIH,eAAe;QACrB;IACA,6GAA6G,GAC/G;IAEAX,OAAOsB,iBAAiB,GAAGnB;IAE3B,8EAA8E;IAC9E,kBAAkB;IAClB,MAAMoB,SAAS,IAAIC,wBAAQ;IAC3BD,OAAOE,IAAI,CAAC3B;IACZyB,OAAOE,IAAI,CAAC;IAEZtB,QAAQuB,GAAG,CAACH,QAAQ;QAClBI,MAAM,IAAI,CAACC,YAAY;IACzB;IAEA,OAAO,IAAIC,QAAgB,CAACC,SAASC;QACnC5B,QAAQ6B,MAAM,CAAC,CAACC,aAAaC;YAC3B,IAAID,aAAa;gBACfF,OAAOE;gBACP;YACF;YAEA,4EAA4E;YAC5E,cAAc;YACdH,QAAQI;QACV;IACF;AACF;MAEA,WAAerC"}
@@ -1,4 +1,5 @@
1
- import { createFromStruct, file, indent, isFile, literal, union, SnapsStructError, named } from '@metamask/snaps-utils';
1
+ import { literal, union } from '@metamask/snaps-sdk';
2
+ import { createFromStruct, file, indent, isFile, SnapsStructError, named } from '@metamask/snaps-utils';
2
3
  import { hasProperty } from '@metamask/utils';
3
4
  import { transform } from '@swc/core';
4
5
  import { dim } from 'chalk';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config.ts"],"sourcesContent":["import {\n createFromStruct,\n file,\n indent,\n isFile,\n literal,\n union,\n SnapsStructError,\n named,\n} from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\nimport { transform } from '@swc/core';\nimport type { BrowserifyObject } from 'browserify';\nimport { dim } from 'chalk';\nimport { readFile } from 'fs/promises';\nimport Module from 'module';\nimport { basename, dirname, resolve } from 'path';\nimport type { Infer } from 'superstruct';\nimport {\n array,\n boolean,\n create,\n defaulted,\n define,\n func,\n number,\n object,\n optional,\n record,\n string,\n type,\n unknown,\n empty,\n} from 'superstruct';\nimport type { Configuration as WebpackConfiguration } from 'webpack';\n\nimport { TranspilationModes } from './builders';\nimport { ConfigError } from './errors';\nimport type { YargsArgs } from './types/yargs';\nimport { CONFIG_FILE, TS_CONFIG_FILE } from './utils';\n\nconst CONFIG_FILES = [CONFIG_FILE, TS_CONFIG_FILE];\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n *\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\nexport type SnapBrowserifyConfig = {\n /**\n * The bundler to use to build the snap. For backwards compatibility, if not\n * specified, Browserify will be used. However, the Browserify bundler is\n * deprecated and will be removed in a future release, so it's recommended to\n * use the Webpack bundler instead.\n */\n bundler?: 'browserify';\n\n /**\n * The options for the Snaps CLI. These are merged with the options passed to\n * the CLI, with the CLI options taking precedence.\n *\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\n cliOptions?: {\n /**\n * The path to the snap bundle file.\n *\n * @default 'dist/bundle.js'\n */\n bundle?: string;\n\n /**\n * The directory to output the snap to. This is only used if `bundle` is\n * not specified.\n *\n * @default 'dist'\n */\n dist?: string;\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n eval?: boolean;\n\n /**\n * Whether to validate the snap manifest.\n *\n * @default true\n */\n manifest?: boolean;\n\n /**\n * The name of the bundle file. This is only used if `bundle` is not\n * specified.\n *\n * @default 'bundle.js'\n */\n outfileName?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n\n /**\n * The root directory to serve the snap from.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * Whether to generate source maps for the snap bundle.\n *\n * @default false\n */\n sourceMaps?: boolean;\n\n /**\n * The path to the snap entry point.\n *\n * @default 'src/index.js'\n */\n src?: string;\n\n /**\n * Whether to remove comments from the bundle.\n *\n * @default true\n */\n stripComments?: boolean;\n\n /**\n * Whether to suppress warnings.\n *\n * @default false\n */\n suppressWarnings?: boolean;\n\n /**\n * The transpilation mode to use, which determines which files are\n * transpiled.\n *\n * - `'localAndDeps'`: Transpile the snap entry point and all dependencies.\n * - `'localOnly'`: Transpile only the snap entry point.\n * - `'none'`: Don't transpile any files.\n *\n * @default 'localOnly'\n */\n transpilationMode?: 'localAndDeps' | 'localOnly' | 'none';\n\n /**\n * The dependencies to transpile when `transpilationMode` is set to\n * `'localAndDeps'`. If not specified, all dependencies will be transpiled.\n */\n depsToTranspile?: string[];\n\n /**\n * Whether to show original errors.\n *\n * @default true\n */\n verboseErrors?: boolean;\n\n /**\n * Whether to write the updated manifest to disk.\n *\n * @default true\n */\n writeManifest?: boolean;\n\n /**\n * Whether to serve the snap locally.\n *\n * @default true\n */\n serve?: boolean;\n };\n\n /**\n * A function that can be used to customize the Browserify instance used to\n * build the snap.\n *\n * @param bundler - The Browserify instance.\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\n bundlerCustomizer?: (bundler: BrowserifyObject) => void;\n};\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapWebpackConfig = {\n /**\n * The bundler to use to build the snap. For backwards compatibility, if not\n * specified, Browserify will be used. However, the Browserify bundler is\n * deprecated and will be removed in a future release, so it's recommended to\n * use the Webpack bundler instead.\n */\n bundler: 'webpack';\n\n /**\n * The path to the snap entry point. This should be a JavaScript or TypeScript\n * file.\n */\n input: string;\n\n /**\n * Whether to generate source maps for the snap. If `true`, source maps will\n * be generated as separate files. If `'inline'`, source maps will be\n * inlined in the generated JavaScript bundle.\n *\n * @default true\n */\n sourceMap?: boolean | 'inline';\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n evaluate?: boolean;\n\n output?: {\n /**\n * The path to the directory where the snap will be built. This directory\n * will be created if it doesn't exist.\n *\n * If the path is relative, it will be resolved relative to the current\n * working directory.\n *\n * @default 'dist'\n */\n path?: string;\n\n /**\n * The name of the JavaScript bundle file.\n *\n * @default 'bundle.js'\n */\n filename?: string;\n\n /**\n * Whether to clean the output directory before building the snap. If\n * `true`, the output directory will be deleted and recreated. Otherwise,\n * the output directory will be left as-is.\n *\n * @default false\n */\n clean?: boolean;\n\n /**\n * Whether to minimize the snap bundle. If `true`, the bundle will be\n * minified. Otherwise, the bundle will be left as-is.\n *\n * @default true\n */\n minimize?: boolean;\n };\n\n manifest?: {\n /**\n * The path to the snap manifest file. If the path is relative, it will be\n * resolved relative to the current working directory.\n *\n * @default 'snap.manifest.json'\n */\n path?: string;\n\n /**\n * Whether to automatically update the manifest. If `true`, the manifest\n * will be updated with the latest shasum of the snap bundle, and some\n * common fields will be updated if they are missing or incorrect. If\n * `false`, the manifest will be left as-is.\n *\n * @default true\n */\n update?: boolean;\n };\n\n server?: {\n /**\n * Whether to enable the local server. If `true`, the snap will be served\n * from a local server, when running the `watch` command. If `false`, the\n * snap will not be served.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * The root directory to serve the snap from. If the path is relative, it\n * will be resolved relative to the current working directory.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n };\n\n /**\n * The environment variables to set when building the snap. These will be\n * available in the snap as `process.env`. In addition to these environment\n * variables, the following environment variables will always be set:\n *\n * - `NODE_DEBUG`: `false`\n * - `NODE_ENV`: `'production'`\n * - `DEBUG`: `false`\n *\n * Any environment variables specified here will override these defaults. You\n * can also override any variables here by setting them in your shell when\n * running the CLI.\n */\n environment?: Record<string, unknown>;\n\n /**\n * Options that control the logging output of the CLI.\n */\n stats?: {\n /**\n * Whether to enable verbose logging.\n *\n * @default false\n */\n verbose?: boolean;\n\n /**\n * Whether to log warnings about unresolved built-in modules. If `false`,\n * warnings will not be logged.\n */\n builtIns?:\n | {\n /**\n * The built-in modules to ignore when resolving modules. If a module\n * is ignored, no warning will be logged if it is not resolved.\n */\n ignore?: string[];\n }\n | false;\n\n /**\n * Whether to log warnings about the use of the `Buffer` global. If `false`,\n * warnings will not be logged. If `true`, the CLI will warn if the `Buffer`\n * global is used, but not provided by Webpack's `DefinePlugin`.\n */\n buffer?: boolean;\n };\n\n /**\n * Whether to provide polyfills for node builtins. If `true`, all the available\n * polyfills will be provided. If `false` no polyfills will be provided. If a\n * configuration object is passed only the polyfills set to `true` will be provided.\n *\n * @default false\n * @example\n * ```ts\n * polyfills: true\n *\n * // or\n *\n * polyfills: {\n * assert: true,\n * buffer: true\n * }\n * ```\n */\n polyfills?:\n | boolean\n | {\n assert?: boolean;\n buffer?: boolean;\n console?: boolean;\n constants?: boolean;\n crypto?: boolean;\n domain?: boolean;\n events?: boolean;\n http?: boolean;\n https?: boolean;\n os?: boolean;\n path?: boolean;\n punycode?: boolean;\n process?: boolean;\n querystring?: boolean;\n stream?: boolean;\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex?: boolean;\n _stream_passthrough?: boolean;\n _stream_readable?: boolean;\n _stream_transform?: boolean;\n _stream_writable?: boolean;\n string_decoder?: boolean;\n /* eslint-enable @typescript-eslint/naming-convention */\n sys?: boolean;\n timers?: boolean;\n tty?: boolean;\n url?: boolean;\n util?: boolean;\n vm?: boolean;\n zlib?: boolean;\n };\n\n /**\n * A function to customize the Webpack configuration used to build the snap.\n * This function will be called with the default Webpack configuration, and\n * should return the modified configuration. If not specified, the default\n * configuration will be used.\n *\n * It's recommended to use the `webpack-merge` package to merge the default\n * configuration with your customizations. The merge function is exported as\n * `merge` from the `@metamask/snaps-cli` package.\n *\n * @example\n * ```ts\n * import type { SnapsConfig } from '@metamask/snaps-cli';\n * import { merge } from '@metamask/snaps-cli';\n *\n * const config: SnapsConfig = {\n * bundler: 'webpack',\n * entry: 'src/index.ts',\n * customizeWebpackConfig: (config) => merge(config, {\n * module: {\n * rules: [\n * {\n * test: /\\.wasm$/,\n * type: 'assets/resource',\n * },\n * ],\n * },\n * }),\n * };\n *\n * export default config;\n * ```\n */\n customizeWebpackConfig?: (\n config: WebpackConfiguration,\n ) => WebpackConfiguration;\n\n /**\n * Experimental features that can be enabled. These features are not\n * guaranteed to be stable, and may be removed or changed in a future release.\n */\n experimental?: {\n /**\n * Whether to enable WebAssembly support. If `true`, the Webpack\n * configuration will be modified to support WebAssembly. If `false`, the\n * Webpack configuration will not be modified.\n *\n * @default false\n */\n wasm?: boolean;\n };\n};\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapConfig = SnapBrowserifyConfig | SnapWebpackConfig;\n\ntype SnapsBrowserifyBundlerCustomizerFunction = (\n bundler: BrowserifyObject,\n) => void;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsBrowserifyBundlerCustomizerFunctionStruct =\n define<SnapsBrowserifyBundlerCustomizerFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsBrowserifyConfigStruct = object({\n bundler: defaulted(literal('browserify'), 'browserify'),\n cliOptions: defaulted(\n object({\n bundle: optional(file()),\n dist: defaulted(file(), 'dist'),\n eval: defaulted(boolean(), true),\n manifest: defaulted(boolean(), true),\n port: defaulted(number(), 8081),\n outfileName: defaulted(string(), 'bundle.js'),\n root: defaulted(file(), process.cwd()),\n sourceMaps: defaulted(boolean(), false),\n src: defaulted(file(), 'src/index.js'),\n stripComments: defaulted(boolean(), true),\n suppressWarnings: defaulted(boolean(), false),\n transpilationMode: defaulted(\n union([literal('localAndDeps'), literal('localOnly'), literal('none')]),\n 'localOnly',\n ),\n depsToTranspile: defaulted(array(string()), []),\n verboseErrors: defaulted(boolean(), true),\n writeManifest: defaulted(boolean(), true),\n serve: defaulted(boolean(), true),\n }),\n {},\n ),\n bundlerCustomizer: optional(SnapsBrowserifyBundlerCustomizerFunctionStruct),\n});\n\ntype SnapsWebpackCustomizeWebpackConfigFunction = (\n config: WebpackConfiguration,\n) => WebpackConfiguration;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsWebpackCustomizeWebpackConfigFunctionStruct =\n define<SnapsWebpackCustomizeWebpackConfigFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsWebpackConfigStruct = object({\n bundler: literal('webpack'),\n input: defaulted(file(), resolve(process.cwd(), 'src/index.js')),\n sourceMap: defaulted(union([boolean(), literal('inline')]), true),\n evaluate: defaulted(boolean(), true),\n\n output: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'dist')),\n filename: defaulted(string(), 'bundle.js'),\n clean: defaulted(boolean(), false),\n minimize: defaulted(boolean(), true),\n }),\n {},\n ),\n\n manifest: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'snap.manifest.json')),\n update: defaulted(boolean(), true),\n }),\n {},\n ),\n\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n root: defaulted(file(), process.cwd()),\n port: defaulted(number(), 8081),\n }),\n {},\n ),\n\n environment: defaulted(record(string(), unknown()), {\n NODE_DEBUG: false,\n NODE_ENV: 'production',\n DEBUG: false,\n }),\n\n stats: defaulted(\n object({\n verbose: defaulted(boolean(), false),\n builtIns: defaulted(\n union([\n object({ ignore: defaulted(array(string()), []) }),\n literal(false),\n ]),\n {},\n ),\n buffer: defaulted(boolean(), true),\n }),\n {},\n ),\n\n polyfills: defaulted(\n union([\n boolean(),\n object({\n assert: defaulted(boolean(), false),\n buffer: defaulted(boolean(), false),\n console: defaulted(boolean(), false),\n constants: defaulted(boolean(), false),\n crypto: defaulted(boolean(), false),\n domain: defaulted(boolean(), false),\n events: defaulted(boolean(), false),\n http: defaulted(boolean(), false),\n https: defaulted(boolean(), false),\n os: defaulted(boolean(), false),\n path: defaulted(boolean(), false),\n punycode: defaulted(boolean(), false),\n process: defaulted(boolean(), false),\n querystring: defaulted(boolean(), false),\n stream: defaulted(boolean(), false),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: defaulted(boolean(), false),\n _stream_passthrough: defaulted(boolean(), false),\n _stream_readable: defaulted(boolean(), false),\n _stream_transform: defaulted(boolean(), false),\n _stream_writable: defaulted(boolean(), false),\n string_decoder: defaulted(boolean(), false),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: defaulted(boolean(), false),\n timers: defaulted(boolean(), false),\n tty: defaulted(boolean(), false),\n url: defaulted(boolean(), false),\n util: defaulted(boolean(), false),\n vm: defaulted(boolean(), false),\n zlib: defaulted(boolean(), false),\n }),\n ]),\n false,\n ),\n\n customizeWebpackConfig: optional(\n SnapsWebpackCustomizeWebpackConfigFunctionStruct,\n ),\n\n experimental: defaulted(\n object({\n wasm: defaulted(boolean(), false),\n }),\n {},\n ),\n});\n\nexport const SnapsConfigStruct = type({\n bundler: defaulted(\n union([literal('browserify'), literal('webpack')]),\n 'browserify',\n ),\n});\n\nexport const LegacyOptionsStruct = union([\n named(\n 'object with `transpilationMode` set to `localAndDeps` and `depsToTranspile` set to an array of strings',\n type({\n depsToTranspile: array(string()),\n transpilationMode: literal(TranspilationModes.LocalAndDeps),\n writeManifest: boolean(),\n bundlerCustomizer: optional(\n SnapsBrowserifyBundlerCustomizerFunctionStruct,\n ),\n }),\n ),\n named(\n 'object without `depsToTranspile`',\n type({\n depsToTranspile: named('empty array', empty(array())),\n transpilationMode: union([\n literal(TranspilationModes.LocalOnly),\n literal(TranspilationModes.None),\n ]),\n writeManifest: boolean(),\n bundlerCustomizer: optional(\n SnapsBrowserifyBundlerCustomizerFunctionStruct,\n ),\n }),\n ),\n]);\n\nexport type LegacyOptions = Infer<typeof LegacyOptionsStruct>;\n\nexport type ProcessedBrowserifyConfig = Infer<\n typeof SnapsBrowserifyConfigStruct\n>;\n\nexport type ProcessedWebpackConfig = Infer<typeof SnapsWebpackConfigStruct> & {\n /**\n * The legacy Browserify config, if the bundler is Browserify. This is used\n * to support the legacy config format.\n */\n legacy?: LegacyOptions;\n};\n\nexport type ProcessedConfig = ProcessedWebpackConfig;\n\n/**\n * Get a validated snap config. This validates the config and adds default\n * values for any missing properties.\n *\n * @param config - The config to validate.\n * @param argv - The CLI arguments.\n * @returns The validated config.\n */\nexport function getConfig(config: unknown, argv: YargsArgs): ProcessedConfig {\n const prefix = 'The snap config file is invalid';\n const suffix = dim(\n // TODO: Link to `docs.metamask.io` once the docs are published.\n 'Refer to the documentation for more information: https://github.com/MetaMask/snaps/tree/main/packages/snaps-cli/',\n );\n\n const { bundler } = createFromStruct(\n config,\n SnapsConfigStruct,\n prefix,\n suffix,\n );\n\n if (bundler === 'browserify') {\n const legacyConfig = createFromStruct(\n config,\n SnapsBrowserifyConfigStruct,\n prefix,\n suffix,\n );\n\n return getWebpackConfig(mergeLegacyOptions(argv, legacyConfig));\n }\n\n return createFromStruct(config, SnapsWebpackConfigStruct, prefix, suffix);\n}\n\n/**\n * Load a snap config from a file. This supports both JavaScript and TypeScript\n * config files, in the CommonJS module format and the ES module format.\n *\n * This assumes that the config file exports a default object, either through\n * `module.exports` or `export default`.\n *\n * @param path - The full path to the config file.\n * @param argv - The CLI arguments.\n * @returns The validated config.\n * @throws If the config file is invalid, or if the config file does not have a\n * default export.\n */\nexport async function loadConfig(path: string, argv: YargsArgs) {\n try {\n const contents = await readFile(path, 'utf8');\n const source = await transform(contents, {\n swcrc: false,\n jsc: {\n parser: {\n syntax: 'typescript',\n },\n },\n module: {\n type: 'commonjs',\n },\n });\n\n const config = new Module(path);\n\n // @ts-expect-error - This function is not typed.\n config.paths = Module._nodeModulePaths(dirname(path));\n\n // @ts-expect-error - This function is not typed.\n config._compile(source.code, path);\n\n if (!hasProperty(config.exports, 'default')) {\n return getConfig(config.exports, argv);\n }\n\n return getConfig(config.exports.default, argv);\n } catch (error) {\n if (error instanceof SnapsStructError) {\n throw new ConfigError(error.message);\n }\n\n throw new ConfigError(\n `Unable to load snap config file at \"${path}\".\\n\\n${indent(\n error.message,\n )}`,\n );\n }\n}\n\n/**\n * Resolve a snap config. This function will look for a `snap.config.js` or\n * `snap.config.ts` file in the current or specified directory.\n *\n * @param path - The path to resolve the snap config from. Defaults to the\n * current working directory.\n * @param argv - The CLI arguments.\n * @returns The resolved and validated snap config.\n * @throws If a snap config could not be found.\n */\nexport async function resolveConfig(path: string, argv: YargsArgs) {\n for (const configFile of CONFIG_FILES) {\n const filePath = resolve(path, configFile);\n if (await isFile(filePath)) {\n return await loadConfig(filePath, argv);\n }\n }\n\n throw new ConfigError(\n `Could not find a \"snap.config.js\" or \"snap.config.ts\" file in the current or specified directory (\"${path}\").`,\n );\n}\n\n/**\n * Get a snap config from the CLI arguments. This will either load the config\n * from the specified config file, or resolve the config from the current\n * working directory.\n *\n * @param argv - The CLI arguments.\n * @param cwd - The current working directory. Defaults to `process.cwd()`.\n * @returns The resolved and validated snap config.\n */\nexport async function getConfigByArgv(\n argv: YargsArgs,\n cwd: string = process.cwd(),\n) {\n if (argv.config) {\n if (!(await isFile(argv.config))) {\n throw new ConfigError(\n `Could not find a config file at \"${argv.config}\". Make sure that the path is correct.`,\n );\n }\n\n return await loadConfig(argv.config, argv);\n }\n\n return await resolveConfig(cwd, argv);\n}\n\n/**\n * Merge legacy CLI options into the config. This is used to support the legacy\n * config format, where options can be specified both in the config file and\n * through CLI flags.\n *\n * @param argv - The CLI arguments.\n * @param config - The config to merge the CLI options into.\n * @returns The config with the CLI options merged in.\n * @deprecated This function is only used to support the legacy config format.\n */\nexport function mergeLegacyOptions(\n argv: YargsArgs,\n config: ProcessedBrowserifyConfig,\n) {\n const cliOptions = Object.keys(config.cliOptions).reduce<\n ProcessedBrowserifyConfig['cliOptions']\n >((accumulator, key) => {\n if (argv[key] !== undefined) {\n return {\n ...accumulator,\n [key]: argv[key],\n };\n }\n\n return accumulator;\n }, config.cliOptions);\n\n return {\n ...config,\n cliOptions,\n };\n}\n\n/**\n * Get a Webpack config from a legacy browserify config. This is used to\n * support the legacy config format, and convert it to the new format.\n *\n * @param legacyConfig - The legacy browserify config.\n * @returns The Webpack config.\n */\nexport function getWebpackConfig(\n legacyConfig: ProcessedBrowserifyConfig,\n): ProcessedWebpackConfig {\n const defaultConfig = create(\n { bundler: 'webpack' },\n SnapsWebpackConfigStruct,\n );\n\n // The legacy config has two options for specifying the output path and\n // filename: `bundle`, and `dist` + `outfileName`. If `bundle` is specified,\n // we use that as the output path and filename. Otherwise, we use `dist` and\n // `outfileName`.\n const path = legacyConfig.cliOptions.bundle\n ? dirname(legacyConfig.cliOptions.bundle)\n : legacyConfig.cliOptions.dist;\n\n const filename = legacyConfig.cliOptions.bundle\n ? basename(legacyConfig.cliOptions.bundle)\n : legacyConfig.cliOptions.outfileName;\n\n return {\n ...defaultConfig,\n input: legacyConfig.cliOptions.src,\n evaluate: legacyConfig.cliOptions.eval,\n sourceMap: legacyConfig.cliOptions.sourceMaps,\n output: {\n path,\n filename,\n\n // The legacy config has an option to remove comments from the bundle, but\n // the terser plugin does this by default, so we only enable the terser if\n // the legacy config has `stripComments` set to `true`. This is not a\n // perfect solution, but it's the best we can do without breaking the\n // legacy config.\n minimize: legacyConfig.cliOptions.stripComments,\n\n // The legacy config does not have a `clean` option, so we default to\n // `false` here.\n clean: false,\n },\n manifest: {\n // The legacy config does not have a `manifest` option, so we default to\n // `process.cwd()/snap.manifest.json`.\n path: resolve(process.cwd(), 'snap.manifest.json'),\n update: legacyConfig.cliOptions.writeManifest,\n },\n server: {\n enabled: legacyConfig.cliOptions.serve,\n port: legacyConfig.cliOptions.port,\n root: legacyConfig.cliOptions.root,\n },\n stats: {\n verbose: false,\n\n // These plugins are designed to be used with the modern config format, so\n // we disable them for the legacy config format.\n builtIns: false,\n buffer: false,\n },\n legacy: createFromStruct(\n {\n ...legacyConfig.cliOptions,\n bundlerCustomizer: legacyConfig.bundlerCustomizer,\n },\n LegacyOptionsStruct,\n 'Invalid Browserify CLI options',\n ),\n };\n}\n"],"names":["createFromStruct","file","indent","isFile","literal","union","SnapsStructError","named","hasProperty","transform","dim","readFile","Module","basename","dirname","resolve","array","boolean","create","defaulted","define","func","number","object","optional","record","string","type","unknown","empty","TranspilationModes","ConfigError","CONFIG_FILE","TS_CONFIG_FILE","CONFIG_FILES","SnapsBrowserifyBundlerCustomizerFunctionStruct","validator","SnapsBrowserifyConfigStruct","bundler","cliOptions","bundle","dist","eval","manifest","port","outfileName","root","process","cwd","sourceMaps","src","stripComments","suppressWarnings","transpilationMode","depsToTranspile","verboseErrors","writeManifest","serve","bundlerCustomizer","SnapsWebpackCustomizeWebpackConfigFunctionStruct","SnapsWebpackConfigStruct","input","sourceMap","evaluate","output","path","filename","clean","minimize","update","server","enabled","environment","NODE_DEBUG","NODE_ENV","DEBUG","stats","verbose","builtIns","ignore","buffer","polyfills","assert","console","constants","crypto","domain","events","http","https","os","punycode","querystring","stream","_stream_duplex","_stream_passthrough","_stream_readable","_stream_transform","_stream_writable","string_decoder","sys","timers","tty","url","util","vm","zlib","customizeWebpackConfig","experimental","wasm","SnapsConfigStruct","LegacyOptionsStruct","LocalAndDeps","LocalOnly","None","getConfig","config","argv","prefix","suffix","legacyConfig","getWebpackConfig","mergeLegacyOptions","loadConfig","contents","source","swcrc","jsc","parser","syntax","module","paths","_nodeModulePaths","_compile","code","exports","default","error","message","resolveConfig","configFile","filePath","getConfigByArgv","Object","keys","reduce","accumulator","key","undefined","defaultConfig","legacy"],"mappings":"AAAA,SACEA,gBAAgB,EAChBC,IAAI,EACJC,MAAM,EACNC,MAAM,EACNC,OAAO,EACPC,KAAK,EACLC,gBAAgB,EAChBC,KAAK,QACA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M0E,aAAajF,UAAU,CAACO,IAAI;QACpC;QACA8B,OAAO;YACLC,SAAS;YAET,0EAA0E;YAC1E,gDAAgD;YAChDC,UAAU;YACVE,QAAQ;QACV;QACAsE,QAAQtJ,iBACN;YACE,GAAGwH,aAAajF,UAAU;YAC1BmB,mBAAmB8D,aAAa9D,iBAAiB;QACnD,GACAqD,qBACA;IAEJ;AACF"}
1
+ {"version":3,"sources":["../../src/config.ts"],"sourcesContent":["import { literal, union } from '@metamask/snaps-sdk';\nimport {\n createFromStruct,\n file,\n indent,\n isFile,\n SnapsStructError,\n named,\n} from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\nimport { transform } from '@swc/core';\nimport type { BrowserifyObject } from 'browserify';\nimport { dim } from 'chalk';\nimport { readFile } from 'fs/promises';\nimport Module from 'module';\nimport { basename, dirname, resolve } from 'path';\nimport type { Infer } from 'superstruct';\nimport {\n array,\n boolean,\n create,\n defaulted,\n define,\n func,\n number,\n object,\n optional,\n record,\n string,\n type,\n unknown,\n empty,\n} from 'superstruct';\nimport type { Configuration as WebpackConfiguration } from 'webpack';\n\nimport { TranspilationModes } from './builders';\nimport { ConfigError } from './errors';\nimport type { YargsArgs } from './types/yargs';\nimport { CONFIG_FILE, TS_CONFIG_FILE } from './utils';\n\nconst CONFIG_FILES = [CONFIG_FILE, TS_CONFIG_FILE];\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n *\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\nexport type SnapBrowserifyConfig = {\n /**\n * The bundler to use to build the snap. For backwards compatibility, if not\n * specified, Browserify will be used. However, the Browserify bundler is\n * deprecated and will be removed in a future release, so it's recommended to\n * use the Webpack bundler instead.\n */\n bundler?: 'browserify';\n\n /**\n * The options for the Snaps CLI. These are merged with the options passed to\n * the CLI, with the CLI options taking precedence.\n *\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\n cliOptions?: {\n /**\n * The path to the snap bundle file.\n *\n * @default 'dist/bundle.js'\n */\n bundle?: string;\n\n /**\n * The directory to output the snap to. This is only used if `bundle` is\n * not specified.\n *\n * @default 'dist'\n */\n dist?: string;\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n eval?: boolean;\n\n /**\n * Whether to validate the snap manifest.\n *\n * @default true\n */\n manifest?: boolean;\n\n /**\n * The name of the bundle file. This is only used if `bundle` is not\n * specified.\n *\n * @default 'bundle.js'\n */\n outfileName?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n\n /**\n * The root directory to serve the snap from.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * Whether to generate source maps for the snap bundle.\n *\n * @default false\n */\n sourceMaps?: boolean;\n\n /**\n * The path to the snap entry point.\n *\n * @default 'src/index.js'\n */\n src?: string;\n\n /**\n * Whether to remove comments from the bundle.\n *\n * @default true\n */\n stripComments?: boolean;\n\n /**\n * Whether to suppress warnings.\n *\n * @default false\n */\n suppressWarnings?: boolean;\n\n /**\n * The transpilation mode to use, which determines which files are\n * transpiled.\n *\n * - `'localAndDeps'`: Transpile the snap entry point and all dependencies.\n * - `'localOnly'`: Transpile only the snap entry point.\n * - `'none'`: Don't transpile any files.\n *\n * @default 'localOnly'\n */\n transpilationMode?: 'localAndDeps' | 'localOnly' | 'none';\n\n /**\n * The dependencies to transpile when `transpilationMode` is set to\n * `'localAndDeps'`. If not specified, all dependencies will be transpiled.\n */\n depsToTranspile?: string[];\n\n /**\n * Whether to show original errors.\n *\n * @default true\n */\n verboseErrors?: boolean;\n\n /**\n * Whether to write the updated manifest to disk.\n *\n * @default true\n */\n writeManifest?: boolean;\n\n /**\n * Whether to serve the snap locally.\n *\n * @default true\n */\n serve?: boolean;\n };\n\n /**\n * A function that can be used to customize the Browserify instance used to\n * build the snap.\n *\n * @param bundler - The Browserify instance.\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\n bundlerCustomizer?: (bundler: BrowserifyObject) => void;\n};\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapWebpackConfig = {\n /**\n * The bundler to use to build the snap. For backwards compatibility, if not\n * specified, Browserify will be used. However, the Browserify bundler is\n * deprecated and will be removed in a future release, so it's recommended to\n * use the Webpack bundler instead.\n */\n bundler: 'webpack';\n\n /**\n * The path to the snap entry point. This should be a JavaScript or TypeScript\n * file.\n */\n input: string;\n\n /**\n * Whether to generate source maps for the snap. If `true`, source maps will\n * be generated as separate files. If `'inline'`, source maps will be\n * inlined in the generated JavaScript bundle.\n *\n * @default true\n */\n sourceMap?: boolean | 'inline';\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n evaluate?: boolean;\n\n output?: {\n /**\n * The path to the directory where the snap will be built. This directory\n * will be created if it doesn't exist.\n *\n * If the path is relative, it will be resolved relative to the current\n * working directory.\n *\n * @default 'dist'\n */\n path?: string;\n\n /**\n * The name of the JavaScript bundle file.\n *\n * @default 'bundle.js'\n */\n filename?: string;\n\n /**\n * Whether to clean the output directory before building the snap. If\n * `true`, the output directory will be deleted and recreated. Otherwise,\n * the output directory will be left as-is.\n *\n * @default false\n */\n clean?: boolean;\n\n /**\n * Whether to minimize the snap bundle. If `true`, the bundle will be\n * minified. Otherwise, the bundle will be left as-is.\n *\n * @default true\n */\n minimize?: boolean;\n };\n\n manifest?: {\n /**\n * The path to the snap manifest file. If the path is relative, it will be\n * resolved relative to the current working directory.\n *\n * @default 'snap.manifest.json'\n */\n path?: string;\n\n /**\n * Whether to automatically update the manifest. If `true`, the manifest\n * will be updated with the latest shasum of the snap bundle, and some\n * common fields will be updated if they are missing or incorrect. If\n * `false`, the manifest will be left as-is.\n *\n * @default true\n */\n update?: boolean;\n };\n\n server?: {\n /**\n * Whether to enable the local server. If `true`, the snap will be served\n * from a local server, when running the `watch` command. If `false`, the\n * snap will not be served.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * The root directory to serve the snap from. If the path is relative, it\n * will be resolved relative to the current working directory.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n };\n\n /**\n * The environment variables to set when building the snap. These will be\n * available in the snap as `process.env`. In addition to these environment\n * variables, the following environment variables will always be set:\n *\n * - `NODE_DEBUG`: `false`\n * - `NODE_ENV`: `'production'`\n * - `DEBUG`: `false`\n *\n * Any environment variables specified here will override these defaults. You\n * can also override any variables here by setting them in your shell when\n * running the CLI.\n */\n environment?: Record<string, unknown>;\n\n /**\n * Options that control the logging output of the CLI.\n */\n stats?: {\n /**\n * Whether to enable verbose logging.\n *\n * @default false\n */\n verbose?: boolean;\n\n /**\n * Whether to log warnings about unresolved built-in modules. If `false`,\n * warnings will not be logged.\n */\n builtIns?:\n | {\n /**\n * The built-in modules to ignore when resolving modules. If a module\n * is ignored, no warning will be logged if it is not resolved.\n */\n ignore?: string[];\n }\n | false;\n\n /**\n * Whether to log warnings about the use of the `Buffer` global. If `false`,\n * warnings will not be logged. If `true`, the CLI will warn if the `Buffer`\n * global is used, but not provided by Webpack's `DefinePlugin`.\n */\n buffer?: boolean;\n };\n\n /**\n * Whether to provide polyfills for node builtins. If `true`, all the available\n * polyfills will be provided. If `false` no polyfills will be provided. If a\n * configuration object is passed only the polyfills set to `true` will be provided.\n *\n * @default false\n * @example\n * ```ts\n * polyfills: true\n *\n * // or\n *\n * polyfills: {\n * assert: true,\n * buffer: true\n * }\n * ```\n */\n polyfills?:\n | boolean\n | {\n assert?: boolean;\n buffer?: boolean;\n console?: boolean;\n constants?: boolean;\n crypto?: boolean;\n domain?: boolean;\n events?: boolean;\n http?: boolean;\n https?: boolean;\n os?: boolean;\n path?: boolean;\n punycode?: boolean;\n process?: boolean;\n querystring?: boolean;\n stream?: boolean;\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex?: boolean;\n _stream_passthrough?: boolean;\n _stream_readable?: boolean;\n _stream_transform?: boolean;\n _stream_writable?: boolean;\n string_decoder?: boolean;\n /* eslint-enable @typescript-eslint/naming-convention */\n sys?: boolean;\n timers?: boolean;\n tty?: boolean;\n url?: boolean;\n util?: boolean;\n vm?: boolean;\n zlib?: boolean;\n };\n\n /**\n * A function to customize the Webpack configuration used to build the snap.\n * This function will be called with the default Webpack configuration, and\n * should return the modified configuration. If not specified, the default\n * configuration will be used.\n *\n * It's recommended to use the `webpack-merge` package to merge the default\n * configuration with your customizations. The merge function is exported as\n * `merge` from the `@metamask/snaps-cli` package.\n *\n * @example\n * ```ts\n * import type { SnapsConfig } from '@metamask/snaps-cli';\n * import { merge } from '@metamask/snaps-cli';\n *\n * const config: SnapsConfig = {\n * bundler: 'webpack',\n * entry: 'src/index.ts',\n * customizeWebpackConfig: (config) => merge(config, {\n * module: {\n * rules: [\n * {\n * test: /\\.wasm$/,\n * type: 'assets/resource',\n * },\n * ],\n * },\n * }),\n * };\n *\n * export default config;\n * ```\n */\n customizeWebpackConfig?: (\n config: WebpackConfiguration,\n ) => WebpackConfiguration;\n\n /**\n * Experimental features that can be enabled. These features are not\n * guaranteed to be stable, and may be removed or changed in a future release.\n */\n experimental?: {\n /**\n * Whether to enable WebAssembly support. If `true`, the Webpack\n * configuration will be modified to support WebAssembly. If `false`, the\n * Webpack configuration will not be modified.\n *\n * @default false\n */\n wasm?: boolean;\n };\n};\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapConfig = SnapBrowserifyConfig | SnapWebpackConfig;\n\ntype SnapsBrowserifyBundlerCustomizerFunction = (\n bundler: BrowserifyObject,\n) => void;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsBrowserifyBundlerCustomizerFunctionStruct =\n define<SnapsBrowserifyBundlerCustomizerFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsBrowserifyConfigStruct = object({\n bundler: defaulted(literal('browserify'), 'browserify'),\n cliOptions: defaulted(\n object({\n bundle: optional(file()),\n dist: defaulted(file(), 'dist'),\n eval: defaulted(boolean(), true),\n manifest: defaulted(boolean(), true),\n port: defaulted(number(), 8081),\n outfileName: defaulted(string(), 'bundle.js'),\n root: defaulted(file(), process.cwd()),\n sourceMaps: defaulted(boolean(), false),\n src: defaulted(file(), 'src/index.js'),\n stripComments: defaulted(boolean(), true),\n suppressWarnings: defaulted(boolean(), false),\n transpilationMode: defaulted(\n union([literal('localAndDeps'), literal('localOnly'), literal('none')]),\n 'localOnly',\n ),\n depsToTranspile: defaulted(array(string()), []),\n verboseErrors: defaulted(boolean(), true),\n writeManifest: defaulted(boolean(), true),\n serve: defaulted(boolean(), true),\n }),\n {},\n ),\n bundlerCustomizer: optional(SnapsBrowserifyBundlerCustomizerFunctionStruct),\n});\n\ntype SnapsWebpackCustomizeWebpackConfigFunction = (\n config: WebpackConfiguration,\n) => WebpackConfiguration;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsWebpackCustomizeWebpackConfigFunctionStruct =\n define<SnapsWebpackCustomizeWebpackConfigFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsWebpackConfigStruct = object({\n bundler: literal('webpack'),\n input: defaulted(file(), resolve(process.cwd(), 'src/index.js')),\n sourceMap: defaulted(union([boolean(), literal('inline')]), true),\n evaluate: defaulted(boolean(), true),\n\n output: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'dist')),\n filename: defaulted(string(), 'bundle.js'),\n clean: defaulted(boolean(), false),\n minimize: defaulted(boolean(), true),\n }),\n {},\n ),\n\n manifest: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'snap.manifest.json')),\n update: defaulted(boolean(), true),\n }),\n {},\n ),\n\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n root: defaulted(file(), process.cwd()),\n port: defaulted(number(), 8081),\n }),\n {},\n ),\n\n environment: defaulted(record(string(), unknown()), {\n NODE_DEBUG: false,\n NODE_ENV: 'production',\n DEBUG: false,\n }),\n\n stats: defaulted(\n object({\n verbose: defaulted(boolean(), false),\n builtIns: defaulted(\n union([\n object({ ignore: defaulted(array(string()), []) }),\n literal(false),\n ]),\n {},\n ),\n buffer: defaulted(boolean(), true),\n }),\n {},\n ),\n\n polyfills: defaulted(\n union([\n boolean(),\n object({\n assert: defaulted(boolean(), false),\n buffer: defaulted(boolean(), false),\n console: defaulted(boolean(), false),\n constants: defaulted(boolean(), false),\n crypto: defaulted(boolean(), false),\n domain: defaulted(boolean(), false),\n events: defaulted(boolean(), false),\n http: defaulted(boolean(), false),\n https: defaulted(boolean(), false),\n os: defaulted(boolean(), false),\n path: defaulted(boolean(), false),\n punycode: defaulted(boolean(), false),\n process: defaulted(boolean(), false),\n querystring: defaulted(boolean(), false),\n stream: defaulted(boolean(), false),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: defaulted(boolean(), false),\n _stream_passthrough: defaulted(boolean(), false),\n _stream_readable: defaulted(boolean(), false),\n _stream_transform: defaulted(boolean(), false),\n _stream_writable: defaulted(boolean(), false),\n string_decoder: defaulted(boolean(), false),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: defaulted(boolean(), false),\n timers: defaulted(boolean(), false),\n tty: defaulted(boolean(), false),\n url: defaulted(boolean(), false),\n util: defaulted(boolean(), false),\n vm: defaulted(boolean(), false),\n zlib: defaulted(boolean(), false),\n }),\n ]),\n false,\n ),\n\n customizeWebpackConfig: optional(\n SnapsWebpackCustomizeWebpackConfigFunctionStruct,\n ),\n\n experimental: defaulted(\n object({\n wasm: defaulted(boolean(), false),\n }),\n {},\n ),\n});\n\nexport const SnapsConfigStruct = type({\n bundler: defaulted(\n union([literal('browserify'), literal('webpack')]),\n 'browserify',\n ),\n});\n\nexport const LegacyOptionsStruct = union([\n named(\n 'object with `transpilationMode` set to `localAndDeps` and `depsToTranspile` set to an array of strings',\n type({\n depsToTranspile: array(string()),\n transpilationMode: literal(TranspilationModes.LocalAndDeps),\n writeManifest: boolean(),\n bundlerCustomizer: optional(\n SnapsBrowserifyBundlerCustomizerFunctionStruct,\n ),\n }),\n ),\n named(\n 'object without `depsToTranspile`',\n type({\n depsToTranspile: named('empty array', empty(array())),\n transpilationMode: union([\n literal(TranspilationModes.LocalOnly),\n literal(TranspilationModes.None),\n ]),\n writeManifest: boolean(),\n bundlerCustomizer: optional(\n SnapsBrowserifyBundlerCustomizerFunctionStruct,\n ),\n }),\n ),\n]);\n\nexport type LegacyOptions = Infer<typeof LegacyOptionsStruct>;\n\nexport type ProcessedBrowserifyConfig = Infer<\n typeof SnapsBrowserifyConfigStruct\n>;\n\nexport type ProcessedWebpackConfig = Infer<typeof SnapsWebpackConfigStruct> & {\n /**\n * The legacy Browserify config, if the bundler is Browserify. This is used\n * to support the legacy config format.\n */\n legacy?: LegacyOptions;\n};\n\nexport type ProcessedConfig = ProcessedWebpackConfig;\n\n/**\n * Get a validated snap config. This validates the config and adds default\n * values for any missing properties.\n *\n * @param config - The config to validate.\n * @param argv - The CLI arguments.\n * @returns The validated config.\n */\nexport function getConfig(config: unknown, argv: YargsArgs): ProcessedConfig {\n const prefix = 'The snap config file is invalid';\n const suffix = dim(\n // TODO: Link to `docs.metamask.io` once the docs are published.\n 'Refer to the documentation for more information: https://github.com/MetaMask/snaps/tree/main/packages/snaps-cli/',\n );\n\n const { bundler } = createFromStruct(\n config,\n SnapsConfigStruct,\n prefix,\n suffix,\n );\n\n if (bundler === 'browserify') {\n const legacyConfig = createFromStruct(\n config,\n SnapsBrowserifyConfigStruct,\n prefix,\n suffix,\n );\n\n return getWebpackConfig(mergeLegacyOptions(argv, legacyConfig));\n }\n\n return createFromStruct(config, SnapsWebpackConfigStruct, prefix, suffix);\n}\n\n/**\n * Load a snap config from a file. This supports both JavaScript and TypeScript\n * config files, in the CommonJS module format and the ES module format.\n *\n * This assumes that the config file exports a default object, either through\n * `module.exports` or `export default`.\n *\n * @param path - The full path to the config file.\n * @param argv - The CLI arguments.\n * @returns The validated config.\n * @throws If the config file is invalid, or if the config file does not have a\n * default export.\n */\nexport async function loadConfig(path: string, argv: YargsArgs) {\n try {\n const contents = await readFile(path, 'utf8');\n const source = await transform(contents, {\n swcrc: false,\n jsc: {\n parser: {\n syntax: 'typescript',\n },\n },\n module: {\n type: 'commonjs',\n },\n });\n\n const config = new Module(path);\n\n // @ts-expect-error - This function is not typed.\n config.paths = Module._nodeModulePaths(dirname(path));\n\n // @ts-expect-error - This function is not typed.\n config._compile(source.code, path);\n\n if (!hasProperty(config.exports, 'default')) {\n return getConfig(config.exports, argv);\n }\n\n return getConfig(config.exports.default, argv);\n } catch (error) {\n if (error instanceof SnapsStructError) {\n throw new ConfigError(error.message);\n }\n\n throw new ConfigError(\n `Unable to load snap config file at \"${path}\".\\n\\n${indent(\n error.message,\n )}`,\n );\n }\n}\n\n/**\n * Resolve a snap config. This function will look for a `snap.config.js` or\n * `snap.config.ts` file in the current or specified directory.\n *\n * @param path - The path to resolve the snap config from. Defaults to the\n * current working directory.\n * @param argv - The CLI arguments.\n * @returns The resolved and validated snap config.\n * @throws If a snap config could not be found.\n */\nexport async function resolveConfig(path: string, argv: YargsArgs) {\n for (const configFile of CONFIG_FILES) {\n const filePath = resolve(path, configFile);\n if (await isFile(filePath)) {\n return await loadConfig(filePath, argv);\n }\n }\n\n throw new ConfigError(\n `Could not find a \"snap.config.js\" or \"snap.config.ts\" file in the current or specified directory (\"${path}\").`,\n );\n}\n\n/**\n * Get a snap config from the CLI arguments. This will either load the config\n * from the specified config file, or resolve the config from the current\n * working directory.\n *\n * @param argv - The CLI arguments.\n * @param cwd - The current working directory. Defaults to `process.cwd()`.\n * @returns The resolved and validated snap config.\n */\nexport async function getConfigByArgv(\n argv: YargsArgs,\n cwd: string = process.cwd(),\n) {\n if (argv.config) {\n if (!(await isFile(argv.config))) {\n throw new ConfigError(\n `Could not find a config file at \"${argv.config}\". Make sure that the path is correct.`,\n );\n }\n\n return await loadConfig(argv.config, argv);\n }\n\n return await resolveConfig(cwd, argv);\n}\n\n/**\n * Merge legacy CLI options into the config. This is used to support the legacy\n * config format, where options can be specified both in the config file and\n * through CLI flags.\n *\n * @param argv - The CLI arguments.\n * @param config - The config to merge the CLI options into.\n * @returns The config with the CLI options merged in.\n * @deprecated This function is only used to support the legacy config format.\n */\nexport function mergeLegacyOptions(\n argv: YargsArgs,\n config: ProcessedBrowserifyConfig,\n) {\n const cliOptions = Object.keys(config.cliOptions).reduce<\n ProcessedBrowserifyConfig['cliOptions']\n >((accumulator, key) => {\n if (argv[key] !== undefined) {\n return {\n ...accumulator,\n [key]: argv[key],\n };\n }\n\n return accumulator;\n }, config.cliOptions);\n\n return {\n ...config,\n cliOptions,\n };\n}\n\n/**\n * Get a Webpack config from a legacy browserify config. This is used to\n * support the legacy config format, and convert it to the new format.\n *\n * @param legacyConfig - The legacy browserify config.\n * @returns The Webpack config.\n */\nexport function getWebpackConfig(\n legacyConfig: ProcessedBrowserifyConfig,\n): ProcessedWebpackConfig {\n const defaultConfig = create(\n { bundler: 'webpack' },\n SnapsWebpackConfigStruct,\n );\n\n // The legacy config has two options for specifying the output path and\n // filename: `bundle`, and `dist` + `outfileName`. If `bundle` is specified,\n // we use that as the output path and filename. Otherwise, we use `dist` and\n // `outfileName`.\n const path = legacyConfig.cliOptions.bundle\n ? dirname(legacyConfig.cliOptions.bundle)\n : legacyConfig.cliOptions.dist;\n\n const filename = legacyConfig.cliOptions.bundle\n ? basename(legacyConfig.cliOptions.bundle)\n : legacyConfig.cliOptions.outfileName;\n\n return {\n ...defaultConfig,\n input: legacyConfig.cliOptions.src,\n evaluate: legacyConfig.cliOptions.eval,\n sourceMap: legacyConfig.cliOptions.sourceMaps,\n output: {\n path,\n filename,\n\n // The legacy config has an option to remove comments from the bundle, but\n // the terser plugin does this by default, so we only enable the terser if\n // the legacy config has `stripComments` set to `true`. This is not a\n // perfect solution, but it's the best we can do without breaking the\n // legacy config.\n minimize: legacyConfig.cliOptions.stripComments,\n\n // The legacy config does not have a `clean` option, so we default to\n // `false` here.\n clean: false,\n },\n manifest: {\n // The legacy config does not have a `manifest` option, so we default to\n // `process.cwd()/snap.manifest.json`.\n path: resolve(process.cwd(), 'snap.manifest.json'),\n update: legacyConfig.cliOptions.writeManifest,\n },\n server: {\n enabled: legacyConfig.cliOptions.serve,\n port: legacyConfig.cliOptions.port,\n root: legacyConfig.cliOptions.root,\n },\n stats: {\n verbose: false,\n\n // These plugins are designed to be used with the modern config format, so\n // we disable them for the legacy config format.\n builtIns: false,\n buffer: false,\n },\n legacy: createFromStruct(\n {\n ...legacyConfig.cliOptions,\n bundlerCustomizer: legacyConfig.bundlerCustomizer,\n },\n LegacyOptionsStruct,\n 'Invalid Browserify CLI options',\n ),\n };\n}\n"],"names":["literal","union","createFromStruct","file","indent","isFile","SnapsStructError","named","hasProperty","transform","dim","readFile","Module","basename","dirname","resolve","array","boolean","create","defaulted","define","func","number","object","optional","record","string","type","unknown","empty","TranspilationModes","ConfigError","CONFIG_FILE","TS_CONFIG_FILE","CONFIG_FILES","SnapsBrowserifyBundlerCustomizerFunctionStruct","validator","SnapsBrowserifyConfigStruct","bundler","cliOptions","bundle","dist","eval","manifest","port","outfileName","root","process","cwd","sourceMaps","src","stripComments","suppressWarnings","transpilationMode","depsToTranspile","verboseErrors","writeManifest","serve","bundlerCustomizer","SnapsWebpackCustomizeWebpackConfigFunctionStruct","SnapsWebpackConfigStruct","input","sourceMap","evaluate","output","path","filename","clean","minimize","update","server","enabled","environment","NODE_DEBUG","NODE_ENV","DEBUG","stats","verbose","builtIns","ignore","buffer","polyfills","assert","console","constants","crypto","domain","events","http","https","os","punycode","querystring","stream","_stream_duplex","_stream_passthrough","_stream_readable","_stream_transform","_stream_writable","string_decoder","sys","timers","tty","url","util","vm","zlib","customizeWebpackConfig","experimental","wasm","SnapsConfigStruct","LegacyOptionsStruct","LocalAndDeps","LocalOnly","None","getConfig","config","argv","prefix","suffix","legacyConfig","getWebpackConfig","mergeLegacyOptions","loadConfig","contents","source","swcrc","jsc","parser","syntax","module","paths","_nodeModulePaths","_compile","code","exports","default","error","message","resolveConfig","configFile","filePath","getConfigByArgv","Object","keys","reduce","accumulator","key","undefined","defaultConfig","legacy"],"mappings":"AAAA,SAASA,OAAO,EAAEC,KAAK,QAAQ,sBAAsB;AACrD,SACEC,gBAAgB,EAChBC,IAAI,EACJC,MAAM,EACNC,MAAM,EACNC,gBAAgB,EAChBC,KAAK,QACA,wBAAwB;AAC/B,SAASC,WAAW,QAAQ,kBAAkB;AAC9C,SAASC,SAAS,QAAQ,YAAY;AAEtC,SAASC,GAAG,QAAQ,QAAQ;AAC5B,SAASC,QAAQ,QAAQ,cAAc;AACvC,OAAOC,YAAY,SAAS;AAC5B,SAASC,QAAQ,EAAEC,OAAO,EAAEC,OAAO,QAAQ,OAAO;AAElD,SACEC,KAAK,EACLC,OAAO,EACPC,MAAM,EACNC,SAAS,EACTC,MAAM,EACNC,IAAI,EACJC,MAAM,EACNC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,OAAO,EACPC,KAAK,QACA,cAAc;AAGrB,SAASC,kBAAkB,QAAQ,aAAa;AAChD,SAASC,WAAW,QAAQ,WAAW;AAEvC,SAASC,WAAW,EAAEC,cAAc,QAAQ,UAAU;AAEtD,MAAMC,eAAe;IAACF;IAAaC;CAAe;AAwblD,6EAA6E;AAC7E,6EAA6E;AAC7E,oBAAoB;AACpB,MAAME,iDACJf,OACE,YACAC,OAAOe,SAAS;AAGpB,OAAO,MAAMC,8BAA8Bd,OAAO;IAChDe,SAASnB,UAAUnB,QAAQ,eAAe;IAC1CuC,YAAYpB,UACVI,OAAO;QACLiB,QAAQhB,SAASrB;QACjBsC,MAAMtB,UAAUhB,QAA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7Ce,QAAQ;YACNC;YACAC;YAEA,0EAA0E;YAC1E,0EAA0E;YAC1E,qEAAqE;YACrE,qEAAqE;YACrE,iBAAiB;YACjBE,UAAUoD,aAAajF,UAAU,CAACY,aAAa;YAE/C,qEAAqE;YACrE,gBAAgB;YAChBgB,OAAO;QACT;QACAxB,UAAU;YACR,wEAAwE;YACxE,sCAAsC;YACtCsB,MAAMlD,QAAQgC,QAAQC,GAAG,IAAI;YAC7BqB,QAAQmD,aAAajF,UAAU,CAACiB,aAAa;QAC/C;QACAc,QAAQ;YACNC,SAASiD,aAAajF,UAAU,CAACkB,KAAK;YACtCb,MAAM4E,aAAajF,UAAU,CAACK,IAAI;YAClCE,MAAM0E,aAAajF,UAAU,CAACO,IAAI;QACpC;QACA8B,OAAO;YACLC,SAAS;YAET,0EAA0E;YAC1E,gDAAgD;YAChDC,UAAU;YACVE,QAAQ;QACV;QACAsE,QAAQpJ,iBACN;YACE,GAAGsH,aAAajF,UAAU;YAC1BmB,mBAAmB8D,aAAa9D,iBAAiB;QACnD,GACAqD,qBACA;IAEJ;AACF"}
@@ -1,5 +1,5 @@
1
1
  import browserify from 'browserify';
2
- import { Readable } from 'stream';
2
+ import { Readable } from 'readable-stream';
3
3
  import { TranspilationModes } from '../../builders';
4
4
  import { processDependencies } from '../../utils';
5
5
  import { getBrowserslistTargets } from '../utils';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/webpack/loaders/browserify.ts"],"sourcesContent":["import browserify from 'browserify';\nimport { Readable } from 'stream';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\nimport { TranspilationModes } from '../../builders';\nimport type { LegacyOptions } from '../../config';\nimport { processDependencies } from '../../utils';\nimport { getBrowserslistTargets } from '../utils';\n\n/**\n * A Browserify loader for Webpack. This exists for backwards compatibility with\n * the legacy configuration format, in order to support the `bundlerCustomizer`\n * function.\n *\n * When this loader is used, the input file will be processed by Browserify, and\n * written to disk by Webpack. Most processing will be handled by Browserify, so\n * there are no benefits like tree-shaking.\n *\n * @param content - The input file contents as a string.\n * @param sourceMap - The source map of the input file.\n */\nconst loader: LoaderDefinitionFunction<LegacyOptions> = async function (\n content,\n sourceMap,\n) {\n const config = this.getOptions();\n\n const { transpilationMode } = config;\n\n const bundler = browserify({\n extensions: ['.js', '.ts'],\n debug: Boolean(sourceMap),\n standalone: '<snap>',\n });\n\n if (transpilationMode !== TranspilationModes.None) {\n const babelifyOptions = processDependencies(config);\n\n // We need to statically import all Browserify transforms, and all Babel\n // presets and plugins, and calling `require` is the sanest way to do that.\n /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n bundler.transform(require('babelify'), {\n global: transpilationMode === TranspilationModes.LocalAndDeps,\n extensions: ['.js', '.ts'],\n presets: [\n require('@babel/preset-typescript'),\n [\n require('@babel/preset-env'),\n {\n targets: {\n browsers: await getBrowserslistTargets(),\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-transform-class-properties'),\n require('@babel/plugin-transform-private-methods'),\n require('@babel/plugin-transform-class-static-block'),\n require('@babel/plugin-transform-private-property-in-object'),\n ],\n ...(babelifyOptions as any),\n });\n /* eslint-enable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n }\n\n config.bundlerCustomizer?.(bundler);\n\n // Browserify doesn't accept a string as an entry point, so we need to convert\n // it to a stream.\n const stream = new Readable();\n stream.push(content);\n stream.push(null);\n\n bundler.add(stream, {\n file: this.resourcePath,\n });\n\n return new Promise<Buffer>((resolve, reject) => {\n bundler.bundle((bundleError, buffer: Buffer) => {\n if (bundleError) {\n reject(bundleError);\n return;\n }\n\n // Browserify inlines the source map, so we just pass the output buffer back\n // to Webpack.\n resolve(buffer);\n });\n });\n};\n\nexport default loader;\n"],"names":["browserify","Readable","TranspilationModes","processDependencies","getBrowserslistTargets","loader","content","sourceMap","config","getOptions","transpilationMode","bundler","extensions","debug","Boolean","standalone","None","babelifyOptions","transform","require","global","LocalAndDeps","presets","targets","browsers","plugins","bundlerCustomizer","stream","push","add","file","resourcePath","Promise","resolve","reject","bundle","bundleError","buffer"],"mappings":"AAAA,OAAOA,gBAAgB,aAAa;AACpC,SAASC,QAAQ,QAAQ,SAAS;AAGlC,SAASC,kBAAkB,QAAQ,iBAAiB;AAEpD,SAASC,mBAAmB,QAAQ,cAAc;AAClD,SAASC,sBAAsB,QAAQ,WAAW;AAElD;;;;;;;;;;;CAWC,GACD,MAAMC,SAAkD,eACtDC,OAAO,EACPC,SAAS;IAET,MAAMC,SAAS,IAAI,CAACC,UAAU;IAE9B,MAAM,EAAEC,iBAAiB,EAAE,GAAGF;IAE9B,MAAMG,UAAUX,WAAW;QACzBY,YAAY;YAAC;YAAO;SAAM;QAC1BC,OAAOC,QAAQP;QACfQ,YAAY;IACd;IAEA,IAAIL,sBAAsBR,mBAAmBc,IAAI,EAAE;QACjD,MAAMC,kBAAkBd,oBAAoBK;QAE5C,wEAAwE;QACxE,2EAA2E;QAC3E,8GAA8G,GAC9GG,QAAQO,SAAS,CAACC,QAAQ,aAAa;YACrCC,QAAQV,sBAAsBR,mBAAmBmB,YAAY;YAC7DT,YAAY;gBAAC;gBAAO;aAAM;YAC1BU,SAAS;gBACPH,QAAQ;gBACR;oBACEA,QAAQ;oBACR;wBACEI,SAAS;4BACPC,UAAU,MAAMpB;wBAClB;oBACF;iBACD;aACF;YACDqB,SAAS;gBACPN,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;aACT;YACD,GAAIF,eAAe;QACrB;IACA,6GAA6G,GAC/G;IAEAT,OAAOkB,iBAAiB,GAAGf;IAE3B,8EAA8E;IAC9E,kBAAkB;IAClB,MAAMgB,SAAS,IAAI1B;IACnB0B,OAAOC,IAAI,CAACtB;IACZqB,OAAOC,IAAI,CAAC;IAEZjB,QAAQkB,GAAG,CAACF,QAAQ;QAClBG,MAAM,IAAI,CAACC,YAAY;IACzB;IAEA,OAAO,IAAIC,QAAgB,CAACC,SAASC;QACnCvB,QAAQwB,MAAM,CAAC,CAACC,aAAaC;YAC3B,IAAID,aAAa;gBACfF,OAAOE;gBACP;YACF;YAEA,4EAA4E;YAC5E,cAAc;YACdH,QAAQI;QACV;IACF;AACF;AAEA,eAAehC,OAAO"}
1
+ {"version":3,"sources":["../../../../src/webpack/loaders/browserify.ts"],"sourcesContent":["import browserify from 'browserify';\nimport { Readable } from 'readable-stream';\nimport type { LoaderDefinitionFunction } from 'webpack';\n\nimport { TranspilationModes } from '../../builders';\nimport type { LegacyOptions } from '../../config';\nimport { processDependencies } from '../../utils';\nimport { getBrowserslistTargets } from '../utils';\n\n/**\n * A Browserify loader for Webpack. This exists for backwards compatibility with\n * the legacy configuration format, in order to support the `bundlerCustomizer`\n * function.\n *\n * When this loader is used, the input file will be processed by Browserify, and\n * written to disk by Webpack. Most processing will be handled by Browserify, so\n * there are no benefits like tree-shaking.\n *\n * @param content - The input file contents as a string.\n * @param sourceMap - The source map of the input file.\n */\nconst loader: LoaderDefinitionFunction<LegacyOptions> = async function (\n content,\n sourceMap,\n) {\n const config = this.getOptions();\n\n const { transpilationMode } = config;\n\n const bundler = browserify({\n extensions: ['.js', '.ts'],\n debug: Boolean(sourceMap),\n standalone: '<snap>',\n });\n\n if (transpilationMode !== TranspilationModes.None) {\n const babelifyOptions = processDependencies(config);\n\n // We need to statically import all Browserify transforms, and all Babel\n // presets and plugins, and calling `require` is the sanest way to do that.\n /* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n bundler.transform(require('babelify'), {\n global: transpilationMode === TranspilationModes.LocalAndDeps,\n extensions: ['.js', '.ts'],\n presets: [\n require('@babel/preset-typescript'),\n [\n require('@babel/preset-env'),\n {\n targets: {\n browsers: await getBrowserslistTargets(),\n },\n },\n ],\n ],\n plugins: [\n require('@babel/plugin-transform-runtime'),\n require('@babel/plugin-transform-class-properties'),\n require('@babel/plugin-transform-private-methods'),\n require('@babel/plugin-transform-class-static-block'),\n require('@babel/plugin-transform-private-property-in-object'),\n ],\n ...(babelifyOptions as any),\n });\n /* eslint-enable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n }\n\n config.bundlerCustomizer?.(bundler);\n\n // Browserify doesn't accept a string as an entry point, so we need to convert\n // it to a stream.\n const stream = new Readable();\n stream.push(content);\n stream.push(null);\n\n bundler.add(stream, {\n file: this.resourcePath,\n });\n\n return new Promise<Buffer>((resolve, reject) => {\n bundler.bundle((bundleError, buffer: Buffer) => {\n if (bundleError) {\n reject(bundleError);\n return;\n }\n\n // Browserify inlines the source map, so we just pass the output buffer back\n // to Webpack.\n resolve(buffer);\n });\n });\n};\n\nexport default loader;\n"],"names":["browserify","Readable","TranspilationModes","processDependencies","getBrowserslistTargets","loader","content","sourceMap","config","getOptions","transpilationMode","bundler","extensions","debug","Boolean","standalone","None","babelifyOptions","transform","require","global","LocalAndDeps","presets","targets","browsers","plugins","bundlerCustomizer","stream","push","add","file","resourcePath","Promise","resolve","reject","bundle","bundleError","buffer"],"mappings":"AAAA,OAAOA,gBAAgB,aAAa;AACpC,SAASC,QAAQ,QAAQ,kBAAkB;AAG3C,SAASC,kBAAkB,QAAQ,iBAAiB;AAEpD,SAASC,mBAAmB,QAAQ,cAAc;AAClD,SAASC,sBAAsB,QAAQ,WAAW;AAElD;;;;;;;;;;;CAWC,GACD,MAAMC,SAAkD,eACtDC,OAAO,EACPC,SAAS;IAET,MAAMC,SAAS,IAAI,CAACC,UAAU;IAE9B,MAAM,EAAEC,iBAAiB,EAAE,GAAGF;IAE9B,MAAMG,UAAUX,WAAW;QACzBY,YAAY;YAAC;YAAO;SAAM;QAC1BC,OAAOC,QAAQP;QACfQ,YAAY;IACd;IAEA,IAAIL,sBAAsBR,mBAAmBc,IAAI,EAAE;QACjD,MAAMC,kBAAkBd,oBAAoBK;QAE5C,wEAAwE;QACxE,2EAA2E;QAC3E,8GAA8G,GAC9GG,QAAQO,SAAS,CAACC,QAAQ,aAAa;YACrCC,QAAQV,sBAAsBR,mBAAmBmB,YAAY;YAC7DT,YAAY;gBAAC;gBAAO;aAAM;YAC1BU,SAAS;gBACPH,QAAQ;gBACR;oBACEA,QAAQ;oBACR;wBACEI,SAAS;4BACPC,UAAU,MAAMpB;wBAClB;oBACF;iBACD;aACF;YACDqB,SAAS;gBACPN,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;gBACRA,QAAQ;aACT;YACD,GAAIF,eAAe;QACrB;IACA,6GAA6G,GAC/G;IAEAT,OAAOkB,iBAAiB,GAAGf;IAE3B,8EAA8E;IAC9E,kBAAkB;IAClB,MAAMgB,SAAS,IAAI1B;IACnB0B,OAAOC,IAAI,CAACtB;IACZqB,OAAOC,IAAI,CAAC;IAEZjB,QAAQkB,GAAG,CAACF,QAAQ;QAClBG,MAAM,IAAI,CAACC,YAAY;IACzB;IAEA,OAAO,IAAIC,QAAgB,CAACC,SAASC;QACnCvB,QAAQwB,MAAM,CAAC,CAACC,aAAaC;YAC3B,IAAID,aAAa;gBACfF,OAAOE;gBACP;YACF;YAEA,4EAA4E;YAC5E,cAAc;YACdH,QAAQI;QACV;IACF;AACF;AAEA,eAAehC,OAAO"}
@@ -481,12 +481,12 @@ export declare const SnapsWebpackConfigStruct: import("superstruct").Struct<{
481
481
  };
482
482
  };
483
483
  polyfills: boolean | {
484
- path: boolean;
485
- assert: boolean;
486
484
  buffer: boolean;
487
485
  stream: boolean;
486
+ path: boolean;
488
487
  http: boolean;
489
488
  zlib: boolean;
489
+ assert: boolean;
490
490
  url: boolean;
491
491
  https: boolean;
492
492
  console: boolean;
@@ -565,12 +565,12 @@ export declare const SnapsWebpackConfigStruct: import("superstruct").Struct<{
565
565
  buffer: import("superstruct").Struct<boolean, null>;
566
566
  }>;
567
567
  polyfills: import("superstruct").Struct<boolean | {
568
- path: boolean;
569
- assert: boolean;
570
568
  buffer: boolean;
571
569
  stream: boolean;
570
+ path: boolean;
572
571
  http: boolean;
573
572
  zlib: boolean;
573
+ assert: boolean;
574
574
  url: boolean;
575
575
  https: boolean;
576
576
  console: boolean;
@@ -594,12 +594,12 @@ export declare const SnapsWebpackConfigStruct: import("superstruct").Struct<{
594
594
  util: boolean;
595
595
  vm: boolean;
596
596
  }, [import("superstruct").Struct<boolean, null>, import("superstruct").Struct<{
597
- path: boolean;
598
- assert: boolean;
599
597
  buffer: boolean;
600
598
  stream: boolean;
599
+ path: boolean;
601
600
  http: boolean;
602
601
  zlib: boolean;
602
+ assert: boolean;
603
603
  url: boolean;
604
604
  https: boolean;
605
605
  console: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-cli",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "A CLI for developing MetaMask Snaps.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -54,9 +54,10 @@
54
54
  "@babel/plugin-transform-runtime": "^7.13.2",
55
55
  "@babel/preset-env": "^7.23.2",
56
56
  "@babel/preset-typescript": "^7.23.2",
57
- "@metamask/snaps-utils": "^4.0.0",
58
- "@metamask/snaps-webpack-plugin": "^3.1.0",
59
- "@metamask/utils": "^8.1.0",
57
+ "@metamask/snaps-sdk": "^1.2.0",
58
+ "@metamask/snaps-utils": "^5.0.0",
59
+ "@metamask/snaps-webpack-plugin": "^3.1.1",
60
+ "@metamask/utils": "^8.2.1",
60
61
  "@swc/core": "1.3.78",
61
62
  "assert": "^2.0.0",
62
63
  "babelify": "^10.0.0",