a tsconfig.json may have comments which are not parsable with JSON.parse (could use jsonc)
if (await fs.exists("tsconfig.json")) {
const tsConfigJson = JSON.parse(await Deno.readTextFile("tsconfig.json"))
assertManifest(tsConfigJson)
if (!/^(es|node)/i.test(tsConfigJson.compilerOptions?.module ?? "")) {
throw new Error(
`Cannot use Capi with 'compilerOptions.module: "${tsConfigJson?.compilerOptions?.module}"'. Set 'tsconfig.json' 'compilerOptions.module' to 'ES*' or 'Node*'"`,
)
}
if (!/^(node|bundler)/i.test(tsConfigJson?.compilerOptions?.moduleResolution ?? "")) {
throw new Error(
`Cannot use Capi with 'compilerOptions.module: "${tsConfigJson?.compilerOptions?.moduleResolution}"'. Set 'tsconfig.json' 'compilerOptions.moduleResolution' to 'node*' or 'bundler"`,
)
}
}
If a
tsconfig.json
is present,capi init
creates anets.ts
file. Theinit
subcommand should also check that thetsconfig.json
compilerOptions.module
isES*
orNode*
compilerOptions.moduleResolution
isnode*
orbundler
nets.ts
(see #1088)This is because the
nets.ts
is imported throughesm/main.js
withnode --loader ts-node/esm
https://github.com/paritytech/capi/blob/950ddd1330c6abf00e9f8198c82309d0309a4357/_tasks/dnt.ts#L142-L147
The following check is naive because
tsconfig.json
may extend from another configtsconfig.json
may have comments which are not parsable withJSON.parse
(could use jsonc)