-
Notifications
You must be signed in to change notification settings - Fork 132
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
Add file extensions to generated imports. #182
Comments
Thanks for bringing this up, @sachaw. I am happy to see that TypeScript will support Node.js 12's ESM additions. I wonder what that means for users of older TypeScript versions, though. Just adding a |
I guess for now, it can be a flag, but considering how the world is moving towards ESM only, I think it will be the default quite soon. |
@timostamm I could make an attempt at implementing this, if you could lead me in the right direction. |
I'm happy to. The following function creates import paths: protobuf-ts/packages/plugin-framework/src/typescript-imports.ts Lines 285 to 288 in fbce12b
The function is local to the The only place the class is used is in the plugin, on this line:
So To add a new plugin option, in // add below the other option definitions:
enable_import_extension: {
description: "...",
},
// further below:
imports = new TypeScriptImports(symbols, !params.enable_import_extension), |
There is also the deprecated There is a spec file for parts of I don't think it will be feasible to add test coverage in |
Yes please. I have to write some post-processing step to add the import { Duration } from "./google/protobuf/duration_pb.js";
import { Timestamp } from "./google/protobuf/timestamp_pb.js"; Or I cannot use it in some of my modules that stepped up. Without the dirty and somewhat dangerous post-processing script. |
Files generated by the protoc plugin, currently, import witht he following syntax
import {x} from 'y'
however for reasons outlined in nodejs/modules#444, the following syntax should be used for forward compatibility with esmodulesimport {x} from 'y.js'
Further reading:
https://nodejs.org/api/esm.html#import-specifiers
https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta/
The text was updated successfully, but these errors were encountered: