MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / nsConfigToJson

Function nsConfigToJson

packages/vite/helpers/utils.ts:11–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9const packageJson = getPackageJson();
10
11export function nsConfigToJson() {
12 let configObject: Record<string, any>;
13 const tsPath = getProjectFilePath('nativescript.config.ts');
14 const tsCode = fs.readFileSync(tsPath, 'utf-8');
15
16 // a) Transpile your TS config to CommonJS so we can require() it
17 const { code: cjsCode } = transformSync(tsCode, {
18 loader: 'ts',
19 format: 'cjs',
20 target: 'esnext',
21 });
22
23 // b) Evaluate it in a VM-style sandbox to pull out the default export
24 const module = { exports: {} as any };
25 const requireFunc = (id: string) => require(id);
26 new Function('exports', 'require', 'module', '__filename', '__dirname', cjsCode)(module.exports, requireFunc, module, tsPath, path.dirname(tsPath));
27 configObject = module.exports.default ?? module.exports;
28 // ensure the config has a name
29 configObject.name = packageJson.name;
30 // ensure the main entry is set to "bundle"
31 configObject.main = 'bundle';
32 return configObject;
33}
34
35/**
36 * Resolves the NativeScript platform-specific file for a given module ID.

Callers 3

loadFunction · 0.85
loadFunction · 0.85
computeProjectAppPathFunction · 0.85

Calls 1

getProjectFilePathFunction · 0.70

Tested by

no test coverage detected