Skip to content

Commit

Permalink
Preserve protoscript import when well known types are imported (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
tatethurston authored Oct 25, 2023
1 parent 314321a commit f02cb79
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.0.20

- Preserve protoscript import when well known types are imported. This corrects a regression in 0.0.19.

## v0.0.19

- Fix JSON serializtion for Timestamp and Duration well known types. See [#39](https://github.com/tatethurston/ProtoScript/issues/39).
Expand Down
5 changes: 5 additions & 0 deletions e2e/serialization/service.pb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
// Source: service.proto
/* eslint-disable */

import * as protoscript from "protoscript";
6 changes: 6 additions & 0 deletions e2e/serialization/service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
syntax = "proto3";
import "google/protobuf/empty.proto";

service Service {
rpc Bar (google.protobuf.Empty) returns (google.protobuf.Empty);
}
3 changes: 2 additions & 1 deletion e2e/serialization/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "dist"
"outDir": "dist",
"noUnusedLocals": false
},
"exclude": ["dist"]
}
2 changes: 1 addition & 1 deletion packages/protoscript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "protoscript",
"version": "0.0.19",
"version": "0.0.20",
"description": "A Protobuf runtime and code generation tool for JavaScript and TypeScript",
"license": "MIT",
"author": "Tate <[email protected]>",
Expand Down
9 changes: 8 additions & 1 deletion packages/protoscript/src/codegen/autogenerate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,10 @@ export function generate(
? writeJSONSerializers(types, [])
: "";

const hasWellKnownTypeImports = imports.some(
({ moduleName }) => moduleName === "protoscript",
);

return `\
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
// Source: ${sourceFile}
Expand All @@ -848,7 +852,10 @@ ${printIf(
config.isTS && hasSerializer,
`import type { ByteSource, PartialDeep } from "protoscript";`,
)}
${printIf(hasSerializer, `import * as protoscript from "protoscript";`)}
${printIf(
hasSerializer || hasWellKnownTypeImports,
`import * as protoscript from "protoscript";`,
)}
${printIf(pluginImports.length > 0, pluginImports.join("\n"))}
${imports
.filter(({ moduleName }) => moduleName !== "protoscript")
Expand Down

0 comments on commit f02cb79

Please sign in to comment.