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 1 commit
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
22 changes: 22 additions & 0 deletions internal/linker/test/issue_1823/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@npm_bazel_typescript//:index.bzl", "ts_library")
load(":ts_jest_test.bzl", "ts_jest_test")

ts_library(
name = "lib",
srcs = [
"lib.ts",
],
deps = [
],
)

ts_jest_test(
name = "test",
srcs = [
"lib.test.ts",
],
jest_config = "jest.config.js",
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", "$(rootpath %s)" % jest_config])

_jest_test(
name = name,
data = [jest_config, ":%s_umd" % name] + deps + data,
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",
},
},
],
]
}
31 changes: 31 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,31 @@
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",
],
)

ts_jest_test(
name = "test",
srcs = [
"lib.test.ts",
],
data = [
".babelrc",
],
jest_config = "jest.config.js",
deps = [
":lib",
"@npm//@babel/preset-env",
"@npm//babel-jest",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
testEnvironment: 'node',
transform: {'^.+\\.mjs?$': 'babel-jest'},
testMatch: ['**/?(*.)(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", "$(rootpath %s)" % jest_config])

_jest_test(
name = name,
data = [jest_config, ":%s_esm" % name] + deps + data,
templated_args = args,
**kwargs
)
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
Loading