@particle/tooling 0.1.5 → 0.1.6

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
@@ -21,7 +21,7 @@ It asks what kind of project this is (or takes `--style`), prints everything it
21
21
  What it does, depending on what it finds:
22
22
 
23
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
- - **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`.
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. In a package that is not an ES module (no `"type": "module"`), the files are `.mts`, and existing `.ts` ones are renamed: Node only loads a `.ts` config as an ES module in an ES module package, and otherwise warns or fails. 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
  - **`.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.
package/lib/migrate.js CHANGED
@@ -41,11 +41,11 @@ const LEGACY_FILES = [
41
41
 
42
42
  /**
43
43
  * @param {string} style
44
- * @returns {Record<string, string>} lint and format config contents by file name. TypeScript styles get the type-aware lint config.
44
+ * @returns {Record<string, string>} lint and format config contents by file name without its extension. TypeScript styles get the type-aware lint config.
45
45
  */
46
- const lintFiles = (style) => ({
47
- 'oxlint.config.ts': `export { default } from '${TOOLING}/${style === 'js' ? 'oxlint' : 'oxlint-typescript'}';\n`,
48
- 'oxfmt.config.ts': `export { default } from '${TOOLING}/oxfmt';\n`
46
+ const lintConfigs = (style) => ({
47
+ 'oxlint.config': `export { default } from '${TOOLING}/${style === 'js' ? 'oxlint' : 'oxlint-typescript'}';\n`,
48
+ 'oxfmt.config': `export { default } from '${TOOLING}/oxfmt';\n`
49
49
  });
50
50
 
51
51
  const FORMAT_CHECK = 'oxfmt --check';
@@ -602,6 +602,9 @@ export async function createPlan(dir, style, options = {}) {
602
602
  );
603
603
  }
604
604
 
605
+ // The configs use ES module syntax. Node only reads a .ts file that way in a package with "type": "module".
606
+ const configExtension = original.type === 'module' ? 'ts' : 'mts';
607
+
605
608
  const legacyFiles = LEGACY_FILES.filter((file) => existsSync(path.join(dir, file)));
606
609
  const tracked = await Promise.all(legacyFiles.map((file) => isTracked(dir, file)));
607
610
  for (const [index, file] of legacyFiles.entries()) {
@@ -611,13 +614,24 @@ export async function createPlan(dir, style, options = {}) {
611
614
  const legacyLintConfigs = legacyFiles.filter((file) => file !== '.eslintignore' && !file.startsWith('.oxfmtrc'));
612
615
  if (legacyLintConfigs.length > 0) {
613
616
  plan.attention.push(
614
- `${legacyLintConfigs.join(', ')}: project-specific rules and ignores are not carried over, and the files are deleted. Save anything you still need before applying, then re-add it in oxlint.config.ts.`
617
+ `${legacyLintConfigs.join(', ')}: project-specific rules and ignores are not carried over, and the files are deleted. Save anything you still need before applying, then re-add it in oxlint.config.${configExtension}.`
615
618
  );
616
619
  }
617
- for (const [file, contents] of Object.entries(lintFiles(style))) {
618
- if (!existsSync(path.join(dir, file))) {
620
+ for (const [name, contents] of Object.entries(lintConfigs(style))) {
621
+ const file = `${name}.${configExtension}`;
622
+ const existing = ['ts', 'mts']
623
+ .map((extension) => `${name}.${extension}`)
624
+ .find((candidate) => existsSync(path.join(dir, candidate)));
625
+ if (existing === undefined) {
619
626
  plan.writes.push({ file, contents });
620
627
  plan.files.push(`create ${file}`);
628
+ } else if (existing !== file && configExtension === 'mts') {
629
+ // oxlint-disable-next-line no-await-in-loop
630
+ plan.writes.push({ file, contents: await readFile(path.join(dir, existing), 'utf8') });
631
+ plan.deletes.push(existing);
632
+ plan.files.push(
633
+ `rename ${existing} to ${file} (this package is not an ES module, so Node needs the .mts extension to load it)`
634
+ );
621
635
  }
622
636
  }
623
637
 
@@ -722,7 +736,7 @@ function lineColor(line) {
722
736
  if (/^(remove|delete|removes:|drops) /.test(text)) {
723
737
  return 'red';
724
738
  }
725
- if (/^(rewrite|changes:|moves:) /.test(text) || text.includes(' -> ')) {
739
+ if (/^(rewrite|rename|changes:|moves:) /.test(text) || text.includes(' -> ')) {
726
740
  return 'yellow';
727
741
  }
728
742
  if (/^(add|create|adds:) /.test(text)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@particle/tooling",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
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": {