@metamask/snaps-cli 6.7.0 → 7.0.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 +32 -1
- package/README.md +11 -244
- package/dist/builders.cjs +0 -97
- package/dist/builders.cjs.map +1 -1
- package/dist/builders.d.cts +0 -94
- package/dist/builders.d.cts.map +1 -1
- package/dist/builders.d.mts +0 -94
- package/dist/builders.d.mts.map +1 -1
- package/dist/builders.mjs +0 -96
- package/dist/builders.mjs.map +1 -1
- package/dist/cli.cjs +4 -9
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts.map +1 -1
- package/dist/cli.d.mts.map +1 -1
- package/dist/cli.mjs +4 -16
- package/dist/cli.mjs.map +1 -1
- package/dist/commands/build/build.cjs +7 -7
- package/dist/commands/build/build.cjs.map +1 -1
- package/dist/commands/build/build.d.cts.map +1 -1
- package/dist/commands/build/build.d.mts.map +1 -1
- package/dist/commands/build/build.mjs +2 -2
- package/dist/commands/build/build.mjs.map +1 -1
- package/dist/commands/build/implementation.cjs.map +1 -1
- package/dist/commands/build/implementation.d.cts +2 -2
- package/dist/commands/build/implementation.d.cts.map +1 -1
- package/dist/commands/build/implementation.d.mts +2 -2
- package/dist/commands/build/implementation.d.mts.map +1 -1
- package/dist/commands/build/implementation.mjs.map +1 -1
- package/dist/commands/build/index.cjs +2 -14
- 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 +2 -14
- package/dist/commands/build/index.mjs.map +1 -1
- package/dist/commands/eval/__test__/webpack/bad/snap.config.cjs +0 -1
- package/dist/commands/eval/__test__/webpack/bad/snap.config.cjs.map +1 -1
- package/dist/commands/eval/__test__/webpack/bad/snap.config.d.cts.map +1 -1
- package/dist/commands/eval/__test__/webpack/bad/snap.config.d.mts.map +1 -1
- package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs +0 -1
- package/dist/commands/eval/__test__/webpack/bad/snap.config.mjs.map +1 -1
- package/dist/commands/eval/__test__/webpack/good/snap.config.cjs +0 -1
- package/dist/commands/eval/__test__/webpack/good/snap.config.cjs.map +1 -1
- package/dist/commands/eval/__test__/webpack/good/snap.config.d.cts.map +1 -1
- package/dist/commands/eval/__test__/webpack/good/snap.config.d.mts.map +1 -1
- package/dist/commands/eval/__test__/webpack/good/snap.config.mjs +0 -1
- package/dist/commands/eval/__test__/webpack/good/snap.config.mjs.map +1 -1
- package/dist/commands/eval/__test__/webpack/snap.config.cjs +0 -1
- package/dist/commands/eval/__test__/webpack/snap.config.cjs.map +1 -1
- package/dist/commands/eval/__test__/webpack/snap.config.d.cts.map +1 -1
- package/dist/commands/eval/__test__/webpack/snap.config.d.mts.map +1 -1
- package/dist/commands/eval/__test__/webpack/snap.config.mjs +0 -1
- package/dist/commands/eval/__test__/webpack/snap.config.mjs.map +1 -1
- package/dist/commands/eval/eval.cjs +1 -1
- package/dist/commands/eval/eval.cjs.map +1 -1
- package/dist/commands/eval/eval.d.cts.map +1 -1
- package/dist/commands/eval/eval.d.mts.map +1 -1
- package/dist/commands/eval/eval.mjs +1 -1
- package/dist/commands/eval/eval.mjs.map +1 -1
- package/dist/commands/eval/index.cjs +1 -4
- package/dist/commands/eval/index.cjs.map +1 -1
- package/dist/commands/eval/index.d.cts.map +1 -1
- package/dist/commands/eval/index.d.mts.map +1 -1
- package/dist/commands/eval/index.mjs +1 -4
- package/dist/commands/eval/index.mjs.map +1 -1
- package/dist/commands/manifest/index.cjs +1 -4
- package/dist/commands/manifest/index.cjs.map +1 -1
- package/dist/commands/manifest/index.d.cts.map +1 -1
- package/dist/commands/manifest/index.d.mts.map +1 -1
- package/dist/commands/manifest/index.mjs +1 -4
- package/dist/commands/manifest/index.mjs.map +1 -1
- package/dist/commands/manifest/manifest.cjs +5 -6
- package/dist/commands/manifest/manifest.cjs.map +1 -1
- package/dist/commands/manifest/manifest.d.cts.map +1 -1
- package/dist/commands/manifest/manifest.d.mts.map +1 -1
- package/dist/commands/manifest/manifest.mjs +5 -6
- package/dist/commands/manifest/manifest.mjs.map +1 -1
- package/dist/commands/serve/index.cjs +2 -2
- package/dist/commands/serve/index.cjs.map +1 -1
- package/dist/commands/serve/index.d.cts.map +1 -1
- package/dist/commands/serve/index.d.mts.map +1 -1
- package/dist/commands/serve/index.mjs +2 -2
- package/dist/commands/serve/index.mjs.map +1 -1
- package/dist/commands/watch/implementation.cjs +2 -0
- package/dist/commands/watch/implementation.cjs.map +1 -1
- package/dist/commands/watch/implementation.d.cts +2 -2
- package/dist/commands/watch/implementation.d.cts.map +1 -1
- package/dist/commands/watch/implementation.d.mts +2 -2
- package/dist/commands/watch/implementation.d.mts.map +1 -1
- package/dist/commands/watch/implementation.mjs +2 -0
- package/dist/commands/watch/implementation.mjs.map +1 -1
- package/dist/commands/watch/index.cjs +2 -17
- 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 +2 -17
- package/dist/commands/watch/index.mjs.map +1 -1
- package/dist/commands/watch/watch.cjs +1 -1
- package/dist/commands/watch/watch.cjs.map +1 -1
- package/dist/commands/watch/watch.d.cts.map +1 -1
- package/dist/commands/watch/watch.d.mts.map +1 -1
- package/dist/commands/watch/watch.mjs +1 -1
- package/dist/commands/watch/watch.mjs.map +1 -1
- package/dist/config.cjs +11 -155
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.cts +216 -314
- package/dist/config.d.cts.map +1 -1
- package/dist/config.d.mts +216 -314
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs +13 -155
- package/dist/config.mjs.map +1 -1
- package/dist/main.cjs +0 -1
- package/dist/main.cjs.map +1 -1
- package/dist/main.mjs +0 -1
- package/dist/main.mjs.map +1 -1
- package/dist/utils/index.cjs +0 -1
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +0 -1
- package/dist/utils/index.d.cts.map +1 -1
- package/dist/utils/index.d.mts +0 -1
- package/dist/utils/index.d.mts.map +1 -1
- package/dist/utils/index.mjs +0 -1
- package/dist/utils/index.mjs.map +1 -1
- package/dist/utils/steps.cjs.map +1 -1
- package/dist/utils/steps.d.cts +1 -1
- package/dist/utils/steps.d.cts.map +1 -1
- package/dist/utils/steps.d.mts +1 -1
- package/dist/utils/steps.d.mts.map +1 -1
- package/dist/utils/steps.mjs.map +1 -1
- package/dist/webpack/compiler.cjs.map +1 -1
- package/dist/webpack/compiler.d.cts +2 -2
- package/dist/webpack/compiler.d.cts.map +1 -1
- package/dist/webpack/compiler.d.mts +2 -2
- package/dist/webpack/compiler.d.mts.map +1 -1
- package/dist/webpack/compiler.mjs.map +1 -1
- package/dist/webpack/config.cjs +1 -2
- package/dist/webpack/config.cjs.map +1 -1
- package/dist/webpack/config.d.cts +2 -2
- package/dist/webpack/config.d.cts.map +1 -1
- package/dist/webpack/config.d.mts +2 -2
- package/dist/webpack/config.d.mts.map +1 -1
- package/dist/webpack/config.mjs +1 -2
- package/dist/webpack/config.mjs.map +1 -1
- package/dist/webpack/loaders/function.cjs +7 -10
- package/dist/webpack/loaders/function.cjs.map +1 -1
- package/dist/webpack/loaders/function.d.cts +1 -0
- package/dist/webpack/loaders/function.d.cts.map +1 -1
- package/dist/webpack/loaders/function.d.mts +1 -0
- package/dist/webpack/loaders/function.d.mts.map +1 -1
- package/dist/webpack/loaders/function.mjs +6 -9
- package/dist/webpack/loaders/function.mjs.map +1 -1
- package/dist/webpack/loaders/index.cjs +1 -3
- package/dist/webpack/loaders/index.cjs.map +1 -1
- package/dist/webpack/loaders/index.d.cts +0 -1
- package/dist/webpack/loaders/index.d.cts.map +1 -1
- package/dist/webpack/loaders/index.d.mts +0 -1
- package/dist/webpack/loaders/index.d.mts.map +1 -1
- package/dist/webpack/loaders/index.mjs +0 -1
- package/dist/webpack/loaders/index.mjs.map +1 -1
- package/dist/webpack/loaders/wasm.cjs +0 -2
- package/dist/webpack/loaders/wasm.cjs.map +1 -1
- package/dist/webpack/loaders/wasm.d.cts.map +1 -1
- package/dist/webpack/loaders/wasm.d.mts.map +1 -1
- package/dist/webpack/loaders/wasm.mjs +0 -2
- package/dist/webpack/loaders/wasm.mjs.map +1 -1
- package/dist/webpack/plugins.cjs +15 -20
- package/dist/webpack/plugins.cjs.map +1 -1
- package/dist/webpack/plugins.d.cts +13 -3
- package/dist/webpack/plugins.d.cts.map +1 -1
- package/dist/webpack/plugins.d.mts +13 -3
- package/dist/webpack/plugins.d.mts.map +1 -1
- package/dist/webpack/plugins.mjs +4 -9
- package/dist/webpack/plugins.mjs.map +1 -1
- package/dist/webpack/utils.cjs +5 -21
- package/dist/webpack/utils.cjs.map +1 -1
- package/dist/webpack/utils.d.cts +6 -36
- package/dist/webpack/utils.d.cts.map +1 -1
- package/dist/webpack/utils.d.mts +6 -36
- package/dist/webpack/utils.d.mts.map +1 -1
- package/dist/webpack/utils.mjs +4 -18
- package/dist/webpack/utils.mjs.map +1 -1
- package/package.json +13 -38
- package/dist/commands/eval/__test__/browserify/bad/snap.config.cjs +0 -10
- package/dist/commands/eval/__test__/browserify/bad/snap.config.cjs.map +0 -1
- package/dist/commands/eval/__test__/browserify/bad/snap.config.d.cts +0 -4
- package/dist/commands/eval/__test__/browserify/bad/snap.config.d.cts.map +0 -1
- package/dist/commands/eval/__test__/browserify/bad/snap.config.d.mts +0 -4
- package/dist/commands/eval/__test__/browserify/bad/snap.config.d.mts.map +0 -1
- package/dist/commands/eval/__test__/browserify/bad/snap.config.mjs +0 -8
- package/dist/commands/eval/__test__/browserify/bad/snap.config.mjs.map +0 -1
- package/dist/commands/eval/__test__/browserify/good/snap.config.cjs +0 -10
- package/dist/commands/eval/__test__/browserify/good/snap.config.cjs.map +0 -1
- package/dist/commands/eval/__test__/browserify/good/snap.config.d.cts +0 -4
- package/dist/commands/eval/__test__/browserify/good/snap.config.d.cts.map +0 -1
- package/dist/commands/eval/__test__/browserify/good/snap.config.d.mts +0 -4
- package/dist/commands/eval/__test__/browserify/good/snap.config.d.mts.map +0 -1
- package/dist/commands/eval/__test__/browserify/good/snap.config.mjs +0 -8
- package/dist/commands/eval/__test__/browserify/good/snap.config.mjs.map +0 -1
- package/dist/utils/legacy.cjs +0 -53
- package/dist/utils/legacy.cjs.map +0 -1
- package/dist/utils/legacy.d.cts +0 -28
- package/dist/utils/legacy.d.cts.map +0 -1
- package/dist/utils/legacy.d.mts +0 -28
- package/dist/utils/legacy.d.mts.map +0 -1
- package/dist/utils/legacy.mjs +0 -47
- package/dist/utils/legacy.mjs.map +0 -1
- package/dist/webpack/loaders/browserify.cjs +0 -84
- package/dist/webpack/loaders/browserify.cjs.map +0 -1
- package/dist/webpack/loaders/browserify.d.cts +0 -18
- package/dist/webpack/loaders/browserify.d.cts.map +0 -1
- package/dist/webpack/loaders/browserify.d.mts +0 -18
- package/dist/webpack/loaders/browserify.d.mts.map +0 -1
- package/dist/webpack/loaders/browserify.mjs +0 -88
- package/dist/webpack/loaders/browserify.mjs.map +0 -1
package/dist/config.mjs
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { literal, union } from "@metamask/snaps-sdk";
|
|
2
|
-
import { createFromStruct, indent, isFile, SnapsStructError
|
|
3
|
-
import { array, boolean,
|
|
2
|
+
import { createFromStruct, indent, isFile, SnapsStructError } from "@metamask/snaps-utils/node";
|
|
3
|
+
import { array, boolean, defaulted, define, func, number, object, optional, record, string, unknown } from "@metamask/superstruct";
|
|
4
4
|
import { hasProperty } from "@metamask/utils";
|
|
5
5
|
import { transform } from "@swc/core";
|
|
6
6
|
import $chalk from "chalk";
|
|
7
7
|
const { dim } = $chalk;
|
|
8
8
|
import { readFile } from "fs/promises";
|
|
9
9
|
import Module from "module";
|
|
10
|
-
import {
|
|
11
|
-
import { TranspilationModes } from "./builders.mjs";
|
|
10
|
+
import { dirname, resolve } from "path";
|
|
12
11
|
import { ConfigError } from "./errors.mjs";
|
|
13
12
|
import { file } from "./structs.mjs";
|
|
14
13
|
import { CONFIG_FILE, TS_CONFIG_FILE } from "./utils/index.mjs";
|
|
@@ -16,35 +15,8 @@ const CONFIG_FILES = [CONFIG_FILE, TS_CONFIG_FILE];
|
|
|
16
15
|
// This struct is essentially the same as the `func` struct, but it's defined
|
|
17
16
|
// separately so that we include the function type in the inferred TypeScript
|
|
18
17
|
// type definitions.
|
|
19
|
-
const SnapsBrowserifyBundlerCustomizerFunctionStruct = define('function', func().validator);
|
|
20
|
-
export const SnapsBrowserifyConfigStruct = object({
|
|
21
|
-
bundler: literal('browserify'),
|
|
22
|
-
cliOptions: defaulted(object({
|
|
23
|
-
bundle: optional(file()),
|
|
24
|
-
dist: defaulted(file(), 'dist'),
|
|
25
|
-
eval: defaulted(boolean(), true),
|
|
26
|
-
manifest: defaulted(boolean(), true),
|
|
27
|
-
port: defaulted(number(), 8081),
|
|
28
|
-
outfileName: defaulted(string(), 'bundle.js'),
|
|
29
|
-
root: defaulted(file(), process.cwd()),
|
|
30
|
-
sourceMaps: defaulted(boolean(), false),
|
|
31
|
-
src: defaulted(file(), 'src/index.js'),
|
|
32
|
-
stripComments: defaulted(boolean(), true),
|
|
33
|
-
suppressWarnings: defaulted(boolean(), false),
|
|
34
|
-
transpilationMode: defaulted(union([literal('localAndDeps'), literal('localOnly'), literal('none')]), 'localOnly'),
|
|
35
|
-
depsToTranspile: defaulted(array(string()), []),
|
|
36
|
-
verboseErrors: defaulted(boolean(), true),
|
|
37
|
-
writeManifest: defaulted(boolean(), true),
|
|
38
|
-
serve: defaulted(boolean(), true),
|
|
39
|
-
}), {}),
|
|
40
|
-
bundlerCustomizer: optional(SnapsBrowserifyBundlerCustomizerFunctionStruct),
|
|
41
|
-
});
|
|
42
|
-
// This struct is essentially the same as the `func` struct, but it's defined
|
|
43
|
-
// separately so that we include the function type in the inferred TypeScript
|
|
44
|
-
// type definitions.
|
|
45
18
|
const SnapsWebpackCustomizeWebpackConfigFunctionStruct = define('function', func().validator);
|
|
46
|
-
export const
|
|
47
|
-
bundler: defaulted(literal('webpack'), 'webpack'),
|
|
19
|
+
export const SnapsConfigStruct = object({
|
|
48
20
|
input: defaulted(file(), resolve(process.cwd(), 'src/index.js')),
|
|
49
21
|
sourceMap: defaulted(union([boolean(), literal('inline')]), false),
|
|
50
22
|
evaluate: defaulted(boolean(), true),
|
|
@@ -119,43 +91,17 @@ export const SnapsWebpackConfigStruct = object({
|
|
|
119
91
|
wasm: defaulted(boolean(), false),
|
|
120
92
|
}), {}),
|
|
121
93
|
});
|
|
122
|
-
export const SnapsConfigStruct = type({
|
|
123
|
-
bundler: defaulted(union([literal('browserify'), literal('webpack')]), 'webpack'),
|
|
124
|
-
});
|
|
125
|
-
export const LegacyOptionsStruct = union([
|
|
126
|
-
named('object with `transpilationMode` set to `localAndDeps` and `depsToTranspile` set to an array of strings', type({
|
|
127
|
-
depsToTranspile: array(string()),
|
|
128
|
-
transpilationMode: literal(TranspilationModes.LocalAndDeps),
|
|
129
|
-
writeManifest: boolean(),
|
|
130
|
-
bundlerCustomizer: optional(SnapsBrowserifyBundlerCustomizerFunctionStruct),
|
|
131
|
-
})),
|
|
132
|
-
named('object without `depsToTranspile`', type({
|
|
133
|
-
depsToTranspile: named('empty array', empty(array())),
|
|
134
|
-
transpilationMode: union([
|
|
135
|
-
literal(TranspilationModes.LocalOnly),
|
|
136
|
-
literal(TranspilationModes.None),
|
|
137
|
-
]),
|
|
138
|
-
writeManifest: boolean(),
|
|
139
|
-
bundlerCustomizer: optional(SnapsBrowserifyBundlerCustomizerFunctionStruct),
|
|
140
|
-
})),
|
|
141
|
-
]);
|
|
142
94
|
/**
|
|
143
95
|
* Get a validated snap config. This validates the config and adds default
|
|
144
96
|
* values for any missing properties.
|
|
145
97
|
*
|
|
146
98
|
* @param config - The config to validate.
|
|
147
|
-
* @param argv - The CLI arguments.
|
|
148
99
|
* @returns The validated config.
|
|
149
100
|
*/
|
|
150
|
-
export function getConfig(config
|
|
101
|
+
export function getConfig(config) {
|
|
151
102
|
const prefix = 'The snap config file is invalid';
|
|
152
103
|
const suffix = dim('Refer to the documentation for more information: https://docs.metamask.io/snaps/reference/cli/options/');
|
|
153
|
-
|
|
154
|
-
if (bundler === 'browserify') {
|
|
155
|
-
const legacyConfig = createFromStruct(config, SnapsBrowserifyConfigStruct, prefix, suffix);
|
|
156
|
-
return getWebpackConfig(mergeLegacyOptions(argv, legacyConfig));
|
|
157
|
-
}
|
|
158
|
-
return createFromStruct(config, SnapsWebpackConfigStruct, prefix, suffix);
|
|
104
|
+
return createFromStruct(config, SnapsConfigStruct, prefix, suffix);
|
|
159
105
|
}
|
|
160
106
|
/**
|
|
161
107
|
* Load a snap config from a file. This supports both JavaScript and TypeScript
|
|
@@ -165,12 +111,11 @@ export function getConfig(config, argv) {
|
|
|
165
111
|
* `module.exports` or `export default`.
|
|
166
112
|
*
|
|
167
113
|
* @param path - The full path to the config file.
|
|
168
|
-
* @param argv - The CLI arguments.
|
|
169
114
|
* @returns The validated config.
|
|
170
115
|
* @throws If the config file is invalid, or if the config file does not have a
|
|
171
116
|
* default export.
|
|
172
117
|
*/
|
|
173
|
-
export async function loadConfig(path
|
|
118
|
+
export async function loadConfig(path) {
|
|
174
119
|
try {
|
|
175
120
|
const contents = await readFile(path, 'utf8');
|
|
176
121
|
const source = await transform(contents, {
|
|
@@ -190,9 +135,9 @@ export async function loadConfig(path, argv) {
|
|
|
190
135
|
// @ts-expect-error - This function is not typed.
|
|
191
136
|
config._compile(source.code, path);
|
|
192
137
|
if (!hasProperty(config.exports, 'default')) {
|
|
193
|
-
return getConfig(config.exports
|
|
138
|
+
return getConfig(config.exports);
|
|
194
139
|
}
|
|
195
|
-
return getConfig(config.exports.default
|
|
140
|
+
return getConfig(config.exports.default);
|
|
196
141
|
}
|
|
197
142
|
catch (error) {
|
|
198
143
|
if (error instanceof SnapsStructError) {
|
|
@@ -207,15 +152,14 @@ export async function loadConfig(path, argv) {
|
|
|
207
152
|
*
|
|
208
153
|
* @param path - The path to resolve the snap config from. Defaults to the
|
|
209
154
|
* current working directory.
|
|
210
|
-
* @param argv - The CLI arguments.
|
|
211
155
|
* @returns The resolved and validated snap config.
|
|
212
156
|
* @throws If a snap config could not be found.
|
|
213
157
|
*/
|
|
214
|
-
export async function resolveConfig(path
|
|
158
|
+
export async function resolveConfig(path) {
|
|
215
159
|
for (const configFile of CONFIG_FILES) {
|
|
216
160
|
const filePath = resolve(path, configFile);
|
|
217
161
|
if (await isFile(filePath)) {
|
|
218
|
-
return await loadConfig(filePath
|
|
162
|
+
return await loadConfig(filePath);
|
|
219
163
|
}
|
|
220
164
|
}
|
|
221
165
|
throw new ConfigError(`Could not find a "snap.config.js" or "snap.config.ts" file in the current or specified directory ("${path}").`);
|
|
@@ -234,94 +178,8 @@ export async function getConfigByArgv(argv, cwd = process.cwd()) {
|
|
|
234
178
|
if (!(await isFile(argv.config))) {
|
|
235
179
|
throw new ConfigError(`Could not find a config file at "${argv.config}". Make sure that the path is correct.`);
|
|
236
180
|
}
|
|
237
|
-
return await loadConfig(argv.config
|
|
181
|
+
return await loadConfig(argv.config);
|
|
238
182
|
}
|
|
239
|
-
return await resolveConfig(cwd
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Merge legacy CLI options into the config. This is used to support the legacy
|
|
243
|
-
* config format, where options can be specified both in the config file and
|
|
244
|
-
* through CLI flags.
|
|
245
|
-
*
|
|
246
|
-
* @param argv - The CLI arguments.
|
|
247
|
-
* @param config - The config to merge the CLI options into.
|
|
248
|
-
* @returns The config with the CLI options merged in.
|
|
249
|
-
* @deprecated This function is only used to support the legacy config format.
|
|
250
|
-
*/
|
|
251
|
-
export function mergeLegacyOptions(argv, config) {
|
|
252
|
-
const cliOptions = Object.keys(config.cliOptions).reduce((accumulator, key) => {
|
|
253
|
-
if (argv[key] !== undefined) {
|
|
254
|
-
return {
|
|
255
|
-
...accumulator,
|
|
256
|
-
[key]: argv[key],
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
return accumulator;
|
|
260
|
-
}, config.cliOptions);
|
|
261
|
-
return {
|
|
262
|
-
...config,
|
|
263
|
-
cliOptions,
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Get a Webpack config from a legacy browserify config. This is used to
|
|
268
|
-
* support the legacy config format, and convert it to the new format.
|
|
269
|
-
*
|
|
270
|
-
* @param legacyConfig - The legacy browserify config.
|
|
271
|
-
* @returns The Webpack config.
|
|
272
|
-
*/
|
|
273
|
-
export function getWebpackConfig(legacyConfig) {
|
|
274
|
-
const defaultConfig = create({ bundler: 'webpack' }, SnapsWebpackConfigStruct);
|
|
275
|
-
// The legacy config has two options for specifying the output path and
|
|
276
|
-
// filename: `bundle`, and `dist` + `outfileName`. If `bundle` is specified,
|
|
277
|
-
// we use that as the output path and filename. Otherwise, we use `dist` and
|
|
278
|
-
// `outfileName`.
|
|
279
|
-
const path = legacyConfig.cliOptions.bundle
|
|
280
|
-
? dirname(legacyConfig.cliOptions.bundle)
|
|
281
|
-
: legacyConfig.cliOptions.dist;
|
|
282
|
-
const filename = legacyConfig.cliOptions.bundle
|
|
283
|
-
? basename(legacyConfig.cliOptions.bundle)
|
|
284
|
-
: legacyConfig.cliOptions.outfileName;
|
|
285
|
-
return {
|
|
286
|
-
...defaultConfig,
|
|
287
|
-
input: legacyConfig.cliOptions.src,
|
|
288
|
-
evaluate: legacyConfig.cliOptions.eval,
|
|
289
|
-
sourceMap: legacyConfig.cliOptions.sourceMaps,
|
|
290
|
-
output: {
|
|
291
|
-
path,
|
|
292
|
-
filename,
|
|
293
|
-
// The legacy config has an option to remove comments from the bundle, but
|
|
294
|
-
// the terser plugin does this by default, so we only enable the terser if
|
|
295
|
-
// the legacy config has `stripComments` set to `true`. This is not a
|
|
296
|
-
// perfect solution, but it's the best we can do without breaking the
|
|
297
|
-
// legacy config.
|
|
298
|
-
minimize: legacyConfig.cliOptions.stripComments,
|
|
299
|
-
// The legacy config does not have a `clean` option, so we default to
|
|
300
|
-
// `false` here.
|
|
301
|
-
clean: false,
|
|
302
|
-
},
|
|
303
|
-
manifest: {
|
|
304
|
-
// The legacy config does not have a `manifest` option, so we default to
|
|
305
|
-
// `process.cwd()/snap.manifest.json`.
|
|
306
|
-
path: resolve(process.cwd(), 'snap.manifest.json'),
|
|
307
|
-
update: legacyConfig.cliOptions.writeManifest,
|
|
308
|
-
},
|
|
309
|
-
server: {
|
|
310
|
-
enabled: legacyConfig.cliOptions.serve,
|
|
311
|
-
port: legacyConfig.cliOptions.port,
|
|
312
|
-
root: legacyConfig.cliOptions.root,
|
|
313
|
-
},
|
|
314
|
-
stats: {
|
|
315
|
-
verbose: false,
|
|
316
|
-
// These plugins are designed to be used with the modern config format, so
|
|
317
|
-
// we disable them for the legacy config format.
|
|
318
|
-
builtIns: false,
|
|
319
|
-
buffer: false,
|
|
320
|
-
},
|
|
321
|
-
legacy: createFromStruct({
|
|
322
|
-
...legacyConfig.cliOptions,
|
|
323
|
-
bundlerCustomizer: legacyConfig.bundlerCustomizer,
|
|
324
|
-
}, LegacyOptionsStruct, 'Invalid Browserify CLI options'),
|
|
325
|
-
};
|
|
183
|
+
return await resolveConfig(cwd);
|
|
326
184
|
}
|
|
327
185
|
//# sourceMappingURL=config.mjs.map
|
package/dist/config.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.mjs","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,4BAA4B;AACrD,OAAO,EACL,gBAAgB,EAChB,MAAM,EACN,MAAM,EACN,gBAAgB,EAChB,KAAK,EACN,mCAAmC;AACpC,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,SAAS,EACT,MAAM,EACN,IAAI,EACJ,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,IAAI,EACJ,OAAO,EACP,KAAK,EACN,8BAA8B;AAE/B,OAA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;YAChB,KAAK,EAAE,KAAK;SACb;QACD,QAAQ,EAAE;YACR,wEAAwE;YACxE,sCAAsC;YACtC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,oBAAoB,CAAC;YAClD,MAAM,EAAE,YAAY,CAAC,UAAU,CAAC,aAAa;SAC9C;QACD,MAAM,EAAE;YACN,OAAO,EAAE,YAAY,CAAC,UAAU,CAAC,KAAK;YACtC,IAAI,EAAE,YAAY,CAAC,UAAU,CAAC,IAAI;YAClC,IAAI,EAAE,YAAY,CAAC,UAAU,CAAC,IAAI;SACnC;QACD,KAAK,EAAE;YACL,OAAO,EAAE,KAAK;YAEd,0EAA0E;YAC1E,gDAAgD;YAChD,QAAQ,EAAE,KAAK;YACf,MAAM,EAAE,KAAK;SACd;QACD,MAAM,EAAE,gBAAgB,CACtB;YACE,GAAG,YAAY,CAAC,UAAU;YAC1B,iBAAiB,EAAE,YAAY,CAAC,iBAAiB;SAClD,EACD,mBAAmB,EACnB,gCAAgC,CACjC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { literal, union } from '@metamask/snaps-sdk';\nimport {\n createFromStruct,\n indent,\n isFile,\n SnapsStructError,\n named,\n} from '@metamask/snaps-utils/node';\nimport {\n array,\n boolean,\n create,\n defaulted,\n define,\n func,\n number,\n object,\n optional,\n record,\n string,\n type,\n unknown,\n empty,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { hasProperty } from '@metamask/utils';\nimport { transform } from '@swc/core';\nimport type { BrowserifyObject } from 'browserify';\nimport { dim } from 'chalk';\nimport { readFile } from 'fs/promises';\nimport Module from 'module';\nimport { basename, dirname, resolve } from 'path';\nimport type { Configuration as WebpackConfiguration } from 'webpack';\n\nimport { TranspilationModes } from './builders';\nimport { ConfigError } from './errors';\nimport { file } from './structs';\nimport type { YargsArgs } from './types/yargs';\nimport { CONFIG_FILE, TS_CONFIG_FILE } from './utils';\n\nconst CONFIG_FILES = [CONFIG_FILE, TS_CONFIG_FILE];\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n *\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\nexport type SnapBrowserifyConfig = {\n /**\n * The bundler to use to build the snap. For backwards compatibility, if not\n * specified, Browserify will be used. However, the Browserify bundler is\n * deprecated and will be removed in a future release, so it's recommended to\n * use the Webpack bundler instead.\n */\n bundler: 'browserify';\n\n /**\n * The options for the Snaps CLI. These are merged with the options passed to\n * the CLI, with the CLI options taking precedence.\n *\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\n cliOptions?: {\n /**\n * The path to the snap bundle file.\n *\n * @default 'dist/bundle.js'\n */\n bundle?: string;\n\n /**\n * The directory to output the snap to. This is only used if `bundle` is\n * not specified.\n *\n * @default 'dist'\n */\n dist?: string;\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n eval?: boolean;\n\n /**\n * Whether to validate the snap manifest.\n *\n * @default true\n */\n manifest?: boolean;\n\n /**\n * The name of the bundle file. This is only used if `bundle` is not\n * specified.\n *\n * @default 'bundle.js'\n */\n outfileName?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n\n /**\n * The root directory to serve the snap from.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * Whether to generate source maps for the snap bundle.\n *\n * @default false\n */\n sourceMaps?: boolean;\n\n /**\n * The path to the snap entry point.\n *\n * @default 'src/index.js'\n */\n src?: string;\n\n /**\n * Whether to remove comments from the bundle.\n *\n * @default true\n */\n stripComments?: boolean;\n\n /**\n * Whether to suppress warnings.\n *\n * @default false\n */\n suppressWarnings?: boolean;\n\n /**\n * The transpilation mode to use, which determines which files are\n * transpiled.\n *\n * - `'localAndDeps'`: Transpile the snap entry point and all dependencies.\n * - `'localOnly'`: Transpile only the snap entry point.\n * - `'none'`: Don't transpile any files.\n *\n * @default 'localOnly'\n */\n transpilationMode?: 'localAndDeps' | 'localOnly' | 'none';\n\n /**\n * The dependencies to transpile when `transpilationMode` is set to\n * `'localAndDeps'`. If not specified, all dependencies will be transpiled.\n */\n depsToTranspile?: string[];\n\n /**\n * Whether to show original errors.\n *\n * @default true\n */\n verboseErrors?: boolean;\n\n /**\n * Whether to write the updated manifest to disk.\n *\n * @default true\n */\n writeManifest?: boolean;\n\n /**\n * Whether to serve the snap locally.\n *\n * @default true\n */\n serve?: boolean;\n };\n\n /**\n * A function that can be used to customize the Browserify instance used to\n * build the snap.\n *\n * @param bundler - The Browserify instance.\n * @deprecated The Browserify bundler is deprecated and will be removed in a\n * future release. Use the Webpack bundler instead.\n */\n bundlerCustomizer?: (bundler: BrowserifyObject) => void;\n};\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapWebpackConfig = {\n /**\n * The bundler to use to build the snap. For backwards compatibility, if not\n * specified, Browserify will be used. However, the Browserify bundler is\n * deprecated and will be removed in a future release, so it's recommended to\n * use the Webpack bundler instead.\n */\n bundler?: 'webpack';\n\n /**\n * The path to the snap entry point. This should be a JavaScript or TypeScript\n * file.\n */\n input: string;\n\n /**\n * Whether to generate source maps for the snap. If `true`, source maps will\n * be generated as separate files. If `'inline'`, source maps will be\n * inlined in the generated JavaScript bundle.\n *\n * @default true\n */\n sourceMap?: boolean | 'inline';\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n evaluate?: boolean;\n\n output?: {\n /**\n * The path to the directory where the snap will be built. This directory\n * will be created if it doesn't exist.\n *\n * If the path is relative, it will be resolved relative to the current\n * working directory.\n *\n * @default 'dist'\n */\n path?: string;\n\n /**\n * The name of the JavaScript bundle file.\n *\n * @default 'bundle.js'\n */\n filename?: string;\n\n /**\n * Whether to clean the output directory before building the snap. If\n * `true`, the output directory will be deleted and recreated. Otherwise,\n * the output directory will be left as-is.\n *\n * @default false\n */\n clean?: boolean;\n\n /**\n * Whether to minimize the snap bundle. If `true`, the bundle will be\n * minified. Otherwise, the bundle will be left as-is.\n *\n * @default true\n */\n minimize?: boolean;\n };\n\n manifest?: {\n /**\n * The path to the snap manifest file. If the path is relative, it will be\n * resolved relative to the current working directory.\n *\n * @default 'snap.manifest.json'\n */\n path?: string;\n\n /**\n * Whether to automatically update the manifest. If `true`, the manifest\n * will be updated with the latest shasum of the snap bundle, and some\n * common fields will be updated if they are missing or incorrect. If\n * `false`, the manifest will be left as-is.\n *\n * @default true\n */\n update?: boolean;\n };\n\n server?: {\n /**\n * Whether to enable the local server. If `true`, the snap will be served\n * from a local server, when running the `watch` command. If `false`, the\n * snap will not be served.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * The root directory to serve the snap from. If the path is relative, it\n * will be resolved relative to the current working directory.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n };\n\n /**\n * The environment variables to set when building the snap. These will be\n * available in the snap as `process.env`. In addition to these environment\n * variables, the following environment variables will always be set:\n *\n * - `NODE_DEBUG`: `false`\n * - `NODE_ENV`: `'production'`\n * - `DEBUG`: `false`\n *\n * Any environment variables specified here will override these defaults. You\n * can also override any variables here by setting them in your shell when\n * running the CLI.\n */\n environment?: Record<string, unknown>;\n\n /**\n * Options that control the logging output of the CLI.\n */\n stats?: {\n /**\n * Whether to enable verbose logging.\n *\n * @default false\n */\n verbose?: boolean;\n\n /**\n * Whether to log warnings about unresolved built-in modules. If `false`,\n * warnings will not be logged.\n */\n builtIns?:\n | {\n /**\n * The built-in modules to ignore when resolving modules. If a module\n * is ignored, no warning will be logged if it is not resolved.\n */\n ignore?: string[];\n }\n | false;\n\n /**\n * Whether to log warnings about the use of the `Buffer` global. If `false`,\n * warnings will not be logged. If `true`, the CLI will warn if the `Buffer`\n * global is used, but not provided by Webpack's `DefinePlugin`.\n */\n buffer?: boolean;\n };\n\n /**\n * Whether to provide polyfills for node builtins. If `true`, all the available\n * polyfills will be provided. If `false` no polyfills will be provided. If a\n * configuration object is passed only the polyfills set to `true` will be provided.\n *\n * @default false\n * @example\n * ```ts\n * polyfills: true\n *\n * // or\n *\n * polyfills: {\n * assert: true,\n * buffer: true\n * }\n * ```\n */\n polyfills?:\n | boolean\n | {\n assert?: boolean;\n buffer?: boolean;\n console?: boolean;\n constants?: boolean;\n crypto?: boolean;\n domain?: boolean;\n events?: boolean;\n http?: boolean;\n https?: boolean;\n os?: boolean;\n path?: boolean;\n punycode?: boolean;\n process?: boolean;\n querystring?: boolean;\n stream?: boolean;\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex?: boolean;\n _stream_passthrough?: boolean;\n _stream_readable?: boolean;\n _stream_transform?: boolean;\n _stream_writable?: boolean;\n string_decoder?: boolean;\n /* eslint-enable @typescript-eslint/naming-convention */\n sys?: boolean;\n timers?: boolean;\n tty?: boolean;\n url?: boolean;\n util?: boolean;\n vm?: boolean;\n zlib?: boolean;\n };\n\n /**\n * Support for TypeScript type-checking feature.\n *\n * @example\n * {\n * enabled: true;\n * configFile: './path/to/tsconfig.json'\n * }\n */\n typescript?: {\n /**\n * Whether to enable TypeScript type-checking feature.\n *\n * @default false\n */\n enabled?: boolean;\n /**\n * Path to tsconfig.json file for the Snap.\n *\n * @default 'tsconfig.json'\n */\n configFile?: string;\n };\n\n /**\n * Optional features to enable in the CLI.\n *\n * @example\n * {\n * features: {\n * images: true,\n * }\n * }\n */\n features?: {\n /**\n * Whether to enable support for images. If `true`, the Webpack\n * configuration will be modified to support images. If `false`, the\n * Webpack configuration will not be modified.\n *\n * @default true\n */\n images?: boolean;\n };\n\n /**\n * A function to customize the Webpack configuration used to build the snap.\n * This function will be called with the default Webpack configuration, and\n * should return the modified configuration. If not specified, the default\n * configuration will be used.\n *\n * It's recommended to use the `webpack-merge` package to merge the default\n * configuration with your customizations. The merge function is exported as\n * `merge` from the `@metamask/snaps-cli` package.\n *\n * @example\n * ```ts\n * import type { SnapsConfig } from '@metamask/snaps-cli';\n * import { merge } from '@metamask/snaps-cli';\n *\n * const config: SnapsConfig = {\n * bundler: 'webpack',\n * entry: 'src/index.ts',\n * customizeWebpackConfig: (config) => merge(config, {\n * module: {\n * rules: [\n * {\n * test: /\\.wasm$/,\n * type: 'assets/resource',\n * },\n * ],\n * },\n * }),\n * };\n *\n * export default config;\n * ```\n */\n customizeWebpackConfig?: (\n config: WebpackConfiguration,\n ) => WebpackConfiguration;\n\n /**\n * Experimental features that can be enabled. These features are not\n * guaranteed to be stable, and may be removed or changed in a future release.\n */\n experimental?: {\n /**\n * Whether to enable WebAssembly support. If `true`, the Webpack\n * configuration will be modified to support WebAssembly. If `false`, the\n * Webpack configuration will not be modified.\n *\n * @default false\n */\n wasm?: boolean;\n };\n};\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapConfig = SnapBrowserifyConfig | SnapWebpackConfig;\n\ntype SnapsBrowserifyBundlerCustomizerFunction = (\n bundler: BrowserifyObject,\n) => void;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsBrowserifyBundlerCustomizerFunctionStruct =\n define<SnapsBrowserifyBundlerCustomizerFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsBrowserifyConfigStruct = object({\n bundler: literal('browserify'),\n cliOptions: defaulted(\n object({\n bundle: optional(file()),\n dist: defaulted(file(), 'dist'),\n eval: defaulted(boolean(), true),\n manifest: defaulted(boolean(), true),\n port: defaulted(number(), 8081),\n outfileName: defaulted(string(), 'bundle.js'),\n root: defaulted(file(), process.cwd()),\n sourceMaps: defaulted(boolean(), false),\n src: defaulted(file(), 'src/index.js'),\n stripComments: defaulted(boolean(), true),\n suppressWarnings: defaulted(boolean(), false),\n transpilationMode: defaulted(\n union([literal('localAndDeps'), literal('localOnly'), literal('none')]),\n 'localOnly',\n ),\n depsToTranspile: defaulted(array(string()), []),\n verboseErrors: defaulted(boolean(), true),\n writeManifest: defaulted(boolean(), true),\n serve: defaulted(boolean(), true),\n }),\n {},\n ),\n bundlerCustomizer: optional(SnapsBrowserifyBundlerCustomizerFunctionStruct),\n});\n\ntype SnapsWebpackCustomizeWebpackConfigFunction = (\n config: WebpackConfiguration,\n) => WebpackConfiguration;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsWebpackCustomizeWebpackConfigFunctionStruct =\n define<SnapsWebpackCustomizeWebpackConfigFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsWebpackConfigStruct = object({\n bundler: defaulted(literal('webpack'), 'webpack'),\n input: defaulted(file(), resolve(process.cwd(), 'src/index.js')),\n sourceMap: defaulted(union([boolean(), literal('inline')]), false),\n evaluate: defaulted(boolean(), true),\n\n output: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'dist')),\n filename: defaulted(string(), 'bundle.js'),\n clean: defaulted(boolean(), false),\n minimize: defaulted(boolean(), true),\n }),\n {},\n ),\n\n manifest: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'snap.manifest.json')),\n update: defaulted(boolean(), true),\n }),\n {},\n ),\n\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n root: defaulted(file(), process.cwd()),\n port: defaulted(number(), 8081),\n }),\n {},\n ),\n\n environment: defaulted(record(string(), unknown()), {}),\n\n stats: defaulted(\n object({\n verbose: defaulted(boolean(), false),\n builtIns: defaulted(\n union([\n object({ ignore: defaulted(array(string()), []) }),\n literal(false),\n ]),\n {},\n ),\n buffer: defaulted(boolean(), true),\n }),\n {},\n ),\n\n polyfills: defaulted(\n union([\n boolean(),\n object({\n assert: defaulted(boolean(), false),\n buffer: defaulted(boolean(), false),\n console: defaulted(boolean(), false),\n constants: defaulted(boolean(), false),\n crypto: defaulted(boolean(), false),\n domain: defaulted(boolean(), false),\n events: defaulted(boolean(), false),\n http: defaulted(boolean(), false),\n https: defaulted(boolean(), false),\n os: defaulted(boolean(), false),\n path: defaulted(boolean(), false),\n punycode: defaulted(boolean(), false),\n process: defaulted(boolean(), false),\n querystring: defaulted(boolean(), false),\n stream: defaulted(boolean(), false),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: defaulted(boolean(), false),\n _stream_passthrough: defaulted(boolean(), false),\n _stream_readable: defaulted(boolean(), false),\n _stream_transform: defaulted(boolean(), false),\n _stream_writable: defaulted(boolean(), false),\n string_decoder: defaulted(boolean(), false),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: defaulted(boolean(), false),\n timers: defaulted(boolean(), false),\n tty: defaulted(boolean(), false),\n url: defaulted(boolean(), false),\n util: defaulted(boolean(), false),\n vm: defaulted(boolean(), false),\n zlib: defaulted(boolean(), false),\n }),\n ]),\n false,\n ),\n\n typescript: defaulted(\n object({\n enabled: defaulted(boolean(), false),\n configFile: defaulted(file(), 'tsconfig.json'),\n }),\n {},\n ),\n\n features: defaulted(\n object({\n images: defaulted(boolean(), true),\n }),\n {},\n ),\n\n customizeWebpackConfig: optional(\n SnapsWebpackCustomizeWebpackConfigFunctionStruct,\n ),\n\n experimental: defaulted(\n object({\n wasm: defaulted(boolean(), false),\n }),\n {},\n ),\n});\n\nexport const SnapsConfigStruct = type({\n bundler: defaulted(\n union([literal('browserify'), literal('webpack')]),\n 'webpack',\n ),\n});\n\nexport const LegacyOptionsStruct = union([\n named(\n 'object with `transpilationMode` set to `localAndDeps` and `depsToTranspile` set to an array of strings',\n type({\n depsToTranspile: array(string()),\n transpilationMode: literal(TranspilationModes.LocalAndDeps),\n writeManifest: boolean(),\n bundlerCustomizer: optional(\n SnapsBrowserifyBundlerCustomizerFunctionStruct,\n ),\n }),\n ),\n named(\n 'object without `depsToTranspile`',\n type({\n depsToTranspile: named('empty array', empty(array())),\n transpilationMode: union([\n literal(TranspilationModes.LocalOnly),\n literal(TranspilationModes.None),\n ]),\n writeManifest: boolean(),\n bundlerCustomizer: optional(\n SnapsBrowserifyBundlerCustomizerFunctionStruct,\n ),\n }),\n ),\n]);\n\nexport type LegacyOptions = Infer<typeof LegacyOptionsStruct>;\n\nexport type ProcessedBrowserifyConfig = Infer<\n typeof SnapsBrowserifyConfigStruct\n>;\n\nexport type ProcessedWebpackConfig = Infer<typeof SnapsWebpackConfigStruct> & {\n /**\n * The legacy Browserify config, if the bundler is Browserify. This is used\n * to support the legacy config format.\n */\n legacy?: LegacyOptions;\n};\n\nexport type ProcessedConfig = ProcessedWebpackConfig;\n\n/**\n * Get a validated snap config. This validates the config and adds default\n * values for any missing properties.\n *\n * @param config - The config to validate.\n * @param argv - The CLI arguments.\n * @returns The validated config.\n */\nexport function getConfig(config: unknown, argv: YargsArgs): ProcessedConfig {\n const prefix = 'The snap config file is invalid';\n const suffix = dim(\n 'Refer to the documentation for more information: https://docs.metamask.io/snaps/reference/cli/options/',\n );\n\n const { bundler } = createFromStruct(\n config,\n SnapsConfigStruct,\n prefix,\n suffix,\n );\n\n if (bundler === 'browserify') {\n const legacyConfig = createFromStruct(\n config,\n SnapsBrowserifyConfigStruct,\n prefix,\n suffix,\n );\n\n return getWebpackConfig(mergeLegacyOptions(argv, legacyConfig));\n }\n\n return createFromStruct(config, SnapsWebpackConfigStruct, prefix, suffix);\n}\n\n/**\n * Load a snap config from a file. This supports both JavaScript and TypeScript\n * config files, in the CommonJS module format and the ES module format.\n *\n * This assumes that the config file exports a default object, either through\n * `module.exports` or `export default`.\n *\n * @param path - The full path to the config file.\n * @param argv - The CLI arguments.\n * @returns The validated config.\n * @throws If the config file is invalid, or if the config file does not have a\n * default export.\n */\nexport async function loadConfig(path: string, argv: YargsArgs) {\n try {\n const contents = await readFile(path, 'utf8');\n const source = await transform(contents, {\n swcrc: false,\n jsc: {\n parser: {\n syntax: 'typescript',\n },\n },\n module: {\n type: 'commonjs',\n },\n });\n\n const config = new Module(path);\n\n // @ts-expect-error - This function is not typed.\n config.paths = Module._nodeModulePaths(dirname(path));\n\n // @ts-expect-error - This function is not typed.\n config._compile(source.code, path);\n\n if (!hasProperty(config.exports, 'default')) {\n return getConfig(config.exports, argv);\n }\n\n return getConfig(config.exports.default, argv);\n } catch (error) {\n if (error instanceof SnapsStructError) {\n throw new ConfigError(error.message);\n }\n\n throw new ConfigError(\n `Unable to load snap config file at \"${path}\".\\n\\n${indent(\n error.message,\n )}`,\n );\n }\n}\n\n/**\n * Resolve a snap config. This function will look for a `snap.config.js` or\n * `snap.config.ts` file in the current or specified directory.\n *\n * @param path - The path to resolve the snap config from. Defaults to the\n * current working directory.\n * @param argv - The CLI arguments.\n * @returns The resolved and validated snap config.\n * @throws If a snap config could not be found.\n */\nexport async function resolveConfig(path: string, argv: YargsArgs) {\n for (const configFile of CONFIG_FILES) {\n const filePath = resolve(path, configFile);\n if (await isFile(filePath)) {\n return await loadConfig(filePath, argv);\n }\n }\n\n throw new ConfigError(\n `Could not find a \"snap.config.js\" or \"snap.config.ts\" file in the current or specified directory (\"${path}\").`,\n );\n}\n\n/**\n * Get a snap config from the CLI arguments. This will either load the config\n * from the specified config file, or resolve the config from the current\n * working directory.\n *\n * @param argv - The CLI arguments.\n * @param cwd - The current working directory. Defaults to `process.cwd()`.\n * @returns The resolved and validated snap config.\n */\nexport async function getConfigByArgv(\n argv: YargsArgs,\n cwd: string = process.cwd(),\n) {\n if (argv.config) {\n if (!(await isFile(argv.config))) {\n throw new ConfigError(\n `Could not find a config file at \"${argv.config}\". Make sure that the path is correct.`,\n );\n }\n\n return await loadConfig(argv.config, argv);\n }\n\n return await resolveConfig(cwd, argv);\n}\n\n/**\n * Merge legacy CLI options into the config. This is used to support the legacy\n * config format, where options can be specified both in the config file and\n * through CLI flags.\n *\n * @param argv - The CLI arguments.\n * @param config - The config to merge the CLI options into.\n * @returns The config with the CLI options merged in.\n * @deprecated This function is only used to support the legacy config format.\n */\nexport function mergeLegacyOptions(\n argv: YargsArgs,\n config: ProcessedBrowserifyConfig,\n) {\n const cliOptions = Object.keys(config.cliOptions).reduce<\n ProcessedBrowserifyConfig['cliOptions']\n >((accumulator, key) => {\n if (argv[key] !== undefined) {\n return {\n ...accumulator,\n [key]: argv[key],\n };\n }\n\n return accumulator;\n }, config.cliOptions);\n\n return {\n ...config,\n cliOptions,\n };\n}\n\n/**\n * Get a Webpack config from a legacy browserify config. This is used to\n * support the legacy config format, and convert it to the new format.\n *\n * @param legacyConfig - The legacy browserify config.\n * @returns The Webpack config.\n */\nexport function getWebpackConfig(\n legacyConfig: ProcessedBrowserifyConfig,\n): ProcessedWebpackConfig {\n const defaultConfig = create(\n { bundler: 'webpack' },\n SnapsWebpackConfigStruct,\n );\n\n // The legacy config has two options for specifying the output path and\n // filename: `bundle`, and `dist` + `outfileName`. If `bundle` is specified,\n // we use that as the output path and filename. Otherwise, we use `dist` and\n // `outfileName`.\n const path = legacyConfig.cliOptions.bundle\n ? dirname(legacyConfig.cliOptions.bundle)\n : legacyConfig.cliOptions.dist;\n\n const filename = legacyConfig.cliOptions.bundle\n ? basename(legacyConfig.cliOptions.bundle)\n : legacyConfig.cliOptions.outfileName;\n\n return {\n ...defaultConfig,\n input: legacyConfig.cliOptions.src,\n evaluate: legacyConfig.cliOptions.eval,\n sourceMap: legacyConfig.cliOptions.sourceMaps,\n output: {\n path,\n filename,\n\n // The legacy config has an option to remove comments from the bundle, but\n // the terser plugin does this by default, so we only enable the terser if\n // the legacy config has `stripComments` set to `true`. This is not a\n // perfect solution, but it's the best we can do without breaking the\n // legacy config.\n minimize: legacyConfig.cliOptions.stripComments,\n\n // The legacy config does not have a `clean` option, so we default to\n // `false` here.\n clean: false,\n },\n manifest: {\n // The legacy config does not have a `manifest` option, so we default to\n // `process.cwd()/snap.manifest.json`.\n path: resolve(process.cwd(), 'snap.manifest.json'),\n update: legacyConfig.cliOptions.writeManifest,\n },\n server: {\n enabled: legacyConfig.cliOptions.serve,\n port: legacyConfig.cliOptions.port,\n root: legacyConfig.cliOptions.root,\n },\n stats: {\n verbose: false,\n\n // These plugins are designed to be used with the modern config format, so\n // we disable them for the legacy config format.\n builtIns: false,\n buffer: false,\n },\n legacy: createFromStruct(\n {\n ...legacyConfig.cliOptions,\n bundlerCustomizer: legacyConfig.bundlerCustomizer,\n },\n LegacyOptionsStruct,\n 'Invalid Browserify CLI options',\n ),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"config.mjs","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,4BAA4B;AACrD,OAAO,EACL,gBAAgB,EAChB,MAAM,EACN,MAAM,EACN,gBAAgB,EACjB,mCAAmC;AACpC,OAAO,EACL,KAAK,EACL,OAAO,EACP,SAAS,EACT,MAAM,EACN,IAAI,EACJ,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,OAAO,EACR,8BAA8B;AAE/B,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAC9C,OAAO,EAAE,SAAS,EAAE,kBAAkB;;;AAEtC,OAAO,EAAE,QAAQ,EAAE,oBAAoB;AACvC,OAAO,MAAM,eAAe;AAC5B,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa;AAGxC,OAAO,EAAE,WAAW,EAAE,qBAAiB;AACvC,OAAO,EAAE,IAAI,EAAE,sBAAkB;AAEjC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,0BAAgB;AAEtD,MAAM,YAAY,GAAG,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;AA4TnD,6EAA6E;AAC7E,6EAA6E;AAC7E,oBAAoB;AACpB,MAAM,gDAAgD,GACpD,MAAM,CACJ,UAAU,EACV,IAAI,EAAE,CAAC,SAAS,CACjB,CAAC;AAEJ,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;IACtC,KAAK,EAAE,SAAS,CAAC,IAAI,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC,G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metamask/snaps-sdk';\nimport {\n createFromStruct,\n indent,\n isFile,\n SnapsStructError,\n} from '@metamask/snaps-utils/node';\nimport {\n array,\n boolean,\n defaulted,\n define,\n func,\n number,\n object,\n optional,\n record,\n string,\n unknown,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { hasProperty } from '@metamask/utils';\nimport { transform } from '@swc/core';\nimport { dim } from 'chalk';\nimport { readFile } from 'fs/promises';\nimport Module from 'module';\nimport { dirname, resolve } from 'path';\nimport type { Configuration as WebpackConfiguration } from 'webpack';\n\nimport { ConfigError } from './errors';\nimport { file } from './structs';\nimport type { YargsArgs } from './types/yargs';\nimport { CONFIG_FILE, TS_CONFIG_FILE } from './utils';\n\nconst CONFIG_FILES = [CONFIG_FILE, TS_CONFIG_FILE];\n\n/**\n * The configuration for the Snaps CLI, stored as `snap.config.js` or\n * `snap.config.ts` in the root of the project.\n */\nexport type SnapConfig = {\n /**\n * The path to the snap entry point. This should be a JavaScript or TypeScript\n * file.\n */\n input: string;\n\n /**\n * Whether to generate source maps for the snap. If `true`, source maps will\n * be generated as separate files. If `'inline'`, source maps will be\n * inlined in the generated JavaScript bundle.\n *\n * @default true\n */\n sourceMap?: boolean | 'inline';\n\n /**\n * Whether to attempt to evaluate the snap in SES. This can catch some errors\n * that would otherwise only be caught at runtime.\n *\n * @default true\n */\n evaluate?: boolean;\n\n output?: {\n /**\n * The path to the directory where the snap will be built. This directory\n * will be created if it doesn't exist.\n *\n * If the path is relative, it will be resolved relative to the current\n * working directory.\n *\n * @default 'dist'\n */\n path?: string;\n\n /**\n * The name of the JavaScript bundle file.\n *\n * @default 'bundle.js'\n */\n filename?: string;\n\n /**\n * Whether to clean the output directory before building the snap. If\n * `true`, the output directory will be deleted and recreated. Otherwise,\n * the output directory will be left as-is.\n *\n * @default false\n */\n clean?: boolean;\n\n /**\n * Whether to minimize the snap bundle. If `true`, the bundle will be\n * minified. Otherwise, the bundle will be left as-is.\n *\n * @default true\n */\n minimize?: boolean;\n };\n\n manifest?: {\n /**\n * The path to the snap manifest file. If the path is relative, it will be\n * resolved relative to the current working directory.\n *\n * @default 'snap.manifest.json'\n */\n path?: string;\n\n /**\n * Whether to automatically update the manifest. If `true`, the manifest\n * will be updated with the latest shasum of the snap bundle, and some\n * common fields will be updated if they are missing or incorrect. If\n * `false`, the manifest will be left as-is.\n *\n * @default true\n */\n update?: boolean;\n };\n\n server?: {\n /**\n * Whether to enable the local server. If `true`, the snap will be served\n * from a local server, when running the `watch` command. If `false`, the\n * snap will not be served.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * The root directory to serve the snap from. If the path is relative, it\n * will be resolved relative to the current working directory.\n *\n * @default `process.cwd()`\n */\n root?: string;\n\n /**\n * The port to run the server on.\n *\n * @default 8081\n */\n port?: number;\n };\n\n /**\n * The environment variables to set when building the snap. These will be\n * available in the snap as `process.env`. In addition to these environment\n * variables, the following environment variables will always be set:\n *\n * - `NODE_DEBUG`: `false`\n * - `NODE_ENV`: `'production'`\n * - `DEBUG`: `false`\n *\n * Any environment variables specified here will override these defaults. You\n * can also override any variables here by setting them in your shell when\n * running the CLI.\n */\n environment?: Record<string, unknown>;\n\n /**\n * Options that control the logging output of the CLI.\n */\n stats?: {\n /**\n * Whether to enable verbose logging.\n *\n * @default false\n */\n verbose?: boolean;\n\n /**\n * Whether to log warnings about unresolved built-in modules. If `false`,\n * warnings will not be logged.\n */\n builtIns?:\n | {\n /**\n * The built-in modules to ignore when resolving modules. If a module\n * is ignored, no warning will be logged if it is not resolved.\n */\n ignore?: string[];\n }\n | false;\n\n /**\n * Whether to log warnings about the use of the `Buffer` global. If `false`,\n * warnings will not be logged. If `true`, the CLI will warn if the `Buffer`\n * global is used, but not provided by Webpack's `DefinePlugin`.\n */\n buffer?: boolean;\n };\n\n /**\n * Whether to provide polyfills for node builtins. If `true`, all the available\n * polyfills will be provided. If `false` no polyfills will be provided. If a\n * configuration object is passed only the polyfills set to `true` will be provided.\n *\n * @default false\n * @example\n * ```ts\n * polyfills: true\n *\n * // or\n *\n * polyfills: {\n * assert: true,\n * buffer: true\n * }\n * ```\n */\n polyfills?:\n | boolean\n | {\n assert?: boolean;\n buffer?: boolean;\n console?: boolean;\n constants?: boolean;\n crypto?: boolean;\n domain?: boolean;\n events?: boolean;\n http?: boolean;\n https?: boolean;\n os?: boolean;\n path?: boolean;\n punycode?: boolean;\n process?: boolean;\n querystring?: boolean;\n stream?: boolean;\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex?: boolean;\n _stream_passthrough?: boolean;\n _stream_readable?: boolean;\n _stream_transform?: boolean;\n _stream_writable?: boolean;\n string_decoder?: boolean;\n /* eslint-enable @typescript-eslint/naming-convention */\n sys?: boolean;\n timers?: boolean;\n tty?: boolean;\n url?: boolean;\n util?: boolean;\n vm?: boolean;\n zlib?: boolean;\n };\n\n /**\n * Support for TypeScript type-checking feature.\n *\n * @example\n * {\n * enabled: true;\n * configFile: './path/to/tsconfig.json'\n * }\n */\n typescript?: {\n /**\n * Whether to enable TypeScript type-checking feature.\n *\n * @default false\n */\n enabled?: boolean;\n /**\n * Path to tsconfig.json file for the Snap.\n *\n * @default 'tsconfig.json'\n */\n configFile?: string;\n };\n\n /**\n * Optional features to enable in the CLI.\n *\n * @example\n * {\n * features: {\n * images: true,\n * }\n * }\n */\n features?: {\n /**\n * Whether to enable support for images. If `true`, the Webpack\n * configuration will be modified to support images. If `false`, the\n * Webpack configuration will not be modified.\n *\n * @default true\n */\n images?: boolean;\n };\n\n /**\n * A function to customize the Webpack configuration used to build the snap.\n * This function will be called with the default Webpack configuration, and\n * should return the modified configuration. If not specified, the default\n * configuration will be used.\n *\n * It's recommended to use the `webpack-merge` package to merge the default\n * configuration with your customizations. The merge function is exported as\n * `merge` from the `@metamask/snaps-cli` package.\n *\n * @example\n * ```ts\n * import type { SnapsConfig } from '@metamask/snaps-cli';\n * import { merge } from '@metamask/snaps-cli';\n *\n * const config: SnapsConfig = {\n * bundler: 'webpack',\n * entry: 'src/index.ts',\n * customizeWebpackConfig: (config) => merge(config, {\n * module: {\n * rules: [\n * {\n * test: /\\.wasm$/,\n * type: 'assets/resource',\n * },\n * ],\n * },\n * }),\n * };\n *\n * export default config;\n * ```\n */\n customizeWebpackConfig?: (\n config: WebpackConfiguration,\n ) => WebpackConfiguration;\n\n /**\n * Experimental features that can be enabled. These features are not\n * guaranteed to be stable, and may be removed or changed in a future release.\n */\n experimental?: {\n /**\n * Whether to enable WebAssembly support. If `true`, the Webpack\n * configuration will be modified to support WebAssembly. If `false`, the\n * Webpack configuration will not be modified.\n *\n * @default false\n */\n wasm?: boolean;\n };\n};\n\ntype SnapsWebpackCustomizeWebpackConfigFunction = (\n config: WebpackConfiguration,\n) => WebpackConfiguration;\n\n// This struct is essentially the same as the `func` struct, but it's defined\n// separately so that we include the function type in the inferred TypeScript\n// type definitions.\nconst SnapsWebpackCustomizeWebpackConfigFunctionStruct =\n define<SnapsWebpackCustomizeWebpackConfigFunction>(\n 'function',\n func().validator,\n );\n\nexport const SnapsConfigStruct = object({\n input: defaulted(file(), resolve(process.cwd(), 'src/index.js')),\n sourceMap: defaulted(union([boolean(), literal('inline')]), false),\n evaluate: defaulted(boolean(), true),\n\n output: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'dist')),\n filename: defaulted(string(), 'bundle.js'),\n clean: defaulted(boolean(), false),\n minimize: defaulted(boolean(), true),\n }),\n {},\n ),\n\n manifest: defaulted(\n object({\n path: defaulted(file(), resolve(process.cwd(), 'snap.manifest.json')),\n update: defaulted(boolean(), true),\n }),\n {},\n ),\n\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n root: defaulted(file(), process.cwd()),\n port: defaulted(number(), 8081),\n }),\n {},\n ),\n\n environment: defaulted(record(string(), unknown()), {}),\n\n stats: defaulted(\n object({\n verbose: defaulted(boolean(), false),\n builtIns: defaulted(\n union([\n object({ ignore: defaulted(array(string()), []) }),\n literal(false),\n ]),\n {},\n ),\n buffer: defaulted(boolean(), true),\n }),\n {},\n ),\n\n polyfills: defaulted(\n union([\n boolean(),\n object({\n assert: defaulted(boolean(), false),\n buffer: defaulted(boolean(), false),\n console: defaulted(boolean(), false),\n constants: defaulted(boolean(), false),\n crypto: defaulted(boolean(), false),\n domain: defaulted(boolean(), false),\n events: defaulted(boolean(), false),\n http: defaulted(boolean(), false),\n https: defaulted(boolean(), false),\n os: defaulted(boolean(), false),\n path: defaulted(boolean(), false),\n punycode: defaulted(boolean(), false),\n process: defaulted(boolean(), false),\n querystring: defaulted(boolean(), false),\n stream: defaulted(boolean(), false),\n /* eslint-disable @typescript-eslint/naming-convention */\n _stream_duplex: defaulted(boolean(), false),\n _stream_passthrough: defaulted(boolean(), false),\n _stream_readable: defaulted(boolean(), false),\n _stream_transform: defaulted(boolean(), false),\n _stream_writable: defaulted(boolean(), false),\n string_decoder: defaulted(boolean(), false),\n /* eslint-enable @typescript-eslint/naming-convention */\n sys: defaulted(boolean(), false),\n timers: defaulted(boolean(), false),\n tty: defaulted(boolean(), false),\n url: defaulted(boolean(), false),\n util: defaulted(boolean(), false),\n vm: defaulted(boolean(), false),\n zlib: defaulted(boolean(), false),\n }),\n ]),\n false,\n ),\n\n typescript: defaulted(\n object({\n enabled: defaulted(boolean(), false),\n configFile: defaulted(file(), 'tsconfig.json'),\n }),\n {},\n ),\n\n features: defaulted(\n object({\n images: defaulted(boolean(), true),\n }),\n {},\n ),\n\n customizeWebpackConfig: optional(\n SnapsWebpackCustomizeWebpackConfigFunctionStruct,\n ),\n\n experimental: defaulted(\n object({\n wasm: defaulted(boolean(), false),\n }),\n {},\n ),\n});\n\nexport type ProcessedConfig = Infer<typeof SnapsConfigStruct>;\n\n/**\n * Get a validated snap config. This validates the config and adds default\n * values for any missing properties.\n *\n * @param config - The config to validate.\n * @returns The validated config.\n */\nexport function getConfig(config: unknown): ProcessedConfig {\n const prefix = 'The snap config file is invalid';\n const suffix = dim(\n 'Refer to the documentation for more information: https://docs.metamask.io/snaps/reference/cli/options/',\n );\n\n return createFromStruct(config, SnapsConfigStruct, prefix, suffix);\n}\n\n/**\n * Load a snap config from a file. This supports both JavaScript and TypeScript\n * config files, in the CommonJS module format and the ES module format.\n *\n * This assumes that the config file exports a default object, either through\n * `module.exports` or `export default`.\n *\n * @param path - The full path to the config file.\n * @returns The validated config.\n * @throws If the config file is invalid, or if the config file does not have a\n * default export.\n */\nexport async function loadConfig(path: string) {\n try {\n const contents = await readFile(path, 'utf8');\n const source = await transform(contents, {\n swcrc: false,\n jsc: {\n parser: {\n syntax: 'typescript',\n },\n },\n module: {\n type: 'commonjs',\n },\n });\n\n const config = new Module(path);\n\n // @ts-expect-error - This function is not typed.\n config.paths = Module._nodeModulePaths(dirname(path));\n\n // @ts-expect-error - This function is not typed.\n config._compile(source.code, path);\n\n if (!hasProperty(config.exports, 'default')) {\n return getConfig(config.exports);\n }\n\n return getConfig(config.exports.default);\n } catch (error) {\n if (error instanceof SnapsStructError) {\n throw new ConfigError(error.message);\n }\n\n throw new ConfigError(\n `Unable to load snap config file at \"${path}\".\\n\\n${indent(\n error.message,\n )}`,\n );\n }\n}\n\n/**\n * Resolve a snap config. This function will look for a `snap.config.js` or\n * `snap.config.ts` file in the current or specified directory.\n *\n * @param path - The path to resolve the snap config from. Defaults to the\n * current working directory.\n * @returns The resolved and validated snap config.\n * @throws If a snap config could not be found.\n */\nexport async function resolveConfig(path: string) {\n for (const configFile of CONFIG_FILES) {\n const filePath = resolve(path, configFile);\n if (await isFile(filePath)) {\n return await loadConfig(filePath);\n }\n }\n\n throw new ConfigError(\n `Could not find a \"snap.config.js\" or \"snap.config.ts\" file in the current or specified directory (\"${path}\").`,\n );\n}\n\n/**\n * Get a snap config from the CLI arguments. This will either load the config\n * from the specified config file, or resolve the config from the current\n * working directory.\n *\n * @param argv - The CLI arguments.\n * @param cwd - The current working directory. Defaults to `process.cwd()`.\n * @returns The resolved and validated snap config.\n */\nexport async function getConfigByArgv(\n argv: YargsArgs,\n cwd: string = process.cwd(),\n) {\n if (argv.config) {\n if (!(await isFile(argv.config))) {\n throw new ConfigError(\n `Could not find a config file at \"${argv.config}\". Make sure that the path is correct.`,\n );\n }\n\n return await loadConfig(argv.config);\n }\n\n return await resolveConfig(cwd);\n}\n"]}
|
package/dist/main.cjs
CHANGED
|
@@ -15,7 +15,6 @@ const commands_1 = __importDefault(require("./commands/index.cjs"));
|
|
|
15
15
|
* npx update-browserslist-db@latest
|
|
16
16
|
* Why you should do it regularly: https://github.com/browserslist/update-db#readme
|
|
17
17
|
*/
|
|
18
|
-
// eslint-disable-next-line n/no-process-env
|
|
19
18
|
process.env.BROWSERSLIST_IGNORE_OLD_DATA = '1';
|
|
20
19
|
(0, cli_1.cli)(process.argv, commands_1.default).catch((error) => {
|
|
21
20
|
(0, snaps_utils_1.logError)(error);
|
package/dist/main.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.cjs","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;AAEA,uDAAiD;AAEjD,mCAA4B;AAC5B,oEAAkC;AAElC;;;;;;;GAOG;AACH,
|
|
1
|
+
{"version":3,"file":"main.cjs","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;AAEA,uDAAiD;AAEjD,mCAA4B;AAC5B,oEAAkC;AAElC;;;;;;;GAOG;AACH,OAAO,CAAC,GAAG,CAAC,4BAA4B,GAAG,GAAG,CAAC;AAE/C,IAAA,SAAG,EAAC,OAAO,CAAC,IAAI,EAAE,kBAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAC1C,IAAA,sBAAQ,EAAC,KAAK,CAAC,CAAC;IAChB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { logError } from '@metamask/snaps-utils';\n\nimport { cli } from './cli';\nimport commands from './commands';\n\n/*\n * Disable the following error, we target an old version\n * of a browser, and this error is not useful to our users.\n *\n * Browserslist: caniuse-lite is outdated. Please run:\n * npx update-browserslist-db@latest\n * Why you should do it regularly: https://github.com/browserslist/update-db#readme\n */\nprocess.env.BROWSERSLIST_IGNORE_OLD_DATA = '1';\n\ncli(process.argv, commands).catch((error) => {\n logError(error);\n process.exitCode = 1;\n});\n"]}
|
package/dist/main.mjs
CHANGED
|
@@ -10,7 +10,6 @@ import commands from "./commands/index.mjs";
|
|
|
10
10
|
* npx update-browserslist-db@latest
|
|
11
11
|
* Why you should do it regularly: https://github.com/browserslist/update-db#readme
|
|
12
12
|
*/
|
|
13
|
-
// eslint-disable-next-line n/no-process-env
|
|
14
13
|
process.env.BROWSERSLIST_IGNORE_OLD_DATA = '1';
|
|
15
14
|
cli(process.argv, commands).catch((error) => {
|
|
16
15
|
logError(error);
|
package/dist/main.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.mjs","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAEjD,OAAO,EAAE,GAAG,EAAE,kBAAc;AAC5B,OAAO,QAAQ,6BAAmB;AAElC;;;;;;;GAOG;AACH,
|
|
1
|
+
{"version":3,"file":"main.mjs","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAEjD,OAAO,EAAE,GAAG,EAAE,kBAAc;AAC5B,OAAO,QAAQ,6BAAmB;AAElC;;;;;;;GAOG;AACH,OAAO,CAAC,GAAG,CAAC,4BAA4B,GAAG,GAAG,CAAC;AAE/C,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAC1C,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { logError } from '@metamask/snaps-utils';\n\nimport { cli } from './cli';\nimport commands from './commands';\n\n/*\n * Disable the following error, we target an old version\n * of a browser, and this error is not useful to our users.\n *\n * Browserslist: caniuse-lite is outdated. Please run:\n * npx update-browserslist-db@latest\n * Why you should do it regularly: https://github.com/browserslist/update-db#readme\n */\nprocess.env.BROWSERSLIST_IGNORE_OLD_DATA = '1';\n\ncli(process.argv, commands).catch((error) => {\n logError(error);\n process.exitCode = 1;\n});\n"]}
|
package/dist/utils/index.cjs
CHANGED
|
@@ -16,7 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./cli.cjs"), exports);
|
|
18
18
|
__exportStar(require("./errors.cjs"), exports);
|
|
19
|
-
__exportStar(require("./legacy.cjs"), exports);
|
|
20
19
|
__exportStar(require("./logging.cjs"), exports);
|
|
21
20
|
__exportStar(require("./path.cjs"), exports);
|
|
22
21
|
__exportStar(require("./steps.cjs"), exports);
|
package/dist/utils/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAsB;AACtB,+CAAyB;AACzB
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAsB;AACtB,+CAAyB;AACzB,gDAA0B;AAC1B,6CAAuB;AACvB,8CAAwB","sourcesContent":["export * from './cli';\nexport * from './errors';\nexport * from './logging';\nexport * from './path';\nexport * from './steps';\n"]}
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,0BAAsB;AACtB,6BAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,0BAAsB;AACtB,6BAAyB;AACzB,8BAA0B;AAC1B,2BAAuB;AACvB,4BAAwB"}
|
package/dist/utils/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,0BAAsB;AACtB,6BAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,0BAAsB;AACtB,6BAAyB;AACzB,8BAA0B;AAC1B,2BAAuB;AACvB,4BAAwB"}
|
package/dist/utils/index.mjs
CHANGED
package/dist/utils/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,0BAAsB;AACtB,6BAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,0BAAsB;AACtB,6BAAyB;AACzB,8BAA0B;AAC1B,2BAAuB;AACvB,4BAAwB","sourcesContent":["export * from './cli';\nexport * from './errors';\nexport * from './logging';\nexport * from './path';\nexport * from './steps';\n"]}
|
package/dist/utils/steps.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"steps.cjs","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":";;;;;;AAAA,iCAA4B;AAE5B,uDAAgC;AAEhC,yCAA2C;AAC3C,2CAAkC;
|
|
1
|
+
{"version":3,"file":"steps.cjs","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":";;;;;;AAAA,iCAA4B;AAE5B,uDAAgC;AAEhC,yCAA2C;AAC3C,2CAAkC;AAWlC;;;;;;GAMG;AACI,KAAK,UAAU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type { Ora } from 'ora';\nimport createSpinner from 'ora';\n\nimport { getErrorMessage } from './errors';\nimport { error } from './logging';\n\nexport type Step<Context extends Record<string, unknown>> = {\n name: string;\n condition?: (context: Context) => boolean;\n task: (context: Context & { spinner: Ora }) => Promise<Context | void>;\n};\n\nexport type Steps<Context extends Record<string, unknown>> =\n readonly Step<Context>[];\n\n/**\n * Execute a list of steps in series. Each step receives the context object and\n * a spinner instance.\n *\n * @param steps - The steps to execute.\n * @param context - The context object that will be passed to each step.\n */\nexport async function executeSteps<Context extends Record<string, unknown>>(\n steps: Steps<Context>,\n context: Context,\n) {\n const spinner = createSpinner({\n // Ora writes to `process.stderr` by default.\n stream: process.stdout,\n });\n\n spinner.start();\n\n try {\n await steps.reduce<Promise<Context>>(async (contextPromise, step) => {\n const currentContext = await contextPromise;\n\n // If the step has a condition, and it returns false, we skip the step.\n if (step.condition && !step.condition(currentContext)) {\n return currentContext;\n }\n\n // Calling `start` here instead of setting `spinner.text` seems to work\n // better when the process doesn't have a TTY.\n spinner.start(dim(step.name));\n\n const newContext = await step.task({\n ...currentContext,\n spinner,\n });\n\n // If the task returns a new context, we use it. Otherwise, we keep the\n // current context.\n return newContext ?? currentContext;\n }, Promise.resolve(context));\n\n // The spinner may have been stopped by a step, so we only succeed if it's\n // still spinning.\n if (spinner.isSpinning) {\n spinner.succeed('Done!');\n }\n } catch (_error) {\n error(getErrorMessage(_error), spinner);\n spinner.stop();\n\n // eslint-disable-next-line require-atomic-updates\n process.exitCode = 1;\n }\n}\n"]}
|
package/dist/utils/steps.d.cts
CHANGED
|
@@ -6,7 +6,7 @@ export type Step<Context extends Record<string, unknown>> = {
|
|
|
6
6
|
spinner: Ora;
|
|
7
7
|
}) => Promise<Context | void>;
|
|
8
8
|
};
|
|
9
|
-
export type Steps<Context extends Record<string, unknown>> =
|
|
9
|
+
export type Steps<Context extends Record<string, unknown>> = readonly Step<Context>[];
|
|
10
10
|
/**
|
|
11
11
|
* Execute a list of steps in series. Each step receives the context object and
|
|
12
12
|
* a spinner instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"steps.d.cts","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAM/B,MAAM,MAAM,IAAI,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;IAC1C,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,GAAG;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CACxE,CAAC;AAEF,MAAM,MAAM,KAAK,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"steps.d.cts","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAM/B,MAAM,MAAM,IAAI,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;IAC1C,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,GAAG;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CACxE,CAAC;AAEF,MAAM,MAAM,KAAK,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACvD,SAAS,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;AAE3B;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,EACrB,OAAO,EAAE,OAAO,iBA4CjB"}
|
package/dist/utils/steps.d.mts
CHANGED
|
@@ -6,7 +6,7 @@ export type Step<Context extends Record<string, unknown>> = {
|
|
|
6
6
|
spinner: Ora;
|
|
7
7
|
}) => Promise<Context | void>;
|
|
8
8
|
};
|
|
9
|
-
export type Steps<Context extends Record<string, unknown>> =
|
|
9
|
+
export type Steps<Context extends Record<string, unknown>> = readonly Step<Context>[];
|
|
10
10
|
/**
|
|
11
11
|
* Execute a list of steps in series. Each step receives the context object and
|
|
12
12
|
* a spinner instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"steps.d.mts","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAM/B,MAAM,MAAM,IAAI,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;IAC1C,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,GAAG;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CACxE,CAAC;AAEF,MAAM,MAAM,KAAK,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"steps.d.mts","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,qBAAY;AAM/B,MAAM,MAAM,IAAI,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;IAC1C,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,GAAG;QAAE,OAAO,EAAE,GAAG,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CACxE,CAAC;AAEF,MAAM,MAAM,KAAK,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACvD,SAAS,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;AAE3B;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,EACrB,OAAO,EAAE,OAAO,iBA4CjB"}
|
package/dist/utils/steps.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"steps.mjs","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":";;;;;;;;AAEA,OAAO,cAAa,qBAAY;;AAEhC,OAAO,EAAE,eAAe,EAAE,qBAAiB;AAC3C,OAAO,EAAE,KAAK,EAAE,sBAAkB;
|
|
1
|
+
{"version":3,"file":"steps.mjs","sourceRoot":"","sources":["../../src/utils/steps.ts"],"names":[],"mappings":";;;;;;;;AAEA,OAAO,cAAa,qBAAY;;AAEhC,OAAO,EAAE,eAAe,EAAE,qBAAiB;AAC3C,OAAO,EAAE,KAAK,EAAE,sBAAkB;AAWlC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAqB,EACrB,OAAgB;IAEhB,MAAM,OAAO,GAAG,aAAa,CAAC;QAC5B,6CAA6C;QAC7C,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IAEH,OAAO,CAAC,KAAK,EAAE,CAAC;IAEhB,IAAI,CAAC;QACH,MAAM,KAAK,CAAC,MAAM,CAAmB,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE;YAClE,MAAM,cAAc,GAAG,MAAM,cAAc,CAAC;YAE5C,uEAAuE;YACvE,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC;gBACtD,OAAO,cAAc,CAAC;YACxB,CAAC;YAED,uEAAuE;YACvE,8CAA8C;YAC9C,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAE9B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC;gBACjC,GAAG,cAAc;gBACjB,OAAO;aACR,CAAC,CAAC;YAEH,uEAAuE;YACvE,mBAAmB;YACnB,OAAO,UAAU,IAAI,cAAc,CAAC;QACtC,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QAE7B,0EAA0E;QAC1E,kBAAkB;QAClB,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,EAAE,CAAC;QAEf,kDAAkD;QAClD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["import { dim } from 'chalk';\nimport type { Ora } from 'ora';\nimport createSpinner from 'ora';\n\nimport { getErrorMessage } from './errors';\nimport { error } from './logging';\n\nexport type Step<Context extends Record<string, unknown>> = {\n name: string;\n condition?: (context: Context) => boolean;\n task: (context: Context & { spinner: Ora }) => Promise<Context | void>;\n};\n\nexport type Steps<Context extends Record<string, unknown>> =\n readonly Step<Context>[];\n\n/**\n * Execute a list of steps in series. Each step receives the context object and\n * a spinner instance.\n *\n * @param steps - The steps to execute.\n * @param context - The context object that will be passed to each step.\n */\nexport async function executeSteps<Context extends Record<string, unknown>>(\n steps: Steps<Context>,\n context: Context,\n) {\n const spinner = createSpinner({\n // Ora writes to `process.stderr` by default.\n stream: process.stdout,\n });\n\n spinner.start();\n\n try {\n await steps.reduce<Promise<Context>>(async (contextPromise, step) => {\n const currentContext = await contextPromise;\n\n // If the step has a condition, and it returns false, we skip the step.\n if (step.condition && !step.condition(currentContext)) {\n return currentContext;\n }\n\n // Calling `start` here instead of setting `spinner.text` seems to work\n // better when the process doesn't have a TTY.\n spinner.start(dim(step.name));\n\n const newContext = await step.task({\n ...currentContext,\n spinner,\n });\n\n // If the task returns a new context, we use it. Otherwise, we keep the\n // current context.\n return newContext ?? currentContext;\n }, Promise.resolve(context));\n\n // The spinner may have been stopped by a step, so we only succeed if it's\n // still spinning.\n if (spinner.isSpinning) {\n spinner.succeed('Done!');\n }\n } catch (_error) {\n error(getErrorMessage(_error), spinner);\n spinner.stop();\n\n // eslint-disable-next-line require-atomic-updates\n process.exitCode = 1;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.cjs","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;
|
|
1
|
+
{"version":3,"file":"compiler.cjs","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAGlC,yCAAmD;AAGnD;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAC/B,MAAuB,EACvB,OAAwB;IAExB,MAAM,iBAAiB,GAAG,MAAM,IAAA,gCAAuB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzE,MAAM,aAAa,GACjB,MAAM,CAAC,sBAAsB,EAAE,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,CAAC;IAE1E,OAAO,IAAA,iBAAO,EAAC,aAAa,CAAC,CAAC;AAChC,CAAC;AATD,kCASC","sourcesContent":["import { webpack } from 'webpack';\n\nimport type { WebpackOptions } from './config';\nimport { getDefaultConfiguration } from './config';\nimport type { ProcessedConfig } from '../config';\n\n/**\n * Get a Webpack compiler for the given config.\n *\n * @param config - The config object.\n * @param options - The Webpack options.\n * @returns The Webpack compiler.\n */\nexport async function getCompiler(\n config: ProcessedConfig,\n options?: WebpackOptions,\n) {\n const baseWebpackConfig = await getDefaultConfiguration(config, options);\n const webpackConfig =\n config.customizeWebpackConfig?.(baseWebpackConfig) ?? baseWebpackConfig;\n\n return webpack(webpackConfig);\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ProcessedWebpackConfig } from "../config.cjs";
|
|
2
1
|
import type { WebpackOptions } from "./config.cjs";
|
|
2
|
+
import type { ProcessedConfig } from "../config.cjs";
|
|
3
3
|
/**
|
|
4
4
|
* Get a Webpack compiler for the given config.
|
|
5
5
|
*
|
|
@@ -7,5 +7,5 @@ import type { WebpackOptions } from "./config.cjs";
|
|
|
7
7
|
* @param options - The Webpack options.
|
|
8
8
|
* @returns The Webpack compiler.
|
|
9
9
|
*/
|
|
10
|
-
export declare function getCompiler(config:
|
|
10
|
+
export declare function getCompiler(config: ProcessedConfig, options?: WebpackOptions): Promise<import("webpack").Compiler>;
|
|
11
11
|
//# sourceMappingURL=compiler.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.d.cts","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"compiler.d.cts","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAiB;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAEjD;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,eAAe,EACvB,OAAO,CAAC,EAAE,cAAc,uCAOzB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ProcessedWebpackConfig } from "../config.mjs";
|
|
2
1
|
import type { WebpackOptions } from "./config.mjs";
|
|
2
|
+
import type { ProcessedConfig } from "../config.mjs";
|
|
3
3
|
/**
|
|
4
4
|
* Get a Webpack compiler for the given config.
|
|
5
5
|
*
|
|
@@ -7,5 +7,5 @@ import type { WebpackOptions } from "./config.mjs";
|
|
|
7
7
|
* @param options - The Webpack options.
|
|
8
8
|
* @returns The Webpack compiler.
|
|
9
9
|
*/
|
|
10
|
-
export declare function getCompiler(config:
|
|
10
|
+
export declare function getCompiler(config: ProcessedConfig, options?: WebpackOptions): Promise<import("webpack").Compiler>;
|
|
11
11
|
//# sourceMappingURL=compiler.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.d.mts","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"compiler.d.mts","sourceRoot":"","sources":["../../src/webpack/compiler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAiB;AAE/C,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAkB;AAEjD;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,eAAe,EACvB,OAAO,CAAC,EAAE,cAAc,uCAOzB"}
|