@tailor-platform/sdk-codemod 0.8.2 → 0.8.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @tailor-platform/sdk-codemod
2
2
 
3
+ ## 0.8.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2225](https://github.com/tailor-platform/sdk/pull/2225) [`4a295de`](https://github.com/tailor-platform/sdk/commit/4a295dee514408339bf511129d01cffe3a42da2d) Thanks [@dqn](https://github.com/dqn)! - Keep package script migrations consistent across codemods.
8
+
9
+ ## 0.8.4
10
+
11
+ ### Patch Changes
12
+
13
+ - [#2190](https://github.com/tailor-platform/sdk/pull/2190) [`b358644`](https://github.com/tailor-platform/sdk/commit/b35864405973390a40b4ca202ce1d887689d6603) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update dependency picomatch to v4.0.7
14
+
15
+ ## 0.8.3
16
+
17
+ ### Patch Changes
18
+
19
+ - [#2205](https://github.com/tailor-platform/sdk/pull/2205) [`1cff028`](https://github.com/tailor-platform/sdk/commit/1cff028c263be7b42e58e3dbc5278f444df802aa) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): update @inquirer
20
+
3
21
  ## 0.8.2
4
22
 
5
23
  ### Patch Changes
@@ -0,0 +1,24 @@
1
+ //#region src/package-json-scripts.ts
2
+ function transformPackageScripts(source, transformScript) {
3
+ let parsed;
4
+ try {
5
+ parsed = JSON.parse(source);
6
+ } catch {
7
+ return null;
8
+ }
9
+ const scripts = parsed.scripts;
10
+ if (typeof scripts !== "object" || scripts == null || Array.isArray(scripts)) return null;
11
+ let modified = false;
12
+ for (const [name, value] of Object.entries(scripts)) {
13
+ if (typeof value !== "string") continue;
14
+ const updated = transformScript(value);
15
+ if (updated == null || updated === value) continue;
16
+ scripts[name] = updated;
17
+ modified = true;
18
+ }
19
+ if (!modified) return null;
20
+ const trailing = source.endsWith("\n") ? "\n" : "";
21
+ return JSON.stringify(parsed, null, 2) + trailing;
22
+ }
23
+ //#endregion
24
+ export { transformPackageScripts as t };
@@ -1,3 +1,4 @@
1
+ import { t as transformPackageScripts } from "../../../package-json-scripts-DVHZc1mk.js";
1
2
  import * as path from "pathe";
2
3
  //#region codemods/v2/apply-to-deploy/scripts/transform.ts
3
4
  const ARG_VALUE = `(?:[^\\s'"\`;&|]+|'[^']*'|"(?:(?:\\\\.)|[^"\\\\])*")`;
@@ -27,26 +28,7 @@ function transformSourceText(source) {
27
28
  return updated === source ? null : updated;
28
29
  }
29
30
  function transformPackageJson(source) {
30
- let parsed;
31
- try {
32
- parsed = JSON.parse(source);
33
- } catch {
34
- return null;
35
- }
36
- let modified = false;
37
- const scripts = parsed.scripts;
38
- if (typeof scripts === "object" && scripts != null && !Array.isArray(scripts)) for (const [name, value] of Object.entries(scripts)) {
39
- if (typeof value !== "string") continue;
40
- if (!value.includes("tailor-sdk")) continue;
41
- const updated = replaceApply(value);
42
- if (updated !== value) {
43
- scripts[name] = updated;
44
- modified = true;
45
- }
46
- }
47
- if (!modified) return null;
48
- const trailing = source.endsWith("\n") ? "\n" : "";
49
- return JSON.stringify(parsed, null, 2) + trailing;
31
+ return transformPackageScripts(source, replaceApply);
50
32
  }
51
33
  /**
52
34
  * Replace `tailor-sdk apply` invocations with `tailor-sdk deploy`.
@@ -1,3 +1,4 @@
1
+ import { t as transformPackageScripts } from "../../../package-json-scripts-DVHZc1mk.js";
1
2
  import * as path from "pathe";
2
3
  //#region codemods/v2/cli-rename/scripts/transform.ts
3
4
  const COMMAND_RENAMES = [["crash-report", "crashreport"]];
@@ -375,25 +376,7 @@ function transformText(source, filePath) {
375
376
  return updated === source ? null : updated;
376
377
  }
377
378
  function transformPackageJson(source) {
378
- let parsed;
379
- try {
380
- parsed = JSON.parse(source);
381
- } catch {
382
- return null;
383
- }
384
- let modified = false;
385
- const scripts = parsed.scripts;
386
- if (typeof scripts === "object" && scripts != null && !Array.isArray(scripts)) for (const [name, value] of Object.entries(scripts)) {
387
- if (typeof value !== "string") continue;
388
- const updated = replaceAll(value);
389
- if (updated !== value) {
390
- scripts[name] = updated;
391
- modified = true;
392
- }
393
- }
394
- if (!modified) return null;
395
- const trailing = source.endsWith("\n") ? "\n" : "";
396
- return JSON.stringify(parsed, null, 2) + trailing;
379
+ return transformPackageScripts(source, replaceAll);
397
380
  }
398
381
  /**
399
382
  * Apply v2 CLI naming conventions: multi-word commands collapse into a single
@@ -1,3 +1,4 @@
1
+ import { t as transformPackageScripts } from "../../../package-json-scripts-DVHZc1mk.js";
1
2
  import { Lang, parse } from "@ast-grep/napi";
2
3
  import * as path from "pathe";
3
4
  //#region codemods/v2/rename-bin/scripts/transform.ts
@@ -1041,26 +1042,7 @@ function transformSourceFile(source, filePath) {
1041
1042
  return updated === source ? null : updated;
1042
1043
  }
1043
1044
  function transformPackageJson(source) {
1044
- let parsed;
1045
- try {
1046
- parsed = JSON.parse(source);
1047
- } catch {
1048
- return null;
1049
- }
1050
- let modified = false;
1051
- const scripts = parsed.scripts;
1052
- if (typeof scripts === "object" && scripts != null && !Array.isArray(scripts)) for (const [name, value] of Object.entries(scripts)) {
1053
- if (typeof value !== "string") continue;
1054
- if (!value.includes("tailor-sdk")) continue;
1055
- const updated = renameBinary(value);
1056
- if (updated !== value) {
1057
- scripts[name] = updated;
1058
- modified = true;
1059
- }
1060
- }
1061
- if (!modified) return null;
1062
- const trailing = source.endsWith("\n") ? "\n" : "";
1063
- return JSON.stringify(parsed, null, 2) + trailing;
1045
+ return transformPackageScripts(source, renameBinary);
1064
1046
  }
1065
1047
  /**
1066
1048
  * Rename `tailor-sdk` binary references to `tailor`.
@@ -1,3 +1,4 @@
1
+ import { t as transformPackageScripts } from "../../../package-json-scripts-DVHZc1mk.js";
1
2
  import * as path from "pathe";
2
3
  //#region codemods/v2/sdk-skills-shim/scripts/transform.ts
3
4
  const SHIM_PATTERN = new RegExp(`((?<![\\w.-])(?:npx|bunx|(?:pnpm|yarn)[ \\t]+dlx|npm[ \\t]+exec)(?:[ \\t]+-{1,2}[\\w-]*)*[ \\t]+)?\\btailor-sdk-skills(?:@[^\\s'"\`]+)?(?:[ \\t]+install)?\\b(?!-)`, "g");
@@ -13,26 +14,7 @@ function transformText(source) {
13
14
  return updated === source ? null : updated;
14
15
  }
15
16
  function transformPackageJson(source) {
16
- let parsed;
17
- try {
18
- parsed = JSON.parse(source);
19
- } catch {
20
- return null;
21
- }
22
- let modified = false;
23
- const scripts = parsed.scripts;
24
- if (typeof scripts === "object" && scripts != null && !Array.isArray(scripts)) for (const [name, value] of Object.entries(scripts)) {
25
- if (typeof value !== "string") continue;
26
- if (!value.includes("tailor-sdk-skills")) continue;
27
- const updated = replaceShim(value);
28
- if (updated !== value) {
29
- scripts[name] = updated;
30
- modified = true;
31
- }
32
- }
33
- if (!modified) return null;
34
- const trailing = source.endsWith("\n") ? "\n" : "";
35
- return JSON.stringify(parsed, null, 2) + trailing;
17
+ return transformPackageScripts(source, replaceShim);
36
18
  }
37
19
  /**
38
20
  * Replace `tailor-sdk-skills` invocations with `tailor skills add`.
@@ -1,3 +1,4 @@
1
+ import { t as transformPackageScripts } from "../../../package-json-scripts-DVHZc1mk.js";
1
2
  import * as path from "pathe";
2
3
  //#region codemods/v2/seed-exec-to-cli-plugin/scripts/transform.ts
3
4
  const NODE_BINARY = "(?<![\\w.-])node(?![\\w-])";
@@ -64,26 +65,7 @@ function transformSourceText(source) {
64
65
  return updated === source ? null : updated;
65
66
  }
66
67
  function transformPackageJson(source) {
67
- let parsed;
68
- try {
69
- parsed = JSON.parse(source);
70
- } catch {
71
- return null;
72
- }
73
- const scripts = parsed.scripts;
74
- if (typeof scripts !== "object" || scripts == null || Array.isArray(scripts)) return null;
75
- let modified = false;
76
- for (const [name, value] of Object.entries(scripts)) {
77
- if (typeof value !== "string") continue;
78
- const updated = rewrite(value);
79
- if (updated !== value) {
80
- scripts[name] = updated;
81
- modified = true;
82
- }
83
- }
84
- if (!modified) return null;
85
- const trailing = source.endsWith("\n") ? "\n" : "";
86
- return JSON.stringify(parsed, null, 2) + trailing;
68
+ return transformPackageScripts(source, rewrite);
87
69
  }
88
70
  /**
89
71
  * Rewrite generated seed runner invocations to the `tailor seed` CLI plugin.
@@ -1,3 +1,4 @@
1
+ import { t as transformPackageScripts } from "../../../package-json-scripts-DVHZc1mk.js";
1
2
  import * as path from "pathe";
2
3
  //#region codemods/v2/test-run-arg-input/scripts/transform.ts
3
4
  const COMMAND_PATTERN = /\btailor-sdk\s+function\s+test-run\b/;
@@ -104,27 +105,7 @@ function transformShellLikeText(source) {
104
105
  return lines.join("\n").split(JOIN_MARKER).join("\\\n");
105
106
  }
106
107
  function transformPackageJson(source) {
107
- let parsed;
108
- try {
109
- parsed = JSON.parse(source);
110
- } catch {
111
- return null;
112
- }
113
- const scripts = parsed.scripts;
114
- if (typeof scripts !== "object" || scripts == null || Array.isArray(scripts)) return null;
115
- let modified = false;
116
- for (const [name, value] of Object.entries(scripts)) {
117
- if (typeof value !== "string") continue;
118
- if (!COMMAND_PATTERN.test(value)) continue;
119
- const updated = transformShellLikeText(value);
120
- if (updated != null) {
121
- scripts[name] = updated;
122
- modified = true;
123
- }
124
- }
125
- if (!modified) return null;
126
- const trailing = source.endsWith("\n") ? "\n" : "";
127
- return JSON.stringify(parsed, null, 2) + trailing;
108
+ return transformPackageScripts(source, transformShellLikeText);
128
109
  }
129
110
  /**
130
111
  * Strip `{ "input": ... }` wrappers from `tailor-sdk function test-run --arg` JSON.
@@ -1,3 +1,4 @@
1
+ import { t as transformPackageScripts } from "../../../package-json-scripts-DVHZc1mk.js";
1
2
  import * as path from "pathe";
2
3
  //#region codemods/v3/function-test-run-rename/scripts/transform.ts
3
4
  const TOKEN_SEPARATOR = "(?:[ \\t]|\\\\\\r?\\n)+";
@@ -10,25 +11,7 @@ function transformText(source) {
10
11
  return updated === source ? null : updated;
11
12
  }
12
13
  function transformPackageJson(source) {
13
- let parsed;
14
- try {
15
- parsed = JSON.parse(source);
16
- } catch {
17
- return null;
18
- }
19
- let modified = false;
20
- const scripts = parsed.scripts;
21
- if (typeof scripts === "object" && scripts != null && !Array.isArray(scripts)) for (const [name, value] of Object.entries(scripts)) {
22
- if (typeof value !== "string") continue;
23
- const updated = replaceCommand(value);
24
- if (updated !== value) {
25
- scripts[name] = updated;
26
- modified = true;
27
- }
28
- }
29
- if (!modified) return null;
30
- const trailing = source.endsWith("\n") ? "\n" : "";
31
- return JSON.stringify(parsed, null, 2) + trailing;
14
+ return transformPackageScripts(source, replaceCommand);
32
15
  }
33
16
  /**
34
17
  * Rename `tailor function test-run` invocations to `tailor function run`.
@@ -1,3 +1,4 @@
1
+ import { t as transformPackageScripts } from "../../../package-json-scripts-DVHZc1mk.js";
1
2
  import * as path from "pathe";
2
3
  //#region codemods/v3/setup-branch-flag-rename/scripts/transform.ts
3
4
  const TOKEN_SEPARATOR = "(?:[ \\t]|\\\\\\r?\\n)+";
@@ -36,25 +37,7 @@ function transformText(source) {
36
37
  return updated === source ? null : updated;
37
38
  }
38
39
  function transformPackageJson(source) {
39
- let parsed;
40
- try {
41
- parsed = JSON.parse(source);
42
- } catch {
43
- return null;
44
- }
45
- let modified = false;
46
- const scripts = parsed.scripts;
47
- if (typeof scripts === "object" && scripts != null && !Array.isArray(scripts)) for (const [name, value] of Object.entries(scripts)) {
48
- if (typeof value !== "string") continue;
49
- const updated = replaceCommand(value);
50
- if (updated !== value) {
51
- scripts[name] = updated;
52
- modified = true;
53
- }
54
- }
55
- if (!modified) return null;
56
- const trailing = source.endsWith("\n") ? "\n" : "";
57
- return JSON.stringify(parsed, null, 2) + trailing;
40
+ return transformPackageScripts(source, replaceCommand);
58
41
  }
59
42
  /**
60
43
  * Rename the `--branch` option of `tailor setup branch` invocations to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tailor-platform/sdk-codemod",
3
- "version": "0.8.2",
3
+ "version": "0.8.5",
4
4
  "description": "Codemod runner for Tailor Platform SDK upgrades",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -19,7 +19,7 @@
19
19
  "@ast-grep/napi": "0.45.2",
20
20
  "diff": "9.0.0",
21
21
  "pathe": "2.0.3",
22
- "picomatch": "4.0.5",
22
+ "picomatch": "4.0.7",
23
23
  "pkg-types": "2.3.1",
24
24
  "politty": "0.11.9",
25
25
  "semver": "7.8.5",