Skip to content

feat(importmap): implement package-scoped vendor structure for staticDeps - #14

Merged
tatang26 merged 2 commits into
mainfrom
improving-importmaps-tool
Apr 29, 2026
Merged

feat(importmap): implement package-scoped vendor structure for staticDeps#14
tatang26 merged 2 commits into
mainfrom
improving-importmaps-tool

Conversation

@tatang26

Copy link
Copy Markdown
Contributor

Summary

This PR changes the way vendor packages are downloaded and organized in the importmap tool.

Currently the importmap tool downloads packages into a flattened structure. This approach is not including the download of packages that require internal dependencies (scopes).

The new approach downloads all package scopes and places them within their vendored path, creating an isolated directory structure per package:

// Before
vendor/
└── package@1.0.0.js              # Single flat file
// After  
vendor/
└── package@1.0.0/
    ├── dist/index.js             # Main entry point
    ├── _/helper.js               # Internal dependencies
    └── scopes/                   # Isolated scoped dependencies
        └── dependency@2.0.0/

Breaking Change

After upgrading, you must run:

go run github.com/leapkit/leapkit/tools/importmap@latest pristine

This reorganizes the vendor directory to the new structure.

⚠️ Important: Embed Directive Update

Some internal dependencies are placed in _/ folders (e.g., _/index.js). The Go embed directive with standard * pattern excludes directories starting with _ or .

Update required in template/internal/system/assets/assets.go:

// Before:
//go:embed *

// After:
//go:embed all:*

Without this change, _/ directories won't be embedded and the application will fail at runtime.
See Go embed docs for details.

tatang26 added 2 commits April 28, 2026 08:45
…cDeps

Completely rewrite import map pinning to use package-scoped directory
structure with full JSPM staticDeps support for proper dependency isolation.

Changes:
- Pin now downloads ALL files from JSPM staticDeps (main + deps + internal)
- Package-scoped structure: vendor/{pkg}@{ver}/ with scopes/ subdirectory
- Internal files (_/, jsx-runtime/) downloaded but not added to importmap
- Rollback mechanism on download errors for clean failure handling
- Pristine command updated to extract packages from new URL format
- Unpin deletes entire package directory including all scopes

Structure:
  vendor/
  ├── @org/package@1.0.0/
  │   ├── dist/index.js              (main)
  │   ├── _/abc123.js                (internal - not in importmap)
  │   └── scopes/
  │       └── dependency@2.0.0/      (isolated deps)

Breaking changes:
- Vendor directory structure changed from flat to package-scoped
- Old: vendor/pkg@1.0.0.js
- New: vendor/pkg@1.0.0/dist/index.js

Benefits:
- Version coexistence (different packages can use different dep versions)
- Clean unpin (single directory deletion removes all files)
- JSPM structure preservation (exact paths from JSPM CDN)
- Better isolation (no shared dependency conflicts)

Tests:
- Added comprehensive test suite (pin_test.go) for new structure
- Updated existing tests to use generic package names
- All tests passing with new architecture
@tatang26
tatang26 merged commit 6a34508 into main Apr 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant