@particle/tooling 0.1.4 → 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,9 +21,10 @@ 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
+ - **`.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
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.
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';
@@ -57,6 +57,8 @@ const FORMAT_SCRIPTS = {
57
57
  };
58
58
 
59
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';
60
62
  const BUILD_SCRIPT = `rm -rf ${BUILD_DIR}/ && tsc -p tsconfig.build.json`;
61
63
  const OUT_DIR_REFERENCE_FILES = ['.gitignore', '.dockerignore', 'Dockerfile', '.circleci/config.yml'];
62
64
  const REDUNDANT_UNDER_STRICT = new Set(['noImplicitAny', 'strictNullChecks']);
@@ -600,6 +602,9 @@ export async function createPlan(dir, style, options = {}) {
600
602
  );
601
603
  }
602
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
+
603
608
  const legacyFiles = LEGACY_FILES.filter((file) => existsSync(path.join(dir, file)));
604
609
  const tracked = await Promise.all(legacyFiles.map((file) => isTracked(dir, file)));
605
610
  for (const [index, file] of legacyFiles.entries()) {
@@ -609,13 +614,24 @@ export async function createPlan(dir, style, options = {}) {
609
614
  const legacyLintConfigs = legacyFiles.filter((file) => file !== '.eslintignore' && !file.startsWith('.oxfmtrc'));
610
615
  if (legacyLintConfigs.length > 0) {
611
616
  plan.attention.push(
612
- `${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}.`
613
618
  );
614
619
  }
615
- for (const [file, contents] of Object.entries(lintFiles(style))) {
616
- 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) {
617
626
  plan.writes.push({ file, contents });
618
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
+ );
619
635
  }
620
636
  }
621
637
 
@@ -624,14 +640,14 @@ export async function createPlan(dir, style, options = {}) {
624
640
  );
625
641
  const { hasBuildConfig, previousOutDir } = await planTsconfigs(dir, style, plan, hasSentry);
626
642
 
627
- if (hasBuildConfig) {
628
- const gitignore = (await readOptional(dir, '.gitignore')) ?? '';
629
- const ignored = gitignore.split('\n').some((line) => directoryOf(line.trim().replace(/^\//, '')) === BUILD_DIR);
630
- if (!ignored) {
631
- const separator = gitignore === '' || gitignore.endsWith('\n') ? '' : '\n';
632
- plan.writes.push({ file: '.gitignore', contents: `${gitignore}${separator}${BUILD_DIR}/\n` });
633
- plan.files.push(`add ${BUILD_DIR}/ to .gitignore`);
634
- }
643
+ const gitignore = (await readOptional(dir, '.gitignore')) ?? '';
644
+ const ignoredDirectories = new Set(gitignore.split('\n').map((line) => directoryOf(line.trim().replace(/^\//, ''))));
645
+ const toIgnore = [...(hasBuildConfig ? [BUILD_DIR] : []), AGENT_DIR].filter((name) => !ignoredDirectories.has(name));
646
+ if (toIgnore.length > 0) {
647
+ const separator = gitignore === '' || gitignore.endsWith('\n') ? '' : '\n';
648
+ const lines = toIgnore.map((name) => `${name}/\n`).join('');
649
+ plan.writes.push({ file: '.gitignore', contents: `${gitignore}${separator}${lines}` });
650
+ plan.files.push(`add ${toIgnore.map((name) => `${name}/`).join(' and ')} to .gitignore`);
635
651
  }
636
652
  if (previousOutDir !== null && previousOutDir !== BUILD_DIR) {
637
653
  const references = await findOutDirReferences(dir, original, previousOutDir);
@@ -720,7 +736,7 @@ function lineColor(line) {
720
736
  if (/^(remove|delete|removes:|drops) /.test(text)) {
721
737
  return 'red';
722
738
  }
723
- if (/^(rewrite|changes:|moves:) /.test(text) || text.includes(' -> ')) {
739
+ if (/^(rewrite|rename|changes:|moves:) /.test(text) || text.includes(' -> ')) {
724
740
  return 'yellow';
725
741
  }
726
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.4",
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": {