@tailor-platform/sdk-codemod 0.2.7 → 0.3.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @tailor-platform/sdk-codemod
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
### Minor Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#1435](https://github.com/tailor-platform/sdk/pull/1435) [`49c0cc9`](https://github.com/tailor-platform/sdk/commit/49c0cc99171d7e317a50a18804a21067d89f9493) Thanks [@dqn](https://github.com/dqn)! - Add the `v2/plugin-cli-import` codemod so `tailor-sdk upgrade` rewrites deprecated plugin imports from `@tailor-platform/sdk/cli` (`kyselyTypePlugin`, `enumConstantsPlugin`, `fileUtilsPlugin`, `seedPlugin`) to their dedicated `@tailor-platform/sdk/plugin/*` subpaths, splitting any non-plugin specifiers onto a separate import.
|
|
9
|
+
|
|
3
10
|
## 0.2.7
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Lang, parse } from "@ast-grep/napi";
|
|
2
|
+
//#region codemods/v2/plugin-cli-import/scripts/transform.ts
|
|
3
|
+
const CLI_MODULE = "@tailor-platform/sdk/cli";
|
|
4
|
+
/** Deprecated plugin re-exports from `@tailor-platform/sdk/cli` and their dedicated subpaths. */
|
|
5
|
+
const PLUGIN_SUBPATHS = {
|
|
6
|
+
kyselyTypePlugin: "@tailor-platform/sdk/plugin/kysely-type",
|
|
7
|
+
enumConstantsPlugin: "@tailor-platform/sdk/plugin/enum-constants",
|
|
8
|
+
fileUtilsPlugin: "@tailor-platform/sdk/plugin/file-utils",
|
|
9
|
+
seedPlugin: "@tailor-platform/sdk/plugin/seed"
|
|
10
|
+
};
|
|
11
|
+
function* iterateImportSpecs(importStmt) {
|
|
12
|
+
const specs = importStmt.findAll({ rule: { kind: "import_specifier" } });
|
|
13
|
+
for (const spec of specs) {
|
|
14
|
+
const idents = spec.children().filter((c) => c.kind() === "identifier");
|
|
15
|
+
if (idents.length === 0) continue;
|
|
16
|
+
yield {
|
|
17
|
+
importedName: idents[0].text(),
|
|
18
|
+
text: spec.text()
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** True for `import type { ... }` (statement-level `type`), not inline `{ type x }`. */
|
|
23
|
+
function isTypeOnlyImport(importStmt) {
|
|
24
|
+
return importStmt.children().some((c) => c.kind() === "type");
|
|
25
|
+
}
|
|
26
|
+
/** True when the import has a default binding or a `* as x` namespace binding. */
|
|
27
|
+
function hasNonNamedBinding(importStmt) {
|
|
28
|
+
const clause = importStmt.children().find((c) => c.kind() === "import_clause");
|
|
29
|
+
if (!clause) return false;
|
|
30
|
+
return clause.children().some((c) => c.kind() === "identifier" || c.kind() === "namespace_import");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Rewrite deprecated plugin re-export imports from `@tailor-platform/sdk/cli`
|
|
34
|
+
* to their dedicated plugin subpaths.
|
|
35
|
+
*
|
|
36
|
+
* Plugin specifiers are split into one `import { plugin } from "<subpath>"`
|
|
37
|
+
* statement each; any non-plugin specifiers stay on the original `/cli`
|
|
38
|
+
* import. A statement-level `import type` is carried over to every generated
|
|
39
|
+
* line. `/cli` imports without plugin specifiers are left untouched.
|
|
40
|
+
* @param source - File contents
|
|
41
|
+
* @param filePath - Absolute path to the file (kept for the runner signature)
|
|
42
|
+
* @returns Transformed source or null when nothing matched.
|
|
43
|
+
*/
|
|
44
|
+
function transform(source, _filePath) {
|
|
45
|
+
if (!source.includes(CLI_MODULE)) return null;
|
|
46
|
+
const root = parse(source.includes("</") || source.includes("/>") ? Lang.Tsx : Lang.TypeScript, source).root();
|
|
47
|
+
const edits = [];
|
|
48
|
+
const importStmts = root.findAll({ rule: {
|
|
49
|
+
kind: "import_statement",
|
|
50
|
+
has: {
|
|
51
|
+
kind: "string",
|
|
52
|
+
regex: `^["']${CLI_MODULE}["']$`
|
|
53
|
+
}
|
|
54
|
+
} });
|
|
55
|
+
for (const importStmt of importStmts) {
|
|
56
|
+
if (hasNonNamedBinding(importStmt)) continue;
|
|
57
|
+
const keyword = isTypeOnlyImport(importStmt) ? "import type" : "import";
|
|
58
|
+
const pluginSpecs = [];
|
|
59
|
+
const otherSpecs = [];
|
|
60
|
+
for (const spec of iterateImportSpecs(importStmt)) (Object.hasOwn(PLUGIN_SUBPATHS, spec.importedName) ? pluginSpecs : otherSpecs).push(spec);
|
|
61
|
+
if (pluginSpecs.length === 0) continue;
|
|
62
|
+
const lines = pluginSpecs.map((s) => `${keyword} { ${s.text} } from "${PLUGIN_SUBPATHS[s.importedName]}";`).toSorted();
|
|
63
|
+
if (otherSpecs.length > 0) lines.unshift(`${keyword} { ${otherSpecs.map((s) => s.text).join(", ")} } from "${CLI_MODULE}";`);
|
|
64
|
+
edits.push(importStmt.replace(lines.join("\n")));
|
|
65
|
+
}
|
|
66
|
+
if (edits.length === 0) return null;
|
|
67
|
+
return root.commitEdits(edits);
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { transform as default };
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,14 @@ const allCodemods = [
|
|
|
23
23
|
scriptPath: "v2/define-generators-to-plugins/scripts/transform.js",
|
|
24
24
|
legacyPatterns: ["defineGenerators"]
|
|
25
25
|
},
|
|
26
|
+
{
|
|
27
|
+
id: "v2/plugin-cli-import",
|
|
28
|
+
name: "@tailor-platform/sdk/cli plugin imports → dedicated subpaths",
|
|
29
|
+
description: "Rewrite deprecated plugin re-export imports (kyselyTypePlugin, enumConstantsPlugin, fileUtilsPlugin, seedPlugin) from `@tailor-platform/sdk/cli` to their dedicated plugin subpaths",
|
|
30
|
+
since: "1.0.0",
|
|
31
|
+
until: "2.0.0",
|
|
32
|
+
scriptPath: "v2/plugin-cli-import/scripts/transform.js"
|
|
33
|
+
},
|
|
26
34
|
{
|
|
27
35
|
id: "v2/test-run-arg-input",
|
|
28
36
|
name: "function test-run --arg input unwrap",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tailor-platform/sdk-codemod",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Codemod runner for Tailor Platform SDK upgrades",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@types/node": "24.13.1",
|
|
31
31
|
"@types/picomatch": "4.0.3",
|
|
32
32
|
"@types/semver": "7.7.1",
|
|
33
|
-
"oxlint": "1.
|
|
33
|
+
"oxlint": "1.69.0",
|
|
34
34
|
"tsdown": "0.22.2",
|
|
35
35
|
"typescript": "5.9.3",
|
|
36
36
|
"vitest": "4.1.8"
|