@coreframe/vite 0.1.22 → 0.1.23
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.
package/dist/plugins/assets.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{readFile as e}from"node:fs/promises";import{checkAssets as t,formatAssetProblems as n,materializeAsset as r,readAssetManifest as i,resolveAssetVariantFile as a}from"@coreframe/scripts/assets";const
|
|
2
|
-
`)},async transform(t,r){let[a]=r.split(`?`,1);if(!a?.endsWith(`.md`)&&!a?.endsWith(`.mdx`))return;let
|
|
1
|
+
import{readFile as e}from"node:fs/promises";import{checkAssets as t,formatAssetProblems as n,materializeAsset as r,readAssetManifest as i,resolveAssetVariantFile as a}from"@coreframe/scripts/assets";import{readProjectConfig as o}from"@coreframe/scripts/config";const s=/!\[([^\]]*)\]\(@asset\s+([a-z0-9][a-z0-9/-]*)\)/g;function c({cwd:e=process.cwd(),devMaterialize:c=!0}={}){let f=`virtual:assets`,g=`\0${f}`,_=new Map,v=``,y=!1;async function b(){v||=u((await o({cwd:e})).assets?.publicBaseUrl)}function x(e){return{...e,variants:[...e.variants].sort((e,t)=>e.width-t.width).map(e=>({...e,src:l(v,e.path)}))}}async function S(t){let i=_.get(t);if(i)return i;let a=(async()=>{let i=await r(t,{cwd:e,updateManifest:!1});if(!i.ok)throw Error(n(i.problems));return i})();_.set(t,a);try{return await a}finally{_.delete(t)}}return{name:`coreframe:assets`,configResolved(e){v=u(e.env.VITE_ASSETS_PUBLIC_BASE_URL),y=e.mode===`test`||process.env.VITEST===`true`},configureServer(t){t.middlewares.use(async(r,o,s)=>{try{if(!r.url||![`GET`,`HEAD`].includes(r.method??`GET`)){s();return}let l=p(r.url);if(!l){s();return}let u=await i(e);if(u.problems.length>0){s(Error(n(u.problems)));return}let d=m(u.manifest,l);if(!d){s();return}let f=a(e,l),g=await h(f);if(!g&&c&&(t.config.logger.info(`Materializing Coreframe asset "${d}" for dev.`),await S(d),g=await h(f),!g))throw Error(`Coreframe asset variant "${l}" does not match its source. Run: coreframe assets build --id ${d}`);if(!g){s();return}o.statusCode=200,o.setHeader(`Content-Type`,`image/webp`),o.setHeader(`Cache-Control`,`public, max-age=31536000, immutable`),o.setHeader(`Content-Length`,g.byteLength),o.end(r.method===`HEAD`?void 0:g)}catch(e){s(e)}})},async buildStart(){if(this.meta.watchMode||y)return;let r=await t({cwd:e});if(!r.ok)throw Error(n(r.problems))},async resolveId(e){if(e===f)return g},async load(t){if(t!==g)return;await b();let{manifest:r,problems:a}=await i(e);if(a.length>0)throw Error(n(a));let o=Object.fromEntries(Object.entries(r.assets).map(([e,t])=>[e,x(t)]));return[`const manifest = ${JSON.stringify(o)};`,`export { manifest };`,`export function asset(id) {`,` const entry = manifest[id];`," if (!entry) throw new Error(`Unknown Coreframe asset: ${id}`);",` if (entry.variants.length === 0) {`," throw new Error(`Coreframe asset has no generated variants: ${id}. Run: coreframe assets build --id ${id}`);",` }`,` return entry;`,`}`].join(`
|
|
2
|
+
`)},async transform(t,r){let[a]=r.split(`?`,1);if(!a?.endsWith(`.md`)&&!a?.endsWith(`.mdx`))return;let o=[...t.matchAll(s)];if(o.length===0)return;await b();let l=await i(e),u=[...l.problems],f=t;for(let e of o){let[t,n,i]=e,a=l.manifest.assets[i];if(!a){u.push({code:`INVALID_REFERENCE`,message:`Asset reference "${i}" in "${r}" is not present in assets/manifest.json.`,assetId:i,file:r});continue}if(this.meta.watchMode&&c&&a.variants.length===0){this.warn(`Materializing Coreframe asset "${i}" for dev.`);let e=await S(i);u.push(...e.problems);let t=e.assets.find(e=>e.assetId===i);t&&(l.manifest.assets[i]={...a,variants:t.variants})}let o=x(l.manifest.assets[i]??a);if(o.variants.length===0){u.push({code:`GENERATED_VARIANT_MISSING`,message:`Asset "${i}" has no generated variants.`,assetId:i,file:r,fix:`Run: coreframe assets build --id ${i}`});continue}f=f.replace(t,d(n,o))}if(u.length>0)throw Error(n(u));return f}}}function l(e,t){return`${e}/${t}`}function u(e){return(e??``).replace(/\/+$/,``)}function d(e,t){let n=t.variants.at(-1),r=t.variants.map(e=>`${e.src} ${e.width}w`).join(`, `);return[`<img alt="${f(e)}"`,`src="${f(n.src)}"`,`srcset="${f(r)}"`,`sizes="100vw"`,`width="${t.width}"`,`height="${t.height}">`].join(` `)}function f(e){return e.replaceAll(`&`,`&`).replaceAll(`"`,`"`).replaceAll(`<`,`<`).replaceAll(`>`,`>`)}function p(e){let t=decodeURIComponent(new URL(e,`http://coreframe.local`).pathname).replace(/^\/+/,``);return t.startsWith(`projects/`)?t:void 0}function m(e,t){return Object.entries(e.assets).find(([,e])=>e.variants.some(e=>e.path===t))?.[0]}async function h(t){try{return await e(t)}catch(e){if(g(e)&&e.code===`ENOENT`)return;throw e}}function g(e){return e instanceof Error&&`code`in e}export{c as coreframeAssetsPlugin};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cp as e,readFile as t}from"node:fs/promises";import{basename as
|
|
1
|
+
import{cp as e,readFile as t}from"node:fs/promises";import{readProjectConfig as n}from"@coreframe/scripts/config";import{basename as r,join as i,resolve as a}from"node:path";import{createDashboardRequestHandler as o,resolveDashboardClientDist as s}from"@coreframe/dashboard/server";const c=`/__dashboard`;function l({clientDist:t=s(),env:n=process.env,projectRoot:a=process.cwd()}={}){return{name:`coreframe:dashboard`,async config(){return{define:{__COREFRAME_DASHBOARD_BUILD__:JSON.stringify(await d(a,n))}}},configureServer(e){let n=o({clientDist:t,projectRoot:a});return e.middlewares.use(async(e,t,r)=>{if(!e.url||!u(e.url)){r();return}await n.handle(e,t)}),e.httpServer?.once(`close`,()=>{n.dispose()}),()=>{let t=e.printUrls.bind(e);e.printUrls=()=>{t();let n=e.resolvedUrls?.local[0];n&&e.config.logger.info(` ➜ Dashboard: ${new URL(c,n)}`)}}},async writeBundle(n){!n.dir||r(n.dir)!==`client`||await e(t,i(n.dir,c.slice(1)),{force:!0,recursive:!0})}}}function u(e){let t=new URL(e,`http://coreframe.local`).pathname;return t===c||t.startsWith(`${c}/`)}async function d(e,r){let[i,o]=await Promise.all([t(a(e,`package.json`),`utf8`),n({cwd:e})]),s=JSON.parse(i),c=Object.entries(o.worker?.environment??{}).flatMap(([e,t])=>t.kind===`generated`?[]:[{description:t.description,kind:t.kind,name:e,requiredIn:t.requiredIn??[]}]);return{applicationName:s.name??`Coreframe application`,applicationVersion:s.version,commit:r.GITHUB_SHA,configuration:c,coreframeVersion:s.engines?.coreframe,deployUrls:{production:o.deploy?.environments?.production?.url,staging:o.deploy?.environments?.staging?.url}}}export{l as coreframeDashboardPlugin};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreframe/vite",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/airlock-labs/coreframe.git",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"lucide-react": "^1.24.0",
|
|
32
32
|
"obug": "^2.1.3",
|
|
33
33
|
"unplugin": "^2.3.11",
|
|
34
|
-
"@coreframe/dashboard": "^0.2.12",
|
|
35
34
|
"@coreframe/lib": "^0.1.12",
|
|
36
|
-
"@coreframe/scripts": "^0.1.
|
|
35
|
+
"@coreframe/scripts": "^0.1.35",
|
|
36
|
+
"@coreframe/dashboard": "^0.2.13"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@tsdown/css": "0.22.3",
|