-
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 'sourcemap' option to configure sourcemap generati…
…on (#2528)
- Loading branch information
1 parent
97b3886
commit 8d0218c
Showing
4 changed files
with
150 additions
and
3 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,55 @@ | ||
load("//packages/esbuild/test:tests.bzl", "esbuild") | ||
load("//packages/jasmine:index.bzl", "jasmine_node_test") | ||
load("//packages/typescript:index.bzl", "ts_library") | ||
|
||
ts_library( | ||
name = "main", | ||
srcs = [ | ||
"main.ts", | ||
], | ||
deps = [ | ||
"@npm//@types/node", | ||
], | ||
) | ||
|
||
esbuild( | ||
name = "bundle_default", | ||
args = ["--keep-names"], | ||
entry_point = "main.ts", | ||
deps = [":main"], | ||
) | ||
|
||
esbuild( | ||
name = "bundle_inline", | ||
args = ["--keep-names"], | ||
entry_point = "main.ts", | ||
sourcemap = "inline", | ||
deps = [":main"], | ||
) | ||
|
||
esbuild( | ||
name = "bundle_external", | ||
args = ["--keep-names"], | ||
entry_point = "main.ts", | ||
sourcemap = "external", | ||
deps = [":main"], | ||
) | ||
|
||
esbuild( | ||
name = "bundle_both", | ||
args = ["--keep-names"], | ||
entry_point = "main.ts", | ||
sourcemap = "both", | ||
deps = [":main"], | ||
) | ||
|
||
jasmine_node_test( | ||
name = "bundle_test", | ||
srcs = ["bundle_test.js"], | ||
data = [ | ||
":bundle_both", | ||
":bundle_default", | ||
":bundle_external", | ||
":bundle_inline", | ||
], | ||
) |
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,62 @@ | ||
const {readFileSync, exists} = require('fs'); | ||
const path = require('path'); | ||
|
||
const helper = require(process.env.BAZEL_NODE_RUNFILES_HELPER); | ||
const locationBase = 'build_bazel_rules_nodejs/packages/esbuild/test/sourcemap/'; | ||
|
||
// Location for :bundle_default | ||
const bundleDefaultLocation = helper.resolve(path.join(locationBase, 'bundle_default.js')); | ||
const bundleDefaultSourcemapLocation = | ||
helper.resolve(path.join(locationBase, 'bundle_default.js.map')); | ||
|
||
// Location for :bundle_inline | ||
const bundleInlineLocation = helper.resolve(path.join(locationBase, 'bundle_inline.js')); | ||
|
||
// Location for :bundle_external | ||
const bundleExternalLocation = helper.resolve(path.join(locationBase, 'bundle_external.js')); | ||
const bundleExternalSourcemapLocation = | ||
helper.resolve(path.join(locationBase, 'bundle_external.js.map')); | ||
|
||
// Location for :bundle_both | ||
const bundleBothLocation = helper.resolve(path.join(locationBase, 'bundle_both.js')); | ||
const bundleBothSourcemapLocation = helper.resolve(path.join(locationBase, 'bundle_both.js.map')); | ||
|
||
describe('esbuild sourcemap', () => { | ||
it('creates an external sourcemap by default', () => { | ||
const sourcemap = readFileSync(bundleDefaultSourcemapLocation, {encoding: 'utf8'}); | ||
expect(sourcemap).toContain( | ||
'"sources": ["../../../../../../../packages/esbuild/test/sourcemap/main.ts"]'); | ||
}); | ||
|
||
it('does not inline the sourcemap by default', () => { | ||
const bundle = readFileSync(bundleDefaultLocation, {encoding: 'utf8'}); | ||
expect(bundle).toContain('//# sourceMappingURL=bundle_default.js.map'); | ||
}); | ||
|
||
it('inlines the sourcemap when set to \'inline\'', () => { | ||
const bundle = readFileSync(bundleInlineLocation, {encoding: 'utf8'}); | ||
expect(bundle).toContain('//# sourceMappingURL=data:application/json;base64'); | ||
}); | ||
|
||
it('has no sourcemap comment when set to \'external\'', () => { | ||
const bundle = readFileSync(bundleExternalLocation, {encoding: 'utf8'}); | ||
expect(bundle).not.toContain('//# sourceMappingURL='); | ||
}); | ||
|
||
it('creates an external sourcemap when set to \'external\'', () => { | ||
const sourcemap = readFileSync(bundleExternalSourcemapLocation, {encoding: 'utf8'}); | ||
expect(sourcemap).toContain( | ||
'"sources": ["../../../../../../../packages/esbuild/test/sourcemap/main.ts"]'); | ||
}); | ||
|
||
it('inlines the sourcemap when set to \'both\'', () => { | ||
const bundle = readFileSync(bundleInlineLocation, {encoding: 'utf8'}); | ||
expect(bundle).toContain('//# sourceMappingURL=data:application/json;base64'); | ||
}); | ||
|
||
it('creates an external sourcemap when set to \'both\'', () => { | ||
const sourcemap = readFileSync(bundleDefaultSourcemapLocation, {encoding: 'utf8'}); | ||
expect(sourcemap).toContain( | ||
'"sources": ["../../../../../../../packages/esbuild/test/sourcemap/main.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,8 @@ | ||
export interface Foo { | ||
x: number, y: string, | ||
} | ||
|
||
export const foo: Foo = { | ||
x: 123, | ||
y: 'hello', | ||
} |