@cmssy/codemod 6.2.0 → 7.0.1

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.
Files changed (2) hide show
  1. package/dist/index.js +30 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -13,8 +13,8 @@ var SERVER_SYMBOLS = /* @__PURE__ */ new Set([
13
13
  "createCmssyPage",
14
14
  "createCmssyEditPage",
15
15
  "createCmssyNotFound",
16
- "CmssyChrome",
17
- "CmssyChromeProps",
16
+ "CmssyLayoutSlot",
17
+ "CmssyLayoutSlotProps",
18
18
  "CreateCmssyNotFoundOptions",
19
19
  "buildCmssyMetadata",
20
20
  "BuildCmssyMetadataOptions",
@@ -144,7 +144,27 @@ function transform(source) {
144
144
  return { code, changed };
145
145
  }
146
146
 
147
+ // src/v7.ts
148
+ var RENAMES2 = {
149
+ CmssyChrome: "CmssyLayoutSlot",
150
+ CmssyChromeProps: "CmssyLayoutSlotProps"
151
+ };
152
+ function transform2(source) {
153
+ let code = source;
154
+ let changed = false;
155
+ for (const [from, to] of Object.entries(RENAMES2)) {
156
+ const pattern = new RegExp(`\\b${from}\\b`, "g");
157
+ if (pattern.test(code)) {
158
+ code = code.replace(pattern, to);
159
+ changed = true;
160
+ }
161
+ }
162
+ return { code, changed };
163
+ }
164
+
147
165
  // src/index.ts
166
+ var TRANSFORMS = { v5: transform, v7: transform2 };
167
+ var PREVIOUS_MAJOR = { v5: "4.x", v7: "6.x" };
148
168
  var SKIP = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "out", "coverage"]);
149
169
  var EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mjs"];
150
170
  function skipDirectory(name) {
@@ -166,28 +186,31 @@ async function sourceFiles(dir) {
166
186
  async function main() {
167
187
  const args = process.argv.slice(2);
168
188
  const version = args[0];
169
- if (version !== "v5") {
170
- console.error("usage: cmssy-codemod v5 [path] [--dry]");
189
+ const transform3 = TRANSFORMS[version];
190
+ if (!transform3) {
191
+ console.error("usage: cmssy-codemod v5|v7 [path] [--dry]");
171
192
  process.exitCode = 1;
172
193
  return;
173
194
  }
174
195
  const dry = args.includes("--dry");
175
196
  const target = resolve(
176
- args.find((a) => !a.startsWith("-") && a !== "v5") ?? "."
197
+ args.find((a) => !a.startsWith("-") && !(a in TRANSFORMS)) ?? "."
177
198
  );
178
199
  const files = await sourceFiles(target);
179
200
  const touched = [];
180
201
  let needsCore = false;
181
202
  for (const file of files) {
182
203
  const source = await readFile(file, "utf8");
183
- const { code, changed } = transform(source);
204
+ const { code, changed } = transform3(source);
184
205
  if (!changed) continue;
185
206
  touched.push(file);
186
207
  if (code.includes('from "@cmssy/core"')) needsCore = true;
187
208
  if (!dry) await writeFile(file, code);
188
209
  }
189
210
  if (touched.length === 0) {
190
- console.log("cmssy: nothing to migrate - no 4.x imports found.");
211
+ console.log(
212
+ `cmssy: nothing to migrate - no ${PREVIOUS_MAJOR[version]} imports found.`
213
+ );
191
214
  return;
192
215
  }
193
216
  console.log(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/codemod",
3
- "version": "6.2.0",
3
+ "version": "7.0.1",
4
4
  "description": "Rewrites cmssy imports across major versions, so a breaking release costs minutes instead of an afternoon.",
5
5
  "keywords": [
6
6
  "cmssy",