@cmssy/codemod 5.0.0 → 5.0.2

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 +47 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -63,10 +63,40 @@ var CLIENT_SYMBOLS = /* @__PURE__ */ new Set([
63
63
  "CmssyLocaleProviderProps",
64
64
  "useCmssyLocale"
65
65
  ]);
66
+ var CORE_SYMBOLS = /* @__PURE__ */ new Set([
67
+ "resolveApiUrl",
68
+ "DEFAULT_CMSSY_API_URL",
69
+ "evaluateFieldConditionGroup",
70
+ "FieldCondition",
71
+ "FieldConditionGroup",
72
+ "FieldConditionLogic",
73
+ "splitCmssyLocale",
74
+ "sealSession",
75
+ "openSession",
76
+ "isAccessExpired",
77
+ "sessionCookieOptions",
78
+ "SESSION_MAX_AGE_SECONDS",
79
+ "CmssySessionPayload",
80
+ "CmssySessionUser",
81
+ "SessionCookieOptions",
82
+ "verifyCmssyWebhook",
83
+ "CmssyWebhookError",
84
+ "CmssyWebhookEvent",
85
+ "CmssyWebhookOrder",
86
+ "VerifyCmssyWebhookOptions",
87
+ "fetchOrderByToken",
88
+ "FetchOrderByTokenOptions",
89
+ "MyOrdersResult",
90
+ "FetchProductsOptions",
91
+ "FetchProductOptions",
92
+ "CmssyProductPage",
93
+ "CmssyStockState"
94
+ ]);
66
95
  var ENTRY_FOR = (symbol) => {
67
96
  if (SERVER_SYMBOLS.has(symbol)) return "@cmssy/next/server";
68
97
  if (MIDDLEWARE_SYMBOLS.has(symbol)) return "@cmssy/next/middleware";
69
98
  if (CLIENT_SYMBOLS.has(symbol)) return "@cmssy/next/client";
99
+ if (CORE_SYMBOLS.has(symbol)) return "@cmssy/core";
70
100
  return "@cmssy/next";
71
101
  };
72
102
  var IMPORT = /import\s+(type\s+)?\{([^}]*)\}\s+from\s+["']@cmssy\/next(?:\/preset)?["'];?/g;
@@ -147,11 +177,13 @@ async function main() {
147
177
  );
148
178
  const files = await sourceFiles(target);
149
179
  const touched = [];
180
+ let needsCore = false;
150
181
  for (const file of files) {
151
182
  const source = await readFile(file, "utf8");
152
183
  const { code, changed } = transform(source);
153
184
  if (!changed) continue;
154
185
  touched.push(file);
186
+ if (code.includes('from "@cmssy/core"')) needsCore = true;
155
187
  if (!dry) await writeFile(file, code);
156
188
  }
157
189
  if (touched.length === 0) {
@@ -164,10 +196,25 @@ async function main() {
164
196
  for (const file of touched) {
165
197
  console.log(` ${file.slice(target.length + 1)}`);
166
198
  }
199
+ if (needsCore && !await dependsOnCore(target)) {
200
+ console.log(
201
+ "\nYour code now imports @cmssy/core, which you do not depend on yet:\n npm install @cmssy/core (or pnpm add / yarn add)"
202
+ );
203
+ }
167
204
  console.log(
168
205
  "\nThe imports moved; the wiring did not. Run your build, then the editor\nsmoke test - a site whose editor is dead still builds:\n https://github.com/cmssy-io/cmssy-sdk/blob/main/docs/testing.md"
169
206
  );
170
207
  }
208
+ async function dependsOnCore(target) {
209
+ try {
210
+ const manifest = JSON.parse(
211
+ await readFile(join(target, "package.json"), "utf8")
212
+ );
213
+ return Boolean(manifest.dependencies?.["@cmssy/core"]);
214
+ } catch {
215
+ return true;
216
+ }
217
+ }
171
218
  main().catch((error) => {
172
219
  console.error(error);
173
220
  process.exitCode = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/codemod",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
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",