Skip to content

Commit c63e6b1

Browse files
authored
fix/versions (#30)
* fix: readme and enumable version * 0.2.12 * export type
1 parent 184f892 commit c63e6b1

File tree

7 files changed

+63
-18
lines changed

7 files changed

+63
-18
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,27 @@ async function readExample() {
8080
}
8181
```
8282

83+
### Test Move Package
84+
```ts
85+
import { MoveBuilder } from '@initia/builder.js';
86+
87+
async function testExample() {
88+
const builder = new MoveBuilder(path.resolve(__dirname, 'moon_coin'), {});
89+
// test module with options
90+
const testResult = await builder.test({
91+
filter: '...',
92+
reportStatistics: true,
93+
reportStorageOnError: true,
94+
ignoreCompileWarnings: true,
95+
computeCoverage: true,
96+
})
97+
console.log(testResult) // 'ok'
98+
}
99+
```
100+
> **⚠ WARNING:**
101+
> If the test fails due to a native function conflict, note that `builder.js` always follows the latest MoveVM version.
102+
> If you are using an older version of MoveVM, you need to replace the library used in `@initia/builder.js/library`.
103+
> You should replace the `.so` files in `node_modules/@initia/builder.js/library` with the `.so` libraries from the movevm version you are using.
83104
## Options
84105

85106
For more details on the available options, refer to the [source code](src/types/options.ts).

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@initia/builder.js",
3-
"version": "0.2.11",
3+
"version": "0.2.12",
44
"description": "The JavaScript Move Builder for Initia",
55
"license": "MIT",
66
"author": "Initia Foundation",

src/builder.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ import {
1414
DecodedModuleBytes,
1515
DecodedScriptBytes,
1616
ModuleInfo,
17+
BytecodeVersion,
18+
LanguageVersion,
19+
CompilerVersion,
1720
} from './types'
1821

1922
type ModuleName = string
2023

21-
const DEFAULT_BYTECODE_VERSION = 7
22-
const DEFAULT_LANGUAGE_VERSION = '2'
23-
const DEFAULT_COMPILER_VERSION = '2'
24+
const DEFAULT_BYTECODE_VERSION = BytecodeVersion.V7
25+
const DEFAULT_LANGUAGE_VERSION = LanguageVersion.V2_1
26+
const DEFAULT_COMPILER_VERSION = CompilerVersion.V2_1
2427
export class MoveBuilder {
2528
private readonly packagePath: string
2629
private buildOptions: BuildOptions

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ export {
55
ModuleInfo,
66
DecodedModuleBytes,
77
DecodedScriptBytes,
8+
BytecodeVersion,
9+
CompilerVersion,
10+
LanguageVersion,
811
} from './types'
912
export * from './builder'

src/types/options.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
export enum BytecodeVersion {
2+
V6 = 6,
3+
V7 = 7,
4+
}
5+
6+
export enum LanguageVersion {
7+
V1 = '1',
8+
V2_0 = '2.0',
9+
V2_1 = '2.1',
10+
}
11+
12+
export enum CompilerVersion {
13+
V1 = '1',
14+
V2_0 = '2.0',
15+
V2_1 = '2.1',
16+
}
17+
118
export interface BuildOptions {
219
/**
320
* Compile in 'dev' mode. The 'dev-addresses' and 'dev-dependencies' fields will be used if
@@ -43,19 +60,19 @@ export interface BuildOptions {
4360
skipFetchLatestGitDeps?: boolean
4461

4562
/**
46-
* Bytecode version. Set to 0 to unset and use default.
63+
* Bytecode version. unset and use default.
4764
*/
48-
bytecodeVersion?: number
65+
bytecodeVersion?: BytecodeVersion
4966

5067
/**
51-
* Compiler version. Set to 0 to unset and use default.
68+
* Compiler version. unset and use default.
5269
*/
53-
compilerVersion?: string
70+
compilerVersion?: CompilerVersion
5471

5572
/**
56-
* Language version. Set to 0 to unset and use default.
73+
* Language version. unset and use default.
5774
*/
58-
languageVersion?: string
75+
languageVersion?: LanguageVersion
5976

6077
/**
6178
* Additional named address mapping. Useful for tools in Rust.

test/build.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'path'
22
import { readFile } from 'fs/promises'
33
import { MoveBuilder } from '../src/builder'
4+
import { BytecodeVersion, CompilerVersion, LanguageVersion } from '../src/types'
45

56
describe('build move package', () => {
67
const contractDir = path.resolve(__dirname, 'contract/dummy')
@@ -12,9 +13,9 @@ describe('build move package', () => {
1213
forceRecompilation: true,
1314
fetchDepsOnly: true,
1415
skipFetchLatestGitDeps: true,
15-
bytecodeVersion: 7,
16-
compilerVersion: '2',
17-
languageVersion: '1',
16+
bytecodeVersion: BytecodeVersion.V7,
17+
compilerVersion: CompilerVersion.V2_1,
18+
languageVersion: LanguageVersion.V2_1,
1819
additionalNamedAddresses: [['test', '0x4']],
1920
})
2021
const dummyModulePath = path.join(
@@ -25,9 +26,9 @@ describe('build move package', () => {
2526

2627
it('get default values of move builder', () => {
2728
expect(MoveBuilder.getDefaultVersions()).toEqual({
28-
bytecodeVersion: 7,
29-
compilerVersion: '2',
30-
languageVersion: '2',
29+
bytecodeVersion: BytecodeVersion.V7,
30+
compilerVersion: CompilerVersion.V2_1,
31+
languageVersion: LanguageVersion.V2_1,
3132
})
3233
})
3334

0 commit comments

Comments
 (0)