-
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(typescript): add devmode_target, devmode_module, prodmode_target…
… & prodmode_module attributes (#1687) This allows users control over the language level & module formats produced by both the dev and prod outputs of ts_library
- Loading branch information
1 parent
baa68c1
commit 1a83a7f
Showing
5 changed files
with
122 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
33 changes: 33 additions & 0 deletions
33
packages/typescript/test/target_module_attributes/BUILD.bazel
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,33 @@ | ||
load("@npm_bazel_jasmine//:index.from_src.bzl", "jasmine_node_test") | ||
load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library") | ||
load("//packages/typescript/test/devmode_consumer:devmode_consumer.bzl", "devmode_consumer") | ||
load("//packages/typescript/test/es6_consumer:es6_consumer.bzl", "es6_consumer") | ||
|
||
ts_library( | ||
name = "override", | ||
srcs = ["a.ts"], | ||
devmode_module = "amd", | ||
devmode_target = "es5", | ||
prodmode_module = "amd", | ||
prodmode_target = "es5", | ||
tsconfig = ":tsconfig-override.json", | ||
) | ||
|
||
devmode_consumer( | ||
name = "override_devmode_output", | ||
deps = [":override"], | ||
) | ||
|
||
es6_consumer( | ||
name = "override_prodmode_output", | ||
deps = [":override"], | ||
) | ||
|
||
jasmine_node_test( | ||
name = "override_output_test", | ||
srcs = ["override_output_test.js"], | ||
data = [ | ||
":override_devmode_output", | ||
":override_prodmode_output", | ||
], | ||
) |
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 a: any = () => 'hello world'; |
35 changes: 35 additions & 0 deletions
35
packages/typescript/test/target_module_attributes/override_output_test.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,35 @@ | ||
const fs = require('fs'); | ||
const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']); | ||
|
||
describe('googmodule', () => { | ||
let devmodeOutput; | ||
let prodmodeOutput; | ||
beforeAll(() => { | ||
devmodeOutput = runfiles.resolvePackageRelative('a.js'); | ||
prodmodeOutput = runfiles.resolvePackageRelative('a.mjs'); | ||
}); | ||
|
||
it('should have amd module syntax in devmode', () => { | ||
expect(fs.readFileSync(devmodeOutput, {encoding: 'utf-8'})) | ||
.toContain( | ||
`define("build_bazel_rules_nodejs/packages/typescript/test/target_module_attributes/a", ["require", "exports"], function (require, exports) {`); | ||
}); | ||
|
||
it('should have es5 in devmode', () => { | ||
expect(fs.readFileSync(devmodeOutput, { | ||
encoding: 'utf-8' | ||
})).toContain(`exports.a = function () { return 'hello world'; };`); | ||
}); | ||
|
||
it('should have amd module syntax in prodmode', () => { | ||
expect(fs.readFileSync(prodmodeOutput, {encoding: 'utf-8'})) | ||
.toContain( | ||
`define("build_bazel_rules_nodejs/packages/typescript/test/target_module_attributes/a", ["require", "exports"], function (require, exports) {`); | ||
}); | ||
|
||
it('should have es5 in prodmode', () => { | ||
expect(fs.readFileSync(prodmodeOutput, { | ||
encoding: 'utf-8' | ||
})).toContain(`exports.a = function () { return 'hello world'; };`); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/typescript/test/target_module_attributes/tsconfig-override.json
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 @@ | ||
{ | ||
"compilerOptions": { | ||
// Explicitly set types settings so typescript doesn't auto-discover types. | ||
// If all types are discovered then all types need to be included as deps | ||
// or typescript may error out with TS2688: Cannot find type definition file for 'foo'. | ||
"types": [] | ||
}, | ||
} |