Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsconfig's rootDirs overridden by synthesized rootDir in compiler.ts #679

Open
joeyparrish opened this issue Feb 2, 2023 · 3 comments · May be fixed by #680
Open

tsconfig's rootDirs overridden by synthesized rootDir in compiler.ts #679

joeyparrish opened this issue Feb 2, 2023 · 3 comments · May be fixed by #680

Comments

@joeyparrish
Copy link

Expected behavior:
If I use rootDirs (plural) and not rootDir (singular) in tsconfig.json, only rootDirs should be passed to the compiler.

Actual behavior:
compiler.ts synthesizes a value for rootDir, which is then passed to the compiler. This overrides rootDirs and causes my project to fail with gulp-typescript, even though it builds with tsc.

Your gulpfile:

Include your gulpfile, or only the related task (with ts.createProject).

import gulp from 'gulp';
import ts from 'gulp-typescript';

const mainProject = ts.createProject('tsconfig.json');

function buildTypeScriptProject(project) {
  const projectSources = project.src();
  const projectBuilder = project();
  const outDir = project.options.outDir;
  const buildResults = projectSources.pipe(projectBuilder);
  return buildResults.js.pipe(gulp.dest(outDir));
}

// Omitting the rather complicated generate-sources task...

gulp.task('build', gulp.series('generate-sources', () => {
  return buildTypeScriptProject(mainProject);
}));

tsconfig.json

Include your tsconfig, if related to this issue.

{
  // Use these TypeScript settings as defaults:
  "extends": "./tsconfig-base.json",

  "compilerOptions": {
    // output JS to dist/
    "outDir": "dist",

    // Some generated modules should be found in generated/ as well.
    // Treat src/ and generated/ as equivalent during module resolution.
    "rootDirs": ["src/", "generated/"],
  },
  "include": [
    "src/**/*.ts",
  ],
}

Code

Include your TypeScript code, if necessary.
Not strictly necessary, given:

I have a simple fix in mind that works for me locally. In compiler.ts, rootDir is created on this.project.options, when it should instead be created on this. It should fall back through options.rootDir, options.rootDirs[0], and then finally the computed version that exists today. With this change made locally, everything works correctly. Either rootDir or rootDirs[0] can be used to determine the locations of things, but the config from tsconfig.json won't be modified inappropriately before being passed to the compiler.

I will send a PR shortly.

@joeyparrish
Copy link
Author

This fails with TypeScript 4.9.4, but doesn't fail with the 3.6 or 3.7 versions that you test with in gulp-typescript.

@joeyparrish
Copy link
Author

It looks like you haven't updated typescript/dev in 3 years, but a regression test for this will not be effective without testing against TypeScript v4.

@joeyparrish
Copy link
Author

The minimum version I can find that fails in this case is v4.3.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant