-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add link_workspace_root to nodejs_binary, npm_package_bin, roll…
…up_bundle, terser_minified, ts_project Link the workspace root to the bin_dir to support absolute requires like 'my_wksp/path/to/file'. If source files need to be required then they can be copied to the bin_dir with copy_to_bin.
- Loading branch information
1 parent
df18c61
commit 4dcb37f
Showing
23 changed files
with
196 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("//packages/jasmine:index.bzl", "jasmine_node_test") | ||
|
||
jasmine_node_test( | ||
name = "test", | ||
srcs = ["test.js"], | ||
link_workspace_root = True, | ||
templated_args = ["--nobazel_patch_module_resolver"], | ||
deps = [ | ||
"//internal/linker/test/workspace_link/bar", | ||
"//internal/linker/test/workspace_link/foo", | ||
], | ||
) |
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,10 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin") | ||
|
||
copy_to_bin( | ||
name = "bar", | ||
srcs = [ | ||
"main.js", | ||
"package.json", | ||
], | ||
visibility = ["//internal/linker/test/workspace_link:__pkg__"], | ||
) |
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 = { | ||
bar: 'bar', | ||
} |
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,5 @@ | ||
{ | ||
"name": "bar", | ||
"main": "main.js", | ||
"typings": "main.d.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,35 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin") | ||
load("@npm//typescript:index.bzl", "tsc") | ||
|
||
tsc( | ||
name = "foo_lib", | ||
outs = [ | ||
"main.d.ts", | ||
"main.js", | ||
], | ||
args = [ | ||
"-p", | ||
"$(execpath tsconfig.json)", | ||
"--outDir", | ||
# $(RULEDIR) is a shorthand for the dist/bin directory where Bazel requires we write outputs | ||
"$(RULEDIR)", | ||
], | ||
data = [ | ||
"main.ts", | ||
"tsconfig.json", | ||
], | ||
) | ||
|
||
copy_to_bin( | ||
name = "foo_files", | ||
srcs = ["package.json"], | ||
) | ||
|
||
filegroup( | ||
name = "foo", | ||
srcs = [ | ||
":foo_files", | ||
":foo_lib", | ||
], | ||
visibility = ["//internal/linker/test/workspace_link:__pkg__"], | ||
) |
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 @@ | ||
export const foo: string = 'foo'; |
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,5 @@ | ||
{ | ||
"name": "foo", | ||
"main": "main.js", | ||
"typings": "main.d.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,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
describe('linker', () => { | ||
it('should be able to require by absolute path when link_workspace_root is True', () => { | ||
const foo = require('build_bazel_rules_nodejs/internal/linker/test/workspace_link/foo'); | ||
expect(foo.foo).toBe('foo'); | ||
const bar = require('build_bazel_rules_nodejs/internal/linker/test/workspace_link/bar'); | ||
expect(bar.bar).toBe('bar'); | ||
}); | ||
}); |
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
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("//packages/jasmine:index.bzl", "jasmine_node_test") | ||
load("//packages/rollup:index.bzl", "rollup_bundle") | ||
|
||
copy_to_bin( | ||
name = "foo", | ||
srcs = ["foo.js"], | ||
) | ||
|
||
rollup_bundle( | ||
name = "bundle", | ||
srcs = [ | ||
"bar.js", | ||
"main.js", | ||
":foo", | ||
], | ||
config_file = "rollup.config.js", | ||
entry_point = "main.js", | ||
link_workspace_root = True, | ||
deps = [ | ||
"@npm//@rollup/plugin-commonjs", | ||
"@npm//@rollup/plugin-node-resolve", | ||
], | ||
) | ||
|
||
jasmine_node_test( | ||
name = "test", | ||
srcs = ["spec.js"], | ||
deps = ["bundle"], | ||
) |
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 @@ | ||
export const bar = 'bar'; |
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 @@ | ||
export const foo = 'foo'; |
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,5 @@ | ||
import * as foo from 'build_bazel_rules_nodejs/packages/rollup/test/workspace_link/foo'; | ||
import * as bar from './bar'; | ||
|
||
console.log(foo); | ||
console.log(bar); |
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,15 @@ | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import nodeResolve from '@rollup/plugin-node-resolve'; | ||
|
||
module.exports = { | ||
onwarn: (warning) => { | ||
// Always fail on warnings, assuming we don't know which are harmless. | ||
// We can add exclusions here based on warning.code, if we discover some | ||
// types of warning should always be ignored under bazel. | ||
throw new Error(warning.message); | ||
}, | ||
plugins: [ | ||
nodeResolve(), | ||
commonjs(), | ||
], | ||
}; |
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,11 @@ | ||
const fs = require('fs'); | ||
const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']); | ||
|
||
describe('rollup', () => { | ||
it('should bundle absolute & relative imports', async () => { | ||
const file = runfiles.resolvePackageRelative('bundle.js'); | ||
const bundle = fs.readFileSync(file, 'utf-8'); | ||
expect(bundle).toContain(`const foo = 'foo';`); | ||
expect(bundle).toContain(`const bar = 'bar';`); | ||
}); | ||
}); |
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