Microsoft/TypeScript

TypeScript 4.2 caches cwd between builds when using the programatic api

Open

#43.120 geöffnet am 6. März 2021

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
BugDomain: tsc -bHelp Wanted

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

Bug Report

When using TypeScript 4.2 from the programmatic API, it seems to cache the CWD between runs. I don't think this is the desired effect. This can result in "Cannot read file '..../tsconfig.json'"

🔎 Search Terms

cwd, current working directory

🕗 Version & Regression Information

  • This bug started in 4.2.2.
  • Earlier versions as far back as 3.7 work as expected.
  • Nightly typescript@next also has this problem.

⏯ Playground Link

Programmatic API, so no playground link available. I made a small repro repo: ts-cwd-issue.zip

Unzip, npm i and node compile.js.

💻 Code

// @ts-check
const ts = require('typescript');
const path = require('path');

async function build(tsconfig) {
    return new Promise(res => {
        const compiler = ts.createSolutionBuilderWithWatch(
            ts.createSolutionBuilderWithWatchHost(ts.sys,
                undefined,
                (error) => console.error(tsconfig,'error: ', error.messageText),
                (status) => console.log(tsconfig,'status:', status.messageText),
                (summary) => {
                    console.log(tsconfig, 'summary: ', summary.messageText);
                    res();
                }
            ),
            [tsconfig],
            {}
        );
        compiler.build();
    });
}

async function main() {
    process.chdir(path.resolve(__dirname, 'sample-a'));
    await build('tsconfig.a.json')
    process.chdir(path.resolve(__dirname, 'sample-b'));
    await build('tsconfig.b.json')
}

main().catch(console.error);

🙁 Actual behavior

$ node compile.js
tsconfig.a.json summary:  Found 0 errors. Watching for file changes.
tsconfig.b.json error:  Cannot read file '.../sample-a/tsconfig.b.json'.
tsconfig.b.json summary:  Found 1 error. Watching for file changes.

🙂 Expected behavior

$ node compile.js
tsconfig.a.json summary:  Found 0 errors. Watching for file changes.
tsconfig.b.json summary:  Found 0 errors. Watching for file changes.

Contributor Guide