@particle/tooling 0.1.2 → 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 CHANGED
@@ -20,12 +20,12 @@ It asks what kind of project this is (or takes `--style`), prints everything it
20
20
 
21
21
  What it does, depending on what it finds:
22
22
 
23
- - **Dependencies:** removes ESLint and its configs and plugins, adds `@particle/tooling` (which installs `oxlint` and `oxfmt` as peers), and moves `typescript` to version 7. TypeScript projects also get `oxlint-tsgolint`, which runs the type-aware lint rules.
23
+ - **Dependencies:** removes ESLint and its configs and plugins, adds `@particle/tooling` (which installs `oxlint`, `oxfmt` and `oxlint-tsgolint` as peers), and moves `typescript` to version 7.
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
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:** replaces plain `eslint` steps with `oxlint --deny-warnings` (so a warning fails the check, in CI too), adds `oxfmt --check` to an existing `check` script, and adds `fmt` and `fmt:check` where they are missing. TypeScript projects without them also get `check` (`tsc && oxlint --deny-warnings && oxfmt --check`) and `build`. It does not add a `lint` script.
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
 
@@ -55,7 +55,7 @@ The config files are TypeScript, which requires Node 22.23.4 or later.
55
55
  | `@particle/tooling/oxlint` | JavaScript projects |
56
56
  | `@particle/tooling/oxlint-typescript` | TypeScript projects: the same rules plus the TypeScript rules, with type-aware linting on |
57
57
 
58
- Type-aware rules such as `no-floating-promises` need the `oxlint-tsgolint` package and a `tsconfig.json`. Only the typed rules named in `oxlint-typescript.js` are enforced. The other typed rules in the enabled categories are switched off there, and a project can turn one on in its own config.
58
+ Type-aware rules such as `no-floating-promises` run through `oxlint-tsgolint`, which is installed as a peer dependency, and need a `tsconfig.json`. Only the typed rules named in `oxlint-typescript.js` are enforced. The other typed rules in the enabled categories are switched off there, and a project can turn one on in its own config.
59
59
 
60
60
  ## Overriding
61
61
 
package/lib/migrate.js CHANGED
@@ -19,7 +19,7 @@ export const STYLES = {
19
19
  };
20
20
 
21
21
  const LEGACY_PACKAGES =
22
- /^(eslint|eslint-config-.+|eslint-plugin-.+|@eslint\/.+|typescript-eslint|@typescript-eslint\/.+|oxlint|oxfmt)$/;
22
+ /^(eslint|eslint-config-.+|eslint-plugin-.+|@eslint\/.+|typescript-eslint|@typescript-eslint\/.+|oxlint|oxfmt|oxlint-tsgolint)$/;
23
23
 
