diff --git a/docs/writing_plugins.md b/docs/writing_plugins.md index 61ad07ae8..a218bc230 100644 --- a/docs/writing_plugins.md +++ b/docs/writing_plugins.md @@ -429,7 +429,7 @@ export const default_host: Extension = ... 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"; diff --git a/packages/bundle-size/src/protoc-gen-entrypoints.ts b/packages/bundle-size/src/protoc-gen-entrypoints.ts index 77b36637f..e4cc92560 100644 --- a/packages/bundle-size/src/protoc-gen-entrypoints.ts +++ b/packages/bundle-size/src/protoc-gen-entrypoints.ts @@ -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( diff --git a/packages/protobuf/src/reflect/names.ts b/packages/protobuf/src/reflect/names.ts index 5a52c8d7e..833607c7a 100644 --- a/packages/protobuf/src/reflect/names.ts +++ b/packages/protobuf/src/reflect/names.ts @@ -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; diff --git a/packages/protoc-gen-es/src/protoc-gen-es-plugin.ts b/packages/protoc-gen-es/src/protoc-gen-es-plugin.ts index 344baf40b..effecab4a 100644 --- a/packages/protoc-gen-es/src/protoc-gen-es-plugin.ts +++ b/packages/protoc-gen-es/src/protoc-gen-es-plugin.ts @@ -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"; @@ -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); @@ -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; @@ -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)); @@ -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)]); @@ -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)]); diff --git a/packages/protoc-gen-es/src/util.ts b/packages/protoc-gen-es/src/util.ts index d53c5a229..c61e1e811 100644 --- a/packages/protoc-gen-es/src/util.ts +++ b/packages/protoc-gen-es/src/util.ts @@ -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; diff --git a/packages/protoplugin-example/src/protoc-gen-twirp-es.ts b/packages/protoplugin-example/src/protoc-gen-twirp-es.ts index b89c8f4af..a52d553ef 100755 --- a/packages/protoplugin-example/src/protoc-gen-twirp-es.ts +++ b/packages/protoplugin-example/src/protoc-gen-twirp-es.ts @@ -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"; diff --git a/packages/protoplugin-test/src/byo-transpile.test.ts b/packages/protoplugin-test/src/byo-transpile.test.ts index f520540a8..16b1f2889 100644 --- a/packages/protoplugin-test/src/byo-transpile.test.ts +++ b/packages/protoplugin-test/src/byo-transpile.test.ts @@ -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", () => { diff --git a/packages/protoplugin-test/src/custom-options.test.ts b/packages/protoplugin-test/src/custom-options.test.ts index 9cc48aeba..cbeba69bf 100644 --- a/packages/protoplugin-test/src/custom-options.test.ts +++ b/packages/protoplugin-test/src/custom-options.test.ts @@ -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"; diff --git a/packages/protoplugin-test/src/file-export-decl.test.ts b/packages/protoplugin-test/src/file-export-decl.test.ts index 0e7386b99..ad68cde14 100644 --- a/packages/protoplugin-test/src/file-export-decl.test.ts +++ b/packages/protoplugin-test/src/file-export-decl.test.ts @@ -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", () => { diff --git a/packages/protoplugin-test/src/file-print.test.ts b/packages/protoplugin-test/src/file-print.test.ts index 17822b182..9237627ae 100644 --- a/packages/protoplugin-test/src/file-print.test.ts +++ b/packages/protoplugin-test/src/file-print.test.ts @@ -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", () => { diff --git a/packages/protoplugin-test/src/file-string.test.ts b/packages/protoplugin-test/src/file-string.test.ts index 9abf39d1b..e4bcb5d75 100644 --- a/packages/protoplugin-test/src/file-string.test.ts +++ b/packages/protoplugin-test/src/file-string.test.ts @@ -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", () => { diff --git a/packages/protoplugin-test/src/helpers.ts b/packages/protoplugin-test/src/helpers.ts index fcd404c3a..8159ef08a 100644 --- a/packages/protoplugin-test/src/helpers.ts +++ b/packages/protoplugin-test/src/helpers.ts @@ -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"; @@ -41,27 +42,27 @@ type CreateTestPluginAndRunOptions; + filesToGenerate?: string[]; + parameter?: string; + name?: PluginInit["name"]; + version?: PluginInit["version"]; + parseOption?: PluginInit["parseOption"]; + minimumEdition?: PluginInit["minimumEdition"]; + maximumEdition?: PluginInit["maximumEdition"]; + } + & + ( { - proto: string | Record; - 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, diff --git a/packages/protoplugin-test/src/import_extension.test.ts b/packages/protoplugin-test/src/import_extension.test.ts index 928b56d6d..5819addb1 100644 --- a/packages/protoplugin-test/src/import_extension.test.ts +++ b/packages/protoplugin-test/src/import_extension.test.ts @@ -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 () { diff --git a/packages/protoplugin-test/src/js_import_style.test.ts b/packages/protoplugin-test/src/js_import_style.test.ts index e7422493d..6f4978476 100644 --- a/packages/protoplugin-test/src/js_import_style.test.ts +++ b/packages/protoplugin-test/src/js_import_style.test.ts @@ -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", () => { diff --git a/packages/protoplugin-test/src/rewrite_imports.test.ts b/packages/protoplugin-test/src/rewrite_imports.test.ts index 1fef83f2a..33508c34b 100644 --- a/packages/protoplugin-test/src/rewrite_imports.test.ts +++ b/packages/protoplugin-test/src/rewrite_imports.test.ts @@ -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 () { diff --git a/packages/protoplugin-test/src/safe-identifier.test.ts b/packages/protoplugin-test/src/safe-identifier.test.ts index 3ceb38004..7b11cdb39 100644 --- a/packages/protoplugin-test/src/safe-identifier.test.ts +++ b/packages/protoplugin-test/src/safe-identifier.test.ts @@ -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", () => { diff --git a/packages/protoplugin-test/src/target.test.ts b/packages/protoplugin-test/src/target.test.ts index e6c219e74..ee0de7b73 100644 --- a/packages/protoplugin-test/src/target.test.ts +++ b/packages/protoplugin-test/src/target.test.ts @@ -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", () => { diff --git a/packages/protoplugin/package.json b/packages/protoplugin/package.json index 0b2d3806a..1b55658ba 100644 --- a/packages/protoplugin/package.json +++ b/packages/protoplugin/package.json @@ -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": { diff --git a/packages/protoplugin/src/create-es-plugin.ts b/packages/protoplugin/src/create-es-plugin.ts index 9926f1844..ee7678cf6 100644 --- a/packages/protoplugin/src/create-es-plugin.ts +++ b/packages/protoplugin/src/create-es-plugin.ts @@ -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 { /** diff --git a/packages/protoplugin/src/ecmascript/index.ts b/packages/protoplugin/src/ecmascript/index.ts deleted file mode 100644 index b794bbf5f..000000000 --- a/packages/protoplugin/src/ecmascript/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2021-2024 Buf Technologies, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -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"; diff --git a/packages/protoplugin/src/ecmascript/file-preamble.ts b/packages/protoplugin/src/file-preamble.ts similarity index 98% rename from packages/protoplugin/src/ecmascript/file-preamble.ts rename to packages/protoplugin/src/file-preamble.ts index 9ae9a7161..d930ab71e 100644 --- a/packages/protoplugin/src/ecmascript/file-preamble.ts +++ b/packages/protoplugin/src/file-preamble.ts @@ -18,7 +18,7 @@ import { getPackageComments, getSyntaxComments, getFeatureOptionStrings, -} from "../source-code-info.js"; +} from "./source-code-info.js"; export function makeFilePreamble( file: DescFile, diff --git a/packages/protoplugin/src/ecmascript/generated-file.ts b/packages/protoplugin/src/generated-file.ts similarity index 100% rename from packages/protoplugin/src/ecmascript/generated-file.ts rename to packages/protoplugin/src/generated-file.ts diff --git a/packages/protoplugin/src/ecmascript/import-path.ts b/packages/protoplugin/src/import-path.ts similarity index 100% rename from packages/protoplugin/src/ecmascript/import-path.ts rename to packages/protoplugin/src/import-path.ts diff --git a/packages/protoplugin/src/ecmascript/import-symbol.ts b/packages/protoplugin/src/import-symbol.ts similarity index 100% rename from packages/protoplugin/src/ecmascript/import-symbol.ts rename to packages/protoplugin/src/import-symbol.ts diff --git a/packages/protoplugin/src/index.ts b/packages/protoplugin/src/index.ts index 016e0386a..5930b0e06 100644 --- a/packages/protoplugin/src/index.ts +++ b/packages/protoplugin/src/index.ts @@ -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"; diff --git a/packages/protoplugin/src/ecmascript/jsdoc.ts b/packages/protoplugin/src/jsdoc.ts similarity index 98% rename from packages/protoplugin/src/ecmascript/jsdoc.ts rename to packages/protoplugin/src/jsdoc.ts index 66dd95a0a..bcb520dcd 100644 --- a/packages/protoplugin/src/ecmascript/jsdoc.ts +++ b/packages/protoplugin/src/jsdoc.ts @@ -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) { diff --git a/packages/protoplugin/src/ecmascript/names.ts b/packages/protoplugin/src/names.ts similarity index 100% rename from packages/protoplugin/src/ecmascript/names.ts rename to packages/protoplugin/src/names.ts diff --git a/packages/protoplugin/src/ecmascript/parameter.ts b/packages/protoplugin/src/parameter.ts similarity index 99% rename from packages/protoplugin/src/ecmascript/parameter.ts rename to packages/protoplugin/src/parameter.ts index cc2827c72..47e958684 100644 --- a/packages/protoplugin/src/ecmascript/parameter.ts +++ b/packages/protoplugin/src/parameter.ts @@ -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[]; diff --git a/packages/protoplugin/src/ecmascript/printable.ts b/packages/protoplugin/src/printable.ts similarity index 100% rename from packages/protoplugin/src/ecmascript/printable.ts rename to packages/protoplugin/src/printable.ts diff --git a/packages/protoplugin/src/ecmascript/runtime-imports.ts b/packages/protoplugin/src/runtime-imports.ts similarity index 100% rename from packages/protoplugin/src/ecmascript/runtime-imports.ts rename to packages/protoplugin/src/runtime-imports.ts diff --git a/packages/protoplugin/src/ecmascript/safe-identifier.ts b/packages/protoplugin/src/safe-identifier.ts similarity index 100% rename from packages/protoplugin/src/ecmascript/safe-identifier.ts rename to packages/protoplugin/src/safe-identifier.ts diff --git a/packages/protoplugin/src/ecmascript/schema.ts b/packages/protoplugin/src/schema.ts similarity index 100% rename from packages/protoplugin/src/ecmascript/schema.ts rename to packages/protoplugin/src/schema.ts diff --git a/packages/protoplugin/src/ecmascript/target.ts b/packages/protoplugin/src/target.ts similarity index 100% rename from packages/protoplugin/src/ecmascript/target.ts rename to packages/protoplugin/src/target.ts diff --git a/packages/protoplugin/src/ecmascript/transpile.ts b/packages/protoplugin/src/transpile.ts similarity index 100% rename from packages/protoplugin/src/ecmascript/transpile.ts rename to packages/protoplugin/src/transpile.ts diff --git a/packages/protoplugin/tsconfig.json b/packages/protoplugin/tsconfig.json index 7dfdebd10..69dbd8089 100644 --- a/packages/protoplugin/tsconfig.json +++ b/packages/protoplugin/tsconfig.json @@ -1,5 +1,5 @@ { - "files": ["src/index.ts", "src/ecmascript/index.ts"], + "files": ["src/index.ts"], "extends": "../../tsconfig.base.json", "compilerOptions": { "esModuleInterop": true,