paritytech / capi

[WIP] A framework for crafting interactions with Substrate chains
https://docs.capi.dev
Apache License 2.0
105 stars 10 forks source link

`capi init` `tsconfig.json` improvements #1064

Open kratico opened 1 year ago

kratico commented 1 year ago

If a tsconfig.json is present, capi init creates a nets.ts file. The init subcommand should also check that the tsconfig.json

This is because the nets.ts is imported through esm/main.js with node --loader ts-node/esm

https://github.com/paritytech/capi/blob/950ddd1330c6abf00e9f8198c82309d0309a4357/_tasks/dnt.ts#L142-L147

The following check is naive because


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"`,
      )
    }
  }
ryanleecode commented 1 year ago

it cant be node has to be at least nodenext i think because node is still commonjs