-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(builtin): fix regression in 1.6.0 in linker linking root package when under runfiles #1854
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin") | ||
load("@npm_bazel_typescript//:index.bzl", "ts_library") | ||
load(":ts_jest_test.bzl", "ts_jest_test") | ||
|
||
ts_library( | ||
name = "lib", | ||
srcs = [ | ||
"lib.ts", | ||
], | ||
deps = [ | ||
], | ||
) | ||
|
||
# Shenanigans for Windows which doesn't have runfiles symlinks | ||
# We need the jest config to be in the output tree where the specs are | ||
copy_to_bin( | ||
name = "jest_config", | ||
srcs = ["jest.config.js"], | ||
) | ||
|
||
ts_jest_test( | ||
name = "test", | ||
srcs = [ | ||
"lib.test.ts", | ||
], | ||
jest_config = ":jest_config", | ||
deps = [ | ||
":lib", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {doStuff} from './lib'; | ||
|
||
describe('doStuff', () => { | ||
it('should do some stuff', () => { | ||
expect(doStuff('boom')).toContain('boom'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function doStuff(a: string): string { | ||
return a | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Simple macro around jest_test""" | ||
|
||
load("@npm//jest-cli:index.bzl", _jest_test = "jest_test") | ||
load("@npm_bazel_typescript//:index.bzl", "ts_library") | ||
|
||
def ts_jest_test(name, srcs, jest_config, deps = [], data = [], **kwargs): | ||
"""A macro around the autogenerated jest_test rule that takes typescript sources | ||
|
||
Uses ts_library devmode UMD output""" | ||
|
||
ts_library( | ||
name = "%s_ts" % name, | ||
srcs = srcs, | ||
data = data, | ||
deps = deps + ["@npm//@types/jest"], | ||
) | ||
native.filegroup( | ||
name = "%s_umd" % name, | ||
srcs = [":%s_ts" % name], | ||
output_group = "es5_sources", | ||
) | ||
|
||
args = [ | ||
"--no-cache", | ||
"--no-watchman", | ||
"--ci", | ||
] | ||
args.extend(["--config", "$$(rlocation $(rootpath %s))" % jest_config]) | ||
|
||
_jest_test( | ||
name = name, | ||
data = [jest_config, ":%s_umd" % name] + deps + data, | ||
templated_args = args, | ||
**kwargs | ||
) |
12 changes: 12 additions & 0 deletions
12
internal/linker/test/issue_1823_use_ts_library_esm/.babelrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": "current", | ||
}, | ||
}, | ||
], | ||
] | ||
} |
50 changes: 50 additions & 0 deletions
50
internal/linker/test/issue_1823_use_ts_library_esm/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin") | ||
load("@npm_bazel_typescript//:index.bzl", "ts_library") | ||
load(":ts_jest_test.bzl", "ts_jest_test") | ||
|
||
ts_library( | ||
name = "lib", | ||
srcs = [ | ||
"lib.ts", | ||
], | ||
# NB: hacky hidden configuration setting so that es6_sources does not include tsickle | ||
# .externs.js outputs | ||
runtime = "nodejs", | ||
deps = [ | ||
"@npm//@types/node", | ||
], | ||
) | ||
|
||
# Shenanigans for Windows which doesn't have runfiles symlinks | ||
# We need the jest config to be in the output tree where the specs are | ||
copy_to_bin( | ||
name = "jest_config", | ||
srcs = [ | ||
"jest.config.js", | ||
], | ||
) | ||
|
||
# Same goes for babelrc. We can't add it to the jest_config copy_to_bin | ||
# since must be a file that is passed to jest in the --config arg. | ||
copy_to_bin( | ||
name = "babel_rc", | ||
srcs = [ | ||
".babelrc", | ||
], | ||
) | ||
|
||
ts_jest_test( | ||
name = "test", | ||
srcs = [ | ||
"lib.test.ts", | ||
], | ||
data = [ | ||
":babel_rc", | ||
], | ||
jest_config = ":jest_config", | ||
deps = [ | ||
":lib", | ||
"@npm//@babel/preset-env", | ||
"@npm//babel-jest", | ||
], | ||
) |
18 changes: 18 additions & 0 deletions
18
internal/linker/test/issue_1823_use_ts_library_esm/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const isWindows = process.platform === 'win32'; | ||
|
||
module.exports = { | ||
testEnvironment: 'node', | ||
transform: {'^.+\\.mjs?$': 'babel-jest'}, | ||
// More Shenanigans for Windows where jest is running both the original .mjs & the babel | ||
// transformed .js and fails. Not sure what why this is the case or exactly why changing | ||
// testMatch solves it but not a priority to solve: | ||
// ``` | ||
// PASS ../../lib.test.js | ||
// FAIL ../../lib.test.mjs | ||
// C:\b\swkzcapm\execroot\build_bazel_rules_nodejs\bazel-out\x64_windows-fastbuild\bin\internal\linker\test\issue_1823_use_ts_library_esm\lib.test.mjs:1 | ||
// import { doStuff } from './lib'; | ||
// ^^^^^^ | ||
// ``` | ||
testMatch: [isWindows ? '**/?(*.)(spec|test).js?(x)' : '**/?(*.)(spec|test).?(m)js?(x)'], | ||
moduleFileExtensions: ['js', 'mjs'], | ||
}; |
7 changes: 7 additions & 0 deletions
7
internal/linker/test/issue_1823_use_ts_library_esm/lib.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {doStuff} from './lib'; | ||
|
||
describe('doStuff', () => { | ||
it('should do some stuff', () => { | ||
expect(doStuff('boom')).toContain('boom'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function doStuff(a: string): string { | ||
return a | ||
} |
38 changes: 38 additions & 0 deletions
38
internal/linker/test/issue_1823_use_ts_library_esm/ts_jest_test.bzl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Simple macro around jest_test""" | ||
|
||
load("@npm//jest-cli:index.bzl", _jest_test = "jest_test") | ||
load("@npm_bazel_typescript//:index.bzl", "ts_library") | ||
|
||
def ts_jest_test(name, srcs, jest_config, deps = [], data = [], **kwargs): | ||
"""A macro around the autogenerated jest_test rule that takes typescript sources | ||
|
||
Uses ts_library prodmode ems output""" | ||
|
||
ts_library( | ||
name = "%s_ts" % name, | ||
srcs = srcs, | ||
data = data, | ||
deps = deps + ["@npm//@types/jest"], | ||
# NB: hacky hidden configuration setting so that es6_sources does not include tsickle | ||
# .externs.js outputs | ||
runtime = "nodejs", | ||
) | ||
native.filegroup( | ||
name = "%s_esm" % name, | ||
srcs = [":%s_ts" % name], | ||
output_group = "es6_sources", | ||
) | ||
|
||
args = [ | ||
"--no-cache", | ||
"--no-watchman", | ||
"--ci", | ||
] | ||
args.extend(["--config", "$$(rlocation $(rootpath %s))" % jest_config]) | ||
|
||
_jest_test( | ||
name = name, | ||
data = [jest_config, ":%s_esm" % name] + deps + data, | ||
templated_args = args, | ||
**kwargs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"declaration": true | ||
"declaration": true, | ||
"types": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
{} | ||
{ | ||
"compilerOptions": { | ||
"types": ["node"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"types": [] | ||
}, | ||
"include": ["main.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"declaration": true | ||
"declaration": true, | ||
"types": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"declaration": true | ||
"declaration": true, | ||
"types": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"declaration": true | ||
"declaration": true, | ||
"types": [] | ||
}, | ||
"include": ["*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
packages/typescript/test/ts_project/empty_intermediate/tsconfig-a.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"files": ["a.d.ts"] | ||
"files": ["a.d.ts"], | ||
"compilerOptions": { | ||
"types": [] | ||
} | ||
} |
5 changes: 4 additions & 1 deletion
5
packages/typescript/test/ts_project/empty_intermediate/tsconfig-b.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"files": [] | ||
"files": [], | ||
"compilerOptions": { | ||
"types": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
{} | ||
{ | ||
"compilerOptions": { | ||
"types": [] | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add this everywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep Windows CI from breaking. Explained in commit message:
This prevents @types packages added to the root package.json from inadvertently breaking tests on buildkite Windows CI where there is no sandboxing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://buildkite.com/bazel/rules-nodejs-nodejs/builds/6691#41586486-08b9-447a-aed1-6f9fff24121b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding @types/jest blew things up and it is generally good practice to be explicit about what types are needed. The other option was
skipLibCheck: true
which is not ideal as it skips checks for all .d.ts files.