ts-proto 1.115.4 → 1.115.5

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.115.5](https://github.com/stephenh/ts-proto/compare/v1.115.4...v1.115.5) (2022-06-22)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * remove Long import statement when Long was unused ([#599](https://github.com/stephenh/ts-proto/issues/599)) ([58dc10c](https://github.com/stephenh/ts-proto/commit/58dc10c61ec5a76d4b54ba9eddf34021979dd4aa))
7
+
1
8
  ## [1.115.4](https://github.com/stephenh/ts-proto/compare/v1.115.3...v1.115.4) (2022-06-05)
2
9
 
3
10
 
package/build/main.js CHANGED
@@ -188,9 +188,6 @@ function generateFile(ctx, fileDesc) {
188
188
  if (v instanceof ConditionalOutput_1.ConditionalOutput) {
189
189
  return ts_poet_1.code `${v.ifUsed}`;
190
190
  }
191
- else if (v instanceof ts_poet_1.Code) {
192
- return v;
193
- }
194
191
  else {
195
192
  return ts_poet_1.code ``;
196
193
  }
@@ -237,23 +234,22 @@ function makeLongUtils(options, bytes) {
237
234
  //
238
235
  // I.e there is not an import for long that "just works" in both esModuleInterop and
239
236
  // not esModuleInterop.
240
- const Long = options.esModuleInterop ? ts_poet_1.imp('Long=long') : ts_poet_1.imp('Long*long');
237
+ const LongImp = options.esModuleInterop ? ts_poet_1.imp('Long=long') : ts_poet_1.imp('Long*long');
241
238
  const disclaimer = options.esModuleInterop
242
239
  ? ''
243
240
  : `
244
241
  // If you get a compile-error about 'Constructor<Long> and ... have no overlap',
245
242
  // add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'.`;
246
- // Kinda hacky, but we always init long unless in onlyTypes mode. I'd rather do
247
- // this more implicitly, like if `Long@long` is imported or something like that.
248
- const longInit = options.onlyTypes
249
- ? ts_poet_1.code ``
250
- : ts_poet_1.code `
243
+ // Instead of exposing `LongImp` directly, let callers think that they are getting the
244
+ // `imp(Long)` but really it is that + our long initialization snippet. This means the
245
+ // initialization code will only be emitted in files that actually use the Long import.
246
+ const Long = ts_poet_1.conditionalOutput('Long', ts_poet_1.code `
251
247
  ${disclaimer}
252
- if (${util}.Long !== ${Long}) {
253
- ${util}.Long = ${Long} as any;
248
+ if (${util}.Long !== ${LongImp}) {
249
+ ${util}.Long = ${LongImp} as any;
254
250
  ${configure}();
255
251
  }
256
- `;
252
+ `);
257
253
  // TODO This is unused?
258
254
  const numberToLong = ts_poet_1.conditionalOutput('numberToLong', ts_poet_1.code `
259
255
  function numberToLong(number: number) {
@@ -273,7 +269,7 @@ function makeLongUtils(options, bytes) {
273
269
  return long.toNumber();
274
270
  }
275
271
  `);
276
- return { numberToLong, longToNumber, longToString, longInit, Long };
272
+ return { numberToLong, longToNumber, longToString, Long };
277
273
  }
278
274
  function makeByteUtils() {
279
275
  const globalThis = ts_poet_1.conditionalOutput('globalThis', ts_poet_1.code `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.115.4",
3
+ "version": "1.115.5",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",