@metamask/snaps-cli 8.3.0 → 8.4.0
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 +38 -1
- package/dist/builders.cjs +11 -0
- package/dist/builders.cjs.map +1 -1
- package/dist/builders.d.cts +11 -0
- package/dist/builders.d.cts.map +1 -1
- package/dist/builders.d.mts +11 -0
- package/dist/builders.d.mts.map +1 -1
- package/dist/builders.mjs +11 -0
- package/dist/builders.mjs.map +1 -1
- package/dist/commands/build/build.cjs +15 -7
- package/dist/commands/build/build.cjs.map +1 -1
- package/dist/commands/build/build.d.cts +19 -3
- package/dist/commands/build/build.d.cts.map +1 -1
- package/dist/commands/build/build.d.mts +19 -3
- package/dist/commands/build/build.d.mts.map +1 -1
- package/dist/commands/build/build.mjs +15 -7
- package/dist/commands/build/build.mjs.map +1 -1
- package/dist/commands/build/index.cjs +15 -2
- package/dist/commands/build/index.cjs.map +1 -1
- package/dist/commands/build/index.d.cts.map +1 -1
- package/dist/commands/build/index.d.mts.map +1 -1
- package/dist/commands/build/index.mjs +15 -2
- package/dist/commands/build/index.mjs.map +1 -1
- package/dist/commands/manifest/implementation.cjs +1 -2
- package/dist/commands/manifest/implementation.cjs.map +1 -1
- package/dist/commands/manifest/implementation.d.cts.map +1 -1
- package/dist/commands/manifest/implementation.d.mts.map +1 -1
- package/dist/commands/manifest/implementation.mjs +1 -2
- package/dist/commands/manifest/implementation.mjs.map +1 -1
- package/dist/commands/sandbox/sandbox.cjs +4 -1
- package/dist/commands/sandbox/sandbox.cjs.map +1 -1
- package/dist/commands/sandbox/sandbox.d.cts.map +1 -1
- package/dist/commands/sandbox/sandbox.d.mts.map +1 -1
- package/dist/commands/sandbox/sandbox.mjs +4 -1
- package/dist/commands/sandbox/sandbox.mjs.map +1 -1
- package/dist/commands/watch/index.cjs +7 -4
- package/dist/commands/watch/index.cjs.map +1 -1
- package/dist/commands/watch/index.d.cts.map +1 -1
- package/dist/commands/watch/index.d.mts.map +1 -1
- package/dist/commands/watch/index.mjs +7 -4
- package/dist/commands/watch/index.mjs.map +1 -1
- package/dist/config.cjs +5 -0
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +71 -22
- package/dist/config.d.cts.map +1 -1
- package/dist/config.d.mts +71 -22
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs +5 -0
- package/dist/config.mjs.map +1 -1
- package/dist/utils/cli.cjs +44 -4
- package/dist/utils/cli.cjs.map +1 -1
- package/dist/utils/cli.d.cts +9 -0
- package/dist/utils/cli.d.cts.map +1 -1
- package/dist/utils/cli.d.mts +9 -0
- package/dist/utils/cli.d.mts.map +1 -1
- package/dist/utils/cli.mjs +20 -1
- package/dist/utils/cli.mjs.map +1 -1
- package/dist/webpack/config.cjs +7 -1
- package/dist/webpack/config.cjs.map +1 -1
- package/dist/webpack/config.d.cts +16 -4
- package/dist/webpack/config.d.cts.map +1 -1
- package/dist/webpack/config.d.mts +16 -4
- package/dist/webpack/config.d.mts.map +1 -1
- package/dist/webpack/config.mjs +8 -2
- package/dist/webpack/config.mjs.map +1 -1
- package/dist/webpack/plugins.cjs +90 -2
- package/dist/webpack/plugins.cjs.map +1 -1
- package/dist/webpack/plugins.d.cts +36 -2
- package/dist/webpack/plugins.d.cts.map +1 -1
- package/dist/webpack/plugins.d.mts +36 -2
- package/dist/webpack/plugins.d.mts.map +1 -1
- package/dist/webpack/plugins.mjs +90 -3
- package/dist/webpack/plugins.mjs.map +1 -1
- package/dist/webpack/server.cjs +14 -3
- package/dist/webpack/server.cjs.map +1 -1
- package/dist/webpack/server.d.cts.map +1 -1
- package/dist/webpack/server.d.mts.map +1 -1
- package/dist/webpack/server.mjs +16 -5
- package/dist/webpack/server.mjs.map +1 -1
- package/dist/webpack/utils.cjs +29 -1
- package/dist/webpack/utils.cjs.map +1 -1
- package/dist/webpack/utils.d.cts +9 -1
- package/dist/webpack/utils.d.cts.map +1 -1
- package/dist/webpack/utils.d.mts +9 -1
- package/dist/webpack/utils.d.mts.map +1 -1
- package/dist/webpack/utils.mjs +27 -0
- package/dist/webpack/utils.mjs.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/webpack/utils.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAgD;AAChD,iCAA4B;AAC5B,2BAAoC;AACpC,mCAAwC;AAExC,+BAAwC;AACxC,qEAAmC;AAKtB,QAAA,iBAAiB,GAAG,IAAA,cAAO,EACtC,IAAA,cAAO,EAAC,OAAO,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC,EAC5D,iBAAiB,CAClB,CAAC;AAEW,QAAA,iBAAiB,GAAG;IAC/B,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;IAClC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;IAClC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC;IAC9C,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC;IAClD,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC;IAC5C,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC;IACzC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;IAClC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC;IACpC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC;IAC1C,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC,uBAAuB,CAAC;IAC5C,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC;IACxC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;IACtC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC;IAC3C,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,iBA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AAC,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,EAAE;gBAC/D,iBAAiB,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM;aAC/C,CAAC;QACJ,CAAC;QAED,+CAA+C;QAC/C,OAAO;YACL,aAAa,EAAE,aAAa,GAAG,eAAe,GAAG,IAAI;YACrD,iBAAiB,EAAE,iBAAiB,GAAG,mBAAmB;SAC3D,CAAC;IACJ,CAAC,EACD;QACE,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC;QACxC,iBAAiB,EAAE,aAAa;KACjC,CACF,CAAC,aAAa,CAAC;AAClB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,UAAU,CACxB,IAAY,EACZ,MAAc,EACd,aAAa,GAAG,MAAM;IAEtB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE/B,+DAA+D;IAC/D,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACnB,MAAM,UAAU,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC;QACxD,OAAO,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC9C,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAdD,gCAcC;AAED;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,QAAgB,EAAE,KAAiB;IAC7D,MAAM,OAAO,GAAG,QAAQ,QAAQ,WAAW,IAAA,qBAAa,EAAC,KAAK,CAAC,EAAE,CAAC;IAClE,OAAO,wDAAwD,OAAO,YAAY,CAAC;AACrF,CAAC;AAHD,kCAGC","sourcesContent":["import { bytesToBase64 } from '@metamask/utils';\nimport { dim } from 'chalk';\nimport { promises as fs } from 'fs';\nimport { builtinModules } from 'module';\nimport type { Ora } from 'ora';\nimport { dirname, resolve } from 'path';\nimport stripAnsi from 'strip-ansi';\nimport type { Configuration } from 'webpack';\n\nimport type { ProcessedConfig } from '../config';\n\nexport const BROWSERSLIST_FILE = resolve(\n dirname(require.resolve('@metamask/snaps-cli/package.json')),\n '.browserslistrc',\n);\n\nexport const WEBPACK_FALLBACKS = {\n assert: require.resolve('assert/'),\n buffer: require.resolve('buffer/'),\n console: require.resolve('console-browserify'),\n constants: require.resolve('constants-browserify'),\n crypto: require.resolve('crypto-browserify'),\n domain: require.resolve('domain-browser'),\n events: require.resolve('events/'),\n http: require.resolve('stream-http'),\n https: require.resolve('https-browserify'),\n os: require.resolve('os-browserify/browser'),\n path: require.resolve('path-browserify'),\n punycode: require.resolve('punycode/'),\n process: require.resolve('process/browser'),\n querystring: require.resolve('querystring-es3'),\n stream: require.resolve('stream-browserify'),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),\n _stream_passthrough: require.resolve(\n 'readable-stream/lib/_stream_passthrough',\n ),\n _stream_readable: require.resolve('readable-stream/lib/_stream_readable'),\n _stream_transform: require.resolve('readable-stream/lib/_stream_transform'),\n _stream_writable: require.resolve('readable-stream/lib/_stream_writable'),\n string_decoder: require.resolve('string_decoder/'),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: require.resolve('util/'),\n timers: require.resolve('timers-browserify'),\n tty: require.resolve('tty-browserify'),\n url: require.resolve('url/'),\n util: require.resolve('util/'),\n vm: require.resolve('vm-browserify'),\n zlib: require.resolve('browserify-zlib'),\n};\n\n/**\n * Get the default loader for JavaScript and TypeScript files, based on the\n * config object.\n *\n * We use the `swc-loader`, which is a Webpack loader that uses the `SWC`\n * compiler, a much faster alternative to Babel and TypeScript's own compiler.\n *\n * @param config - The processed snap Webpack config.\n * @param config.sourceMap - Whether to generate source maps.\n * @see https://swc.rs/docs/usage/swc-loader\n * @returns The default loader.\n */\nexport async function getDefaultLoader({ sourceMap }: ProcessedConfig) {\n const targets = await getBrowserslistTargets();\n return {\n /**\n * We use the `swc-loader` to transpile TypeScript and JavaScript files.\n * This is a Webpack loader that uses the `SWC` compiler, which is a much\n * faster alternative to Babel and TypeScript's own compiler.\n */\n loader: require.resolve('swc-loader'),\n\n /**\n * The options for the `swc-loader`. These can be overridden in the\n * `.swcrc` file.\n *\n * @see https://swc.rs/docs/configuration/swcrc\n */\n options: {\n sync: false,\n\n /**\n * This tells SWC to generate source maps. We set it to the\n * `sourceMap` value from the config object.\n *\n * This must be enabled if source maps are enabled in the config.\n */\n sourceMaps: Boolean(getDevTool(sourceMap)),\n\n jsc: {\n parser: {\n /**\n * This tells the parser to parse TypeScript files. If you\n * don't need to support TypeScript, you can set this to\n * `ecmascript` instead, but there's no harm in leaving it\n * as `typescript`.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n */\n syntax: 'typescript',\n\n /**\n * This tells the parser to transpile JSX.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n * @see https://swc.rs/docs/configuration/compilation#jscparserjsx\n */\n tsx: true,\n },\n\n transform: {\n react: {\n /**\n * This tells SWC to use the JSX runtime, instead of the\n * `createElement` function.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n runtime: 'automatic',\n\n /**\n * This tells SWC to import the JSX runtime from the\n * `@metamask/snaps-sdk` package, instead of the default React\n * package.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n importSource: '@metamask/snaps-sdk',\n\n /**\n * This tells SWC to use `Object.assign` and `Object.create` for\n * JSX spread attributes, instead of the default behavior.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n useBuiltins: true,\n },\n },\n },\n\n /**\n * The module configuration. This tells SWC how to output the\n * transpiled code.\n *\n * @see https://swc.rs/docs/configuration/modules\n */\n module: {\n /**\n * This tells SWC to output ES6 modules. This will allow Webpack to\n * optimize the output code better. Snaps don't support ES6 however, so\n * the output code will be transpiled to CommonJS by Webpack later in\n * the build process.\n *\n * @see https://swc.rs/docs/configuration/modules#es6\n */\n type: 'es6',\n },\n\n env: {\n targets: targets.join(', '),\n },\n },\n };\n}\n\n/**\n * Get the Webpack devtool configuration based on the given snap config.\n *\n * - If `sourceMap` is `inline`, return `inline-source-map`.\n * - If `sourceMap` is `true`, return `source-map`.\n * - Otherwise, return `false`.\n *\n * @param sourceMap - The `sourceMap` value from the snap config.\n * @returns The Webpack devtool configuration.\n */\nexport function getDevTool(\n sourceMap: ProcessedConfig['sourceMap'],\n): Configuration['devtool'] {\n if (sourceMap === 'inline') {\n return 'inline-source-map';\n }\n\n if (sourceMap) {\n return 'source-map';\n }\n\n return false;\n}\n\n/**\n * Get a function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n *\n * @param spinner - The spinner to update.\n * @param spinnerText - The initial spinner text. This will be prepended to the\n * percentage.\n * @returns A function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n */\n// Note: This is extracted for testing purposes.\nexport function getProgressHandler(spinner?: Ora, spinnerText?: string) {\n return (percentage: number) => {\n if (spinner && spinnerText) {\n spinner.text = `${spinnerText} ${dim(\n `(${Math.round(percentage * 100)}%)`,\n )}`;\n }\n };\n}\n\n/**\n * Get the targets from the `.browserslistrc` file.\n *\n * @returns The browser targets as an array of strings.\n */\nexport async function getBrowserslistTargets() {\n const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');\n return contents\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line && !line.startsWith('#'));\n}\n\n/**\n * Get a singular or plural string based on the given count. This is useful for\n * generating messages like \"1 error\" or \"2 errors\". By default, the plural\n * string is the singular string with an \"s\" appended to it.\n *\n * This assumes that the text is in English, and likely won't work for some\n * other languages.\n *\n * @param count - The count.\n * @param singular - The singular string.\n * @param plural - The plural string.\n * @returns The singular or plural string.\n * @example\n * ```typescript\n * pluralize(1, 'error'); // => 'error'\n * pluralize(2, 'error'); // => 'errors'\n * pluralize(1, 'error', 'problem'); // => 'error'\n * pluralize(2, 'error', 'problems'); // => 'problems'\n * ```\n */\nexport function pluralize(\n count: number,\n singular: string,\n plural = `${singular}s`,\n) {\n return count === 1 ? singular : plural;\n}\n\n/**\n * Get an object that can be used as fallback config for Webpack's\n * `fallback` config.\n *\n * @param polyfills - The polyfill object from the snap config.\n * @returns The webpack fallback config.\n */\nexport function getFallbacks(polyfills: ProcessedConfig['polyfills']): {\n [index: string]: string | false;\n} {\n if (polyfills === true) {\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS] ?? false,\n ]),\n );\n }\n\n if (polyfills === false) {\n return Object.fromEntries(builtinModules.map((name) => [name, false]));\n }\n\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n polyfills[name as keyof ProcessedConfig['polyfills']]\n ? WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS]\n : false,\n ]),\n );\n}\n\n/**\n * Get an object that can be used as environment variables for Webpack's\n * `DefinePlugin`.\n *\n * @param environment - The environment object from the Snap config.\n * @param defaults - The default environment variables.\n * @returns The Webpack environment variables.\n */\nexport function getEnvironmentVariables(\n environment: Record<string, unknown>,\n defaults = {\n NODE_DEBUG: 'false',\n NODE_ENV: 'production',\n DEBUG: 'false',\n },\n) {\n return Object.fromEntries(\n Object.entries({\n ...defaults,\n ...environment,\n }).map(([key, value]) => [`process.env.${key}`, JSON.stringify(value)]),\n );\n}\n\n/**\n * Format the given line to fit within the terminal width.\n *\n * @param line - The line to format.\n * @param indent - The indentation to use.\n * @param initialIndent - The initial indentation to use, i.e., the indentation\n * for the first line.\n * @returns The formatted line.\n */\nfunction formatLine(line: string, indent: number, initialIndent: number) {\n const terminalWidth = process.stdout.columns;\n if (!terminalWidth) {\n return `${' '.repeat(initialIndent)}${line}`;\n }\n\n return line.split(' ').reduce(\n ({ formattedText, currentLineLength }, word, index) => {\n // `chalk` adds ANSI escape codes to the text, which are not visible\n // characters. We need to strip them to get the visible length of the\n // text.\n const visibleWord = stripAnsi(word);\n\n // Determine if a space should be added before the word.\n const spaceBeforeWord = index > 0 ? ' ' : '';\n const wordLengthWithSpace = visibleWord.length + spaceBeforeWord.length;\n\n // If the word would exceed the terminal width, start a new line.\n if (currentLineLength + wordLengthWithSpace > terminalWidth) {\n return {\n formattedText: `${formattedText}\\n${' '.repeat(indent)}${word}`,\n currentLineLength: indent + visibleWord.length,\n };\n }\n\n // Otherwise, add the word to the current line.\n return {\n formattedText: formattedText + spaceBeforeWord + word,\n currentLineLength: currentLineLength + wordLengthWithSpace,\n };\n },\n {\n formattedText: ' '.repeat(initialIndent),\n currentLineLength: initialIndent,\n },\n ).formattedText;\n}\n\n/**\n * Format the given text to fit within the terminal width.\n *\n * @param text - The text to format.\n * @param indent - The indentation to use.\n * @param initialIndent - The initial indentation to use, i.e., the indentation\n * for the first line.\n * @returns The formatted text.\n */\nexport function formatText(\n text: string,\n indent: number,\n initialIndent = indent,\n) {\n const lines = text.split('\\n');\n\n // Apply formatting to each line separately and then join them.\n return lines\n .map((line, index) => {\n const lineIndent = index === 0 ? initialIndent : indent;\n return formatLine(line, indent, lineIndent);\n })\n .join('\\n');\n}\n\n/**\n * Get an SVG from the given bytes and mime type.\n *\n * @param mimeType - The mime type of the image.\n * @param bytes - The image bytes.\n * @returns The SVG.\n */\nexport function getImageSVG(mimeType: string, bytes: Uint8Array) {\n const dataUrl = `data:${mimeType};base64,${bytesToBase64(bytes)}`;\n return `<svg xmlns=\"http://www.w3.org/2000/svg\"><image href=\"${dataUrl}\" /></svg>`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/webpack/utils.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAgD;AAChD,iCAA4B;AAC5B,2BAAoC;AACpC,mCAAwC;AAExC,+BAAwC;AACxC,qEAAmC;AAKtB,QAAA,iBAAiB,GAAG,IAAA,cAAO,EACtC,IAAA,cAAO,EAAC,OAAO,CAAC,OAAO,CAAC,kCAAkC,CAAC,CAAC,EAC5D,iBAAiB,CAClB,CA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B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAxBD,0CAwBC","sourcesContent":["import { bytesToBase64 } from '@metamask/utils';\nimport { dim } from 'chalk';\nimport { promises as fs } from 'fs';\nimport { builtinModules } from 'module';\nimport type { Ora } from 'ora';\nimport { dirname, resolve } from 'path';\nimport stripAnsi from 'strip-ansi';\nimport type { Configuration, InputFileSystem, OutputFileSystem } from 'webpack';\n\nimport type { ProcessedConfig } from '../config';\n\nexport const BROWSERSLIST_FILE = resolve(\n dirname(require.resolve('@metamask/snaps-cli/package.json')),\n '.browserslistrc',\n);\n\nexport const WEBPACK_FALLBACKS = {\n assert: require.resolve('assert/'),\n buffer: require.resolve('buffer/'),\n console: require.resolve('console-browserify'),\n constants: require.resolve('constants-browserify'),\n crypto: require.resolve('crypto-browserify'),\n domain: require.resolve('domain-browser'),\n events: require.resolve('events/'),\n http: require.resolve('stream-http'),\n https: require.resolve('https-browserify'),\n os: require.resolve('os-browserify/browser'),\n path: require.resolve('path-browserify'),\n punycode: require.resolve('punycode/'),\n process: require.resolve('process/browser'),\n querystring: require.resolve('querystring-es3'),\n stream: require.resolve('stream-browserify'),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),\n _stream_passthrough: require.resolve(\n 'readable-stream/lib/_stream_passthrough',\n ),\n _stream_readable: require.resolve('readable-stream/lib/_stream_readable'),\n _stream_transform: require.resolve('readable-stream/lib/_stream_transform'),\n _stream_writable: require.resolve('readable-stream/lib/_stream_writable'),\n string_decoder: require.resolve('string_decoder/'),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: require.resolve('util/'),\n timers: require.resolve('timers-browserify'),\n tty: require.resolve('tty-browserify'),\n url: require.resolve('url/'),\n util: require.resolve('util/'),\n vm: require.resolve('vm-browserify'),\n zlib: require.resolve('browserify-zlib'),\n};\n\n/**\n * Get the default loader for JavaScript and TypeScript files, based on the\n * config object.\n *\n * We use the `swc-loader`, which is a Webpack loader that uses the `SWC`\n * compiler, a much faster alternative to Babel and TypeScript's own compiler.\n *\n * @param config - The processed snap Webpack config.\n * @param config.sourceMap - Whether to generate source maps.\n * @see https://swc.rs/docs/usage/swc-loader\n * @returns The default loader.\n */\nexport async function getDefaultLoader({ sourceMap }: ProcessedConfig) {\n const targets = await getBrowserslistTargets();\n return {\n /**\n * We use the `swc-loader` to transpile TypeScript and JavaScript files.\n * This is a Webpack loader that uses the `SWC` compiler, which is a much\n * faster alternative to Babel and TypeScript's own compiler.\n */\n loader: require.resolve('swc-loader'),\n\n /**\n * The options for the `swc-loader`. These can be overridden in the\n * `.swcrc` file.\n *\n * @see https://swc.rs/docs/configuration/swcrc\n */\n options: {\n sync: false,\n\n /**\n * This tells SWC to generate source maps. We set it to the\n * `sourceMap` value from the config object.\n *\n * This must be enabled if source maps are enabled in the config.\n */\n sourceMaps: Boolean(getDevTool(sourceMap)),\n\n jsc: {\n parser: {\n /**\n * This tells the parser to parse TypeScript files. If you\n * don't need to support TypeScript, you can set this to\n * `ecmascript` instead, but there's no harm in leaving it\n * as `typescript`.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n */\n syntax: 'typescript',\n\n /**\n * This tells the parser to transpile JSX.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n * @see https://swc.rs/docs/configuration/compilation#jscparserjsx\n */\n tsx: true,\n },\n\n transform: {\n react: {\n /**\n * This tells SWC to use the JSX runtime, instead of the\n * `createElement` function.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n runtime: 'automatic',\n\n /**\n * This tells SWC to import the JSX runtime from the\n * `@metamask/snaps-sdk` package, instead of the default React\n * package.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n importSource: '@metamask/snaps-sdk',\n\n /**\n * This tells SWC to use `Object.assign` and `Object.create` for\n * JSX spread attributes, instead of the default behavior.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n useBuiltins: true,\n },\n },\n },\n\n /**\n * The module configuration. This tells SWC how to output the\n * transpiled code.\n *\n * @see https://swc.rs/docs/configuration/modules\n */\n module: {\n /**\n * This tells SWC to output ES6 modules. This will allow Webpack to\n * optimize the output code better. Snaps don't support ES6 however, so\n * the output code will be transpiled to CommonJS by Webpack later in\n * the build process.\n *\n * @see https://swc.rs/docs/configuration/modules#es6\n */\n type: 'es6',\n },\n\n env: {\n targets: targets.join(', '),\n },\n },\n };\n}\n\n/**\n * Get the Webpack devtool configuration based on the given snap config.\n *\n * - If `sourceMap` is `inline`, return `inline-source-map`.\n * - If `sourceMap` is `true`, return `source-map`.\n * - Otherwise, return `false`.\n *\n * @param sourceMap - The `sourceMap` value from the snap config.\n * @returns The Webpack devtool configuration.\n */\nexport function getDevTool(\n sourceMap: ProcessedConfig['sourceMap'],\n): Configuration['devtool'] {\n if (sourceMap === 'inline') {\n return 'inline-source-map';\n }\n\n if (sourceMap) {\n return 'source-map';\n }\n\n return false;\n}\n\n/**\n * Get a function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n *\n * @param spinner - The spinner to update.\n * @param spinnerText - The initial spinner text. This will be prepended to the\n * percentage.\n * @returns A function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n */\n// Note: This is extracted for testing purposes.\nexport function getProgressHandler(spinner?: Ora, spinnerText?: string) {\n return (percentage: number) => {\n if (spinner && spinnerText) {\n spinner.text = `${spinnerText} ${dim(\n `(${Math.round(percentage * 100)}%)`,\n )}`;\n }\n };\n}\n\n/**\n * Get the targets from the `.browserslistrc` file.\n *\n * @returns The browser targets as an array of strings.\n */\nexport async function getBrowserslistTargets() {\n const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');\n return contents\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line && !line.startsWith('#'));\n}\n\n/**\n * Get a singular or plural string based on the given count. This is useful for\n * generating messages like \"1 error\" or \"2 errors\". By default, the plural\n * string is the singular string with an \"s\" appended to it.\n *\n * This assumes that the text is in English, and likely won't work for some\n * other languages.\n *\n * @param count - The count.\n * @param singular - The singular string.\n * @param plural - The plural string.\n * @returns The singular or plural string.\n * @example\n * ```typescript\n * pluralize(1, 'error'); // => 'error'\n * pluralize(2, 'error'); // => 'errors'\n * pluralize(1, 'error', 'problem'); // => 'error'\n * pluralize(2, 'error', 'problems'); // => 'problems'\n * ```\n */\nexport function pluralize(\n count: number,\n singular: string,\n plural = `${singular}s`,\n) {\n return count === 1 ? singular : plural;\n}\n\n/**\n * Get an object that can be used as fallback config for Webpack's\n * `fallback` config.\n *\n * @param polyfills - The polyfill object from the snap config.\n * @returns The webpack fallback config.\n */\nexport function getFallbacks(polyfills: ProcessedConfig['polyfills']): {\n [index: string]: string | false;\n} {\n if (polyfills === true) {\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS] ?? false,\n ]),\n );\n }\n\n if (polyfills === false) {\n return Object.fromEntries(builtinModules.map((name) => [name, false]));\n }\n\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n polyfills[name as keyof ProcessedConfig['polyfills']]\n ? WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS]\n : false,\n ]),\n );\n}\n\n/**\n * Get an object that can be used as environment variables for Webpack's\n * `DefinePlugin`.\n *\n * @param environment - The environment object from the Snap config.\n * @param defaults - The default environment variables.\n * @returns The Webpack environment variables.\n */\nexport function getEnvironmentVariables(\n environment: Record<string, unknown>,\n defaults = {\n NODE_DEBUG: 'false',\n NODE_ENV: 'production',\n DEBUG: 'false',\n },\n) {\n return Object.fromEntries(\n Object.entries({\n ...defaults,\n ...environment,\n }).map(([key, value]) => [`process.env.${key}`, JSON.stringify(value)]),\n );\n}\n\n/**\n * Format the given line to fit within the terminal width.\n *\n * @param line - The line to format.\n * @param indent - The indentation to use.\n * @param initialIndent - The initial indentation to use, i.e., the indentation\n * for the first line.\n * @returns The formatted line.\n */\nfunction formatLine(line: string, indent: number, initialIndent: number) {\n const terminalWidth = process.stdout.columns;\n if (!terminalWidth) {\n return `${' '.repeat(initialIndent)}${line}`;\n }\n\n return line.split(' ').reduce(\n ({ formattedText, currentLineLength }, word, index) => {\n // `chalk` adds ANSI escape codes to the text, which are not visible\n // characters. We need to strip them to get the visible length of the\n // text.\n const visibleWord = stripAnsi(word);\n\n // Determine if a space should be added before the word.\n const spaceBeforeWord = index > 0 ? ' ' : '';\n const wordLengthWithSpace = visibleWord.length + spaceBeforeWord.length;\n\n // If the word would exceed the terminal width, start a new line.\n if (currentLineLength + wordLengthWithSpace > terminalWidth) {\n return {\n formattedText: `${formattedText}\\n${' '.repeat(indent)}${word}`,\n currentLineLength: indent + visibleWord.length,\n };\n }\n\n // Otherwise, add the word to the current line.\n return {\n formattedText: formattedText + spaceBeforeWord + word,\n currentLineLength: currentLineLength + wordLengthWithSpace,\n };\n },\n {\n formattedText: ' '.repeat(initialIndent),\n currentLineLength: initialIndent,\n },\n ).formattedText;\n}\n\n/**\n * Format the given text to fit within the terminal width.\n *\n * @param text - The text to format.\n * @param indent - The indentation to use.\n * @param initialIndent - The initial indentation to use, i.e., the indentation\n * for the first line.\n * @returns The formatted text.\n */\nexport function formatText(\n text: string,\n indent: number,\n initialIndent = indent,\n) {\n const lines = text.split('\\n');\n\n // Apply formatting to each line separately and then join them.\n return lines\n .map((line, index) => {\n const lineIndent = index === 0 ? initialIndent : indent;\n return formatLine(line, indent, lineIndent);\n })\n .join('\\n');\n}\n\n/**\n * Get an SVG from the given bytes and mime type.\n *\n * @param mimeType - The mime type of the image.\n * @param bytes - The image bytes.\n * @returns The SVG.\n */\nexport function getImageSVG(mimeType: string, bytes: Uint8Array) {\n const dataUrl = `data:${mimeType};base64,${bytesToBase64(bytes)}`;\n return `<svg xmlns=\"http://www.w3.org/2000/svg\"><image href=\"${dataUrl}\" /></svg>`;\n}\n\n/**\n * Read a file from a Webpack input or output file system.\n *\n * @param fileSystem - The Webpack file system.\n * @param path - The path to the file.\n * @returns The file contents.\n */\nexport async function readWebpackFile(\n fileSystem: InputFileSystem | OutputFileSystem,\n path: string,\n): Promise<string> {\n // This function doesn't use `promisify`, since it doesn't seem to infer the\n // correct type when providing an encoding. We also can't use `readFileSync`,\n // because it isn't guaranteed to be available on all file systems.\n return new Promise((resolvePromise, rejectPromise) => {\n fileSystem.readFile(path, 'utf-8', (error, data) => {\n if (error) {\n rejectPromise(error);\n return;\n }\n\n // Webpack's file system can return `undefined` according to its types,\n // in which case we assume the file was not found.\n if (data === undefined) {\n rejectPromise(new Error(`File not found: \"${path}\".`));\n return;\n }\n\n resolvePromise(data);\n });\n });\n}\n"]}
|
package/dist/webpack/utils.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Ora } from "ora/index.js";
|
|
2
|
-
import type { Configuration } from "webpack";
|
|
2
|
+
import type { Configuration, InputFileSystem, OutputFileSystem } from "webpack";
|
|
3
3
|
import type { ProcessedConfig } from "../config.cjs";
|
|
4
4
|
export declare const BROWSERSLIST_FILE: string;
|
|
5
5
|
export declare const WEBPACK_FALLBACKS: {
|
|
@@ -226,4 +226,12 @@ export declare function formatText(text: string, indent: number, initialIndent?:
|
|
|
226
226
|
* @returns The SVG.
|
|
227
227
|
*/
|
|
228
228
|
export declare function getImageSVG(mimeType: string, bytes: Uint8Array): string;
|
|
229
|
+
/**
|
|
230
|
+
* Read a file from a Webpack input or output file system.
|
|
231
|
+
*
|
|
232
|
+
* @param fileSystem - The Webpack file system.
|
|
233
|
+
* @param path - The path to the file.
|
|
234
|
+
* @returns The file contents.
|
|
235
|
+
*/
|
|
236
|
+
export declare function readWebpackFile(fileSystem: InputFileSystem | OutputFileSystem, path: string): Promise<string>;
|
|
229
237
|
//# sourceMappingURL=utils.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/webpack/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,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MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;CACjC,CAsBA;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,QAAQ;;;;CAIP;;EAQF;AAiDD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,aAAa,SAAS,UAWvB;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,UAG9D;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,UAAU,EAAE,eAAe,GAAG,gBAAgB,EAC9C,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,CAAC,CAqBjB"}
|
package/dist/webpack/utils.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Ora } from "ora/index.js";
|
|
2
|
-
import type { Configuration } from "webpack";
|
|
2
|
+
import type { Configuration, InputFileSystem, OutputFileSystem } from "webpack";
|
|
3
3
|
import type { ProcessedConfig } from "../config.mjs";
|
|
4
4
|
export declare const BROWSERSLIST_FILE: string;
|
|
5
5
|
export declare const WEBPACK_FALLBACKS: {
|
|
@@ -226,4 +226,12 @@ export declare function formatText(text: string, indent: number, initialIndent?:
|
|
|
226
226
|
* @returns The SVG.
|
|
227
227
|
*/
|
|
228
228
|
export declare function getImageSVG(mimeType: string, bytes: Uint8Array): string;
|
|
229
|
+
/**
|
|
230
|
+
* Read a file from a Webpack input or output file system.
|
|
231
|
+
*
|
|
232
|
+
* @param fileSystem - The Webpack file system.
|
|
233
|
+
* @param path - The path to the file.
|
|
234
|
+
* @returns The file contents.
|
|
235
|
+
*/
|
|
236
|
+
export declare function readWebpackFile(fileSystem: InputFileSystem | OutputFileSystem, path: string): Promise<string>;
|
|
229
237
|
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/webpack/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB;
|
|
1
|
+
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/webpack/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAG/B,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB;AAEhF,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAEjD,eAAO,MAAM,iBAAiB,QAG7B,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiC7B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAsB,gBAAgB,CAAC,EAAE,SAAS,EAAE,EAAE,eAAe;IAGjE;;;;OAIG;;IAGH;;;;;OAKG;;;QAID;;;;;WAKG;;;;gBAKC;;;;;;;mBAOG;;gBAGH;;;;;mBAKG;;;;;oBAMD;;;;;uBAKG;;oBAGH;;;;;;uBAMG;;oBAGH;;;;;uBAKG;;;;;QAMT;;;;;WAKG;;YAED;;;;;;;eAOG;;;;;;;GASV;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,eAAe,CAAC,WAAW,CAAC,GACtC,aAAa,CAAC,SAAS,CAAC,CAU1B;AAED;;;;;;;;;GASG;AAEH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,EAAE,MAAM,gBAChD,MAAM,UAO3B;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,sBAM3C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,MAAM,SAAiB,UAGxB;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,eAAe,CAAC,WAAW,CAAC,GAAG;IACrE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;CACjC,CAsBA;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,QAAQ;;;;CAIP;;EAQF;AAiDD;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,aAAa,SAAS,UAWvB;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,UAG9D;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,UAAU,EAAE,eAAe,GAAG,gBAAgB,EAC9C,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,CAAC,CAqBjB"}
|
package/dist/webpack/utils.mjs
CHANGED
|
@@ -335,4 +335,31 @@ export function getImageSVG(mimeType, bytes) {
|
|
|
335
335
|
const dataUrl = `data:${mimeType};base64,${bytesToBase64(bytes)}`;
|
|
336
336
|
return `<svg xmlns="http://www.w3.org/2000/svg"><image href="${dataUrl}" /></svg>`;
|
|
337
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Read a file from a Webpack input or output file system.
|
|
340
|
+
*
|
|
341
|
+
* @param fileSystem - The Webpack file system.
|
|
342
|
+
* @param path - The path to the file.
|
|
343
|
+
* @returns The file contents.
|
|
344
|
+
*/
|
|
345
|
+
export async function readWebpackFile(fileSystem, path) {
|
|
346
|
+
// This function doesn't use `promisify`, since it doesn't seem to infer the
|
|
347
|
+
// correct type when providing an encoding. We also can't use `readFileSync`,
|
|
348
|
+
// because it isn't guaranteed to be available on all file systems.
|
|
349
|
+
return new Promise((resolvePromise, rejectPromise) => {
|
|
350
|
+
fileSystem.readFile(path, 'utf-8', (error, data) => {
|
|
351
|
+
if (error) {
|
|
352
|
+
rejectPromise(error);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
// Webpack's file system can return `undefined` according to its types,
|
|
356
|
+
// in which case we assume the file was not found.
|
|
357
|
+
if (data === undefined) {
|
|
358
|
+
rejectPromise(new Error(`File not found: "${path}".`));
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
resolvePromise(data);
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
}
|
|
338
365
|
//# sourceMappingURL=utils.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/webpack/utils.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,wBAAwB;;;AAEhD,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,WAAW;AACpC,OAAO,EAAE,cAAc,EAAE,eAAe;AAExC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa;AACxC,OAAO,UAAS,4BAAmB;;AAKnC,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CACtC,OAAO,kBAAiB,kCAAkC,EAAE,EAC5D,iBAAiB,CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM,mBAAkB,SAAS,CAAC;IAClC,MAAM,mBAAkB,SAAS,CAAC;IAClC,OAAO,mBAAkB,oBAAoB,CAAC;IAC9C,SAAS,mBAAkB,sBAAsB,CAAC;IAClD,MAAM,mBAAkB,mBAAmB,CAAC;IAC5C,MAAM,mBAAkB,gBAAgB,CAAC;IACzC,MAAM,mBAAkB,SAAS,CAAC;IAClC,IAAI,mBAAkB,aAAa,CAAC;IACpC,KAAK,mBAAkB,kBAAkB,CAAC;IAC1C,EAAE,mBAAkB,uBAAuB,CAAC;IAC5C,IAAI,mBAAkB,iBAAiB,CAAC;IACxC,QAAQ,mBAAkB,W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a,CAAC;QACxC,iBAAiB,EAAE,aAAa;KACjC,CACF,CAAC,aAAa,CAAC;AAClB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACxB,IAAY,EACZ,MAAc,EACd,aAAa,GAAG,MAAM;IAEtB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE/B,+DAA+D;IAC/D,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACnB,MAAM,UAAU,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC;QACxD,OAAO,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC9C,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,QAAgB,EAAE,KAAiB;IAC7D,MAAM,OAAO,GAAG,QAAQ,QAAQ,WAAW,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;IAClE,OAAO,wDAAwD,OAAO,YAAY,CAAC;AACrF,CAAC","sourcesContent":["import { bytesToBase64 } from '@metamask/utils';\nimport { dim } from 'chalk';\nimport { promises as fs } from 'fs';\nimport { builtinModules } from 'module';\nimport type { Ora } from 'ora';\nimport { dirname, resolve } from 'path';\nimport stripAnsi from 'strip-ansi';\nimport type { Configuration } from 'webpack';\n\nimport type { ProcessedConfig } from '../config';\n\nexport const BROWSERSLIST_FILE = resolve(\n dirname(require.resolve('@metamask/snaps-cli/package.json')),\n '.browserslistrc',\n);\n\nexport const WEBPACK_FALLBACKS = {\n assert: require.resolve('assert/'),\n buffer: require.resolve('buffer/'),\n console: require.resolve('console-browserify'),\n constants: require.resolve('constants-browserify'),\n crypto: require.resolve('crypto-browserify'),\n domain: require.resolve('domain-browser'),\n events: require.resolve('events/'),\n http: require.resolve('stream-http'),\n https: require.resolve('https-browserify'),\n os: require.resolve('os-browserify/browser'),\n path: require.resolve('path-browserify'),\n punycode: require.resolve('punycode/'),\n process: require.resolve('process/browser'),\n querystring: require.resolve('querystring-es3'),\n stream: require.resolve('stream-browserify'),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),\n _stream_passthrough: require.resolve(\n 'readable-stream/lib/_stream_passthrough',\n ),\n _stream_readable: require.resolve('readable-stream/lib/_stream_readable'),\n _stream_transform: require.resolve('readable-stream/lib/_stream_transform'),\n _stream_writable: require.resolve('readable-stream/lib/_stream_writable'),\n string_decoder: require.resolve('string_decoder/'),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: require.resolve('util/'),\n timers: require.resolve('timers-browserify'),\n tty: require.resolve('tty-browserify'),\n url: require.resolve('url/'),\n util: require.resolve('util/'),\n vm: require.resolve('vm-browserify'),\n zlib: require.resolve('browserify-zlib'),\n};\n\n/**\n * Get the default loader for JavaScript and TypeScript files, based on the\n * config object.\n *\n * We use the `swc-loader`, which is a Webpack loader that uses the `SWC`\n * compiler, a much faster alternative to Babel and TypeScript's own compiler.\n *\n * @param config - The processed snap Webpack config.\n * @param config.sourceMap - Whether to generate source maps.\n * @see https://swc.rs/docs/usage/swc-loader\n * @returns The default loader.\n */\nexport async function getDefaultLoader({ sourceMap }: ProcessedConfig) {\n const targets = await getBrowserslistTargets();\n return {\n /**\n * We use the `swc-loader` to transpile TypeScript and JavaScript files.\n * This is a Webpack loader that uses the `SWC` compiler, which is a much\n * faster alternative to Babel and TypeScript's own compiler.\n */\n loader: require.resolve('swc-loader'),\n\n /**\n * The options for the `swc-loader`. These can be overridden in the\n * `.swcrc` file.\n *\n * @see https://swc.rs/docs/configuration/swcrc\n */\n options: {\n sync: false,\n\n /**\n * This tells SWC to generate source maps. We set it to the\n * `sourceMap` value from the config object.\n *\n * This must be enabled if source maps are enabled in the config.\n */\n sourceMaps: Boolean(getDevTool(sourceMap)),\n\n jsc: {\n parser: {\n /**\n * This tells the parser to parse TypeScript files. If you\n * don't need to support TypeScript, you can set this to\n * `ecmascript` instead, but there's no harm in leaving it\n * as `typescript`.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n */\n syntax: 'typescript',\n\n /**\n * This tells the parser to transpile JSX.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n * @see https://swc.rs/docs/configuration/compilation#jscparserjsx\n */\n tsx: true,\n },\n\n transform: {\n react: {\n /**\n * This tells SWC to use the JSX runtime, instead of the\n * `createElement` function.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n runtime: 'automatic',\n\n /**\n * This tells SWC to import the JSX runtime from the\n * `@metamask/snaps-sdk` package, instead of the default React\n * package.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n importSource: '@metamask/snaps-sdk',\n\n /**\n * This tells SWC to use `Object.assign` and `Object.create` for\n * JSX spread attributes, instead of the default behavior.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n useBuiltins: true,\n },\n },\n },\n\n /**\n * The module configuration. This tells SWC how to output the\n * transpiled code.\n *\n * @see https://swc.rs/docs/configuration/modules\n */\n module: {\n /**\n * This tells SWC to output ES6 modules. This will allow Webpack to\n * optimize the output code better. Snaps don't support ES6 however, so\n * the output code will be transpiled to CommonJS by Webpack later in\n * the build process.\n *\n * @see https://swc.rs/docs/configuration/modules#es6\n */\n type: 'es6',\n },\n\n env: {\n targets: targets.join(', '),\n },\n },\n };\n}\n\n/**\n * Get the Webpack devtool configuration based on the given snap config.\n *\n * - If `sourceMap` is `inline`, return `inline-source-map`.\n * - If `sourceMap` is `true`, return `source-map`.\n * - Otherwise, return `false`.\n *\n * @param sourceMap - The `sourceMap` value from the snap config.\n * @returns The Webpack devtool configuration.\n */\nexport function getDevTool(\n sourceMap: ProcessedConfig['sourceMap'],\n): Configuration['devtool'] {\n if (sourceMap === 'inline') {\n return 'inline-source-map';\n }\n\n if (sourceMap) {\n return 'source-map';\n }\n\n return false;\n}\n\n/**\n * Get a function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n *\n * @param spinner - The spinner to update.\n * @param spinnerText - The initial spinner text. This will be prepended to the\n * percentage.\n * @returns A function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n */\n// Note: This is extracted for testing purposes.\nexport function getProgressHandler(spinner?: Ora, spinnerText?: string) {\n return (percentage: number) => {\n if (spinner && spinnerText) {\n spinner.text = `${spinnerText} ${dim(\n `(${Math.round(percentage * 100)}%)`,\n )}`;\n }\n };\n}\n\n/**\n * Get the targets from the `.browserslistrc` file.\n *\n * @returns The browser targets as an array of strings.\n */\nexport async function getBrowserslistTargets() {\n const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');\n return contents\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line && !line.startsWith('#'));\n}\n\n/**\n * Get a singular or plural string based on the given count. This is useful for\n * generating messages like \"1 error\" or \"2 errors\". By default, the plural\n * string is the singular string with an \"s\" appended to it.\n *\n * This assumes that the text is in English, and likely won't work for some\n * other languages.\n *\n * @param count - The count.\n * @param singular - The singular string.\n * @param plural - The plural string.\n * @returns The singular or plural string.\n * @example\n * ```typescript\n * pluralize(1, 'error'); // => 'error'\n * pluralize(2, 'error'); // => 'errors'\n * pluralize(1, 'error', 'problem'); // => 'error'\n * pluralize(2, 'error', 'problems'); // => 'problems'\n * ```\n */\nexport function pluralize(\n count: number,\n singular: string,\n plural = `${singular}s`,\n) {\n return count === 1 ? singular : plural;\n}\n\n/**\n * Get an object that can be used as fallback config for Webpack's\n * `fallback` config.\n *\n * @param polyfills - The polyfill object from the snap config.\n * @returns The webpack fallback config.\n */\nexport function getFallbacks(polyfills: ProcessedConfig['polyfills']): {\n [index: string]: string | false;\n} {\n if (polyfills === true) {\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS] ?? false,\n ]),\n );\n }\n\n if (polyfills === false) {\n return Object.fromEntries(builtinModules.map((name) => [name, false]));\n }\n\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n polyfills[name as keyof ProcessedConfig['polyfills']]\n ? WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS]\n : false,\n ]),\n );\n}\n\n/**\n * Get an object that can be used as environment variables for Webpack's\n * `DefinePlugin`.\n *\n * @param environment - The environment object from the Snap config.\n * @param defaults - The default environment variables.\n * @returns The Webpack environment variables.\n */\nexport function getEnvironmentVariables(\n environment: Record<string, unknown>,\n defaults = {\n NODE_DEBUG: 'false',\n NODE_ENV: 'production',\n DEBUG: 'false',\n },\n) {\n return Object.fromEntries(\n Object.entries({\n ...defaults,\n ...environment,\n }).map(([key, value]) => [`process.env.${key}`, JSON.stringify(value)]),\n );\n}\n\n/**\n * Format the given line to fit within the terminal width.\n *\n * @param line - The line to format.\n * @param indent - The indentation to use.\n * @param initialIndent - The initial indentation to use, i.e., the indentation\n * for the first line.\n * @returns The formatted line.\n */\nfunction formatLine(line: string, indent: number, initialIndent: number) {\n const terminalWidth = process.stdout.columns;\n if (!terminalWidth) {\n return `${' '.repeat(initialIndent)}${line}`;\n }\n\n return line.split(' ').reduce(\n ({ formattedText, currentLineLength }, word, index) => {\n // `chalk` adds ANSI escape codes to the text, which are not visible\n // characters. We need to strip them to get the visible length of the\n // text.\n const visibleWord = stripAnsi(word);\n\n // Determine if a space should be added before the word.\n const spaceBeforeWord = index > 0 ? ' ' : '';\n const wordLengthWithSpace = visibleWord.length + spaceBeforeWord.length;\n\n // If the word would exceed the terminal width, start a new line.\n if (currentLineLength + wordLengthWithSpace > terminalWidth) {\n return {\n formattedText: `${formattedText}\\n${' '.repeat(indent)}${word}`,\n currentLineLength: indent + visibleWord.length,\n };\n }\n\n // Otherwise, add the word to the current line.\n return {\n formattedText: formattedText + spaceBeforeWord + word,\n currentLineLength: currentLineLength + wordLengthWithSpace,\n };\n },\n {\n formattedText: ' '.repeat(initialIndent),\n currentLineLength: initialIndent,\n },\n ).formattedText;\n}\n\n/**\n * Format the given text to fit within the terminal width.\n *\n * @param text - The text to format.\n * @param indent - The indentation to use.\n * @param initialIndent - The initial indentation to use, i.e., the indentation\n * for the first line.\n * @returns The formatted text.\n */\nexport function formatText(\n text: string,\n indent: number,\n initialIndent = indent,\n) {\n const lines = text.split('\\n');\n\n // Apply formatting to each line separately and then join them.\n return lines\n .map((line, index) => {\n const lineIndent = index === 0 ? initialIndent : indent;\n return formatLine(line, indent, lineIndent);\n })\n .join('\\n');\n}\n\n/**\n * Get an SVG from the given bytes and mime type.\n *\n * @param mimeType - The mime type of the image.\n * @param bytes - The image bytes.\n * @returns The SVG.\n */\nexport function getImageSVG(mimeType: string, bytes: Uint8Array) {\n const dataUrl = `data:${mimeType};base64,${bytesToBase64(bytes)}`;\n return `<svg xmlns=\"http://www.w3.org/2000/svg\"><image href=\"${dataUrl}\" /></svg>`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/webpack/utils.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,wBAAwB;;;AAEhD,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,WAAW;AACpC,OAAO,EAAE,cAAc,EAAE,eAAe;AAExC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa;AACxC,OAAO,UAAS,4BAAmB;;AAKnC,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CACtC,OAAO,kBAAiB,kCAAkC,EAAE,EAC5D,iBAAiB,CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM,mBAAkB,SAAS,CAAC;IAClC,MAAM,mBAAkB,SAAS,CAAC;IAClC,OAAO,mBAAkB,oBAAoB,CAAC;IAC9C,SAAS,mBAAkB,sBAAsB,CAAC;IAClD,MAAM,mBAAkB,mBAAmB,CAAC;IAC5C,MAAM,mBAAkB,gBAAgB,CAAC;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AAI,KAAK,EAAE,CAAC;gBACV,aAAa,CAAC,KAAK,CAAC,CAAC;gBACrB,OAAO;YACT,CAAC;YAED,uEAAuE;YACvE,kDAAkD;YAClD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,aAAa,CAAC,IAAI,KAAK,CAAC,oBAAoB,IAAI,IAAI,CAAC,CAAC,CAAC;gBACvD,OAAO;YACT,CAAC;YAED,cAAc,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { bytesToBase64 } from '@metamask/utils';\nimport { dim } from 'chalk';\nimport { promises as fs } from 'fs';\nimport { builtinModules } from 'module';\nimport type { Ora } from 'ora';\nimport { dirname, resolve } from 'path';\nimport stripAnsi from 'strip-ansi';\nimport type { Configuration, InputFileSystem, OutputFileSystem } from 'webpack';\n\nimport type { ProcessedConfig } from '../config';\n\nexport const BROWSERSLIST_FILE = resolve(\n dirname(require.resolve('@metamask/snaps-cli/package.json')),\n '.browserslistrc',\n);\n\nexport const WEBPACK_FALLBACKS = {\n assert: require.resolve('assert/'),\n buffer: require.resolve('buffer/'),\n console: require.resolve('console-browserify'),\n constants: require.resolve('constants-browserify'),\n crypto: require.resolve('crypto-browserify'),\n domain: require.resolve('domain-browser'),\n events: require.resolve('events/'),\n http: require.resolve('stream-http'),\n https: require.resolve('https-browserify'),\n os: require.resolve('os-browserify/browser'),\n path: require.resolve('path-browserify'),\n punycode: require.resolve('punycode/'),\n process: require.resolve('process/browser'),\n querystring: require.resolve('querystring-es3'),\n stream: require.resolve('stream-browserify'),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),\n _stream_passthrough: require.resolve(\n 'readable-stream/lib/_stream_passthrough',\n ),\n _stream_readable: require.resolve('readable-stream/lib/_stream_readable'),\n _stream_transform: require.resolve('readable-stream/lib/_stream_transform'),\n _stream_writable: require.resolve('readable-stream/lib/_stream_writable'),\n string_decoder: require.resolve('string_decoder/'),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: require.resolve('util/'),\n timers: require.resolve('timers-browserify'),\n tty: require.resolve('tty-browserify'),\n url: require.resolve('url/'),\n util: require.resolve('util/'),\n vm: require.resolve('vm-browserify'),\n zlib: require.resolve('browserify-zlib'),\n};\n\n/**\n * Get the default loader for JavaScript and TypeScript files, based on the\n * config object.\n *\n * We use the `swc-loader`, which is a Webpack loader that uses the `SWC`\n * compiler, a much faster alternative to Babel and TypeScript's own compiler.\n *\n * @param config - The processed snap Webpack config.\n * @param config.sourceMap - Whether to generate source maps.\n * @see https://swc.rs/docs/usage/swc-loader\n * @returns The default loader.\n */\nexport async function getDefaultLoader({ sourceMap }: ProcessedConfig) {\n const targets = await getBrowserslistTargets();\n return {\n /**\n * We use the `swc-loader` to transpile TypeScript and JavaScript files.\n * This is a Webpack loader that uses the `SWC` compiler, which is a much\n * faster alternative to Babel and TypeScript's own compiler.\n */\n loader: require.resolve('swc-loader'),\n\n /**\n * The options for the `swc-loader`. These can be overridden in the\n * `.swcrc` file.\n *\n * @see https://swc.rs/docs/configuration/swcrc\n */\n options: {\n sync: false,\n\n /**\n * This tells SWC to generate source maps. We set it to the\n * `sourceMap` value from the config object.\n *\n * This must be enabled if source maps are enabled in the config.\n */\n sourceMaps: Boolean(getDevTool(sourceMap)),\n\n jsc: {\n parser: {\n /**\n * This tells the parser to parse TypeScript files. If you\n * don't need to support TypeScript, you can set this to\n * `ecmascript` instead, but there's no harm in leaving it\n * as `typescript`.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n */\n syntax: 'typescript',\n\n /**\n * This tells the parser to transpile JSX.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n * @see https://swc.rs/docs/configuration/compilation#jscparserjsx\n */\n tsx: true,\n },\n\n transform: {\n react: {\n /**\n * This tells SWC to use the JSX runtime, instead of the\n * `createElement` function.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n runtime: 'automatic',\n\n /**\n * This tells SWC to import the JSX runtime from the\n * `@metamask/snaps-sdk` package, instead of the default React\n * package.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n importSource: '@metamask/snaps-sdk',\n\n /**\n * This tells SWC to use `Object.assign` and `Object.create` for\n * JSX spread attributes, instead of the default behavior.\n *\n * @see https://swc.rs/docs/configuration/compilation#jsctransformreact\n */\n useBuiltins: true,\n },\n },\n },\n\n /**\n * The module configuration. This tells SWC how to output the\n * transpiled code.\n *\n * @see https://swc.rs/docs/configuration/modules\n */\n module: {\n /**\n * This tells SWC to output ES6 modules. This will allow Webpack to\n * optimize the output code better. Snaps don't support ES6 however, so\n * the output code will be transpiled to CommonJS by Webpack later in\n * the build process.\n *\n * @see https://swc.rs/docs/configuration/modules#es6\n */\n type: 'es6',\n },\n\n env: {\n targets: targets.join(', '),\n },\n },\n };\n}\n\n/**\n * Get the Webpack devtool configuration based on the given snap config.\n *\n * - If `sourceMap` is `inline`, return `inline-source-map`.\n * - If `sourceMap` is `true`, return `source-map`.\n * - Otherwise, return `false`.\n *\n * @param sourceMap - The `sourceMap` value from the snap config.\n * @returns The Webpack devtool configuration.\n */\nexport function getDevTool(\n sourceMap: ProcessedConfig['sourceMap'],\n): Configuration['devtool'] {\n if (sourceMap === 'inline') {\n return 'inline-source-map';\n }\n\n if (sourceMap) {\n return 'source-map';\n }\n\n return false;\n}\n\n/**\n * Get a function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n *\n * @param spinner - The spinner to update.\n * @param spinnerText - The initial spinner text. This will be prepended to the\n * percentage.\n * @returns A function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n */\n// Note: This is extracted for testing purposes.\nexport function getProgressHandler(spinner?: Ora, spinnerText?: string) {\n return (percentage: number) => {\n if (spinner && spinnerText) {\n spinner.text = `${spinnerText} ${dim(\n `(${Math.round(percentage * 100)}%)`,\n )}`;\n }\n };\n}\n\n/**\n * Get the targets from the `.browserslistrc` file.\n *\n * @returns The browser targets as an array of strings.\n */\nexport async function getBrowserslistTargets() {\n const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');\n return contents\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line && !line.startsWith('#'));\n}\n\n/**\n * Get a singular or plural string based on the given count. This is useful for\n * generating messages like \"1 error\" or \"2 errors\". By default, the plural\n * string is the singular string with an \"s\" appended to it.\n *\n * This assumes that the text is in English, and likely won't work for some\n * other languages.\n *\n * @param count - The count.\n * @param singular - The singular string.\n * @param plural - The plural string.\n * @returns The singular or plural string.\n * @example\n * ```typescript\n * pluralize(1, 'error'); // => 'error'\n * pluralize(2, 'error'); // => 'errors'\n * pluralize(1, 'error', 'problem'); // => 'error'\n * pluralize(2, 'error', 'problems'); // => 'problems'\n * ```\n */\nexport function pluralize(\n count: number,\n singular: string,\n plural = `${singular}s`,\n) {\n return count === 1 ? singular : plural;\n}\n\n/**\n * Get an object that can be used as fallback config for Webpack's\n * `fallback` config.\n *\n * @param polyfills - The polyfill object from the snap config.\n * @returns The webpack fallback config.\n */\nexport function getFallbacks(polyfills: ProcessedConfig['polyfills']): {\n [index: string]: string | false;\n} {\n if (polyfills === true) {\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS] ?? false,\n ]),\n );\n }\n\n if (polyfills === false) {\n return Object.fromEntries(builtinModules.map((name) => [name, false]));\n }\n\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n polyfills[name as keyof ProcessedConfig['polyfills']]\n ? WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS]\n : false,\n ]),\n );\n}\n\n/**\n * Get an object that can be used as environment variables for Webpack's\n * `DefinePlugin`.\n *\n * @param environment - The environment object from the Snap config.\n * @param defaults - The default environment variables.\n * @returns The Webpack environment variables.\n */\nexport function getEnvironmentVariables(\n environment: Record<string, unknown>,\n defaults = {\n NODE_DEBUG: 'false',\n NODE_ENV: 'production',\n DEBUG: 'false',\n },\n) {\n return Object.fromEntries(\n Object.entries({\n ...defaults,\n ...environment,\n }).map(([key, value]) => [`process.env.${key}`, JSON.stringify(value)]),\n );\n}\n\n/**\n * Format the given line to fit within the terminal width.\n *\n * @param line - The line to format.\n * @param indent - The indentation to use.\n * @param initialIndent - The initial indentation to use, i.e., the indentation\n * for the first line.\n * @returns The formatted line.\n */\nfunction formatLine(line: string, indent: number, initialIndent: number) {\n const terminalWidth = process.stdout.columns;\n if (!terminalWidth) {\n return `${' '.repeat(initialIndent)}${line}`;\n }\n\n return line.split(' ').reduce(\n ({ formattedText, currentLineLength }, word, index) => {\n // `chalk` adds ANSI escape codes to the text, which are not visible\n // characters. We need to strip them to get the visible length of the\n // text.\n const visibleWord = stripAnsi(word);\n\n // Determine if a space should be added before the word.\n const spaceBeforeWord = index > 0 ? ' ' : '';\n const wordLengthWithSpace = visibleWord.length + spaceBeforeWord.length;\n\n // If the word would exceed the terminal width, start a new line.\n if (currentLineLength + wordLengthWithSpace > terminalWidth) {\n return {\n formattedText: `${formattedText}\\n${' '.repeat(indent)}${word}`,\n currentLineLength: indent + visibleWord.length,\n };\n }\n\n // Otherwise, add the word to the current line.\n return {\n formattedText: formattedText + spaceBeforeWord + word,\n currentLineLength: currentLineLength + wordLengthWithSpace,\n };\n },\n {\n formattedText: ' '.repeat(initialIndent),\n currentLineLength: initialIndent,\n },\n ).formattedText;\n}\n\n/**\n * Format the given text to fit within the terminal width.\n *\n * @param text - The text to format.\n * @param indent - The indentation to use.\n * @param initialIndent - The initial indentation to use, i.e., the indentation\n * for the first line.\n * @returns The formatted text.\n */\nexport function formatText(\n text: string,\n indent: number,\n initialIndent = indent,\n) {\n const lines = text.split('\\n');\n\n // Apply formatting to each line separately and then join them.\n return lines\n .map((line, index) => {\n const lineIndent = index === 0 ? initialIndent : indent;\n return formatLine(line, indent, lineIndent);\n })\n .join('\\n');\n}\n\n/**\n * Get an SVG from the given bytes and mime type.\n *\n * @param mimeType - The mime type of the image.\n * @param bytes - The image bytes.\n * @returns The SVG.\n */\nexport function getImageSVG(mimeType: string, bytes: Uint8Array) {\n const dataUrl = `data:${mimeType};base64,${bytesToBase64(bytes)}`;\n return `<svg xmlns=\"http://www.w3.org/2000/svg\"><image href=\"${dataUrl}\" /></svg>`;\n}\n\n/**\n * Read a file from a Webpack input or output file system.\n *\n * @param fileSystem - The Webpack file system.\n * @param path - The path to the file.\n * @returns The file contents.\n */\nexport async function readWebpackFile(\n fileSystem: InputFileSystem | OutputFileSystem,\n path: string,\n): Promise<string> {\n // This function doesn't use `promisify`, since it doesn't seem to infer the\n // correct type when providing an encoding. We also can't use `readFileSync`,\n // because it isn't guaranteed to be available on all file systems.\n return new Promise((resolvePromise, rejectPromise) => {\n fileSystem.readFile(path, 'utf-8', (error, data) => {\n if (error) {\n rejectPromise(error);\n return;\n }\n\n // Webpack's file system can return `undefined` according to its types,\n // in which case we assume the file was not found.\n if (data === undefined) {\n rejectPromise(new Error(`File not found: \"${path}\".`));\n return;\n }\n\n resolvePromise(data);\n });\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -64,13 +64,13 @@
|
|
|
64
64
|
"test:watch": "jest --watch"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@metamask/snaps-rpc-methods": "^
|
|
67
|
+
"@metamask/snaps-rpc-methods": "^14.2.0",
|
|
68
68
|
"@metamask/snaps-sandbox": "^1.0.0",
|
|
69
|
-
"@metamask/snaps-sdk": "^
|
|
70
|
-
"@metamask/snaps-utils": "^
|
|
71
|
-
"@metamask/snaps-webpack-plugin": "^5.1.
|
|
69
|
+
"@metamask/snaps-sdk": "^10.4.0",
|
|
70
|
+
"@metamask/snaps-utils": "^12.0.0",
|
|
71
|
+
"@metamask/snaps-webpack-plugin": "^5.1.2",
|
|
72
72
|
"@metamask/superstruct": "^3.2.1",
|
|
73
|
-
"@metamask/utils": "^11.
|
|
73
|
+
"@metamask/utils": "^11.9.0",
|
|
74
74
|
"@swc/core": "1.11.31",
|
|
75
75
|
"assert": "^2.0.0",
|
|
76
76
|
"browserify-zlib": "^0.2.0",
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
"yargs": "^17.7.1"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
|
-
"@lavamoat/allow-scripts": "^3.
|
|
112
|
+
"@lavamoat/allow-scripts": "^3.4.2",
|
|
113
113
|
"@metamask/auto-changelog": "^5.0.2",
|
|
114
114
|
"@swc/jest": "^0.2.38",
|
|
115
115
|
"@ts-bridge/cli": "^0.6.1",
|