MCPcopy
hub / github.com/electron/forge / proxify

Function proxify

packages/api/core/src/util/forge-config.ts:35–100  ·  view source on GitHub ↗
(
  buildIdentifier: string | (() => string),
  proxifiedObject: T,
  envPrefix: string,
)

Source from the content-addressed store, hash-verified

33}
34
35const proxify = <T extends ProxiedObject>(
36 buildIdentifier: string | (() => string),
37 proxifiedObject: T,
38 envPrefix: string,
39): T => {
40 let newObject: T = {} as any;
41 if (Array.isArray(proxifiedObject)) {
42 newObject = [] as any;
43 }
44
45 for (const [key, val] of Object.entries(proxifiedObject)) {
46 if (
47 typeof val === 'object' &&
48 (val.constructor === Object || val.constructor === Array) &&
49 key !== 'pluginInterface' &&
50 !(val instanceof RegExp)
51 ) {
52 (newObject as any)[key] = proxify(
53 buildIdentifier,
54 (proxifiedObject as any)[key],
55 `${envPrefix}_${underscoreCase(key)}`,
56 );
57 } else {
58 (newObject as any)[key] = (proxifiedObject as any)[key];
59 }
60 }
61
62 return new Proxy<T>(newObject, {
63 get(target, name, receiver) {
64 // eslint-disable-next-line no-prototype-builtins
65 if (!target.hasOwnProperty(name) && typeof name === 'string') {
66 const envValue = process.env[`${envPrefix}_${underscoreCase(name)}`];
67 if (envValue) return envValue;
68 }
69 const value = Reflect.get(target, name, receiver);
70
71 if (isBuildIdentifierConfig(value)) {
72 const identifier =
73 typeof buildIdentifier === 'function'
74 ? buildIdentifier()
75 : buildIdentifier;
76 return value.map[identifier];
77 }
78 return value;
79 },
80 getOwnPropertyDescriptor(target, name) {
81 const envValue =
82 process.env[`${envPrefix}_${underscoreCase(name as string)}`];
83 // eslint-disable-next-line no-prototype-builtins
84 if (target.hasOwnProperty(name)) {
85 return Reflect.getOwnPropertyDescriptor(target, name);
86 }
87
88 if (envValue) {
89 return {
90 writable: true,
91 enumerable: true,
92 configurable: true,

Callers 1

forge-config.tsFile · 0.85

Calls 1

underscoreCaseFunction · 0.85

Tested by

no test coverage detected