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
Add e2e tests/examples of transitive npm deps for ts_library - nodejs_binary interop #612
Changes from 21 commits
08d8125
38de67d
4846436
473f089
20d0cab
a05534b
896df4b
a228060
e3b8695
5cf4e8e
3890729
ea41bce
d1f48da
451232e
d6ef7f0
6f970c2
b8de6f0
089cbce
aac3532
54a8f6d
29e668e
57fd800
e483eee
417d9ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {format} from 'date-fns' | ||
|
||
export function sayDate() { | ||
return 'hello ' + format(new Date(2014, 1, 11), 'MM/dd/YYYY'); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import {sayDate} from './lib'; | ||
|
||
console.log(sayDate()); | ||
|
||
export function test() { | ||
return 'test'; | ||
return `test ${sayDate()}`; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,36 @@ NodeModuleInfo = provider( | |
}, | ||
) | ||
|
||
NodeModuleSources = provider( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect this is over complicating things here with two different node_modules providers and a @kyliau recently added the |
||
doc = "This provider contains all the transtive npm dependency sources of a non-npm dependency.", | ||
fields = { | ||
"srcs": "List of source files that are npm dependencies", | ||
}, | ||
) | ||
|
||
def _collect_node_modules_aspect_impl(target, ctx): | ||
nm_wksp = None | ||
|
||
if hasattr(ctx.rule.attr, "tags") and "NODE_MODULE_MARKER" in ctx.rule.attr.tags: | ||
nm_wksp = target.label.workspace_root.split("/")[1] if target.label.workspace_root else ctx.workspace_name | ||
return [NodeModuleInfo(workspace = nm_wksp)] | ||
|
||
info = [] | ||
srcs = depset() | ||
if hasattr(ctx.rule.attr, "deps"): | ||
for dep in ctx.rule.attr.deps: | ||
if NodeModuleInfo in dep and NodeModuleSources in dep: | ||
fail("Dependency %s has both NodeModuleInfo and NodeModuleSources provider. It can only have one or the other." % dep) | ||
if NodeModuleInfo in dep: | ||
if nm_wksp and dep[NodeModuleInfo].workspace != nm_wksp: | ||
fail("All npm dependencies need to come from a single workspace. Found '%s' and '%s'." % (nm_wksp, dep[NodeModuleInfo].workspace)) | ||
srcs = depset(transitive = [dep.files, srcs]) | ||
if NodeModuleSources in dep: | ||
srcs = depset(transitive = [dep[NodeModuleSources].srcs, srcs]) | ||
|
||
if srcs: | ||
return [NodeModuleSources(srcs = srcs)] | ||
|
||
return [] | ||
|
||
collect_node_modules_aspect = aspect( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,6 +177,7 @@ const config = { | |
module: true, | ||
jsnext: true, | ||
main: true, | ||
jail: process.cwd(), | ||
customResolveOptions: {moduleDirectory: nodeModulesRoot} | ||
}), | ||
amd({ | ||
|
@@ -193,6 +194,7 @@ const config = { | |
banner, | ||
format: 'TMPL_output_format', | ||
}, | ||
preserveSymlinks: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. Do these preserve symlinks & jail changes work as intended to keep the resolve within the cwd()? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, in this particular case it was really the |
||
} | ||
|
||
if (enableCodeSplitting) { | ||
|
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.
Should change the
test
script in package.json tobazel build ... && bazel test ...
so that these targets are builtThere 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.
I am pretty sure
bazel test ...
implicitly also builds all targets (unless--build_tests_only
) is also specified. Let me verify this though.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.
Yep just verified. I had a failing
rollup_bundle
andbazel test ...
failed on building it.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.
Ahhhh. Good to know. Thanks for verifying.