Skip to content

Commit cf4170e

Browse files
authored
Merge branch 'main' into fix/sig-params-v2
2 parents 854ab59 + bba4201 commit cf4170e

File tree

5 files changed

+46
-24
lines changed

5 files changed

+46
-24
lines changed

app/manifest/v3/_base.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
"notifications",
8585
"scripting",
8686
"storage",
87-
"tabs",
8887
"unlimitedStorage",
8988
"webRequest",
9089
"offscreen",

development/webpack/test/config.test.ts

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'node:fs';
2-
import { describe, it, after, mock } from 'node:test';
2+
import { describe, it, afterEach, mock } from 'node:test';
33
import assert from 'node:assert';
44
import { resolve } from 'node:path';
55
import { version } from '../../../package.json';
@@ -13,21 +13,29 @@ describe('./utils/config.ts', () => {
1313
// behaving
1414
describe('variables', () => {
1515
const originalReadFileSync = fs.readFileSync;
16-
function mockRc(env: Record<string, string> = {}) {
16+
function mockRc(
17+
env: Record<string, string> = {},
18+
prodEnv: Record<string, string> = {},
19+
) {
1720
mock.method(fs, 'readFileSync', (path: string, options: object) => {
21+
// mock the rc files as users might have customized it which may break our tests
1822
if (path === resolve(__dirname, '../../../.metamaskrc')) {
19-
// mock `.metamaskrc`, as users might have customized it which may
20-
// break our tests
2123
return `
22-
${Object.entries(env)
23-
.map(([key, value]) => `${key}=${value}`)
24-
.join('\n')}
25-
`;
24+
${Object.entries(env)
25+
.map(([key, value]) => `${key}=${value}`)
26+
.join('\n')}
27+
`;
28+
} else if (path === resolve(__dirname, '../../../.metamaskprodrc')) {
29+
return `
30+
${Object.entries(prodEnv)
31+
.map(([key, value]) => `${key}=${value}`)
32+
.join('\n')}
33+
`;
2634
}
2735
return originalReadFileSync(path, options);
2836
});
2937
}
30-
after(() => mock.restoreAll());
38+
afterEach(() => mock.restoreAll());
3139

3240
it('should return valid build variables for the default build', () => {
3341
const buildTypes = loadBuildTypesConfig();
@@ -49,17 +57,31 @@ ${Object.entries(env)
4957
);
5058
});
5159

52-
it('should prefer .metamaskrc variables over others', () => {
60+
it('should prefer .metamaskprodrc over .metamaskrc', () => {
5361
const buildTypes = loadBuildTypesConfig();
5462
const { args } = parseArgv([], buildTypes);
5563
const defaultVars = config.getVariables(args, buildTypes);
5664

5765
// verify the default value of the main build is false
5866
assert.strictEqual(defaultVars.variables.get('ALLOW_LOCAL_SNAPS'), false);
5967

60-
mockRc({
61-
ALLOW_LOCAL_SNAPS: 'true',
62-
});
68+
mockRc({ ALLOW_LOCAL_SNAPS: 'false' }, { ALLOW_LOCAL_SNAPS: 'true' });
69+
70+
const overrides = config.getVariables(args, buildTypes);
71+
72+
// verify the value of the main build is set to the value in .metamaskprodrc
73+
assert.strictEqual(overrides.variables.get('ALLOW_LOCAL_SNAPS'), true);
74+
});
75+
76+
it('should prefer .metamaskrc variables over builds.yml', () => {
77+
const buildTypes = loadBuildTypesConfig();
78+
const { args } = parseArgv([], buildTypes);
79+
const defaultVars = config.getVariables(args, buildTypes);
80+
81+
// verify the default value of the main build is false
82+
assert.strictEqual(defaultVars.variables.get('ALLOW_LOCAL_SNAPS'), false);
83+
84+
mockRc({ ALLOW_LOCAL_SNAPS: 'true' });
6385

6486
const overrides = config.getVariables(args, buildTypes);
6587

@@ -68,10 +90,8 @@ ${Object.entries(env)
6890
});
6991

7092
it('should return valid build variables for a non-default build', () => {
71-
mockRc({
72-
// required by the `beta` build type
73-
SEGMENT_BETA_WRITE_KEY: '.',
74-
});
93+
// required by the `beta` build type
94+
mockRc({ SEGMENT_BETA_WRITE_KEY: '.' });
7595
const buildTypes = loadBuildTypesConfig();
7696
const { args } = parseArgv(
7797
['--type', 'beta', '--test', '--env', 'production'],

development/webpack/utils/config.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,16 @@ export function getVariables(
155155
}
156156

157157
/**
158-
* Loads configuration variables from process.env, .metamaskrc, and build.yml.
158+
* Loads configuration variables from process.env, .metamaskprodrc, .metamaskrc, and build.yml.
159159
*
160160
* The order of precedence is:
161161
* 1. process.env
162-
* 2. .metamaskrc
163-
* 3. build.yml
162+
* 2. .metamaskprodrc
163+
* 3. .metamaskrc
164+
* 4. builds.yml
164165
*
165166
* i.e., if a variable is defined in `process.env`, it will take precedence over
166-
* the same variable defined in `.metamaskrc` or `build.yml`.
167+
* the same variable defined in `.metamaskprodrc`, `.metamaskrc` or `build.yml`.
167168
*
168169
* @param activeBuild
169170
* @param build
@@ -175,6 +176,7 @@ function loadConfigVars(
175176
{ env }: BuildTypesConfig,
176177
) {
177178
const definitions = loadEnv();
179+
addRc(definitions, join(__dirname, '../../../.metamaskprodrc'));
178180
addRc(definitions, join(__dirname, '../../../.metamaskrc'));
179181
addVars(activeBuild.env);
180182
addVars(env);

development/webpack/utils/plugins/ManifestPlugin/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ export function transformManifest(
8282
}
8383
}
8484

85-
if (args.test && args.manifest_version === 2) {
86-
// test builds need "tabs" permission for switchToWindowWithTitle in MV2
85+
if (args.test) {
86+
// test builds need "tabs" permission for switchToWindowWithTitle
8787
transforms.push(addTabsPermission);
8888
}
8989

development/webpack/webpack.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const cache = args.cache
8181
// `buildDependencies`
8282
config: [
8383
__filename,
84+
join(context, '../.metamaskprodrc'),
8485
join(context, '../.metamaskrc'),
8586
join(context, '../builds.yml'),
8687
browsersListPath,

0 commit comments

Comments
 (0)