aspect-build / rules_ts

Bazel rules for the `tsc` compiler from http://typescriptlang.org
https://docs.aspect.build/rules/aspect_rules_ts
Apache License 2.0
94 stars 53 forks source link

[Bug]: options_validator rejects module: "preserve" #604

Closed Zemnmez closed 1 month ago

Zemnmez commented 2 months ago

What happened?

In typescript 5.4, module preserve was added to better reflect code which a bundler would later compile.

I needed it to fix this grpc bug: https://github.com/grpc/grpc-node/issues/2617

Unfortunately, with rules_ts it fails options_validator:

INFO: From TsValidateOptions ts/pulumi/shadwell.im/luke/next_next_config_typings.optionsvalid.d.ts:
  /tmp/bazel-working-directory/_main/bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/aspect_rules_ts~~ext~npm_typescript/validator.sh.runfiles/aspect_rules_ts~~ext~npm_typescript/ts_project_options_validator.js Error: tsconfig.json:error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'es2022', 'esnext', 'node16', 'nodenext'.

      at main (/tmp/bazel-working-directory/_main/bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/aspect_rules_ts~~ext~npm_typescript/validator.sh.runfiles/aspect_rules_ts~~ext~npm_typescript/ts_project_options_validator.js:52:15)
      at Object.<anonymous> (/tmp/bazel-working-directory/_main/bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/aspect_rules_ts~~ext~npm_typescript/validator.sh.runfiles/aspect_rules_ts~~ext~npm_typescript/ts_project_options_validator.js:227:28)
      at Module._compile (node:internal/modules/cjs/loader:1364:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
      at Module.load (node:internal/modules/cjs/loader:1203:32)
      at Module._load (node:internal/modules/cjs/loader:1019:12)
      at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
      at node:internal/main/run_main_module:28:49

Version

Development (host) and target OS/architectures:

Output of bazel --version:

bazel 7.1.1

Version of the Aspect rules, or other relevant rules from your WORKSPACE or MODULE.bazel file:

bazel_dep(name = "aspect_rules_ts", version = "2.2.0")

Language(s) and/or frameworks involved:

typescript

How to reproduce

Minimal commit:

https://github.com/zemn-me/monorepo/blob/4065efa728b4452275e63581cb28b62f93d09899/tsconfig.json

Any other information?

No response

Zemnmez commented 1 month ago

I actually think this might be a bug in upstream parseJsonConfigFileContent parseJsonConfigFileContent

https://github.com/microsoft/TypeScript/blob/506f3e26c3c8af7e4de38996656c947050e68567/src/compiler/commandLineParser.ts#L2877

Zemnmez commented 1 month ago

OK I tried this on actual tsc and it doesn't reject. looks like maybe somehow parseJsonConfigFileContent is using an older version of the typescript API

Zemnmez commented 1 month ago

Appears to be because npm_typescript is out of date:

thomas@DESKTOP-B82ERE8:~/monorepo/VERSION$ bazel run @npm_typescript//:tsc -- --version
INFO: Invocation ID: c7296e97-7565-4cf0-91d7-f10287e12f57
INFO: Analyzed target @@aspect_rules_ts~~ext~npm_typescript//:tsc (180 packages loaded, 5124 targets configured).
WARNING: /home/thomas/.cache/bazel/_bazel_thomas/19a58029a3d1c17a94df635d4e2b032e/external/aspect_rules_ts~~ext~npm_typescript/BUILD.bazel:32:17: input 'package' to @@aspect_rules_ts~~ext~npm_typescript//:.aspect_rules_js/node_modules/typescript is a directory; dependency checking of directories is unsound
INFO: Found 1 target...
Target @@aspect_rules_ts~~ext~npm_typescript//:tsc up-to-date:
  dist/bin/external/aspect_rules_ts~~ext~npm_typescript/tsc.sh
INFO: Elapsed time: 1.406s, Critical Path: 0.29s
INFO: 8 processes: 7 internal, 1 local.
INFO: Build completed successfully, 8 total actions
INFO: Running command line: dist/bin/external/aspect_rules_ts~~ext~npm_typescript/tsc.sh --version
Version 5.3.3

Is it possible that options_validator could use the workspace's local version?

Zemnmez commented 1 month ago

Found the issue! I moved to MODULE.bazel and did not use ts_version_from = "//:package.json", (it's not currently in the release docs) and as a result there had been drift between the typescript versions in my repo and that used by aspect_rules_ts