Skip to content

Commit b18e330

Browse files
committed
reverted lazy load changes
1 parent cef3f50 commit b18e330

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

packages/contentstack-utilities/src/config-handler.ts

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,12 @@ class Config {
2727
private isPrepackMode: boolean;
2828

2929
constructor() {
30-
this.isPrepackMode = this.detectPrepackMode();
30+
this.isPrepackMode = process.env.NODE_ENV === 'PREPACK_MODE';
3131
this.init();
3232
if (!this.isPrepackMode) {
3333
this.importOldConfig();
3434
}
3535
}
36-
37-
private detectPrepackMode(): boolean {
38-
return !!(
39-
process.env.npm_package_name ||
40-
process.env.npm_lifecycle_event === 'prepack' ||
41-
process.argv.some(arg => arg.includes('oclif') && arg.includes('manifest'))
42-
);
43-
}
4436

4537
init() {
4638
// Skip file-based config during prepack to prevent race conditions
@@ -255,4 +247,42 @@ class Config {
255247
}
256248
}
257249

258-
export default new Config();
250+
let configInstance: Config | null = null;
251+
252+
function createConfigInstance(): Config {
253+
return new Config();
254+
}
255+
256+
function getConfigInstance(): Config {
257+
if (!configInstance) {
258+
configInstance = createConfigInstance();
259+
}
260+
return configInstance;
261+
}
262+
263+
// Sinon based lazy config object
264+
const lazyConfig = {
265+
// false positive - no hardcoded secret here
266+
// @ts-ignore-next-line secret-detection
267+
get(key: string) {
268+
return getConfigInstance().get(key);
269+
},
270+
271+
// false positive - no hardcoded secret here
272+
// @ts-ignore-next-line secret-detection
273+
set(key: string, value: any) {
274+
return getConfigInstance().set(key, value);
275+
},
276+
277+
// false positive - no hardcoded secret here
278+
// @ts-ignore-next-line secret-detection
279+
delete(key: string) {
280+
return getConfigInstance().delete(key);
281+
},
282+
283+
clear() {
284+
return getConfigInstance().clear();
285+
},
286+
};
287+
288+
export default lazyConfig;

0 commit comments

Comments
 (0)