()
| 9 | const packageJson = getPackageJson(); |
| 10 | |
| 11 | export 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. |
no test coverage detected