diff --git a/examples/angular_view_engine/BUILD.bazel b/examples/angular_view_engine/BUILD.bazel index 0bccf0762c..270d7480a0 100644 --- a/examples/angular_view_engine/BUILD.bazel +++ b/examples/angular_view_engine/BUILD.bazel @@ -1,3 +1,5 @@ +load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm") + package(default_visibility = ["//:__subpackages__"]) # ts_library and ng_module use the `//:tsconfig.json` target @@ -13,3 +15,23 @@ sh_test( name = "dummy_test", srcs = ["dummy_test.sh"], ) + +# Here we selectively chose which files to include in node_modules/examples_angular_view_engine +# as node_modules/examples_angular_view_engine is no longer automatically linke to the root of bazel-bin. +# Because ngfactory files are generated with absolute `examples_angular_view_engine/` imports, we need +# to ensure all the files that these imports reference are available under +# node_modules/examples_angular_view_engine for rollup_bundle to find. +pkg_npm( + name = "examples_angular_view_engine", + package_name = "examples_angular_view_engine", + deps = [ + "//src:src_esm", + "//src/app:app_esm", + "//src/app/hello-world:hello-world_esm", + "//src/app/home:home_esm", + "//src/app/todos:todos_esm", + "//src/app/todos/reducers:reducers_esm", + "//src/lib/typography:typography_esm", + "//src/shared/material:material_esm", + ], +) diff --git a/examples/angular_view_engine/src/BUILD.bazel b/examples/angular_view_engine/src/BUILD.bazel index acb8129441..cec783340c 100644 --- a/examples/angular_view_engine/src/BUILD.bazel +++ b/examples/angular_view_engine/src/BUILD.bazel @@ -60,6 +60,12 @@ ng_module( ], ) +filegroup( + name = "src_esm", + srcs = [":src"], + output_group = "es6_sources", +) + filegroup( name = "rxjs_umd_modules", srcs = [ @@ -137,6 +143,7 @@ rollup_bundle( }, output_dir = True, deps = [ + "//:examples_angular_view_engine", "//src", "@npm//rollup-plugin-amd", "@npm//rollup-plugin-commonjs", diff --git a/examples/angular_view_engine/src/app/BUILD.bazel b/examples/angular_view_engine/src/app/BUILD.bazel index 08093a112e..02b9e24fd4 100644 --- a/examples/angular_view_engine/src/app/BUILD.bazel +++ b/examples/angular_view_engine/src/app/BUILD.bazel @@ -26,3 +26,9 @@ ng_module( "@npm//@ngrx/store", ], ) + +filegroup( + name = "app_esm", + srcs = [":app"], + output_group = "es6_sources", +) diff --git a/examples/angular_view_engine/src/app/hello-world/BUILD.bazel b/examples/angular_view_engine/src/app/hello-world/BUILD.bazel index 33c977abc3..20e106eed2 100644 --- a/examples/angular_view_engine/src/app/hello-world/BUILD.bazel +++ b/examples/angular_view_engine/src/app/hello-world/BUILD.bazel @@ -38,6 +38,12 @@ ng_module( ], ) +filegroup( + name = "hello-world_esm", + srcs = [":hello-world"], + output_group = "es6_sources", +) + ts_library( name = "test_lib", testonly = 1, diff --git a/examples/angular_view_engine/src/app/home/BUILD.bazel b/examples/angular_view_engine/src/app/home/BUILD.bazel index e88628c8e5..700df35b57 100644 --- a/examples/angular_view_engine/src/app/home/BUILD.bazel +++ b/examples/angular_view_engine/src/app/home/BUILD.bazel @@ -12,3 +12,9 @@ ng_module( "@npm//@angular/router", ], ) + +filegroup( + name = "home_esm", + srcs = [":home"], + output_group = "es6_sources", +) diff --git a/examples/angular_view_engine/src/app/todos/BUILD.bazel b/examples/angular_view_engine/src/app/todos/BUILD.bazel index e35ec0d7a7..7301e7d0c4 100644 --- a/examples/angular_view_engine/src/app/todos/BUILD.bazel +++ b/examples/angular_view_engine/src/app/todos/BUILD.bazel @@ -35,3 +35,9 @@ ng_module( "@npm//rxjs", ], ) + +filegroup( + name = "todos_esm", + srcs = [":todos"], + output_group = "es6_sources", +) diff --git a/examples/angular_view_engine/src/app/todos/reducers/BUILD.bazel b/examples/angular_view_engine/src/app/todos/reducers/BUILD.bazel index eddd3de3e9..9ede71c5ee 100644 --- a/examples/angular_view_engine/src/app/todos/reducers/BUILD.bazel +++ b/examples/angular_view_engine/src/app/todos/reducers/BUILD.bazel @@ -9,3 +9,9 @@ ts_library( "@npm//@ngrx/store", ], ) + +filegroup( + name = "reducers_esm", + srcs = [":reducers"], + output_group = "es6_sources", +) diff --git a/examples/angular_view_engine/src/lib/typography/BUILD.bazel b/examples/angular_view_engine/src/lib/typography/BUILD.bazel index c84729d253..3c03c3478d 100644 --- a/examples/angular_view_engine/src/lib/typography/BUILD.bazel +++ b/examples/angular_view_engine/src/lib/typography/BUILD.bazel @@ -11,3 +11,9 @@ ng_module( "@npm//@angular/core", ], ) + +filegroup( + name = "typography_esm", + srcs = [":typography"], + output_group = "es6_sources", +) diff --git a/examples/angular_view_engine/src/shared/material/BUILD.bazel b/examples/angular_view_engine/src/shared/material/BUILD.bazel index 9dec0e57b5..74f77d039f 100644 --- a/examples/angular_view_engine/src/shared/material/BUILD.bazel +++ b/examples/angular_view_engine/src/shared/material/BUILD.bazel @@ -17,3 +17,9 @@ ng_module( "@npm//@angular/material", ], ) + +filegroup( + name = "material_esm", + srcs = [":material"], + output_group = "es6_sources", +) diff --git a/examples/protocol_buffers/BUILD.bazel b/examples/protocol_buffers/BUILD.bazel index c42dba665e..86470b8771 100644 --- a/examples/protocol_buffers/BUILD.bazel +++ b/examples/protocol_buffers/BUILD.bazel @@ -5,6 +5,7 @@ load("@npm//@bazel/rollup:index.bzl", "rollup_bundle") load("@npm//@bazel/terser:index.bzl", "terser_minified") load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_devserver", "ts_library") load("@npm//http-server:index.bzl", "http_server") +load("@rules_proto//proto:defs.bzl", "proto_library") proto_library( name = "tire_proto", diff --git a/examples/protocol_buffers/app.ts b/examples/protocol_buffers/app.ts index c6d3d171a9..392a05c6dd 100644 --- a/examples/protocol_buffers/app.ts +++ b/examples/protocol_buffers/app.ts @@ -1,5 +1,5 @@ -import {CarServiceClient} from 'examples_protocol_buffers/car_grpc_web_pb'; -import {Car} from 'examples_protocol_buffers/car_pb'; +import {CarServiceClient} from './car_grpc_web_pb'; +import {Car} from './car_pb'; const car = new Car(); car.setMake('Porsche'); diff --git a/examples/protocol_buffers/car.spec.ts b/examples/protocol_buffers/car.spec.ts index 6618fc1aaf..4d4713336e 100644 --- a/examples/protocol_buffers/car.spec.ts +++ b/examples/protocol_buffers/car.spec.ts @@ -1,5 +1,5 @@ -import {Car} from 'examples_protocol_buffers/car_pb'; -import {Tire} from 'examples_protocol_buffers/tire_pb'; +import {Car} from './car_pb'; +import {Tire} from './tire_pb'; describe('protocol buffers', () => { it('allows creation of an object described by proto', () => { diff --git a/internal/linker/link_node_modules.bzl b/internal/linker/link_node_modules.bzl index c2ed6de67f..0785c29720 100644 --- a/internal/linker/link_node_modules.bzl +++ b/internal/linker/link_node_modules.bzl @@ -64,13 +64,7 @@ def write_node_modules_manifest(ctx, extra_data = []): extra_data: labels to search for npm packages that need to be linked (ctx.attr.deps and ctx.attr.data will always be searched) """ - mappings = { - # We always map the workspace to itself to support absolute require like - # import from 'my_wksp/path/to/file' and it's always links to the bin_dir. - # If source files need to be required then they can be copied to the bin_dir - # with copy_to_bin. - ctx.workspace_name: ["execroot", ctx.bin_dir.path], - } + mappings = {} node_modules_root = "" # Look through data/deps attributes to find... diff --git a/internal/linker/test/integration/BUILD.bazel b/internal/linker/test/integration/BUILD.bazel index 158dfd3b25..06a7ace30c 100644 --- a/internal/linker/test/integration/BUILD.bazel +++ b/internal/linker/test/integration/BUILD.bazel @@ -41,8 +41,10 @@ sh_binary( "//internal/linker:index.js", "//internal/linker/test/integration/static_linked_pkg", "//internal/linker/test/integration/static_linked_scoped_pkg", - "@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel/tools/bash/runfiles", - "@build_bazel_rules_nodejs//toolchains/node:node_bin", + "//internal/linker/test/integration/absolute_import:index.js", + "//third_party/github.com/bazelbuild/bazel/tools/bash/runfiles", + "//toolchains/node:node_bin", + "//internal/linker:runfiles_helper.js", ], ) @@ -53,8 +55,6 @@ linked( out = "actual", program = ":run_program", deps = [ - # NB: reference the copy of index.js in the output folder - "//%s/absolute_import:copy_to_bin" % package_name(), ":run_program", # NB: Verify that a direct dep on :some_program and a transitive dep on # the same via :run_program works with the linker. These should both @@ -80,7 +80,6 @@ linked( # do not sort deps = [ # NB: reference the copy of index.js in the output folder - "//%s/absolute_import:copy_to_bin" % package_name(), # Intentinally include this before static_linked_pkg as order matters for the linker. # The order here exercises a different code path in the linker conflict resolution logic # than `example_with_conflicts_alt`. @@ -108,8 +107,6 @@ linked( program = ":run_program", # do not sort deps = [ - # NB: reference the copy of index.js in the output folder - "//%s/absolute_import:copy_to_bin" % package_name(), # NB: static_linked maps to both # ["runfiles", "build_bazel_rules_nodejs/internal/linker/test/integration/static_linked_pkg"] and # ["bin", "build_bazel_rules_nodejs/internal/linker/test/integration/static_linked_pkg"] diff --git a/internal/linker/test/integration/absolute_import/BUILD.bazel b/internal/linker/test/integration/absolute_import/BUILD.bazel index e76f5d4115..3d2f1d6cc6 100644 --- a/internal/linker/test/integration/absolute_import/BUILD.bazel +++ b/internal/linker/test/integration/absolute_import/BUILD.bazel @@ -1,8 +1,3 @@ -load("//:index.bzl", "copy_to_bin") - package(default_visibility = ["//internal/linker/test:__subpackages__"]) -copy_to_bin( - name = "copy_to_bin", - srcs = ["index.js"], -) +exports_files(["index.js"]) diff --git a/internal/linker/test/integration/program.js b/internal/linker/test/integration/program.js index 18c483d213..3a56cb9130 100644 --- a/internal/linker/test/integration/program.js +++ b/internal/linker/test/integration/program.js @@ -7,8 +7,20 @@ const t = require('transitive_static_linked'); // they should get resolved from the execroot const b = require('dynamic_linked'); const d = require('@linker_scoped/dynamic_linked'); -// We've always supported `require('my_workspace')` for absolute imports like Google does it -const c = require('build_bazel_rules_nodejs/internal/linker/test/integration/absolute_import'); + +let c; +try { + // As of 2.0, we no longer support `require('my_workspace/path/to/output/file.js')` for absolute + // imports + c = require('build_bazel_rules_nodejs/internal/linker/test/integration/absolute_import'); + console.error('should have failed'); + process.exit(1); +} catch (_) { + // You now need to use the runfiles helper library to resolve absolute workspace imports + const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']); + c = require(runfiles.resolve( + 'build_bazel_rules_nodejs/internal/linker/test/integration/absolute_import')); +} // Third-party package installed in the root node_modules const semver = require('semver'); diff --git a/internal/linker/test/integration/run_program.sh b/internal/linker/test/integration/run_program.sh index fbc4b950b7..12855e79b9 100755 --- a/internal/linker/test/integration/run_program.sh +++ b/internal/linker/test/integration/run_program.sh @@ -35,6 +35,12 @@ export VERBOSE_LOGS=1 # Too spammy for CI logs # export NODE_DEBUG=module +# Export the location of the runfiles helpers script +export BAZEL_NODE_RUNFILES_HELPER=$(rlocation "build_bazel_rules_nodejs/internal/linker/runfiles_helper.js") +if [[ "${BAZEL_NODE_RUNFILES_HELPER}" != /* ]] && [[ ! "${BAZEL_NODE_RUNFILES_HELPER}" =~ ^[A-Z]:[\\/] ]]; then + export BAZEL_NODE_RUNFILES_HELPER=$(pwd)/${BAZEL_NODE_RUNFILES_HELPER} +fi + for ARG in "$@"; do case "$ARG" in --bazel_node_modules_manifest=*) MODULES_MANIFEST="${ARG#--bazel_node_modules_manifest=}" ;; diff --git a/internal/linker/test/issue_1823/BUILD.bazel b/internal/linker/test/issue_1823/BUILD.bazel deleted file mode 100644 index 675f163f0e..0000000000 --- a/internal/linker/test/issue_1823/BUILD.bazel +++ /dev/null @@ -1,30 +0,0 @@ -load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin") -load("//packages/typescript:index.bzl", "ts_library") -load(":ts_jest_test.bzl", "ts_jest_test") - -ts_library( - name = "lib", - srcs = [ - "lib.ts", - ], - deps = [ - ], -) - -# Shenanigans for Windows which doesn't have runfiles symlinks -# We need the jest config to be in the output tree where the specs are -copy_to_bin( - name = "jest_config", - srcs = ["jest.config.js"], -) - -ts_jest_test( - name = "test", - srcs = [ - "lib.test.ts", - ], - jest_config = ":jest_config", - deps = [ - ":lib", - ], -) diff --git a/internal/linker/test/issue_1823/jest.config.js b/internal/linker/test/issue_1823/jest.config.js deleted file mode 100644 index 25c9bac510..0000000000 --- a/internal/linker/test/issue_1823/jest.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - testEnvironment: 'node', -}; diff --git a/internal/linker/test/issue_1823/ts_jest_test.bzl b/internal/linker/test/issue_1823/ts_jest_test.bzl deleted file mode 100644 index 5e76a728f2..0000000000 --- a/internal/linker/test/issue_1823/ts_jest_test.bzl +++ /dev/null @@ -1,35 +0,0 @@ -"""Simple macro around jest_test""" - -load("@npm//jest-cli:index.bzl", _jest_test = "jest_test") -load("//packages/typescript:index.bzl", "ts_library") - -def ts_jest_test(name, srcs, jest_config, deps = [], data = [], **kwargs): - """A macro around the autogenerated jest_test rule that takes typescript sources - -Uses ts_library devmode UMD output""" - - ts_library( - name = "%s_ts" % name, - srcs = srcs, - data = data, - deps = deps + ["@npm//@types/jest"], - ) - native.filegroup( - name = "%s_umd" % name, - srcs = [":%s_ts" % name], - output_group = "es5_sources", - ) - - args = [ - "--no-cache", - "--no-watchman", - "--ci", - ] - args.extend(["--config", "$$(rlocation $(rootpath %s))" % jest_config]) - - _jest_test( - name = name, - data = [jest_config, ":%s_umd" % name] + deps + data, - templated_args = args, - **kwargs - ) diff --git a/internal/linker/test/issue_1823_use_ts_library_esm/jest.config.js b/internal/linker/test/issue_1823_use_ts_library_esm/jest.config.js deleted file mode 100644 index a29201ecef..0000000000 --- a/internal/linker/test/issue_1823_use_ts_library_esm/jest.config.js +++ /dev/null @@ -1,18 +0,0 @@ -const isWindows = process.platform === 'win32'; - -module.exports = { - testEnvironment: 'node', - transform: {'^.+\\.mjs?$': 'babel-jest'}, - // More Shenanigans for Windows where jest is running both the original .mjs & the babel - // transformed .js and fails. Not sure what why this is the case or exactly why changing - // testMatch solves it but not a priority to solve: - // ``` - // PASS ../../lib.test.js - // FAIL ../../lib.test.mjs - // C:\b\swkzcapm\execroot\build_bazel_rules_nodejs\bazel-out\x64_windows-fastbuild\bin\internal\linker\test\issue_1823_use_ts_library_esm\lib.test.mjs:1 - // import { doStuff } from './lib'; - // ^^^^^^ - // ``` - testMatch: [isWindows ? '**/?(*.)(spec|test).js?(x)' : '**/?(*.)(spec|test).?(m)js?(x)'], - moduleFileExtensions: ['js', 'mjs'], -}; diff --git a/internal/linker/test/issue_1823_use_ts_library_esm/lib.test.ts b/internal/linker/test/issue_1823_use_ts_library_esm/lib.test.ts deleted file mode 100644 index 0ea73f6237..0000000000 --- a/internal/linker/test/issue_1823_use_ts_library_esm/lib.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import {doStuff} from './lib'; - -describe('doStuff', () => { - it('should do some stuff', () => { - expect(doStuff('boom')).toContain('boom'); - }); -}); diff --git a/internal/linker/test/issue_1823_use_ts_library_esm/lib.ts b/internal/linker/test/issue_1823_use_ts_library_esm/lib.ts deleted file mode 100644 index d7318214c4..0000000000 --- a/internal/linker/test/issue_1823_use_ts_library_esm/lib.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function doStuff(a: string): string { - return a -} \ No newline at end of file diff --git a/packages/labs/grpc_web/change_import_style.js b/packages/labs/grpc_web/change_import_style.js index 45ecefae13..b849422ff6 100644 --- a/packages/labs/grpc_web/change_import_style.js +++ b/packages/labs/grpc_web/change_import_style.js @@ -13,6 +13,7 @@ */ const minimist = require('minimist'); const fs = require('fs'); +const path = require('path'); function main() { const args = minimist(process.argv.slice(2)); @@ -143,21 +144,36 @@ function convertToESM(args, initialContents) { const replaceRequiresWithImports = (contents) => { return contents .replace( - /(?:var|const|let) ([\w\d_]+) = require\((['"][\.\\]*[\w\d@/_-]+['"])\)/g, - 'import * as $1 from $2') + /(?:var|const|let) ([\w\d_]+) = require\(['"]([\.\\]*[\w\d@/_-]+)['"]\)/g, + (_, variable, importPath) => { + if (importPath.startsWith(args.workspace_name)) { + importPath = `./${path.relative(args.input_base_path, importPath)}`; + } + return `import * as ${variable} from '${importPath}';` + }) .replace( - /([\.\w\d_]+) = require\((['"][\.\w\d@/_-]+['"])\)/g, (_, variable, importPath) => { + /([\.\w\d_]+) = require\(['"]([\.\w\d@/_-]+)['"]\)/g, (_, variable, importPath) => { + if (importPath.startsWith(args.workspace_name)) { + importPath = `./${path.relative(args.input_base_path, importPath)}`; + } + const normalizedVariable = variable.replace(/\./g, '_'); - return `import * as ${normalizedVariable} from ${importPath};\n${variable} = {...${ + return `import * as ${normalizedVariable} from '${importPath}';\n${variable} = {...${ normalizedVariable}}`; }); }; - const replaceRequiresWithSubpackageImports = (contents) => { - return contents.replace( - /(?:var|const|let) ([\w\d_]+) = require\((['"][\w\d@/_-]+['"])\)\.([\w\d_]+);/g, - 'import * as $1 from $2;'); - }; + const replaceRequiresWithSubpackageImports = + (contents) => { + return contents.replace( + /(?:var|const|let) ([\w\d_]+) = require\(['"]([\w\d@/_-]+)['"]\)\.([\w\d_]+);/g, + (_, variable, importPath) => { + if (importPath.startsWith(args.workspace_name)) { + importPath = `./${path.relative(args.input_base_path, importPath)}`; + } + return `import * as ${variable} from '${importPath}';` + }); + } const replaceCJSExportsWithECMAExports = (contents) => { return contents.replace(/exports\.([\w\d_]+) = .*;/g, 'export { $1 };'); diff --git a/packages/labs/test/grpc_web/BUILD.bazel b/packages/labs/test/grpc_web/BUILD.bazel index a809c33a41..486a9237e7 100644 --- a/packages/labs/test/grpc_web/BUILD.bazel +++ b/packages/labs/test/grpc_web/BUILD.bazel @@ -81,11 +81,8 @@ karma_web_test_suite( rollup_bundle( name = "test_es6_bundling", config_file = "rollup.config.js", - entry_points = { - ":test_bundling.ts": "index", - }, + entry_point = ":test_bundling.ts", format = "cjs", - output_dir = True, deps = [ ":test_bundling_lib", "@npm//rollup-plugin-commonjs", @@ -105,12 +102,22 @@ ts_library( ], ) +ts_library( + name = "rollup_test_lib", + testonly = 1, + srcs = ["rollup_test.spec.ts"], + deps = [ + "@npm//@types/jasmine", + "@npm//@types/node", + ], +) + jasmine_node_test( name = "rollup_test", - srcs = [ - ":rollup_test.spec.js", - ], data = [ ":test_es6_bundling", ], + deps = [ + ":rollup_test_lib", + ], ) diff --git a/packages/labs/test/grpc_web/commonjs_test.spec.ts b/packages/labs/test/grpc_web/commonjs_test.spec.ts index e49d23e71c..1ae0fbf68f 100644 --- a/packages/labs/test/grpc_web/commonjs_test.spec.ts +++ b/packages/labs/test/grpc_web/commonjs_test.spec.ts @@ -1,5 +1,5 @@ -import deliveryPersonPb = require('build_bazel_rules_nodejs/packages/labs/test/grpc_web/proto/common/delivery_person_pb'); -import {PizzaServiceClient} from 'build_bazel_rules_nodejs/packages/labs/test/grpc_web/proto/pizza_service_grpc_web_pb'; +import deliveryPersonPb = require('./proto/common/delivery_person_pb'); +import {PizzaServiceClient} from './proto/pizza_service_grpc_web_pb'; describe('CommonJs', () => { it('Loads imports using require()', () => { diff --git a/packages/labs/test/grpc_web/pizza_service_proto_test.spec.ts b/packages/labs/test/grpc_web/pizza_service_proto_test.spec.ts index 9fa649a54f..183b846443 100644 --- a/packages/labs/test/grpc_web/pizza_service_proto_test.spec.ts +++ b/packages/labs/test/grpc_web/pizza_service_proto_test.spec.ts @@ -1,8 +1,8 @@ import 'google-protobuf'; -import {Pizza, PizzaSize} from 'build_bazel_rules_nodejs/packages/labs/test/grpc_web/proto/common/pizza_pb'; -import {PizzaServiceClient} from 'build_bazel_rules_nodejs/packages/labs/test/grpc_web/proto/pizza_service_grpc_web_pb'; -import {OrderPizzaRequest, OrderPizzaResponse} from 'build_bazel_rules_nodejs/packages/labs/test/grpc_web/proto/pizza_service_pb'; +import {Pizza, PizzaSize} from './proto/common/pizza_pb'; +import {PizzaServiceClient} from './proto/pizza_service_grpc_web_pb'; +import {OrderPizzaRequest, OrderPizzaResponse} from './proto/pizza_service_pb'; declare function require(module: string): any; @@ -27,8 +27,7 @@ describe('DeliveryPerson', () => { }); it('delivery_person_ts_proto is included since it is a transitive dependency', () => { - const PROTOS = require( - 'build_bazel_rules_nodejs/packages/labs/test/grpc_web/proto/common/delivery_person_pb'); + const PROTOS = require('./proto/common/delivery_person_pb'); const DeliveryPerson = PROTOS.DeliveryPerson; const pizza = new Pizza(); pizza.setSize(PizzaSize.PIZZA_SIZE_LARGE); diff --git a/packages/labs/test/grpc_web/rollup_test.spec.js b/packages/labs/test/grpc_web/rollup_test.spec.ts similarity index 82% rename from packages/labs/test/grpc_web/rollup_test.spec.js rename to packages/labs/test/grpc_web/rollup_test.spec.ts index ae0bf36661..1ee2d9a58d 100644 --- a/packages/labs/test/grpc_web/rollup_test.spec.js +++ b/packages/labs/test/grpc_web/rollup_test.spec.ts @@ -1,16 +1,14 @@ const grpcWeb = require('grpc-web'); grpcWeb.MethodType = { - UNARY: 'unary' + UNARY: 'unary', }; -const bundle = require('build_bazel_rules_nodejs/packages/labs/test/grpc_web/test_es6_bundling/'); +const bundle = require('./test_es6_bundling'); describe('Rollup', () => { it('should define Pizza with protobuf API', () => { expect(bundle.Pizza).toBeDefined(); - const pizza = new bundle.Pizza(); pizza.setSize(bundle.PizzaSize.PIZZA_SIZE_LARGE); - expect(pizza.getSize()).toBe(bundle.PizzaSize.PIZZA_SIZE_LARGE); expect(Array.isArray(pizza.getToppingIdsList())).toBe(true); }); diff --git a/packages/labs/test/grpc_web/test_bundling.ts b/packages/labs/test/grpc_web/test_bundling.ts index f8cb156b0b..96aafb885f 100644 --- a/packages/labs/test/grpc_web/test_bundling.ts +++ b/packages/labs/test/grpc_web/test_bundling.ts @@ -1,2 +1,2 @@ -export {DeliveryPerson} from 'build_bazel_rules_nodejs/packages/labs/test/grpc_web/proto/common/delivery_person_pb'; -export {Pizza, PizzaSize} from 'build_bazel_rules_nodejs/packages/labs/test/grpc_web/proto/common/pizza_pb'; +export {DeliveryPerson} from './proto/common/delivery_person_pb'; +export {Pizza, PizzaSize} from './proto/common/pizza_pb'; diff --git a/internal/linker/test/issue_1823_use_ts_library_esm/.babelrc b/packages/typescript/test/ts_library_esm_with_jest/.babelrc similarity index 100% rename from internal/linker/test/issue_1823_use_ts_library_esm/.babelrc rename to packages/typescript/test/ts_library_esm_with_jest/.babelrc diff --git a/internal/linker/test/issue_1823_use_ts_library_esm/BUILD.bazel b/packages/typescript/test/ts_library_esm_with_jest/BUILD.bazel similarity index 100% rename from internal/linker/test/issue_1823_use_ts_library_esm/BUILD.bazel rename to packages/typescript/test/ts_library_esm_with_jest/BUILD.bazel diff --git a/packages/typescript/test/ts_library_esm_with_jest/jest.config.js b/packages/typescript/test/ts_library_esm_with_jest/jest.config.js new file mode 100644 index 0000000000..e153404932 --- /dev/null +++ b/packages/typescript/test/ts_library_esm_with_jest/jest.config.js @@ -0,0 +1,6 @@ +module.exports = { + testEnvironment: 'node', + transform: {'^.+\\.mjs?$': ['babel-jest', {configFile: __dirname + '/.babelrc'}]}, + testMatch: ['**/?(*.)(spec|test).?(m)js?(x)'], + moduleFileExtensions: ['js', 'mjs'], +}; diff --git a/internal/linker/test/issue_1823/lib.test.ts b/packages/typescript/test/ts_library_esm_with_jest/lib.test.ts similarity index 100% rename from internal/linker/test/issue_1823/lib.test.ts rename to packages/typescript/test/ts_library_esm_with_jest/lib.test.ts diff --git a/internal/linker/test/issue_1823/lib.ts b/packages/typescript/test/ts_library_esm_with_jest/lib.ts similarity index 100% rename from internal/linker/test/issue_1823/lib.ts rename to packages/typescript/test/ts_library_esm_with_jest/lib.ts diff --git a/internal/linker/test/issue_1823_use_ts_library_esm/ts_jest_test.bzl b/packages/typescript/test/ts_library_esm_with_jest/ts_jest_test.bzl similarity index 81% rename from internal/linker/test/issue_1823_use_ts_library_esm/ts_jest_test.bzl rename to packages/typescript/test/ts_library_esm_with_jest/ts_jest_test.bzl index 92f39313c5..4c531eedb3 100644 --- a/internal/linker/test/issue_1823_use_ts_library_esm/ts_jest_test.bzl +++ b/packages/typescript/test/ts_library_esm_with_jest/ts_jest_test.bzl @@ -6,7 +6,7 @@ load("//packages/typescript:index.bzl", "ts_library") def ts_jest_test(name, srcs, jest_config, deps = [], data = [], **kwargs): """A macro around the autogenerated jest_test rule that takes typescript sources -Uses ts_library prodmode ems output""" +Uses ts_library prodmode esm output""" ts_library( name = "%s_ts" % name, @@ -16,6 +16,9 @@ Uses ts_library prodmode ems output""" # NB: hacky hidden configuration setting so that es6_sources does not include tsickle # .externs.js outputs runtime = "nodejs", + # Prevent requesting the .d.ts output as that will also produce lib.test.js + # Without sandbox (e.g. windows) that will be loaded instead of lib.test.mjs + tags = ["manual"], ) native.filegroup( name = "%s_esm" % name,