-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
js_run_devserver symlinks scoped node_modules to bazel-out instead of…
… runfiles (unscoped node_modules are already linked to bazel-out) (#1210) * js_run_devserver symlinks scoped node_modules to bazel-out instead of runfiles * Add test which confirms the single node_modules tree * Little cleanup * Simplify test script, exit test even if server still has connections * Clarify comment * Move tests to Jasmine, add explicit symlink tests * Simplify tests to just the symlink tests * Add js_run_devserver_internal to keep original js_run_devserver API the same * Dedicate test target specifically to the node_modules symlinks * Identifier name fix * Second identifier name fix in test * Fix docs * Fix macro for docs update * Update npm/private/test/repositories_checked.bzl - fixes test * Buildifier fix for js_run_devserver_test.bzl * Use 'tool' instead of 'command' for js_run_devserver_test * Workaround for "js_run_devserver_internal() got multiple values for parameter 'rule_to_execute'" error * Slight comment tweak * Remove unnecessary js_run_devserver_internal macro * Turns out still need to scope stardoc with the symbol name to avoid printing docs for the lib --------- Co-authored-by: Greg Magolan <greg@aspect.dev>
- Loading branch information
1 parent
0109c77
commit da7e731
Showing
13 changed files
with
808 additions
and
81 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
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,29 @@ | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
load("@npm//js/private/test/js_run_devserver:jasmine/package_json.bzl", jasmine_bin = "bin") | ||
load(":js_run_devserver_test.bzl", "js_run_devserver_test") | ||
|
||
npm_link_all_packages(name = "node_modules") | ||
|
||
# Checks node_modules symlinks that they refer to exec root (instead of runfiles) | ||
# in order to make sure bundlers see exactly one node_modules tree. Checks: | ||
# - https://github.com/aspect-build/rules_js/pull/1043 | ||
# - https://github.com/aspect-build/rules_js/issues/1204 | ||
js_run_devserver_test( | ||
name = "node_modules_symlink_to_execroot_test", | ||
args = ["node_modules_symlink_to_execroot.test.mjs"], | ||
chdir = "js/private/test/js_run_devserver", | ||
data = [ | ||
"node_modules_symlink_to_execroot.test.mjs", | ||
|
||
# Some packages to link back to the exec root for the tests for | ||
# https://github.com/aspect-build/rules_js/issues/1204 (and need jasmine | ||
# anyway for the runner) | ||
":node_modules/@types/node", | ||
":node_modules/jasmine", | ||
], | ||
tool = ":jasmine", | ||
) | ||
|
||
jasmine_bin.jasmine_binary( | ||
name = "jasmine", | ||
) |
41 changes: 41 additions & 0 deletions
41
js/private/test/js_run_devserver/js_run_devserver_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,41 @@ | ||
"Implementation of the js_run_devserver_test rule (the 'test' version of js_run_devserver)" | ||
|
||
load("//js/private:js_run_devserver.bzl", "js_run_devserver", "js_run_devserver_lib") | ||
|
||
# 'test' version of the _js_run_devserver` rule | ||
_js_run_devserver_test = rule( | ||
attrs = js_run_devserver_lib.attrs, | ||
implementation = js_run_devserver_lib.implementation, | ||
toolchains = js_run_devserver_lib.toolchains, | ||
test = True, | ||
) | ||
|
||
def js_run_devserver_test( | ||
name, | ||
tags = [], | ||
**kwargs): | ||
""" | ||
'Test' version of the `js_run_devserver` macro. | ||
Provides the test rule to the macro, along with the 'no-sandbox' tag in | ||
order to properly simulate the js_run_devserver environment of 'bazel run'. | ||
Args: | ||
name: A unique name for this target. | ||
tags: Additional Bazel tags to supply to the rule. | ||
**kwargs: All other args for `js_run_devserver`. | ||
See https://docs.aspect.build/rules/aspect_rules_js/docs/js_run_devserver | ||
""" | ||
js_run_devserver( | ||
name, | ||
# Override the rule to execute | ||
rule_to_execute = _js_run_devserver_test, | ||
# 'no-sandbox' needed to simulate 'bazel run' command - normally tests | ||
# are sandboxed, but sandboxing doesn't exhibit the issue in | ||
# https://github.com/aspect-build/rules_js/issues/1204 | ||
tags = tags + ["no-sandbox"], | ||
**kwargs | ||
) |
30 changes: 30 additions & 0 deletions
30
js/private/test/js_run_devserver/node_modules_symlink_to_execroot.test.mjs
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 @@ | ||
import fs from 'fs' | ||
|
||
describe('node_modules symlinks >', () => { | ||
const execRootDir = process.env.JS_BINARY__EXECROOT | ||
const runfilesDir = process.env.JS_BINARY__RUNFILES | ||
|
||
beforeAll(() => { | ||
// first ensure that the environment variables are strings with some value | ||
if (typeof execRootDir !== 'string' || execRootDir.length === 0) { | ||
throw new Error(`process.env.JS_BINARY__EXECROOT is empty - can't run tests which rely on it`) | ||
} | ||
if (typeof runfilesDir !== 'string' || runfilesDir.length === 0) { | ||
throw new Error(`process.env.JS_BINARY__RUNFILES is empty - can't run tests which rely on it`) | ||
} | ||
}) | ||
|
||
it(`symlinks non-scoped node_modules (e.g. 'jasmine') to the exec root instead of runfiles to ensure bundlers see a single node_modules tree (https://github.com/aspect-build/rules_js/pull/1043)`, () => { | ||
const jasmineSymlink = fs.readlinkSync('./node_modules/jasmine') | ||
|
||
expect(jasmineSymlink).toContain(execRootDir) | ||
expect(jasmineSymlink).not.toContain(runfilesDir) | ||
}) | ||
|
||
it(`symlinks scoped node_modules (e.g. '@types/node') to the exec root instead of runfiles to ensure bundlers see a single node_modules tree (https://github.com/aspect-build/rules_js/issues/1204)`, () => { | ||
const typesNodeSymlink = fs.readlinkSync('./node_modules/@types/node') | ||
|
||
expect(typesNodeSymlink).toContain(execRootDir) | ||
expect(typesNodeSymlink).not.toContain(runfilesDir) | ||
}) | ||
}) |
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,9 @@ | ||
{ | ||
"name": "js_run_devserver_test", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@types/node": "16.18.11", | ||
"jasmine": "5.1.0" | ||
} | ||
} |
Oops, something went wrong.