tw-migrate 0.7.0 → 0.8.0

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/dist/bin.js CHANGED
@@ -4,7 +4,7 @@ import { styleText } from "node:util";
4
4
  //#region src/bin.ts
5
5
  const { version } = {
6
6
  name: "tw-migrate",
7
- version: "0.7.0",
7
+ version: "0.8.0",
8
8
  description: "Preview and migrate React, Vue, and HTML CSS to Tailwind utilities",
9
9
  keywords: [
10
10
  "codemod",
@@ -80,7 +80,7 @@ const { version } = {
80
80
  "x86_64-pc-windows-msvc"
81
81
  ]
82
82
  },
83
- engines: { "node": ">=22.23.2" },
83
+ engines: { "node": ">=22.23.3" },
84
84
  packageManager: "pnpm@11.24.0"
85
85
  };
86
86
  const usage = "Usage: tw-migrate [style-file] [options]";
package/dist/index.js CHANGED
@@ -284,6 +284,16 @@ async function rejectSymlinkTarget(path, root) {
284
284
  if (current === root) break;
285
285
  }
286
286
  }
287
+ async function* readInBatches(paths) {
288
+ for (let offset = 0; offset < paths.length; offset += 32) {
289
+ const batch = paths.slice(offset, offset + 32);
290
+ const reads = await Promise.allSettled(batch.map((path) => readFile(path, "utf8")));
291
+ for (const [index, path] of batch.entries()) yield {
292
+ path,
293
+ read: reads[index]
294
+ };
295
+ }
296
+ }
287
297
  async function snapshotFile(snapshots, path) {
288
298
  return recordSnapshot(snapshots, path, await readFile(path, "utf8"));
289
299
  }
