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

V2: Remove ecmascript subpath #857

Merged
merged 1 commit into from
May 28, 2024
Merged
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
2 changes: 1 addition & 1 deletion docs/writing_plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export const default_host: Extension<ServiceOptions, string> = ...
Now we can utilize this extension to read custom options in our plugin:

```ts
import type { GeneratedFile } from "@bufbuild/protoplugin/ecmascript";
import type { GeneratedFile } from "@bufbuild/protoplugin";
import { ServiceOptions, ServiceDesc, hasExtension, getExtension } from "@bufbuild/protobuf";
import { default_host } from "./customoptions/default_host_pb.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/bundle-size/src/protoc-gen-entrypoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { createEcmaScriptPlugin, runNodeJs } from "@bufbuild/protoplugin";
import { DescMessage } from "@bufbuild/protobuf";
import { type Schema } from "@bufbuild/protoplugin/ecmascript";
import type { Schema } from "@bufbuild/protoplugin";
import { files, sizes } from "./constants.js";

runNodeJs(
Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/src/reflect/names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const reservedObjectProperties = new Set([
/**
* Escapes names that are reserved for ECMAScript built-in object properties.
*
* Also see safeIdentifier() from @bufbuild/protoplugin/ecmascript.
* Also see safeIdentifier() from @bufbuild/protoplugin.
*/
export function safeObjectProperty(name: string): string {
return reservedObjectProperties.has(name) ? name + "$" : name;
Expand Down
12 changes: 6 additions & 6 deletions packages/protoc-gen-es/src/protoc-gen-es-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type {
Printable,
Schema,
Target,
} from "@bufbuild/protoplugin/ecmascript";
} from "@bufbuild/protoplugin";
import { arrayLiteral, fieldTypeScriptType, functionCall } from "./util";
import { version } from "../package.json";

Expand Down Expand Up @@ -59,7 +59,7 @@ function generateTs(schema: Schema) {
switch (desc.kind) {
case "message": {
generateMessageShape(f, desc, "ts");
const {GenDescMessage, messageDesc} = f.runtime.codegen;
const { GenDescMessage, messageDesc } = f.runtime.codegen;
const MessageShape = f.importShape(desc);
const name = f.importDesc(desc).name;
generateDescDoc(f, desc);
Expand All @@ -71,7 +71,7 @@ function generateTs(schema: Schema) {
}
case "enum": {
generateEnumShape(f, desc);
const {GenDescEnum, enumDesc} = f.runtime.codegen;
const { GenDescEnum, enumDesc } = f.runtime.codegen;
const EnumShape = f.importShape(desc);
generateDescDoc(f, desc);
const name = f.importDesc(desc).name;
Expand All @@ -94,7 +94,7 @@ function generateTs(schema: Schema) {
break;
}
case "service": {
const { GenDescService, serviceDesc} = f.runtime.codegen;
const { GenDescService, serviceDesc } = f.runtime.codegen;
const name = f.importDesc(desc).name;
const call = functionCall(serviceDesc, [fileDesc, ...pathInFileDesc(desc)]);
f.print(f.jsDoc(desc));
Expand All @@ -121,7 +121,7 @@ function generateJs(schema: Schema) {
for (const desc of schema.typesInFile(file)) {
switch (desc.kind) {
case "message": {
const { messageDesc} = f.runtime.codegen;
const { messageDesc } = f.runtime.codegen;
const name = f.importDesc(desc).name;
generateDescDoc(f, desc);
const call = functionCall(messageDesc, [fileDesc, ...pathInFileDesc(desc)]);
Expand Down Expand Up @@ -163,7 +163,7 @@ function generateJs(schema: Schema) {
break;
}
case "service": {
const { serviceDesc} = f.runtime.codegen;
const { serviceDesc } = f.runtime.codegen;
const name = f.importDesc(desc).name;
f.print(f.jsDoc(desc));
const call = functionCall(serviceDesc, [fileDesc, ...pathInFileDesc(desc)]);
Expand Down
2 changes: 1 addition & 1 deletion packages/protoc-gen-es/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from "@bufbuild/protobuf";
import { scalarTypeScriptType } from "@bufbuild/protobuf/reflect";
import { isWrapperDesc } from "@bufbuild/protobuf/wkt";
import type { Printable } from "@bufbuild/protoplugin/ecmascript";
import type { Printable } from "@bufbuild/protoplugin";

export function fieldTypeScriptType(field: DescField | DescExtension): {
typing: Printable;
Expand Down
8 changes: 6 additions & 2 deletions packages/protoplugin-example/src/protoc-gen-twirp-es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { createEcmaScriptPlugin, runNodeJs } from "@bufbuild/protoplugin";
import {
createEcmaScriptPlugin,
runNodeJs,
type Schema,
safeIdentifier,
} from "@bufbuild/protoplugin";
import { getOption, hasOption } from "@bufbuild/protobuf";
import { type Schema, safeIdentifier } from "@bufbuild/protoplugin/ecmascript";
import { default_host } from "./gen/customoptions/default_host_pb.js";
import { version } from "../package.json";

Expand Down
2 changes: 1 addition & 1 deletion packages/protoplugin-test/src/byo-transpile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { describe, expect, test } from "@jest/globals";
import type { FileInfo } from "@bufbuild/protoplugin/ecmascript";
import type { FileInfo } from "@bufbuild/protoplugin";
import { createTestPluginAndRun } from "./helpers.js";

describe("bring your own transpile", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/protoplugin-test/src/custom-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
type CodeGeneratorRequest,
CodeGeneratorRequestDesc,
} from "@bufbuild/protobuf/wkt";
import type { Schema } from "@bufbuild/protoplugin/ecmascript";
import type { Schema } from "@bufbuild/protoplugin";
import { UpstreamProtobuf } from "upstream-protobuf";
import { compileFile, createTestPluginAndRun } from "./helpers.js";
import assert from "node:assert";
Expand Down
2 changes: 1 addition & 1 deletion packages/protoplugin-test/src/file-export-decl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import { describe, expect, test } from "@jest/globals";
import type { DescEnum, DescMessage } from "@bufbuild/protobuf";
import type { GeneratedFile } from "@bufbuild/protoplugin/ecmascript";
import type { GeneratedFile } from "@bufbuild/protoplugin";
import { createTestPluginAndRun } from "./helpers.js";

describe("GeneratedFile.export", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/protoplugin-test/src/file-print.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import { describe, expect, test } from "@jest/globals";
import { protoInt64, ScalarType } from "@bufbuild/protobuf";
import type { GeneratedFile, Schema } from "@bufbuild/protoplugin/ecmascript";
import { createImportSymbol } from "@bufbuild/protoplugin/ecmascript";
import type { GeneratedFile, Schema } from "@bufbuild/protoplugin";
import { createImportSymbol } from "@bufbuild/protoplugin";
import { createTestPluginAndRun } from "./helpers.js";

describe("GeneratedFile.print", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/protoplugin-test/src/file-string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { describe, expect, test } from "@jest/globals";
import type { GeneratedFile } from "@bufbuild/protoplugin/ecmascript";
import type { GeneratedFile } from "@bufbuild/protoplugin";
import { createTestPluginAndRun } from "./helpers.js";

describe("GeneratedFile.string", () => {
Expand Down
41 changes: 21 additions & 20 deletions packages/protoplugin-test/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import {
FileDescriptorSetDesc,
} from "@bufbuild/protobuf/wkt";
import { fromBinary, createFileRegistry } from "@bufbuild/protobuf";
import { type Plugin, createEcmaScriptPlugin } from "@bufbuild/protoplugin";
import { createEcmaScriptPlugin } from "@bufbuild/protoplugin";
import type {
GeneratedFile,
Schema,
Target,
} from "@bufbuild/protoplugin/ecmascript";
Plugin,
} from "@bufbuild/protoplugin";
import { UpstreamProtobuf } from "upstream-protobuf";
import { expect } from "@jest/globals";
import assert from "node:assert";
Expand All @@ -41,27 +42,27 @@ type CreateTestPluginAndRunOptions<ReturnLinesOfFirstFile extends boolean | unde
returnLinesOfFirstFile?: ReturnLinesOfFirstFile;
}
&
{
proto: string | Record<string, string>;
filesToGenerate?: string[];
parameter?: string;
name?: PluginInit["name"];
version?: PluginInit["version"];
parseOption?: PluginInit["parseOption"];
minimumEdition?: PluginInit["minimumEdition"];
maximumEdition?: PluginInit["maximumEdition"];
}
&
(
{
proto: string | Record<string, string>;
filesToGenerate?: string[];
parameter?: string;
name?: PluginInit["name"];
version?: PluginInit["version"];
parseOption?: PluginInit["parseOption"];
minimumEdition?: PluginInit["minimumEdition"];
maximumEdition?: PluginInit["maximumEdition"];
generateTs: PluginInit["generateTs"];
generateJs?: PluginInit["generateJs"];
generateDts?: PluginInit["generateDts"];
transpile?: PluginInit["transpile"];
}
&
(
{
generateTs: PluginInit["generateTs"];
generateJs?: PluginInit["generateJs"];
generateDts?: PluginInit["generateDts"];
transpile?: PluginInit["transpile"];
}
|
{ generateAny: (f: GeneratedFile, schema: Schema, target: Target) => void; }
);
{ generateAny: (f: GeneratedFile, schema: Schema, target: Target) => void; }
);

export async function createTestPluginAndRun(
opt: CreateTestPluginAndRunOptions<false | undefined>,
Expand Down
2 changes: 1 addition & 1 deletion packages/protoplugin-test/src/import_extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { describe, expect, test } from "@jest/globals";
import type { GeneratedFile, Schema } from "@bufbuild/protoplugin/ecmascript";
import type { GeneratedFile, Schema } from "@bufbuild/protoplugin";
import { createTestPluginAndRun } from "./helpers.js";

describe("import_extension", function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/protoplugin-test/src/js_import_style.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { describe, expect, test } from "@jest/globals";
import type { Schema } from "@bufbuild/protoplugin/ecmascript";
import type { Schema } from "@bufbuild/protoplugin";
import { createTestPluginAndRun } from "./helpers.js";

describe("js_import_style", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/protoplugin-test/src/rewrite_imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { describe, expect, test } from "@jest/globals";
import type { GeneratedFile, Schema } from "@bufbuild/protoplugin/ecmascript";
import type { GeneratedFile, Schema } from "@bufbuild/protoplugin";
import { createTestPluginAndRun } from "./helpers.js";

describe("rewrite_imports", function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/protoplugin-test/src/safe-identifier.test.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 { safeIdentifier } from "@bufbuild/protoplugin/ecmascript";
import { safeIdentifier } from "@bufbuild/protoplugin";
import { describe, expect, test } from "@jest/globals";

describe("safeIdentifier", () => {
Expand Down
7 changes: 5 additions & 2 deletions packages/protoplugin-test/src/target.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
// limitations under the License.

import { beforeEach, describe, expect, jest, test } from "@jest/globals";
import type { FileInfo, Schema } from "@bufbuild/protoplugin/ecmascript";
import { createTestPluginAndRun } from "./helpers.js";
import type { createEcmaScriptPlugin } from "@bufbuild/protoplugin";
import type {
createEcmaScriptPlugin,
FileInfo,
Schema,
} from "@bufbuild/protoplugin";
import type { CodeGeneratorResponse } from "@bufbuild/protobuf/wkt";

describe("target", () => {
Expand Down
11 changes: 0 additions & 11 deletions packages/protoplugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"./ecmascript": {
"import": "./dist/esm/ecmascript/index.js",
"require": "./dist/cjs/ecmascript/index.js"
}
},
"typesVersions": {
"*": {
"ecmascript": [
"./dist/cjs/ecmascript/index.d.ts"
]
}
},
"dependencies": {
Expand Down
10 changes: 5 additions & 5 deletions packages/protoplugin/src/create-es-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import {
CodeGeneratorResponse_Feature,
CodeGeneratorResponseDesc,
} from "@bufbuild/protobuf/wkt";
import { createSchema } from "./ecmascript/schema.js";
import type { Schema } from "./ecmascript/schema.js";
import type { FileInfo } from "./ecmascript/generated-file.js";
import { createSchema } from "./schema.js";
import type { Schema } from "./schema.js";
import type { FileInfo } from "./generated-file.js";
import type { Plugin } from "./plugin.js";
import { transpile } from "./ecmascript/transpile.js";
import { parseParameter } from "./ecmascript/parameter.js";
import { transpile } from "./transpile.js";
import { parseParameter } from "./parameter.js";

interface PluginInit {
/**
Expand Down
21 changes: 0 additions & 21 deletions packages/protoplugin/src/ecmascript/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
getPackageComments,
getSyntaxComments,
getFeatureOptionStrings,
} from "../source-code-info.js";
} from "./source-code-info.js";

export function makeFilePreamble(
file: DescFile,
Expand Down
8 changes: 8 additions & 0 deletions packages/protoplugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ export {
getPackageComments,
getSyntaxComments,
} from "./source-code-info.js";

export type { Target } from "./target.js";
export type { Schema } from "./schema.js";
export type { GeneratedFile, FileInfo } from "./generated-file.js";
export type { ImportSymbol } from "./import-symbol.js";
export { createImportSymbol } from "./import-symbol.js";
export type { Printable } from "./printable.js";
export { safeIdentifier } from "./safe-identifier.js";
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
getComments,
getDeclarationString,
getFeatureOptionStrings,
} from "../source-code-info.js";
} from "./source-code-info.js";
import { parentTypes } from "@bufbuild/protobuf/reflect";

export function createJsDocTextFromDesc(desc: Exclude<AnyDesc, DescFile>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import type { Target } from "./target.js";
import type { RewriteImports } from "./import-path.js";
import { PluginOptionError } from "../error.js";
import { PluginOptionError } from "./error.js";

export interface ParsedParameter {
targets: Target[];
Expand Down
2 changes: 1 addition & 1 deletion packages/protoplugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"files": ["src/index.ts", "src/ecmascript/index.ts"],
"files": ["src/index.ts"],
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"esModuleInterop": true,
Expand Down