@particle/tooling 0.1.3 → 0.1.5
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 +2 -1
- package/lib/migrate.js +45 -17
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -24,8 +24,9 @@ What it does, depending on what it finds:
|
|
|
24
24
|
- **Lint and format configs:** deletes `eslint.config.*`, `.eslintrc*`, `.oxlintrc.json` and `.oxfmtrc.json`, and creates `oxlint.config.ts` and `oxfmt.config.ts` that re-export the shared configs. TypeScript projects re-export `@particle/tooling/oxlint-typescript`, JavaScript projects `@particle/tooling/oxlint`.
|
|
25
25
|
- **tsconfigs:** rewrites `tsconfig.json` and `tsconfig.build.json` to extend the shared configs, keeping the project's own `include`, `exclude` and `types`. A config with other project-specific compiler options, or one that already extends something else, is left alone and reported for you to migrate by hand.
|
|
26
26
|
- **Sentry:** when the project depends on a `@sentry/*` package, the build config gets `"sourceRoot": "/"`, which strips the build path from source references so Sentry groups issues consistently. Without Sentry it is removed, because it makes Node stack traces point at paths that do not exist.
|
|
27
|
+
- **`.gitignore`:** adds `.claude/`, so agent worktrees (full copies of the repo) are not linted and formatted along with the project. oxlint and oxfmt only skip what the project's own `.gitignore` lists, not a global gitignore.
|
|
27
28
|
- **Build output:** standardizes on `build/`, adds it to `.gitignore`, and lists every place that still names the old directory (`package.json` fields, scripts, `Dockerfile`, CI config) for you to update.
|
|
28
|
-
- **Scripts:**
|
|
29
|
+
- **Scripts:** removes a `lint` script and has `check` do the linting: plain `eslint` steps become `oxlint --deny-warnings` (so a warning fails the check, in CI too), `check` gains `oxfmt --check`, and other scripts that ran `npm run lint` are pointed at `npm run check`. Adds `fmt` where it is missing, a `check` for TypeScript projects (`tsc && oxlint --deny-warnings && oxfmt --check`) and for JavaScript projects that had a `lint` script, and `build` for TypeScript projects.
|
|
29
30
|
- **CI:** looks at `.circleci/config.yml` and `.github/workflows` and reminds you to confirm that CI runs a step that checks formatting.
|
|
30
31
|
- **Install:** runs `npm install` at the end.
|
|
31
32
|
|
package/lib/migrate.js
CHANGED
|
@@ -53,11 +53,12 @@ const FORMAT_CHECK = 'oxfmt --check';
|
|
|
53
53
|
const LINT = 'oxlint --deny-warnings';
|
|
54
54
|
|
|
55
55
|
const FORMAT_SCRIPTS = {
|
|
56
|
-
fmt: 'oxfmt'
|
|
57
|
-
'fmt:check': FORMAT_CHECK
|
|
56
|
+
fmt: 'oxfmt'
|
|
58
57
|
};
|
|
59
58
|
|
|
60
59
|
const BUILD_DIR = 'build';
|
|
60
|
+
/** Holds agent worktrees, which are full copies of the repo. oxlint and oxfmt skip it only when the project's own .gitignore lists it. */
|
|
61
|
+
const AGENT_DIR = '.claude';
|
|
61
62
|
const BUILD_SCRIPT = `rm -rf ${BUILD_DIR}/ && tsc -p tsconfig.build.json`;
|
|
62
63
|
const OUT_DIR_REFERENCE_FILES = ['.gitignore', '.dockerignore', 'Dockerfile', '.circleci/config.yml'];
|
|
63
64
|
const REDUNDANT_UNDER_STRICT = new Set(['noImplicitAny', 'strictNullChecks']);
|
|
@@ -498,9 +499,10 @@ async function findOutDirReferences(dir, pkg, previous) {
|
|
|
498
499
|
/**
|
|
499
500
|
* @param {string} dir
|
|
500
501
|
* @param {Record<string, string>} scripts the project's scripts after the migration
|
|
501
|
-
* @
|
|
502
|
+
* @param {boolean} removedLint whether the migration removed the lint script
|
|
503
|
+
* @returns {Promise<string[]>} reminders to make sure CI checks formatting and does not call a removed script
|
|
502
504
|
*/
|
|
503
|
-
async function
|
|
505
|
+
async function ciReminders(dir, scripts, removedLint) {
|
|
504
506
|
const workflows = await readdir(path.join(dir, '.github/workflows')).catch(() => []);
|
|
505
507
|
const candidates = [
|
|
506
508
|
'.circleci/config.yml',
|
|
@@ -514,12 +516,24 @@ async function ciReminder(dir, scripts) {
|
|
|
514
516
|
const ciText = sources.filter((source) => source !== null).join('\n');
|
|
515
517
|
const covered = formatScripts.find((name) => new RegExp(`npm run ${name}(\\s|$)`, 'm').test(ciText));
|
|
516
518
|
if (configs.length === 0) {
|
|
517
|
-
return
|
|
519
|
+
return [
|
|
520
|
+
'Double check your CI: no CI config was found here. It should run a step that fails on unformatted code, such as "npx oxfmt --check".'
|
|
521
|
+
];
|
|
522
|
+
}
|
|
523
|
+
const reminders = [];
|
|
524
|
+
if (removedLint && /npm run lint(\s|$)/m.test(ciText)) {
|
|
525
|
+
reminders.push(`${configs.join(', ')} runs "npm run lint", which was removed. Change it to "npm run check".`);
|
|
518
526
|
}
|
|
519
527
|
if (covered) {
|
|
520
|
-
|
|
528
|
+
reminders.push(
|
|
529
|
+
`Double check CI: ${configs.join(', ')} runs "npm run ${covered}", which now includes the format check. Confirm that step fails the build on unformatted code.`
|
|
530
|
+
);
|
|
531
|
+
} else {
|
|
532
|
+
reminders.push(
|
|
533
|
+
`Double check CI: ${configs.join(', ')} does not appear to run a script that checks formatting. Add a step such as "${formatScripts.includes('check') ? 'npm run check' : 'npx oxfmt --check'}".`
|
|
534
|
+
);
|
|
521
535
|
}
|
|
522
|
-
return
|
|
536
|
+
return reminders;
|
|
523
537
|
}
|
|
524
538
|
|
|
525
539
|
/**
|
|
@@ -612,14 +626,14 @@ export async function createPlan(dir, style, options = {}) {
|
|
|
612
626
|
);
|
|
613
627
|
const { hasBuildConfig, previousOutDir } = await planTsconfigs(dir, style, plan, hasSentry);
|
|
614
628
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
}
|
|
629
|
+
const gitignore = (await readOptional(dir, '.gitignore')) ?? '';
|
|
630
|
+
const ignoredDirectories = new Set(gitignore.split('\n').map((line) => directoryOf(line.trim().replace(/^\//, ''))));
|
|
631
|
+
const toIgnore = [...(hasBuildConfig ? [BUILD_DIR] : []), AGENT_DIR].filter((name) => !ignoredDirectories.has(name));
|
|
632
|
+
if (toIgnore.length > 0) {
|
|
633
|
+
const separator = gitignore === '' || gitignore.endsWith('\n') ? '' : '\n';
|
|
634
|
+
const lines = toIgnore.map((name) => `${name}/\n`).join('');
|
|
635
|
+
plan.writes.push({ file: '.gitignore', contents: `${gitignore}${separator}${lines}` });
|
|
636
|
+
plan.files.push(`add ${toIgnore.map((name) => `${name}/`).join(' and ')} to .gitignore`);
|
|
623
637
|
}
|
|
624
638
|
if (previousOutDir !== null && previousOutDir !== BUILD_DIR) {
|
|
625
639
|
const references = await findOutDirReferences(dir, original, previousOutDir);
|
|
@@ -632,9 +646,22 @@ export async function createPlan(dir, style, options = {}) {
|
|
|
632
646
|
}
|
|
633
647
|
|
|
634
648
|
pkg.scripts ??= {};
|
|
649
|
+
const removedLint = typeof pkg.scripts.lint === 'string' && /\b(eslint|oxlint)\b/.test(pkg.scripts.lint);
|
|
650
|
+
if (removedLint) {
|
|
651
|
+
plan.scripts.push(`remove lint ("${pkg.scripts.lint}"): check runs the linter`);
|
|
652
|
+
delete pkg.scripts.lint;
|
|
653
|
+
}
|
|
635
654
|
for (const [name, command] of Object.entries(pkg.scripts)) {
|
|
636
655
|
let steps = command.split('&&').map((step) => step.trim());
|
|
637
|
-
steps = steps.map((step) =>
|
|
656
|
+
steps = steps.map((step) => {
|
|
657
|
+
if (/^(eslint( \.)?|oxlint)$/.test(step)) {
|
|
658
|
+
return LINT;
|
|
659
|
+
}
|
|
660
|
+
if (removedLint && step === 'npm run lint') {
|
|
661
|
+
return name === 'check' ? LINT : 'npm run check';
|
|
662
|
+
}
|
|
663
|
+
return step;
|
|
664
|
+
});
|
|
638
665
|
if (name === 'check' && !/\boxfmt\b|\b(fmt|format):check\b/.test(command)) {
|
|
639
666
|
const lintStep = steps.findIndex((step) => /^oxlint\b/.test(step));
|
|
640
667
|
steps = steps.toSpliced(lintStep === -1 ? steps.length : lintStep + 1, 0, FORMAT_CHECK);
|
|
@@ -657,6 +684,7 @@ export async function createPlan(dir, style, options = {}) {
|
|
|
657
684
|
const wantedScripts = {
|
|
658
685
|
...FORMAT_SCRIPTS,
|
|
659
686
|
...(style !== 'js' && { check: `tsc && ${LINT} && ${FORMAT_CHECK}` }),
|
|
687
|
+
...(style === 'js' && removedLint && { check: `${LINT} && ${FORMAT_CHECK}` }),
|
|
660
688
|
...(style !== 'js' && hasBuildConfig && { build: BUILD_SCRIPT })
|
|
661
689
|
};
|
|
662
690
|
const added = [];
|
|
@@ -674,7 +702,7 @@ export async function createPlan(dir, style, options = {}) {
|
|
|
674
702
|
plan.packageJson = serialize(packageSource, pkg);
|
|
675
703
|
}
|
|
676
704
|
if (hasChanges(plan)) {
|
|
677
|
-
plan.attention.push(await
|
|
705
|
+
plan.attention.push(...(await ciReminders(dir, pkg.scripts, removedLint)));
|
|
678
706
|
}
|
|
679
707
|
return plan;
|
|
680
708
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@particle/tooling",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Shared oxlint, oxfmt and TypeScript configuration for Particle projects",
|
|
5
5
|
"homepage": "https://github.com/particle-iot-inc/particle-tooling",
|
|
6
6
|
"bugs": {
|
|
@@ -46,10 +46,8 @@
|
|
|
46
46
|
"access": "restricted"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
|
-
"check": "
|
|
50
|
-
"lint": "oxlint --deny-warnings",
|
|
49
|
+
"check": "oxlint --deny-warnings && oxfmt --check",
|
|
51
50
|
"fmt": "oxfmt",
|
|
52
|
-
"fmt:check": "oxfmt --check",
|
|
53
51
|
"test": "vitest run"
|
|
54
52
|
},
|
|
55
53
|
"devDependencies": {
|