@@ -2814,16 +2824,15 @@ async function preparePackageVue({ packageRoot, styleCompilers, sourceFiles, sty
2814
2824
  //#endregion
2815
2825
  //#region src/util/write.ts
2816
2826
  async function verifySnapshots(snapshots) {
2817
- const entries = [...snapshots].sort(([left], [right]) => left.localeCompare(right));
2818
- const reads = await Promise.allSettled(entries.map(([path]) => readFile(path, "utf8")));
2819
- for (const [index, [path, before]] of entries.entries()) {
2820
- const read = reads[index];
2827
+ const expected = new Map(snapshots);
2828
+ const paths = [...expected.keys()].sort((left, right) => left.localeCompare(right));
2829
+ for await (const { path, read } of readInBatches(paths)) {
2821
2830
  if (read.status === "rejected") {
2822
2831
  const error = read.reason;
2823
2832
  const detail = errorCode(error) ?? errorMessage(error);
2824
2833
  throw new Error(`Source changed after planning: ${path} (${detail})`);
2825
2834
  }
2826
- if (read.value !== before) throw new Error(`Source changed after planning: ${path}`);
2835
+ if (read.value !== expected.get(path)) throw new Error(`Source changed after planning: ${path}`);
2827
2836
  }
2828
2837
  }
2829
2838
  async function writeChanges(changes, deletions) {
@@ -2911,28 +2920,30 @@ async function migrate(options = {}) {
2911
2920
  throw new Error(`Found leftover tw-migrate files from an interrupted run:\n${listed}\nRestore each ".<name>.tw-migrate-backup-*" file by renaming it back to "<name>", delete any remaining ".<name>.tw-migrate-*" staging files, then re-run.`);
2912
2921
  }
2913
2922
  const snapshots = /* @__PURE__ */ new Map();
2914
- const stylePaths = scope.scannedPaths.filter(isStylesheetPath);
2915
- const sourcePaths = scope.scannedPaths.filter((path) => SOURCE_EXTENSIONS.has(extname(path)));
2916
- const [styleSources, sourceCandidates] = await Promise.all([
2917
- Promise.all(stylePaths.map(async (path) => [path, await snapshotFile(snapshots, path)])).then((entries) => new Map(entries)),
2918
- Promise.all(sourcePaths.map(async (path) => {
2919
- const source = await readFile(path, "utf8");
2920
- const mayReferenceModule = extname(path) !== ".html" || (() => {
2921
- try {
2922
- return parseHtmlSource(path, source).links.length > 0;
2923
- } catch {
2924
- return /<link\b/i.test(source);
2925
- }
2926
- })();
2927
- if (!scope.targetable.has(path) && !mayReferenceModule) return void 0;
2928
- return {
2929
- path,
2930
- source: recordSnapshot(snapshots, path, source)
2931
- };
2932
- })),
2933
- ...selectedPackages.map((packageRoot) => snapshotFile(snapshots, join(packageRoot, "package.json")))
2934
- ]);
2935
- const sourceFiles = sourceCandidates.flatMap((file) => file ? [file] : []);
2923
+ const styleSources = /* @__PURE__ */ new Map();
2924
+ const sourceFiles = [];
2925
+ const inputPaths = [...scope.scannedPaths.filter((path) => isStylesheetPath(path) || SOURCE_EXTENSIONS.has(extname(path))), ...selectedPackages.map((packageRoot) => join(packageRoot, "package.json"))];
2926
+ for await (const { path, read } of readInBatches(inputPaths)) {
2927
+ if (read.status === "rejected") throw read.reason;
2928
+ const source = read.value;
2929
+ if (!SOURCE_EXTENSIONS.has(extname(path))) {
2930
+ recordSnapshot(snapshots, path, source);
2931
+ if (isStylesheetPath(path)) styleSources.set(path, source);
2932
+ continue;
2933
+ }
2934
+ const mayReferenceModule = extname(path) !== ".html" || (() => {
2935
+ try {
2936
+ return parseHtmlSource(path, source).links.length > 0;
2937
+ } catch {
2938
+ return /<link\b/i.test(source);
2939
+ }
2940
+ })();
2941
+ if (!scope.targetable.has(path) && !mayReferenceModule) continue;
2942
+ sourceFiles.push({
2943
+ path,
2944
+ source: recordSnapshot(snapshots, path, source)
2945
+ });
2946
+ }
2936
2947
  if (explicitStyle && isStylesheetPath(explicitStyle) && !styleSources.has(explicitStyle)) styleSources.set(explicitStyle, await snapshotFile(snapshots, explicitStyle));
2937
2948
  if (configuredEntry && !styleSources.has(configuredEntry)) styleSources.set(configuredEntry, await snapshotFile(snapshots, configuredEntry));
2938
2949
  const vueStyleRanges = /* @__PURE__ */ new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tw-migrate",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Preview and migrate React, Vue, and HTML CSS to Tailwind utilities",
5
5
  "keywords": [
6
6
  "codemod",
@@ -66,11 +66,11 @@
66
66
  "vue": "catalog:"
67
67
  },
68
68
  "optionalDependencies": {
69
- "tw-migrate-darwin-arm64": "0.7.0",
70
- "tw-migrate-darwin-x64": "0.7.0",
71
- "tw-migrate-linux-arm64-gnu": "0.7.0",
72
- "tw-migrate-linux-x64-gnu": "0.7.0",
73
- "tw-migrate-win32-x64-msvc": "0.7.0"
69
+ "tw-migrate-darwin-arm64": "0.8.0",
70
+ "tw-migrate-darwin-x64": "0.8.0",
71
+ "tw-migrate-linux-arm64-gnu": "0.8.0",
72
+ "tw-migrate-linux-x64-gnu": "0.8.0",
73
+ "tw-migrate-win32-x64-msvc": "0.8.0"
74
74
  },
75
75
  "napi": {
76
76
  "binaryName": "tw-migrate",
@@ -83,7 +83,7 @@
83
83
  ]
84
84
  },
85
85
  "engines": {
86
- "node": ">=22.23.2"
86
+ "node": ">=22.23.3"
87
87
  },
88
88
  "packageManager": "pnpm@11.24.0"
89
89
  }