microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.91k stars 12.47k forks source link

Hier. "tsc -b -w" build - Allow option for change in dependency ".t.ds" file to trigger recheck/rebuild in depender #48021

Closed craigphicks closed 2 years ago

craigphicks commented 2 years ago

Hier. "tsc -b -w" build - Allow option for change in dependency ".t.ds" file to trigger recheck/rebuild in depender

🔍 Search Terms

hierarchical dependencies watch build dependencies

List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.

✅ Viability Checklist

My suggestion meets these guidelines:

⭐ Suggestion

In a hierarchical "tsc -b -w" build, allow option for change in dependency ".t.ds" file to trigger recheck/rebuild in depender.

📃 Motivating Example

Example 1

xyz-a/hello.ts

export function hello(){
  console.log("hello world");
}

xyz-a/index.ts

export {hello} from "./hello"

xyz-b/call.ts

import {hello} from "xyz-a"
hello();

Top level configuration tsconfig.json

{
  "references": [
    {
      "path": "xyz-a/tsconfig.ref.json"
    },
    {
      "path": "xyz-b/tsconfig.ref.json"
    }
  ]
}

tsconfig.options.json

{
  "compilerOptions": {
    "target": "es2016",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
    "module": "commonjs",                                /* Specify what module code is generated. */
    "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
    "forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. */
    "strict": true,                                      /* Enable all strict type-checking options. */
    "skipLibCheck": false,
    "declaration": true,
    "baseUrl": "./",
    "paths":{
      "xyz-a":["xyz-a"],
    }
  },
  "watchOptions": {
    "excludeDirectories": ["**/node_modules"]
  }
}

Suppose xyz-a/src/index.ts is changed to xyz-a/index.ts

export {hello as foobar} from "./hello"

Currently with a top level

npx tsc -b -w

that will cause xzy-a to be rebuilt but the change in xyz-a/dist/src/index.d.ts does not trigger an rebuild/recheck of xyz-b

Example 2

Similar initial situation as Example 1 but suppose a separate build step from a non-Typescript tool, in a manner opaque to Typescript, creates an output from xyz-a to serve as an input to xyz-b.
Any solution ought to work for this case too. (Two birds one stone.) Therefore "pushing" xyz-a's change to xyz-b without a file watch would probably not be a good solution.

(Above example as a working project available on demand.)

💻 Use Cases

Currently these changes aren't propagated and requires a forced rebuild to detect any errors resulting from the change.

RyanCavanaugh commented 2 years ago

This just sounds like a bug. Can you provide a sample repo? There are some necessary files not listed here.

craigphicks commented 2 years ago

My mistake.