Skip to content

Commit

Permalink
feat(builtin): add js_library JSEcmaScriptModuleInfo support (#2658)
Browse files Browse the repository at this point in the history
jbedard authored May 11, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 8ffea3e commit 5ad1596
Showing 3 changed files with 18 additions and 43 deletions.
10 changes: 10 additions & 0 deletions internal/js_library/js_library.bzl
Original file line number Diff line number Diff line change
@@ -18,10 +18,12 @@ load(
"//:providers.bzl",
"DeclarationInfo",
"ExternalNpmPackageInfo",
"JSEcmaScriptModuleInfo",
"JSModuleInfo",
"JSNamedModuleInfo",
"LinkablePackageInfo",
"declaration_info",
"js_ecma_script_module_info",
"js_module_info",
"js_named_module_info",
)
@@ -164,6 +166,7 @@ def _impl(ctx):

files_depsets = [files_depset]
npm_sources_depsets = [files_depset]
direct_ecma_script_module_depsets = [files_depset]
direct_sources_depsets = [files_depset]
direct_named_module_sources_depsets = [named_module_files_depset]
typings_depsets = [typings_depset]
@@ -173,6 +176,9 @@ def _impl(ctx):
if ExternalNpmPackageInfo in dep:
npm_sources_depsets.append(dep[ExternalNpmPackageInfo].sources)
else:
if JSEcmaScriptModuleInfo in dep:
direct_ecma_script_module_depsets.append(dep[JSEcmaScriptModuleInfo].direct_sources)
direct_sources_depsets.append(dep[JSEcmaScriptModuleInfo].direct_sources)
if JSModuleInfo in dep:
js_files_depsets.append(dep[JSModuleInfo].direct_sources)
direct_sources_depsets.append(dep[JSModuleInfo].direct_sources)
@@ -196,6 +202,10 @@ def _impl(ctx):
),
),
AmdNamesInfo(names = ctx.attr.amd_names),
js_ecma_script_module_info(
sources = depset(transitive = direct_ecma_script_module_depsets),
deps = ctx.attr.deps,
),
js_module_info(
sources = depset(transitive = js_files_depsets),
deps = ctx.attr.deps,
48 changes: 6 additions & 42 deletions packages/esbuild/test/typescript/bundle.golden.txt
Original file line number Diff line number Diff line change
@@ -1,59 +1,23 @@
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
var __name = (target, value) => __defProp(target, "name", {value, configurable: true});
var __commonJS = (cb, mod) => () => (mod || cb((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 require_module_dynamic = __commonJS((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("build_bazel_rules_nodejs/packages/esbuild/test/typescript/module-dynamic/index", ["require", "exports"], factory);
}
})(function(require2, exports2) {
"use strict";
Object.defineProperty(exports2, "__esModule", {value: true});
exports2.getId = void 0;
exports2.getId = () => "dynamic-id";
});
});


var import_module_dynamic = __toModule(require_module_dynamic());
var getId = /* @__PURE__ */ __name(() => "dynamic-id", "getId");


var getId = /* @__PURE__ */ __name(() => "module-one", "getId");
var getId2 = /* @__PURE__ */ __name(() => "module-one", "getId");


var getId2 = /* @__PURE__ */ __name(() => "module-two", "getId");
var getId3 = /* @__PURE__ */ __name(() => "module-two", "getId");


var getId3 = /* @__PURE__ */ __name(() => `generated-module`, "getId");
var getId4 = /* @__PURE__ */ __name(() => `generated-module`, "getId");


var getId4 = /* @__PURE__ */ __name(() => "relative-module", "getId");
var getId5 = /* @__PURE__ */ __name(() => "relative-module", "getId");


var ID = `Full ID: ${getId()} - ${getId2()} - ${(0, import_module_dynamic.getId)()} - ${getId4()} - ${getId3()}`;
var ID = `Full ID: ${getId2()} - ${getId3()} - ${getId()} - ${getId5()} - ${getId4()}`;
console.log(ID);
export {
ID
3 changes: 2 additions & 1 deletion packages/rollup/rollup_bundle.bzl
Original file line number Diff line number Diff line change
@@ -254,7 +254,8 @@ def _rollup_bundle(ctx):
for dep in ctx.attr.deps:
if JSEcmaScriptModuleInfo in dep:
deps_depsets.append(dep[JSEcmaScriptModuleInfo].sources)
elif JSModuleInfo in dep:

if JSModuleInfo in dep:
deps_depsets.append(dep[JSModuleInfo].sources)
elif hasattr(dep, "files"):
deps_depsets.append(dep.files)

0 comments on commit 5ad1596

Please sign in to comment.