diff --git a/CHANGELOG.md b/CHANGELOG.md index 597b97f..9c07cdc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/e2e/serialization/service.pb.ts b/e2e/serialization/service.pb.ts new file mode 100644 index 0000000..83b9eff --- /dev/null +++ b/e2e/serialization/service.pb.ts @@ -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"; diff --git a/e2e/serialization/service.proto b/e2e/serialization/service.proto new file mode 100644 index 0000000..07c50b7 --- /dev/null +++ b/e2e/serialization/service.proto @@ -0,0 +1,6 @@ +syntax = "proto3"; +import "google/protobuf/empty.proto"; + +service Service { + rpc Bar (google.protobuf.Empty) returns (google.protobuf.Empty); +} diff --git a/e2e/serialization/tsconfig.json b/e2e/serialization/tsconfig.json index 060dd2c..0bb78ff 100644 --- a/e2e/serialization/tsconfig.json +++ b/e2e/serialization/tsconfig.json @@ -2,7 +2,8 @@ "extends": "../../tsconfig.json", "compilerOptions": { "rootDir": ".", - "outDir": "dist" + "outDir": "dist", + "noUnusedLocals": false }, "exclude": ["dist"] } diff --git a/packages/protoscript/package.json b/packages/protoscript/package.json index 04d62f6..6f1e5d4 100644 --- a/packages/protoscript/package.json +++ b/packages/protoscript/package.json @@ -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 ", diff --git a/packages/protoscript/src/codegen/autogenerate/index.ts b/packages/protoscript/src/codegen/autogenerate/index.ts index 79fb340..31946ab 100644 --- a/packages/protoscript/src/codegen/autogenerate/index.ts +++ b/packages/protoscript/src/codegen/autogenerate/index.ts @@ -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} @@ -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")