skittles 1.4.1 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +16 -9
- package/dist/commands/clean.js.map +1 -1
- package/dist/commands/compile.d.ts.map +1 -1
- package/dist/commands/compile.js +26 -31
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +76 -88
- package/dist/commands/init.js.map +1 -1
- package/dist/compiler/analysis.d.ts.map +1 -1
- package/dist/compiler/analysis.js +17 -136
- package/dist/compiler/analysis.js.map +1 -1
- package/dist/compiler/class-parser.d.ts +25 -0
- package/dist/compiler/class-parser.d.ts.map +1 -0
- package/dist/compiler/class-parser.js +1040 -0
- package/dist/compiler/class-parser.js.map +1 -0
- package/dist/compiler/codegen-context.d.ts +10 -0
- package/dist/compiler/codegen-context.d.ts.map +1 -0
- package/dist/compiler/codegen-context.js +13 -0
- package/dist/compiler/codegen-context.js.map +1 -0
- package/dist/compiler/codegen.d.ts +2 -0
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/codegen.js +895 -304
- package/dist/compiler/codegen.js.map +1 -1
- package/dist/compiler/compiler.d.ts +1 -0
- package/dist/compiler/compiler.d.ts.map +1 -1
- package/dist/compiler/compiler.js +339 -265
- package/dist/compiler/compiler.js.map +1 -1
- package/dist/compiler/constants.d.ts +25 -0
- package/dist/compiler/constants.d.ts.map +1 -0
- package/dist/compiler/constants.js +34 -0
- package/dist/compiler/constants.js.map +1 -0
- package/dist/compiler/expression-parser.d.ts +5 -0
- package/dist/compiler/expression-parser.d.ts.map +1 -0
- package/dist/compiler/expression-parser.js +1212 -0
- package/dist/compiler/expression-parser.js.map +1 -0
- package/dist/compiler/formatter.d.ts +9 -0
- package/dist/compiler/formatter.d.ts.map +1 -0
- package/dist/compiler/formatter.js +126 -0
- package/dist/compiler/formatter.js.map +1 -0
- package/dist/compiler/mutability.d.ts +66 -0
- package/dist/compiler/mutability.d.ts.map +1 -0
- package/dist/compiler/mutability.js +677 -0
- package/dist/compiler/mutability.js.map +1 -0
- package/dist/compiler/parser-context.d.ts +24 -0
- package/dist/compiler/parser-context.d.ts.map +1 -0
- package/dist/compiler/parser-context.js +25 -0
- package/dist/compiler/parser-context.js.map +1 -0
- package/dist/compiler/parser-utils.d.ts +49 -0
- package/dist/compiler/parser-utils.d.ts.map +1 -0
- package/dist/compiler/parser-utils.js +566 -0
- package/dist/compiler/parser-utils.js.map +1 -0
- package/dist/compiler/parser.d.ts +6 -16
- package/dist/compiler/parser.d.ts.map +1 -1
- package/dist/compiler/parser.js +161 -3375
- package/dist/compiler/parser.js.map +1 -1
- package/dist/compiler/solc.d.ts +6 -6
- package/dist/compiler/solc.d.ts.map +1 -1
- package/dist/compiler/solc.js +36 -59
- package/dist/compiler/solc.js.map +1 -1
- package/dist/compiler/statement-parser.d.ts +14 -0
- package/dist/compiler/statement-parser.d.ts.map +1 -0
- package/dist/compiler/statement-parser.js +1081 -0
- package/dist/compiler/statement-parser.js.map +1 -0
- package/dist/compiler/type-parser.d.ts +7 -0
- package/dist/compiler/type-parser.d.ts.map +1 -0
- package/dist/compiler/type-parser.js +239 -0
- package/dist/compiler/type-parser.js.map +1 -0
- package/dist/compiler/walker.d.ts +20 -0
- package/dist/compiler/walker.d.ts.map +1 -0
- package/dist/compiler/walker.js +124 -0
- package/dist/compiler/walker.js.map +1 -0
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +94 -3
- package/dist/config/config.js.map +1 -1
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +6 -0
- package/dist/config/defaults.js.map +1 -1
- package/dist/exports.d.ts +2 -0
- package/dist/exports.d.ts.map +1 -1
- package/dist/exports.js +3 -0
- package/dist/exports.js.map +1 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/stdlib/resolver.d.ts +7 -0
- package/dist/stdlib/resolver.d.ts.map +1 -1
- package/dist/stdlib/resolver.js +31 -9
- package/dist/stdlib/resolver.js.map +1 -1
- package/dist/types/artifacts.d.ts +25 -0
- package/dist/types/artifacts.d.ts.map +1 -0
- package/dist/types/artifacts.js +2 -0
- package/dist/types/artifacts.js.map +1 -0
- package/dist/types/config.d.ts +25 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +5 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +4 -313
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +4 -23
- package/dist/types/index.js.map +1 -1
- package/dist/types/ir.d.ts +294 -0
- package/dist/types/ir.d.ts.map +1 -0
- package/dist/types/ir.js +21 -0
- package/dist/types/ir.js.map +1 -0
- package/dist/types/primitives.d.ts +6 -0
- package/dist/types/primitives.d.ts.map +1 -0
- package/dist/types/primitives.js +6 -0
- package/dist/types/primitives.js.map +1 -0
- package/dist/utils/regex.d.ts +5 -0
- package/dist/utils/regex.d.ts.map +1 -0
- package/dist/utils/regex.js +7 -0
- package/dist/utils/regex.js.map +1 -0
- package/package.json +8 -1
- package/stdlib/contracts/access/AccessControl.ts +103 -0
- package/stdlib/contracts/access/Ownable.ts +6 -5
- package/stdlib/contracts/constants.ts +3 -0
- package/stdlib/contracts/index.ts +6 -0
- package/stdlib/contracts/security/Pausable.ts +3 -3
- package/stdlib/contracts/security/ReentrancyGuard.ts +8 -5
- package/stdlib/contracts/token/ERC20.ts +17 -16
- package/stdlib/contracts/token/ERC20Permit.ts +81 -0
- package/stdlib/contracts/token/ERC20Votes.ts +92 -0
- package/stdlib/contracts/token/ERC721.ts +29 -28
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"AAKA,wBAAsB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"AAKA,wBAAsB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBrE"}
|
package/dist/commands/clean.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { removeDirectory } from "../utils/file.js";
|
|
3
|
-
import { logSuccess, logInfo } from "../utils/console.js";
|
|
3
|
+
import { logSuccess, logInfo, logError } from "../utils/console.js";
|
|
4
4
|
import { loadConfig } from "../config/config.js";
|
|
5
5
|
export async function cleanCommand(projectRoot) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
try {
|
|
7
|
+
const config = await loadConfig(projectRoot);
|
|
8
|
+
const outputDir = path.join(projectRoot, config.outputDir);
|
|
9
|
+
const cacheDir = path.join(projectRoot, config.cacheDir);
|
|
10
|
+
logInfo(`Removing output directory: ${config.outputDir}/`);
|
|
11
|
+
removeDirectory(outputDir);
|
|
12
|
+
logInfo(`Removing cache directory: ${config.cacheDir}/`);
|
|
13
|
+
removeDirectory(cacheDir);
|
|
14
|
+
logSuccess("Build artifacts cleaned");
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
const message = err instanceof Error ? err.message : "Unknown error occurred";
|
|
18
|
+
logError(message);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
14
21
|
}
|
|
15
22
|
//# sourceMappingURL=clean.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.js","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"clean.js","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,WAAmB;IACpD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,WAAW,CAAC,CAAC;QAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;QAC3D,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;QACzD,OAAO,CAAC,8BAA8B,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC;QAC3D,eAAe,CAAC,SAAS,CAAC,CAAC;QAC3B,OAAO,CAAC,6BAA6B,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC;QACzD,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC1B,UAAU,CAAC,yBAAyB,CAAC,CAAC;IACxC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,OAAO,GACX,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB,CAAC;QAChE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAClB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/commands/compile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/commands/compile.ts"],"names":[],"mappings":"AA2DA,wBAAsB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvE;AAED,wBAAsB,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAiC3E"}
|
package/dist/commands/compile.js
CHANGED
|
@@ -4,8 +4,12 @@ import ora from "ora";
|
|
|
4
4
|
import { loadConfig } from "../config/config.js";
|
|
5
5
|
import { compile } from "../compiler/compiler.js";
|
|
6
6
|
import { logSuccess, logError, logInfo } from "../utils/console.js";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const DEBOUNCE_MS = 200;
|
|
8
|
+
async function executeCompilation(projectRoot, options) {
|
|
9
|
+
const spinner = ora({
|
|
10
|
+
text: "Loading configuration...",
|
|
11
|
+
color: "cyan",
|
|
12
|
+
}).start();
|
|
9
13
|
try {
|
|
10
14
|
const config = await loadConfig(projectRoot);
|
|
11
15
|
spinner.text = "Compiling contracts...";
|
|
@@ -13,27 +17,40 @@ export async function compileCommand(projectRoot) {
|
|
|
13
17
|
if (result.success) {
|
|
14
18
|
spinner.succeed("Compilation complete");
|
|
15
19
|
logSuccess(`${result.artifacts.length} contract(s) compiled successfully`);
|
|
20
|
+
return true;
|
|
16
21
|
}
|
|
17
22
|
else {
|
|
18
23
|
spinner.fail("Compilation failed");
|
|
19
|
-
|
|
20
|
-
logError(
|
|
24
|
+
if (result.failedFiles > 0) {
|
|
25
|
+
logError(`${result.failedFiles} file(s) failed to compile`);
|
|
21
26
|
}
|
|
22
|
-
|
|
27
|
+
if (result.artifacts.length > 0) {
|
|
28
|
+
logSuccess(`${result.artifacts.length} contract(s) compiled successfully`);
|
|
29
|
+
}
|
|
30
|
+
if (options?.exitOnError) {
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
23
34
|
}
|
|
24
35
|
}
|
|
25
36
|
catch (err) {
|
|
26
37
|
spinner.fail("Compilation failed");
|
|
27
38
|
const message = err instanceof Error ? err.message : "Unknown error occurred";
|
|
28
39
|
logError(message);
|
|
29
|
-
|
|
40
|
+
if (options?.exitOnError) {
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
30
44
|
}
|
|
31
45
|
}
|
|
46
|
+
export async function compileCommand(projectRoot) {
|
|
47
|
+
await executeCompilation(projectRoot, { exitOnError: true });
|
|
48
|
+
}
|
|
32
49
|
export async function watchCompile(projectRoot) {
|
|
33
50
|
const config = await loadConfig(projectRoot);
|
|
34
51
|
const contractsDir = path.join(projectRoot, config.contractsDir);
|
|
35
52
|
// Run initial compilation
|
|
36
|
-
await
|
|
53
|
+
await executeCompilation(projectRoot);
|
|
37
54
|
logInfo(`Watching for file changes in ${config.contractsDir}/...`);
|
|
38
55
|
let debounceTimer = null;
|
|
39
56
|
if (!fs.existsSync(contractsDir)) {
|
|
@@ -46,8 +63,8 @@ export async function watchCompile(projectRoot) {
|
|
|
46
63
|
clearTimeout(debounceTimer);
|
|
47
64
|
debounceTimer = setTimeout(() => {
|
|
48
65
|
logInfo(`File changed: ${filename}`);
|
|
49
|
-
|
|
50
|
-
},
|
|
66
|
+
void executeCompilation(projectRoot);
|
|
67
|
+
}, DEBOUNCE_MS);
|
|
51
68
|
});
|
|
52
69
|
return () => {
|
|
53
70
|
if (debounceTimer)
|
|
@@ -55,26 +72,4 @@ export async function watchCompile(projectRoot) {
|
|
|
55
72
|
watcher.close();
|
|
56
73
|
};
|
|
57
74
|
}
|
|
58
|
-
async function runCompilation(projectRoot) {
|
|
59
|
-
const spinner = ora({ text: "Compiling contracts...", color: "cyan" }).start();
|
|
60
|
-
try {
|
|
61
|
-
const config = await loadConfig(projectRoot);
|
|
62
|
-
const result = await compile(projectRoot, config);
|
|
63
|
-
if (result.success) {
|
|
64
|
-
spinner.succeed("Compilation complete");
|
|
65
|
-
logSuccess(`${result.artifacts.length} contract(s) compiled successfully`);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
spinner.fail("Compilation failed");
|
|
69
|
-
for (const error of result.errors) {
|
|
70
|
-
logError(error);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
spinner.fail("Compilation failed");
|
|
76
|
-
const message = err instanceof Error ? err.message : "Unknown error occurred";
|
|
77
|
-
logError(message);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
75
|
//# sourceMappingURL=compile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/commands/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEpE,MAAM,CAAC,KAAK,UAAU,
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/commands/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEpE,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,KAAK,UAAU,kBAAkB,CAC/B,WAAmB,EACnB,OAAmC;IAEnC,MAAM,OAAO,GAAG,GAAG,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,CAAC,CAAC;IAClB,CAAC,CACF,CAAC;IAEF,OAAO,GAAG,EAAE;QACV,IAAI,aAAa;YAAE,YAAY,CAAC,aAAa,CAAC,CAAC;QAC/C,OAAO,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAgXA,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAsB,WAAW,CAC/B,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,IAAI,CAAC,CAcf"}
|
package/dist/commands/init.js
CHANGED
|
@@ -120,6 +120,28 @@ describe("Token", function () {
|
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
122
|
`;
|
|
123
|
+
/**
|
|
124
|
+
* Shared dependency and script definitions used by both buildPackageJson
|
|
125
|
+
* and the existing package.json merge logic.
|
|
126
|
+
*/
|
|
127
|
+
const DEFAULT_SCRIPTS = {
|
|
128
|
+
compile: "skittles compile",
|
|
129
|
+
build: "skittles compile && hardhat build",
|
|
130
|
+
clean: "skittles clean",
|
|
131
|
+
test: "skittles compile && hardhat test",
|
|
132
|
+
};
|
|
133
|
+
const REQUIRED_DEV_DEPS = {
|
|
134
|
+
"@nomicfoundation/hardhat-ethers": "^4.0.0",
|
|
135
|
+
"@nomicfoundation/hardhat-ethers-chai-matchers": "^3.0.0",
|
|
136
|
+
"@nomicfoundation/hardhat-mocha": "^3.0.0",
|
|
137
|
+
"@nomicfoundation/hardhat-network-helpers": "^3.0.0",
|
|
138
|
+
"@nomicfoundation/hardhat-typechain": "^3.0.0",
|
|
139
|
+
chai: "^5.1.2",
|
|
140
|
+
ethers: "^6.16.0",
|
|
141
|
+
hardhat: "^3.0.0",
|
|
142
|
+
mocha: "^11.0.0",
|
|
143
|
+
"@types/mocha": "^10.0.0",
|
|
144
|
+
};
|
|
123
145
|
/**
|
|
124
146
|
* Detect which package manager is in use based on lock files.
|
|
125
147
|
*/
|
|
@@ -139,37 +161,35 @@ function buildPackageJson(projectName) {
|
|
|
139
161
|
version: "1.0.0",
|
|
140
162
|
private: true,
|
|
141
163
|
type: "module",
|
|
142
|
-
scripts: {
|
|
143
|
-
compile: "skittles compile",
|
|
144
|
-
build: "skittles compile && hardhat build",
|
|
145
|
-
clean: "skittles clean",
|
|
146
|
-
test: "skittles compile && hardhat test",
|
|
147
|
-
},
|
|
164
|
+
scripts: { ...DEFAULT_SCRIPTS },
|
|
148
165
|
dependencies: {
|
|
149
166
|
skittles: "latest",
|
|
150
167
|
},
|
|
151
|
-
devDependencies: {
|
|
152
|
-
"@nomicfoundation/hardhat-ethers": "^4.0.0",
|
|
153
|
-
"@nomicfoundation/hardhat-ethers-chai-matchers": "^3.0.0",
|
|
154
|
-
"@nomicfoundation/hardhat-mocha": "^3.0.0",
|
|
155
|
-
"@nomicfoundation/hardhat-network-helpers": "^3.0.0",
|
|
156
|
-
"@nomicfoundation/hardhat-typechain": "^3.0.0",
|
|
157
|
-
chai: "^5.1.2",
|
|
158
|
-
ethers: "^6.16.0",
|
|
159
|
-
hardhat: "^3.0.0",
|
|
160
|
-
mocha: "^11.0.0",
|
|
161
|
-
"@types/mocha": "^10.0.0",
|
|
162
|
-
},
|
|
168
|
+
devDependencies: { ...REQUIRED_DEV_DEPS },
|
|
163
169
|
engines: {
|
|
164
170
|
node: ">=22.0.0",
|
|
165
171
|
},
|
|
166
172
|
}, null, 2);
|
|
167
173
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Write a file if it does not already exist, logging the result.
|
|
176
|
+
* If the file exists, a warning is logged. Otherwise the file is written
|
|
177
|
+
* and a success message is logged.
|
|
178
|
+
*/
|
|
179
|
+
function writeIfNotExists(filePath, content, description) {
|
|
180
|
+
if (fs.existsSync(filePath)) {
|
|
181
|
+
logWarning(`${description} already exists, skipping`);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
writeFile(filePath, content);
|
|
185
|
+
logSuccess(`Created ${description}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Create or update package.json with required dependencies and scripts.
|
|
190
|
+
*/
|
|
191
|
+
function initPackageJson(projectRoot) {
|
|
171
192
|
const projectName = path.basename(projectRoot);
|
|
172
|
-
// Create package.json (or update existing)
|
|
173
193
|
const packageJsonPath = path.join(projectRoot, "package.json");
|
|
174
194
|
if (fs.existsSync(packageJsonPath)) {
|
|
175
195
|
try {
|
|
@@ -181,19 +201,7 @@ export async function initCommand(projectRoot, options = {}) {
|
|
|
181
201
|
}
|
|
182
202
|
if (!pkg.devDependencies)
|
|
183
203
|
pkg.devDependencies = {};
|
|
184
|
-
const
|
|
185
|
-
"@nomicfoundation/hardhat-ethers": "^4.0.0",
|
|
186
|
-
"@nomicfoundation/hardhat-ethers-chai-matchers": "^3.0.0",
|
|
187
|
-
"@nomicfoundation/hardhat-mocha": "^3.0.0",
|
|
188
|
-
"@nomicfoundation/hardhat-network-helpers": "^3.0.0",
|
|
189
|
-
"@nomicfoundation/hardhat-typechain": "^3.0.0",
|
|
190
|
-
chai: "^5.1.2",
|
|
191
|
-
ethers: "^6.16.0",
|
|
192
|
-
hardhat: "^3.0.0",
|
|
193
|
-
mocha: "^11.0.0",
|
|
194
|
-
"@types/mocha": "^10.0.0",
|
|
195
|
-
};
|
|
196
|
-
for (const [dep, version] of Object.entries(requiredDevDeps)) {
|
|
204
|
+
for (const [dep, version] of Object.entries(REQUIRED_DEV_DEPS)) {
|
|
197
205
|
if (!pkg.devDependencies[dep] && !pkg.dependencies?.[dep]) {
|
|
198
206
|
pkg.devDependencies[dep] = version;
|
|
199
207
|
updated = true;
|
|
@@ -207,13 +215,7 @@ export async function initCommand(projectRoot, options = {}) {
|
|
|
207
215
|
}
|
|
208
216
|
if (!pkg.scripts)
|
|
209
217
|
pkg.scripts = {};
|
|
210
|
-
const
|
|
211
|
-
compile: "skittles compile",
|
|
212
|
-
build: "skittles compile && hardhat build",
|
|
213
|
-
clean: "skittles clean",
|
|
214
|
-
test: "skittles compile && hardhat test",
|
|
215
|
-
};
|
|
216
|
-
for (const [name, cmd] of Object.entries(defaultScripts)) {
|
|
218
|
+
for (const [name, cmd] of Object.entries(DEFAULT_SCRIPTS)) {
|
|
217
219
|
if (!pkg.scripts[name]) {
|
|
218
220
|
pkg.scripts[name] = cmd;
|
|
219
221
|
updated = true;
|
|
@@ -224,8 +226,9 @@ export async function initCommand(projectRoot, options = {}) {
|
|
|
224
226
|
logSuccess("Updated package.json");
|
|
225
227
|
}
|
|
226
228
|
}
|
|
227
|
-
catch {
|
|
228
|
-
|
|
229
|
+
catch (err) {
|
|
230
|
+
const message = err instanceof Error ? err.message : "Unknown error";
|
|
231
|
+
logWarning(`Could not update existing package.json (${message}), creating a new one`);
|
|
229
232
|
writeFile(packageJsonPath, buildPackageJson(projectName) + "\n");
|
|
230
233
|
logSuccess("Created package.json");
|
|
231
234
|
}
|
|
@@ -234,59 +237,26 @@ export async function initCommand(projectRoot, options = {}) {
|
|
|
234
237
|
writeFile(packageJsonPath, buildPackageJson(projectName) + "\n");
|
|
235
238
|
logSuccess("Created package.json");
|
|
236
239
|
}
|
|
237
|
-
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Create project directories and scaffold example files.
|
|
243
|
+
*/
|
|
244
|
+
function initProjectFiles(projectRoot) {
|
|
245
|
+
// Create directories
|
|
238
246
|
const contractsDir = path.join(projectRoot, "contracts");
|
|
239
247
|
ensureDirectory(contractsDir);
|
|
240
248
|
logSuccess("Created contracts/ directory");
|
|
241
|
-
// Create test directory
|
|
242
249
|
const testDir = path.join(projectRoot, "test");
|
|
243
250
|
ensureDirectory(testDir);
|
|
244
251
|
logSuccess("Created test/ directory");
|
|
245
|
-
// Write config file
|
|
246
|
-
const configPath = path.join(projectRoot, "skittles.config.json");
|
|
247
|
-
if (fs.existsSync(configPath)) {
|
|
248
|
-
logWarning("skittles.config.json already exists, skipping");
|
|
249
|
-
}
|
|
250
|
-
else {
|
|
251
|
-
writeFile(configPath, CONFIG_TEMPLATE + "\n");
|
|
252
|
-
logSuccess("Created skittles.config.json");
|
|
253
|
-
}
|
|
254
252
|
// Write example contract
|
|
255
|
-
|
|
256
|
-
if (fs.existsSync(examplePath)) {
|
|
257
|
-
logWarning("contracts/Token.ts already exists, skipping");
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
writeFile(examplePath, EXAMPLE_CONTRACT);
|
|
261
|
-
logSuccess("Created contracts/Token.ts");
|
|
262
|
-
}
|
|
253
|
+
writeIfNotExists(path.join(contractsDir, "Token.ts"), EXAMPLE_CONTRACT, "contracts/Token.ts");
|
|
263
254
|
// Write example test
|
|
264
|
-
|
|
265
|
-
if (fs.existsSync(exampleTestPath)) {
|
|
266
|
-
logWarning("test/Token.test.ts already exists, skipping");
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
writeFile(exampleTestPath, EXAMPLE_TEST);
|
|
270
|
-
logSuccess("Created test/Token.test.ts");
|
|
271
|
-
}
|
|
255
|
+
writeIfNotExists(path.join(testDir, "Token.test.ts"), EXAMPLE_TEST, "test/Token.test.ts");
|
|
272
256
|
// Write tsconfig.json
|
|
273
|
-
|
|
274
|
-
if (fs.existsSync(tsconfigPath)) {
|
|
275
|
-
logWarning("tsconfig.json already exists, skipping");
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
writeFile(tsconfigPath, TSCONFIG_TEMPLATE + "\n");
|
|
279
|
-
logSuccess("Created tsconfig.json");
|
|
280
|
-
}
|
|
257
|
+
writeIfNotExists(path.join(projectRoot, "tsconfig.json"), TSCONFIG_TEMPLATE + "\n", "tsconfig.json");
|
|
281
258
|
// Write hardhat.config.ts
|
|
282
|
-
|
|
283
|
-
if (fs.existsSync(hardhatConfigPath)) {
|
|
284
|
-
logWarning("hardhat.config.ts already exists, skipping");
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
writeFile(hardhatConfigPath, HARDHAT_CONFIG_TEMPLATE);
|
|
288
|
-
logSuccess("Created hardhat.config.ts");
|
|
289
|
-
}
|
|
259
|
+
writeIfNotExists(path.join(projectRoot, "hardhat.config.ts"), HARDHAT_CONFIG_TEMPLATE, "hardhat.config.ts");
|
|
290
260
|
// Update .gitignore
|
|
291
261
|
const gitignorePath = path.join(projectRoot, ".gitignore");
|
|
292
262
|
const gitignoreEntries = [
|
|
@@ -310,7 +280,17 @@ export async function initCommand(projectRoot, options = {}) {
|
|
|
310
280
|
writeFile(gitignorePath, gitignoreEntries.join("\n") + "\n");
|
|
311
281
|
logSuccess("Created .gitignore");
|
|
312
282
|
}
|
|
313
|
-
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Write the skittles.config.json file.
|
|
286
|
+
*/
|
|
287
|
+
function initConfig(projectRoot) {
|
|
288
|
+
writeIfNotExists(path.join(projectRoot, "skittles.config.json"), CONFIG_TEMPLATE + "\n", "skittles.config.json");
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Install project dependencies using the detected package manager.
|
|
292
|
+
*/
|
|
293
|
+
function installDependencies(projectRoot, install) {
|
|
314
294
|
const pm = detectPackageManager(projectRoot);
|
|
315
295
|
if (install) {
|
|
316
296
|
logInfo(`Installing dependencies with ${pm}...`);
|
|
@@ -330,6 +310,14 @@ export async function initCommand(projectRoot, options = {}) {
|
|
|
330
310
|
else {
|
|
331
311
|
logInfo(`Skipping dependency installation. Run \`${pm} install\` manually.`);
|
|
332
312
|
}
|
|
313
|
+
}
|
|
314
|
+
export async function initCommand(projectRoot, options = {}) {
|
|
315
|
+
const { install = true } = options;
|
|
316
|
+
logInfo("Initializing new Skittles project...");
|
|
317
|
+
initPackageJson(projectRoot);
|
|
318
|
+
initProjectFiles(projectRoot);
|
|
319
|
+
initConfig(projectRoot);
|
|
320
|
+
installDependencies(projectRoot, install);
|
|
333
321
|
logSuccess("Skittles project initialized!");
|
|
334
322
|
logInfo("");
|
|
335
323
|
logInfo("Next steps:");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEhF,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CACpC;IACE,SAAS,EAAE,IAAI;IACf,UAAU,EAAE,IAAI;IAChB,YAAY,EAAE,WAAW;IACzB,SAAS,EAAE,WAAW;CACvB,EACD,IAAI,EACJ,CAAC,CACF,CAAC;AAEF,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CACtC;IACE,eAAe,EAAE;QACf,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,UAAU;QAClB,gBAAgB,EAAE,UAAU;QAC5B,GAAG,EAAE,CAAC,QAAQ,CAAC;QACf,MAAM,EAAE,IAAI;QACZ,4BAA4B,EAAE,KAAK;QACnC,wBAAwB,EAAE,KAAK;QAC/B,eAAe,EAAE,IAAI;QACrB,YAAY,EAAE,IAAI;QAClB,gCAAgC,EAAE,IAAI;QACtC,iBAAiB,EAAE,IAAI;QACvB,MAAM,EAAE,QAAQ;QAChB,OAAO,EAAE,GAAG;KACb;IACD,OAAO,EAAE,CAAC,gBAAgB,EAAE,WAAW,EAAE,YAAY,CAAC;IACtD,OAAO,EAAE,CAAC,c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AAM,CAAC,KAAK,UAAU,WAAW,CAC/B,WAAmB,EACnB,UAAuB,EAAE;IAEzB,MAAM,EAAE,OAAO,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IACnC,OAAO,CAAC,sCAAsC,CAAC,CAAC;IAEhD,eAAe,CAAC,WAAW,CAAC,CAAC;IAC7B,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAC9B,UAAU,CAAC,WAAW,CAAC,CAAC;IACxB,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAE1C,UAAU,CAAC,+BAA+B,CAAC,CAAC;IAC5C,OAAO,CAAC,EAAE,CAAC,CAAC;IACZ,OAAO,CAAC,aAAa,CAAC,CAAC;IACvB,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC/B,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analysis.d.ts","sourceRoot":"","sources":["../../src/compiler/analysis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"analysis.d.ts","sourceRoot":"","sources":["../../src/compiler/analysis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAG3B;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,gBAAgB,GAAG,mBAAmB,EAC1C,YAAY,EAAE,MAAM,GACnB,MAAM,EAAE,CAeV"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { walkStatements } from "./walker.js";
|
|
1
2
|
/**
|
|
2
3
|
* Analyze a function body for unreachable code and unused local variables.
|
|
3
4
|
* Returns an array of warning strings.
|
|
@@ -51,8 +52,6 @@ function walkNestedBlocks(stmt, visitor) {
|
|
|
51
52
|
visitor(stmt.body);
|
|
52
53
|
break;
|
|
53
54
|
case "while":
|
|
54
|
-
visitor(stmt.body);
|
|
55
|
-
break;
|
|
56
55
|
case "do-while":
|
|
57
56
|
visitor(stmt.body);
|
|
58
57
|
break;
|
|
@@ -89,146 +88,28 @@ function checkUnusedVariables(statements, parameterNames, contractName, function
|
|
|
89
88
|
}
|
|
90
89
|
/**
|
|
91
90
|
* Walk all statements recursively, collecting declared variable names
|
|
92
|
-
* and used identifier names.
|
|
91
|
+
* and used identifier names via the shared AST walker.
|
|
93
92
|
*/
|
|
94
93
|
function walkAllStatements(stmts, declared, used) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
walkStatements(stmts, {
|
|
95
|
+
visitStatement(stmt) {
|
|
96
|
+
if (stmt.kind === "variable-declaration") {
|
|
98
97
|
declared.add(stmt.name);
|
|
99
|
-
if (stmt.initializer)
|
|
100
|
-
collectUsedIdentifiers(stmt.initializer, used);
|
|
101
|
-
break;
|
|
102
|
-
case "return":
|
|
103
|
-
if (stmt.value)
|
|
104
|
-
collectUsedIdentifiers(stmt.value, used);
|
|
105
|
-
break;
|
|
106
|
-
case "expression":
|
|
107
|
-
collectUsedIdentifiers(stmt.expression, used);
|
|
108
|
-
break;
|
|
109
|
-
case "if":
|
|
110
|
-
collectUsedIdentifiers(stmt.condition, used);
|
|
111
|
-
walkAllStatements(stmt.thenBody, declared, used);
|
|
112
|
-
if (stmt.elseBody)
|
|
113
|
-
walkAllStatements(stmt.elseBody, declared, used);
|
|
114
|
-
break;
|
|
115
|
-
case "for":
|
|
116
|
-
if (stmt.initializer) {
|
|
117
|
-
if (stmt.initializer.kind === "variable-declaration") {
|
|
118
|
-
declared.add(stmt.initializer.name);
|
|
119
|
-
if (stmt.initializer.initializer)
|
|
120
|
-
collectUsedIdentifiers(stmt.initializer.initializer, used);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
collectUsedIdentifiers(stmt.initializer.expression, used);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (stmt.condition)
|
|
127
|
-
collectUsedIdentifiers(stmt.condition, used);
|
|
128
|
-
if (stmt.incrementor)
|
|
129
|
-
collectUsedIdentifiers(stmt.incrementor, used);
|
|
130
|
-
walkAllStatements(stmt.body, declared, used);
|
|
131
|
-
break;
|
|
132
|
-
case "while":
|
|
133
|
-
collectUsedIdentifiers(stmt.condition, used);
|
|
134
|
-
walkAllStatements(stmt.body, declared, used);
|
|
135
|
-
break;
|
|
136
|
-
case "do-while":
|
|
137
|
-
collectUsedIdentifiers(stmt.condition, used);
|
|
138
|
-
walkAllStatements(stmt.body, declared, used);
|
|
139
|
-
break;
|
|
140
|
-
case "revert":
|
|
141
|
-
if (stmt.message)
|
|
142
|
-
collectUsedIdentifiers(stmt.message, used);
|
|
143
|
-
if (stmt.customErrorArgs) {
|
|
144
|
-
for (const arg of stmt.customErrorArgs) {
|
|
145
|
-
collectUsedIdentifiers(arg, used);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
break;
|
|
149
|
-
case "emit":
|
|
150
|
-
for (const arg of stmt.args) {
|
|
151
|
-
collectUsedIdentifiers(arg, used);
|
|
152
|
-
}
|
|
153
|
-
break;
|
|
154
|
-
case "switch":
|
|
155
|
-
collectUsedIdentifiers(stmt.discriminant, used);
|
|
156
|
-
for (const c of stmt.cases) {
|
|
157
|
-
if (c.value)
|
|
158
|
-
collectUsedIdentifiers(c.value, used);
|
|
159
|
-
walkAllStatements(c.body, declared, used);
|
|
160
|
-
}
|
|
161
|
-
break;
|
|
162
|
-
case "delete":
|
|
163
|
-
collectUsedIdentifiers(stmt.target, used);
|
|
164
|
-
break;
|
|
165
|
-
case "try-catch":
|
|
166
|
-
collectUsedIdentifiers(stmt.call, used);
|
|
167
|
-
if (stmt.returnVarName)
|
|
168
|
-
declared.add(stmt.returnVarName);
|
|
169
|
-
walkAllStatements(stmt.successBody, declared, used);
|
|
170
|
-
walkAllStatements(stmt.catchBody, declared, used);
|
|
171
|
-
break;
|
|
172
|
-
case "console-log":
|
|
173
|
-
for (const arg of stmt.args) {
|
|
174
|
-
collectUsedIdentifiers(arg, used);
|
|
175
|
-
}
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Collect all identifier names used in an expression.
|
|
182
|
-
*/
|
|
183
|
-
function collectUsedIdentifiers(expr, used) {
|
|
184
|
-
switch (expr.kind) {
|
|
185
|
-
case "identifier":
|
|
186
|
-
used.add(expr.name);
|
|
187
|
-
break;
|
|
188
|
-
case "binary":
|
|
189
|
-
collectUsedIdentifiers(expr.left, used);
|
|
190
|
-
collectUsedIdentifiers(expr.right, used);
|
|
191
|
-
break;
|
|
192
|
-
case "unary":
|
|
193
|
-
collectUsedIdentifiers(expr.operand, used);
|
|
194
|
-
break;
|
|
195
|
-
case "assignment":
|
|
196
|
-
collectUsedIdentifiers(expr.target, used);
|
|
197
|
-
collectUsedIdentifiers(expr.value, used);
|
|
198
|
-
break;
|
|
199
|
-
case "call":
|
|
200
|
-
collectUsedIdentifiers(expr.callee, used);
|
|
201
|
-
for (const arg of expr.args) {
|
|
202
|
-
collectUsedIdentifiers(arg, used);
|
|
203
98
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
case "element-access":
|
|
209
|
-
collectUsedIdentifiers(expr.object, used);
|
|
210
|
-
collectUsedIdentifiers(expr.index, used);
|
|
211
|
-
break;
|
|
212
|
-
case "conditional":
|
|
213
|
-
collectUsedIdentifiers(expr.condition, used);
|
|
214
|
-
collectUsedIdentifiers(expr.whenTrue, used);
|
|
215
|
-
collectUsedIdentifiers(expr.whenFalse, used);
|
|
216
|
-
break;
|
|
217
|
-
case "new":
|
|
218
|
-
for (const arg of expr.args) {
|
|
219
|
-
collectUsedIdentifiers(arg, used);
|
|
99
|
+
if (stmt.kind === "tuple-destructuring") {
|
|
100
|
+
for (const n of stmt.names)
|
|
101
|
+
if (n !== null)
|
|
102
|
+
declared.add(n);
|
|
220
103
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
for (const prop of expr.properties) {
|
|
224
|
-
collectUsedIdentifiers(prop.value, used);
|
|
104
|
+
if (stmt.kind === "try-catch" && stmt.returnVarName) {
|
|
105
|
+
declared.add(stmt.returnVarName);
|
|
225
106
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
107
|
+
},
|
|
108
|
+
visitExpression(expr) {
|
|
109
|
+
if (expr.kind === "identifier") {
|
|
110
|
+
used.add(expr.name);
|
|
230
111
|
}
|
|
231
|
-
|
|
232
|
-
}
|
|
112
|
+
},
|
|
113
|
+
});
|
|
233
114
|
}
|
|
234
115
|
//# sourceMappingURL=analysis.js.map
|