Skip to content

Commit

Permalink
Revert "js_run_devserver symlinks scoped node_modules to bazel-out in…
Browse files Browse the repository at this point in the history
…stead of runfiles (unscoped node_modules are already linked to bazel-out) (#1210)" (#1230)

This reverts commit da7e731.
  • Loading branch information
alexeagle authored Aug 24, 2023
1 parent 36f1065 commit 06ad186
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 808 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Input hashes for repository rule npm_translate_lock(name = "npm", pnpm_lock = "//:pnpm-lock.yaml").
# This file should be checked into version control along with the pnpm-lock.yaml file.
.npmrc=-2065072158
pnpm-lock.yaml=1169067734
pnpm-lock.yaml=754060271
examples/npm_deps/patches/meaning-of-life@1.0.0-pnpm.patch=-442666336
package.json=965846805
pnpm-workspace.yaml=116986059
pnpm-workspace.yaml=1536402859
examples/js_binary/package.json=-41174383
examples/macro/package.json=857146175
examples/npm_deps/package.json=283109008
Expand All @@ -16,7 +16,6 @@ examples/webpack_cli/package.json=1911342006
js/private/coverage/bundle/package.json=-1543718929
js/private/image/package.json=-1260474848
js/private/test/image/package.json=1295393035
js/private/test/js_run_devserver/package.json=-260856079
js/private/worker/src/package.json=1608383745
npm/private/test/package.json=1424344949
npm/private/test/vendored/lodash-4.17.21.tgz=-1206623349
Expand Down
1 change: 0 additions & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ examples/webpack_cli/node_modules/
js/private/coverage/bundle/node_modules
js/private/image/node_modules
js/private/test/image/node_modules
js/private/test/js_run_devserver/node_modules
js/private/worker/src/node_modules
node_modules/
npm/private/test/node_modules/
Expand Down
1 change: 0 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ npm_translate_lock(
"//js/private/coverage/bundle:package.json",
"//js/private/image:package.json",
"//js/private/test/image:package.json",
"//js/private/test/js_run_devserver:package.json",
"//js/private/worker/src:package.json",
"//npm/private/test:package.json",
"//npm/private/test:vendored/lodash-4.17.21.tgz",
Expand Down
1 change: 0 additions & 1 deletion docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ stardoc_with_diff_test(
stardoc_with_diff_test(
name = "js_run_devserver",
bzl_library_target = "//js/private:js_run_devserver",
symbol_names = ["js_run_devserver"],
)

stardoc_with_diff_test(
Expand Down
13 changes: 2 additions & 11 deletions js/private/js_run_devserver.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,10 @@ def _impl(ctx):
),
]

js_run_devserver_lib = struct(
_js_run_devserver = rule(
attrs = _attrs,
implementation = _impl,
toolchains = js_binary_lib.toolchains,
)

_js_run_devserver = rule(
attrs = js_run_devserver_lib.attrs,
implementation = js_run_devserver_lib.implementation,
toolchains = js_run_devserver_lib.toolchains,
executable = True,
)

Expand Down Expand Up @@ -243,10 +237,7 @@ def js_run_devserver(
if kwargs.get("entry_point", None):
fail("`entry_point` is set implicitly by `js_run_devserver` and cannot be overridden.")

# Allow the js_run_devserver rule to execute to be overridden for tests
rule_to_execute = kwargs.pop("rule_to_execute", _js_run_devserver)

rule_to_execute(
_js_run_devserver(
name = name,
enable_runfiles = select({
"@aspect_rules_js//js:enable_runfiles": True,
Expand Down
23 changes: 1 addition & 22 deletions js/private/js_run_devserver.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,6 @@ function mkdirpSync(p) {
mkdirs.add(p)
}

// Determines if a file path refers to a node module.
//
// Examples:
// isNodeModulePath('/private/var/.../node_modules/@babel/core') // true
// isNodeModulePath('/private/var/.../node_modules/lodash') // true
// isNodeModulePath('/private/var/.../some-file.js') // false
function isNodeModulePath(srcPath) {
const parentDir = path.dirname(srcPath);
const parentDirName = path.basename(parentDir);

if (parentDirName === 'node_modules') {
// unscoped module like 'lodash'
return true;
} else if (parentDirName.startsWith('@')) {
// scoped module like '@babel/core'
const parentParentDir = path.dirname(parentDir);
return path.basename(parentParentDir) === 'node_modules';
}
return false;
}

// Recursively copies a file, symlink or directory to a destination. If the file has been previously
// synced it is only re-copied if the file's last modified time has changed since the last time that
// file was copied. Symlinks are not copied but instead a symlink is created under the destination
Expand All @@ -73,7 +52,7 @@ async function syncRecursive(src, dst, writePerm) {
if (process.env.JS_BINARY__LOG_DEBUG) {
console.error(`Syncing symlink ${srcWorkspacePath}`)
}
if (isNodeModulePath(src)) {
if (path.basename(path.dirname(src)) == 'node_modules') {
// Special case for node_modules symlinks where we should _not_ symlink to the runfiles but rather
// the bin copy of the symlink to avoid finding npm packages in multiple node_modules trees
const maybeBinSrc = path.join(
Expand Down
29 changes: 0 additions & 29 deletions js/private/test/js_run_devserver/BUILD

This file was deleted.

41 changes: 0 additions & 41 deletions js/private/test/js_run_devserver/js_run_devserver_test.bzl

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions js/private/test/js_run_devserver/package.json

This file was deleted.

Loading

0 comments on commit 06ad186

Please sign in to comment.