-
Notifications
You must be signed in to change notification settings - Fork 522
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 output_css flag to esbuild() (#2545)
- Loading branch information
Showing
6 changed files
with
114 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
load("//packages/esbuild/test:tests.bzl", "esbuild") | ||
load("//packages/jasmine:index.bzl", "jasmine_node_test") | ||
load("//packages/typescript:index.bzl", "ts_library") | ||
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin") | ||
|
||
copy_to_bin( | ||
name = "external_copied", | ||
srcs = ["external.css"], | ||
) | ||
|
||
ts_library( | ||
name = "dep", | ||
srcs = [ | ||
"dep.ts", | ||
], | ||
data = [ | ||
":external_copied", | ||
], | ||
deps = [ | ||
"@npm//@types/node", | ||
], | ||
) | ||
|
||
ts_library( | ||
name = "main", | ||
srcs = [ | ||
"main.ts", | ||
], | ||
deps = [ | ||
":dep", | ||
"@npm//@types/node", | ||
], | ||
) | ||
|
||
esbuild( | ||
name = "default", | ||
args = [ | ||
"--keep-names", | ||
"--resolve-extensions=.mjs,.js", | ||
], | ||
entry_point = "main.ts", | ||
deps = [ | ||
":main", | ||
], | ||
) | ||
|
||
esbuild( | ||
name = "with_css", | ||
args = [ | ||
"--keep-names", | ||
"--resolve-extensions=.mjs,.js", | ||
], | ||
entry_point = "main.ts", | ||
output_css = "with_css.css", | ||
deps = [ | ||
":main", | ||
], | ||
) | ||
|
||
jasmine_node_test( | ||
name = "bundle_test", | ||
srcs = ["bundle_test.js"], | ||
data = [ | ||
":default", | ||
":with_css", | ||
], | ||
) |
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 { readFileSync } = require("fs"); | ||
const path = require("path"); | ||
|
||
const helper = require(process.env.BAZEL_NODE_RUNFILES_HELPER); | ||
const locationBase = "build_bazel_rules_nodejs/packages/esbuild/test/css/"; | ||
|
||
const cssExpected = helper.resolve(path.join(locationBase, "with_css.css")); | ||
|
||
describe("esbuild css", () => { | ||
it("no css by default", () => { | ||
if (process.platform === "win32") { | ||
// Windows has no sandbox, and the runfiles helper will return files | ||
// that happen to exist in the folder, even if they are not declared outputs | ||
return; | ||
} | ||
expect(() => | ||
helper.resolve(path.join(locationBase, "default.css")) | ||
).toThrow(); | ||
}); | ||
|
||
it("css if requested", () => { | ||
const contents = readFileSync(cssExpected, { encoding: "utf8" }); | ||
expect(contents).toContain("external-content"); | ||
}); | ||
}); |
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 "./external.css"; | ||
|
||
export function dep() {} |
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,2 @@ | ||
.external-content { | ||
} |
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 { dep } from "./dep"; | ||
|
||
dep(); |