Skip to content

Commit e3cee38

Browse files
authored
refactor: migrate protoc plugins to ESM (#428)
1 parent c681582 commit e3cee38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+242
-187
lines changed

.changeset/wise-stingrays-leave.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@proto-graphql/protoc-plugin-helpers": patch
3+
"@proto-graphql/scalars-protobuf-es": patch
4+
"@proto-graphql/codegen-core": patch
5+
"protoc-gen-pothos": patch
6+
"protoc-gen-nexus": patch
7+
---
8+
9+
refactor: migrate protoc plugins to ESM

devPackages/testapis-proto/package.json

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22
"name": "@proto-graphql/testapis-proto",
33
"version": "0.1.1",
44
"description": "Generated codes from protobuf IDL",
5+
"type": "module",
6+
"main": "./dist/index.cjs",
7+
"module": "./dist/index.js",
8+
"types": "./dist/index.d.ts",
9+
"exports": {
10+
".": {
11+
"import": {
12+
"types": "./dist/index.d.ts",
13+
"default": "./dist/index.js"
14+
},
15+
"require": {
16+
"types": "./dist/index.d.ts",
17+
"default": "./dist/index.cjs"
18+
}
19+
}
20+
},
21+
"sideEffects": false,
522
"private": true,
623
"scripts": {
724
"build": "tsup",
@@ -13,16 +30,5 @@
1330
"devDependencies": {
1431
"@proto-graphql/tsconfig": "workspace:*",
1532
"glob": "^10.4.5"
16-
},
17-
"main": "./dist/index.js",
18-
"module": "./dist/index.mjs",
19-
"types": "./dist/index.d.ts",
20-
"exports": {
21-
".": {
22-
"import": "./dist/index.mjs",
23-
"require": "./dist/index.js",
24-
"types": "./dist/index.d.ts",
25-
"default": "./dist/index.js"
26-
}
2733
}
2834
}

devPackages/testapis-proto/scripts/build-proto.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import { exec as _exec } from "node:child_process";
44
import { mkdir, writeFile } from "node:fs/promises";
55
import { dirname, join, relative } from "node:path";
6+
import { fileURLToPath } from "node:url";
67
import { promisify } from "node:util";
7-
88
import { glob } from "glob";
99

1010
const exec = promisify(_exec);
1111

12+
const __filename = fileURLToPath(import.meta.url);
13+
const __dirname = dirname(__filename);
14+
1215
const rootDir = dirname(__dirname);
1316
const protoDir = join(rootDir, "proto");
1417

devPackages/testapis-proto/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
type FileDescriptorSet,
66
FileDescriptorSetSchema,
77
} from "@bufbuild/protobuf/wkt";
8-
import { fileDescriptorSetBins } from "./__generated__/fileDescriptorSetBins";
8+
import { fileDescriptorSetBins } from "./__generated__/fileDescriptorSetBins.js";
99

1010
function objectKeys<K extends string>(obj: Record<K, unknown>): K[] {
1111
return Object.keys(obj) as K[];

packages/@proto-graphql/codegen-core/package.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@
66
"repository": "git@github.com:proto-graphql/proto-graphql-js.git",
77
"author": "izumin5210 <m@izum.in>",
88
"license": "MIT",
9-
"main": "./dist/index.js",
10-
"module": "./dist/index.mjs",
9+
"type": "module",
10+
"main": "./dist/index.cjs",
11+
"module": "./dist/index.js",
1112
"types": "./dist/index.d.ts",
1213
"exports": {
1314
".": {
14-
"import": "./dist/index.mjs",
15-
"require": "./dist/index.js",
16-
"types": "./dist/index.d.ts",
17-
"default": "./dist/index.js"
15+
"import": {
16+
"types": "./dist/index.d.ts",
17+
"default": "./dist/index.js"
18+
},
19+
"require": {
20+
"types": "./dist/index.d.ts",
21+
"default": "./dist/index.cjs"
22+
}
1823
}
1924
},
25+
"files": ["src/", "dist/", "!src/**/*.test.ts", "!src/**/__tests__/"],
26+
"sideEffects": false,
2027
"private": false,
2128
"publishConfig": {
2229
"access": "public"
@@ -35,7 +42,6 @@
3542
"@proto-graphql/testapis-proto": "workspace:*",
3643
"@proto-graphql/tsconfig": "workspace:*"
3744
},
38-
"files": ["src/", "dist/", "!src/**/*.test.ts", "!src/**/__tests__/"],
3945
"scripts": {
4046
"build": "tsup",
4147
"prebuild": "../../../scripts/compile-extensions-proto",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from "./types";
2-
export * from "./printer";
1+
export * from "./types/index.js";
2+
export * from "./printer/index.js";

packages/@proto-graphql/codegen-core/src/printer/graphqlExtensions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
isMapField,
1212
isMessageField,
1313
isScalarField,
14-
} from "../proto/util";
14+
} from "../proto/util.js";
1515
import {
1616
EnumType,
1717
EnumTypeValue,
@@ -23,8 +23,8 @@ import {
2323
OneofUnionType,
2424
SquashedOneofUnionType,
2525
scalarMapLabelByType,
26-
} from "../types";
27-
import { compact } from "./util";
26+
} from "../types/index.js";
27+
import { compact } from "./util.js";
2828

2929
export function protobufGraphQLExtensions(
3030
type:
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from "./util";
2-
export * from "./graphqlExtensions";
3-
export * from "./print";
4-
export * from "./options";
1+
export * from "./util.js";
2+
export * from "./graphqlExtensions.js";
3+
export * from "./print.js";
4+
export * from "./options.js";

packages/@proto-graphql/codegen-core/src/printer/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
isMapField,
1919
isMessageField,
2020
isScalarField,
21-
} from "../proto/util";
21+
} from "../proto/util.js";
2222
import {
2323
type EnumType,
2424
type InputObjectField,
@@ -29,8 +29,8 @@ import {
2929
type ObjectType,
3030
type OneofUnionType,
3131
type SquashedOneofUnionType,
32-
} from "../types";
33-
import type { PrinterOptions } from "./options";
32+
} from "../types/index.js";
33+
import type { PrinterOptions } from "./options.js";
3434

3535
export function filename(
3636
type:

packages/@proto-graphql/codegen-core/src/types/EnumType.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type { DescEnum, DescEnumValue } from "@bufbuild/protobuf";
22
import { constantCase } from "change-case";
33

4-
import { TypeBase } from "./TypeBase";
4+
import { TypeBase } from "./TypeBase.js";
55
import {
66
descriptionFromProto,
77
getDeprecationReason,
88
isIgnoredField,
9-
} from "./util";
9+
} from "./util.js";
1010

1111
export class EnumType extends TypeBase<DescEnum> {
1212
get unspecifiedValue(): EnumTypeValue | null {

0 commit comments

Comments
 (0)