mirror of
https://github.com/affaan-m/ECC.git
synced 2026-10-26 18:35:05 +00:00
Merge pull request #3594 from ketpatil77/fix/managed-hook-config-bom
fix(hooks): honor managed preferences in BOM-prefixed config
This commit is contained in:
2 files changed
+17
-1
No files matched your search
@@ -48,7 +48,7 @@ function readManagedHookConfig(env = process.env) {
|
||||
if (!configPath || !fs.existsSync(configPath)) return {};
|
||||
|
||||
try {
|
||||
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
||||
const config = JSON.parse(fs.readFileSync(configPath, 'utf8').replace(/^\uFEFF/, ''));
|
||||
return config?.hooks
|
||||
&& typeof config.hooks === 'object'
|
||||
&& !Array.isArray(config.hooks)
|
||||
|
||||
@@ -162,6 +162,22 @@ function runTests() {
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('managed hook config accepts a leading UTF-8 BOM', () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-hook-flags-bom-'));
|
||||
const configPath = path.join(root, 'setup.json');
|
||||
const env = { ECC_HOOK_CONFIG: configPath };
|
||||
try {
|
||||
fs.writeFileSync(configPath, '\uFEFF' + JSON.stringify({
|
||||
hooks: { enabled: false, profile: 'minimal', note: 'keep\uFEFFinside' },
|
||||
}));
|
||||
assert.strictEqual(areHooksEnabled(env), false);
|
||||
assert.strictEqual(getHookProfile(env), 'minimal');
|
||||
assert.strictEqual(readManagedHookConfig(env).note, 'keep\uFEFFinside');
|
||||
} finally {
|
||||
fs.rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('a hook evaluation reads managed config only once', () => {
|
||||
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-hook-flags-read-once-'));
|
||||
const configPath = path.join(root, 'setup.json');
|
||||
|
||||
Reference in new issue
Block a user