@tailor-platform/sdk-codemod 0.4.1 → 0.5.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,27 @@
1
1
  # @tailor-platform/sdk-codemod
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2023](https://github.com/tailor-platform/sdk/pull/2023) [`9dc826f`](https://github.com/tailor-platform/sdk/commit/9dc826fc0a83aa926de5b07245513f67c1ace877) Thanks [@dqn](https://github.com/dqn)! - Guide users through the v2 type-only import requirement. The CLI loads TypeScript by stripping types from each file in isolation, so a plain import of a type-only export fails at load time with `SyntaxError: ... does not provide an export named '<name>'` and no indication that the import form is the cause.
8
+
9
+ - The CLI now appends a suggestion to that error: import the name with `import type` and set `"verbatimModuleSyntax": true` in tsconfig.json to catch violations at typecheck.
10
+ - Projects scaffolded by `tailor init` now enable `verbatimModuleSyntax` in their tsconfig.json, so new projects catch violations at typecheck instead of at load time.
11
+ - The v2 migration guide gains a `v2/type-only-imports` entry documenting the requirement, the failure mode, and the migration steps, offered by `tailor upgrade` when crossing the v2 boundary.
12
+
13
+ ## 0.4.2
14
+
15
+ ### Patch Changes
16
+
17
+ - [#1934](https://github.com/tailor-platform/sdk/pull/1934) [`2a3ec7b`](https://github.com/tailor-platform/sdk/commit/2a3ec7b108275410bf5b35d23784b07aa147c5ea) Thanks [@toiroakr](https://github.com/toiroakr)! - Drop the `chalk` dependency in favor of Node's built-in styling, and decide color support per output stream. Diagnostics on stderr now keep their colors when you redirect stdout (`tailor executor list > out.txt`), and stop writing escape codes into the file when you redirect stderr (`tailor deploy 2> log.txt`). `NO_COLOR`, `FORCE_COLOR` and non-TTY detection keep working as before.
18
+
19
+ `@tailor-platform/sdk-codemod`, `@tailor-platform/sdk-plugin-seed` and `@tailor-platform/sdk-plugin-tailordb-erd` now declare the Node and Bun versions they need (`node >=22.15.0`, `bun >=1.2.0`), matching `@tailor-platform/sdk`. Installing them on an older runtime reports the mismatch instead of failing once the CLI runs.
20
+
21
+ - [#2008](https://github.com/tailor-platform/sdk/pull/2008) [`f2135ab`](https://github.com/tailor-platform/sdk/commit/f2135ab6dd3d130d88803b9829a26024de930ed3) Thanks [@toiroakr](https://github.com/toiroakr)! - Consistently call a TailorDB schema definition a "table" instead of a "type" across the docs, matching the `db.type()` → `db.table()` rename. Also fix three leftover `db.type(...)` code samples in `docs/services/tailordb.md` that should have read `db.table(...)`.
22
+
23
+ Update the `v2/idp-publish-events-rename` codemod registry description to say "tables" instead of "types", matching the same wording fix.
24
+
3
25
  ## 0.4.1
4
26
 
5
27
  ### Patch Changes
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { gte, lt, parse, valid } from "semver";
9
9
  import * as fs from "node:fs";
10
10
  import { realpathSync } from "node:fs";
11
11
  import { Lang, parse as parse$1 } from "@ast-grep/napi";
12
- import chalk from "chalk";
12
+ import { stripVTControlCharacters, styleText } from "node:util";
13
13
  import { structuredPatch } from "diff";
14
14
  import picomatch from "picomatch";
15
15
  import { execFileSync } from "node:child_process";
@@ -116,6 +116,7 @@ const RENAME_BIN_QUOTED_LEGACY_COMMAND_PATTERN = new RegExp([
116
116
  ].join(""));
117
117
  const V2_NEXT_1 = "2.0.0-next.1";
118
118
  const V2_NEXT_2 = "2.0.0-next.2";
119
+ const V2_NEXT_3 = "2.0.0-next.3";
119
120
  const V2_NEXT_4 = "2.0.0-next.4";
120
121
  const V2_NEXT_5 = "2.0.0-next.5";
121
122
  const V2_NEXT_6 = "2.0.0-next.6";
@@ -124,6 +125,50 @@ const V2_NEXT_9 = "2.0.0-next.9";
124
125
  const V2_NEXT_11 = "2.0.0-next.11";
125
126
  /** All registered codemods, in registration order. */
126
127
  const allCodemods = [
128
+ {
129
+ id: "v2/type-only-imports",
130
+ name: "Type-only imports → `import type`",
131
+ description: [
132
+ "The v2 CLI runs TypeScript by stripping types from each file in isolation,",
133
+ "with no cross-file type information. A plain (non-`type`) import of a",
134
+ "type-only export therefore survives stripping and fails when the module",
135
+ "loads:",
136
+ "",
137
+ "```",
138
+ "SyntaxError: The requested module './types.ts' does not provide an export named 'Row'",
139
+ "```",
140
+ "",
141
+ "`tailor generate` / `tailor deploy` stop at this error before doing any work.",
142
+ "Import types with `import type` (or the inline `type` modifier), and",
143
+ "re-export them with `export type`, in every module the CLI loads. Generated",
144
+ "Kysely types (`DB`, `Insertable`, `Selectable`, table row types) are almost",
145
+ "entirely type-only, so v1 projects typically hit this in many files at once.",
146
+ "Set `\"verbatimModuleSyntax\": true` in tsconfig.json to catch every violation",
147
+ "at typecheck; projects scaffolded by v2 `tailor init` enable it by default."
148
+ ].join("\n"),
149
+ since: "1.0.0",
150
+ until: "2.0.0",
151
+ prereleaseUntil: V2_NEXT_3,
152
+ examples: [{
153
+ before: "import { DB, getDB } from \"./generated/db\";",
154
+ after: "import { type DB, getDB } from \"./generated/db\";"
155
+ }],
156
+ prompt: [
157
+ "In Tailor SDK v2 the CLI loads TypeScript by stripping types from each file",
158
+ "in isolation, so type-only exports do not exist at runtime and plain imports",
159
+ "of them fail to load with \"does not provide an export named '<name>'\".",
160
+ "Migrate the project so every type-only import and re-export is marked:",
161
+ "",
162
+ "1. Add `\"verbatimModuleSyntax\": true` to compilerOptions in tsconfig.json.",
163
+ "2. Run `tsc --noEmit` and fix every reported violation: add the `type`",
164
+ " modifier to type-only named imports (`import type { Row }` or",
165
+ " `import { type Row, marker }`) and change type-only re-exports to",
166
+ " `export type { ... }`.",
167
+ "",
168
+ "Only add `type` modifiers; do not reorder, remove, or otherwise change",
169
+ "imports that are used as values."
170
+ ].join("\n")
171
+ },
127
172
  {
128
173
  id: "v2/define-generators-to-plugins",
129
174
  name: "defineGenerators → definePlugins",
@@ -683,7 +728,7 @@ const allCodemods = [
683
728
  {
684
729
  id: "v2/idp-publish-events-rename",
685
730
  name: "defineIdp publishUserEvents → publishEvents",
686
- description: "Rename the `defineIdp` option `publishUserEvents` to `publishEvents`, matching the field name TailorDB types, resolvers, and workflows already use.",
731
+ description: "Rename the `defineIdp` option `publishUserEvents` to `publishEvents`, matching the field name that TailorDB tables, resolvers, and workflows already use.",
687
732
  since: "1.5.0",
688
733
  until: "2.0.0",
689
734
  prereleaseUntil: V2_NEXT_11,
@@ -1521,6 +1566,46 @@ function getApplicableCodemods(fromVersion, toVersion) {
1521
1566
  return allCodemods.filter((codemod) => gte(fromVersion, codemod.since) && lt(fromVersion, effectiveCodemodBoundary(codemod)) && reachesCodemodBoundary(toVersion, codemod));
1522
1567
  }
1523
1568
  //#endregion
1569
+ //#region ../shared/src/color.ts
1570
+ const style = (name) => (text) => styleText(name, text, { validateStream: false });
1571
+ /**
1572
+ * Style functions by name, so call sites read `color.bold(text)`. Styling is
1573
+ * always applied; `renderFor` drops it again when the destination stream has no
1574
+ * color support. Add a name here when a package needs one that is not listed.
1575
+ */
1576
+ const color = {
1577
+ bold: style("bold"),
1578
+ dim: style("dim"),
1579
+ italic: style("italic"),
1580
+ gray: style("gray"),
1581
+ white: style("white"),
1582
+ red: style("red"),
1583
+ green: style("green"),
1584
+ yellow: style("yellow"),
1585
+ cyan: style("cyan"),
1586
+ magenta: style("magenta"),
1587
+ redBright: style("redBright"),
1588
+ greenBright: style("greenBright"),
1589
+ cyanBright: style("cyanBright")
1590
+ };
1591
+ const supportsColor = (stream) => {
1592
+ const forced = process.env.FORCE_COLOR;
1593
+ if (forced !== void 0) return forced !== "0" && forced !== "false";
1594
+ if (process.env.NODE_DISABLE_COLORS !== void 0) return false;
1595
+ if ((process.env.NO_COLOR ?? "") !== "") return false;
1596
+ if (process.env.TERM === "dumb") return false;
1597
+ return stream.isTTY === true;
1598
+ };
1599
+ /**
1600
+ * Prepares styled text for the stream it is written to.
1601
+ * @param stream - Stream the text is written to
1602
+ * @param text - Styled text
1603
+ * @returns Text with styling removed when the stream has no color support
1604
+ */
1605
+ function renderFor(stream, text) {
1606
+ return supportsColor(stream) ? text : stripVTControlCharacters(text);
1607
+ }
1608
+ //#endregion
1524
1609
  //#region src/runner.ts
1525
1610
  /** Default file patterns for TypeScript files. */
1526
1611
  const DEFAULT_FILE_PATTERNS = ["**/*.{ts,tsx,mts,cts}"];
@@ -1592,6 +1677,9 @@ async function* walkFiles(root, relativeDir = "") {
1592
1677
  if (entry.isFile()) yield relative;
1593
1678
  }
1594
1679
  }
1680
+ function writeDiffLine(line, style) {
1681
+ process.stderr.write(renderFor(process.stderr, `${style ? style(line) : line}\n`));
1682
+ }
1595
1683
  /**
1596
1684
  * Print a colorized unified diff for a single file to stderr.
1597
1685
  * @param filePath - Absolute path to the file
@@ -1601,13 +1689,14 @@ async function* walkFiles(root, relativeDir = "") {
1601
1689
  function printDiff(filePath, before, after) {
1602
1690
  const patch = structuredPatch(filePath, filePath, before, after, "", "", { context: 3 });
1603
1691
  if (patch.hunks.length === 0) return;
1604
- process.stderr.write(`\n${chalk.bold(`--- ${filePath}`)}\n`);
1605
- process.stderr.write(`${chalk.bold(`+++ ${filePath}`)}\n`);
1692
+ writeDiffLine("");
1693
+ writeDiffLine(`--- ${filePath}`, color.bold);
1694
+ writeDiffLine(`+++ ${filePath}`, color.bold);
1606
1695
  for (const hunk of patch.hunks) {
1607
- process.stderr.write(chalk.cyan(`@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@\n`));
1608
- for (const line of hunk.lines) if (line.startsWith("+")) process.stderr.write(`${chalk.green(line)}\n`);
1609
- else if (line.startsWith("-")) process.stderr.write(`${chalk.red(line)}\n`);
1610
- else process.stderr.write(`${line}\n`);
1696
+ writeDiffLine(`@@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`, color.cyan);
1697
+ for (const line of hunk.lines) if (line.startsWith("+")) writeDiffLine(line, color.green);
1698
+ else if (line.startsWith("-")) writeDiffLine(line, color.red);
1699
+ else writeDiffLine(line);
1611
1700
  }
1612
1701
  }
1613
1702
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tailor-platform/sdk-codemod",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Codemod runner for Tailor Platform SDK upgrades",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,7 +17,6 @@
17
17
  "type": "module",
18
18
  "dependencies": {
19
19
  "@ast-grep/napi": "0.45.0",
20
- "chalk": "5.6.2",
21
20
  "diff": "9.0.0",
22
21
  "pathe": "2.0.3",
23
22
  "picomatch": "4.0.5",
@@ -29,12 +28,17 @@
29
28
  "devDependencies": {
30
29
  "@types/node": "24.13.3",
31
30
  "@types/picomatch": "4.0.3",
32
- "@types/semver": "7.7.1",
31
+ "@types/semver": "7.8.0",
33
32
  "eslint-plugin-zod": "4.9.0",
34
33
  "oxlint": "1.76.0",
35
34
  "tsdown": "0.22.14",
36
35
  "typescript": "6.0.3",
37
- "vitest": "4.1.10"
36
+ "vitest": "4.1.10",
37
+ "@tailor-platform/shared": "^0.0.0"
38
+ },
39
+ "engines": {
40
+ "bun": ">=1.2.0",
41
+ "node": ">=22.15.0"
38
42
  },
39
43
  "scripts": {
40
44
  "build": "tsdown",