adamantite 0.17.0 → 0.18.0
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/README.md +76 -74
- package/dist/index.js +239 -143
- package/package.json +10 -11
- package/presets/oxlint/core.json +439 -0
- package/presets/oxlint/node.json +8 -0
- package/presets/oxlint/react.json +7 -0
- package/presets/tsconfig.json +2 -0
- package/presets/biome.jsonc +0 -439
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { Fault as Fault3 } from "faultier";
|
|
|
9
9
|
import { ok as ok3, safeTry as safeTry3 } from "neverthrow";
|
|
10
10
|
import { dlxCommand } from "nypm";
|
|
11
11
|
|
|
12
|
-
// src/helpers/packages/
|
|
12
|
+
// src/helpers/packages/oxlint.ts
|
|
13
13
|
import { readFile as readFile2, writeFile } from "node:fs/promises";
|
|
14
14
|
import { join as join2 } from "node:path";
|
|
15
15
|
import { Fault as Fault2 } from "faultier";
|
|
@@ -20,7 +20,7 @@ import { spawnSync } from "node:child_process";
|
|
|
20
20
|
import { access, readFile } from "node:fs/promises";
|
|
21
21
|
import { join } from "node:path";
|
|
22
22
|
import process2 from "node:process";
|
|
23
|
-
import defu from "defu";
|
|
23
|
+
import { defu } from "defu";
|
|
24
24
|
import { Fault } from "faultier";
|
|
25
25
|
import { parse } from "jsonc-parser";
|
|
26
26
|
import { err, fromPromise, fromThrowable, ok, safeTry } from "neverthrow";
|
|
@@ -50,11 +50,12 @@ var parseJson = (content) => {
|
|
|
50
50
|
}
|
|
51
51
|
return ok(parsed);
|
|
52
52
|
};
|
|
53
|
+
var isJsonObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
53
54
|
var WORKSPACE_PREFIX_REGEX = /^workspace:/;
|
|
54
55
|
var RANGE_PREFIX_REGEX = /^[\^~]/;
|
|
55
56
|
var normalizeDependencyVersion = (specifier) => specifier.trim().replace(WORKSPACE_PREFIX_REGEX, "").replace(RANGE_PREFIX_REGEX, "");
|
|
56
57
|
var mergeConfig = fromThrowable(defu, (error) => Fault.wrap(error).withTag("FAILED_TO_MERGE_CONFIG").withDescription("Failed to merge configuration", "We're unable to merge the configuration files."));
|
|
57
|
-
var readPackageJson = (cwd = process2.cwd()) => fromPromise(readFile(join(cwd, "package.json"), "
|
|
58
|
+
var readPackageJson = (cwd = process2.cwd()) => fromPromise(readFile(join(cwd, "package.json"), "utf8"), (error) => Fault.wrap(error).withTag("FAILED_TO_READ_FILE").withDescription("Failed to read package.json", "We're unable to read the package.json file in the current directory.").withContext({ path: join(cwd, "package.json") })).andThen((content) => parseJson(content)).andThen((parsed) => ok(parsed));
|
|
58
59
|
var checkIsMonorepo = () => safeTry(async function* () {
|
|
59
60
|
const pnpmWorkspace = await checkIfExists(join(process2.cwd(), "pnpm-workspace.yaml"));
|
|
60
61
|
if (pnpmWorkspace) {
|
|
@@ -63,84 +64,81 @@ var checkIsMonorepo = () => safeTry(async function* () {
|
|
|
63
64
|
const packageJson = yield* readPackageJson();
|
|
64
65
|
return ok(packageJson?.workspaces !== undefined);
|
|
65
66
|
});
|
|
66
|
-
var TITLE = `
|
|
67
|
-
o ooooooooo o oooo oooo o oooo oooo ooooooooooo ooooo ooooooooooo ooooooooooo
|
|
68
|
-
888 888 88o 888 8888o 888 888 8888o 88 88 888 88 888 88 888 88 888 88
|
|
69
|
-
8 88 888 888 8 88 88 888o8 88 8 88 88 888o88 888 888 888 888ooo8
|
|
70
|
-
8oooo88 888 888 8oooo88 88 888 88 8oooo88 88 8888 888 888 888 888 oo
|
|
71
|
-
o88o o888o o888ooo88 o88o o888o o88o 8 o88o o88o o888o o88o 88 o888o o888o o888o o888ooo8888
|
|
72
|
-
`;
|
|
73
67
|
function printTitle() {
|
|
74
|
-
const
|
|
68
|
+
const title = `
|
|
69
|
+
.o8 . o8o .
|
|
70
|
+
"888 .o8 \`"' .o8
|
|
71
|
+
.oooo. .oooo888 .oooo. ooo. .oo. .oo. .oooo. ooo. .oo. .o888oo oooo .o888oo .ooooo.
|
|
72
|
+
\`P )88b d88' \`888 \`P )88b \`888P"Y88bP"Y88b \`P )88b \`888P"Y88b 888 \`888 888 d88' \`88b
|
|
73
|
+
.oP"888 888 888 .oP"888 888 888 888 .oP"888 888 888 888 888 888 888ooo888
|
|
74
|
+
d8( 888 888 888 d8( 888 888 888 888 d8( 888 888 888 888 . 888 888 . 888 .o
|
|
75
|
+
\`Y888""8o \`Y8bod88P" \`Y888""8o o888o o888o o888o \`Y888""8o o888o o888o "888" o888o "888" \`Y8bod8P'
|
|
76
|
+
`;
|
|
77
|
+
const columns = title.split(`
|
|
75
78
|
`).reduce((max, line) => Math.max(max, line.trim().length), 0);
|
|
76
79
|
if (process2.stdout.columns && process2.stdout.columns >= columns) {
|
|
77
|
-
console.
|
|
80
|
+
console.info(title);
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
|
|
81
|
-
// src/helpers/packages/
|
|
82
|
-
var
|
|
83
|
-
name: "
|
|
84
|
-
version: "
|
|
84
|
+
// src/helpers/packages/oxlint.ts
|
|
85
|
+
var oxlint = {
|
|
86
|
+
name: "oxlint",
|
|
87
|
+
version: "1.35.0",
|
|
85
88
|
config: {
|
|
86
|
-
$schema: "./node_modules
|
|
89
|
+
$schema: "./node_modules/oxlint/configuration_schema.json"
|
|
87
90
|
},
|
|
88
91
|
exists: async () => {
|
|
89
|
-
if (await checkIfExists(join2(process.cwd(), "
|
|
90
|
-
return { path: join2(process.cwd(), "
|
|
91
|
-
}
|
|
92
|
-
if (await checkIfExists(join2(process.cwd(), "biome.json"))) {
|
|
93
|
-
return { path: join2(process.cwd(), "biome.json") };
|
|
92
|
+
if (await checkIfExists(join2(process.cwd(), ".oxlintrc.json"))) {
|
|
93
|
+
return { path: join2(process.cwd(), ".oxlintrc.json") };
|
|
94
94
|
}
|
|
95
95
|
return { path: null };
|
|
96
96
|
},
|
|
97
|
-
create: () => fromPromise2(writeFile(join2(process.cwd(), "
|
|
97
|
+
create: () => fromPromise2(writeFile(join2(process.cwd(), ".oxlintrc.json"), JSON.stringify({ ...oxlint.config, extends: ["adamantite/lint"] }, null, 2)), (error) => Fault2.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write oxlint configuration", "We're unable to write the oxlint configuration to the current directory.")),
|
|
98
98
|
update: () => safeTry2(async function* () {
|
|
99
|
-
const exists = await
|
|
99
|
+
const exists = await oxlint.exists();
|
|
100
100
|
if (!exists.path) {
|
|
101
|
-
return err2(Fault2.create("FILE_NOT_FOUND").withDescription("No
|
|
101
|
+
return err2(Fault2.create("FILE_NOT_FOUND").withDescription("No `.oxlintrc.json` found", "We're unable to find an oxlint configuration in the current directory."));
|
|
102
102
|
}
|
|
103
|
-
const
|
|
104
|
-
const existingConfig = yield* parseJson(
|
|
105
|
-
if (!
|
|
106
|
-
return err2(Fault2.create("
|
|
103
|
+
const oxlintFile = yield* fromPromise2(readFile2(exists.path, "utf8"), (error) => Fault2.wrap(error).withTag("FAILED_TO_READ_FILE").withDescription("Failed to read oxlint configuration", "We're unable to read the oxlint configuration from the current directory."));
|
|
104
|
+
const existingConfig = yield* parseJson(oxlintFile);
|
|
105
|
+
if (!isJsonObject(existingConfig)) {
|
|
106
|
+
return err2(Fault2.create("INVALID_CONFIG_FORMAT").withDescription("Invalid oxlint configuration format", "The oxlint configuration must be a JSON object."));
|
|
107
107
|
}
|
|
108
108
|
const newConfig = { ...existingConfig };
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const mergedConfig = yield* mergeConfig(newConfig,
|
|
116
|
-
mergedConfig.$schema =
|
|
117
|
-
yield* fromPromise2(writeFile(exists.path, JSON.stringify(mergedConfig, null, 2)), (error) => Fault2.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write
|
|
109
|
+
const extendsArray = Array.isArray(newConfig.extends) ? newConfig.extends : typeof newConfig.extends === "string" ? [newConfig.extends] : [];
|
|
110
|
+
const hasAdamantite = extendsArray.some((ext) => ext === "adamantite/lint" || ext === "adamantite/lint/core");
|
|
111
|
+
if (!hasAdamantite) {
|
|
112
|
+
extendsArray.push("adamantite/lint");
|
|
113
|
+
}
|
|
114
|
+
newConfig.extends = extendsArray;
|
|
115
|
+
const mergedConfig = yield* mergeConfig(newConfig, oxlint.config);
|
|
116
|
+
mergedConfig.$schema = oxlint.config.$schema;
|
|
117
|
+
yield* fromPromise2(writeFile(exists.path, JSON.stringify(mergedConfig, null, 2)), (error) => Fault2.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write oxlint configuration", "We're unable to write the oxlint configuration to the current directory.").withContext({ path: exists.path }));
|
|
118
118
|
return ok2();
|
|
119
119
|
})
|
|
120
120
|
};
|
|
121
|
+
var tsgolint = {
|
|
122
|
+
name: "oxlint-tsgolint",
|
|
123
|
+
version: "0.10.0"
|
|
124
|
+
};
|
|
121
125
|
|
|
122
126
|
// src/commands/check.ts
|
|
123
127
|
var check_default = defineCommand({
|
|
124
128
|
command: "check [files..]",
|
|
125
|
-
describe: "Find issues in code using
|
|
129
|
+
describe: "Find issues in code using oxlint",
|
|
126
130
|
builder: (yargs) => yargs.positional("files", {
|
|
127
131
|
describe: "Specific files to lint (optional)",
|
|
128
132
|
type: "string",
|
|
129
133
|
array: true
|
|
130
|
-
}).option("summary", {
|
|
131
|
-
type: "boolean",
|
|
132
|
-
description: "Show summary of lint results"
|
|
133
134
|
}),
|
|
134
135
|
handler: (argv) => safeTry3(async function* () {
|
|
135
136
|
const packageManager = yield* getPackageManagerName();
|
|
136
|
-
const args = ["
|
|
137
|
-
if (argv.summary) {
|
|
138
|
-
args.push("--reporter", "summary");
|
|
139
|
-
}
|
|
137
|
+
const args = ["--type-aware"];
|
|
140
138
|
if (argv.files && argv.files.length > 0) {
|
|
141
139
|
args.push(...argv.files);
|
|
142
140
|
}
|
|
143
|
-
const command = dlxCommand(packageManager,
|
|
141
|
+
const command = dlxCommand(packageManager, oxlint.name, { args });
|
|
144
142
|
const result = yield* runCommand(command);
|
|
145
143
|
return ok3(result);
|
|
146
144
|
}).match(() => {
|
|
@@ -161,25 +159,43 @@ import { ok as ok4, safeTry as safeTry4 } from "neverthrow";
|
|
|
161
159
|
import { dlxCommand as dlxCommand2 } from "nypm";
|
|
162
160
|
var fix_default = defineCommand({
|
|
163
161
|
command: "fix [files..]",
|
|
164
|
-
describe: "Fix issues in code using
|
|
162
|
+
describe: "Fix issues in code using oxlint",
|
|
165
163
|
builder: (yargs) => yargs.positional("files", {
|
|
166
164
|
describe: "Specific files to fix (optional)",
|
|
167
165
|
type: "string",
|
|
168
166
|
array: true
|
|
169
|
-
}).option("
|
|
167
|
+
}).option("suggested", {
|
|
170
168
|
type: "boolean",
|
|
171
|
-
description: "Apply
|
|
169
|
+
description: "Apply suggested fixes",
|
|
170
|
+
default: false
|
|
171
|
+
}).option("dangerous", {
|
|
172
|
+
type: "boolean",
|
|
173
|
+
description: "Apply dangerous fixes",
|
|
174
|
+
default: false
|
|
175
|
+
}).option("all", {
|
|
176
|
+
type: "boolean",
|
|
177
|
+
description: "Apply all fixes, including suggested and dangerous fixes",
|
|
178
|
+
default: false
|
|
172
179
|
}),
|
|
173
180
|
handler: (argv) => safeTry4(async function* () {
|
|
174
181
|
const packageManager = yield* getPackageManagerName();
|
|
175
|
-
const args = ["
|
|
176
|
-
if (argv.
|
|
177
|
-
args.
|
|
182
|
+
const args = new Set(["--type-aware", "--fix"]);
|
|
183
|
+
if (argv.suggested) {
|
|
184
|
+
args.add("--fix-suggestions");
|
|
185
|
+
}
|
|
186
|
+
if (argv.dangerous) {
|
|
187
|
+
args.add("--fix-dangerously");
|
|
188
|
+
}
|
|
189
|
+
if (argv.all) {
|
|
190
|
+
args.add("--fix-suggestions");
|
|
191
|
+
args.add("--fix-dangerously");
|
|
178
192
|
}
|
|
179
193
|
if (argv.files && argv.files.length > 0) {
|
|
180
|
-
|
|
194
|
+
for (const file of argv.files) {
|
|
195
|
+
args.add(file);
|
|
196
|
+
}
|
|
181
197
|
}
|
|
182
|
-
const command = dlxCommand2(packageManager,
|
|
198
|
+
const command = dlxCommand2(packageManager, oxlint.name, { args: Array.from(args) });
|
|
183
199
|
yield* runCommand(command);
|
|
184
200
|
return ok4();
|
|
185
201
|
}).match(() => {
|
|
@@ -266,10 +282,10 @@ var oxfmt = {
|
|
|
266
282
|
if (!exists.path) {
|
|
267
283
|
return err3(Fault5.create("FILE_NOT_FOUND").withDescription("No `.oxfmtrc.jsonc` or `.oxfmtrc.json` found", "We're unable to find an oxfmt configuration in the current directory."));
|
|
268
284
|
}
|
|
269
|
-
const oxfmtFile = yield* fromPromise3(readFile3(exists.path, "
|
|
285
|
+
const oxfmtFile = yield* fromPromise3(readFile3(exists.path, "utf8"), (error) => Fault5.wrap(error).withTag("FAILED_TO_READ_FILE").withDescription("Failed to read oxfmt configuration", "We're unable to read the oxfmt configuration from the current directory."));
|
|
270
286
|
const existingConfig = yield* parseJson(oxfmtFile);
|
|
271
|
-
if (!
|
|
272
|
-
return err3(Fault5.create("
|
|
287
|
+
if (!isJsonObject(existingConfig)) {
|
|
288
|
+
return err3(Fault5.create("INVALID_CONFIG_FORMAT").withDescription("Invalid oxfmt configuration format", "The oxfmt configuration must be a JSON object."));
|
|
273
289
|
}
|
|
274
290
|
const mergedConfig = yield* mergeConfig(existingConfig, oxfmt.config);
|
|
275
291
|
mergedConfig.$schema = oxfmt.config.$schema;
|
|
@@ -318,7 +334,7 @@ import { join as join7 } from "node:path";
|
|
|
318
334
|
import process7 from "node:process";
|
|
319
335
|
import * as p from "@clack/prompts";
|
|
320
336
|
import { Fault as Fault10 } from "faultier";
|
|
321
|
-
import { err as
|
|
337
|
+
import { err as err6, fromPromise as fromPromise7, fromSafePromise, ok as ok10, safeTry as safeTry10 } from "neverthrow";
|
|
322
338
|
import { addDevDependency } from "nypm";
|
|
323
339
|
|
|
324
340
|
// src/helpers/ci/github.ts
|
|
@@ -328,11 +344,20 @@ import process6 from "node:process";
|
|
|
328
344
|
import { Fault as Fault7 } from "faultier";
|
|
329
345
|
import { fromPromise as fromPromise4, ok as ok7, safeTry as safeTry7 } from "neverthrow";
|
|
330
346
|
import { runScriptCommand } from "nypm";
|
|
331
|
-
var CI_COMPATIBLE_SCRIPTS = ["check", "format", "typecheck", "check:monorepo"];
|
|
332
347
|
var setupSteps = {
|
|
333
348
|
bun: ` - name: Setup Bun
|
|
334
349
|
uses: oven-sh/setup-bun@v2
|
|
335
350
|
|
|
351
|
+
- name: Cache dependencies
|
|
352
|
+
uses: actions/cache@v4
|
|
353
|
+
with:
|
|
354
|
+
path: |
|
|
355
|
+
~/.bun/install/cache
|
|
356
|
+
node_modules
|
|
357
|
+
key: \${{ runner.os }}-bun-\${{ hashFiles('bun.lock') }}
|
|
358
|
+
restore-keys: |
|
|
359
|
+
\${{ runner.os }}-bun-
|
|
360
|
+
|
|
336
361
|
- name: Install dependencies
|
|
337
362
|
run: bun install --frozen-lockfile`,
|
|
338
363
|
pnpm: ` - name: Setup pnpm
|
|
@@ -368,36 +393,40 @@ var setupSteps = {
|
|
|
368
393
|
- name: Install dependencies
|
|
369
394
|
run: deno install --frozen`
|
|
370
395
|
};
|
|
371
|
-
var
|
|
372
|
-
${jobName}:
|
|
373
|
-
runs-on: ubuntu-latest
|
|
374
|
-
timeout-minutes: 10
|
|
375
|
-
steps:
|
|
376
|
-
- name: Checkout code
|
|
377
|
-
uses: actions/checkout@v4
|
|
378
|
-
|
|
379
|
-
${setupSteps[packageManager]}
|
|
380
|
-
|
|
381
|
-
- name: ${stepName}
|
|
382
|
-
run: ${runScriptCommand(packageManager, script)}`;
|
|
396
|
+
var buildCommand = (packageManager, script, args) => runScriptCommand(packageManager, script, { args });
|
|
383
397
|
var generateWorkflow = ({ packageManager, scripts }) => {
|
|
384
|
-
const
|
|
398
|
+
const matrixEntries = [];
|
|
385
399
|
if (scripts.includes("check")) {
|
|
386
|
-
|
|
400
|
+
matrixEntries.push({
|
|
401
|
+
name: "lint",
|
|
402
|
+
command: buildCommand(packageManager, "check")
|
|
403
|
+
});
|
|
387
404
|
}
|
|
388
405
|
if (scripts.includes("format")) {
|
|
389
|
-
|
|
406
|
+
matrixEntries.push({
|
|
407
|
+
name: "format",
|
|
408
|
+
command: buildCommand(packageManager, "format", ["--check"])
|
|
409
|
+
});
|
|
390
410
|
}
|
|
391
411
|
if (scripts.includes("typecheck")) {
|
|
392
|
-
|
|
412
|
+
matrixEntries.push({
|
|
413
|
+
name: "types",
|
|
414
|
+
command: buildCommand(packageManager, "typecheck")
|
|
415
|
+
});
|
|
393
416
|
}
|
|
394
417
|
if (scripts.includes("check:monorepo")) {
|
|
395
|
-
|
|
418
|
+
matrixEntries.push({
|
|
419
|
+
name: "monorepo",
|
|
420
|
+
command: buildCommand(packageManager, "check:monorepo")
|
|
421
|
+
});
|
|
396
422
|
}
|
|
397
|
-
if (
|
|
423
|
+
if (matrixEntries.length === 0) {
|
|
398
424
|
return null;
|
|
399
425
|
}
|
|
400
|
-
const
|
|
426
|
+
const matrixInclude = matrixEntries.map((entry) => ` - name: ${entry.name}
|
|
427
|
+
command: ${entry.command}`).join(`
|
|
428
|
+
`);
|
|
429
|
+
const workflow = `name: adamantite
|
|
401
430
|
|
|
402
431
|
on:
|
|
403
432
|
push:
|
|
@@ -406,16 +435,36 @@ on:
|
|
|
406
435
|
pull_request:
|
|
407
436
|
types: [opened, synchronize, reopened]
|
|
408
437
|
|
|
438
|
+
permissions:
|
|
439
|
+
contents: read
|
|
440
|
+
|
|
409
441
|
concurrency:
|
|
410
442
|
group: \${{ github.workflow }}-\${{ github.ref }}
|
|
411
443
|
cancel-in-progress: true
|
|
412
444
|
|
|
413
|
-
jobs
|
|
414
|
-
|
|
445
|
+
jobs:
|
|
446
|
+
verify:
|
|
447
|
+
name: \${{ matrix.name }}
|
|
448
|
+
runs-on: ubuntu-latest
|
|
449
|
+
timeout-minutes: 10
|
|
450
|
+
strategy:
|
|
451
|
+
fail-fast: false
|
|
452
|
+
matrix:
|
|
453
|
+
include:
|
|
454
|
+
${matrixInclude}
|
|
455
|
+
|
|
456
|
+
steps:
|
|
457
|
+
- name: Checkout
|
|
458
|
+
uses: actions/checkout@v4
|
|
459
|
+
|
|
460
|
+
${setupSteps[packageManager]}
|
|
461
|
+
|
|
462
|
+
- name: Run \${{ matrix.name }}
|
|
463
|
+
run: \${{ matrix.command }}`;
|
|
415
464
|
return `${workflow}
|
|
416
465
|
`;
|
|
417
466
|
};
|
|
418
|
-
var hasCICompatibleScripts = (scripts) => scripts.some((script) =>
|
|
467
|
+
var hasCICompatibleScripts = (scripts) => scripts.some((script) => ["check", "format", "typecheck", "check:monorepo"].includes(script));
|
|
419
468
|
var github = {
|
|
420
469
|
workflowPath: ".github/workflows/adamantite.yml",
|
|
421
470
|
exists: () => checkIfExists(join4(process6.cwd(), ".github", "workflows", "adamantite.yml")),
|
|
@@ -444,14 +493,14 @@ var github = {
|
|
|
444
493
|
import { mkdir as mkdir2, readFile as readFile4, writeFile as writeFile4 } from "node:fs/promises";
|
|
445
494
|
import { join as join5 } from "node:path";
|
|
446
495
|
import { Fault as Fault8 } from "faultier";
|
|
447
|
-
import { fromPromise as fromPromise5, ok as ok8, safeTry as safeTry8 } from "neverthrow";
|
|
496
|
+
import { err as err4, fromPromise as fromPromise5, ok as ok8, safeTry as safeTry8 } from "neverthrow";
|
|
448
497
|
var vscode = {
|
|
449
498
|
config: {
|
|
450
499
|
"typescript.tsdk": "node_modules/typescript/lib",
|
|
451
500
|
"editor.formatOnSave": true,
|
|
452
501
|
"editor.formatOnPaste": true,
|
|
453
502
|
"editor.codeActionsOnSave": {
|
|
454
|
-
"source.fixAll.
|
|
503
|
+
"source.fixAll.oxc": "explicit"
|
|
455
504
|
},
|
|
456
505
|
"[javascript][typescript][javascriptreact][typescriptreact][json][jsonc][css][graphql]": {
|
|
457
506
|
"editor.defaultFormatter": "oxc.oxc-vscode"
|
|
@@ -466,8 +515,11 @@ var vscode = {
|
|
|
466
515
|
}),
|
|
467
516
|
update: () => safeTry8(async function* () {
|
|
468
517
|
const vscodePath = join5(process.cwd(), ".vscode", "settings.json");
|
|
469
|
-
const vscodeFile = yield* fromPromise5(readFile4(vscodePath, "
|
|
518
|
+
const vscodeFile = yield* fromPromise5(readFile4(vscodePath, "utf8"), (error) => Fault8.wrap(error).withTag("FAILED_TO_READ_FILE").withDescription("Failed to read .vscode/settings.json", "We're unable to read the .vscode/settings.json file in the current directory.").withContext({ path: vscodePath }));
|
|
470
519
|
const existingConfig = yield* parseJson(vscodeFile);
|
|
520
|
+
if (!isJsonObject(existingConfig)) {
|
|
521
|
+
return err4(Fault8.create("INVALID_CONFIG_FORMAT").withDescription("Invalid .vscode/settings.json format", "The VS Code settings file must be a JSON object."));
|
|
522
|
+
}
|
|
471
523
|
const newConfig = yield* mergeConfig(vscode.config, existingConfig);
|
|
472
524
|
yield* fromPromise5(writeFile4(join5(process.cwd(), ".vscode", "settings.json"), JSON.stringify(newConfig, null, 2)), (error) => Fault8.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write .vscode/settings.json", "We're unable to write the .vscode/settings.json file in the current directory.").withContext({ path: vscodePath }));
|
|
473
525
|
return ok8();
|
|
@@ -480,19 +532,23 @@ var sherif = {
|
|
|
480
532
|
version: "1.9.0"
|
|
481
533
|
};
|
|
482
534
|
|
|
483
|
-
// src/helpers/
|
|
535
|
+
// src/helpers/packages/typescript.ts
|
|
484
536
|
import { readFile as readFile5, writeFile as writeFile5 } from "node:fs/promises";
|
|
485
537
|
import { join as join6 } from "node:path";
|
|
486
538
|
import { Fault as Fault9 } from "faultier";
|
|
487
|
-
import { fromPromise as fromPromise6, ok as ok9, safeTry as safeTry9 } from "neverthrow";
|
|
488
|
-
var
|
|
539
|
+
import { err as err5, fromPromise as fromPromise6, ok as ok9, safeTry as safeTry9 } from "neverthrow";
|
|
540
|
+
var typescript = {
|
|
541
|
+
name: "tsc",
|
|
489
542
|
config: { extends: "adamantite/typescript" },
|
|
490
543
|
exists: () => checkIfExists(join6(process.cwd(), "tsconfig.json")),
|
|
491
|
-
create: () => fromPromise6(writeFile5(join6(process.cwd(), "tsconfig.json"), JSON.stringify(
|
|
544
|
+
create: () => fromPromise6(writeFile5(join6(process.cwd(), "tsconfig.json"), JSON.stringify(typescript.config, null, 2)), (error) => Fault9.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write tsconfig.json", "We're unable to write the tsconfig.json file in the current directory.")),
|
|
492
545
|
update: () => safeTry9(async function* () {
|
|
493
|
-
const tsconfigFile = yield* fromPromise6(readFile5(join6(process.cwd(), "tsconfig.json"), "
|
|
546
|
+
const tsconfigFile = yield* fromPromise6(readFile5(join6(process.cwd(), "tsconfig.json"), "utf8"), (error) => Fault9.wrap(error).withTag("FAILED_TO_READ_FILE").withDescription("Failed to read tsconfig.json", "We're unable to read the tsconfig.json file in the current directory."));
|
|
494
547
|
const existingConfig = yield* parseJson(tsconfigFile);
|
|
495
|
-
|
|
548
|
+
if (!isJsonObject(existingConfig)) {
|
|
549
|
+
return err5(Fault9.create("INVALID_CONFIG_FORMAT").withDescription("Invalid tsconfig.json format", "The tsconfig.json file must be a JSON object."));
|
|
550
|
+
}
|
|
551
|
+
const newConfig = yield* mergeConfig(typescript.config, existingConfig);
|
|
496
552
|
yield* fromPromise6(writeFile5(join6(process.cwd(), "tsconfig.json"), JSON.stringify(newConfig, null, 2)), (error) => Fault9.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write tsconfig.json", "We're unable to write the tsconfig.json file in the current directory."));
|
|
497
553
|
return ok9();
|
|
498
554
|
})
|
|
@@ -509,18 +565,18 @@ var installDependencies = (packages) => safeTry10(async function* () {
|
|
|
509
565
|
s.stop("Dependencies installed.");
|
|
510
566
|
return ok10();
|
|
511
567
|
});
|
|
512
|
-
var
|
|
568
|
+
var setupOxlintConfig = () => safeTry10(async function* () {
|
|
513
569
|
const spinner2 = p.spinner();
|
|
514
|
-
spinner2.start("Setting up
|
|
515
|
-
const
|
|
516
|
-
if (
|
|
517
|
-
spinner2.message(`Found \`${
|
|
518
|
-
yield*
|
|
519
|
-
spinner2.stop("
|
|
570
|
+
spinner2.start("Setting up oxlint config...");
|
|
571
|
+
const oxlintPath = await oxlint.exists();
|
|
572
|
+
if (oxlintPath.path) {
|
|
573
|
+
spinner2.message(`Found \`${oxlintPath.path}\`, updating...`);
|
|
574
|
+
yield* oxlint.update();
|
|
575
|
+
spinner2.stop("oxlint config updated successfully.");
|
|
520
576
|
} else {
|
|
521
|
-
spinner2.message("`.
|
|
522
|
-
yield*
|
|
523
|
-
spinner2.stop("
|
|
577
|
+
spinner2.message("`.oxlintrc.json` not found, creating...");
|
|
578
|
+
yield* oxlint.create();
|
|
579
|
+
spinner2.stop("oxlint config created successfully.");
|
|
524
580
|
}
|
|
525
581
|
return ok10();
|
|
526
582
|
});
|
|
@@ -544,9 +600,7 @@ var addScripts = (scripts) => safeTry10(async function* () {
|
|
|
544
600
|
const packageJson = yield* readPackageJson();
|
|
545
601
|
const spinner2 = p.spinner();
|
|
546
602
|
spinner2.start("Adding scripts to your `package.json`...");
|
|
547
|
-
|
|
548
|
-
packageJson.scripts = {};
|
|
549
|
-
}
|
|
603
|
+
packageJson.scripts ??= {};
|
|
550
604
|
for (const script of scripts) {
|
|
551
605
|
switch (script) {
|
|
552
606
|
case "check":
|
|
@@ -559,7 +613,7 @@ var addScripts = (scripts) => safeTry10(async function* () {
|
|
|
559
613
|
packageJson.scripts.format = "adamantite format";
|
|
560
614
|
break;
|
|
561
615
|
case "typecheck":
|
|
562
|
-
packageJson.scripts.typecheck = "
|
|
616
|
+
packageJson.scripts.typecheck = "adamantite typecheck";
|
|
563
617
|
break;
|
|
564
618
|
case "check:monorepo":
|
|
565
619
|
packageJson.scripts["check:monorepo"] = "adamantite monorepo";
|
|
@@ -568,7 +622,7 @@ var addScripts = (scripts) => safeTry10(async function* () {
|
|
|
568
622
|
packageJson.scripts["fix:monorepo"] = "adamantite monorepo --fix";
|
|
569
623
|
break;
|
|
570
624
|
default:
|
|
571
|
-
return
|
|
625
|
+
return err6(Fault10.create("UNKNOWN_SCRIPT").withContext({ script }));
|
|
572
626
|
}
|
|
573
627
|
}
|
|
574
628
|
yield* fromPromise7(writeFile6(join7(cwd, "package.json"), JSON.stringify(packageJson, null, 2)), (error) => Fault10.wrap(error).withTag("FAILED_TO_WRITE_FILE").withDescription("Failed to write package.json", "We're unable to update the package.json file.").withContext({ path: join7(cwd, "package.json") }));
|
|
@@ -578,13 +632,13 @@ var addScripts = (scripts) => safeTry10(async function* () {
|
|
|
578
632
|
var setupTypescript = () => safeTry10(async function* () {
|
|
579
633
|
const spinner2 = p.spinner();
|
|
580
634
|
spinner2.start("Setting up TypeScript config...");
|
|
581
|
-
if (await
|
|
635
|
+
if (await typescript.exists()) {
|
|
582
636
|
spinner2.message("`tsconfig.json` found, updating...");
|
|
583
|
-
yield*
|
|
637
|
+
yield* typescript.update();
|
|
584
638
|
spinner2.stop("`tsconfig.json` updated successfully");
|
|
585
639
|
} else {
|
|
586
640
|
spinner2.message("`tsconfig.json` not found, creating...");
|
|
587
|
-
yield*
|
|
641
|
+
yield* typescript.create();
|
|
588
642
|
spinner2.stop("`tsconfig.json` created successfully");
|
|
589
643
|
}
|
|
590
644
|
return ok10();
|
|
@@ -637,12 +691,12 @@ var init_default = defineCommand({
|
|
|
637
691
|
message: "Which scripts do you want to add to your `package.json`?",
|
|
638
692
|
options: [
|
|
639
693
|
{
|
|
640
|
-
label: "check - find issues in code using
|
|
694
|
+
label: "check - find issues in code using oxlint",
|
|
641
695
|
value: "check",
|
|
642
696
|
hint: "recommended"
|
|
643
697
|
},
|
|
644
698
|
{
|
|
645
|
-
label: "fix - fix code issues using
|
|
699
|
+
label: "fix - fix code issues using oxlint",
|
|
646
700
|
value: "fix",
|
|
647
701
|
hint: "recommended"
|
|
648
702
|
},
|
|
@@ -671,7 +725,7 @@ var init_default = defineCommand({
|
|
|
671
725
|
]
|
|
672
726
|
}));
|
|
673
727
|
if (p.isCancel(scripts)) {
|
|
674
|
-
return
|
|
728
|
+
return err6(Fault10.create("OPERATION_CANCELLED"));
|
|
675
729
|
}
|
|
676
730
|
const editors = yield* fromSafePromise(p.multiselect({
|
|
677
731
|
message: "Which editors do you want to configure? (optional)",
|
|
@@ -682,7 +736,7 @@ var init_default = defineCommand({
|
|
|
682
736
|
required: false
|
|
683
737
|
}));
|
|
684
738
|
if (p.isCancel(editors)) {
|
|
685
|
-
return
|
|
739
|
+
return err6(Fault10.create("OPERATION_CANCELLED"));
|
|
686
740
|
}
|
|
687
741
|
const hasCIScripts = hasCICompatibleScripts(scripts);
|
|
688
742
|
let enableGitHubActions = false;
|
|
@@ -692,17 +746,18 @@ var init_default = defineCommand({
|
|
|
692
746
|
initialValue: false
|
|
693
747
|
}));
|
|
694
748
|
if (p.isCancel(response)) {
|
|
695
|
-
return
|
|
749
|
+
return err6(Fault10.create("OPERATION_CANCELLED"));
|
|
696
750
|
}
|
|
697
751
|
enableGitHubActions = response;
|
|
698
752
|
}
|
|
699
|
-
const
|
|
753
|
+
const hasOxlint = scripts.includes("check") || scripts.includes("fix");
|
|
700
754
|
const hasOxfmt = scripts.includes("format");
|
|
701
755
|
const hasSherif = scripts.includes("check:monorepo") || scripts.includes("fix:monorepo");
|
|
702
756
|
const hasTypecheck = scripts.includes("typecheck");
|
|
703
757
|
const dependencies = ["adamantite"];
|
|
704
|
-
if (
|
|
705
|
-
dependencies.push(`${
|
|
758
|
+
if (hasOxlint) {
|
|
759
|
+
dependencies.push(`${oxlint.name}@${oxlint.version}`);
|
|
760
|
+
dependencies.push(`${tsgolint.name}@${tsgolint.version}`);
|
|
706
761
|
}
|
|
707
762
|
if (hasOxfmt) {
|
|
708
763
|
dependencies.push(`${oxfmt.name}@${oxfmt.version}`);
|
|
@@ -717,8 +772,8 @@ var init_default = defineCommand({
|
|
|
717
772
|
if (hasOxfmt) {
|
|
718
773
|
yield* setupOxfmtConfig();
|
|
719
774
|
}
|
|
720
|
-
if (
|
|
721
|
-
yield*
|
|
775
|
+
if (hasOxlint) {
|
|
776
|
+
yield* setupOxlintConfig();
|
|
722
777
|
}
|
|
723
778
|
yield* addScripts(scripts);
|
|
724
779
|
if (hasTypecheck) {
|
|
@@ -769,7 +824,7 @@ var monorepo_default = defineCommand({
|
|
|
769
824
|
}
|
|
770
825
|
const command = dlxCommand4(packageManager, sherif.name, { args });
|
|
771
826
|
yield* runCommand(command);
|
|
772
|
-
return ok11(
|
|
827
|
+
return ok11();
|
|
773
828
|
}).match(() => {
|
|
774
829
|
process8.exit(0);
|
|
775
830
|
}, (error) => {
|
|
@@ -780,22 +835,62 @@ var monorepo_default = defineCommand({
|
|
|
780
835
|
})
|
|
781
836
|
});
|
|
782
837
|
|
|
783
|
-
// src/commands/
|
|
838
|
+
// src/commands/typecheck.ts
|
|
784
839
|
import process9 from "node:process";
|
|
785
|
-
import {
|
|
840
|
+
import { log as log6 } from "@clack/prompts";
|
|
786
841
|
import { Fault as Fault12 } from "faultier";
|
|
787
|
-
import {
|
|
842
|
+
import { ok as ok12, safeTry as safeTry12 } from "neverthrow";
|
|
843
|
+
import { dlxCommand as dlxCommand5 } from "nypm";
|
|
844
|
+
var typecheck_default = defineCommand({
|
|
845
|
+
command: "typecheck",
|
|
846
|
+
describe: "Run TypeScript type checking",
|
|
847
|
+
builder: (yargs) => yargs.option("project", {
|
|
848
|
+
alias: "p",
|
|
849
|
+
type: "string",
|
|
850
|
+
description: "Path to tsconfig.json file"
|
|
851
|
+
}).option("watch", {
|
|
852
|
+
alias: "w",
|
|
853
|
+
type: "boolean",
|
|
854
|
+
description: "Run in watch mode"
|
|
855
|
+
}),
|
|
856
|
+
handler: (argv) => safeTry12(async function* () {
|
|
857
|
+
const packageManager = yield* getPackageManagerName();
|
|
858
|
+
const args = ["--noEmit"];
|
|
859
|
+
if (argv.project) {
|
|
860
|
+
args.push("--project", argv.project);
|
|
861
|
+
}
|
|
862
|
+
if (argv.watch) {
|
|
863
|
+
args.push("--watch");
|
|
864
|
+
}
|
|
865
|
+
const command = dlxCommand5(packageManager, typescript.name, { args });
|
|
866
|
+
const result = yield* runCommand(command);
|
|
867
|
+
return ok12(result);
|
|
868
|
+
}).match(() => {
|
|
869
|
+
process9.exit(0);
|
|
870
|
+
}, (error) => {
|
|
871
|
+
if (Fault12.isFault(error) && error.tag === "NO_PACKAGE_MANAGER") {
|
|
872
|
+
log6.error(error.flatten());
|
|
873
|
+
}
|
|
874
|
+
process9.exit(1);
|
|
875
|
+
})
|
|
876
|
+
});
|
|
877
|
+
|
|
878
|
+
// src/commands/update.ts
|
|
879
|
+
import process10 from "node:process";
|
|
880
|
+
import { cancel as cancel2, confirm as confirm2, intro as intro2, isCancel as isCancel2, log as log7, outro as outro2, spinner as spinner2 } from "@clack/prompts";
|
|
881
|
+
import { Fault as Fault13 } from "faultier";
|
|
882
|
+
import { err as err7, fromPromise as fromPromise8, fromSafePromise as fromSafePromise2, ok as ok13, safeTry as safeTry13 } from "neverthrow";
|
|
788
883
|
import { addDevDependency as addDevDependency2 } from "nypm";
|
|
789
884
|
var update_default = defineCommand({
|
|
790
885
|
command: "update",
|
|
791
886
|
describe: "Update adamantite dependencies to latest compatible versions",
|
|
792
887
|
builder: (yargs) => yargs,
|
|
793
|
-
handler:
|
|
888
|
+
handler: () => safeTry13(async function* () {
|
|
794
889
|
const packageJson = yield* readPackageJson();
|
|
795
890
|
printTitle();
|
|
796
891
|
intro2("\uD83D\uDCA0 adamantite update");
|
|
797
892
|
const updates = [];
|
|
798
|
-
for (const pkg of [
|
|
893
|
+
for (const pkg of [oxlint, oxfmt, sherif]) {
|
|
799
894
|
const dependency = packageJson.devDependencies?.[pkg.name];
|
|
800
895
|
if (dependency && normalizeDependencyVersion(dependency) !== pkg.version) {
|
|
801
896
|
updates.push({
|
|
@@ -807,31 +902,31 @@ var update_default = defineCommand({
|
|
|
807
902
|
}
|
|
808
903
|
}
|
|
809
904
|
if (updates.length === 0) {
|
|
810
|
-
|
|
811
|
-
return
|
|
905
|
+
log7.success("All adamantite dependencies are already up to date!");
|
|
906
|
+
return ok13("no-updates");
|
|
812
907
|
}
|
|
813
|
-
|
|
814
|
-
|
|
908
|
+
log7.message("The following dependencies will be updated:");
|
|
909
|
+
log7.message("");
|
|
815
910
|
for (const dep of updates) {
|
|
816
|
-
|
|
911
|
+
log7.message(` ${dep.name}: ${dep.currentVersion} → ${dep.targetVersion}`);
|
|
817
912
|
}
|
|
818
|
-
|
|
913
|
+
log7.message("");
|
|
819
914
|
const shouldUpdate = yield* fromSafePromise2(confirm2({
|
|
820
915
|
message: "Do you want to proceed with these updates?"
|
|
821
916
|
}));
|
|
822
917
|
if (isCancel2(shouldUpdate)) {
|
|
823
|
-
return
|
|
918
|
+
return err7(Fault13.create("OPERATION_CANCELLED"));
|
|
824
919
|
}
|
|
825
920
|
if (!shouldUpdate) {
|
|
826
|
-
return
|
|
921
|
+
return ok13("cancelled");
|
|
827
922
|
}
|
|
828
923
|
const s = spinner2();
|
|
829
924
|
s.start("Updating dependencies...");
|
|
830
925
|
for (const dep of updates) {
|
|
831
|
-
yield* fromPromise8(addDevDependency2(`${dep.name}@${dep.targetVersion}`), (error) =>
|
|
926
|
+
yield* fromPromise8(addDevDependency2(`${dep.name}@${dep.targetVersion}`), (error) => Fault13.wrap(error).withTag("FAILED_TO_INSTALL_DEPENDENCY").withMessage(`Failed to update ${dep.name}`));
|
|
832
927
|
}
|
|
833
928
|
s.stop("Dependencies updated successfully");
|
|
834
|
-
return
|
|
929
|
+
return ok13("updated");
|
|
835
930
|
}).match((value) => {
|
|
836
931
|
if (value === "no-updates") {
|
|
837
932
|
outro2("✅ No updates needed");
|
|
@@ -840,21 +935,22 @@ var update_default = defineCommand({
|
|
|
840
935
|
} else if (value === "updated") {
|
|
841
936
|
outro2("✅ Dependencies updated successfully!");
|
|
842
937
|
}
|
|
843
|
-
|
|
938
|
+
process10.exit(0);
|
|
844
939
|
}, (error) => {
|
|
845
|
-
if (
|
|
940
|
+
if (Fault13.isFault(error) && error.tag === "OPERATION_CANCELLED") {
|
|
846
941
|
cancel2("You've cancelled the update process.");
|
|
847
|
-
|
|
942
|
+
process10.exit(0);
|
|
848
943
|
}
|
|
849
|
-
if (
|
|
850
|
-
|
|
944
|
+
if (Fault13.isFault(error)) {
|
|
945
|
+
log7.error(error.flatten());
|
|
851
946
|
} else {
|
|
852
|
-
|
|
947
|
+
log7.error(String(error));
|
|
853
948
|
}
|
|
854
949
|
cancel2("Failed to update dependencies");
|
|
855
|
-
|
|
950
|
+
process10.exit(1);
|
|
856
951
|
})
|
|
857
952
|
});
|
|
858
953
|
|
|
859
954
|
// src/index.ts
|
|
860
|
-
|
|
955
|
+
var version = await "0.18.0";
|
|
956
|
+
yargs(hideBin(process.argv)).scriptName("adamantite").version(version).command(check_default).command(fix_default).command(format_default).command(init_default).command(monorepo_default).command(typecheck_default).command(update_default).demandCommand(1).strict().help().parse();
|