Skip to content

Commit

Permalink
BREAKING: Change CLI config to use Webpack by default (#2214)
Browse files Browse the repository at this point in the history
Initially when implementing the Webpack configuration for the CLI, the
goal was to be fully backwards compatible with legacy Browserify-based
Snap configs. This meant that in order to use Webpack, you would have to
specify `bundler: 'webpack'` in your config. Now that the Webpack-based
configuration has been available for some time, we can further deprecate
Browserify by making Webpack the default. You can still opt-in to
Browserify by setting `bundler: 'browserify'`.
  • Loading branch information
Mrtenz committed Feb 23, 2024
1 parent df74d38 commit 33f01f1
Show file tree
Hide file tree
Showing 32 changed files with 57 additions and 40 deletions.
1 change: 0 additions & 1 deletion packages/examples/packages/bip32/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8001,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/bip44/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8002,
Expand Down
1 change: 1 addition & 0 deletions packages/examples/packages/browserify/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'browserify',
cliOptions: {
src: resolve(__dirname, 'src/index.ts'),
port: 8021,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/client-status/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8027,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/cronjobs/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8004,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/dialogs/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8005,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/errors/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8006,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8007,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/ethers-js/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { resolve } from 'path';
import { DefinePlugin } from 'webpack';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8008,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/get-entropy/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8009,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/get-file/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8024,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/home-page/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8025,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/images/snap.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { SnapConfig } from '@metamask/snaps-cli';

const config: SnapConfig = {
bundler: 'webpack',
input: './src/index.ts',
server: {
port: 8026,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/interactive-ui/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8028,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8012,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8011,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/json-rpc/snap.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { SnapConfig } from '@metamask/snaps-cli';

const config: SnapConfig = {
bundler: 'webpack',
input: './src/index.ts',
server: {
port: 8013,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/lifecycle-hooks/snap.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { SnapConfig } from '@metamask/snaps-cli';

const config: SnapConfig = {
bundler: 'webpack',
input: './src/index.ts',
server: {
port: 8022,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/localization/snap.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { SnapConfig } from '@metamask/snaps-cli';

const config: SnapConfig = {
bundler: 'webpack',
input: './src/index.ts',
server: {
port: 8020,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/manage-state/snap.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { SnapConfig } from '@metamask/snaps-cli';

const config: SnapConfig = {
bundler: 'webpack',
input: './src/index.ts',
server: {
port: 8014,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/name-lookup/snap.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { SnapConfig } from '@metamask/snaps-cli';

const config: SnapConfig = {
bundler: 'webpack',
input: './src/index.ts',
server: {
port: 8023,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/network-access/snap.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { SnapConfig } from '@metamask/snaps-cli';

const config: SnapConfig = {
bundler: 'webpack',
input: './src/index.ts',
server: {
port: 8015,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/notifications/snap.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { SnapConfig } from '@metamask/snaps-cli';

const config: SnapConfig = {
bundler: 'webpack',
input: './src/index.ts',
server: {
port: 8016,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8017,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { SnapConfig } from '@metamask/snaps-cli';

const config: SnapConfig = {
bundler: 'webpack',
input: './src/index.ts',
server: {
port: 8018,
Expand Down
1 change: 0 additions & 1 deletion packages/examples/packages/wasm/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8019,
Expand Down
1 change: 0 additions & 1 deletion packages/snaps-cli/src/__fixtures__/configs/cjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import type { SnapConfig } from '../../config';

const config: SnapConfig = {
bundler: 'webpack',
input: 'src/index.ts',
};

Expand Down
1 change: 0 additions & 1 deletion packages/snaps-cli/src/__fixtures__/configs/esm.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { SnapConfig } from '../../config';

const config: SnapConfig = {
bundler: 'webpack',
input: 'src/index.ts',
};

Expand Down
1 change: 0 additions & 1 deletion packages/snaps-cli/src/__fixtures__/configs/invalid.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { SnapConfig } from '../../config';

const config: SnapConfig = {
bundler: 'webpack',
// @ts-expect-error - Invalid option.
foo: 'bar',
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { SnapConfig } from '../../../config';

const config: SnapConfig = {
bundler: 'webpack',
input: 'src/index.ts',
};

Expand Down
57 changes: 51 additions & 6 deletions packages/snaps-cli/src/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,52 @@ describe('getConfig', () => {
).toThrow(`Unknown key: ${bold('cliOptions')}, received:`);
});

it.each([
{
input: 'src/index.js',
sourceMap: false,
output: {
path: 'dist',
},
server: {
port: 8081,
},
},
{
input: 'src/index.js',
output: {
path: 'dist',
},
server: {
port: 8081,
},
},
{
input: 'src/index.js',
server: {
port: 8081,
},
},
{
input: 'src/index.js',
output: {},
},
{
input: 'src/index.js',
},
{},
])('returns a valid config for `%o`', (value) => {
const config = getConfig(value, MOCK_ARGV);

expect(config).toStrictEqual(
getMockConfig('webpack', {
input: resolve(process.cwd(), 'src', 'index.js'),
}),
);

expect(config.legacy).toBeUndefined();
});

describe('browserify', () => {
it.each([
{
Expand All @@ -73,20 +119,18 @@ describe('getConfig', () => {
},
},
{
bundler: 'browserify',
cliOptions: {
src: 'src/index.js',
port: 8081,
},
},
{
cliOptions: {
port: 8081,
},
bundler: 'browserify',
cliOptions: {},
},
{
cliOptions: {},
bundler: 'browserify',
},
{},
])('returns a valid config for `%o`', (value) => {
const config = getConfig(value, MOCK_ARGV);

Expand Down Expand Up @@ -115,6 +159,7 @@ describe('getConfig', () => {
expect(() =>
getConfig(
{
bundler: 'browserify',
cliOptions: {
depsToTranspile: ['foo', 'bar'],
transpilationMode: TranspilationModes.LocalOnly,
Expand Down
10 changes: 5 additions & 5 deletions packages/snaps-cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type SnapBrowserifyConfig = {
* deprecated and will be removed in a future release, so it's recommended to
* use the Webpack bundler instead.
*/
bundler?: 'browserify';
bundler: 'browserify';

/**
* The options for the Snaps CLI. These are merged with the options passed to
Expand Down Expand Up @@ -206,7 +206,7 @@ export type SnapWebpackConfig = {
* deprecated and will be removed in a future release, so it's recommended to
* use the Webpack bundler instead.
*/
bundler: 'webpack';
bundler?: 'webpack';

/**
* The path to the snap entry point. This should be a JavaScript or TypeScript
Expand Down Expand Up @@ -488,7 +488,7 @@ const SnapsBrowserifyBundlerCustomizerFunctionStruct =
);

export const SnapsBrowserifyConfigStruct = object({
bundler: defaulted(literal('browserify'), 'browserify'),
bundler: literal('browserify'),
cliOptions: defaulted(
object({
bundle: optional(file()),
Expand Down Expand Up @@ -530,7 +530,7 @@ const SnapsWebpackCustomizeWebpackConfigFunctionStruct =
);

export const SnapsWebpackConfigStruct = object({
bundler: literal('webpack'),
bundler: defaulted(literal('webpack'), 'webpack'),
input: defaulted(file(), resolve(process.cwd(), 'src/index.js')),
sourceMap: defaulted(union([boolean(), literal('inline')]), false),
evaluate: defaulted(boolean(), true),
Expand Down Expand Up @@ -633,7 +633,7 @@ export const SnapsWebpackConfigStruct = object({
export const SnapsConfigStruct = type({
bundler: defaulted(
union([literal('browserify'), literal('webpack')]),
'browserify',
'webpack',
),
});

Expand Down

0 comments on commit 33f01f1

Please sign in to comment.