-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(esbuild): add support for multiple entry points (#2663)
- Loading branch information
Showing
7 changed files
with
116 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
load("//:index.bzl", "nodejs_test") | ||
load("//packages/esbuild/test:tests.bzl", "esbuild") | ||
load("//packages/typescript:index.bzl", "ts_library") | ||
|
||
ts_library( | ||
name = "index", | ||
srcs = ["index.ts"], | ||
module_name = "lib", | ||
) | ||
|
||
ts_library( | ||
name = "lib", | ||
srcs = [ | ||
"a.ts", | ||
"b.ts", | ||
], | ||
deps = [":index"], | ||
) | ||
|
||
esbuild( | ||
name = "bundle", | ||
entry_points = [ | ||
"a.ts", | ||
"b.ts", | ||
], | ||
deps = [":lib"], | ||
) | ||
|
||
nodejs_test( | ||
name = "bundle_test", | ||
data = [ | ||
"bundle.spec.js", | ||
":bundle", | ||
], | ||
entry_point = ":bundle.spec.js", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {NAME} from 'lib'; | ||
|
||
console.log(`Hello ${NAME}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {NAME} from 'lib'; | ||
|
||
console.log(`Hello ${NAME} from b.ts`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const {join} = require('path'); | ||
const {readFileSync, lstatSync} = require('fs'); | ||
|
||
const helper = require(process.env.BAZEL_NODE_RUNFILES_HELPER); | ||
const location = helper.resolve('build_bazel_rules_nodejs/packages/esbuild/test/entries/bundle/'); | ||
|
||
const a = readFileSync(join(location, 'a.js'), {encoding: 'utf8'}); | ||
const b = readFileSync(join(location, 'b.js'), {encoding: 'utf8'}); | ||
const aHasImportOfChunk = a.match(/\/(chunk-[a-zA-Z0-9]+\.js)";/); | ||
const bHasImportOfChunk = b.match(/\/(chunk-[a-zA-Z0-9]+\.js)";/); | ||
|
||
if (!aHasImportOfChunk || !bHasImportOfChunk) { | ||
console.error(`Expected entry_points 'a.js' and 'b.js' to have an import of './chunk-[hash].js'`); | ||
} | ||
|
||
if (aHasImportOfChunk[1] !== bHasImportOfChunk[1]) { | ||
console.error(`Expected entry_points 'a.js' and 'b.js' to the same shared chunk`); | ||
} | ||
|
||
// throws if file does not exist | ||
lstatSync(join(location, aHasImportOfChunk && aHasImportOfChunk[1])); | ||
|
||
process.exit( | ||
(aHasImportOfChunk && bHasImportOfChunk && aHasImportOfChunk[1] === bHasImportOfChunk[1]) ? 0 : | ||
1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const NAME = 'bazel'; |