-
Notifications
You must be signed in to change notification settings - Fork 33
Fix import statement with "subpackages" in converted ESModule #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,13 +106,13 @@ rollup_bundle( | |
entry_points = { | ||
":test_bundling.ts": "index", | ||
}, | ||
format = "cjs", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this You'll also need to add to the rollup config:
|
||
output_dir = True, | ||
deps = [ | ||
":test_bundling_lib", | ||
"@npm//rollup-plugin-commonjs", | ||
"@npm//rollup-plugin-node-resolve", | ||
], | ||
format = "cjs", | ||
) | ||
|
||
ts_library( | ||
|
@@ -121,20 +121,46 @@ ts_library( | |
tsconfig = ":test_bundling_tsconfig.json", | ||
deps = [ | ||
"//test/proto:naming_styles_ts_proto", | ||
"//test/proto/common:pizza_ts_proto", | ||
"//test/proto:pizza_service_ts_proto", | ||
"//test/proto/common:delivery_person_ts_proto", | ||
"@npm//google-protobuf", | ||
"//test/proto/common:pizza_ts_proto", | ||
"@npm//@improbable-eng/grpc-web", | ||
"@npm//google-protobuf", | ||
], | ||
) | ||
|
||
jasmine_node_test( | ||
name = "rollup_test", | ||
srcs = [ | ||
":rollup_test.spec.js" | ||
":rollup_test.spec.js", | ||
], | ||
data = [ | ||
":test_es6_bundling" | ||
] | ||
":test_es6_bundling", | ||
], | ||
) | ||
|
||
ts_library( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was a little confused why you duplicated the rollup test until I saw your comment: "because it runs on Node.js instead of the browser". Can you change the names of both tests to indicate what's being tested? E.g. |
||
name = "rollup_test_spec", | ||
testonly = 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: You can use |
||
srcs = ["rollup_test.spec.ts"], | ||
tsconfig = ":tsconfig.json", | ||
|
||
deps=["@npm//@types/jasmine",] | ||
) | ||
|
||
|
||
karma_web_test_suite( | ||
name = "rollup_browser_test_suite", | ||
srcs = [ | ||
"require.config.js", | ||
], | ||
browsers = [ | ||
"@io_bazel_rules_webtesting//browsers:chromium-local", | ||
], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll need to add the files:
|
||
tags = ["native"], | ||
deps = [ | ||
":rollup_test_spec", | ||
":test_es6_bundling", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be removed if it's in the |
||
|
||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
declare function require(module: string): any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can do:
You'll also need a declaration file to get this to compile. I couldn't figure out how to export one, so I just added:
And added it to the |
||
|
||
const bundle = require('rules_typescript_proto/test/test_es6_bundling'); | ||
|
||
describe('Rollup', () => { | ||
it('should define Pizza with protobuf API', () => { | ||
expect(bundle.Pizza).toBeDefined(); | ||
|
||
const pizza = new bundle.Pizza(); | ||
pizza.setSize(bundle.PizzaSize.PIZZA_SIZE_LARGE); | ||
|
||
expect(pizza.getSize()).toBe(bundle.PizzaSize.PIZZA_SIZE_LARGE); | ||
expect(Array.isArray(pizza.getToppingIdsList())).toBe(true); | ||
}); | ||
|
||
it('should define DeliveryPerson', () => { | ||
expect(bundle.DeliveryPerson).toBeDefined(); | ||
expect(new bundle.DeliveryPerson()).toBeTruthy(); | ||
}); | ||
|
||
it('should define PizzaService', () => { | ||
expect(bundle.PizzaService).toBeDefined(); | ||
expect(bundle.PizzaService.serviceName).toBe('test.bazel.proto.PizzaService'); | ||
expect(bundle.PizzaService.OrderPizza.methodName).toBe('OrderPizza'); | ||
}); | ||
|
||
it('should define PizzaServiceClient', () => { | ||
expect(bundle.PizzaServiceClient).toBeDefined(); | ||
const client = new bundle.PizzaServiceClient('http://localhost', {}); | ||
expect(typeof client.orderPizza).toBe('function'); | ||
}); | ||
|
||
it('should follow expected naming styles', () => { | ||
expect(new bundle.alllowercase().setTest(1)).toBeTruthy(); | ||
expect(new bundle.ALLUPPERCASE().setTest(1)).toBeTruthy(); | ||
expect(new bundle.lowerCamelCase().setTest(1)).toBeTruthy(); | ||
expect(new bundle.UpperCamelCase().setTest(1)).toBeTruthy(); | ||
expect(new bundle.snake_case_snake_case().setTest(1)).toBeTruthy(); | ||
expect(new bundle.Upper_snake_Case().setTest(1)).toBeTruthy(); | ||
expect(new bundle.M2M().setTest(1)).toBeTruthy(); | ||
expect(new bundle.M_2M().setTest(1)).toBeTruthy(); | ||
expect(new bundle.M2_M().setTest(1)).toBeTruthy(); | ||
expect(new bundle.M2M_().setTest(1)).toBeTruthy(); | ||
expect(new bundle.m_22M().setTest(1)).toBeTruthy(); | ||
expect(new bundle.m42_M().setTest(1)).toBeTruthy(); | ||
expect(new bundle.m24M_().setTest(1)).toBeTruthy(); | ||
expect(new bundle.M9().setTest(1)).toBeTruthy(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export {alllowercase, ALLUPPERCASE, lowerCamelCase, m24M_, M2_M, M2M, M2M_, m42_M, M9, m_22M, M_2M, snake_case_snake_case, Upper_snake_Case, UpperCamelCase,} from 'rules_typescript_proto/test/proto/naming_styles_pb'; | ||
export { alllowercase, ALLUPPERCASE, lowerCamelCase, m24M_, M2_M, M2M, M2M_, m42_M, M9, m_22M, M_2M, snake_case_snake_case, Upper_snake_Case, UpperCamelCase, } from 'rules_typescript_proto/test/proto/naming_styles_pb'; | ||
export { DeliveryPerson } from 'rules_typescript_proto/test/proto/common/delivery_person_pb'; | ||
export { Pizza, PizzaSize } from 'rules_typescript_proto/test/proto/common/pizza_pb'; | ||
export { PizzaService, PizzaServiceClient } from 'rules_typescript_proto/test/proto/pizza_service_pb_service'; | ||
export { OrderPizzaRequest } from 'rules_typescript_proto/test/proto/pizza_service_pb'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this check needed? It makes the code look cleaner, but since this code is generated anyways I don't think it really matters. I think you could just do:
'import {$3 as $1} from $2;