@sps-woodland/codemods 8.53.8 → 8.53.9

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.
@@ -10,9 +10,12 @@
10
10
  //
11
11
  // AST-based find-and-replace (via jscodeshift): rewrite imports of
12
12
  // @sps-woodland/<wrapper> packages (thin re-export shims) to import
13
- // directly from the @sps-woodland/core subpath they wrap. Does NOT touch
14
- // anything else: no @spscommerce/ds-react, no imported-name changes, no
15
- // JSX, no package.json/lockfile edits.
13
+ // directly from the @sps-woodland/core subpath they wrap. Also rewrites
14
+ // the matching CSS/SCSS/LESS "@sps-woodland/<wrapper>/style.css" (or
15
+ // "/lib/style.css") @import paths, since those are just as real a wrapper
16
+ // dependency as the JS imports and are otherwise invisible to a JS-only
17
+ // codemod. Does NOT touch anything else: no @spscommerce/ds-react, no
18
+ // imported-name changes, no JSX, no package.json/lockfile edits.
16
19
  //
17
20
  // This is intentionally NOT part of the main jscodeshift transform
18
21
  // pipeline (main.js / src/transform.ts) — that pipeline migrates
@@ -79,7 +82,8 @@ const WRAPPER_TO_CORE = {
79
82
  // @sps-woodland/codemods (these ship real, independent code, not re-exports).
80
83
 
81
84
  const SCOPE = "@sps-woodland";
82
- const EXTENSIONS = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]);
85
+ const JS_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]);
86
+ const CSS_EXTENSIONS = new Set([".css", ".scss", ".sass", ".less"]);
83
87
  const SKIP_DIRS = new Set(["node_modules", ".git", "dist", "build", "lib", "coverage"]);
84
88
 
85
89
  function resolveNewSource(oldSource) {
@@ -159,6 +163,38 @@ function transformSource(source) {
159
163
  };
160
164
  }
161
165
 
166
+ // Matches: @import [url(] ("|') @sps-woodland/<name><rest> (matching quote)
167
+ // Only the two CSS subpath forms wrapper packages actually ship
168
+ // ("/style.css" and "/lib/style.css") are rewritten — anything else for a
169
+ // known package is left alone and flagged, since guessing wrong here fails
170
+ // silently (no compiler to catch a bad CSS path).
171
+ const CSS_IMPORT_RE =
172
+ /(@import\s+(?:url\(\s*)?)(["'])@sps-woodland\/([a-z-]+)((?:\/[^"']*)?)\2/g;
173
+
174
+ function transformCssSource(source) {
175
+ const changes = []; // { oldSource, newSource }
176
+ const unknown = new Set();
177
+
178
+ const output = source.replace(CSS_IMPORT_RE, (match, prefix, quote, name, rest) => {
179
+ const mapping = WRAPPER_TO_CORE[name];
180
+ if (!mapping) {
181
+ unknown.add(name);
182
+ return match;
183
+ }
184
+ if (rest !== "/style.css" && rest !== "/lib/style.css") {
185
+ unknown.add(`${name}${rest}`);
186
+ return match;
187
+ }
188
+
189
+ const oldSource = `${SCOPE}/${name}${rest}`;
190
+ const newSource = `${SCOPE}/core/${mapping.cssSubpath}/style.css`;
191
+ changes.push({ oldSource, newSource });
192
+ return `${prefix}${quote}${newSource}${quote}`;
193
+ });
194
+
195
+ return { changes, unknown, output };
196
+ }
197
+
162
198
  async function* walk(dir) {
163
199
  const entries = await readdir(dir, { withFileTypes: true });
164
200
  for (const entry of entries) {
@@ -166,7 +202,7 @@ async function* walk(dir) {
166
202
  const full = path.join(dir, entry.name);
167
203
  if (entry.isDirectory()) {
168
204
  yield* walk(full);
169
- } else if (EXTENSIONS.has(path.extname(entry.name))) {
205
+ } else if (JS_EXTENSIONS.has(path.extname(entry.name)) || CSS_EXTENSIONS.has(path.extname(entry.name))) {
170
206
  yield full;
171
207
  }
172
208
  }
@@ -184,9 +220,10 @@ async function main() {
184
220
 
185
221
  for await (const file of walk(srcDir)) {
186
222
  const original = await readFile(file, "utf8");
223
+ const isCss = CSS_EXTENSIONS.has(path.extname(file));
187
224
  let result;
188
225
  try {
189
- result = transformSource(original);
226
+ result = isCss ? transformCssSource(original) : transformSource(original);
190
227
  } catch (err) {
191
228
  console.error(`skipped (parse error): ${file} — ${err.message}`);
192
229
  continue;
@@ -215,8 +252,10 @@ async function main() {
215
252
  console.log(`${filesChanged} file(s), ${totalReplacements} import(s) ${write ? "rewritten" : "would be rewritten"}.`);
216
253
  if (unknownPackagesSeen.size > 0) {
217
254
  console.log(
218
- `Note: found imports from @sps-woodland/${[...unknownPackagesSeen].join(", @sps-woodland/")} — ` +
219
- `not in the wrapper map, left untouched. Add them to WRAPPER_TO_CORE if they're also re-export shims.`,
255
+ `Note: found @sps-woodland/${[...unknownPackagesSeen].join(", @sps-woodland/")} — ` +
256
+ `either not a wrapper package (e.g. core/tokens/illustrations, left untouched on purpose) ` +
257
+ `or a subpath this script doesn't recognize. Review manually, or add it to WRAPPER_TO_CORE ` +
258
+ `if it's a wrapper re-export this script should also handle.`,
220
259
  );
221
260
  }
222
261
  if (!write) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sps-woodland/codemods",
3
3
  "description": "SPS Woodland Design System codemods",
4
- "version": "8.53.8",
4
+ "version": "8.53.9",
5
5
  "author": "SPS Commerce",
6
6
  "license": "UNLICENSED",
7
7
  "repository": "https://github.com/spscommerce/woodland/tree/master/packages/@sps-woodland/codemods",
Binary file
Binary file