@bufbuild/protoplugin 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -103,7 +103,7 @@ function printableToEl(printables, el, createTypeImport, runtimeImports) {
103
103
  el.push(p);
104
104
  break;
105
105
  case "number":
106
- el.push(literalNumber(p));
106
+ el.push(...literalNumber(p, runtimeImports));
107
107
  break;
108
108
  case "boolean":
109
109
  el.push(p.toString());
@@ -241,15 +241,15 @@ function processImports(el, importerPath, rewriteImportPath, makeImportStatement
241
241
  }
242
242
  return symbolToIdentifier;
243
243
  }
244
- function literalNumber(value) {
244
+ function literalNumber(value, runtimeImports) {
245
245
  if (Number.isNaN(value)) {
246
- return "globalThis.Number.NaN";
246
+ return [runtimeImports.protoDouble, ".NaN"];
247
247
  }
248
248
  if (value === Number.POSITIVE_INFINITY) {
249
- return "globalThis.Number.POSITIVE_INFINITY";
249
+ return [runtimeImports.protoDouble, ".POSITIVE_INFINITY"];
250
250
  }
251
251
  if (value === Number.NEGATIVE_INFINITY) {
252
- return "globalThis.Number.NEGATIVE_INFINITY";
252
+ return [runtimeImports.protoDouble, ".NEGATIVE_INFINITY"];
253
253
  }
254
254
  return value.toString(10);
255
255
  }
@@ -15,11 +15,6 @@
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.findCustomEnumOption = exports.findCustomMessageOption = exports.findCustomScalarOption = exports.literalString = exports.makeJsDoc = exports.getFieldTyping = exports.getFieldIntrinsicDefaultValue = exports.getFieldExplicitDefaultValue = exports.createJsDocBlock = exports.reifyWkt = exports.localName = void 0;
17
17
  const protobuf_1 = require("@bufbuild/protobuf");
18
- var target_js_1 = require("./target.js");
19
- var schema_js_1 = require("./schema.js");
20
- var runtime_imports_js_1 = require("./runtime-imports.js");
21
- var generated_file_js_1 = require("./generated-file.js");
22
- var import_symbol_js_1 = require("./import-symbol.js");
23
18
  exports.localName = protobuf_1.codegenInfo.localName, exports.reifyWkt = protobuf_1.codegenInfo.reifyWkt;
24
19
  var gencommon_js_1 = require("./gencommon.js");
25
20
  Object.defineProperty(exports, "createJsDocBlock", { enumerable: true, get: function () { return gencommon_js_1.createJsDocBlock; } });
@@ -32,6 +32,7 @@ function createRuntimeImports(bootstrapWkt) {
32
32
  JsonWriteOptions: infoToSymbol("JsonWriteOptions", bootstrapWkt),
33
33
  JsonValue: infoToSymbol("JsonValue", bootstrapWkt),
34
34
  JsonObject: infoToSymbol("JsonObject", bootstrapWkt),
35
+ protoDouble: infoToSymbol("protoDouble", bootstrapWkt),
35
36
  protoInt64: infoToSymbol("protoInt64", bootstrapWkt),
36
37
  ScalarType: infoToSymbol("ScalarType", bootstrapWkt),
37
38
  MethodKind: infoToSymbol("MethodKind", bootstrapWkt),
package/dist/cjs/index.js CHANGED
@@ -14,8 +14,6 @@
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.createEcmaScriptPlugin = exports.runNodeJs = void 0;
17
- var plugin_js_1 = require("./plugin.js");
18
- var schema_js_1 = require("./ecmascript/schema.js");
19
17
  var run_node_js_1 = require("./run-node.js");
20
18
  Object.defineProperty(exports, "runNodeJs", { enumerable: true, get: function () { return run_node_js_1.runNodeJs; } });
21
19
  var create_es_plugin_js_1 = require("./create-es-plugin.js");
@@ -99,7 +99,7 @@ function printableToEl(printables, el, createTypeImport, runtimeImports) {
99
99
  el.push(p);
100
100
  break;
101
101
  case "number":
102
- el.push(literalNumber(p));
102
+ el.push(...literalNumber(p, runtimeImports));
103
103
  break;
104
104
  case "boolean":
105
105
  el.push(p.toString());
@@ -237,15 +237,15 @@ function processImports(el, importerPath, rewriteImportPath, makeImportStatement
237
237
  }
238
238
  return symbolToIdentifier;
239
239
  }
240
- function literalNumber(value) {
240
+ function literalNumber(value, runtimeImports) {
241
241
  if (Number.isNaN(value)) {
242
- return "globalThis.Number.NaN";
242
+ return [runtimeImports.protoDouble, ".NaN"];
243
243
  }
244
244
  if (value === Number.POSITIVE_INFINITY) {
245
- return "globalThis.Number.POSITIVE_INFINITY";
245
+ return [runtimeImports.protoDouble, ".POSITIVE_INFINITY"];
246
246
  }
247
247
  if (value === Number.NEGATIVE_INFINITY) {
248
- return "globalThis.Number.NEGATIVE_INFINITY";
248
+ return [runtimeImports.protoDouble, ".NEGATIVE_INFINITY"];
249
249
  }
250
250
  return value.toString(10);
251
251
  }
@@ -12,11 +12,6 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
  import { codegenInfo } from "@bufbuild/protobuf";
15
- export {} from "./target.js";
16
- export {} from "./schema.js";
17
- export {} from "./runtime-imports.js";
18
- export {} from "./generated-file.js";
19
- export {} from "./import-symbol.js";
20
15
  export const { localName, reifyWkt } = codegenInfo;
21
16
  export { createJsDocBlock, getFieldExplicitDefaultValue, getFieldIntrinsicDefaultValue, getFieldTyping, makeJsDoc, literalString, } from "./gencommon.js";
22
17
  export { findCustomScalarOption, findCustomMessageOption, findCustomEnumOption, } from "./custom-options.js";
@@ -29,6 +29,7 @@ export function createRuntimeImports(bootstrapWkt) {
29
29
  JsonWriteOptions: infoToSymbol("JsonWriteOptions", bootstrapWkt),
30
30
  JsonValue: infoToSymbol("JsonValue", bootstrapWkt),
31
31
  JsonObject: infoToSymbol("JsonObject", bootstrapWkt),
32
+ protoDouble: infoToSymbol("protoDouble", bootstrapWkt),
32
33
  protoInt64: infoToSymbol("protoInt64", bootstrapWkt),
33
34
  ScalarType: infoToSymbol("ScalarType", bootstrapWkt),
34
35
  MethodKind: infoToSymbol("MethodKind", bootstrapWkt),
package/dist/esm/index.js CHANGED
@@ -11,7 +11,5 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
- export {} from "./plugin.js";
15
- export {} from "./ecmascript/schema.js";
16
14
  export { runNodeJs } from "./run-node.js";
17
15
  export { createEcmaScriptPlugin } from "./create-es-plugin.js";
@@ -24,6 +24,10 @@ export interface GeneratedFile {
24
24
  *
25
25
  * The preamble is always placed at the very top of the generated file,
26
26
  * above import statements.
27
+ *
28
+ * A file with a preamble but no other content is still considered empty,
29
+ * and will not be generated unless the plugin option keep_empty_files=true
30
+ * is set.
27
31
  */
28
32
  preamble(file: DescFile): void;
29
33
  /**
@@ -13,6 +13,7 @@ export interface RuntimeImports {
13
13
  JsonWriteOptions: ImportSymbol;
14
14
  JsonValue: ImportSymbol;
15
15
  JsonObject: ImportSymbol;
16
+ protoDouble: ImportSymbol;
16
17
  protoInt64: ImportSymbol;
17
18
  ScalarType: ImportSymbol;
18
19
  MethodKind: ImportSymbol;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bufbuild/protoplugin",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "license": "(Apache-2.0 AND BSD-3-Clause)",
5
5
  "description": "Helps to create your own Protocol Buffers code generators.",
6
6
  "repository": {
@@ -35,7 +35,7 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@bufbuild/protobuf": "1.2.0",
38
+ "@bufbuild/protobuf": "1.3.0",
39
39
  "@typescript/vfs": "^1.4.0",
40
40
  "typescript": "4.5.2"
41
41
  },
@@ -43,6 +43,6 @@
43
43
  "dist/**"
44
44
  ],
45
45
  "devDependencies": {
46
- "@types/lz-string": "^1.3.34"
46
+ "@types/lz-string": "^1.5.0"
47
47
  }
48
48
  }