Skip to content

Commit

Permalink
fix(typescript): exclude package(-lock).json from default ts_project …
Browse files Browse the repository at this point in the history
…srcs

Without this, an NPM project receives errors such as:

```
output 'package-lock.json' was not created
output 'package.json' was not created
```

This seems like a very common case that should be covered.
  • Loading branch information
edsrzf authored and alexeagle committed Sep 17, 2021
1 parent b43c594 commit 0245b6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions docs/TypeScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ Defaults to `"tsconfig"`
Label of the tsconfig.json file to use for the compilation

To support "chaining" of more than one extended config, this label could be a target that
provdes `TsConfigInfo` such as `ts_config`.
provides `TsConfigInfo` such as `ts_config`.

By default, we assume the tsconfig file is "tsconfig.json" in the same folder as the ts_project rule.

Expand Down Expand Up @@ -636,7 +636,10 @@ Defaults to `None`

List of labels of TypeScript source files to be provided to the compiler.

If absent, defaults to `**/*.ts[x]` (all TypeScript files in the package).
If absent, the default is set as follows:
- Include `**/*.ts[x]` (all TypeScript files in the package).
- If `allow_js` is set, include `**/*.js[x]` (all JavaScript files in the package).
- If `resolve_json_module` is set, include `**/*.json` (all JSON files in the package), but exclude `**/package.json`, `**/package-lock.json`, and `**/tsconfig*.json`.

Defaults to `None`

Expand Down
11 changes: 7 additions & 4 deletions packages/typescript/internal/ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,17 @@ def ts_project_macro(
srcs: List of labels of TypeScript source files to be provided to the compiler.
If absent, defaults to `**/*.ts[x]` (all TypeScript files in the package).
If absent, the default is set as follows:
- Include `**/*.ts[x]` (all TypeScript files in the package).
- If `allow_js` is set, include `**/*.js[x]` (all JavaScript files in the package).
- If `resolve_json_module` is set, include `**/*.json` (all JSON files in the package), but exclude `**/package.json`, `**/package-lock.json`, and `**/tsconfig*.json`.
deps: List of labels of other rules that produce TypeScript typings (.d.ts files)
tsconfig: Label of the tsconfig.json file to use for the compilation
To support "chaining" of more than one extended config, this label could be a target that
provdes `TsConfigInfo` such as `ts_config`.
provides `TsConfigInfo` such as `ts_config`.
By default, we assume the tsconfig file is "tsconfig.json" in the same folder as the ts_project rule.
Expand Down Expand Up @@ -618,10 +621,10 @@ def ts_project_macro(
include = ["**/*.ts", "**/*.tsx"]
exclude = []
if allow_js == True:
include.append("**/*.js", "**/*.jsx")
include.extend(["**/*.js", "**/*.jsx"])
if resolve_json_module == True:
include.append("**/*.json")
exclude.append("**/tsconfig*.json")
exclude.extend(["**/package.json", "**/package-lock.json", "**/tsconfig*.json"])
srcs = native.glob(include, exclude)
extra_deps = []

Expand Down

0 comments on commit 0245b6d

Please sign in to comment.