From bb9fd46110f85e8f3a7c1b806dd3f706e1a77b7e Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Tue, 29 Jun 2021 23:57:52 -0700 Subject: [PATCH] feat: add package_name to ts_library --- docs/Built-ins.md | 12 ++- docs/Providers.md | 5 +- docs/TypeScript.md | 26 ++++- .../patches/@angular+bazel+9.0.5.patch | 3 +- internal/js_library/js_library.bzl | 14 ++- internal/linker/link_node_modules.bzl | 96 ++++++------------- internal/pkg_npm/pkg_npm.bzl | 12 ++- internal/providers/linkable_package_info.bzl | 4 - packages/esbuild/test/bundle/BUILD.bazel | 1 + .../esbuild/test/bundle/bundle.golden.txt | 49 +++++++++- .../esbuild/test/bundle/bundle.min.golden.txt | 2 +- packages/esbuild/test/entries/BUILD.bazel | 1 + .../test/typescript/module-one/BUILD.bazel | 1 + .../test/typescript/module-two/BUILD.bazel | 1 + packages/typescript/internal/build_defs.bzl | 30 +++--- .../typescript/test/some_module/BUILD.bazel | 8 +- 16 files changed, 156 insertions(+), 109 deletions(-) diff --git a/docs/Built-ins.md b/docs/Built-ins.md index 56c3f7263c..0cc10fb57b 100755 --- a/docs/Built-ins.md +++ b/docs/Built-ins.md @@ -1193,15 +1193,19 @@ Defaults to `@build_bazel_rules_nodejs//internal:node_context_data`

package_name

-(*String*): Optional package_name that this npm package may be imported as. +(*String*): The package name that the linker will link this npm package as. + +If package_path is set, the linker will link this package under /node_modules/. +If package_path is not set the this will be the root node_modules of the workspace. Defaults to `""`

package_path

-(*String*): The directory in the workspace to link to. -If set, link this pkg_npm to the node_modules under the package path specified. -If unset, the default is to link to the node_modules root of the workspace. +(*String*): The package path in the workspace that the linker will link this npm package to. + +If package_path is set, the linker will link this package under /node_modules/. +If package_path is not set the this will be the root node_modules of the workspace. Defaults to `""` diff --git a/docs/Providers.md b/docs/Providers.md index 5c9c9ab16e..0ed690286d 100755 --- a/docs/Providers.md +++ b/docs/Providers.md @@ -168,7 +168,7 @@ Historical note: this was the typescript.es5_sources output. **USAGE**
-LinkablePackageInfo(files, package_name, package_path, path, _tslibrary)
+LinkablePackageInfo(files, package_name, package_path, path)
 
The LinkablePackageInfo provider provides information to the linker for linking pkg_npm built packages @@ -202,9 +202,6 @@ or a source file path such as, `path/to/package` or `external//path/to/package` -

_tslibrary

- - For internal use only ## NodeContextInfo diff --git a/docs/TypeScript.md b/docs/TypeScript.md index a451c15b2e..f63cf4d5ab 100755 --- a/docs/TypeScript.md +++ b/docs/TypeScript.md @@ -185,8 +185,9 @@ Defaults to `[]`
 ts_library(name, angular_assets, compiler, data, deps, devmode_module, devmode_target,
            expected_diagnostics, generate_externs, internal_testing_type_check_dependencies,
-           link_workspace_root, module_name, module_root, prodmode_module, prodmode_target, runtime,
-           runtime_deps, srcs, supports_workers, tsconfig, tsickle_typed, use_angular_plugin)
+           link_workspace_root, module_name, module_root, package_name, package_path, prodmode_module,
+           prodmode_target, runtime, runtime_deps, srcs, supports_workers, tsconfig, tsickle_typed,
+           use_angular_plugin)
 
type-check and compile a set of TypeScript sources to JavaScript. @@ -338,7 +339,8 @@ Defaults to `False` (*Boolean*): Link the workspace root to the bin_dir to support absolute requires like 'my_wksp/path/to/file'. - If source files need to be required then they can be copied to the bin_dir with copy_to_bin. + +If source files need to be required then they can be copied to the bin_dir with copy_to_bin. Defaults to `False` @@ -354,6 +356,24 @@ Defaults to `""` Defaults to `""` +

