Skip to content

Commit

Permalink
WIP prototype of symlinking user node_modules in yarn_install & npm_i…
Browse files Browse the repository at this point in the history
…nstall
  • Loading branch information
gregmagolan committed Apr 11, 2019
1 parent bb8b46c commit 6ad987a
Show file tree
Hide file tree
Showing 29 changed files with 188 additions and 254 deletions.
8 changes: 8 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
node_modules
examples/program/node_modules
internal/history-server/node_modules
internal/http-server/node_modules
internal/npm_install/test/package/node_modules
internal/npm_install/node_modules
internal/rollup/node_modules
internal/web_package/node_modules
dist
# Each e2e test is a nested workspace
e2e/
Expand All @@ -12,6 +17,9 @@ packages/
# TODO(gregmagolan): move these to /e2e
internal/e2e/bazel_workspaces
internal/e2e/bazel_workspaces_compat
internal/e2e/fine_grained_deps/npm/node_modules
internal/e2e/fine_grained_deps/yarn/node_modules
internal/e2e/fine_grained_no_bin/node_modules
internal/e2e/fine_grained_symlinks
internal/e2e/node_loader_no_preserve_symlinks
internal/e2e/node_loader_preserve_symlinks
Expand Down
18 changes: 0 additions & 18 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,6 @@ node_repositories(

yarn_install(
name = "npm",
data = [
"@build_bazel_rules_nodejs//:tools/npm_packages/hello/index.js",
"@build_bazel_rules_nodejs//:tools/npm_packages/hello/package.json",
"@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_index/index.js",
"@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_index_2/index.js",
"@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_index_2/package.json",
"@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_index_3/index.js",
"@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_index_3/package.json",
"@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_index_4/index.js",
"@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_index_4/package.json",
"@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_main/main.js",
"@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_main/package.json",
"@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_main_2/main.js",
"@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_main_2/package.json",
"@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_nested_main/nested/main.js",
"@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_nested_main/nested/package.json",
"@build_bazel_rules_nodejs//:tools/npm_packages/node_resolve_nested_main/package.json",
],
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
Expand Down
4 changes: 0 additions & 4 deletions e2e/bazel_bin/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install")

yarn_install(
name = "npm",
data = [
"@e2e_bazel_bin//:npm/testy/index.js",
"@e2e_bazel_bin//:npm/testy/package.json",
],
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
6 changes: 1 addition & 5 deletions examples/program/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,4 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")
# bazel run @nodejs//:yarn
# or
# bazel run @nodejs//:npm
node_repositories(
node_version = "8.11.1",
package_json = ["//:package.json"],
yarn_version = "1.5.1",
)
node_repositories(package_json = ["//:package.json"])
7 changes: 0 additions & 7 deletions internal/e2e/bazel_workspaces/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install")

yarn_install(
name = "npm",
data = [
"@bazel_workspaces//:npm/test_workspace/WORKSPACE",
"@bazel_workspaces//:npm/test_workspace/package.json",
"@bazel_workspaces//:npm/test_workspace/src/BUILD.bazel",
"@bazel_workspaces//:npm/test_workspace/src/test.spec.js",
"@bazel_workspaces//:npm/test_workspace/yarn.lock",
],
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
Expand Down
17 changes: 0 additions & 17 deletions internal/e2e/bazel_workspaces_compat/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,6 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install")

yarn_install(
name = "npm",
data = [
"@bazel_workspaces_compat//:npm/test_workspace_a/WORKSPACE",
"@bazel_workspaces_compat//:npm/test_workspace_a/package.json",
"@bazel_workspaces_compat//:npm/test_workspace_a/src/BUILD.bazel",
"@bazel_workspaces_compat//:npm/test_workspace_a/src/test.spec.js",
"@bazel_workspaces_compat//:npm/test_workspace_a/yarn.lock",
"@bazel_workspaces_compat//:npm/test_workspace_b/WORKSPACE",
"@bazel_workspaces_compat//:npm/test_workspace_b/package.json",
"@bazel_workspaces_compat//:npm/test_workspace_b/src/BUILD.bazel",
"@bazel_workspaces_compat//:npm/test_workspace_b/src/test.spec.js",
"@bazel_workspaces_compat//:npm/test_workspace_b/yarn.lock",
"@bazel_workspaces_compat//:npm/test_workspace_c/WORKSPACE",
"@bazel_workspaces_compat//:npm/test_workspace_c/package.json",
"@bazel_workspaces_compat//:npm/test_workspace_c/src/BUILD.bazel",
"@bazel_workspaces_compat//:npm/test_workspace_c/src/test.spec.js",
"@bazel_workspaces_compat//:npm/test_workspace_c/yarn.lock",
],
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
Expand Down
2 changes: 1 addition & 1 deletion internal/e2e/fine_grained_no_bin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"dependencies": {
"fs.realpath": "1.0.0"
}
}
}
1 change: 0 additions & 1 deletion internal/e2e/packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ filegroup(

VARIANTS = [
"npm_install",
"npm_no_lockfile",
"yarn_install",
]

Expand Down
2 changes: 1 addition & 1 deletion internal/e2e/packages/npm1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"jasmine": "2.8.0"
},
"scripts": {
"postinstall": "node ./postinstall.js"
"postinstall": "node ../postinstall.js"
}
}
2 changes: 1 addition & 1 deletion internal/e2e/packages/npm2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"jasmine": "2.8.0"
},
"scripts": {
"postinstall": "node ./postinstall.js"
"postinstall": "node ../postinstall.js"
}
}
10 changes: 0 additions & 10 deletions internal/e2e/packages/npm3/package.json

