Skip to content

Commit

Permalink
feat(builtin): allow bundling ESM output with the pkg_npm rule (#2648)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkaillZ committed May 11, 2021
1 parent 5ad1596 commit 911529f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/pkg_npm/pkg_npm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ If all users of your library code use Bazel, they should just add your library
to the `deps` of one of their targets.
"""

load("//:providers.bzl", "DeclarationInfo", "JSModuleInfo", "LinkablePackageInfo", "NODE_CONTEXT_ATTRS", "NodeContextInfo")
load("//:providers.bzl", "DeclarationInfo", "JSEcmaScriptModuleInfo", "JSModuleInfo", "JSNamedModuleInfo", "LinkablePackageInfo", "NODE_CONTEXT_ATTRS", "NodeContextInfo")

_DOC = """The pkg_npm rule creates a directory containing a publishable npm artifact.
Expand Down Expand Up @@ -299,7 +299,15 @@ def _pkg_npm(ctx):
if JSModuleInfo in dep:
deps_files_depsets.append(dep[JSModuleInfo].sources)

# Include all transitive declerations
# All direct and transitive deps that produce CommonJS modules
if JSNamedModuleInfo in dep:
deps_files_depsets.append(dep[JSNamedModuleInfo].sources)

# All direct and transitive deps that produce ES6 modules
if JSEcmaScriptModuleInfo in dep:
deps_files_depsets.append(dep[JSEcmaScriptModuleInfo].sources)

# Include all transitive declarations
if DeclarationInfo in dep:
deps_files_depsets.append(dep[DeclarationInfo].transitive_declarations)

Expand Down
3 changes: 3 additions & 0 deletions internal/pkg_npm/test/pkg_npm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ describe('pkg_npm', () => {
it('copies declaration files from ts_library', () => {
expect(readFromPkg('foo.d.ts')).toContain('export declare const a: string;');
});
it('copies ESM files from ts_library', () => {
expect(readFromPkg('foo.mjs')).toContain('export const a = \'\';');
});
it('copies data dependencies', () => {
expect(readFromPkg('data.json')).toEqual('[]');
});
Expand Down

0 comments on commit 911529f

Please sign in to comment.