package_name

+ +(*String*): The package name that the linker will link this ts_library output as. + +If package_path is set, the linker will link this package under /node_modules/. +If package_path is not set the this will be the root node_modules of the workspace. + +Defaults to `""` + +

package_path

+ +(*String*): The package path in the workspace that the linker will link this ts_library output to. + +If package_path is set, the linker will link this package under /node_modules/. +If package_path is not set the this will be the root node_modules of the workspace. + +Defaults to `""` +

prodmode_module

(*String*): Set the typescript `module` compiler option for prodmode output. diff --git a/examples/angular_view_engine/patches/@angular+bazel+9.0.5.patch b/examples/angular_view_engine/patches/@angular+bazel+9.0.5.patch index b657db0fe0..c6a1fa7822 100644 --- a/examples/angular_view_engine/patches/@angular+bazel+9.0.5.patch +++ b/examples/angular_view_engine/patches/@angular+bazel+9.0.5.patch @@ -822,7 +822,7 @@ index a38f6a8..436d83b 100755 "NpmPackageInfo", "TsConfigInfo", "compile_ts", -@@ -629,6 +630,15 @@ def _ng_module_impl(ctx): +@@ -629,6 +630,14 @@ def _ng_module_impl(ctx): # once it is no longer needed. ]) @@ -832,7 +832,6 @@ index a38f6a8..436d83b 100755 + package_name = ctx.attr.module_name, + path = path, + files = ts_providers["typescript"]["es5_sources"], -+ _tslibrary = True, + )) + return ts_providers_dict_to_struct(ts_providers) diff --git a/internal/js_library/js_library.bzl b/internal/js_library/js_library.bzl index 6b5341e27c..58ee46e6ac 100644 --- a/internal/js_library/js_library.bzl +++ b/internal/js_library/js_library.bzl @@ -56,8 +56,18 @@ _ATTRS = { They will be copied into the package bin folder if needed.""", allow_files = True, ), - "package_name": attr.string(), - "package_path": attr.string(), + "package_name": attr.string( + doc = """The package name that the linker will link this js_library as. + +If package_path is set, the linker will link this package under /node_modules/. +If package_path is not set the this will be the root node_modules of the workspace.""", + ), + "package_path": attr.string( + doc = """The package path in the workspace that the linker will link this js_library to. + +If package_path is set, the linker will link this package under /node_modules/. +If package_path is not set the this will be the root node_modules of the workspace.""", + ), "srcs": attr.label_list(allow_files = True), "strip_prefix": attr.string( doc = "Path components to strip from the start of the package import path", diff --git a/internal/linker/link_node_modules.bzl b/internal/linker/link_node_modules.bzl index 5d30429c91..280312ad7d 100644 --- a/internal/linker/link_node_modules.bzl +++ b/internal/linker/link_node_modules.bzl @@ -39,29 +39,17 @@ def add_arg(args, arg): def _link_mapping(label, mappings, k, v): # Check that two package name mapping do not map to two different source paths package_name = k.split(":")[0] - source_path = v[1] - - # Special case for ts_library module_name for legacy behavior and for AMD name work-around - # Mapping is tagged as "__tslibrary__". - # See longer comment below in _get_module_mappings for more details. - if v[0] != "__tslibrary__": - for iter_key, iter_values in mappings.items(): - # Map key is of format "package_name:package_path" - # Map values are of format [deprecated, source_path] - iter_package_name = iter_key.split(":")[0] - iter_source_path = iter_values[1] - if iter_values[0] != "__tslibrary__" and package_name == iter_package_name and source_path != iter_source_path: - fail("conflicting mapping at '%s': '%s' and '%s' map to conflicting %s and %s" % (label, k, iter_key, source_path, iter_source_path)) - - # Allow __tslibrary__ special case to be overridden other matching mappings - if k in mappings and mappings[k] != v: - if mappings[k][0] == "__tslibrary__": - return True - elif v[0] == "__tslibrary__": - return False - fail(("conflicting mapping at '%s': '%s' maps to both %s and %s" % (label, k, mappings[k], v)), "deps") - else: - return True + link_path = v + + for iter_key, iter_values in mappings.items(): + # Map key is of format "package_name:package_path" + # Map values are of format [deprecated, link_path] + iter_package_name = iter_key.split(":")[0] + iter_source_path = iter_values + if package_name == iter_package_name and link_path != iter_source_path: + fail("conflicting mapping at '%s': '%s' and '%s' map to conflicting %s and %s" % (label, k, iter_key, link_path, iter_source_path)) + + return True def write_node_modules_manifest(ctx, extra_data = [], mnemonic = None, link_workspace_root = False): """Writes a manifest file read by the linker, containing info about resolving runtime dependencies @@ -74,7 +62,7 @@ def write_node_modules_manifest(ctx, extra_data = [], mnemonic = None, link_work If source files need to be required then they can be copied to the bin_dir with copy_to_bin. """ - mappings = {ctx.workspace_name: ["__link__", ctx.bin_dir.path]} if link_workspace_root else {} + mappings = {ctx.workspace_name: ctx.bin_dir.path} if link_workspace_root else {} node_modules_roots = {} # Look through data/deps attributes to find the root directories for the third-party node_modules; @@ -104,7 +92,7 @@ def write_node_modules_manifest(ctx, extra_data = [], mnemonic = None, link_work # Convert mappings to a module sets (modules per package package_path) # { # "package_path": { - # "package_name": "source_path", + # "package_name": "link_path", # ... # }, # ... @@ -114,10 +102,10 @@ def write_node_modules_manifest(ctx, extra_data = [], mnemonic = None, link_work map_key_split = k.split(":") package_name = map_key_split[0] package_path = map_key_split[1] if len(map_key_split) > 1 else "" - source_path = v[1] + link_path = v if package_path not in module_sets: module_sets[package_path] = {} - module_sets[package_path][package_name] = source_path + module_sets[package_path][package_name] = link_path # Write the result to a file, and use the magic node option --bazel_node_modules_manifest # The launcher.sh will peel off this argument and pass it to the linker rather than the program. @@ -135,19 +123,15 @@ def write_node_modules_manifest(ctx, extra_data = [], mnemonic = None, link_work return modules_manifest def _get_module_mappings(target, ctx): - """Returns the module_mappings from the given attrs. - - Collects a {module_name - module_root} hash from all transitive dependencies, - checking for collisions. If a module has a non-empty `module_root` attribute, - all sources underneath it are treated as if they were rooted at a folder - `module_name`. - + """Gathers module mappings from LinkablePackageInfo which maps "package_name:package_path" to link_path. + Args: target: target ctx: ctx Returns: - The module mappings + Returns module mappings of shape: + { "package_name:package_path": link_path, ... } """ mappings = {} @@ -165,50 +149,26 @@ def _get_module_mappings(target, ctx): _debug(ctx.var, "No LinkablePackageInfo for", target.label) return mappings + linkable_package_info = target[LinkablePackageInfo] + # LinkablePackageInfo may be provided without a package_name so check for that case as well - if not target[LinkablePackageInfo].package_name: + if not linkable_package_info.package_name: # No mappings contributed here, short-circuit with the transitive ones we collected _debug(ctx.var, "No package_name in LinkablePackageInfo for", target.label) return mappings - linkable_package_info = target[LinkablePackageInfo] + map_key = "%s:%s" % (linkable_package_info.package_name, linkable_package_info.package_path) + map_value = linkable_package_info.path - if hasattr(linkable_package_info, "package_path") and linkable_package_info.package_path: - mn = "%s:%s" % (linkable_package_info.package_name, linkable_package_info.package_path) - else: - # legacy (root linked) style mapping - # TODO(4.0): remove this else condition and always use "%s:%s" style - mn = linkable_package_info.package_name - mr = ["__link__", linkable_package_info.path] - - # Special case for ts_library module_name for legacy behavior and for AMD name work-around - # Tag the mapping as "__tslibrary__" so it can be overridden by any other mapping if found. - # - # In short, ts_library module_name attribute results in both setting the AMD name (which - # desired and necessary in devmode which outputs UMD) and in making a linkable mapping. Because - # of this, you can get in the situation where a ts_library module_name and a downstream pkg_name - # package_name conflict and result in duplicate mappings. This work-around will make this - # situation work however it is not a recommended pattern since a ts_library can be a dep of a - # pkg_npm but not vice-verse at the moment since ts_library cannot handle directory artifacts as - # deps. - # - # TODO(4.0): In a future major release, ts_library will get a package_name attribute to enable the linker - # and the __tslibrary__ special case can be factored out. - # This is planned for 4.0: https://github.com/bazelbuild/rules_nodejs/issues/2450. - if hasattr(linkable_package_info, "_tslibrary") and linkable_package_info._tslibrary: - mr[0] = "__tslibrary__" - - if _link_mapping(target.label, mappings, mn, mr): - _debug(ctx.var, "target %s adding module mapping %s: %s" % (target.label, mn, mr)) - mappings[mn] = mr + if _link_mapping(target.label, mappings, map_key, map_value): + _debug(ctx.var, "target %s adding module mapping %s: %s" % (target.label, map_key, map_value)) + mappings[map_key] = map_value # Returns mappings of shape: # { - # "package_name": [legacy_tslibary_usage, source_path], - # "package_name:package_path": [legacy_tslibary_usage, source_path], + # "package_name:package_path": link_path, # ... # } - # TODO(4.0): simplify to { "package_name:package_path": source_path, ... } once __tslibrary__ is no longer needed return mappings def _module_mappings_aspect_impl(target, ctx): diff --git a/internal/pkg_npm/pkg_npm.bzl b/internal/pkg_npm/pkg_npm.bzl index b97534d9b8..42bfe24205 100644 --- a/internal/pkg_npm/pkg_npm.bzl +++ b/internal/pkg_npm/pkg_npm.bzl @@ -103,12 +103,16 @@ PKG_NPM_ATTRS = dict(NODE_CONTEXT_ATTRS, **{ allow_files = True, ), "package_name": attr.string( - doc = """Optional package_name that this npm package may be imported as.""", + doc = """The package name that the linker will link this npm package as. + +If package_path is set, the linker will link this package under /node_modules/. +If package_path is not set the this will be the root node_modules of the workspace.""", ), "package_path": attr.string( - doc = """The directory in the workspace to link to. -If set, link this pkg_npm to the node_modules under the package path specified. -If unset, the default is to link to the node_modules root of the workspace.""", + doc = """The package path in the workspace that the linker will link this npm package to. + +If package_path is set, the linker will link this package under /node_modules/. +If package_path is not set the this will be the root node_modules of the workspace.""", ), "srcs": attr.label_list( doc = """Files inside this directory which are simply copied into the package.""", diff --git a/internal/providers/linkable_package_info.bzl b/internal/providers/linkable_package_info.bzl index 7e161e7faa..75a3b24d1b 100644 --- a/internal/providers/linkable_package_info.bzl +++ b/internal/providers/linkable_package_info.bzl @@ -40,9 +40,5 @@ or a source file path such as, `path/to/package` or `external//path/to/package` """, - # TODO(4.0): In a future major release, ts_library will get a package_name attribute to enable the linker - # and the _tslibrary special case can be removed. - # This is planned for 4.0: https://github.com/bazelbuild/rules_nodejs/issues/2450. - "_tslibrary": "For internal use only", }, ) diff --git a/packages/esbuild/test/bundle/BUILD.bazel b/packages/esbuild/test/bundle/BUILD.bazel index 4ce5f22c89..b2e58e2ccb 100644 --- a/packages/esbuild/test/bundle/BUILD.bazel +++ b/packages/esbuild/test/bundle/BUILD.bazel @@ -12,6 +12,7 @@ ts_library( name = "lib", srcs = ["a.ts"], deps = [":index"], + package_name = "lib", ) esbuild( diff --git a/packages/esbuild/test/bundle/bundle.golden.txt b/packages/esbuild/test/bundle/bundle.golden.txt index 5583922b8b..e68f3bbb0a 100644 --- a/packages/esbuild/test/bundle/bundle.golden.txt +++ b/packages/esbuild/test/bundle/bundle.golden.txt @@ -1,8 +1,53 @@ (() => { + var __create = Object.create; + var __defProp = Object.defineProperty; + var __getOwnPropDesc = Object.getOwnPropertyDescriptor; + var __getOwnPropNames = Object.getOwnPropertyNames; + var __getProtoOf = Object.getPrototypeOf; + var __hasOwnProp = Object.prototype.hasOwnProperty; + var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); + var __require = (x) => { + if (typeof require !== "undefined") + return require(x); + throw new Error('Dynamic require of "' + x + '" is not supported'); + }; + var __commonJS = (cb, mod) => function __require2() { + return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; + }; + var __reExport = (target, module, desc) => { + if (module && typeof module === "object" || typeof module === "function") { + for (let key of __getOwnPropNames(module)) + if (!__hasOwnProp.call(target, key) && key !== "default") + __defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable }); + } + return target; + }; + var __toModule = (module) => { + return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module); + }; + - var NAME = "bazel"; + var require_lib = __commonJS({ + "node_modules/lib/index.js"(exports, module) { + (function(factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(__require, exports); + if (v !== void 0) + module.exports = v; + } else if (typeof define === "function" && define.amd) { + define("lib", ["require", "exports"], factory); + } + })(function(require2, exports2) { + "use strict"; + Object.defineProperty(exports2, "__esModule", { value: true }); + exports2.NAME = void 0; + exports2.NAME = "bazel"; + }); + } + }); - console.log(`Hello ${NAME}`); + var import_lib = __toModule(require_lib()); + console.log(`Hello ${import_lib.NAME}`); })(); //# sourceMappingURL=bundle.js.map diff --git a/packages/esbuild/test/bundle/bundle.min.golden.txt b/packages/esbuild/test/bundle/bundle.min.golden.txt index 37e8681982..9bb8333b5a 100644 --- a/packages/esbuild/test/bundle/bundle.min.golden.txt +++ b/packages/esbuild/test/bundle/bundle.min.golden.txt @@ -1,2 +1,2 @@ -(()=>{var o="bazel";console.log(`Hello ${o}`);})(); +(()=>{var c=Object.create;var n=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var s=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var a=e=>n(e,"__esModule",{value:!0});var r=e=>{if(typeof require!="undefined")return require(e);throw new Error('Dynamic require of "'+e+'" is not supported')};var j=(e,i)=>()=>(i||e((i={exports:{}}).exports,i),i.exports);var m=(e,i,t)=>{if(i&&typeof i=="object"||typeof i=="function")for(let o of p(i))!M.call(e,o)&&o!=="default"&&n(e,o,{get:()=>i[o],enumerable:!(t=b(i,o))||t.enumerable});return e},q=e=>m(a(n(e!=null?c(s(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);var l=j((u,f)=>{(function(e){if(typeof f=="object"&&typeof f.exports=="object"){var i=e(r,u);i!==void 0&&(f.exports=i)}else typeof define=="function"&&define.amd&&define("lib",["require","exports"],e)})(function(e,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.NAME=void 0,i.NAME="bazel"})});var d=q(l());console.log(`Hello ${d.NAME}`);})(); //# sourceMappingURL=bundle.min.js.map diff --git a/packages/esbuild/test/entries/BUILD.bazel b/packages/esbuild/test/entries/BUILD.bazel index 2063a159ae..4d9dac3a33 100644 --- a/packages/esbuild/test/entries/BUILD.bazel +++ b/packages/esbuild/test/entries/BUILD.bazel @@ -5,6 +5,7 @@ load("//packages/typescript:index.bzl", "ts_library") ts_library( name = "index", srcs = ["index.ts"], + package_name = "lib", module_name = "lib", ) diff --git a/packages/esbuild/test/typescript/module-one/BUILD.bazel b/packages/esbuild/test/typescript/module-one/BUILD.bazel index de33f9b0f4..6de65c8ff0 100644 --- a/packages/esbuild/test/typescript/module-one/BUILD.bazel +++ b/packages/esbuild/test/typescript/module-one/BUILD.bazel @@ -5,6 +5,7 @@ package(default_visibility = ["//packages/esbuild/test:__subpackages__"]) ts_library( name = "module-one", srcs = [":index.ts"], + package_name = "@typescript/module-one", module_name = "@typescript/module-one", tsconfig = "//packages/esbuild/test/typescript:tsconfig.json", ) diff --git a/packages/esbuild/test/typescript/module-two/BUILD.bazel b/packages/esbuild/test/typescript/module-two/BUILD.bazel index 14f755f4f0..9a2cc57d00 100644 --- a/packages/esbuild/test/typescript/module-two/BUILD.bazel +++ b/packages/esbuild/test/typescript/module-two/BUILD.bazel @@ -5,6 +5,7 @@ package(default_visibility = ["//packages/esbuild/test:__subpackages__"]) ts_library( name = "module-two", srcs = [":index.ts"], + package_name = "@typescript/module-two", module_name = "@typescript/module-two", tsconfig = "//packages/esbuild/test/typescript:tsconfig.json", ) diff --git a/packages/typescript/internal/build_defs.bzl b/packages/typescript/internal/build_defs.bzl index f5e2fd83ed..e81df1a5c7 100644 --- a/packages/typescript/internal/build_defs.bzl +++ b/packages/typescript/internal/build_defs.bzl @@ -347,18 +347,13 @@ def _ts_library_impl(ctx): # once it is no longer needed. ]) - if ctx.attr.module_name: - path = "/".join([p for p in [ctx.bin_dir.path, ctx.label.workspace_root, ctx.label.package] if p]) + if ctx.attr.package_name: + link_path = "/".join([p for p in [ctx.bin_dir.path, ctx.label.workspace_root, ctx.label.package] if p]) ts_providers["providers"].append(LinkablePackageInfo( - package_name = ctx.attr.module_name, - # TODO(4.0): ts_library doesn't support multi-linked first party deps yet. - # it can be added in 4.0 on the next set of breaking change when we - # also add the package_name attribute to separate turning on the linker - # from the module_name attribute - package_path = "", - path = path, + package_name = ctx.attr.package_name, + package_path = ctx.attr.package_path, + path = link_path, files = ts_providers["typescript"]["es5_sources"], - _tslibrary = True, )) return ts_providers_dict_to_struct(ts_providers) @@ -434,7 +429,20 @@ This value will override the `target` option in the user supplied tsconfig.""", "internal_testing_type_check_dependencies": attr.bool(default = False, doc = "Testing only, whether to type check inputs that aren't srcs."), "link_workspace_root": attr.bool( doc = """Link the workspace root to the bin_dir to support absolute requires like 'my_wksp/path/to/file'. - If source files need to be required then they can be copied to the bin_dir with copy_to_bin.""", + +If source files need to be required then they can be copied to the bin_dir with copy_to_bin.""", + ), + "package_name": attr.string( + doc = """The package name that the linker will link this ts_library output as. + +If package_path is set, the linker will link this package under /node_modules/. +If package_path is not set the this will be the root node_modules of the workspace.""", + ), + "package_path": attr.string( + doc = """The package path in the workspace that the linker will link this ts_library output to. + +If package_path is set, the linker will link this package under /node_modules/. +If package_path is not set the this will be the root node_modules of the workspace.""", ), "prodmode_module": attr.string( doc = """Set the typescript `module` compiler option for prodmode output. diff --git a/packages/typescript/test/some_module/BUILD.bazel b/packages/typescript/test/some_module/BUILD.bazel index a56a1430ce..3ae13613ae 100644 --- a/packages/typescript/test/some_module/BUILD.bazel +++ b/packages/typescript/test/some_module/BUILD.bazel @@ -2,14 +2,14 @@ load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") load("//packages/typescript:index.bzl", "ts_library") load("//packages/typescript/test/some_module:run_node_test.bzl", "ts_write_file") -# We compile this library with the module name "sm" to make it possible to -# use `import {} from 'sm';` both at type-check time (we include the mapping in -# the paths map in tsconfig) as well as runtime (we patch the nodejs module -# loader to discover the path in the runfiles). +# We compile this library with the module_name and package_name "sm" to make it possible to use +# `import {} from 'sm';` both at type-check time (we include the module_name mapping in the paths +# map in tsconfig) as well as runtime (we link the module tonode_modules/package_name at runtime). ts_library( name = "some_module", srcs = ["index.ts"], module_name = "sm", + package_name = "sm", ) ts_library(