diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03da2ec40..6ff0da200 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -172,7 +172,7 @@ jobs: uses: thollander/actions-comment-pull-request@v2 with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - comment_includes: '## Deployed site previews with [![Cloudflare Pages]' + comment_tag: '## Deployed site previews with [![Cloudflare Pages]' message: | > **Latest commit**: ${{ github.sha }} diff --git a/sites/twind.run/src/lib/transpile.api.ts b/sites/twind.run/src/lib/transpile.api.ts index 1e6195b07..2767e43be 100644 --- a/sites/twind.run/src/lib/transpile.api.ts +++ b/sites/twind.run/src/lib/transpile.api.ts @@ -92,16 +92,7 @@ const api: Transpile = { (!input.version || SemverRange.match(input.version, output.version)) ) { source = output.id + output.path - } - } - - for (const [key, value] of Object.entries(manifest.imports || {})) { - // add all sub-path imports - if ( - key === source || - (key.startsWith(source + '/') && key !== source + '/package.json') - ) { - ;(inputMap.imports ||= {})[key] = value + ;(inputMap.imports ||= {})[source] = resolved } } @@ -121,10 +112,11 @@ const api: Transpile = { ], }) + // console.debug({ manifest, dependencies, inputMap }) + const generator = new Generator({ baseUrl: 'memory://', inputMap, - defaultProvider: 'jspm.system', env: [ 'development', 'modern', @@ -135,9 +127,49 @@ const api: Transpile = { 'import', 'default', ], + defaultProvider: 'jspm.system', + providers: { + '@twind': 'local', + }, + customProviders: { + local: { + pkgToUrl(pkg) { + if (manifest.packages[pkg.name] === pkg.version) { + return new URL(`./immutable/cdn/${pkg.name}@${pkg.version}/`, manifest.url) + .href as 'x/' + } + + return `https://ga.system.jspm.io/${pkg.registry}:${pkg.name}@${pkg.version}/` + }, + parseUrlPkg(url) { + const base = new URL(`./immutable/cdn/`, manifest.url).href + if (url.startsWith(base)) { + const [, name, version] = + url + .slice(base.length) + .match(/^((?:@[^/\\%@]+\/)?[^./\\%@][^/\\%@]*)@([^\/]+)(\/.*)?$/) || [] + + return { registry: 'npm', name, version } + } + }, + async resolveLatestTarget(target, layer, parentUrl) { + const version = manifest.packages[target.name] + + if (version) { + return { registry: target.registry, name: target.name, version } + } + + return null + }, + }, + }, }) - // TODO: trace generator.logStream + // ;(async () => { + // for await (const { type, message } of generator.logStream()) { + // console.log(`${type}: ${message}`); + // } + // })(); const [{ dynamicDeps = [], staticDeps = [] } = {}, { output }] = await Promise.all([ generator.install([...dependencies]), @@ -194,7 +226,7 @@ const api: Transpile = { prefetch: dynamicDeps.map(scopeToManifest), } - console.debug('importMap', importMap) + // console.debug('importMap', importMap) return { ...Object.fromEntries( output diff --git a/sites/twind.run/src/routes/[[key]]/+page.server.ts b/sites/twind.run/src/routes/[[key]]/+page.server.ts index 2398c9d5d..44c858f68 100644 --- a/sites/twind.run/src/routes/[[key]]/+page.server.ts +++ b/sites/twind.run/src/routes/[[key]]/+page.server.ts @@ -200,11 +200,11 @@ export async function load({ const alias = version === '*' ? 'latest' : version.toLowerCase().replace(/[^a-z\d]/g, '-') const origin = - version === SITE_VERSION + version === SITE_VERSION || alias.includes('-dev-') ? new URL(request.url).origin : alias === 'latest' ? `https://${HOSTNAME}` - : `https://${/^\d\.\d\.\d/.test(alias) ? 'v' + alias : alias}.${HOSTNAME}` + : `https://${/\d/.test(alias) ? 'v' + alias : alias}.${HOSTNAME}` const url = origin + MANIFEST_PATH @@ -220,7 +220,7 @@ export async function load({ response = await fetch(url) if (!(response.ok && response.status === 200)) { - throw new Error(`[${response.status}] ${response.statusText || 'request failed'}`) + throw new Error(`[${response.status}] ${response.statusText || 'request failed'}: ${url}`) } cache?.put(url, response.clone())