Skip to content

Commit

Permalink
Remove node export conditions (#744)
Browse files Browse the repository at this point in the history
Fixes #713

In #728, #729, and #742, we made changes that remove a common failure
point for the dual package hazard -- usage of `instanceof` with custom
types . As a result, the `node` exports condition for our packages
should not be necessary and is actually problematic for some bundlers.
  • Loading branch information
smaye81 authored Mar 13, 2024
1 parent 00c7213 commit 38ca963
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 144 deletions.
8 changes: 1 addition & 7 deletions packages/protobuf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
},
"scripts": {
"clean": "rm -rf ./dist/*",
"build": "npm run build:cjs && npm run build:esm && npm run build:proxy",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
"build:proxy": "node ../../scripts/gen-esm-proxy.mjs .",
"bootstrap:featureset-defaults": "upstream-inject-feature-defaults src/private/feature-set.ts",
"prebootstrap:wkt": "rm -rf .tmp && mkdir -p .tmp/google/protobuf && cp -rp src/google/protobuf/* .tmp/google/protobuf",
"bootstrap:wkt": "protoc --es_out=src --es_opt=bootstrap_wkt=true,ts_nocheck=false,target=ts --proto_path $(upstream-include wkt) $(upstream-files wkt) && license-header src/google/protobuf",
Expand All @@ -25,11 +24,6 @@
"main": "./dist/cjs/index.js",
"exports": {
".": {
"node": {
"import": "./dist/proxy/index.js",
"require": "./dist/cjs/index.js"
},
"module": "./dist/esm/index.js",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/src/create-descriptor-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import type { BinaryReadOptions, BinaryWriteOptions } from "./binary-format.js";
import type { FeatureResolverFn } from "./private/feature-set.js";
import { createFeatureResolver } from "./private/feature-set.js";
import { LongType, ScalarType } from "./scalar.js";
import { isMessage } from "./is-message";
import { isMessage } from "./is-message.js";

/**
* Create a DescriptorSet, a convenient interface for working with a set of
Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/src/create-registry-from-desc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import type {
import { createDescriptorSet } from "./create-descriptor-set.js";
import type { Extension } from "./extension.js";
import type { ExtensionFieldSource } from "./private/extensions.js";
import { isMessage } from "./is-message";
import { isMessage } from "./is-message.js";

// well-known message types with specialized JSON representation
const wkMessages = [
Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/src/private/binary-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { assert } from "./assert.js";
import { isFieldSet } from "./reflect.js";
import type { ScalarValue } from "../scalar.js";
import { LongType, ScalarType } from "../scalar.js";
import { isMessage } from "../is-message";
import { isMessage } from "../is-message.js";

/* eslint-disable prefer-const,no-case-declarations,@typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return */

Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/src/private/field-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Message } from "../message.js";
import type { MessageType } from "../message-type.js";
import type { DescExtension, DescField } from "../descriptor-set.js";
import { ScalarType } from "../scalar.js";
import { isMessage } from "../is-message";
import { isMessage } from "../is-message.js";

/* eslint-disable @typescript-eslint/no-explicit-any -- unknown fields are represented with any */

Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/src/private/json-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { scalarZeroValue } from "./scalars.js";
import { isScalarZeroValue } from "./scalars.js";
import type { ScalarValue } from "../scalar.js";
import { LongType, ScalarType } from "../scalar.js";
import { isMessage } from "../is-message";
import { isMessage } from "../is-message.js";

/* eslint-disable no-case-declarations,@typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call */

Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/src/private/util-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { MessageType } from "../message-type.js";
import type { Util } from "./util.js";
import { scalarEquals } from "./scalars.js";
import { ScalarType } from "../scalar.js";
import { isMessage } from "../is-message";
import { isMessage } from "../is-message.js";

/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-argument,no-case-declarations */

Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/src/to-plain-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { Message } from "./message.js";
import type { AnyMessage, PlainMessage } from "./message.js";
import { isMessage } from "./is-message";
import { isMessage } from "./is-message.js";

/**
* toPlainMessage returns a new object by stripping
Expand Down
13 changes: 1 addition & 12 deletions packages/protoplugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,20 @@
},
"scripts": {
"clean": "rm -rf ./dist/*",
"build": "npm run build:cjs && npm run build:esm && npm run build:proxy",
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
"build:proxy": "node ../../scripts/gen-esm-proxy.mjs . ecmascript",
"attw": "attw --pack"
},
"type": "module",
"sideEffects": false,
"main": "./dist/cjs/index.js",
"exports": {
".": {
"node": {
"import": "./dist/proxy/index.js",
"require": "./dist/cjs/index.js"
},
"module": "./dist/esm/index.js",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
},
"./ecmascript": {
"node": {
"import": "./dist/proxy/ecmascript/index.js",
"require": "./dist/cjs/ecmascript/index.js"
},
"module": "./dist/esm/ecmascript/index.js",
"import": "./dist/esm/ecmascript/index.js",
"require": "./dist/cjs/ecmascript/index.js"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/protoplugin/src/ecmascript/generated-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
LiteralString,
RefDescEnum,
RefDescMessage,
} from "./opaque-printables";
} from "./opaque-printables.js";

/**
* All types that can be passed to GeneratedFile.print()
Expand Down
117 changes: 0 additions & 117 deletions scripts/gen-esm-proxy.mjs

This file was deleted.

0 comments on commit 38ca963

Please sign in to comment.