|
1 | | -const { execSync } = require("child_process"); |
2 | | -const LoadingStrategy = require("./LoadingStrategy"); |
3 | | -const VersionRange = require("./VersionRange"); |
| 1 | +const { execSync } = require('child_process'); |
| 2 | +const LoadingStrategy = require('./LoadingStrategy'); |
| 3 | +const VersionRange = require('./VersionRange'); |
4 | 4 |
|
5 | 5 | class Native extends LoadingStrategy { |
6 | | - load() { |
| 6 | + load () { |
7 | 7 | const versionString = this.validateAndGetSolcVersion(); |
8 | | - const command = "solc --standard-json"; |
| 8 | + const command = 'solc --standard-json'; |
| 9 | + const maxBuffer = 1024 * 1024 * 10; |
9 | 10 |
|
10 | | - try { |
11 | | - return { |
12 | | - compile: options => String(execSync(command, { input: options })), |
13 | | - version: () => versionString |
14 | | - }; |
15 | | - } catch (error) { |
16 | | - if (error.message === "No matching version found") { |
17 | | - throw this.errors("noVersion", versionString); |
18 | | - } |
19 | | - throw new Error(error); |
20 | | - } |
| 11 | + return { |
| 12 | + compile: options => |
| 13 | + String(execSync(command, { input: options, maxBuffer })), |
| 14 | + version: () => versionString |
| 15 | + }; |
21 | 16 | } |
22 | 17 |
|
23 | | - validateAndGetSolcVersion() { |
| 18 | + validateAndGetSolcVersion () { |
24 | 19 | let version; |
25 | 20 | try { |
26 | | - version = execSync("solc --version"); |
| 21 | + version = execSync('solc --version'); |
27 | 22 | } catch (error) { |
28 | | - throw this.errors("noNative", null, error); |
| 23 | + throw this.errors('noNative', null, error); |
29 | 24 | } |
30 | 25 | return new VersionRange(this.config).normalizeSolcVersion(version); |
31 | 26 | } |
|
0 commit comments