Add compiler optimizer option to npm package (#310)

This commit is contained in:
PG Herveou
2025-05-08 12:38:27 +02:00
committed by GitHub
parent 8b1a36eddf
commit 761fd8d6a4
2 changed files with 21 additions and 5 deletions
+4 -1
View File
@@ -312,7 +312,10 @@ jobs:
npm -w js/resolc run build npm -w js/resolc run build
- name: Set version - name: Set version
run: npm -w js/resolc version --no-git-tag-version ${{github.event.release.tag_name}} run: |
VERSION="${{ github.event.release.tag_name }}"
STRIPPED_VERSION="${VERSION#v}"
npm -w js/resolc version --no-git-tag-version "$STRIPPED_VERSION"
- name: npm pack - name: npm pack
run: npm -w js/resolc pack run: npm -w js/resolc pack
+17 -4
View File
@@ -93,13 +93,26 @@ export function version(): string {
export async function compile( export async function compile(
sources: SolcInput, sources: SolcInput,
option: { bin?: string } = {} option: {
optimizer?: Record<string, unknown>
bin?: string
} = {}
): Promise<SolcOutput> { ): Promise<SolcOutput> {
const {
optimizer = {
mode: 'z',
fallback_to_optimizing_for_size: true,
enabled: true,
runs: 200,
},
bin,
} = option
const input = JSON.stringify({ const input = JSON.stringify({
language: 'Solidity', language: 'Solidity',
sources: resolveInputs(sources), sources: resolveInputs(sources),
settings: { settings: {
optimizer: { enabled: true, runs: 200 }, optimizer,
outputSelection: { outputSelection: {
'*': { '*': {
'*': ['abi'], '*': ['abi'],
@@ -108,8 +121,8 @@ export async function compile(
}, },
}) })
if (option.bin) { if (bin) {
return compileWithBin(input, option.bin) return compileWithBin(input, bin)
} }
return resolc(input) return resolc(input)