From d0b08d5b07347ec6519cf42048dbe519a9760c01 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Thu, 10 Dec 2020 17:07:01 -0800 Subject: [PATCH] chore: revert files that can be cleanup after flag flip --- e2e/nodejs_image/BUILD.bazel | 2 ++ e2e/typescript/BUILD.bazel | 10 ---------- e2e/typescript/WORKSPACE | 9 --------- examples/nestjs/src/BUILD.bazel | 1 + internal/bazel_integration_test/BUILD.bazel | 5 +---- internal/linker/test/local/BUILD.bazel | 1 + internal/linker/test/workspace_link/BUILD.bazel | 1 + internal/node/test/BUILD.bazel | 9 +++++++++ internal/npm_install/generate_build_file.ts | 9 ++++++--- internal/npm_install/index.js | 7 ++++--- .../golden/@gregmagolan/test-a/bin/BUILD.bazel.golden | 1 + .../test/golden/@gregmagolan/test-a/index.bzl.golden | 4 ++-- .../test/golden/jasmine/bin/BUILD.bazel.golden | 1 + .../npm_install/test/golden/jasmine/index.bzl.golden | 4 ++-- internal/pkg_npm/test/directory/BUILD.bazel | 1 + internal/pkg_npm/test/linking/BUILD.bazel | 1 + internal/providers/node_runtime_deps_info.bzl | 5 +++++ .../cypress/internal/template.cypress_web_test.bzl | 2 ++ packages/labs/test/protobufjs/BUILD.bazel | 1 - packages/rollup/install.md | 1 + packages/typescript/internal/ts_project.bzl | 1 + packages/typescript/test/some_module/BUILD.bazel | 3 ++- packages/typescript/test/ts_project/a/tsconfig.json | 4 ++-- 23 files changed, 46 insertions(+), 37 deletions(-) diff --git a/e2e/nodejs_image/BUILD.bazel b/e2e/nodejs_image/BUILD.bazel index 88ce171dde..c2f9c6b35e 100644 --- a/e2e/nodejs_image/BUILD.bazel +++ b/e2e/nodejs_image/BUILD.bazel @@ -9,6 +9,8 @@ nodejs_binary( "@npm//date-fns", ], entry_point = "main.js", + # Turn off require() monkey patches so linker is required to run inside docker container + templated_args = ["--nobazel_patch_module_resolver"], ) # bazel run --platforms=@build_bazel_rules_nodejs//toolchains/node:linux_amd64 //:nodejs_image diff --git a/e2e/typescript/BUILD.bazel b/e2e/typescript/BUILD.bazel index d907ca13ed..9f225bd1ca 100644 --- a/e2e/typescript/BUILD.bazel +++ b/e2e/typescript/BUILD.bazel @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("@bazel_skylib//rules:write_file.bzl", "write_file") load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test") load("@npm//@bazel/typescript:index.bzl", "ts_library") @@ -46,24 +45,15 @@ ts_library( ], ) -# Run the test with cwd in the output folder -write_file( - name = "write_chdir_script", - out = "chdir.js", - content = ["process.chdir(__dirname)"], -) - jasmine_node_test( name = "test", data = [ - "chdir.js", # Verify that worker_protocol.proto can be referenced as a target in the generated npm bazel workspace "@npm//@bazel/typescript/third_party/github.com/bazelbuild/bazel/src/main/protobuf:worker_protocol.proto", ], templated_args = [ # ts_library produces named AMD output with repo name in the require statement "--bazel_patch_module_resolver", - "--node_options=--require=$$(rlocation $(rootpath chdir.js))", ], deps = [ ":test_lib", diff --git a/e2e/typescript/WORKSPACE b/e2e/typescript/WORKSPACE index fae9ea0c54..8ad23fda69 100644 --- a/e2e/typescript/WORKSPACE +++ b/e2e/typescript/WORKSPACE @@ -25,15 +25,6 @@ http_archive( urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/2.2.2/rules_nodejs-2.2.2.tar.gz"], ) -http_archive( - name = "bazel_skylib", - sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", - ], -) - load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install") yarn_install( diff --git a/examples/nestjs/src/BUILD.bazel b/examples/nestjs/src/BUILD.bazel index 34027a69ad..28e27272a8 100644 --- a/examples/nestjs/src/BUILD.bazel +++ b/examples/nestjs/src/BUILD.bazel @@ -61,6 +61,7 @@ nodejs_binary( "@npm//minimist", ], entry_point = ":main.ts", + templated_args = ["--nobazel_patch_module_resolver"], ) jasmine_node_test( diff --git a/internal/bazel_integration_test/BUILD.bazel b/internal/bazel_integration_test/BUILD.bazel index 69c22078bb..bbc085ec1d 100644 --- a/internal/bazel_integration_test/BUILD.bazel +++ b/internal/bazel_integration_test/BUILD.bazel @@ -22,10 +22,7 @@ nodejs_binary( configuration_env_vars = ["BAZEL_INTEGRATION_TEST_DEBUG"], data = ["@npm//tmp"], entry_point = ":test_runner.js", - templated_args = [ - #"--bazel_patch_module_resolver", - "--node_options=--max-old-space-size=1024", - ], + templated_args = ["--node_options=--max-old-space-size=1024"], ) filegroup( diff --git a/internal/linker/test/local/BUILD.bazel b/internal/linker/test/local/BUILD.bazel index 041d7b4194..27712aacf6 100644 --- a/internal/linker/test/local/BUILD.bazel +++ b/internal/linker/test/local/BUILD.bazel @@ -4,5 +4,6 @@ jasmine_node_test( name = "test", srcs = ["test.js"], tags = ["local"], + templated_args = ["--nobazel_patch_module_resolver"], deps = ["//internal/linker/test/local/fit"], ) diff --git a/internal/linker/test/workspace_link/BUILD.bazel b/internal/linker/test/workspace_link/BUILD.bazel index 560829fd3c..3dd30cd4e5 100644 --- a/internal/linker/test/workspace_link/BUILD.bazel +++ b/internal/linker/test/workspace_link/BUILD.bazel @@ -4,6 +4,7 @@ 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", diff --git a/internal/node/test/BUILD.bazel b/internal/node/test/BUILD.bazel index 414c76b16c..ea1c999313 100644 --- a/internal/node/test/BUILD.bazel +++ b/internal/node/test/BUILD.bazel @@ -338,6 +338,14 @@ jasmine_node_test( "dir_output", "minified.js", ], + # Turn on the linker & turn off require patches so that the external workspace jasmine_node_test + # entry point npm/@bazel/jasmine/jasmine_runner.js's require('@bazel/jasmine') is exercised without + # require patches. + templated_args = select({ + # TODO: fix this linker assertion on Windows + "@bazel_tools//src/conditions:host_windows": [], + "//conditions:default": ["--nobazel_patch_module_resolver"], + }), ) [nodejs_toolchain_test( @@ -490,4 +498,5 @@ nodejs_test( name = "main_test", data = [":main_lib"], entry_point = ":main.js", + templated_args = ["--nobazel_patch_module_resolver"], ) diff --git a/internal/npm_install/generate_build_file.ts b/internal/npm_install/generate_build_file.ts index 8be2e66571..6edcd80206 100644 --- a/internal/npm_install/generate_build_file.ts +++ b/internal/npm_install/generate_build_file.ts @@ -1069,7 +1069,8 @@ export function printPackageBin(pkg: Dep) { nodejs_binary( name = "${name}", entry_point = "//:node_modules/${pkg._dir}/${path}", - data = [${data.map(p => `"${p}"`).join(', ')}],${additionalAttributes(pkg, name)} + data = [${data.map(p => `"${p}"`).join(', ')}], + templated_args = ["--nobazel_patch_module_resolver"],${additionalAttributes(pkg, name)} ) `; } @@ -1104,7 +1105,8 @@ def ${name.replace(/-/g, '_')}(**kwargs): nodejs_binary( entry_point = "@${WORKSPACE}//:node_modules/${pkg._dir}/${path}", data = [${data.map(p => `"${p}"`).join(', ')}] + kwargs.pop("data", []), - templated_args = kwargs.pop("templated_args", []),${additionalAttributes(pkg, name)} + templated_args = ["--nobazel_patch_module_resolver"] + kwargs.pop("templated_args", []),${ + additionalAttributes(pkg, name)} **kwargs ) @@ -1113,7 +1115,8 @@ def ${name.replace(/-/g, '_')}_test(**kwargs): nodejs_test( entry_point = "@${WORKSPACE}//:node_modules/${pkg._dir}/${path}", data = [${data.map(p => `"${p}"`).join(', ')}] + kwargs.pop("data", []), - templated_args = kwargs.pop("templated_args", []),${additionalAttributes(pkg, name)} + templated_args = ["--nobazel_patch_module_resolver"] + kwargs.pop("templated_args", []),${ + additionalAttributes(pkg, name)} **kwargs ) `; diff --git a/internal/npm_install/index.js b/internal/npm_install/index.js index 8f484b9ea7..03f67eb6fc 100644 --- a/internal/npm_install/index.js +++ b/internal/npm_install/index.js @@ -641,7 +641,8 @@ function printPackageBin(pkg) { nodejs_binary( name = "${name}", entry_point = "//:node_modules/${pkg._dir}/${path}", - data = [${data.map(p => `"${p}"`).join(', ')}],${additionalAttributes(pkg, name)} + data = [${data.map(p => `"${p}"`).join(', ')}], + templated_args = ["--nobazel_patch_module_resolver"],${additionalAttributes(pkg, name)} ) `; } @@ -673,7 +674,7 @@ def ${name.replace(/-/g, '_')}(**kwargs): nodejs_binary( entry_point = "@${WORKSPACE}//:node_modules/${pkg._dir}/${path}", data = [${data.map(p => `"${p}"`).join(', ')}] + kwargs.pop("data", []), - templated_args = kwargs.pop("templated_args", []),${additionalAttributes(pkg, name)} + templated_args = ["--nobazel_patch_module_resolver"] + kwargs.pop("templated_args", []),${additionalAttributes(pkg, name)} **kwargs ) @@ -682,7 +683,7 @@ def ${name.replace(/-/g, '_')}_test(**kwargs): nodejs_test( entry_point = "@${WORKSPACE}//:node_modules/${pkg._dir}/${path}", data = [${data.map(p => `"${p}"`).join(', ')}] + kwargs.pop("data", []), - templated_args = kwargs.pop("templated_args", []),${additionalAttributes(pkg, name)} + templated_args = ["--nobazel_patch_module_resolver"] + kwargs.pop("templated_args", []),${additionalAttributes(pkg, name)} **kwargs ) `; diff --git a/internal/npm_install/test/golden/@gregmagolan/test-a/bin/BUILD.bazel.golden b/internal/npm_install/test/golden/@gregmagolan/test-a/bin/BUILD.bazel.golden index b78ca2cd65..92d22a1dbf 100644 --- a/internal/npm_install/test/golden/@gregmagolan/test-a/bin/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/@gregmagolan/test-a/bin/BUILD.bazel.golden @@ -5,4 +5,5 @@ nodejs_binary( name = "test", entry_point = "//:node_modules/@gregmagolan/test-a/@bin/test.js", data = ["//@gregmagolan/test-a:test-a"], + templated_args = ["--nobazel_patch_module_resolver"], ) diff --git a/internal/npm_install/test/golden/@gregmagolan/test-a/index.bzl.golden b/internal/npm_install/test/golden/@gregmagolan/test-a/index.bzl.golden index a386d4ac6b..bd6420ee64 100644 --- a/internal/npm_install/test/golden/@gregmagolan/test-a/index.bzl.golden +++ b/internal/npm_install/test/golden/@gregmagolan/test-a/index.bzl.golden @@ -7,13 +7,13 @@ def test(**kwargs): nodejs_binary( entry_point = "@fine_grained_goldens//:node_modules/@gregmagolan/test-a/@bin/test.js", data = ["@fine_grained_goldens//@gregmagolan/test-a:test-a"] + kwargs.pop("data", []), - templated_args = kwargs.pop("templated_args", []), + templated_args = ["--nobazel_patch_module_resolver"] + kwargs.pop("templated_args", []), **kwargs ) def test_test(**kwargs): nodejs_test( entry_point = "@fine_grained_goldens//:node_modules/@gregmagolan/test-a/@bin/test.js", data = ["@fine_grained_goldens//@gregmagolan/test-a:test-a"] + kwargs.pop("data", []), - templated_args = kwargs.pop("templated_args", []), + templated_args = ["--nobazel_patch_module_resolver"] + kwargs.pop("templated_args", []), **kwargs ) diff --git a/internal/npm_install/test/golden/jasmine/bin/BUILD.bazel.golden b/internal/npm_install/test/golden/jasmine/bin/BUILD.bazel.golden index 9748049b8a..b1b65eb5de 100644 --- a/internal/npm_install/test/golden/jasmine/bin/BUILD.bazel.golden +++ b/internal/npm_install/test/golden/jasmine/bin/BUILD.bazel.golden @@ -5,4 +5,5 @@ nodejs_binary( name = "jasmine", entry_point = "//:node_modules/jasmine/bin/jasmine.js", data = ["//jasmine:jasmine"], + templated_args = ["--nobazel_patch_module_resolver"], ) diff --git a/internal/npm_install/test/golden/jasmine/index.bzl.golden b/internal/npm_install/test/golden/jasmine/index.bzl.golden index ec701d22ec..95c02cce05 100644 --- a/internal/npm_install/test/golden/jasmine/index.bzl.golden +++ b/internal/npm_install/test/golden/jasmine/index.bzl.golden @@ -7,13 +7,13 @@ def jasmine(**kwargs): nodejs_binary( entry_point = "@fine_grained_goldens//:node_modules/jasmine/bin/jasmine.js", data = ["@fine_grained_goldens//jasmine:jasmine"] + kwargs.pop("data", []), - templated_args = kwargs.pop("templated_args", []), + templated_args = ["--nobazel_patch_module_resolver"] + kwargs.pop("templated_args", []), **kwargs ) def jasmine_test(**kwargs): nodejs_test( entry_point = "@fine_grained_goldens//:node_modules/jasmine/bin/jasmine.js", data = ["@fine_grained_goldens//jasmine:jasmine"] + kwargs.pop("data", []), - templated_args = kwargs.pop("templated_args", []), + templated_args = ["--nobazel_patch_module_resolver"] + kwargs.pop("templated_args", []), **kwargs ) diff --git a/internal/pkg_npm/test/directory/BUILD.bazel b/internal/pkg_npm/test/directory/BUILD.bazel index 7e3daf4d29..25501a5e65 100644 --- a/internal/pkg_npm/test/directory/BUILD.bazel +++ b/internal/pkg_npm/test/directory/BUILD.bazel @@ -22,4 +22,5 @@ nodejs_test( ":folder_pkg", ], entry_point = "main.js", + templated_args = ["--nobazel_patch_module_resolver"], ) diff --git a/internal/pkg_npm/test/linking/BUILD.bazel b/internal/pkg_npm/test/linking/BUILD.bazel index 858ae60920..f4a5673248 100644 --- a/internal/pkg_npm/test/linking/BUILD.bazel +++ b/internal/pkg_npm/test/linking/BUILD.bazel @@ -86,4 +86,5 @@ nodejs_test( "//internal/pkg_npm/test/linking/fuz:scoped_fuz", ], entry_point = ":main.js", + templated_args = ["--nobazel_patch_module_resolver"], ) diff --git a/internal/providers/node_runtime_deps_info.bzl b/internal/providers/node_runtime_deps_info.bzl index bf22fe7a08..e08fef2bb8 100644 --- a/internal/providers/node_runtime_deps_info.bzl +++ b/internal/providers/node_runtime_deps_info.bzl @@ -112,6 +112,11 @@ def run_node(ctx, inputs, arguments, executable, **kwargs): add_arg(arguments, "--bazel_capture_exit_code=%s" % exit_code_file.path) outputs = outputs + [exit_code_file] + # By using the run_node helper, you suggest that your program + # doesn't implicitly use runfiles to require() things + # To access runfiles, you must use a runfiles helper in the program instead + add_arg(arguments, "--nobazel_patch_module_resolver") + env = kwargs.pop("env", {}) # Always forward the COMPILATION_MODE to node process as an environment variable diff --git a/packages/cypress/internal/template.cypress_web_test.bzl b/packages/cypress/internal/template.cypress_web_test.bzl index 6a895493ec..77a371ab92 100644 --- a/packages/cypress/internal/template.cypress_web_test.bzl +++ b/packages/cypress/internal/template.cypress_web_test.bzl @@ -112,6 +112,7 @@ def cypress_web_test( ] + srcs, entry_point = "@build_bazel_rules_nodejs//packages/cypress:internal/run-cypress.js", templated_args = [ + "--nobazel_patch_module_resolver", "$(rootpath {config_file})".format(config_file = config_file), "$(rootpath {cypress_plugin})".format(cypress_plugin = cypress_plugin), "$(rootpath {cypress_archive})".format(cypress_archive = cypress_archive), @@ -153,6 +154,7 @@ def cypress_web_test_global_cache( ] + srcs, entry_point = "@build_bazel_rules_nodejs//packages/cypress:internal/run-cypress.js", templated_args = [ + "--nobazel_patch_module_resolver", "$(rootpath {config_file})".format(config_file = config_file), "$(rootpath {cypress_plugin})".format(cypress_plugin = cypress_plugin), ] + templated_args, diff --git a/packages/labs/test/protobufjs/BUILD.bazel b/packages/labs/test/protobufjs/BUILD.bazel index 7a89945b84..8271540814 100644 --- a/packages/labs/test/protobufjs/BUILD.bazel +++ b/packages/labs/test/protobufjs/BUILD.bazel @@ -26,7 +26,6 @@ protobufjs_ts_library( jasmine_node_test( name = "protobuf_test", srcs = [":test"], - #templated_args = ["--bazel_patch_module_resolver"], deps = [ "@npm//protobufjs", ], diff --git a/packages/rollup/install.md b/packages/rollup/install.md index 8fa7b404c1..0278e6a556 100644 --- a/packages/rollup/install.md +++ b/packages/rollup/install.md @@ -144,6 +144,7 @@ nodejs_binary( data = ["@npm//rollup:rollup"], entry_point = "@npm//:node_modules/rollup/dist/bin/rollup", templated_args = [ + "--nobazel_patch_module_resolver", "--node_options=--max-old-space-size=", ], ) diff --git a/packages/typescript/internal/ts_project.bzl b/packages/typescript/internal/ts_project.bzl index 9a61d1a77e..7a094a5f66 100644 --- a/packages/typescript/internal/ts_project.bzl +++ b/packages/typescript/internal/ts_project.bzl @@ -644,6 +644,7 @@ def ts_project_macro( ], entry_point = Label("//packages/typescript/internal/worker:worker_adapter"), templated_args = [ + "--nobazel_patch_module_resolver", "$(execpath {})".format(Label(worker_tsc_bin)), "--project", "$(execpath {})".format(tsconfig), diff --git a/packages/typescript/test/some_module/BUILD.bazel b/packages/typescript/test/some_module/BUILD.bazel index 3cb7b28c2d..a474e43bcf 100644 --- a/packages/typescript/test/some_module/BUILD.bazel +++ b/packages/typescript/test/some_module/BUILD.bazel @@ -54,7 +54,8 @@ nodejs_binary( # custom rule using the executable above via run_node # invoked via bazel build //packages/typescript/test/some_module:test -# the entry_point on the executable is resolved to the ts file - writer.ts +# as --nobazel_patch_module_resolver is added by default by run_node, the entry_point on the executable is resolved +# to the ts file - writer.ts # this works for bazel run //packages/typescript/test/some_module:writer_bin as this will patch require and resolve the # ts to js ts_write_file( diff --git a/packages/typescript/test/ts_project/a/tsconfig.json b/packages/typescript/test/ts_project/a/tsconfig.json index 2feec65a00..3e6e16dcfc 100644 --- a/packages/typescript/test/ts_project/a/tsconfig.json +++ b/packages/typescript/test/ts_project/a/tsconfig.json @@ -12,9 +12,9 @@ // (05:54:49) ERROR: C:/b/bk-windows-b4qr/bazel/rules-nodejs-nodejs/packages/typescript/test/ts_project/b/BUILD.bazel:6:1: Compiling TypeScript project packages/typescript/test/ts_project/b/tsconfig.json failed (Exit 2): tsc.bat failed: error executing command // cd C:/b/uuxnwop3/execroot/build_bazel_rules_nodejs // SET COMPILATION_MODE=fastbuild - // bazel-out/host/bin/external/npm/typescript/bin/tsc.bat -p packages/typescript/test/ts_project/b/tsconfig.json --outDir bazel-out/x64_windows-fastbuild/bin/packages/typescript/test/ts_project/b --declarationDir bazel-out/x64_windows-fastbuild/bin/packages/typescript/test/ts_project/b --bazel_node_modules_manifest=bazel-out/x64_windows-fastbuild/bin/packages/typescript/test/ts_project/b/_tsconfig.module_mappings.json + // bazel-out/host/bin/external/npm/typescript/bin/tsc.bat -p packages/typescript/test/ts_project/b/tsconfig.json --outDir bazel-out/x64_windows-fastbuild/bin/packages/typescript/test/ts_project/b --declarationDir bazel-out/x64_windows-fastbuild/bin/packages/typescript/test/ts_project/b --bazel_node_modules_manifest=bazel-out/x64_windows-fastbuild/bin/packages/typescript/test/ts_project/b/_tsconfig.module_mappings.json --nobazel_patch_module_resolver // Execution platform: @local_config_platform//:host // packages/typescript/test/ts_project/b/b.ts(1,17): error TS6305: Output file 'C:/b/uuxnwop3/execroot/build_bazel_rules_nodejs/packages/typescript/test/ts_project/a/a.d.ts' has not been built from source file 'C:/b/uuxnwop3/execroot/build_bazel_rules_nodejs/packages/typescript/test/ts_project/a/a.ts'. "outDir": "../../../../../bazel-out/x64_windows-fastbuild/bin/packages/typescript/test/ts_project/a", } -} +} \ No newline at end of file