Giter Club home page Giter Club logo

Comments (9)

TimUnderhay avatar TimUnderhay commented on April 30, 2024

This very much appears to be a references bug. If one comments out references in the server tsconfig.json, the issue goes away, and all expected files are compiled, but obviously the benefits of references are then negated.

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "baseUrl": "./src",
    "rootDir": "..",
    "lib": ["ES2022"],
    "outDir": "./dist",
    "paths": {
      ":shared/*": [
        "../../shared/src/*"
      ]
    },
    "types": [
      "node"
    ]
  },
  "include": [
    "src/**/*.ts",
    "../shared/src/**/*.ts"
  ],
  // "references": [
  //   {
  //     "path": "../shared"
  //   }
  // ]
}

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on April 30, 2024

This is exactly what project references is for - treating another config's files as "not part of your project" and thus not built. If the non-reference behavior is the behavior you want, then simply remove the reference.

from typescript.

TimUnderhay avatar TimUnderhay commented on April 30, 2024

@RyanCavanaugh the documentation at https://www.typescriptlang.org/docs/handbook/project-references.html says:

“Build mode (see below) will automatically build the referenced project if needed

By separating into multiple projects, you can greatly improve the speed of typechecking and compiling, reduce memory usage when using an editor, and improve enforcement of the logical groupings of your program.“

“Additionally, to preserve compatibility with existing build workflows, tsc will not automatically build dependencies unless invoked with the --build switch”

“Running tsc --build (tsc -b for short) will do the following:

Find all referenced projects
Detect if they are up-to-date
Build out-of-date projects in the correct order”

This all seems to suggest that building is very much an expected part of references. Why would it build some files but not others?

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on April 30, 2024

The expected setup for project references is that each input file corresponds to exactly one output file

from typescript.

TimUnderhay avatar TimUnderhay commented on April 30, 2024

Respectfully, I don’t think that jives with what I pasted from the documentation. It also doesn’t answer the question of why it sometimes builds shared files but other times it doesn’t.

What then is the point of references if it doesn’t actually build the references? Everything written seems to point to references as building referenced projects, but it seems you’re saying that isn’t the case.

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on April 30, 2024

I don't know what to tell you; this feature is widely adopted, has worked this way since it shipped six years ago, and you're the first person to raise this scenario or interpret the docs that way. The scenario where the same input file ends up as multiple output files isn't supported, and having the same input file not appear in multiple outputs was a motivating scenario for why references were added in the first place.

from typescript.

TimUnderhay avatar TimUnderhay commented on April 30, 2024

I think you’ve misunderstood what I’ve written. I’m saying that files specifically included in compilation by virtue of the includes field aren’t being compiled. I’m not saying that a single input file should produce multiple output files.

Help me to understand.

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on April 30, 2024

Sure.

shared builds shared/src/errors.ts to shared/dist/src/errors.js. The is the first output

server also includes this file, but it's recognized as an input of another project, so it's not built. This would have been the second output of shared/src/errors.ts

This is on purpose; tsc --explainFiles talks about it:

../shared/dist/src/global-type-overrides.d.ts
  Imported via ':shared/global-type-overrides.js' from file 'src/server.ts'
  Matched by include pattern '../shared/src/**/*.ts' in 'tsconfig.json'
  File is output of project reference source '../shared/src/global-type-overrides.ts'
  File is ECMAScript module because '../shared/package.json' has field "type" with value "module"
../shared/dist/src/errors.d.ts
  Imported via ':shared/errors.js' from file 'src/server.ts'
  Matched by include pattern '../shared/src/**/*.ts' in 'tsconfig.json'
  File is output of project reference source '../shared/src/errors.ts'
  File is ECMAScript module because '../shared/package.json' has field "type" with value "module"
src/server.ts
  Matched by include pattern 'src/**/*.ts' in 'tsconfig.json'
  File is ECMAScript module because 'package.json' has field "type" with value "module"
../shared/src/logging.ts
  Matched by include pattern '../shared/src/**/*.ts' in 'tsconfig.json'
  File is ECMAScript module because '../shared/package.json' has field "type" with value "module"

There actually is a bug here, which is that logging.ts should have been identified as an output of the referenced project, but wasn't. The emit of server/dist/shared/src/logging.js is a bug; it shouldn't have been produced

from typescript.

TimUnderhay avatar TimUnderhay commented on April 30, 2024

Thank you for helping me understand, @RyanCavanaugh.

from typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.