Skip to content

Commit

Permalink
fix: require long instead of import (#1313)
Browse files Browse the repository at this point in the history
We'll need to figure out the `Long` stuff once and forever. Pin the dependency for now.
  • Loading branch information
alexander-fenster committed Aug 17, 2022
1 parent 5898da6 commit 325f497
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions test/unit/compileProtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ describe('compileProtos tool', () => {
const ts = await readFile(expectedTSResultFile);
assert(ts.toString().includes('TestMessage'));
assert(ts.toString().includes('LibraryService'));
assert(ts.toString().includes('import * as Long'));
assert(ts.toString().includes('import Long = require'));
assert(!ts.toString().includes('import * as Long'));
assert(
ts.toString().includes('http://www.apache.org/licenses/LICENSE-2.0')
);
Expand Down Expand Up @@ -114,7 +115,8 @@ describe('compileProtos tool', () => {
const ts = await readFile(expectedTSResultFile);
assert(ts.toString().includes('TestMessage'));
assert(ts.toString().includes('LibraryService'));
assert(ts.toString().includes('import * as Long'));
assert(ts.toString().includes('import Long = require'));
assert(!ts.toString().includes('import * as Long'));
assert(
ts.toString().includes('http://www.apache.org/licenses/LICENSE-2.0')
);
Expand Down Expand Up @@ -146,7 +148,8 @@ describe('compileProtos tool', () => {
assert(fs.existsSync(expectedTSResultFile));
const ts = await readFile(expectedTSResultFile);

assert(ts.toString().includes('import * as Long'));
assert(ts.toString().includes('import Long = require'));
assert(!ts.toString().includes('import * as Long'));
assert(
ts.toString().includes('http://www.apache.org/licenses/LICENSE-2.0')
);
Expand Down
8 changes: 6 additions & 2 deletions tools/compileProtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ function fixDtsFile(dts: string): string {
// 1. fix for pbts output: the corresponding protobufjs PR
// https://github.com/protobufjs/protobuf.js/pull/1166
// is merged but not yet released.
if (!dts.match(/import \* as Long/)) {
dts = 'import * as Long from "long";\n' + dts;
dts = dts.replace(
'import * as Long from "long";',
'import Long = require("long");'
);
if (!dts.match(/import Long = require/)) {
dts = 'import Long = require("long");' + dts;
}

// 2. fix protobufjs import: we don't want the libraries to
Expand Down

0 comments on commit 325f497

Please sign in to comment.