Skip to content

fix(migrate): convert $store/ alias imports to ~/ - #64

Merged
JonasJesus42 merged 1 commit into
mainfrom
JonasJesus42/update-migrate-script
Mar 31, 2026
Merged

JonasJesus42 merged 1 commit into
mainfrom
JonasJesus42/update-migrate-script

Conversation

@JonasJesus42

@JonasJesus42 JonasJesus42 commented Mar 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add import rewrite rules for $store/ alias (common in Deno import maps) → ~/ (Vite alias)
  • Add $store/sdk/* specific rewrites matching existing site/sdk/* rules (clx, useOffer, etc.)
  • Update verify phase to detect residual $store/ imports alongside site/

Tested on deco-sites/miess-01 — previously all $store/ imports survived migration causing Vite "Failed to resolve import" errors at runtime.

Test plan

  • Run deco-migrate on a site using $store/ imports (e.g. miess-01)
  • Verify no $store/ imports remain in src/ after migration
  • Verify phase passes without warnings

🤖 Generated with Claude Code


Summary by cubic

Fixes the migrate script to convert $store/ alias imports to ~/ and map $store/sdk/* to the correct packages, preventing Vite resolve errors. The verify phase now flags any remaining site/ or $store/ imports.

  • Bug Fixes
    • Rewrite $store/sdk/* to the right targets: @decocms/start/sdk/clx, react, @decocms/apps/commerce/sdk/useOffer, @decocms/apps/commerce/sdk/useVariantPossibilities; drop deprecated usePlatform.
    • Convert generic $store/... to ~/<path>.
    • Update verify check to detect site/ or $store/ imports in src/.

Written for commit aec6b96. Summary will update on new commits.

The $store/ alias (common in Deno import maps) was not being rewritten
during migration, causing Vite "Failed to resolve import" errors at
runtime. Now handled identically to site/ → ~/ conversion.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@JonasJesus42
JonasJesus42 merged commit 4d257f9 into main Mar 31, 2026
1 check passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.42.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="scripts/migrate/transforms/imports.ts">

<violation number="1" location="scripts/migrate/transforms/imports.ts:53">
P1: The new `$store/sdk/*` rewrite patterns are over-broad (`.*`) and can rewrite unrelated imports with matching prefixes. Anchor these rules to the exact specifier (optionally with `.ts`/`.tsx`) to avoid false matches.</violation>
</file>

<file name="scripts/migrate/phase-verify.ts">

<violation number="1" location="scripts/migrate/phase-verify.ts:181">
P2: The new `$store/` verification regex misses side-effect imports (`import "$store/..."`) because it only searches for `from ...` syntax.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment on lines +53 to +57
[/^"\$store\/sdk\/clx(?:\.tsx?)?.*"$/, `"@decocms/start/sdk/clx"`],
[/^"\$store\/sdk\/useId(?:\.tsx?)?.*"$/, `"react"`],
[/^"\$store\/sdk\/useOffer(?:\.tsx?)?.*"$/, `"@decocms/apps/commerce/sdk/useOffer"`],
[/^"\$store\/sdk\/useVariantPossiblities(?:\.tsx?)?.*"$/, `"@decocms/apps/commerce/sdk/useVariantPossibilities"`],
[/^"\$store\/sdk\/usePlatform(?:\.tsx?)?.*"$/, null],

@cubic-dev-ai cubic-dev-ai Bot Mar 31, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: The new $store/sdk/* rewrite patterns are over-broad (.*) and can rewrite unrelated imports with matching prefixes. Anchor these rules to the exact specifier (optionally with .ts/.tsx) to avoid false matches.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/migrate/transforms/imports.ts, line 53:

<comment>The new `$store/sdk/*` rewrite patterns are over-broad (`.*`) and can rewrite unrelated imports with matching prefixes. Anchor these rules to the exact specifier (optionally with `.ts`/`.tsx`) to avoid false matches.</comment>

<file context>
@@ -49,6 +49,14 @@ const IMPORT_RULES: Array<[RegExp, string | null]> = [
   [/^"site\/sdk\/usePlatform(?:\.tsx?)?.*"$/, null],
 
+  // $store/ → ~/ (common Deno import map alias for project root)
+  [/^"\$store\/sdk\/clx(?:\.tsx?)?.*"$/, `"@decocms/start/sdk/clx"`],
+  [/^"\$store\/sdk\/useId(?:\.tsx?)?.*"$/, `"react"`],
+  [/^"\$store\/sdk\/useOffer(?:\.tsx?)?.*"$/, `"@decocms/apps/commerce/sdk/useOffer"`],
</file context>
Suggested change
[/^"\$store\/sdk\/clx(?:\.tsx?)?.*"$/, `"@decocms/start/sdk/clx"`],
[/^"\$store\/sdk\/useId(?:\.tsx?)?.*"$/, `"react"`],
[/^"\$store\/sdk\/useOffer(?:\.tsx?)?.*"$/, `"@decocms/apps/commerce/sdk/useOffer"`],
[/^"\$store\/sdk\/useVariantPossiblities(?:\.tsx?)?.*"$/, `"@decocms/apps/commerce/sdk/useVariantPossibilities"`],
[/^"\$store\/sdk\/usePlatform(?:\.tsx?)?.*"$/, null],
[/^"\$store\/sdk\/clx(?:\.tsx?)?"$/, `"@decocms/start/sdk/clx"`],
[/^"\$store\/sdk\/useId(?:\.tsx?)?"$/, `"react"`],
[/^"\$store\/sdk\/useOffer(?:\.tsx?)?"$/, `"@decocms/apps/commerce/sdk/useOffer"`],
[/^"\$store\/sdk\/useVariantPossiblities(?:\.tsx?)?"$/, `"@decocms/apps/commerce/sdk/useVariantPossibilities"`],
[/^"\$store\/sdk\/usePlatform(?:\.tsx?)?"$/, null],
Fix with Cubic

const srcDir = path.join(ctx.sourceDir, "src");
if (!fs.existsSync(srcDir)) return true;
const bad = findFilesWithPattern(srcDir, /from\s+["']site\//);
const bad = findFilesWithPattern(srcDir, /from\s+["'](site\/|\$store\/)/);

@cubic-dev-ai cubic-dev-ai Bot Mar 31, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The new $store/ verification regex misses side-effect imports (import "$store/...") because it only searches for from ... syntax.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/migrate/phase-verify.ts, line 181:

<comment>The new `$store/` verification regex misses side-effect imports (`import "$store/..."`) because it only searches for `from ...` syntax.</comment>

<file context>
@@ -173,14 +173,14 @@ const checks: Check[] = [
       const srcDir = path.join(ctx.sourceDir, "src");
       if (!fs.existsSync(srcDir)) return true;
-      const bad = findFilesWithPattern(srcDir, /from\s+["']site\//);
+      const bad = findFilesWithPattern(srcDir, /from\s+["'](site\/|\$store\/)/);
       if (bad.length > 0) {
-        console.log(`    Still has site/ imports: ${bad.join(", ")}`);
</file context>
Suggested change
const bad = findFilesWithPattern(srcDir, /from\s+["'](site\/|\$store\/)/);
const bad = findFilesWithPattern(srcDir, /(?:from\s+["']|import\s+["'])(site\/|\$store\/)/);
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant