as-test 0.4.0 → 0.4.2

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/README.md +12 -12
  3. package/as-test.config.json +1 -1
  4. package/assembly/__tests__/array.spec.ts +3 -3
  5. package/assembly/src/expectation.ts +29 -16
  6. package/assembly/src/suite.ts +2 -0
  7. package/assembly/src/tests.ts +1 -0
  8. package/bin/build.js +65 -77
  9. package/bin/index.js +130 -160
  10. package/bin/init.js +96 -109
  11. package/bin/reporter.js +1 -1
  12. package/bin/run.js +210 -236
  13. package/bin/types.js +25 -25
  14. package/bin/util.js +35 -42
  15. package/cli/run.ts +13 -15
  16. package/cli/tsconfig.json +2 -1
  17. package/package.json +12 -9
  18. package/transform/lib/builder.js +1361 -0
  19. package/transform/lib/builder.js.map +1 -0
  20. package/transform/lib/coverage.js +6 -6
  21. package/transform/lib/coverage.js.map +1 -1
  22. package/transform/lib/index.js +1 -1
  23. package/transform/lib/index.js.map +1 -1
  24. package/transform/lib/linker.js +19 -0
  25. package/transform/lib/linker.js.map +1 -0
  26. package/transform/lib/mock.js +9 -9
  27. package/transform/lib/mock.js.map +1 -1
  28. package/transform/lib/range.js +13 -0
  29. package/transform/lib/range.js.map +1 -0
  30. package/transform/lib/types.js +26 -0
  31. package/transform/lib/types.js.map +1 -0
  32. package/transform/lib/util.js +47 -0
  33. package/transform/lib/util.js.map +1 -0
  34. package/transform/lib/visitor.js +532 -0
  35. package/transform/lib/visitor.js.map +1 -0
  36. package/transform/src/builder.ts +1474 -0
  37. package/transform/src/coverage.ts +6 -7
  38. package/transform/src/index.ts +1 -2
  39. package/transform/src/linker.ts +41 -0
  40. package/transform/src/mock.ts +9 -10
  41. package/transform/src/range.ts +12 -0
  42. package/transform/src/types.ts +35 -0
  43. package/transform/src/util.ts +81 -0
  44. package/transform/src/visitor.ts +744 -0
  45. package/.trunk/configs/.markdownlint.yaml +0 -2
  46. package/.trunk/configs/.yamllint.yaml +0 -7
  47. package/.trunk/trunk.yaml +0 -34
  48. package/bin/about.js +0 -135
  49. package/bin/package.json +0 -3
package/bin/run.js CHANGED
@@ -5,258 +5,232 @@ import { formatTime, getExec, loadConfig } from "./util.js";
5
5
  import * as path from "path";
6
6
  import { existsSync, mkdirSync, writeFileSync } from "fs";
7
7
  import { diff } from "typer-diff";
8
+ import gradient from "gradient-string";
8
9
  const CONFIG_PATH = path.join(process.cwd(), "./as-test.config.json");
