@metamask/snaps-cli 6.3.2 → 6.3.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 +6 -1
- package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs +19 -1
- package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs.map +1 -1
- package/dist/commands/eval/__test__/webpack/good/snap.config.mjs +19 -1
- package/dist/commands/eval/__test__/webpack/good/snap.config.mjs.map +1 -1
- package/dist/commands/index.d.cts +1 -1
- package/dist/commands/index.d.mts +1 -1
- package/dist/webpack/loaders/browserify.cjs +8 -8
- package/dist/webpack/loaders/browserify.cjs.map +1 -1
- package/dist/webpack/loaders/browserify.mjs +10 -8
- package/dist/webpack/loaders/browserify.mjs.map +1 -1
- package/dist/webpack/loaders/function.mjs +5 -1
- package/dist/webpack/loaders/function.mjs.map +1 -1
- package/dist/webpack/utils.d.cts +4 -4
- package/dist/webpack/utils.d.mts +4 -4
- package/dist/webpack/utils.mjs +32 -32
- package/dist/webpack/utils.mjs.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [6.3.3]
|
|
10
|
+
### Fixed
|
|
11
|
+
- Fix invalid types in type declaration in some cases ([#2714](https://github.com/MetaMask/snaps/pull/2714))
|
|
12
|
+
|
|
9
13
|
## [6.3.2]
|
|
10
14
|
### Fixed
|
|
11
15
|
- Fix ESM version of the package ([#2682](https://github.com/MetaMask/snaps/pull/2682))
|
|
@@ -177,7 +181,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
177
181
|
- The version of the package no longer needs to match the version of all other
|
|
178
182
|
MetaMask Snaps packages.
|
|
179
183
|
|
|
180
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.3.
|
|
184
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.3.3...HEAD
|
|
185
|
+
[6.3.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.3.2...@metamask/snaps-cli@6.3.3
|
|
181
186
|
[6.3.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.3.1...@metamask/snaps-cli@6.3.2
|
|
182
187
|
[6.3.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.3.0...@metamask/snaps-cli@6.3.1
|
|
183
188
|
[6.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-cli@6.2.1...@metamask/snaps-cli@6.3.0
|
|
@@ -1,8 +1,26 @@
|
|
|
1
|
+
function $__filename(fileUrl) {
|
|
2
|
+
const url = new URL(fileUrl);
|
|
3
|
+
return url.pathname.replace(/^\/([a-zA-Z]:)/u, "$1");
|
|
4
|
+
}
|
|
5
|
+
function $getDirname(path) {
|
|
6
|
+
const sanitisedPath = path.toString().replace(/\\/gu, "/").replace(/\/$/u, "");
|
|
7
|
+
const index = sanitisedPath.lastIndexOf("/");
|
|
8
|
+
if (index === -1) {
|
|
9
|
+
return path;
|
|
10
|
+
}
|
|
11
|
+
if (index === 0) {
|
|
12
|
+
return "/";
|
|
13
|
+
}
|
|
14
|
+
return sanitisedPath.slice(0, index);
|
|
15
|
+
}
|
|
16
|
+
function $__dirname(url) {
|
|
17
|
+
return $getDirname($__filename(url));
|
|
18
|
+
}
|
|
1
19
|
const config = {
|
|
2
20
|
bundler: 'webpack',
|
|
3
21
|
input: 'src/index.ts',
|
|
4
22
|
output: {
|
|
5
|
-
path: __dirname,
|
|
23
|
+
path: $__dirname(import.meta.url),
|
|
6
24
|
filename: 'eval.js',
|
|
7
25
|
},
|
|
8
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snap.config.mjs","sourceRoot":"","sources":["../../../../../../src/commands/eval/__test__/webpack/bad/snap.config.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,GAAe;IACzB,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,cAAc;IACrB,MAAM,EAAE;QACN,IAAI,
|
|
1
|
+
{"version":3,"file":"snap.config.mjs","sourceRoot":"","sources":["../../../../../../src/commands/eval/__test__/webpack/bad/snap.config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAEA,MAAM,MAAM,GAAe;IACzB,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,cAAc;IACrB,MAAM,EAAE;QACN,IAAI,6BAAW;QACf,QAAQ,EAAE,SAAS;KACpB;CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import type { SnapConfig } from '../../../../../config';\n\nconst config: SnapConfig = {\n bundler: 'webpack',\n input: 'src/index.ts',\n output: {\n path: __dirname,\n filename: 'eval.js',\n },\n};\n\nexport default config;\n"]}
|
|
@@ -1,8 +1,26 @@
|
|
|
1
|
+
function $__filename(fileUrl) {
|
|
2
|
+
const url = new URL(fileUrl);
|
|
3
|
+
return url.pathname.replace(/^\/([a-zA-Z]:)/u, "$1");
|
|
4
|
+
}
|
|
5
|
+
function $getDirname(path) {
|
|
6
|
+
const sanitisedPath = path.toString().replace(/\\/gu, "/").replace(/\/$/u, "");
|
|
7
|
+
const index = sanitisedPath.lastIndexOf("/");
|
|
8
|
+
if (index === -1) {
|
|
9
|
+
return path;
|
|
10
|
+
}
|
|
11
|
+
if (index === 0) {
|
|
12
|
+
return "/";
|
|
13
|
+
}
|
|
14
|
+
return sanitisedPath.slice(0, index);
|
|
15
|
+
}
|
|
16
|
+
function $__dirname(url) {
|
|
17
|
+
return $getDirname($__filename(url));
|
|
18
|
+
}
|
|
1
19
|
const config = {
|
|
2
20
|
bundler: 'webpack',
|
|
3
21
|
input: 'src/index.ts',
|
|
4
22
|
output: {
|
|
5
|
-
path: __dirname,
|
|
23
|
+
path: $__dirname(import.meta.url),
|
|
6
24
|
filename: 'eval.js',
|
|
7
25
|
},
|
|
8
26
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snap.config.mjs","sourceRoot":"","sources":["../../../../../../src/commands/eval/__test__/webpack/good/snap.config.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,GAAe;IACzB,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,cAAc;IACrB,MAAM,EAAE;QACN,IAAI,
|
|
1
|
+
{"version":3,"file":"snap.config.mjs","sourceRoot":"","sources":["../../../../../../src/commands/eval/__test__/webpack/good/snap.config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAEA,MAAM,MAAM,GAAe;IACzB,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,cAAc;IACrB,MAAM,EAAE;QACN,IAAI,6BAAW;QACf,QAAQ,EAAE,SAAS;KACpB;CACF,CAAC;AAEF,eAAe,MAAM,CAAC","sourcesContent":["import type { SnapConfig } from '../../../../../config';\n\nconst config: SnapConfig = {\n bundler: 'webpack',\n input: 'src/index.ts',\n output: {\n path: __dirname,\n filename: 'eval.js',\n },\n};\n\nexport default config;\n"]}
|
|
@@ -3,7 +3,7 @@ declare const commands: {
|
|
|
3
3
|
command: string[];
|
|
4
4
|
desc: string;
|
|
5
5
|
builder: (yarg: import("yargs").Argv<{}>) => void;
|
|
6
|
-
handler: (argv: import("../types/yargs").YargsArgs) => Promise<void>;
|
|
6
|
+
handler: (argv: import("../types/yargs.d.cjs").YargsArgs) => Promise<void>;
|
|
7
7
|
}[];
|
|
8
8
|
export default commands;
|
|
9
9
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -3,7 +3,7 @@ declare const commands: {
|
|
|
3
3
|
command: string[];
|
|
4
4
|
desc: string;
|
|
5
5
|
builder: (yarg: import("yargs").Argv<{}>) => void;
|
|
6
|
-
handler: (argv: import("../types/yargs").YargsArgs) => Promise<void>;
|
|
6
|
+
handler: (argv: import("../types/yargs.d.mjs").YargsArgs) => Promise<void>;
|
|
7
7
|
}[];
|
|
8
8
|
export default commands;
|
|
9
9
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -34,13 +34,13 @@ const loader = async function (content, sourceMap) {
|
|
|
34
34
|
// We need to statically import all Browserify transforms, and all Babel
|
|
35
35
|
// presets and plugins, and calling `require` is the sanest way to do that.
|
|
36
36
|
/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */
|
|
37
|
-
bundler.transform(require(
|
|
37
|
+
bundler.transform(require("babelify/index.js"), {
|
|
38
38
|
global: transpilationMode === builders_1.TranspilationModes.LocalAndDeps,
|
|
39
39
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
40
40
|
presets: [
|
|
41
|
-
require(
|
|
41
|
+
require("@babel/preset-typescript"),
|
|
42
42
|
[
|
|
43
|
-
require(
|
|
43
|
+
require("@babel/preset-env"),
|
|
44
44
|
{
|
|
45
45
|
targets: {
|
|
46
46
|
browsers: await (0, utils_2.getBrowserslistTargets)(),
|
|
@@ -49,11 +49,11 @@ const loader = async function (content, sourceMap) {
|
|
|
49
49
|
],
|
|
50
50
|
],
|
|
51
51
|
plugins: [
|
|
52
|
-
require(
|
|
53
|
-
require(
|
|
54
|
-
require(
|
|
55
|
-
require(
|
|
56
|
-
require(
|
|
52
|
+
require("@babel/plugin-transform-runtime"),
|
|
53
|
+
require("@babel/plugin-transform-class-properties"),
|
|
54
|
+
require("@babel/plugin-transform-private-methods"),
|
|
55
|
+
require("@babel/plugin-transform-class-static-block"),
|
|
56
|
+
require("@babel/plugin-transform-private-property-in-object"),
|
|
57
57
|
],
|
|
58
58
|
...babelifyOptions,
|
|
59
59
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browserify.cjs","sourceRoot":"","sources":["../../../src/webpack/loaders/browserify.ts"],"names":[],"mappings":";;;;;AAAA,4DAAoC;AACpC,qDAA2C;AAG3C,iDAAoD;AAEpD,iDAAkD;AAClD,wCAAkD;AAElD;;;;;;;;;;;;GA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C;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC","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 * @returns The Browserify loader.\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', '.jsx', '.ts', '.tsx'],\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', '.jsx', '.ts', '.tsx'],\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"]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createRequire as $createRequire } from "module";
|
|
2
|
+
const $require = $createRequire(import.meta.url);
|
|
1
3
|
function $importDefault(module) {
|
|
2
4
|
if (module?.__esModule) {
|
|
3
5
|
return module.default;
|
|
@@ -36,13 +38,13 @@ const loader = async function (content, sourceMap) {
|
|
|
36
38
|
// We need to statically import all Browserify transforms, and all Babel
|
|
37
39
|
// presets and plugins, and calling `require` is the sanest way to do that.
|
|
38
40
|
/* eslint-disable @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */
|
|
39
|
-
bundler.transform(require(
|
|
41
|
+
bundler.transform($require("babelify/index.js"), {
|
|
40
42
|
global: transpilationMode === TranspilationModes.LocalAndDeps,
|
|
41
43
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
42
44
|
presets: [
|
|
43
|
-
require(
|
|
45
|
+
$require("@babel/preset-typescript"),
|
|
44
46
|
[
|
|
45
|
-
require(
|
|
47
|
+
$require("@babel/preset-env"),
|
|
46
48
|
{
|
|
47
49
|
targets: {
|
|
48
50
|
browsers: await getBrowserslistTargets(),
|
|
@@ -51,11 +53,11 @@ const loader = async function (content, sourceMap) {
|
|
|
51
53
|
],
|
|
52
54
|
],
|
|
53
55
|
plugins: [
|
|
54
|
-
require(
|
|
55
|
-
require(
|
|
56
|
-
require(
|
|
57
|
-
require(
|
|
58
|
-
require(
|
|
56
|
+
$require("@babel/plugin-transform-runtime"),
|
|
57
|
+
$require("@babel/plugin-transform-class-properties"),
|
|
58
|
+
$require("@babel/plugin-transform-private-methods"),
|
|
59
|
+
$require("@babel/plugin-transform-class-static-block"),
|
|
60
|
+
$require("@babel/plugin-transform-private-property-in-object"),
|
|
59
61
|
],
|
|
60
62
|
...babelifyOptions,
|
|
61
63
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browserify.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/browserify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"browserify.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/browserify.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,WAAU,mBAAmB;;AACpC,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAG3C,OAAO,EAAE,kBAAkB,EAAE,2BAAuB;AAEpD,OAAO,EAAE,mBAAmB,EAAE,8BAAoB;AAClD,OAAO,EAAE,sBAAsB,EAAE,qBAAiB;AAElD;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,GAA4C,KAAK,WAC3D,OAAO,EACP,SAAS;IAET,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IAEjC,MAAM,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAErC,MAAM,OAAO,GAAG,UAAU,CAAC;QACzB,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC;QAC1C,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC;QACzB,UAAU,EAAE,QAAQ;KACrB,CAAC,CAAC;IAEH,IAAI,iBAAiB,KAAK,kBAAkB,CAAC,IAAI,EAAE,CAAC;QAClD,MAAM,eAAe,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;QAEpD,wEAAwE;QACxE,2EAA2E;QAC3E,gHAAgH;QAChH,OAAO,CAAC,SAAS,gCAAsB;YACrC,MAAM,EAAE,iBAAiB,KAAK,kBAAkB,CAAC,YAAY;YAC7D,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC;YAC1C,OAAO,EAAE;;gBAEP;;oBAEE;wBACE,OAAO,EAAE;4BACP,QAAQ,EAAE,MAAM,sBAAsB,EAAE;yBACzC;qBACF;iBACF;aACF;YACD,OAAO,EAAE;;;;;;aAMR;YACD,GAAI,eAAuB;SAC5B,CAAC,CAAC;QACH,+GAA+G;IACjH,CAAC;IAED,MAAM,CAAC,iBAAiB,EAAE,CAAC,OAAO,CAAC,CAAC;IAEpC,8EAA8E;IAC9E,kBAAkB;IAClB,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;IAC9B,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAElB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE;QAClB,IAAI,EAAE,IAAI,CAAC,YAAY;KACxB,CAAC,CAAC;IAEH,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7C,OAAO,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,MAAc,EAAE,EAAE;YAC7C,IAAI,WAAW,EAAE,CAAC;gBAChB,MAAM,CAAC,WAAW,CAAC,CAAC;gBACpB,OAAO;YACT,CAAC;YAED,4EAA4E;YAC5E,cAAc;YACd,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC","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 * @returns The Browserify loader.\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', '.jsx', '.ts', '.tsx'],\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', '.jsx', '.ts', '.tsx'],\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"]}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
function $__filename(fileUrl) {
|
|
2
|
+
const url = new URL(fileUrl);
|
|
3
|
+
return url.pathname.replace(/^\/([a-zA-Z]:)/u, "$1");
|
|
4
|
+
}
|
|
1
5
|
/**
|
|
2
6
|
* A loader that executes a function. See {@link getFunctionLoader} for more
|
|
3
7
|
* information.
|
|
@@ -22,7 +26,7 @@ export function getFunctionLoader(fn, options) {
|
|
|
22
26
|
return {
|
|
23
27
|
// We use `__filename` as the loader, so Webpack will execute the loader in
|
|
24
28
|
// this file, with the actual function in the options.
|
|
25
|
-
loader: __filename,
|
|
29
|
+
loader: $__filename(import.meta.url),
|
|
26
30
|
options: {
|
|
27
31
|
fn,
|
|
28
32
|
...options,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":"AAaA;;;;;;GAMG;AACH,MAAM,MAAM,GAAoD,UAC9D,OAAO;IAEP,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IACjC,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,EAAqC,EACrC,OAAgB;IAEhB,OAAO;QACL,2EAA2E;QAC3E,sDAAsD;QACtD,MAAM,
|
|
1
|
+
{"version":3,"file":"function.mjs","sourceRoot":"","sources":["../../../src/webpack/loaders/function.ts"],"names":[],"mappings":";;;;AAaA;;;;;;GAMG;AACH,MAAM,MAAM,GAAoD,UAC9D,OAAO;IAEP,MAAM,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IACjC,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC;AAEtB;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC/B,EAAqC,EACrC,OAAgB;IAEhB,OAAO;QACL,2EAA2E;QAC3E,sDAAsD;QACtD,MAAM,8BAAY;QAClB,OAAO,EAAE;YACP,EAAE;YACF,GAAG,OAAO;SACX;KACF,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,yCAAyC;AACzC,yBAAyB;AACzB,4CAA4C;AAC5C,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,EAAE,GAAG,EAAE,QAAQ,KAAK,MAAM,EAAE,CAAC;IACvE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,OAAO,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IACrD,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC;AAC5B,CAAC","sourcesContent":["import type { LoaderDefinitionFunction } from 'webpack';\n\n/**\n * Options for the function loader.\n */\nexport type FunctionLoaderOptions = {\n /**\n * The function to execute. This is bound to the loader context, so it can\n * access the loader options and other properties.\n */\n fn: LoaderDefinitionFunction;\n};\n\n/**\n * A loader that executes a function. See {@link getFunctionLoader} for more\n * information.\n *\n * @param content - The input file contents as a `Uint8Array`.\n * @returns The output of the function.\n */\nconst loader: LoaderDefinitionFunction<FunctionLoaderOptions> = function (\n content,\n) {\n const { fn } = this.getOptions();\n return fn.bind(this)(content);\n};\n\nexport default loader;\n\n/**\n * Get a loader that executes the given function. This is useful for executing\n * loaders without needing to pass a file to Webpack.\n *\n * @param fn - The function to execute.\n * @param options - The options to pass to the loader.\n * @returns The loader definition.\n */\nexport function getFunctionLoader<Options>(\n fn: LoaderDefinitionFunction<Options>,\n options: Options,\n) {\n return {\n // We use `__filename` as the loader, so Webpack will execute the loader in\n // this file, with the actual function in the options.\n loader: __filename,\n options: {\n fn,\n ...options,\n },\n };\n}\n\n// When running as CJS, we need to export the loader as a default export, since\n// `tsup` exports it as `loader_default`.\n// istanbul ignore next 3\n// eslint-disable-next-line n/no-process-env\nif (typeof module !== 'undefined' && process?.env?.NODE_ENV !== 'test') {\n module.exports = loader;\n module.exports.getFunctionLoader = getFunctionLoader;\n module.exports.raw = true;\n}\n"]}
|
package/dist/webpack/utils.d.cts
CHANGED
|
@@ -53,23 +53,23 @@ export declare function getDefaultLoader({ legacy, sourceMap, }: ProcessedWebpac
|
|
|
53
53
|
loader: string;
|
|
54
54
|
options: {
|
|
55
55
|
fn: import("webpack").LoaderDefinitionFunction<{
|
|
56
|
-
transpilationMode: import("../builders").TranspilationModes.LocalAndDeps;
|
|
56
|
+
transpilationMode: import("../builders.cjs").TranspilationModes.LocalAndDeps;
|
|
57
57
|
depsToTranspile: string[];
|
|
58
58
|
writeManifest: boolean;
|
|
59
59
|
bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
|
|
60
60
|
} | {
|
|
61
|
-
transpilationMode: import("../builders").TranspilationModes.LocalOnly | import("../builders").TranspilationModes.None;
|
|
61
|
+
transpilationMode: import("../builders.cjs").TranspilationModes.LocalOnly | import("../builders.cjs").TranspilationModes.None;
|
|
62
62
|
depsToTranspile: unknown[];
|
|
63
63
|
writeManifest: boolean;
|
|
64
64
|
bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
|
|
65
65
|
}, {}>;
|
|
66
66
|
} & ({
|
|
67
|
-
transpilationMode: import("../builders").TranspilationModes.LocalAndDeps;
|
|
67
|
+
transpilationMode: import("../builders.cjs").TranspilationModes.LocalAndDeps;
|
|
68
68
|
depsToTranspile: string[];
|
|
69
69
|
writeManifest: boolean;
|
|
70
70
|
bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
|
|
71
71
|
} | {
|
|
72
|
-
transpilationMode: import("../builders").TranspilationModes.LocalOnly | import("../builders").TranspilationModes.None;
|
|
72
|
+
transpilationMode: import("../builders.cjs").TranspilationModes.LocalOnly | import("../builders.cjs").TranspilationModes.None;
|
|
73
73
|
depsToTranspile: unknown[];
|
|
74
74
|
writeManifest: boolean;
|
|
75
75
|
bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
|
package/dist/webpack/utils.d.mts
CHANGED
|
@@ -53,23 +53,23 @@ export declare function getDefaultLoader({ legacy, sourceMap, }: ProcessedWebpac
|
|
|
53
53
|
loader: string;
|
|
54
54
|
options: {
|
|
55
55
|
fn: import("webpack").LoaderDefinitionFunction<{
|
|
56
|
-
transpilationMode: import("../builders").TranspilationModes.LocalAndDeps;
|
|
56
|
+
transpilationMode: import("../builders.mjs").TranspilationModes.LocalAndDeps;
|
|
57
57
|
depsToTranspile: string[];
|
|
58
58
|
writeManifest: boolean;
|
|
59
59
|
bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
|
|
60
60
|
} | {
|
|
61
|
-
transpilationMode: import("../builders").TranspilationModes.LocalOnly | import("../builders").TranspilationModes.None;
|
|
61
|
+
transpilationMode: import("../builders.mjs").TranspilationModes.LocalOnly | import("../builders.mjs").TranspilationModes.None;
|
|
62
62
|
depsToTranspile: unknown[];
|
|
63
63
|
writeManifest: boolean;
|
|
64
64
|
bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
|
|
65
65
|
}, {}>;
|
|
66
66
|
} & ({
|
|
67
|
-
transpilationMode: import("../builders").TranspilationModes.LocalAndDeps;
|
|
67
|
+
transpilationMode: import("../builders.mjs").TranspilationModes.LocalAndDeps;
|
|
68
68
|
depsToTranspile: string[];
|
|
69
69
|
writeManifest: boolean;
|
|
70
70
|
bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
|
|
71
71
|
} | {
|
|
72
|
-
transpilationMode: import("../builders").TranspilationModes.LocalOnly | import("../builders").TranspilationModes.None;
|
|
72
|
+
transpilationMode: import("../builders.mjs").TranspilationModes.LocalOnly | import("../builders.mjs").TranspilationModes.None;
|
|
73
73
|
depsToTranspile: unknown[];
|
|
74
74
|
writeManifest: boolean;
|
|
75
75
|
bundlerCustomizer?: ((bundler: import("browserify").BrowserifyObject) => void) | undefined;
|
package/dist/webpack/utils.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createRequire as $createRequire } from "module";
|
|
2
|
+
const $require = $createRequire(import.meta.url);
|
|
1
3
|
function $importDefault(module) {
|
|
2
4
|
if (module?.__esModule) {
|
|
3
5
|
return module.default;
|
|
@@ -13,40 +15,38 @@ import { dirname, resolve } from "path";
|
|
|
13
15
|
import $stripAnsi from "strip-ansi/index.js";
|
|
14
16
|
const stripAnsi = $importDefault($stripAnsi);
|
|
15
17
|
import { browserify, getFunctionLoader } from "./loaders/index.mjs";
|
|
16
|
-
export const BROWSERSLIST_FILE = resolve(dirname(
|
|
17
|
-
// eslint-disable-next-line n/no-extraneous-require
|
|
18
|
-
require.resolve('@metamask/snaps-cli/package.json')), '.browserslistrc');
|
|
18
|
+
export const BROWSERSLIST_FILE = resolve(dirname($require.resolve('@metamask/snaps-cli/package.json')), '.browserslistrc');
|
|
19
19
|
export const WEBPACK_FALLBACKS = {
|
|
20
|
-
assert: require.resolve('assert/'),
|
|
21
|
-
buffer: require.resolve('buffer/'),
|
|
22
|
-
console: require.resolve('console-browserify'),
|
|
23
|
-
constants: require.resolve('constants-browserify'),
|
|
24
|
-
crypto: require.resolve('crypto-browserify'),
|
|
25
|
-
domain: require.resolve('domain-browser'),
|
|
26
|
-
events: require.resolve('events/'),
|
|
27
|
-
http: require.resolve('stream-http'),
|
|
28
|
-
https: require.resolve('https-browserify'),
|
|
29
|
-
os: require.resolve('os-browserify/browser'),
|
|
30
|
-
path: require.resolve('path-browserify'),
|
|
31
|
-
punycode: require.resolve('punycode/'),
|
|
32
|
-
process: require.resolve('process/browser'),
|
|
33
|
-
querystring: require.resolve('querystring-es3'),
|
|
34
|
-
stream: require.resolve('stream-browserify'),
|
|
20
|
+
assert: $require.resolve('assert/'),
|
|
21
|
+
buffer: $require.resolve('buffer/'),
|
|
22
|
+
console: $require.resolve('console-browserify'),
|
|
23
|
+
constants: $require.resolve('constants-browserify'),
|
|
24
|
+
crypto: $require.resolve('crypto-browserify'),
|
|
25
|
+
domain: $require.resolve('domain-browser'),
|
|
26
|
+
events: $require.resolve('events/'),
|
|
27
|
+
http: $require.resolve('stream-http'),
|
|
28
|
+
https: $require.resolve('https-browserify'),
|
|
29
|
+
os: $require.resolve('os-browserify/browser'),
|
|
30
|
+
path: $require.resolve('path-browserify'),
|
|
31
|
+
punycode: $require.resolve('punycode/'),
|
|
32
|
+
process: $require.resolve('process/browser'),
|
|
33
|
+
querystring: $require.resolve('querystring-es3'),
|
|
34
|
+
stream: $require.resolve('stream-browserify'),
|
|
35
35
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
36
|
-
_stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),
|
|
37
|
-
_stream_passthrough: require.resolve('readable-stream/lib/_stream_passthrough'),
|
|
38
|
-
_stream_readable: require.resolve('readable-stream/lib/_stream_readable'),
|
|
39
|
-
_stream_transform: require.resolve('readable-stream/lib/_stream_transform'),
|
|
40
|
-
_stream_writable: require.resolve('readable-stream/lib/_stream_writable'),
|
|
41
|
-
string_decoder: require.resolve('string_decoder/'),
|
|
36
|
+
_stream_duplex: $require.resolve('readable-stream/lib/_stream_duplex'),
|
|
37
|
+
_stream_passthrough: $require.resolve('readable-stream/lib/_stream_passthrough'),
|
|
38
|
+
_stream_readable: $require.resolve('readable-stream/lib/_stream_readable'),
|
|
39
|
+
_stream_transform: $require.resolve('readable-stream/lib/_stream_transform'),
|
|
40
|
+
_stream_writable: $require.resolve('readable-stream/lib/_stream_writable'),
|
|
41
|
+
string_decoder: $require.resolve('string_decoder/'),
|
|
42
42
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
43
|
-
sys: require.resolve('util/'),
|
|
44
|
-
timers: require.resolve('timers-browserify'),
|
|
45
|
-
tty: require.resolve('tty-browserify'),
|
|
46
|
-
url: require.resolve('url/'),
|
|
47
|
-
util: require.resolve('util/'),
|
|
48
|
-
vm: require.resolve('vm-browserify'),
|
|
49
|
-
zlib: require.resolve('browserify-zlib'),
|
|
43
|
+
sys: $require.resolve('util/'),
|
|
44
|
+
timers: $require.resolve('timers-browserify'),
|
|
45
|
+
tty: $require.resolve('tty-browserify'),
|
|
46
|
+
url: $require.resolve('url/'),
|
|
47
|
+
util: $require.resolve('util/'),
|
|
48
|
+
vm: $require.resolve('vm-browserify'),
|
|
49
|
+
zlib: $require.resolve('browserify-zlib'),
|
|
50
50
|
};
|
|
51
51
|
/**
|
|
52
52
|
* Get the default loader for JavaScript and TypeScript files, based on the
|
|
@@ -81,7 +81,7 @@ export async function getDefaultLoader({ legacy, sourceMap, }) {
|
|
|
81
81
|
* This is a Webpack loader that uses the `SWC` compiler, which is a much
|
|
82
82
|
* faster alternative to Babel and TypeScript's own compiler.
|
|
83
83
|
*/
|
|
84
|
-
loader: require.resolve('swc-loader'),
|
|
84
|
+
loader: $require.resolve('swc-loader'),
|
|
85
85
|
/**
|
|
86
86
|
* The options for the `swc-loader`. These can be overridden in the
|
|
87
87
|
* `.swcrc` file.
|
|
@@ -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;;AAInC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,4BAAkB;AAE1D,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CACtC,OAAO;AACL,mDAAmD;AACnD,OAAO,CAAC,OAAO,CAAC,kCAAkC,CAAC,CACpD,EACD,iBAA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AC;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 { ProcessedWebpackConfig } from '../config';\nimport { browserify, getFunctionLoader } from './loaders';\n\nexport const BROWSERSLIST_FILE = resolve(\n dirname(\n // eslint-disable-next-line n/no-extraneous-require\n require.resolve('@metamask/snaps-cli/package.json'),\n ),\n '.browserslistrc',\n);\n\nexport const WEBPACK_FALLBACKS = {\n assert: require.resolve('assert/'),\n buffer: require.resolve('buffer/'),\n console: require.resolve('console-browserify'),\n constants: require.resolve('constants-browserify'),\n crypto: require.resolve('crypto-browserify'),\n domain: require.resolve('domain-browser'),\n events: require.resolve('events/'),\n http: require.resolve('stream-http'),\n https: require.resolve('https-browserify'),\n os: require.resolve('os-browserify/browser'),\n path: require.resolve('path-browserify'),\n punycode: require.resolve('punycode/'),\n process: require.resolve('process/browser'),\n querystring: require.resolve('querystring-es3'),\n stream: require.resolve('stream-browserify'),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),\n _stream_passthrough: require.resolve(\n 'readable-stream/lib/_stream_passthrough',\n ),\n _stream_readable: require.resolve('readable-stream/lib/_stream_readable'),\n _stream_transform: require.resolve('readable-stream/lib/_stream_transform'),\n _stream_writable: require.resolve('readable-stream/lib/_stream_writable'),\n string_decoder: require.resolve('string_decoder/'),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: require.resolve('util/'),\n timers: require.resolve('timers-browserify'),\n tty: require.resolve('tty-browserify'),\n url: require.resolve('url/'),\n util: require.resolve('util/'),\n vm: require.resolve('vm-browserify'),\n zlib: require.resolve('browserify-zlib'),\n};\n\n/**\n * Get the default loader for JavaScript and TypeScript files, based on the\n * config object.\n *\n * - If the `legacy` option is set, we use the custom `browserify` loader. This\n * uses the legacy Browserify config to transpile the code.\n * - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the\n * `SWC` compiler, which is a much faster alternative to Babel and TypeScript's\n * own compiler.\n *\n * @param config - The processed snap Webpack config.\n * @param config.legacy - The legacy config object, if any.\n * @param config.sourceMap - Whether to generate source maps.\n * @see https://swc.rs/docs/usage/swc-loader\n * @returns The default loader.\n */\nexport async function getDefaultLoader({\n legacy,\n sourceMap,\n}: ProcessedWebpackConfig) {\n if (legacy) {\n /**\n * If the snap uses the legacy config, we use the custom `browserify`\n * loader. This uses the legacy Browserify config to transpile the code.\n * This is necessary for backwards compatibility with the\n * `bundlerCustomizer` function.\n */\n return getFunctionLoader(browserify, legacy);\n }\n\n const targets = await getBrowserslistTargets();\n return {\n /**\n * We use the `swc-loader` to transpile TypeScript and JavaScript files.\n * This is a Webpack loader that uses the `SWC` compiler, which is a much\n * faster alternative to Babel and TypeScript's own compiler.\n */\n loader: require.resolve('swc-loader'),\n\n /**\n * The options for the `swc-loader`. These can be overridden in the\n * `.swcrc` file.\n *\n * @see https://swc.rs/docs/configuration/swcrc\n */\n options: {\n sync: false,\n\n /**\n * This tells SWC to generate source maps. We set it to the\n * `sourceMap` value from the config object.\n *\n * This must be enabled if source maps are enabled in the config.\n */\n sourceMaps: Boolean(getDevTool(sourceMap)),\n\n jsc: {\n parser: {\n /**\n * This tells the parser to parse TypeScript files. If you\n * don't need to support TypeScript, you can set this to\n * `ecmascript` instead, but there's no harm in leaving it\n * as `typescript`.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n */\n syntax: 'typescript',\n\n /**\n * 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: ProcessedWebpackConfig['sourceMap'],\n): Configuration['devtool'] {\n if (sourceMap === 'inline') {\n return 'inline-source-map';\n }\n\n if (sourceMap === true) {\n return 'source-map';\n }\n\n return false;\n}\n\n/**\n * Get a function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n *\n * @param spinner - The spinner to update.\n * @param spinnerText - The initial spinner text. This will be prepended to the\n * percentage.\n * @returns A function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n */\n// Note: This is extracted for testing purposes.\nexport function getProgressHandler(spinner?: Ora, spinnerText?: string) {\n return (percentage: number) => {\n if (spinner && spinnerText) {\n spinner.text = `${spinnerText} ${dim(\n `(${Math.round(percentage * 100)}%)`,\n )}`;\n }\n };\n}\n\n/**\n * Get the targets from the `.browserslistrc` file.\n *\n * @returns The browser targets as an array of strings.\n */\nexport async function getBrowserslistTargets() {\n const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');\n return contents\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line && !line.startsWith('#'));\n}\n\n/**\n * Get a singular or plural string based on the given count. This is useful for\n * generating messages like \"1 error\" or \"2 errors\". By default, the plural\n * string is the singular string with an \"s\" appended to it.\n *\n * This assumes that the text is in English, and likely won't work for some\n * other languages.\n *\n * @param count - The count.\n * @param singular - The singular string.\n * @param plural - The plural string.\n * @returns The singular or plural string.\n * @example\n * ```typescript\n * pluralize(1, 'error'); // => 'error'\n * pluralize(2, 'error'); // => 'errors'\n * pluralize(1, 'error', 'problem'); // => 'error'\n * pluralize(2, 'error', 'problems'); // => 'problems'\n * ```\n */\nexport function pluralize(\n count: number,\n singular: string,\n plural = `${singular}s`,\n) {\n return count === 1 ? singular : plural;\n}\n\n/**\n * Get an object that can be used as fallback config for Webpack's\n * `fallback` config.\n *\n * @param polyfills - The polyfill object from the snap config.\n * @returns The webpack fallback config.\n */\nexport function getFallbacks(polyfills: ProcessedWebpackConfig['polyfills']): {\n [index: string]: string | false;\n} {\n if (polyfills === true) {\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS] ?? false,\n ]),\n );\n }\n\n if (polyfills === false) {\n return Object.fromEntries(builtinModules.map((name) => [name, false]));\n }\n\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n polyfills[name as keyof ProcessedWebpackConfig['polyfills']]\n ? WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS]\n : false,\n ]),\n );\n}\n\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;;AAInC,O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C;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 { ProcessedWebpackConfig } from '../config';\nimport { browserify, getFunctionLoader } from './loaders';\n\nexport const BROWSERSLIST_FILE = resolve(\n dirname(\n // eslint-disable-next-line n/no-extraneous-require\n require.resolve('@metamask/snaps-cli/package.json'),\n ),\n '.browserslistrc',\n);\n\nexport const WEBPACK_FALLBACKS = {\n assert: require.resolve('assert/'),\n buffer: require.resolve('buffer/'),\n console: require.resolve('console-browserify'),\n constants: require.resolve('constants-browserify'),\n crypto: require.resolve('crypto-browserify'),\n domain: require.resolve('domain-browser'),\n events: require.resolve('events/'),\n http: require.resolve('stream-http'),\n https: require.resolve('https-browserify'),\n os: require.resolve('os-browserify/browser'),\n path: require.resolve('path-browserify'),\n punycode: require.resolve('punycode/'),\n process: require.resolve('process/browser'),\n querystring: require.resolve('querystring-es3'),\n stream: require.resolve('stream-browserify'),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: require.resolve('readable-stream/lib/_stream_duplex'),\n _stream_passthrough: require.resolve(\n 'readable-stream/lib/_stream_passthrough',\n ),\n _stream_readable: require.resolve('readable-stream/lib/_stream_readable'),\n _stream_transform: require.resolve('readable-stream/lib/_stream_transform'),\n _stream_writable: require.resolve('readable-stream/lib/_stream_writable'),\n string_decoder: require.resolve('string_decoder/'),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: require.resolve('util/'),\n timers: require.resolve('timers-browserify'),\n tty: require.resolve('tty-browserify'),\n url: require.resolve('url/'),\n util: require.resolve('util/'),\n vm: require.resolve('vm-browserify'),\n zlib: require.resolve('browserify-zlib'),\n};\n\n/**\n * Get the default loader for JavaScript and TypeScript files, based on the\n * config object.\n *\n * - If the `legacy` option is set, we use the custom `browserify` loader. This\n * uses the legacy Browserify config to transpile the code.\n * - Otherwise, we use the `swc-loader`. This is a Webpack loader that uses the\n * `SWC` compiler, which is a much faster alternative to Babel and TypeScript's\n * own compiler.\n *\n * @param config - The processed snap Webpack config.\n * @param config.legacy - The legacy config object, if any.\n * @param config.sourceMap - Whether to generate source maps.\n * @see https://swc.rs/docs/usage/swc-loader\n * @returns The default loader.\n */\nexport async function getDefaultLoader({\n legacy,\n sourceMap,\n}: ProcessedWebpackConfig) {\n if (legacy) {\n /**\n * If the snap uses the legacy config, we use the custom `browserify`\n * loader. This uses the legacy Browserify config to transpile the code.\n * This is necessary for backwards compatibility with the\n * `bundlerCustomizer` function.\n */\n return getFunctionLoader(browserify, legacy);\n }\n\n const targets = await getBrowserslistTargets();\n return {\n /**\n * We use the `swc-loader` to transpile TypeScript and JavaScript files.\n * This is a Webpack loader that uses the `SWC` compiler, which is a much\n * faster alternative to Babel and TypeScript's own compiler.\n */\n loader: require.resolve('swc-loader'),\n\n /**\n * The options for the `swc-loader`. These can be overridden in the\n * `.swcrc` file.\n *\n * @see https://swc.rs/docs/configuration/swcrc\n */\n options: {\n sync: false,\n\n /**\n * This tells SWC to generate source maps. We set it to the\n * `sourceMap` value from the config object.\n *\n * This must be enabled if source maps are enabled in the config.\n */\n sourceMaps: Boolean(getDevTool(sourceMap)),\n\n jsc: {\n parser: {\n /**\n * This tells the parser to parse TypeScript files. If you\n * don't need to support TypeScript, you can set this to\n * `ecmascript` instead, but there's no harm in leaving it\n * as `typescript`.\n *\n * @see https://swc.rs/docs/configuration/compilation#jscparser\n */\n syntax: 'typescript',\n\n /**\n * 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: ProcessedWebpackConfig['sourceMap'],\n): Configuration['devtool'] {\n if (sourceMap === 'inline') {\n return 'inline-source-map';\n }\n\n if (sourceMap === true) {\n return 'source-map';\n }\n\n return false;\n}\n\n/**\n * Get a function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n *\n * @param spinner - The spinner to update.\n * @param spinnerText - The initial spinner text. This will be prepended to the\n * percentage.\n * @returns A function that can be used as handler function for Webpack's\n * `ProgressPlugin`.\n */\n// Note: This is extracted for testing purposes.\nexport function getProgressHandler(spinner?: Ora, spinnerText?: string) {\n return (percentage: number) => {\n if (spinner && spinnerText) {\n spinner.text = `${spinnerText} ${dim(\n `(${Math.round(percentage * 100)}%)`,\n )}`;\n }\n };\n}\n\n/**\n * Get the targets from the `.browserslistrc` file.\n *\n * @returns The browser targets as an array of strings.\n */\nexport async function getBrowserslistTargets() {\n const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');\n return contents\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line && !line.startsWith('#'));\n}\n\n/**\n * Get a singular or plural string based on the given count. This is useful for\n * generating messages like \"1 error\" or \"2 errors\". By default, the plural\n * string is the singular string with an \"s\" appended to it.\n *\n * This assumes that the text is in English, and likely won't work for some\n * other languages.\n *\n * @param count - The count.\n * @param singular - The singular string.\n * @param plural - The plural string.\n * @returns The singular or plural string.\n * @example\n * ```typescript\n * pluralize(1, 'error'); // => 'error'\n * pluralize(2, 'error'); // => 'errors'\n * pluralize(1, 'error', 'problem'); // => 'error'\n * pluralize(2, 'error', 'problems'); // => 'problems'\n * ```\n */\nexport function pluralize(\n count: number,\n singular: string,\n plural = `${singular}s`,\n) {\n return count === 1 ? singular : plural;\n}\n\n/**\n * Get an object that can be used as fallback config for Webpack's\n * `fallback` config.\n *\n * @param polyfills - The polyfill object from the snap config.\n * @returns The webpack fallback config.\n */\nexport function getFallbacks(polyfills: ProcessedWebpackConfig['polyfills']): {\n [index: string]: string | false;\n} {\n if (polyfills === true) {\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS] ?? false,\n ]),\n );\n }\n\n if (polyfills === false) {\n return Object.fromEntries(builtinModules.map((name) => [name, false]));\n }\n\n return Object.fromEntries(\n builtinModules.map((name) => [\n name,\n polyfills[name as keyof ProcessedWebpackConfig['polyfills']]\n ? WEBPACK_FALLBACKS[name as keyof typeof WEBPACK_FALLBACKS]\n : false,\n ]),\n );\n}\n\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-cli",
|
|
3
|
-
"version": "6.3.
|
|
3
|
+
"version": "6.3.3",
|
|
4
4
|
"description": "A CLI for developing MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"@babel/plugin-transform-runtime": "^7.13.2",
|
|
60
60
|
"@babel/preset-env": "^7.23.2",
|
|
61
61
|
"@babel/preset-typescript": "^7.23.2",
|
|
62
|
-
"@metamask/snaps-sdk": "^6.
|
|
63
|
-
"@metamask/snaps-utils": "^8.1.
|
|
64
|
-
"@metamask/snaps-webpack-plugin": "^4.1.
|
|
62
|
+
"@metamask/snaps-sdk": "^6.5.0",
|
|
63
|
+
"@metamask/snaps-utils": "^8.1.1",
|
|
64
|
+
"@metamask/snaps-webpack-plugin": "^4.1.2",
|
|
65
65
|
"@metamask/superstruct": "^3.1.0",
|
|
66
66
|
"@metamask/utils": "^9.2.1",
|
|
67
67
|
"@swc/core": "1.3.78",
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|
|
110
110
|
"@metamask/eslint-config-typescript": "^12.1.0",
|
|
111
111
|
"@swc/jest": "^0.2.26",
|
|
112
|
-
"@ts-bridge/cli": "^0.
|
|
112
|
+
"@ts-bridge/cli": "^0.5.1",
|
|
113
113
|
"@types/browserify": "^12.0.37",
|
|
114
114
|
"@types/jest": "^27.5.1",
|
|
115
115
|
"@types/node": "18.14.2",
|