Skip to content

Commit dbfd68e

Browse files
committed
use relative path in artifact file
1 parent 8469349 commit dbfd68e

3 files changed

Lines changed: 32 additions & 27 deletions

File tree

src/compilerWrapper.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ChildProcess, exec, execSync } from 'child_process';
22
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'fs';
3-
import { basename, dirname, join } from 'path';
3+
import { basename, dirname, join, relative } from 'path';
44
import {
55
buildTypeResolver, Artifact, CURRENT_CONTRACT_ARTIFACT_VERSION, findCompiler, hash160, md5, path2uri, resolveConstValue, TypeResolver
66
} from './internal';
@@ -457,6 +457,11 @@ export function handleCompilerOutput(
457457
const artifact = result.toArtifact();
458458

459459
writeFileSync(artifactFile, JSON.stringify(artifact, (key, value) => {
460+
461+
if (key === 'file') {
462+
return relative(artifactFile, value)
463+
}
464+
460465
//ignore deprecated fields
461466
if (key == 'sources' || key == 'sourceMap' || key === 'asm')
462467
return undefined;
@@ -542,7 +547,7 @@ export function getFullFilePath(relativePath: string, baseDir: string, curFileNa
542547
}
543548

544549
if (relativePath === 'std') {
545-
return 'std'; //
550+
return 'std'; //
546551
}
547552

548553
return join(baseDir, relativePath);
@@ -612,7 +617,7 @@ function shortGenericType(genericType: string): string {
612617
}
613618

614619
/**
615-
*
620+
*
616621
* @param astRoot AST root node after main contract compilation
617622
* @param typeResolver a Type Resolver
618623
* @returns All function ABIs defined by the main contract, including constructors
@@ -646,7 +651,7 @@ export function getABIDeclaration(astRoot: unknown, typeResolver: TypeResolver):
646651
}
647652

648653
/**
649-
*
654+
*
650655
* @param astRoot AST root node after main contract compilation
651656
* @param dependencyAsts AST root node after all dependency contract compilation
652657
* @returns all defined structures of the main contract and dependent contracts
@@ -672,7 +677,7 @@ export function getStructDeclaration(astRoot: unknown, dependencyAsts: unknown):
672677

673678

674679
/**
675-
*
680+
*
676681
* @param astRoot AST root node after main contract compilation
677682
* @param dependencyAsts AST root node after all dependency contract compilation
678683
* @returns all defined Library of the main contract and dependent contracts
@@ -748,7 +753,7 @@ export function getContractDeclaration(astRoot: unknown, dependencyAsts: unknown
748753

749754

750755
/**
751-
*
756+
*
752757
* @param astRoot AST root node after main contract compilation
753758
* @param dependencyAsts AST root node after all dependency contract compilation
754759
* @returns all defined type aliaes of the main contract and dependent contracts
@@ -772,7 +777,7 @@ export function getAliasDeclaration(astRoot: unknown, dependencyAsts: unknown):
772777

773778

774779
/**
775-
*
780+
*
776781
* @param astRoot AST root node after main contract compilation
777782
* @param dependencyAsts AST root node after all dependency contract compilation
778783
* @returns all defined static const int literal of the main contract and dependent contracts
@@ -928,7 +933,7 @@ function parserAst(result: CompileResult, ast: any, srcDir: string, sourceFileNa
928933
const allAst = addSourceLocation(ast, srcDir, sourceFileName);
929934

930935
const sourceUri = path2uri(sourcePath);
931-
result.file = sourceUri;
936+
result.file = sourcePath;
932937
result.ast = allAst[sourceUri];
933938
delete allAst[sourceUri];
934939
result.dependencyAsts = allAst;
@@ -977,11 +982,11 @@ function parserAst(result: CompileResult, ast: any, srcDir: string, sourceFileNa
977982

978983
/**
979984
* @deprecated use `--hex` when compiling
980-
* @param result
981-
* @param asmObj
982-
* @param settings
983-
* @param srcDir
984-
* @param sourceFileName
985+
* @param result
986+
* @param asmObj
987+
* @param settings
988+
* @param srcDir
989+
* @param sourceFileName
985990
*/
986991
function parserASM(result: CompileResult, asmObj: any, settings: CompilingSettings, srcDir: string, sourceFileName: string) {
987992

src/contract.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { basename, dirname } from 'path';
1+
import { basename, dirname, join } from 'path';
22
import { ABIEntityType, Argument, LibraryEntity, ParamEntity, parseGenericType } from '.';
33
import { ContractEntity, getFullFilePath, loadSourceMapfromArtifact, OpCode, StaticEntity } from './compilerWrapper';
44
import {
@@ -10,7 +10,7 @@ import { arrayTypeAndSize, checkSupportedParamType, flatternArg, hasGeneric, sub
1010

1111

1212
/**
13-
* TxContext provides some context information of the current transaction,
13+
* TxContext provides some context information of the current transaction,
1414
* needed only if signature is checked inside the contract.
1515
*/
1616
export interface TxContext {
@@ -66,7 +66,7 @@ export interface Artifact {
6666
asm?: string;
6767
/** locking script of the contract in hex format, including placeholders for constructor parameters */
6868
hex: string;
69-
/** file uri of the main contract source code file */
69+
/** relative file uri of the main contract source code file */
7070
file: string;
7171
/** @deprecated **/
7272
sources?: Array<string>;
@@ -326,7 +326,7 @@ export class AbstractContract {
326326
}
327327

328328
/**
329-
* format the error
329+
* format the error
330330
* @param err the result output by `tx.verifyInputScript(inputIndex)`
331331
* @returns string the formatted error message.
332332
*/
@@ -346,7 +346,7 @@ export class AbstractContract {
346346
const sourceMapFilePath = uri2path(this.sourceMapFile);
347347
const sourceMap = JSONParserSync(sourceMapFilePath);
348348

349-
const sourcePath = uri2path(this.file);
349+
const sourcePath = join(sourceMapFilePath, this.file);
350350

351351
const srcDir = dirname(sourcePath);
352352
const sourceFileName = basename(sourcePath);
@@ -397,7 +397,7 @@ export class AbstractContract {
397397

398398
/**
399399
* Generate a debugger launch configuration for the contract's last called public method
400-
* @param txContext
400+
* @param txContext
401401
* @returns a uri of the debugger launch configuration
402402
*/
403403
public genLaunchConfig(txContext?: TxContext): string {
@@ -435,10 +435,10 @@ export class AbstractContract {
435435
}
436436

437437
/**
438-
* @deprecated use setDataPartInASM setDataPartInHex
438+
* @deprecated use setDataPartInASM setDataPartInHex
439439
* set the data part of the contract
440-
* @param state
441-
* @param isStateHex
440+
* @param state
441+
* @param isStateHex
442442
*/
443443
setDataPart(state: string, isStateHex = false): void {
444444
if (isStateHex == false) {
@@ -452,8 +452,8 @@ export class AbstractContract {
452452

453453
/**
454454
* set the data part of the contract in ASM format
455-
* @param asm
456-
* @param
455+
* @param asm
456+
* @param
457457
*/
458458
setDataPartInASM(asm: string): void {
459459
if (AbstractContract.isStateful(this)) {
@@ -465,7 +465,7 @@ export class AbstractContract {
465465

466466
/**
467467
* set the data part of the contract in hex format
468-
* @param hex
468+
* @param hex
469469
*/
470470
setDataPartInHex(hex: string): void {
471471
this._dataPartInHex = hex.trim();
@@ -711,7 +711,7 @@ export class AbstractContract {
711711

712712

713713

714-
// struct / array: sha256 every single element of the flattened struct / array, and concat the result to a joint byte, and sha256 again
714+
// struct / array: sha256 every single element of the flattened struct / array, and concat the result to a joint byte, and sha256 again
715715
// basic type: sha256 every single element
716716
static flattenSha256(data: SupportedParamType, type: string): string {
717717
const error = checkSupportedParamType(data, {

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}
1919
},
2020
"compilerOptions": {
21-
"target": "es5",
21+
"target": "es2020",
2222
"lib": [
2323
"dom",
2424
"dom.iterable",

0 commit comments

Comments
 (0)