This file was deleted.

10 changes: 0 additions & 10 deletions internal/e2e/packages/setup_workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def internal_e2e_packages_setup_workspace():
name = "internal_e2e_packages_npm_install",
package_json = "@internal_e2e_packages//:npm1/package.json",
package_lock_json = "@internal_e2e_packages//:npm1/package-lock.json",
data = ["@internal_e2e_packages//:postinstall.js"],
# Just here as a smoke test for this attribute
prod_only = True,
)
Expand All @@ -33,25 +32,16 @@ def internal_e2e_packages_setup_workspace():
name = "internal_e2e_packages_npm_install_duplicate_for_determinism_testing",
package_json = "@internal_e2e_packages//:npm2/package.json",
package_lock_json = "@internal_e2e_packages//:npm2/package-lock.json",
data = ["@internal_e2e_packages//:postinstall.js"],
)

npm_install(
name = "internal_e2e_packages_npm_no_lockfile",
package_json = "@internal_e2e_packages//:npm3/package.json",
data = ["@internal_e2e_packages//:postinstall.js"],
)

yarn_install(
name = "internal_e2e_packages_yarn_install",
package_json = "@internal_e2e_packages//:yarn1/package.json",
yarn_lock = "@internal_e2e_packages//:yarn1/yarn.lock",
data = ["@internal_e2e_packages//:postinstall.js"],
)

yarn_install(
name = "internal_e2e_packages_yarn_install_duplicate_for_determinism_testing",
package_json = "@internal_e2e_packages//:yarn2/package.json",
yarn_lock = "@internal_e2e_packages//:yarn2/yarn.lock",
data = ["@internal_e2e_packages//:postinstall.js"],
)
2 changes: 1 addition & 1 deletion internal/e2e/packages/yarn1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"jasmine": "2.8.0"
},
"scripts": {
"postinstall": "node ./postinstall.js"
"postinstall": "node ../postinstall.js"
}
}
2 changes: 1 addition & 1 deletion internal/e2e/packages/yarn2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"jasmine": "2.8.0"
},
"scripts": {
"postinstall": "node ./postinstall.js"
"postinstall": "node ../postinstall.js"
}
}
12 changes: 9 additions & 3 deletions internal/node/generate_build_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ function mkdirp(p) {
}
}

function writeFileSync(filePath, contents) {
mkdirp(path.dirname(filePath));
fs.writeFileSync(filePath, contents);
/**
* Writes a file, first ensuring that the directory to
* write to exists, and flushes it to disk.
*/
function writeFileSync(p, content) {
mkdirp(path.dirname(p));
const fd = fs.openSync(p, 'w');
fs.writeSync(fd, content);
fs.fdatasyncSync(fd);
}

/**
Expand Down
5 changes: 2 additions & 3 deletions internal/node/node_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ CALL "%SCRIPT_DIR%\\{node}" %*
set -e
# Generated by node_repositories.bzl
export NODE_REPOSITORY_ARGS={}
""".format("--node_options=--preserve-symlinks" if repository_ctx.attr.preserve_symlinks else ""), executable = True)
""".format("\"--node_options=--preserve-symlinks --node_options=--preserve-symlinks-main\"" if repository_ctx.attr.preserve_symlinks else ""), executable = True)

# The entry points for npm for osx/linux and windows
# Runs npm using appropriate node entry point
Expand Down Expand Up @@ -420,7 +420,7 @@ if %errorlevel% neq 0 exit /b %errorlevel%
)
result = repository_ctx.execute([node_entry, "generate_build_file.js"])
if result.return_code:
fail("node failed: \nSTDOUT:\n%s\nSTDERR:\n%s" % (result.stdout, result.stderr))
fail("generate_build_file.js failed: \nSTDOUT:\n%s\nSTDERR:\n%s" % (result.stdout, result.stderr))

def _nodejs_repo_impl(repository_ctx):
_download_node(repository_ctx)
Expand Down Expand Up @@ -579,7 +579,6 @@ def node_repositories(
name = "build_bazel_rules_nodejs_rollup_deps",
package_json = "@build_bazel_rules_nodejs//internal/rollup:package.json",
yarn_lock = "@build_bazel_rules_nodejs//internal/rollup:yarn.lock",
data = ["@build_bazel_rules_nodejs//internal/rollup:postinstall-patches.js"],
)

_maybe(
Expand Down
Loading

0 comments on commit 6ad987a

Please sign in to comment.