24
24
  const LEGACY_FILES = [
25
25
  'eslint.config.js',
@@ -39,8 +39,6 @@ const LEGACY_FILES = [
39
39
  '.oxfmtrc.jsonc'
40
40
  ];
41
41
 
42
- const TYPE_AWARE_LINTER = 'oxlint-tsgolint';
43
-
44
42
  /**
45
43
  * @param {string} style
46
44
  * @returns {Record<string, string>} lint and format config contents by file name. TypeScript styles get the type-aware lint config.
@@ -55,8 +53,7 @@ const FORMAT_CHECK = 'oxfmt --check';
55
53
  const LINT = 'oxlint --deny-warnings';
56
54
 
57
55
  const FORMAT_SCRIPTS = {
58
- fmt: 'oxfmt',
59
- 'fmt:check': FORMAT_CHECK
56
+ fmt: 'oxfmt'
60
57
  };
61
58
 
62
59
  const BUILD_DIR = 'build';
@@ -500,9 +497,10 @@ async function findOutDirReferences(dir, pkg, previous) {
500
497
  /**
501
498
  * @param {string} dir
502
499
  * @param {Record<string, string>} scripts the project's scripts after the migration
503
- * @returns {Promise<string>} a reminder to make sure CI checks formatting, naming the CI config and script when it can
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
504
502
  */
505
- async function ciReminder(dir, scripts) {
503
+ async function ciReminders(dir, scripts, removedLint) {
506
504
  const workflows = await readdir(path.join(dir, '.github/workflows')).catch(() => []);
507
505
  const candidates = [
508
506
  '.circleci/config.yml',
@@ -516,12 +514,24 @@ async function ciReminder(dir, scripts) {
516
514
  const ciText = sources.filter((source) => source !== null).join('\n');
517
515
  const covered = formatScripts.find((name) => new RegExp(`npm run ${name}(\\s|$)`, 'm').test(ciText));
518
516
  if (configs.length === 0) {
519
- return 'Double check your CI: no CI config was found here. It should run a step that fails on unformatted code, such as "npm run fmt:check".';
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".`);
520
524
  }
521
525
  if (covered) {
522
- return `Double check CI: ${configs.join(', ')} runs "npm run ${covered}", which now includes the format check. Confirm that step fails the build on unformatted code.`;
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
+ );
523
533
  }
524
- return `Double check CI: ${configs.join(', ')} does not appear to run a script that checks formatting. Add a step such as "npm run ${formatScripts.includes('check') ? 'check' : 'fmt:check'}".`;
534
+ return reminders;
525
535
  }
526
536
 
527
537
  /**
@@ -578,16 +588,11 @@ export async function createPlan(dir, style, options = {}) {
578
588
  pkg.devDependencies = { ...pkg.devDependencies, typescript: typescriptSpec };
579
589
  plan.dependencies.push(`add typescript ${typescriptSpec}`);
580
590
  }
581
- if (style !== 'js' && pkg.devDependencies?.[TYPE_AWARE_LINTER] === undefined) {
582
- const spec = toolingPackage.peerDependencies[TYPE_AWARE_LINTER];
583
- pkg.devDependencies = { ...pkg.devDependencies, [TYPE_AWARE_LINTER]: spec };
584
- plan.dependencies.push(
585
- `add ${TYPE_AWARE_LINTER} ${spec} (runs the type-aware lint rules, such as no-floating-promises)`
586
- );
587
- }
588
591
  if (pkg.devDependencies?.[TOOLING] !== toolingSpec) {
589
592
  pkg.devDependencies = { ...pkg.devDependencies, [TOOLING]: toolingSpec };
590
- plan.dependencies.push(`add ${TOOLING} ${toolingSpec} (installs oxlint and oxfmt as peer dependencies)`);
593
+ plan.dependencies.push(
594
+ `add ${TOOLING} ${toolingSpec} (installs oxlint, oxfmt and oxlint-tsgolint as peer dependencies)`
595
+ );
591
596
  }
592
597
  if (pkg.devDependencies) {
593
598
  pkg.devDependencies = Object.fromEntries(
@@ -639,9 +644,22 @@ export async function createPlan(dir, style, options = {}) {
639
644
  }
640
645
 
641
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
+ }
642
652
  for (const [name, command] of Object.entries(pkg.scripts)) {
643
653
  let steps = command.split('&&').map((step) => step.trim());
644
- steps = steps.map((step) => (/^(eslint( \.)?|oxlint)$/.test(step) ? LINT : 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
+ });
645
663
  if (name === 'check' && !/\boxfmt\b|\b(fmt|format):check\b/.test(command)) {
646
664
  const lintStep = steps.findIndex((step) => /^oxlint\b/.test(step));
647
665
  steps = steps.toSpliced(lintStep === -1 ? steps.length : lintStep + 1, 0, FORMAT_CHECK);
@@ -664,6 +682,7 @@ export async function createPlan(dir, style, options = {}) {
664
682
  const wantedScripts = {
665
683
  ...FORMAT_SCRIPTS,
666
684
  ...(style !== 'js' && { check: `tsc && ${LINT} && ${FORMAT_CHECK}` }),
685
+ ...(style === 'js' && removedLint && { check: `${LINT} && ${FORMAT_CHECK}` }),
667
686
  ...(style !== 'js' && hasBuildConfig && { build: BUILD_SCRIPT })
668
687
  };
669
688
  const added = [];
@@ -681,7 +700,7 @@ export async function createPlan(dir, style, options = {}) {
681
700
  plan.packageJson = serialize(packageSource, pkg);
682
701
  }
683
702
  if (hasChanges(plan)) {
684
- plan.attention.push(await ciReminder(dir, pkg.scripts));
703
+ plan.attention.push(...(await ciReminders(dir, pkg.scripts, removedLint)));
685
704
  }
686
705
  return plan;
687
706
  }
package/oxfmt.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /** Types for `oxfmt.js`. */
1
2
  import type { OxfmtConfig } from 'oxfmt';
2
3
 
3
4
  declare const config: OxfmtConfig;
package/oxfmt.js CHANGED
@@ -1,3 +1,4 @@
1
+ /** The oxfmt config published as `@particle/tooling/oxfmt`. */
1
2
  import { defineConfig } from 'oxfmt';
2
3
 
3
4
  export default defineConfig({
@@ -1,3 +1,4 @@
1
+ /** Types for `oxlint-typescript.js`. */
1
2
  import type { OxlintConfig } from 'oxlint';
2
3
 
3
4
  declare const config: OxlintConfig;
@@ -1,3 +1,4 @@
1
+ /** The oxlint config published as `@particle/tooling/oxlint-typescript`, for TypeScript projects. */
1
2
  import { defineConfig } from 'oxlint';
2
3
 
3
4
  import base from './oxlint.js';
package/oxlint.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /** Types for `oxlint.js`. */
1
2
  import type { OxlintConfig } from 'oxlint';
2
3
 
3
4
  declare const config: OxlintConfig;
package/oxlint.js CHANGED
@@ -1,3 +1,4 @@
1
+ /** The oxlint config published as `@particle/tooling/oxlint`, for JavaScript projects. */
1
2
  import { defineConfig } from 'oxlint';
2
3
 
3
4
  const TEST_FILES = ['**/*.{spec,test,e2e,unit,integration}.{mjs,cjs,js,ts}', '**/test/**/*.{mjs,cjs,js,ts}'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@particle/tooling",
3
- "version": "0.1.2",
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": "npm run lint && npm run fmt: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": {
@@ -68,9 +66,6 @@
68
66
  "peerDependenciesMeta": {
69
67
  "typescript": {
70
68
  "optional": true
71
- },
72
- "oxlint-tsgolint": {
73
- "optional": true
74
69
  }
75
70
  },
76
71
  "engines": {