Skip to content

Commit 767752f

Browse files
committed
Revert CLI changes
1 parent 9bcd3bc commit 767752f

File tree

3 files changed

+86
-25
lines changed

3 files changed

+86
-25
lines changed

packages/snaps-cli/src/webpack/__snapshots__/config.test.ts.snap

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
1616
"use": {
1717
"loader": "/foo/bar/node_modules/swc-loader/index.js",
1818
"options": {
19+
"env": {
20+
"targets": "chrome >= 90, firefox >= 91",
21+
},
1922
"jsc": {
2023
"parser": {
2124
"syntax": "typescript",
2225
"tsx": true,
2326
},
24-
"target": "esnext",
2527
"transform": {
2628
"react": {
2729
"importSource": "@metamask/snaps-sdk",
@@ -186,12 +188,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
186188
"use": {
187189
"loader": "/foo/bar/node_modules/swc-loader/index.js",
188190
"options": {
191+
"env": {
192+
"targets": "chrome >= 90, firefox >= 91",
193+
},
189194
"jsc": {
190195
"parser": {
191196
"syntax": "typescript",
192197
"tsx": true,
193198
},
194-
"target": "esnext",
195199
"transform": {
196200
"react": {
197201
"importSource": "@metamask/snaps-sdk",
@@ -356,12 +360,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
356360
"use": {
357361
"loader": "/foo/bar/node_modules/swc-loader/index.js",
358362
"options": {
363+
"env": {
364+
"targets": "chrome >= 90, firefox >= 91",
365+
},
359366
"jsc": {
360367
"parser": {
361368
"syntax": "typescript",
362369
"tsx": true,
363370
},
364-
"target": "esnext",
365371
"transform": {
366372
"react": {
367373
"importSource": "@metamask/snaps-sdk",
@@ -526,12 +532,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
526532
"use": {
527533
"loader": "/foo/bar/node_modules/swc-loader/index.js",
528534
"options": {
535+
"env": {
536+
"targets": "chrome >= 90, firefox >= 91",
537+
},
529538
"jsc": {
530539
"parser": {
531540
"syntax": "typescript",
532541
"tsx": true,
533542
},
534-
"target": "esnext",
535543
"transform": {
536544
"react": {
537545
"importSource": "@metamask/snaps-sdk",
@@ -687,12 +695,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
687695
"use": {
688696
"loader": "/foo/bar/node_modules/swc-loader/index.js",
689697
"options": {
698+
"env": {
699+
"targets": "chrome >= 90, firefox >= 91",
700+
},
690701
"jsc": {
691702
"parser": {
692703
"syntax": "typescript",
693704
"tsx": true,
694705
},
695-
"target": "esnext",
696706
"transform": {
697707
"react": {
698708
"importSource": "@metamask/snaps-sdk",
@@ -865,12 +875,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
865875
"use": {
866876
"loader": "/foo/bar/node_modules/swc-loader/index.js",
867877
"options": {
878+
"env": {
879+
"targets": "chrome >= 90, firefox >= 91",
880+
},
868881
"jsc": {
869882
"parser": {
870883
"syntax": "typescript",
871884
"tsx": true,
872885
},
873-
"target": "esnext",
874886
"transform": {
875887
"react": {
876888
"importSource": "@metamask/snaps-sdk",
@@ -1035,12 +1047,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
10351047
"use": {
10361048
"loader": "/foo/bar/node_modules/swc-loader/index.js",
10371049
"options": {
1050+
"env": {
1051+
"targets": "chrome >= 90, firefox >= 91",
1052+
},
10381053
"jsc": {
10391054
"parser": {
10401055
"syntax": "typescript",
10411056
"tsx": true,
10421057
},
1043-
"target": "esnext",
10441058
"transform": {
10451059
"react": {
10461060
"importSource": "@metamask/snaps-sdk",
@@ -1205,12 +1219,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
12051219
"use": {
12061220
"loader": "/foo/bar/node_modules/swc-loader/index.js",
12071221
"options": {
1222+
"env": {
1223+
"targets": "chrome >= 90, firefox >= 91",
1224+
},
12081225
"jsc": {
12091226
"parser": {
12101227
"syntax": "typescript",
12111228
"tsx": true,
12121229
},
1213-
"target": "esnext",
12141230
"transform": {
12151231
"react": {
12161232
"importSource": "@metamask/snaps-sdk",
@@ -1383,12 +1399,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
13831399
"use": {
13841400
"loader": "/foo/bar/node_modules/swc-loader/index.js",
13851401
"options": {
1402+
"env": {
1403+
"targets": "chrome >= 90, firefox >= 91",
1404+
},
13861405
"jsc": {
13871406
"parser": {
13881407
"syntax": "typescript",
13891408
"tsx": true,
13901409
},
1391-
"target": "esnext",
13921410
"transform": {
13931411
"react": {
13941412
"importSource": "@metamask/snaps-sdk",
@@ -1561,12 +1579,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
15611579
"use": {
15621580
"loader": "/foo/bar/node_modules/swc-loader/index.js",
15631581
"options": {
1582+
"env": {
1583+
"targets": "chrome >= 90, firefox >= 91",
1584+
},
15641585
"jsc": {
15651586
"parser": {
15661587
"syntax": "typescript",
15671588
"tsx": true,
15681589
},
1569-
"target": "esnext",
15701590
"transform": {
15711591
"react": {
15721592
"importSource": "@metamask/snaps-sdk",
@@ -1716,12 +1736,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
17161736
"use": {
17171737
"loader": "/foo/bar/node_modules/swc-loader/index.js",
17181738
"options": {
1739+
"env": {
1740+
"targets": "chrome >= 90, firefox >= 91",
1741+
},
17191742
"jsc": {
17201743
"parser": {
17211744
"syntax": "typescript",
17221745
"tsx": true,
17231746
},
1724-
"target": "esnext",
17251747
"transform": {
17261748
"react": {
17271749
"importSource": "@metamask/snaps-sdk",
@@ -1894,12 +1916,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
18941916
"use": {
18951917
"loader": "/foo/bar/node_modules/swc-loader/index.js",
18961918
"options": {
1919+
"env": {
1920+
"targets": "chrome >= 90, firefox >= 91",
1921+
},
18971922
"jsc": {
18981923
"parser": {
18991924
"syntax": "typescript",
19001925
"tsx": true,
19011926
},
1902-
"target": "esnext",
19031927
"transform": {
19041928
"react": {
19051929
"importSource": "@metamask/snaps-sdk",
@@ -2072,12 +2096,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
20722096
"use": {
20732097
"loader": "/foo/bar/node_modules/swc-loader/index.js",
20742098
"options": {
2099+
"env": {
2100+
"targets": "chrome >= 90, firefox >= 91",
2101+
},
20752102
"jsc": {
20762103
"parser": {
20772104
"syntax": "typescript",
20782105
"tsx": true,
20792106
},
2080-
"target": "esnext",
20812107
"transform": {
20822108
"react": {
20832109
"importSource": "@metamask/snaps-sdk",
@@ -2251,12 +2277,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
22512277
"use": {
22522278
"loader": "/foo/bar/node_modules/swc-loader/index.js",
22532279
"options": {
2280+
"env": {
2281+
"targets": "chrome >= 90, firefox >= 91",
2282+
},
22542283
"jsc": {
22552284
"parser": {
22562285
"syntax": "typescript",
22572286
"tsx": true,
22582287
},
2259-
"target": "esnext",
22602288
"transform": {
22612289
"react": {
22622290
"importSource": "@metamask/snaps-sdk",
@@ -2421,12 +2449,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
24212449
"use": {
24222450
"loader": "/foo/bar/node_modules/swc-loader/index.js",
24232451
"options": {
2452+
"env": {
2453+
"targets": "chrome >= 90, firefox >= 91",
2454+
},
24242455
"jsc": {
24252456
"parser": {
24262457
"syntax": "typescript",
24272458
"tsx": true,
24282459
},
2429-
"target": "esnext",
24302460
"transform": {
24312461
"react": {
24322462
"importSource": "@metamask/snaps-sdk",
@@ -2591,12 +2621,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
25912621
"use": {
25922622
"loader": "/foo/bar/node_modules/swc-loader/index.js",
25932623
"options": {
2624+
"env": {
2625+
"targets": "chrome >= 90, firefox >= 91",
2626+
},
25942627
"jsc": {
25952628
"parser": {
25962629
"syntax": "typescript",
25972630
"tsx": true,
25982631
},
2599-
"target": "esnext",
26002632
"transform": {
26012633
"react": {
26022634
"importSource": "@metamask/snaps-sdk",
@@ -2770,12 +2802,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration for t
27702802
"use": {
27712803
"loader": "/foo/bar/node_modules/swc-loader/index.js",
27722804
"options": {
2805+
"env": {
2806+
"targets": "chrome >= 90, firefox >= 91",
2807+
},
27732808
"jsc": {
27742809
"parser": {
27752810
"syntax": "typescript",
27762811
"tsx": true,
27772812
},
2778-
"target": "esnext",
27792813
"transform": {
27802814
"react": {
27812815
"importSource": "@metamask/snaps-sdk",
@@ -2949,12 +2983,14 @@ exports[`getDefaultConfiguration returns the default Webpack configuration when
29492983
"use": {
29502984
"loader": "/foo/bar/node_modules/swc-loader/index.js",
29512985
"options": {
2986+
"env": {
2987+
"targets": "chrome >= 90, firefox >= 91",
2988+
},
29522989
"jsc": {
29532990
"parser": {
29542991
"syntax": "typescript",
29552992
"tsx": true,
29562993
},
2957-
"target": "esnext",
29582994
"transform": {
29592995
"react": {
29602996
"importSource": "@metamask/snaps-sdk",

packages/snaps-cli/src/webpack/utils.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { dim } from 'chalk';
22

33
import {
44
WEBPACK_FALLBACKS,
5+
getBrowserslistTargets,
56
getDefaultLoader,
67
getDevTool,
78
getFallbacks,
@@ -60,6 +61,18 @@ describe('getProgressHandler', () => {
6061
});
6162
});
6263

64+
describe('getBrowserslistTargets', () => {
65+
it('returns the default targets', async () => {
66+
const targets = await getBrowserslistTargets();
67+
expect(targets).toMatchInlineSnapshot(`
68+
[
69+
"chrome >= 113",
70+
"firefox >= 115",
71+
]
72+
`);
73+
});
74+
});
75+
6376
describe('pluralize', () => {
6477
it('pluralizes a word, based on the count', () => {
6578
expect(pluralize(0, 'test')).toBe('tests');

packages/snaps-cli/src/webpack/utils.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { bytesToBase64 } from '@metamask/utils';
22
import { dim } from 'chalk';
3+
import { promises as fs } from 'fs';
34
import { builtinModules } from 'module';
45
import type { Ora } from 'ora';
56
import { dirname, resolve } from 'path';
@@ -61,6 +62,7 @@ export const WEBPACK_FALLBACKS = {
6162
* @returns The default loader.
6263
*/
6364
export async function getDefaultLoader({ sourceMap }: ProcessedConfig) {
65+
const targets = await getBrowserslistTargets();
6466
return {
6567
/**
6668
* We use the `swc-loader` to transpile TypeScript and JavaScript files.
@@ -87,13 +89,6 @@ export async function getDefaultLoader({ sourceMap }: ProcessedConfig) {
8789
sourceMaps: Boolean(getDevTool(sourceMap)),
8890

8991
jsc: {
90-
/**
91-
* This tells SWC to target the latest ECMAScript version, letting
92-
* Webpack handle the final transpilation to the supported version
93-
* later in the build process.
94-
*/
95-
target: 'esnext',
96-
9792
parser: {
9893
/**
9994
* This tells the parser to parse TypeScript files. If you
@@ -161,6 +156,10 @@ export async function getDefaultLoader({ sourceMap }: ProcessedConfig) {
161156
*/
162157
type: 'es6',
163158
},
159+
160+
env: {
161+
targets: targets.join(', '),
162+
},
164163
},
165164
};
166165
}
@@ -210,6 +209,19 @@ export function getProgressHandler(spinner?: Ora, spinnerText?: string) {
210209
};
211210
}
212211

212+
/**
213+
* Get the targets from the `.browserslistrc` file.
214+
*
215+
* @returns The browser targets as an array of strings.
216+
*/
217+
export async function getBrowserslistTargets() {
218+
const contents = await fs.readFile(BROWSERSLIST_FILE, 'utf8');
219+
return contents
220+
.split('\n')
221+
.map((line) => line.trim())
222+
.filter((line) => line && !line.startsWith('#'));
223+
}
224+
213225
/**
214226
* Get a singular or plural string based on the given count. This is useful for
215227
* generating messages like "1 error" or "2 errors". By default, the plural

0 commit comments

Comments
 (0)