Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Resolve tsconfig from current working dir #29

@itsMapleLeaf

Description

@itsMapleLeaf

According to the esbuild docs here, the transform API doesn't read from the filesystem, and doesn't resolve the tsconfig. I'm using MobX, and I need to define useDefineForClassFields in tsconfig for it to work correctly, but esbuild node loader doesn't pick it up.

The fix here would be to resolve it and pass it as tsconfigRaw:

  const {
    code: js,
    warnings,
    map: jsSourceMap,
  } = transformSync(rawSource.toString(), {
    sourcefile: filename,
    sourcemap: 'both',
    loader: new URL(url).pathname.match(extensionsRegex)[1],
    target: `node${process.versions.node}`,
    format: format === 'module' ? 'esm' : 'cjs',
+   tsconfigRaw: resolveTsConfig(),
  })
function resolveTsConfig(fromDir = process.cwd()) {
  const tsconfigPath = join(fromDir, 'tsconfig.json')
  if (fs.existsSync(tsconfigPath)) {
    return fs.readFileSync(tsconfigPath, 'utf8')
  }

  const parentDir = dirname(fromDir)
  if (parentDir === fromDir) return undefined

  return resolveTsConfig(parentDir)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions