Skip to content

Commit

Permalink
Add option to choose import extension
Browse files Browse the repository at this point in the history
  • Loading branch information
atjn committed Mar 18, 2024
1 parent bcea4b4 commit 1b88422
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/proto-loader/README.md
Expand Up @@ -84,6 +84,8 @@ Options:
[boolean] [default: false]
--includeComments Generate doc comments from comments in the original
files [boolean] [default: false]
--importExtension Specify which extension is used to import files with.
[string] [choices: "", ".ts", ".js", ".mjs"] [default: ""]
-I, --includeDirs Directories to search for included files [array]
-O, --outDir Directory in which to output files [string] [required]
--grpcLib The gRPC implementation library that these types will
Expand Down
5 changes: 4 additions & 1 deletion packages/proto-loader/bin/proto-loader-gen-types.ts
Expand Up @@ -43,6 +43,7 @@ type GeneratorOptions = Protobuf.IParseOptions & Protobuf.IConversionOptions & {
outDir: string;
verbose?: boolean;
includeComments?: boolean;
importExtension: string,
inputTemplate: string;
outputTemplate: string;
inputBranded: boolean;
Expand Down Expand Up @@ -153,7 +154,7 @@ function getImportLine(dependency: Protobuf.Type | Protobuf.Enum | Protobuf.Serv
throw new Error('Invalid object passed to getImportLine');
}
}
return `import type { ${importedTypes} } from '${filePath}';`
return `import type { ${importedTypes} } from '${filePath}${options.importExtension}';`
}

function getChildMessagesAndEnums(namespace: Protobuf.NamespaceBase): (Protobuf.Type | Protobuf.Enum)[] {
Expand Down Expand Up @@ -863,6 +864,7 @@ async function runScript() {
.option('json', boolDefaultFalseOption)
.boolean('verbose')
.option('includeComments', boolDefaultFalseOption)
.option('importExtension', { string: true, choices: ["", ".ts", ".js", ".mjs"], default: "" })
.option('includeDirs', {
normalize: true,
array: true,
Expand Down Expand Up @@ -909,6 +911,7 @@ async function runScript() {
oneofs: 'Output virtual oneof fields set to the present field\'s name',
json: 'Represent Infinity and NaN as strings in float fields. Also decode google.protobuf.Any automatically',
includeComments: 'Generate doc comments from comments in the original files',
importExtension: 'Specify which extension is used to import files with.',
includeDirs: 'Directories to search for included files',
outDir: 'Directory in which to output files',
grpcLib: 'The gRPC implementation library that these types will be used with. If not provided, some types will not be generated',
Expand Down

0 comments on commit 1b88422

Please sign in to comment.