Skip to content

Commit

Permalink
Reverting protoc plugin to node resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-sachs committed Oct 10, 2023
1 parent a83990a commit 760824e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
32 changes: 5 additions & 27 deletions packages/protoc-gen-connect-query/src/generateDts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import type {
DescEnum,
DescEnumValue,
DescField,
DescFile,
DescMessage,
DescMethod,
DescOneof,
DescService,
} from "@bufbuild/protobuf";
import type { DescFile, DescService } from "@bufbuild/protobuf";
import { codegenInfo, MethodIdempotency, MethodKind } from "@bufbuild/protobuf";
import type { Schema } from "@bufbuild/protoplugin";
import {
Expand All @@ -34,19 +25,6 @@ import type { PluginInit } from "./utils";

const { safeIdentifier } = codegenInfo;

// Casting localName since in Node16 resolution scheme, this private API
// is not visible.
const typedLocalName = localName as (
desc:
| DescEnum
| DescEnumValue
| DescField
| DescMessage
| DescMethod
| DescOneof
| DescService,
) => string;

// prettier-ignore
/**
* Handles generating a TypeScript Declaration file for a given Schema, DescFile (protobuf definition) and protobuf Service.
Expand All @@ -56,18 +34,18 @@ const generateServiceFile =
const { MethodKind: rtMethodKind, MethodIdempotency: rtMethodIdempotency } = schema.runtime;

const f = schema.generateFile(
`${protoFile.name}-${typedLocalName(service)}_connectquery.d.ts`,
`${protoFile.name}-${localName(service)}_connectquery.d.ts`,
);

f.preamble(protoFile);

f.print(makeJsDoc(service));
f.print("export declare const ", typedLocalName(service), ": {");
f.print("export declare const ", localName(service), ": {");
f.print(` readonly typeName: `, literalString(service.typeName), `,`);
f.print(" readonly methods: {");
for (const method of service.methods) {
f.print(makeJsDoc(method, " "));
f.print(" readonly ", typedLocalName(method), ": {");
f.print(" readonly ", localName(method), ": {");
f.print(` readonly name: `, literalString(method.name), `,`);
f.print(" readonly I: typeof ", method.input, ",");
f.print(" readonly O: typeof ", method.output, ",");
Expand All @@ -90,7 +68,7 @@ const generateServiceFile =
{
f.print(
`export const `,
safeIdentifier(typedLocalName(method)),
safeIdentifier(localName(method)),
`: `,
unaryFunctionsWithHooks,
`<`,
Expand Down
2 changes: 2 additions & 0 deletions packages/protoc-gen-connect-query/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"files": ["src/protoc-gen-connect-query-plugin.ts"],
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"moduleResolution": "node",
"module": "CommonJS",
"outDir": "dist/cjs",
"resolveJsonModule": true,
"skipLibCheck": true
Expand Down

0 comments on commit 760824e

Please sign in to comment.