@dudousxd/nestjs-codegen 0.21.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,95 @@
1
1
  # @dudousxd/nestjs-codegen
2
2
 
3
+ ## 0.22.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4af626a: Hand extensions the tsconfig-seeded Project instead of making each build its own
8
+
9
+ `ExtensionContext` gains `tsconfigProject()`: a lazily-created, memoized ts-morph
10
+ `Project` built from the consumer's tsconfig (`app.tsconfig`, else
11
+ `<cwd>/tsconfig.json`), so `paths` aliases resolve. `project()` is unchanged — it
12
+ stays the bare, paths-less scratch project — and the two are now documented against
13
+ each other.
14
+
15
+ An extension that needs to follow a `@/api/...` import from a controller to the
16
+ decorator target it reads had no way to get one, so it built its own from
17
+ `tsConfigFilePath`. That has a trap: parsing a tsconfig also resolves its FILE LIST,
18
+ and a tsconfig with no `include` walks the entire project root, so one unreadable
19
+ directory (a docker bind mount a container chowned to its own UID) throws
20
+ `EACCES ... scandir`. Every hand-rolled copy then fell back to a paths-less Project
21
+ in silence, and aliased targets resolved to nothing with no error anywhere — the
22
+ same bug, once per extension. The host now loads it correctly, once, and hands it
23
+ out; N extensions share one parse instead of one each.
24
+
25
+ Typed as optional (`tsconfigProject?()`) on purpose: an extension may run against an
26
+ older host that does not provide it, so the ecosystem pattern is
27
+ `ctx.tsconfigProject?.() ?? <own fallback>`.
28
+
29
+ ## 0.21.1
30
+
31
+ ### Patch Changes
32
+
33
+ - da3c66c: Load the consumer tsconfig without walking their file tree, and stop falling back from it in silence
34
+
35
+ `createDiscoveryProject` handed `tsConfigFilePath` to ts-morph and wrapped the
36
+ call in a bare `try/catch` that, on ANY error, rebuilt the `Project` with no
37
+ tsconfig at all. Both halves of that were a problem.
38
+
39
+ Parsing a tsconfig also resolves its FILE LIST, and a tsconfig with no `include`
40
+ defaults to `**/*` — so TypeScript walks every directory under the project root.
41
+ One directory the codegen process cannot read is enough to throw
42
+ `EACCES: permission denied, scandir ...` and take the whole tsconfig down with
43
+ it; a docker bind mount that a container has chowned to its own UID with
44
+ mode-700 subdirs (Grafana, Prometheus, MinIO, a DB data dir) is exactly that
45
+ shape. `skipAddingFilesFromTsConfig` did not help, because it discards the file
46
+ list only after it has been computed.
47
+
48
+ Discovery never wanted that list — only `paths`/`baseUrl`/`target`/decorator
49
+ flags — so the tsconfig is now read through `ts.readConfigFile` +
50
+ `ts.parseJsonConfigFileContent` with a host whose `readDirectory` returns
51
+ nothing, and the parsed options are passed to `new Project({ compilerOptions })`.
52
+ No directory is read, so no unreadable one can matter. `extends` still resolves,
53
+ and passing the parsed options through wholesale preserves TypeScript's
54
+ `pathsBasePath` (how `paths` resolves when the tsconfig sets no `baseUrl`).
55
+
56
+ The silent fallback is what made this expensive to diagnose. A `Project` with no
57
+ tsconfig has no `paths`, and go-to-definition is how a factory-based controller
58
+ (`class X extends createTableController(...)`) is resolved — so an
59
+ alias-imported factory stops resolving and every route those controllers
60
+ contribute disappears from the generated client. The only output was the
61
+ per-controller `contributes NO routes` warning, which blames the controller. A
62
+ tsconfig that exists but cannot be loaded now warns once, naming the tsconfig,
63
+ the underlying error and what it costs. A MISSING tsconfig stays silent: relative
64
+ imports need no `paths`, so a tsconfig-less consumer is a supported setup.
65
+
66
+ Measured against a real consumer with one unreadable directory in its root:
67
+ 313 routes and 0 factory-derived routes with 22 `contributes NO routes`
68
+ warnings, versus 357 routes and 44 factory-derived routes with none.
69
+
70
+ Also folds the tsconfig into the generate manifest's input hash. The freshness
71
+ check ("up to date, skipped") did not cover it, so a tsconfig that made discovery
72
+ generate a WRONG artifact left that artifact on disk after the tsconfig was
73
+ fixed, and every later run skipped over it — the only way out was deleting
74
+ `.codegen-manifest.json` by hand. Raw contents are hashed rather than the
75
+ resolved options, because `include`/`exclude` are not compiler options and an
76
+ added `exclude` is exactly what such a fix tends to be. The whole `extends` chain
77
+ is hashed, not just the entry file, since that is where a shared `paths` block
78
+ usually lives.
79
+
80
+ Two things follow from loading the tsconfig properly, both previously wrong in the
81
+ same direction — an alias that silently resolved to nothing:
82
+
83
+ - `paths` now come from that single load, so a mapping declared in a tsconfig
84
+ reached through `extends` is finally seen. The old reader parsed the entry
85
+ file's raw JSON itself, so it saw neither `extends` nor block comments, and it
86
+ could disagree with the options the `Project` was built from.
87
+ - Those mappings resolve the way `tsc` resolves them — against `baseUrl` when
88
+ set, else against the directory of the file that DECLARED them (TypeScript's
89
+ `pathsBasePath`). They were resolved against the project root, which is not the
90
+ same directory for a `paths` block inherited from `config/base.json`, or for a
91
+ `baseUrl` of `./src`.
92
+
3
93
  ## 0.21.0
4
94
 
5
95
  ### Minor Changes