Skip to content
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 3 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/linker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ function main(args, runfiles) {
if (runfilesPath.startsWith(`${bin}/`)) {
runfilesPath = runfilesPath.slice(bin.length + 1);
}
else if (runfilesPath === bin) {
runfilesPath = '';
}
const externalPrefix = 'external/';
if (runfilesPath.startsWith(externalPrefix)) {
runfilesPath = runfilesPath.slice(externalPrefix.length);
Expand Down
2 changes: 2 additions & 0 deletions internal/linker/link_node_modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ export async function main(args: string[], runfiles: Runfiles) {
let runfilesPath = modulePath;
if (runfilesPath.startsWith(`${bin}/`)) {
runfilesPath = runfilesPath.slice(bin.length + 1);
} else if (runfilesPath === bin) {
runfilesPath = '';
}
const externalPrefix = 'external/';
if (runfilesPath.startsWith(externalPrefix)) {
Expand Down
30 changes: 30 additions & 0 deletions internal/linker/test/issue_1823/BUILD.bazel
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",
],
)
3 changes: 3 additions & 0 deletions internal/linker/test/issue_1823/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
testEnvironment: 'node',
};
7 changes: 7 additions & 0 deletions internal/linker/test/issue_1823/lib.test.ts
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');
});
});
3 changes: 3 additions & 0 deletions internal/linker/test/issue_1823/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function doStuff(a: string): string {
return a
}
35 changes: 35 additions & 0 deletions internal/linker/test/issue_1823/ts_jest_test.bzl
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 internal/linker/test/issue_1823_use_ts_library_esm/.babelrc
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 internal/linker/test/issue_1823_use_ts_library_esm/BUILD.bazel
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 internal/linker/test/issue_1823_use_ts_library_esm/jest.config.js
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'],
};
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');
});
});
3 changes: 3 additions & 0 deletions internal/linker/test/issue_1823_use_ts_library_esm/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function doStuff(a: string): string {
return a
}
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
)
3 changes: 2 additions & 1 deletion internal/linker/test/local/fit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"declaration": true
"declaration": true,
"types": []
}
}
6 changes: 5 additions & 1 deletion internal/node/test/lib2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{}
{
"compilerOptions": {
"types": ["node"]
}
}
3 changes: 3 additions & 0 deletions internal/node/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"compilerOptions": {
"types": []
},
"include": ["main.ts"]
}
3 changes: 2 additions & 1 deletion internal/pkg_npm/test/linking/fub/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"declaration": true
"declaration": true,
"types": []
}
}
3 changes: 2 additions & 1 deletion internal/pkg_npm/test/linking/fuz/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"declaration": true
"declaration": true,
"types": []
}
}
3 changes: 2 additions & 1 deletion internal/pkg_npm/test/linking/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"declaration": true
"declaration": true,
"types": []
},
"include": ["*.ts"]
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
"@gregmagolan/test-a": "0.0.5",
"@types/hammerjs": "2.0.35",
"@types/jasmine": "~3.3.13",
"@types/jest": "24.9.0",
"@types/node": "^12.0.0",
"@types/semver": "6.2.0",
"babel-jest": "^25.5.1",
"bazel_workspaces": "file:./tools/npm_packages/bazel_workspaces",
"clang-format": "1.2.2",
"conventional-changelog-cli": "^2.0.21",
Expand Down
3 changes: 2 additions & 1 deletion packages/rollup/test/integration/far/a/b/c/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"strict": true,
"target": "es2015",
"module": "esnext",
"moduleResolution": "node"
"moduleResolution": "node",
"types": []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this everywhere?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


