Skip to content
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

Reproduce Node16 import issue #585

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 89 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 32 additions & 7 deletions packages/protobuf/src/codegen-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,42 @@ import {
import { getUnwrappedFieldType } from "./private/field-wrapper.js";
import { scalarDefaultValue } from "./private/scalars.js";
import { reifyWkt } from "./private/reify-wkt.js";
import type {
DescEnum,
DescEnumValue,
DescField,
DescMessage,
DescMethod,
DescOneof,
DescService,
} from "./descriptor-set";
import { LongType, ScalarType } from "./field.js";

interface CodegenInfo {
/**
* Name of the runtime library NPM package.
*/
readonly packageName: string;
readonly localName: typeof localName;
readonly localName: (
desc:
| DescEnum
| DescEnumValue
| DescMessage
| DescOneof
| DescField
| DescService
| DescMethod,
) => string;
readonly symbols: Record<RuntimeSymbolName, RuntimeSymbolInfo>;
readonly getUnwrappedFieldType: typeof getUnwrappedFieldType;
readonly getUnwrappedFieldType: (field: DescField) => ScalarType | undefined;
readonly wktSourceFiles: readonly string[];
readonly scalarDefaultValue: typeof scalarDefaultValue;
readonly scalarDefaultValue: (type: ScalarType, longType: LongType) => any; // eslint-disable-line @typescript-eslint/no-explicit-any
/**
* @deprecated please use reifyWkt from @bufbuild/protoplugin/ecmascript instead
*/
readonly reifyWkt: typeof reifyWkt;
readonly safeIdentifier: typeof safeIdentifier;
readonly safeObjectProperty: typeof safeObjectProperty;
readonly safeIdentifier: (name: string) => string;
readonly safeObjectProperty: (name: string) => string;
}

type RuntimeSymbolName =
Expand Down Expand Up @@ -64,7 +89,7 @@ type RuntimeSymbolInfo = {
const packageName = "@bufbuild/protobuf";

export const codegenInfo: CodegenInfo = {
packageName,
packageName: "@bufbuild/protobuf",
localName,
reifyWkt,
getUnwrappedFieldType,
Expand Down Expand Up @@ -108,4 +133,4 @@ export const codegenInfo: CodegenInfo = {
"google/protobuf/type.proto",
"google/protobuf/wrappers.proto",
],
} as const;
};
2 changes: 1 addition & 1 deletion packages/protobuf/src/private/options-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import type { JsonValue } from "../json-format";
import type { JsonValue } from "../json-format.js";

/**
*
Expand Down
2 changes: 2 additions & 0 deletions packages/protobuf/src/private/reify-wkt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ type DescWkt =
};

/**
* @deprecated please use reifyWkt from @bufbuild/protoplugin/ecmascript instead
*
* Reifies a given DescMessage into a more concrete object representing its
* respective well-known type. The returned object will contain properties
* representing the WKT's defined fields.
Expand Down
1 change: 1 addition & 0 deletions packages/protoplugin-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@bufbuild/protoplugin-example",
"version": "1.4.0",
"private": true,
"type": "module",
"scripts": {
"build": "../../node_modules/typescript/bin/tsc --noEmit",
"start": "npx esbuild src/index.ts --serve=localhost:3000 --servedir=www --outdir=www --bundle --global-name=eliza",
Expand Down
4 changes: 2 additions & 2 deletions packages/protoplugin-example/test/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import * as assert from "node:assert/strict";
import { describe, it, mock } from "node:test";
import { ElizaServiceClient } from "../src/gen/connectrpc/eliza/v1/eliza_twirp";
import { SayRequest } from "../src/gen/connectrpc/eliza/v1/eliza_pb";
import { ElizaServiceClient } from "../src/gen/connectrpc/eliza/v1/eliza_twirp.js";
import { SayRequest } from "../src/gen/connectrpc/eliza/v1/eliza_pb.js";

describe("custom plugin", async () => {
it("should generate client class", () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/protoplugin-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"include": ["src/**/*.ts", "test/*.ts"],
"compilerOptions": {
"target": "es2017",
"moduleResolution": "Node",
"moduleResolution": "Node16",
"module": "Node16",
"esModuleInterop": false,
"resolveJsonModule": true,
"strict": true,
Expand Down
4 changes: 2 additions & 2 deletions packages/protoplugin/src/ecmascript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
// limitations under the License.

import { codegenInfo } from "@bufbuild/protobuf";

export { reifyWkt } from "./reify-wkt.js";
export { Target } from "./target.js";
export { Schema } from "./schema.js";
export { RuntimeImports } from "./runtime-imports.js";
export { GeneratedFile, FileInfo, Printable } from "./generated-file.js";
export { ImportSymbol } from "./import-symbol.js";

export const { localName, reifyWkt } = codegenInfo;
export const { localName } = codegenInfo;

export {
createJsDocBlock,
Expand Down
Loading