Skip to content

Commit 25c98cb

Browse files
stephen-slmcameel
authored andcommitted
fix: use esModuleInterop to resolve commonjs default require
By doing so allows the commonjs default imports to work as expected not blocking backwards compatibility. reference: https://www.typescriptlang.org/tsconfig#esModuleInterop
1 parent c5aae68 commit 25c98cb

18 files changed

+33
-51
lines changed

abi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ function update (compilerVersion, abi) {
5858
return abi;
5959
}
6060

61-
export default {
61+
export = {
6262
update
6363
};

downloadCurrentVersion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// This is used to download the correct binary version
44
// as part of the prepublish step.
55

6-
import * as pkg from './package.json';
76
import * as fs from 'fs';
87
import { https } from 'follow-redirects';
9-
import * as MemoryStream from 'memorystream';
8+
import MemoryStream from 'memorystream';
109
import { keccak256 } from 'js-sha3';
10+
const pkg = require('./package.json');
1111

1212
function getVersionList (cb) {
1313
console.log('Retrieving available version list...');

index.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,4 @@
11
import wrapper from './wrapper';
22

33
const soljson = require('./soljson.js');
4-
const wrapped = wrapper(soljson);
5-
6-
const {
7-
version,
8-
semver,
9-
license,
10-
lowlevel,
11-
features,
12-
compile,
13-
loadRemoteVersion,
14-
setupMethods
15-
} = wrapped;
16-
17-
export {
18-
version,
19-
semver,
20-
license,
21-
lowlevel,
22-
features,
23-
compile,
24-
loadRemoteVersion,
25-
setupMethods
26-
};
4+
export = wrapper(soljson);

linker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as assert from 'assert';
1+
import assert from 'assert';
22
import { keccak256 } from 'js-sha3';
33

44
function libraryHashPlaceholder (input) {
@@ -88,7 +88,7 @@ const findLinkReferences = function (bytecode) {
8888
return linkReferences;
8989
};
9090

91-
export default {
91+
export = {
9292
linkBytecode,
9393
findLinkReferences
9494
};

smtchecker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function smtCallback (solverFunction, solver?: any) {
3636
};
3737
}
3838

39-
export default {
39+
export = {
4040
handleSMTQueries,
4141
smtCallback
4242
};

smtsolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function solve (query, solver) {
6767
return solverOutput;
6868
}
6969

70-
export default {
70+
export = {
7171
smtSolver: solve,
7272
availableSolvers: solvers
7373
};

solc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as commander from 'commander';
44
import * as fs from 'fs';
55
import * as os from 'os';
66
import * as path from 'path';
7-
import * as solc from './index';
7+
import solc from './index';
88
import smtchecker from './smtchecker';
99
import smtsolver from './smtsolver';
1010

test/abi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as tape from 'tape';
1+
import tape from 'tape';
22
import abi from '../abi';
33

44
tape('ABI translator', function (t) {

test/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as tape from 'tape';
2-
import * as spawn from 'tape-spawn';
1+
import tape from 'tape';
2+
import spawn from 'tape-spawn';
33
import * as path from 'path';
4-
import * as pkg from '../package.json';
4+
const pkg = require('../package.json');
55

66
tape('CLI', function (t) {
77
t.test('--version', function (st) {

test/compiler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as assert from 'assert';
2-
import * as tape from 'tape';
1+
import assert from 'assert';
2+
import tape from 'tape';
33
import * as semver from 'semver';
4-
import * as solc from '../';
4+
import solc from '../';
55
import linker from '../linker';
66
import { execSync } from 'child_process';
77
import wrapper from '../wrapper';

test/linker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as tape from 'tape';
1+
import tape from 'tape';
22
import linker from '../linker';
33

44
tape('Link references', function (t) {

test/smtcallback.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import * as assert from 'assert';
2-
import * as tape from 'tape';
1+
import assert from 'assert';
2+
import tape from 'tape';
33
import * as fs from 'fs';
44
import * as path from 'path';
55
import * as semver from 'semver';
6-
import * as solc from '../';
6+
import solc from '../';
77
import smtchecker from '../smtchecker';
88
import smtsolver from '../smtsolver';
99

test/smtchecker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as tape from 'tape';
1+
import tape from 'tape';
22
import * as semver from 'semver';
3-
import * as solc from '../';
3+
import solc from '../';
44
import smtchecker from '../smtchecker';
55
import smtsolver from '../smtsolver';
66

test/translate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
3-
import * as tape from 'tape';
3+
import tape from 'tape';
44
import translate from '../translate';
55

66
const versionToSemver = translate.versionToSemver;

translate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function prettyPrintLegacyAssemblyJSON (assembly, source) {
193193
return formatAssemblyText(assembly, '', source);
194194
}
195195

196-
export default {
196+
export = {
197197
versionToSemver,
198198
translateJsonCompilerOutput,
199199
prettyPrintLegacyAssemblyJSON

tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"target": "esnext",
55
"module": "commonjs",
66
"resolveJsonModule": true,
7+
// This is needed for backwards-compatibility, to keep imports of the form `wrapper = require('solc/wrapper)`
8+
// working like they did before the TypeScript migration.
9+
// TODO: Drop it in the next breaking release.
10+
"esModuleInterop": true,
711
"outDir": "./dist",
812
"forceConsistentCasingInFileNames": true,
913
// Allow JS must be included to ensure that the built binary is included

verifyVersion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env node
22

33
import * as semver from 'semver';
4+
import solc from './';
45

5-
import { version as packageVersion } from './package.json';
6-
import * as solc from './';
6+
const { version: packageVersion } = require('./package.json');
77

88
const solcVersion = (solc as any).version();
99

wrapper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import translate from './translate';
22
import { https } from 'follow-redirects';
3-
import * as MemoryStream from 'memorystream';
4-
import * as assert from 'assert';
3+
import MemoryStream from 'memorystream';
4+
import assert from 'assert';
55
import * as semver from 'semver';
66

77
const Module = module.constructor as any;
@@ -357,4 +357,4 @@ function setupMethods (soljson) {
357357
};
358358
}
359359

360-
export default setupMethods;
360+
export = setupMethods;

0 commit comments

Comments
 (0)