./../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jasmine/ts3.1/index.d.ts(16,1): error TS6200: Definitions of the following identifiers conflict with those in another file: beforeAll, beforeEach, afterAll, afterEach, describe, fdescribe, xdescribe, it, fit, xit, expect, DEFAULT_TIMEOUT_INTERVAL, CustomMatcherFactory, CustomEqualityTester
--
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jasmine/ts3.1/index.d.ts(253,15): error TS2428: All declarations of 'ArrayContaining' must have identical type parameters.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jasmine/ts3.1/index.d.ts(257,15): error TS2428: All declarations of 'ObjectContaining' must have identical type parameters.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jasmine/ts3.1/index.d.ts(304,9): error TS2687: All declarations of 'message' must have identical modifiers.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jasmine/ts3.1/index.d.ts(730,15): error TS2428: All declarations of 'SpyAnd' must have identical type parameters.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jasmine/ts3.1/index.d.ts(747,15): error TS2428: All declarations of 'Calls' must have identical type parameters.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jasmine/ts3.1/index.d.ts(766,15): error TS2428: All declarations of 'CallInfo' must have identical type parameters.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(34,1): error TS6200: Definitions of the following identifiers conflict with those in another file: beforeAll, beforeEach, afterAll, afterEach, describe, fdescribe, xdescribe, it, fit, xit, expect, DEFAULT_TIMEOUT_INTERVAL, CustomMatcherFactory, CustomEqualityTester
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1354,46): error TS2314: Generic type 'ArrayContaining<T>' requires 1 type argument(s).
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1355,45): error TS2314: Generic type 'ObjectContaining<T>' requires 1 type argument(s).
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1381,15): error TS2428: All declarations of 'ArrayContaining' must have identical type parameters.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1387,15): error TS2428: All declarations of 'ObjectContaining' must have identical type parameters.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1390,9): error TS2386: Overload signatures must all be optional or required.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1396,14): error TS2314: Generic type 'SpyAnd<Fun>' requires 1 type argument(s).
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1397,16): error TS2314: Generic type 'Calls<Fun>' requires 1 type argument(s).
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1403,15): error TS2428: All declarations of 'SpyAnd' must have identical type parameters.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1436,15): error TS2428: All declarations of 'Calls' must have identical type parameters.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1462,16): error TS2314: Generic type 'CallInfo<Fun>' requires 1 type argument(s).
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1467,23): error TS2314: Generic type 'CallInfo<Fun>' requires 1 type argument(s).
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1472,18): error TS2314: Generic type 'CallInfo<Fun>' requires 1 type argument(s).
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1479,15): error TS2428: All declarations of 'CallInfo' must have identical type parameters.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1487,9): error TS2717: Subsequent property declarations must have the same type.  Property 'args' must be of type 'Parameters<Fun>', but here has type 'any[]'.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1491,9): error TS2717: Subsequent property declarations must have the same type.  Property 'returnValue' must be of type 'ReturnType<Fun>', but here has type 'any'.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1495,9): error TS2374: Duplicate string index signature.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1515,9): error TS2687: All declarations of 'message' must have identical modifiers.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1515,9): error TS2717: Subsequent property declarations must have the same type.  Property 'message' must be of type 'string \| undefined', but here has type 'string \| (() => string)'.
  | ../../../bk-windows-c4d7/bazel/rules-nodejs-nodejs/node_modules/@types/jest/index.d.ts(1520,9): error TS2375: Duplicate number index signature.

Copy link
Collaborator Author

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.

}
}
3 changes: 2 additions & 1 deletion packages/rollup/test/integration/far/a/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"strict": true,
"target": "es2015",
"module": "esnext",
"moduleResolution": "node"
"moduleResolution": "node",
"types": []
},
// For Windows, which is not sand-boxed, we need to limit
// the typescript files included so the "@far/a" compilation
Expand Down
3 changes: 2 additions & 1 deletion packages/rollup/test/integration/foo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"strict": true,
"target": "es2015",
"module": "esnext",
"moduleResolution": "node"
"moduleResolution": "node",
"types": []
}
}
3 changes: 2 additions & 1 deletion packages/rollup/test/integration/foo_a/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"strict": true,
"target": "es2015",
"module": "esnext",
"moduleResolution": "node"
"moduleResolution": "node",
"types": []
}
}
3 changes: 2 additions & 1 deletion packages/rollup/test/integration/foo_aaa/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"strict": true,
"target": "es2015",
"module": "esnext",
"moduleResolution": "node"
"moduleResolution": "node",
"types": []
}
}
1 change: 1 addition & 0 deletions packages/typescript/src/checked_in_ts_project.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def checked_in_ts_project(name, src, checked_in_js = None, **kwargs):
module = "commonjs",
removeComments = True,
declaration = True,
skipLibCheck = True,
),
files = ["/".join([workspace_root, native.package_name(), src])],
).to_json()],
Expand Down
3 changes: 3 additions & 0 deletions packages/typescript/test/ts_project/b/tsconfig-test.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"types": ["jasmine", "node"]
},
"references": [
{"path": "./"}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"files": ["a.d.ts"]
"files": ["a.d.ts"],
"compilerOptions": {
"types": []
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"files": []
"files": [],
"compilerOptions": {
"types": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"../../../../../bazel-out/k8-dbg/bin/packages/typescript/test/ts_project/empty_intermediate",
"../../../../../bazel-out/x64_windows-dbg/bin/packages/typescript/test/ts_project/empty_intermediate",
],
"types": []
}
}
6 changes: 5 additions & 1 deletion packages/typescript/test/ts_project/rootdir/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{}
{
"compilerOptions": {
"types": []
}
}
Loading