Skip to content

Commit 60dae19

Browse files
committed
fix: ignorelist format
1 parent c462b80 commit 60dae19

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ export const getConfig = () => {
66
const submitMnemonic: string | undefined = process.env.SUBMIT_MNEMONIC;
77
const blockchainStateSetup =
88
process.env.BLOCKCHAIN_STATE_SETUP === 'true' || process.env.BLOCKCHAIN_STATE_SETUP === '1';
9-
const ignorelistPath: string | undefined = process.env.IGNORELIST_PATH;
109
const ignorelistOnly =
1110
process.env.IGNORELIST_ONLY === 'true' || process.env.IGNORELIST_ONLY === '1';
1211

12+
if (!network) {
13+
throw new Error(`NETWORK env is not set.`);
14+
}
15+
1316
return {
1417
projectId,
1518
serverUrl,
1619
network,
1720
environment,
1821
submitMnemonic,
1922
blockchainStateSetup,
20-
ignorelistPath,
2123
ignorelistOnly,
2224
};
2325
};

src/index.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,35 @@ const loadIgnorelist = (filePath: string): IgnoreRule[] => {
6060
return [];
6161
}
6262

63+
const network = envConfig.network;
64+
6365
try {
6466
const rawData = fs.readFileSync(filePath, 'utf8');
65-
6667
const parsed: unknown = JSON.parse(rawData);
6768

68-
if (!Array.isArray(parsed)) {
69-
throw new Error(`Expected ${path.basename(filePath)} to contain a JSON array.`);
69+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
70+
throw new Error(`Expected ${path.basename(filePath)} to be a JSON object keyed by network.`);
71+
}
72+
73+
const entries = (parsed as Record<string, IgnoreRule[]>)[network];
74+
75+
if (!entries) {
76+
return [];
77+
}
78+
79+
if (!Array.isArray(entries)) {
80+
throw new Error(`Expected ${path.basename(filePath)}["${network}"] to be an array.`);
7081
}
7182

72-
return parsed as IgnoreRule[];
83+
return entries;
7384
} catch (parseError: unknown) {
7485
const message = parseError instanceof Error ? parseError.message : String(parseError);
7586

7687
throw new Error(`${path.basename(filePath)} is not a valid json: ${message}`);
7788
}
7889
};
7990

80-
// IGNORELIST_PATH env takes precedence over the default file in root
81-
const ignorelist = loadIgnorelist(envConfig.ignorelistPath ?? ignorelistFilePath);
91+
const ignorelist = loadIgnorelist(ignorelistFilePath);
8292

8393
export const isUrlMatch = (urlParameter: string, allowlistPattern: string) => {
8494
try {

0 commit comments

Comments
 (0)