10
+ const version = "0.4.0";
9
11
  export async function run() {
10
- const reports = [];
11
- const config = loadConfig(CONFIG_PATH);
12
- const inputFiles = await glob(config.input);
13
- console.log(
14
- chalk.dim("Running tests using " + config.runOptions.runtime.name + ""),
15
- );
16
- const command = config.runOptions.runtime.run.split(" ")[0];
17
- let execPath = getExec(command);
18
- if (!execPath) {
19
- console.log(
20
- `${chalk.bgRed(" ERROR ")}${chalk.dim(":")} could not locate ${command} in PATH variable!`,
21
- );
22
- process.exit(0);
23
- }
24
- if (inputFiles.length) {
25
- console.log(
26
- chalk.bold.blueBright(` _____ _____ _____ _____ _____ _____ `),
27
- );
28
- console.log(
29
- chalk.bold.blueBright(`| _ || __| ___|_ _|| __|| __||_ _|`),
30
- );
31
- console.log(
32
- chalk.bold.blueBright(`| ||__ ||___| | | | __||__ | | | `),
33
- );
34
- console.log(
35
- chalk.bold.blueBright(`|__|__||_____| |_| |_____||_____| |_| `),
36
- );
37
- console.log(
38
- chalk.dim("\n------------------- v0.3.5 -------------------\n"),
39
- );
40
- }
41
- for (const plugin of Object.keys(config.plugins)) {
42
- if (!config.plugins[plugin]) continue;
43
- console.log(
44
- chalk.bgBlueBright(" PLUGIN ") +
45
- " " +
46
- chalk.dim(
47
- "Using " + plugin.slice(0, 1).toUpperCase() + plugin.slice(1),
48
- ) +
49
- "\n",
50
- );
51
- }
52
- for (let i = 0; i < inputFiles.length; i++) {
53
- const file = inputFiles[i];
54
- const outFile = path.join(
55
- config.outDir,
56
- file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm"),
57
- );
58
- let cmd = config.runOptions.runtime.run.replace(command, execPath);
59
- if (config.buildOptions.target == "bindings") {
60
- cmd = config.runOptions.runtime.run.replace(command, execPath);
61
- if (cmd.includes("<name>")) {
62
- cmd = cmd.replace(
63
- "<name>",
64
- file
65
- .slice(file.lastIndexOf("/") + 1)
66
- .replace(".ts", "")
67
- .replace(".spec", ""),
68
- );
69
- } else {
70
- cmd = cmd.replace(
71
- "<file>",
72
- outFile
73
- .replace("build", "tests")
74
- .replace(".spec", "")
75
- .replace(".wasm", ".run.js"),
76
- );
77
- }
78
- } else {
79
- cmd = cmd.replace("<file>", outFile);
12
+ const reports = [];
13
+ const config = loadConfig(CONFIG_PATH);
14
+ const inputFiles = await glob(config.input);
15
+ console.log(chalk.dim("Running tests using " + config.runOptions.runtime.name + ""));
16
+ const command = config.runOptions.runtime.run.split(" ")[0];
17
+ let execPath = getExec(command);
18
+ if (!execPath) {
19
+ console.log(`${chalk.bgRed(" ERROR ")}${chalk.dim(":")} could not locate ${command} in PATH variable!`);
20
+ process.exit(0);
80
21
  }
81
- const report = JSON.parse(
82
- await (() => {
83
- return new Promise((res, _) => {
84
- let stdout = "";
85
- const io = exec(cmd);
86
- io.stdout.pipe(process.stdout);
87
- io.stderr.pipe(process.stderr);
88
- io.stdout.on("data", (data) => {
89
- stdout += readData(data);
90
- });
91
- io.stdout.on("close", () => {
92
- res(stdout);
93
- });
94
- });
95
- })(),
96
- );
97
- reports.push(report);
98
- }
99
- if (config.logs && config.logs != "none") {
100
- if (!existsSync(path.join(process.cwd(), config.logs))) {
101
- mkdirSync(path.join(process.cwd(), config.logs));
22
+ if (inputFiles.length) {
23
+ console.log("\n" +
24
+ gradient(["#87afff", "#3a5fcd"])
25
+ .multiline(` █████ ███████ ████████ ███████ ███████ ████████
26
+ ██ ██ ██ ██ ██ ██ ██
27
+ ███████ ███████ █████ ██ █████ ███████ ██
28
+ ██ ██ ██ ██ ██ ██ ██
29
+ ██ ██ ███████ ██ ███████ ███████ ██ `));
30
+ console.log(chalk.dim(`\n----------------------- v${version} -----------------------\n`));
102
31
  }
103
- writeFileSync(
104
- path.join(process.cwd(), config.logs, "test.log.json"),
105
- JSON.stringify(reports, null, 2),
106
- );
107
- }
108
- const reporter = new Reporter(reports);
109
- if (reporter.failed.length) {
110
- console.log(chalk.dim("----------------- [FAILED] -------------------\n"));
111
- for (const failed of reporter.failed) {
112
- console.log(
113
- `${chalk.bgRed(" FAIL ")} ${chalk.dim(failed.description)}\n`,
114
- );
115
- for (const test of failed.tests) {
116
- const diffResult = diff(
117
- JSON.stringify(test.left),
118
- JSON.stringify(test.right),
119
- );
120
- let expected = chalk.dim(JSON.stringify(test.left));
121
- let received = "";
122
- for (const res of diffResult.diff) {
123
- switch (res.type) {
124
- case "correct": {
125
- received += chalk.dim(res.value);
126
- continue;
127
- }
128
- case "extra": {
129
- received += chalk.red.strikethrough(res.value);
130
- continue;
131
- }
132
- case "missing": {
133
- received += chalk.bgBlack(res.value);
134
- continue;
135
- }
136
- case "wrong": {
137
- received += chalk.bgRed(res.value);
138
- continue;
139
- }
140
- case "untouched": {
141
- //received += chalk.bgBlackBright(res.value);
142
- continue;
32
+ for (const plugin of Object.keys(config.plugins)) {
33
+ if (!config.plugins[plugin])
34
+ continue;
35
+ console.log(chalk.bgBlueBright(" PLUGIN ") +
36
+ " " +
37
+ chalk.dim("Using " + plugin.slice(0, 1).toUpperCase() + plugin.slice(1)) +
38
+ "\n");
39
+ }
40
+ for (let i = 0; i < inputFiles.length; i++) {
41
+ const file = inputFiles[i];
42
+ const outFile = path.join(config.outDir, file.slice(file.lastIndexOf("/") + 1).replace(".ts", ".wasm"));
43
+ let cmd = config.runOptions.runtime.run.replace(command, execPath);
44
+ if (config.buildOptions.target == "bindings") {
45
+ cmd = config.runOptions.runtime.run.replace(command, execPath);
46
+ if (cmd.includes("<name>")) {
47
+ cmd = cmd.replace("<name>", file
48
+ .slice(file.lastIndexOf("/") + 1)
49
+ .replace(".ts", "")
50
+ .replace(".spec", ""));
143
51
  }
144
- case "spacer": {
145
- //received += chalk.bgBlackBright(res.value);
146
- continue;
52
+ else {
53
+ cmd = cmd.replace("<file>", outFile
54
+ .replace("build", "tests")
55
+ .replace(".spec", "")
56
+ .replace(".wasm", ".run.js"));
147
57
  }
148
- }
149
58
  }
150
- if (test.verdict == "fail") {
151
- console.log(`${chalk.dim("(expected) ->")} ${expected}`);
152
- console.log(`${chalk.dim("(received) ->")} ${received}\n`);
59
+ else {
60
+ cmd = cmd.replace("<file>", outFile);
61
+ }
62
+ const report = JSON.parse(await (() => {
63
+ return new Promise((res, _) => {
64
+ let stdout = "";
65
+ const io = exec(cmd);
66
+ io.stdout.pipe(process.stdout);
67
+ io.stderr.pipe(process.stderr);
68
+ io.stdout.on("data", (data) => {
69
+ stdout += readData(data);
70
+ });
71
+ io.stdout.on("close", () => {
72
+ res(stdout);
73
+ });
74
+ });
75
+ })());
76
+ reports.push(report);
77
+ }
78
+ if (config.logs && config.logs != "none") {
79
+ if (!existsSync(path.join(process.cwd(), config.logs))) {
80
+ mkdirSync(path.join(process.cwd(), config.logs));
153
81
  }
154
- }
82
+ writeFileSync(path.join(process.cwd(), config.logs, "test.log.json"), JSON.stringify(reports, null, 2));
83
+ }
84
+ const reporter = new Reporter(reports);
85
+ if (reporter.failed.length) {
86
+ console.log(chalk.dim("----------------- [FAILED] -------------------\n"));
87
+ for (const failed of reporter.failed) {
88
+ console.log(`${chalk.bgRed(" FAIL ")} ${chalk.dim(failed.description)}\n`);
89
+ for (const test of failed.tests) {
90
+ const diffResult = diff(JSON.stringify(test.left), JSON.stringify(test.right));
91
+ let expected = "";
92
+ let received = chalk.dim(JSON.stringify(test.left));
93
+ for (const res of diffResult.diff) {
94
+ switch (res.type) {
95
+ case "correct": {
96
+ expected += chalk.dim(res.value);
97
+ continue;
98
+ }
99
+ case "extra": {
100
+ expected += chalk.red.strikethrough(res.value);
101
+ continue;
102
+ }
103
+ case "missing": {
104
+ expected += chalk.bgBlack(res.value);
105
+ continue;
106
+ }
107
+ case "wrong": {
108
+ expected += chalk.bgRed(res.value);
109
+ continue;
110
+ }
111
+ case "untouched": {
112
+ //received += chalk.bgBlackBright(res.value);
113
+ continue;
114
+ }
115
+ case "spacer": {
116
+ //received += chalk.bgBlackBright(res.value);
117
+ continue;
118
+ }
119
+ }
120
+ }
121
+ if (test.verdict == "fail") {
122
+ console.log(`${chalk.dim("(expected) ->")} ${expected}`);
123
+ console.log(`${chalk.dim("(received) ->")} ${received}\n`);
124
+ }
125
+ }
126
+ }
127
+ }
128
+ console.log(chalk.dim("----------------- [RESULTS] ------------------\n"));
129
+ process.stdout.write(chalk.bold("Files: "));
130
+ if (reporter.failedFiles) {
131
+ process.stdout.write(chalk.bold.red(reporter.failedFiles + " failed"));
132
+ }
133
+ else {
134
+ process.stdout.write(chalk.bold.greenBright("0 failed"));
135
+ }
136
+ process.stdout.write(", " + (reporter.failedFiles + reporter.passedFiles) + " total\n");
137
+ process.stdout.write(chalk.bold("Suites: "));
138
+ if (reporter.failedSuites) {
139
+ process.stdout.write(chalk.bold.red(reporter.failedSuites + " failed"));
140
+ }
141
+ else {
142
+ process.stdout.write(chalk.bold.greenBright("0 failed"));
143
+ }
144
+ process.stdout.write(", " + (reporter.failedSuites + reporter.passedSuites) + " total\n");
145
+ process.stdout.write(chalk.bold("Tests: "));
146
+ if (reporter.failedTests) {
147
+ process.stdout.write(chalk.bold.red(reporter.failedTests + " failed"));
155
148
  }
156
- }
157
- console.log(chalk.dim("----------------- [RESULTS] ------------------\n"));
158
- process.stdout.write(chalk.bold("Files: "));
159
- if (reporter.failedFiles) {
160
- process.stdout.write(chalk.bold.red(reporter.failedFiles + " failed"));
161
- } else {
162
- process.stdout.write(chalk.bold.greenBright("0 failed"));
163
- }
164
- process.stdout.write(
165
- ", " + (reporter.failedFiles + reporter.passedFiles) + " total\n",
166
- );
167
- process.stdout.write(chalk.bold("Suites: "));
168
- if (reporter.failedSuites) {
169
- process.stdout.write(chalk.bold.red(reporter.failedSuites + " failed"));
170
- } else {
171
- process.stdout.write(chalk.bold.greenBright("0 failed"));
172
- }
173
- process.stdout.write(
174
- ", " + (reporter.failedSuites + reporter.passedSuites) + " total\n",
175
- );
176
- process.stdout.write(chalk.bold("Tests: "));
177
- if (reporter.failedTests) {
178
- process.stdout.write(chalk.bold.red(reporter.failedTests + " failed"));
179
- } else {
180
- process.stdout.write(chalk.bold.greenBright("0 failed"));
181
- }
182
- process.stdout.write(
183
- ", " + (reporter.failedTests + reporter.passedTests) + " total\n",
184
- );
185
- process.stdout.write(
186
- chalk.bold("Time: ") + formatTime(reporter.time) + "\n",
187
- );
188
- if (reporter.failedFiles) process.exit(1);
189
- process.exit(0);
149
+ else {
150
+ process.stdout.write(chalk.bold.greenBright("0 failed"));
151
+ }
152
+ process.stdout.write(", " + (reporter.failedTests + reporter.passedTests) + " total\n");
153
+ process.stdout.write(chalk.bold("Time: ") + formatTime(reporter.time) + "\n");
154
+ if (reporter.failedFiles)
155
+ process.exit(1);
156
+ process.exit(0);
190
157
  }
191
158
  class Reporter {
192
- constructor(reports) {
193
- this.passedFiles = 0;
194
- this.failedFiles = 0;
195
- this.passedSuites = 0;
196
- this.failedSuites = 0;
197
- this.passedTests = 0;
198
- this.failedTests = 0;
199
- this.failed = [];
200
- this.time = 0.0;
201
- this.readReports(reports);
202
- }
203
- readReports(reports) {
204
- for (const file of reports) {
205
- this.readFile(file);
206
- }
207
- }
208
- readFile(file) {
209
- let failed = false;
210
- for (const suite of file) {
211
- if (suite.verdict == "fail") {
212
- failed = true;
213
- this.failedSuites++;
214
- } else {
215
- this.passedSuites++;
216
- }
217
- this.time += suite.time.end - suite.time.start;
218
- for (const subSuite of suite.suites) {
219
- this.readSuite(subSuite);
220
- }
221
- for (const test of suite.tests) {
222
- if (test.verdict == "fail") this.failed.push(suite);
223
- this.readTest(test);
224
- }
159
+ constructor(reports) {
160
+ this.passedFiles = 0;
161
+ this.failedFiles = 0;
162
+ this.passedSuites = 0;
163
+ this.failedSuites = 0;
164
+ this.passedTests = 0;
165
+ this.failedTests = 0;
166
+ this.failed = [];
167
+ this.time = 0.0;
168
+ this.readReports(reports);
225
169
  }
226
- if (failed) this.failedFiles++;
227
- else this.passedFiles++;
228
- }
229
- readSuite(suite) {
230
- if (suite.verdict == "fail") {
231
- this.failedSuites++;
232
- } else {
233
- this.passedSuites++;
170
+ readReports(reports) {
171
+ for (const file of reports) {
172
+ this.readFile(file);
173
+ }
234
174
  }
235
- this.time += suite.time.end - suite.time.start;
236
- for (const subSuite of suite.suites) {
237
- this.readSuite(subSuite);
175
+ readFile(file) {
176
+ let failed = false;
177
+ for (const suite of file) {
178
+ if (suite.verdict == "fail") {
179
+ failed = true;
180
+ this.failedSuites++;
181
+ }
182
+ else {
183
+ this.passedSuites++;
184
+ }
185
+ this.time += suite.time.end - suite.time.start;
186
+ for (const subSuite of suite.suites) {
187
+ this.readSuite(subSuite);
188
+ }
189
+ for (const test of suite.tests) {
190
+ if (test.verdict == "fail")
191
+ this.failed.push(suite);
192
+ this.readTest(test);
193
+ }
194
+ }
195
+ if (failed)
196
+ this.failedFiles++;
197
+ else
198
+ this.passedFiles++;
238
199
  }
239
- for (const test of suite.tests) {
240
- if (test.verdict == "fail") this.failed.push(suite);
241
- this.readTest(test);
200
+ readSuite(suite) {
201
+ if (suite.verdict == "fail") {
202
+ this.failedSuites++;
203
+ }
204
+ else {
205
+ this.passedSuites++;
206
+ }
207
+ this.time += suite.time.end - suite.time.start;
208
+ for (const subSuite of suite.suites) {
209
+ this.readSuite(subSuite);
210
+ }
211
+ for (const test of suite.tests) {
212
+ if (test.verdict == "fail")
213
+ this.failed.push(suite);
214
+ this.readTest(test);
215
+ }
242
216
  }
243
- }
244
- readTest(test) {
245
- if (test.verdict == "fail") {
246
- this.failedTests++;
247
- } else {
248
- this.passedTests++;
217
+ readTest(test) {
218
+ if (test.verdict == "fail") {
219
+ this.failedTests++;
220
+ }
221
+ else {
222
+ this.passedTests++;
223
+ }
249
224
  }
250
- }
251
225
  }
252
226
  function readData(data) {
253
- let out = "";
254
- const start = data.indexOf("READ_LINE");
255
- if (start >= 0) {
256
- const slice = data.slice(start + 9);
257
- const end = slice.indexOf("END_LINE");
258
- out += slice.slice(0, end);
259
- out += readData(slice);
260
- }
261
- return out;
227
+ let out = "";
228
+ const start = data.indexOf("READ_LINE");
229
+ if (start >= 0) {
230
+ const slice = data.slice(start + 9);
231
+ const end = slice.indexOf("END_LINE");
232
+ out += slice.slice(0, end);
233
+ out += readData(slice);
234
+ }
235
+ return out;
262
236
  }
package/bin/types.js CHANGED
@@ -1,35 +1,35 @@
1
1
  export class Config {
2
- constructor() {
3
- this.input = ["./assembly/__tests__/*.spec.ts"];
4
- this.outDir = "./build";
5
- this.logs = "./logs";
6
- this.config = "none";
7
- this.plugins = {
8
- coverage: true,
9
- };
10
- this.buildOptions = new BuildOptions();
11
- this.runOptions = new RunOptions();
12
- }
2
+ constructor() {
3
+ this.input = ["./assembly/__tests__/*.spec.ts"];
4
+ this.outDir = "./build";
5
+ this.logs = "./logs";
6
+ this.config = "none";
7
+ this.plugins = {
8
+ coverage: true,
9
+ };
10
+ this.buildOptions = new BuildOptions();
11
+ this.runOptions = new RunOptions();
12
+ }
13
13
  }
14
14
  export class Suite {
15
- constructor() {
16
- this.name = "";
17
- }
15
+ constructor() {
16
+ this.name = "";
17
+ }
18
18
  }
19
19
  export class BuildOptions {
20
- constructor() {
21
- this.args = [];
22
- this.target = "wasi";
23
- }
20
+ constructor() {
21
+ this.args = [];
22
+ this.target = "wasi";
23
+ }
24
24
  }
25
25
  export class RunOptions {
26
- constructor() {
27
- this.runtime = new Runtime();
28
- }
26
+ constructor() {
27
+ this.runtime = new Runtime();
28
+ }
29
29
  }
30
30
  export class Runtime {
31
- constructor() {
32
- this.name = "wasmtime";
33
- this.run = "wasmtime <file>";
34
- }
31
+ constructor() {
32
+ this.name = "wasmtime";
33
+ this.run = "wasmtime <file>";
34
+ }
35
35
  }
package/bin/util.js CHANGED
@@ -3,52 +3,45 @@ import { Config } from "./types.js";
3
3
  import chalk from "chalk";
4
4
  import { delimiter, join } from "path";
5
5
  export function formatTime(ms) {
6
- if (ms < 0) {
7
- throw new Error("Time should be a non-negative number.");
8
- }
9
- // Convert milliseconds to microseconds
10
- const us = ms * 1000;
11
- const units = [
12
- { name: "μs", divisor: 1 },
13
- { name: "ms", divisor: 1000 },
14
- { name: "s", divisor: 1000 * 1000 },
15
- { name: "m", divisor: 60 * 1000 * 1000 },
16
- { name: "h", divisor: 60 * 60 * 1000 * 1000 },
17
- { name: "d", divisor: 24 * 60 * 60 * 1000 * 1000 },
18
- ];
19
- for (let i = units.length - 1; i >= 0; i--) {
20
- const unit = units[i];
21
- if (us >= unit.divisor) {
22
- const value = Math.round((us / unit.divisor) * 1000) / 1000;
23
- return `${value}${unit.name}`;
6
+ if (ms < 0) {
7
+ throw new Error("Time should be a non-negative number.");
24
8
  }
25
- }
26
- return `${us}us`;
9
+ // Convert milliseconds to microseconds
10
+ const us = ms * 1000;
11
+ const units = [
12
+ { name: "μs", divisor: 1 },
13
+ { name: "ms", divisor: 1000 },
14
+ { name: "s", divisor: 1000 * 1000 },
15
+ { name: "m", divisor: 60 * 1000 * 1000 },
16
+ { name: "h", divisor: 60 * 60 * 1000 * 1000 },
17
+ { name: "d", divisor: 24 * 60 * 60 * 1000 * 1000 },
18
+ ];
19
+ for (let i = units.length - 1; i >= 0; i--) {
20
+ const unit = units[i];
21
+ if (us >= unit.divisor) {
22
+ const value = Math.round((us / unit.divisor) * 1000) / 1000;
23
+ return `${value}${unit.name}`;
24
+ }
25
+ }
26
+ return `${us}us`;
27
27
  }
28
28
  export function loadConfig(CONFIG_PATH, warn = false) {
29
- if (!existsSync(CONFIG_PATH)) {
30
- if (warn)
31
- console.log(
32
- `${chalk.bgMagentaBright(" WARN ")}${chalk.dim(":")} Could not locate config file in the current directory! Continuing with default config.`,
33
- );
34
- return new Config();
35
- } else {
36
- return Object.assign(
37
- new Config(),
38
- JSON.parse(readFileSync(CONFIG_PATH).toString()),
39
- );
40
- }
29
+ if (!existsSync(CONFIG_PATH)) {
30
+ if (warn)
31
+ console.log(`${chalk.bgMagentaBright(" WARN ")}${chalk.dim(":")} Could not locate config file in the current directory! Continuing with default config.`);
32
+ return new Config();
33
+ }
34
+ else {
35
+ return Object.assign(new Config(), JSON.parse(readFileSync(CONFIG_PATH).toString()));
36
+ }
41
37
  }
42
38
  export function getExec(exec) {
43
- const PATH = process.env.PATH.split(delimiter);
44
- for (const pathDir of PATH) {
45
- const fullPath = join(
46
- pathDir,
47
- exec + (process.platform === "win32" ? ".exe" : ""),
48
- );
49
- if (existsSync(fullPath)) {
50
- return fullPath;
39
+ const PATH = process.env.PATH.split(delimiter);
40
+ for (const pathDir of PATH) {
41
+ const fullPath = join(pathDir, exec + (process.platform === "win32" ? ".exe" : ""));
42
+ if (existsSync(fullPath)) {
43
+ return fullPath;
44
+ }
51
45
  }
52
- }
53
- return null;
46
+ return null;
54
47
  }