@particle/tooling 0.1.3 → 0.1.4
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 +1 -1
- package/lib/migrate.js +35 -9
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ What it does, depending on what it finds:
|
|
|
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
27
|
- **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:**
|
|
28
|
+
- **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
29
|
- **CI:** looks at `.circleci/config.yml` and `.github/workflows` and reminds you to confirm that CI runs a step that checks formatting.
|
|
30
30
|
- **Install:** runs `npm install` at the end.
|
|
31
31
|
|
package/lib/migrate.js
CHANGED
|
@@ -53,8 +53,7 @@ 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';
|
|
@@ -498,9 +497,10 @@ async function findOutDirReferences(dir, pkg, previous) {
|
|
|
498
497
|
/**
|
|
499
498
|
* @param {string} dir
|
|
500
499
|
* @param {Record<string, string>} scripts the project's scripts after the migration
|
|
501
|
-
* @
|
|
500
|
+
* @param {boolean} removedLint whether the migration removed the lint script
|
|
501
|
+
* @returns {Promise<string[]>} reminders to make sure CI checks formatting and does not call a removed script
|
|
502
502
|
*/
|
|
503
|
-
async function
|
|
503
|
+
async function ciReminders(dir, scripts, removedLint) {
|
|
504
504
|
const workflows = await readdir(path.join(dir, '.github/workflows')).catch(() => []);
|
|
505
505
|
const candidates = [
|
|
506
506
|
'.circleci/config.yml',
|
|
@@ -514,12 +514,24 @@ async function ciReminder(dir, scripts) {
|
|
|
514
514
|
const ciText = sources.filter((source) => source !== null).join('\n');
|
|
515
515
|
const covered = formatScripts.find((name) => new RegExp(`npm run ${name}(\\s|$)`, 'm').test(ciText));
|
|
516
516
|
if (configs.length === 0) {
|
|
517
|
-
return
|
|
517
|
+
return [
|
|
518
|
+
'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".'
|
|
519
|
+
];
|
|
520
|
+
}
|
|
521
|
+
const reminders = [];
|
|
522
|
+
if (removedLint && /npm run lint(\s|$)/m.test(ciText)) {
|
|
523
|
+
reminders.push(`${configs.join(', ')} runs "npm run lint", which was removed. Change it to "npm run check".`);
|
|
518
524
|
}
|
|
519
525
|
if (covered) {
|
|
520
|
-
|
|
526
|
+
reminders.push(
|
|
527
|
+
`Double check CI: ${configs.join(', ')} runs "npm run ${covered}", which now includes the format check. Confirm that step fails the build on unformatted code.`
|
|
528
|
+
);
|
|
529
|
+
} else {
|
|
530
|
+
reminders.push(
|
|
531
|
+
`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'}".`
|
|
532
|
+
);
|
|
521
533
|
}
|
|
522
|
-
return
|
|
534
|
+
return reminders;
|
|
523
535
|
}
|
|
524
536
|
|
|
525
537
|
/**
|
|
@@ -632,9 +644,22 @@ export async function createPlan(dir, style, options = {}) {
|
|
|
632
644
|
}
|
|
633
645
|
|
|
634
646
|
pkg.scripts ??= {};
|
|
647
|
+
const removedLint = typeof pkg.scripts.lint === 'string' && /\b(eslint|oxlint)\b/.test(pkg.scripts.lint);
|
|
648
|
+
if (removedLint) {
|
|
649
|
+
plan.scripts.push(`remove lint ("${pkg.scripts.lint}"): check runs the linter`);
|
|
650
|
+
delete pkg.scripts.lint;
|
|
651
|
+
}
|
|
635
652
|
for (const [name, command] of Object.entries(pkg.scripts)) {
|
|
636
653
|
let steps = command.split('&&').map((step) => step.trim());
|
|
637
|
-
steps = steps.map((step) =>
|
|
654
|
+
steps = steps.map((step) => {
|
|
655
|
+
if (/^(eslint( \.)?|oxlint)$/.test(step)) {
|
|
656
|
+
return LINT;
|
|
657
|
+
}
|
|
658
|
+
if (removedLint && step === 'npm run lint') {
|
|
659
|
+
return name === 'check' ? LINT : 'npm run check';
|
|
660
|
+
}
|
|
661
|
+
return step;
|
|
662
|
+
});
|
|
638
663
|
if (name === 'check' && !/\boxfmt\b|\b(fmt|format):check\b/.test(command)) {
|
|
639
664
|
const lintStep = steps.findIndex((step) => /^oxlint\b/.test(step));
|
|
640
665
|
steps = steps.toSpliced(lintStep === -1 ? steps.length : lintStep + 1, 0, FORMAT_CHECK);
|
|
@@ -657,6 +682,7 @@ export async function createPlan(dir, style, options = {}) {
|
|
|
657
682
|
const wantedScripts = {
|
|
658
683
|
...FORMAT_SCRIPTS,
|
|
659
684
|
...(style !== 'js' && { check: `tsc && ${LINT} && ${FORMAT_CHECK}` }),
|
|
685
|
+
...(style === 'js' && removedLint && { check: `${LINT} && ${FORMAT_CHECK}` }),
|
|
660
686
|
...(style !== 'js' && hasBuildConfig && { build: BUILD_SCRIPT })
|
|
661
687
|
};
|
|
662
688
|
const added = [];
|
|
@@ -674,7 +700,7 @@ export async function createPlan(dir, style, options = {}) {
|
|
|
674
700
|
plan.packageJson = serialize(packageSource, pkg);
|
|
675
701
|
}
|
|
676
702
|
if (hasChanges(plan)) {
|
|
677
|
-
plan.attention.push(await
|
|
703
|
+
plan.attention.push(...(await ciReminders(dir, pkg.scripts, removedLint)));
|
|
678
704
|
}
|
|
679
705
|
return plan;
|
|
680
706
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@particle/tooling",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
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": {
|