@brynlabs/fusion-ui-codemod 0.0.0 → 1.0.0-alpha.209

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
@@ -40,5 +40,6 @@ The paths default to the current directory; `node_modules`, `.next`, `dist`, `bu
40
40
  | Codemod | |
41
41
  | --- | --- |
42
42
  | `data-table-fixed-height` | `DataTableCollection` scrolls with the page by default: adds `fixedHeight` where `useWindowScroll` was missing or `false`, removes `useWindowScroll` where it was set, negates expressions. Reports `useWindowScroll` in objects |
43
+ | `data-table-collection` | Replaces the deprecated `DataTable` by a `Tile` with a `CollectionHeader` (`{...table.header}`, search, filters, `buttons`, `modalText.filterView`) and a `DataTableCollection fixedHeight` (the other props, `modalText.errorMessages` and the columns texts). Reports tables whose props come from other spreads or expressions, `storageId` (visible columns now stored by the hook's `storageId`) and references of `DataTable` / `DataTableProps` outside of JSX |
43
44
 
44
45
  `npx @brynlabs/fusion-ui-codemod list` shows the fusion-ui version of every codemod.
@@ -0,0 +1,7 @@
1
+ [
2
+ {
3
+ "name": "data-table-fixed-height",
4
+ "description": "DataTableCollection: replaces useWindowScroll by fixedHeight, the table scrolls with the page by default",
5
+ "version": "1.0.0-alpha.208"
6
+ }
7
+ ]
package/lib/git.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ const fs = require("node:fs");
1
2
  const path = require("node:path");
2
3
  const {execFileSync} = require("node:child_process");
3
4
 
@@ -30,4 +31,26 @@ const changedFiles = repositoryRoot =>
30
31
  // "XY path" or "XY old -> new"
31
32
  .map(line => line.slice(3).split(" -> ").pop().replace(/^"|"$/g, ""));
32
33
 
33
- module.exports = {root, showHead, changedFiles};
34
+ /**
35
+ * The files below `paths` that git doesn't ignore (committed or not), relative to `cwd`; `null`
36
+ * outside of a repository. Git applies the ignore files itself (nested ones, negations like
37
+ * `!.yarn/patches`, `.git/info/exclude`, the global excludes file)
38
+ */
39
+ const listFiles = (cwd, paths) => {
40
+ if (root(cwd) === null) return null;
41
+ const output = run(cwd, [
42
+ "ls-files",
43
+ "-z",
44
+ "--cached",
45
+ "--others",
46
+ "--exclude-standard",
47
+ "--",
48
+ ...paths,
49
+ ]);
50
+ // Unmerged files are listed once per stage, deleted ones are still in the index
51
+ return [...new Set(output.split("\0").filter(Boolean))].filter(file =>
52
+ fs.existsSync(path.join(cwd, file)),
53
+ );
54
+ };
55
+
56
+ module.exports = {root, showHead, changedFiles, listFiles};
package/lib/registry.cjs CHANGED
@@ -1,71 +1,18 @@
1
1
  const fs = require("node:fs");
2
2
  const path = require("node:path");
3
- const {execFileSync} = require("node:child_process");
4
- const codemods = require("./codemods.cjs");
5
-
6
- const PACKAGE_DIR = path.join(__dirname, "..");
7
- const TAG_PREFIX = "fusion-ui-v";
8
- /** Written by the release (scripts/release.cjs), not committed */
9
- const VERSIONS_FILE = path.join(__dirname, "codemod-versions.json");
10
-
11
- const git = (cwd, args) =>
12
- execFileSync("git", args, {cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"]}).trim();
13
-
14
- /**
15
- * The first fusion-ui release containing the commit that added a transform: the oldest
16
- * `fusion-ui-v*` tag containing it, else `nextVersion` (the release being made, `null` in a
17
- * checkout outside of a release).
18
- */
19
- const releasedIn = (name, nextVersion = null, cwd = PACKAGE_DIR) => {
20
- let added = "";
21
- try {
22
- added = git(cwd, [
23
- "log",
24
- "--diff-filter=A",
25
- "--format=%H",
26
- "--",
27
- path.join(PACKAGE_DIR, "transforms", `${name}.cjs`),
28
- ])
29
- .split("\n")
30
- .filter(Boolean)
31
- .pop();
32
- } catch {
33
- return nextVersion;
34
- }
35
- if (!added) return nextVersion;
36
-
37
- // The release job installs no dependencies (no semver): the oldest tag is the first release,
38
- // also across branches (an alpha before the stable release)
39
- const tags = git(cwd, [
40
- "tag",
41
- "--contains",
42
- added,
43
- "--list",
44
- `${TAG_PREFIX}*`,
45
- "--sort=creatordate",
46
- ])
47
- .split("\n")
48
- .filter(Boolean)
49
- .map(tag => tag.slice(TAG_PREFIX.length));
50
- return tags[0] ?? nextVersion;
51
- };
52
3
 
53
4
  /**
54
- * The codemods with the fusion-ui version they belong to. An explicit `version` in codemods.cjs
55
- * wins (for a codemod added after its change was released), then the versions of the release,
56
- * else they are read from git; `null` for a codemod that wasn't released yet.
57
- *
58
- * @returns {{name: string, description: string, version: string | null}[]}
5
+ * All codemods, one transform in `transforms/<name>.cjs` each. `version` is the first fusion-ui
6
+ * version with the change; the release sets and commits it for codemods without one
7
+ * (scripts/release.cjs).
59
8
  */
60
- const loadCodemods = () => {
61
- const released = fs.existsSync(VERSIONS_FILE)
62
- ? JSON.parse(fs.readFileSync(VERSIONS_FILE, "utf8"))
63
- : null;
9
+ const CODEMODS_FILE = path.join(__dirname, "codemods.json");
64
10
 
65
- return codemods.map(codemod => ({
11
+ /** @returns {{name: string, description: string, version: string | null}[]} */
12
+ const loadCodemods = () =>
13
+ JSON.parse(fs.readFileSync(CODEMODS_FILE, "utf8")).map(codemod => ({
66
14
  ...codemod,
67
- version: codemod.version ?? (released ? released[codemod.name] : releasedIn(codemod.name)),
15
+ version: codemod.version ?? null,
68
16
  }));
69
- };
70
17
 
71
- module.exports = {loadCodemods, releasedIn, VERSIONS_FILE};
18
+ module.exports = {loadCodemods, CODEMODS_FILE};
package/lib/run.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  const path = require("node:path");
2
2
  // Not part of the public API of jscodeshift, but the way to run it in-process (as @next/codemod does)
3
3
  const Runner = require("jscodeshift/src/Runner");
4
+ const git = require("./git.cjs");
4
5
 
5
6
  const TRANSFORMS = path.join(__dirname, "..", "transforms");
6
7
 
@@ -10,12 +11,12 @@ const TRANSFORMS = path.join(__dirname, "..", "transforms");
10
11
  * @returns {Promise<{ok: number, nochange: number, skip: number, error: number}>}
11
12
  */
12
13
  const runCodemod = (name, paths, {dry = false, print = false, verbose = false} = {}) =>
13
- Runner.run(path.join(TRANSFORMS, `${name}.cjs`), paths, {
14
+ // Git selects the files: the gitignore option of jscodeshift reads only the .gitignore of the
15
+ // current directory (and fails without one) and ignores everything after a negated pattern
16
+ Runner.run(path.join(TRANSFORMS, `${name}.cjs`), git.listFiles(process.cwd(), paths) ?? paths, {
14
17
  parser: "tsx",
15
18
  extensions: "tsx,ts,jsx,js,mjs,cjs",
16
19
  ignorePattern: ["**/node_modules/**", "**/.next/**", "**/dist/**", "**/build/**", "**/out/**"],
17
- // Respect .gitignore like the project's own tools
18
- gitignore: true,
19
20
  // The transforms are plain CommonJS
20
21
  babel: false,
21
22
  dry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brynlabs/fusion-ui-codemod",
3
- "version": "0.0.0",
3
+ "version": "1.0.0-alpha.209",
4
4
  "description": "Codemods for upgrading projects that use @brynlabs/fusion-ui",
5
5
  "author": "The brynlabs.com team",
6
6
  "repository": {
@@ -20,7 +20,7 @@
20
20
  "files": [
21
21
  "bin",
22
22
  "lib/*.cjs",
23
- "lib/codemod-versions.json",
23
+ "lib/*.json",
24
24
  "transforms/*.cjs",
25
25
  "!**/*.test.cjs",
26
26
  "README.md"
package/lib/codemods.cjs DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- * All codemods, one transform in `transforms/<name>.cjs` each. The fusion-ui version a codemod
3
- * belongs to is the first release containing it, set by the release (see registry.cjs). Give a
4
- * `version` only to a codemod added after its breaking change was released: the first fusion-ui
5
- * version with that change.
6
- *
7
- * @type {{name: string, description: string, version?: string}[]}
8
- */
9
- module.exports = [
10
- {
11
- name: "data-table-fixed-height",
12
- description:
13
- "DataTableCollection: replaces useWindowScroll by fixedHeight, the table scrolls with the page by default",
14
- },
15
- ];