@coreframe/vite 0.1.2 → 0.1.4

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.
@@ -0,0 +1,15 @@
1
+ import { Plugin } from "vite";
2
+
3
+ //#region dashboard.d.ts
4
+ type CoreframeDashboardPluginOptions = {
5
+ clientDist?: string;
6
+ env?: NodeJS.ProcessEnv;
7
+ projectRoot?: string;
8
+ };
9
+ declare function coreframeDashboardPlugin({
10
+ clientDist,
11
+ env,
12
+ projectRoot
13
+ }?: CoreframeDashboardPluginOptions): Plugin;
14
+ //#endregion
15
+ export { CoreframeDashboardPluginOptions, coreframeDashboardPlugin };
@@ -0,0 +1 @@
1
+ import{cp as e,readFile as t}from"node:fs/promises";import{basename as n,join as r,resolve as i}from"node:path";import{createDashboardRequestHandler as a,resolveDashboardClientDist as o}from"@coreframe/dashboard/server";import{readProjectConfig as s}from"@coreframe/scripts/config";const c=`/__dashboard`;function l({clientDist:t=o(),env:i=process.env,projectRoot:s=process.cwd()}={}){return{name:`coreframe:dashboard`,async config(){return{define:{__COREFRAME_DASHBOARD_BUILD__:JSON.stringify(await d(s,i))}}},configureServer(e){let n=a({clientDist:t,projectRoot:s});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(i){!i.dir||n(i.dir)!==`client`||await e(t,r(i.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,n){let[r,a]=await Promise.all([t(i(e,`package.json`),`utf8`),s({cwd:e})]),o=JSON.parse(r),c=Object.entries(a.worker?.environment??{}).flatMap(([e,t])=>t.kind===`generated`?[]:[{description:t.description,kind:t.kind,name:e,requiredIn:t.requiredIn??[]}]);return{applicationName:o.name??`Coreframe application`,applicationVersion:o.version,commit:n.GITHUB_SHA,configuration:c,coreframeVersion:o.engines?.coreframe,deployUrls:{production:a.deploy?.environments?.production?.url,staging:a.deploy?.environments?.staging?.url}}}export{l as coreframeDashboardPlugin};
package/dist/icons.js CHANGED
@@ -1,4 +1,4 @@
1
- import{readFile as e}from"node:fs/promises";import{createHash as t}from"node:crypto";import{isAbsolute as n,relative as r,resolve as i}from"node:path";import{buildParsedSVG as a,parseSVGContent as o}from"@iconify/utils";import{loadNodeIcon as s}from"@iconify/utils/lib/loader/node-loader";import c from"unplugin-icons/vite";const l=`src/assets/icons`,u=`\0coreframe:sprite-icon:`,d=`__COREFRAME_SPRITE_URL__`,f=/^[a-z0-9]+(?:-[a-z0-9]+)*$/;function p(t={}){let n=i(t.appIconsDirectory??l);async function r(t){if(f.test(t))try{let r=await e(i(n,`${t}.svg`),`utf8`);S(r,`app/${t}`);let s=o(r);if(!s||!a(s))throw Error(`Icon \`app/${t}\` must contain a valid viewBox`);return r}catch(e){if(O(e)&&e.code===`ENOENT`)return;throw e}}return[m({options:t,loadAppIcon:r,setAppIconsDirectory(e){n=e}}),c({compiler:`jsx`,jsx:`react`,customCollections:{app:r}})]}function m({options:e,loadAppIcon:t,setAppIconsDirectory:n}){let r=new Map,a=``,o,c;return{name:`coreframe:icons`,enforce:`pre`,configResolved(t){o=t,a=w(t.root,e.appIconsDirectory??l),n(a)},resolveId(e){let t=g(e);return t?`${u}${encodeURIComponent(JSON.stringify(t))}.js`:null},async load(e){let n=h(e);if(!n)return null;n.collection===`app`&&this.addWatchFile(i(a,`${n.icon}.svg`));let c=n.collection===`app`?await t(n.icon):await s(n.collection,n.icon,{addXmlNs:!1,autoInstall:!1,cwd:o.root,scale:1.2});if(!c)throw Error(`Icon \`${n.collection}/${n.icon}\` not found`);let l=_(c,n.collection,n.icon);return r.set(l.id,l),v(l,n.props,o.command===`serve`)},renderStart(){o.command!==`build`||r.size===0||(c=this.emitFile({type:`asset`,name:`coreframe-icons.svg`,source:y(r.values())}))},renderChunk(e){if(!e.includes(d))return null;if(!c)throw Error(`Coreframe sprite asset was not emitted before chunk rendering`);let t=b(o.base,this.getFileName(c));return e.replaceAll(d,t)},handleHotUpdate(e){if(T(a,e.file)){for(let t of e.server.moduleGraph.idToModuleMap.values())(t.id?.includes(`~icons/app/`)||t.id?.startsWith(u))&&e.server.moduleGraph.invalidateModule(t);return e.server.ws.send({type:`full-reload`}),[]}}}}function h(e){if(!e.startsWith(u)||!e.endsWith(`.js`))return null;let t=e.slice(23,-3);return JSON.parse(decodeURIComponent(t))}function g(e){let t=e.indexOf(`?`);if(t===-1)return null;let n=new URLSearchParams(e.slice(t+1));if(!n.has(`sprite`))return null;n.delete(`sprite`);let r=e.slice(0,t).replace(/^\/?(?:~icons|virtual:icons|virtual\/icons)\//,``).replace(/\.\w+$/,``).split(`/`);if(r.length!==2||r.some(e=>!f.test(e)))throw Error(`Invalid sprite icon import: ${e}`);let i=Object.create(null);return n.forEach((e,t)=>{if(t===`raw`)throw Error(`An icon import cannot use both ?sprite and ?raw`);if(t===`style`)throw Error(`Pass sprite icon styles through the component style prop`);i[C(t)]=e}),{collection:r[0],icon:r[1],props:i}}function _(e,n,r){S(e,`${n}/${r}`);let i=o(e),s=i&&a(i);if(!i||!s)throw Error(`Icon \`${n}/${r}\` must contain a valid viewBox`);let c=`coreframe-icon-${n}-${r}-${t(`sha256`).update(`${n}/${r}\0${s.attributes.viewBox}\0${s.body}`).digest(`hex`).slice(0,12)}`,l=x(s.body,c),u=i.attribs.preserveAspectRatio?` preserveAspectRatio="${E(i.attribs.preserveAspectRatio)}"`:``;return{id:c,markup:`<symbol id="${c}" viewBox="${E(s.attributes.viewBox)}"${u}>${l}</symbol>`,viewBox:s.attributes.viewBox,width:s.attributes.width,height:s.attributes.height}}function v(e,t,n){let r={...e.width?{width:e.width}:{},...e.height?{height:e.height}:{},...t},i=n?`\nregisterSpriteSymbol(${JSON.stringify({id:e.id,markup:e.markup})})\n`:``,a=n?`import { registerSpriteSymbol, SpriteIcon } from "@coreframe/lib/sprite-icon"`:`import { SpriteIcon } from "@coreframe/lib/sprite-icon"`,o=n?`#${e.id}`:`${d}#${e.id}`;return`${a}
1
+ import{readFile as e}from"node:fs/promises";import{isAbsolute as t,relative as n,resolve as r}from"node:path";import{createHash as i}from"node:crypto";import{buildParsedSVG as a,parseSVGContent as o}from"@iconify/utils";import{loadNodeIcon as s}from"@iconify/utils/lib/loader/node-loader";import c from"unplugin-icons/vite";const l=`src/assets/icons`,u=`\0coreframe:sprite-icon:`,d=`__COREFRAME_SPRITE_URL__`,f=/^[a-z0-9]+(?:-[a-z0-9]+)*$/;function p(t={}){let n=r(t.appIconsDirectory??l);async function i(t){if(f.test(t))try{let i=await e(r(n,`${t}.svg`),`utf8`);S(i,`app/${t}`);let s=o(i);if(!s||!a(s))throw Error(`Icon \`app/${t}\` must contain a valid viewBox`);return i}catch(e){if(O(e)&&e.code===`ENOENT`)return;throw e}}return[m({options:t,loadAppIcon:i,setAppIconsDirectory(e){n=e}}),c({compiler:`jsx`,jsx:`react`,customCollections:{app:i}})]}function m({options:e,loadAppIcon:t,setAppIconsDirectory:n}){let i=new Map,a=``,o,c;return{name:`coreframe:icons`,enforce:`pre`,configResolved(t){o=t,a=w(t.root,e.appIconsDirectory??l),n(a)},resolveId(e){let t=g(e);return t?`${u}${encodeURIComponent(JSON.stringify(t))}.js`:null},async load(e){let n=h(e);if(!n)return null;n.collection===`app`&&this.addWatchFile(r(a,`${n.icon}.svg`));let c=n.collection===`app`?await t(n.icon):await s(n.collection,n.icon,{addXmlNs:!1,autoInstall:!1,cwd:o.root,scale:1.2});if(!c)throw Error(`Icon \`${n.collection}/${n.icon}\` not found`);let l=_(c,n.collection,n.icon);return i.set(l.id,l),v(l,n.props,o.command===`serve`)},renderStart(){o.command!==`build`||i.size===0||(c=this.emitFile({type:`asset`,name:`coreframe-icons.svg`,source:y(i.values())}))},renderChunk(e){if(!e.includes(d))return null;if(!c)throw Error(`Coreframe sprite asset was not emitted before chunk rendering`);let t=b(o.base,this.getFileName(c));return e.replaceAll(d,t)},handleHotUpdate(e){if(T(a,e.file)){for(let t of e.server.moduleGraph.idToModuleMap.values())(t.id?.includes(`~icons/app/`)||t.id?.startsWith(u))&&e.server.moduleGraph.invalidateModule(t);return e.server.ws.send({type:`full-reload`}),[]}}}}function h(e){if(!e.startsWith(u)||!e.endsWith(`.js`))return null;let t=e.slice(23,-3);return JSON.parse(decodeURIComponent(t))}function g(e){let t=e.indexOf(`?`);if(t===-1)return null;let n=new URLSearchParams(e.slice(t+1));if(!n.has(`sprite`))return null;n.delete(`sprite`);let r=e.slice(0,t).replace(/^\/?(?:~icons|virtual:icons|virtual\/icons)\//,``).replace(/\.\w+$/,``).split(`/`);if(r.length!==2||r.some(e=>!f.test(e)))throw Error(`Invalid sprite icon import: ${e}`);let i=Object.create(null);return n.forEach((e,t)=>{if(t===`raw`)throw Error(`An icon import cannot use both ?sprite and ?raw`);if(t===`style`)throw Error(`Pass sprite icon styles through the component style prop`);i[C(t)]=e}),{collection:r[0],icon:r[1],props:i}}function _(e,t,n){S(e,`${t}/${n}`);let r=o(e),s=r&&a(r);if(!r||!s)throw Error(`Icon \`${t}/${n}\` must contain a valid viewBox`);let c=`coreframe-icon-${t}-${n}-${i(`sha256`).update(`${t}/${n}\0${s.attributes.viewBox}\0${s.body}`).digest(`hex`).slice(0,12)}`,l=x(s.body,c),u=r.attribs.preserveAspectRatio?` preserveAspectRatio="${E(r.attribs.preserveAspectRatio)}"`:``;return{id:c,markup:`<symbol id="${c}" viewBox="${E(s.attributes.viewBox)}"${u}>${l}</symbol>`,viewBox:s.attributes.viewBox,width:s.attributes.width,height:s.attributes.height}}function v(e,t,n){let r={...e.width?{width:e.width}:{},...e.height?{height:e.height}:{},...t},i=n?`\nregisterSpriteSymbol(${JSON.stringify({id:e.id,markup:e.markup})})\n`:``,a=n?`import { registerSpriteSymbol, SpriteIcon } from "@coreframe/lib/sprite-icon"`:`import { SpriteIcon } from "@coreframe/lib/sprite-icon"`,o=n?`#${e.id}`:`${d}#${e.id}`;return`${a}
2
2
  import { createElement } from "react"
3
3
  ${i}
4
4
  const defaultProps = ${JSON.stringify(r)}
@@ -11,4 +11,4 @@ export default function CoreframeSpriteIcon(props) {
11
11
  viewBox: "${e.viewBox}",
12
12
  })
13
13
  }
14
- `}function y(e){return`<svg xmlns="http://www.w3.org/2000/svg" id="coreframe-icon-sprite">${Array.from(e,e=>e.markup).join(``)}</svg>`}function b(e,t){return`${e.endsWith(`/`)?e:`${e}/`}${t}`}function x(e,t){let n=Array.from(e.matchAll(/\bid=(['"])(.*?)\1/g),e=>e[2]),r=e;for(let[e,i]of n.entries()){let n=D(i),a=`${t}-${e+1}`;r=r.replace(RegExp(`\\bid=(['"])${n}\\1`,`g`),`id="${a}"`).replace(RegExp(`(["#;])${n}(?=[)"']|\\.[a-z])`,`g`),`$1${a}`)}return r}function S(e,t){if(/<(?:script|foreignObject)\b/i.test(e)||/\son[a-z]+\s*=/i.test(e))throw Error(`Icon \`${t}\` contains executable SVG content`);if(/\b(?:href|xlink:href)\s*=\s*['"](?!#)/i.test(e))throw Error(`Icon \`${t}\` contains an external SVG reference`)}function C(e){return e===`class`?`className`:e.startsWith(`aria-`)||e.startsWith(`data-`)?e:e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function w(e,t){return n(t)?t:i(e,t)}function T(e,t){let i=r(e,t);return i!==``&&!i.startsWith(`..`)&&!n(i)}function E(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`"`,`&quot;`)}function D(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function O(e){return e instanceof Error&&`code`in e}export{p as coreframeIconsPlugin};
14
+ `}function y(e){return`<svg xmlns="http://www.w3.org/2000/svg" id="coreframe-icon-sprite">${Array.from(e,e=>e.markup).join(``)}</svg>`}function b(e,t){return`${e.endsWith(`/`)?e:`${e}/`}${t}`}function x(e,t){let n=Array.from(e.matchAll(/\bid=(['"])(.*?)\1/g),e=>e[2]),r=e;for(let[e,i]of n.entries()){let n=D(i),a=`${t}-${e+1}`;r=r.replace(RegExp(`\\bid=(['"])${n}\\1`,`g`),`id="${a}"`).replace(RegExp(`(["#;])${n}(?=[)"']|\\.[a-z])`,`g`),`$1${a}`)}return r}function S(e,t){if(/<(?:script|foreignObject)\b/i.test(e)||/\son[a-z]+\s*=/i.test(e))throw Error(`Icon \`${t}\` contains executable SVG content`);if(/\b(?:href|xlink:href)\s*=\s*['"](?!#)/i.test(e))throw Error(`Icon \`${t}\` contains an external SVG reference`)}function C(e){return e===`class`?`className`:e.startsWith(`aria-`)||e.startsWith(`data-`)?e:e.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function w(e,n){return t(n)?n:r(e,n)}function T(e,r){let i=n(e,r);return i!==``&&!i.startsWith(`..`)&&!t(i)}function E(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`"`,`&quot;`)}function D(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function O(e){return e instanceof Error&&`code`in e}export{p as coreframeIconsPlugin};
@@ -1,4 +1,4 @@
1
- import{managedDevTokenEnv as e,managedDevUrlEnv as t}from"@coreframe/scripts/managed-dev-protocol";const n=`/@coreframe/managed-dev`,r=`/__coreframe/managed-dev`;function i({env:i=process.env}={}){let u=i[t],d=i[e],f=!!(u&&d);async function p(e,t){if(!u||!d)throw Error(`Managed development is not configured.`);return fetch(new URL(e,u),{...t,headers:{...t?.headers,Authorization:`Bearer ${d}`,"Content-Type":`application/json`}})}return{name:`coreframe:managed-dev`,apply:`serve`,async configureServer(e){if(!f)return;let t=await p(`/handshake`,{method:`POST`});if(!t.ok){let e=await t.text();throw Error(`Coreframe managed development could not start: ${e}`)}e.middlewares.use(async(e,t,i)=>{if(!e.url){i();return}let u=new URL(e.url,`http://coreframe.local`).pathname;if(u===n){t.statusCode=200,t.setHeader(`Content-Type`,`text/javascript; charset=utf-8`),t.end(l);return}if(u===`${r}/status`&&e.method===`GET`){await a(await p(`/status`),t);return}if(u===`${r}/action`&&e.method===`POST`){if(!s(e.socket.remoteAddress)){c(t,403,{error:`Managed development actions require a loopback client.`});return}await a(await p(`/action`,{body:await o(e),method:`POST`}),t);return}i()})},transformIndexHtml(){if(f)return[{tag:`script`,attrs:{src:n,type:`module`},injectTo:`body`}]}}}async function a(e,t){let n=await e.text();t.statusCode=e.status,t.setHeader(`Content-Type`,e.headers.get(`content-type`)??`application/json`),t.end(n)}async function o(e){let t=``;for await(let n of e)if(t+=String(n),t.length>1e6)throw Error(`Managed development request is too large.`);return t}function s(e){return e===`127.0.0.1`||e===`::1`||e?.startsWith(`::ffff:127.`)}function c(e,t,n){e.statusCode=t,e.setHeader(`Content-Type`,`application/json`),e.end(JSON.stringify(n))}const l=String.raw`
1
+ import{managedDevTokenEnv as e,managedDevUrlEnv as t}from"@coreframe/scripts/managed-dev-protocol";const n=`/__coreframe/managed-dev`;function r({env:r=process.env}={}){let l=r[t],u=r[e],d=!!(l&&u);async function f(e,t){if(!l||!u)throw Error(`Managed development is not configured.`);return fetch(new URL(e,l),{...t,headers:{...t?.headers,Authorization:`Bearer ${u}`,"Content-Type":`application/json`}})}return{name:`coreframe:managed-dev`,apply:`serve`,config(){return{define:{"import.meta.env.COREFRAME_MANAGED_DEV":JSON.stringify(d)}}},async configureServer(e){if(!d)return;let t=await f(`/handshake`,{method:`POST`});if(!t.ok){let e=await t.text();throw Error(`Coreframe managed development could not start: ${e}`)}e.middlewares.use(async(e,t,r)=>{if(!e.url){r();return}let l=new URL(e.url,`http://coreframe.local`).pathname;if(l===`/@coreframe/managed-dev`){t.statusCode=200,t.setHeader(`Content-Type`,`text/javascript; charset=utf-8`),t.end(c);return}if(l===`${n}/status`&&e.method===`GET`){await i(await f(`/status`),t);return}if(l===`${n}/action`&&e.method===`POST`){if(!o(e.socket.remoteAddress)){s(t,403,{error:`Managed development actions require a loopback client.`});return}await i(await f(`/action`,{body:await a(e),method:`POST`}),t);return}r()})}}}async function i(e,t){let n=await e.text();t.statusCode=e.status,t.setHeader(`Content-Type`,e.headers.get(`content-type`)??`application/json`),t.end(n)}async function a(e){let t=``;for await(let n of e)if(t+=String(n),t.length>1e6)throw Error(`Managed development request is too large.`);return t}function o(e){return e===`127.0.0.1`||e===`::1`||e?.startsWith(`::ffff:127.`)}function s(e,t,n){e.statusCode=t,e.setHeader(`Content-Type`,`application/json`),e.end(JSON.stringify(n))}const c=String.raw`
2
2
  const endpoint = "/__coreframe/managed-dev"
3
3
  const channel = new BroadcastChannel("coreframe-managed-dev")
4
4
  let status
@@ -149,4 +149,4 @@ function modeMessage(value) {
149
149
  if (value.target?.source === "local") return "New changes are available in local main."
150
150
  return "A newer main commit is ready."
151
151
  }
152
- `;export{l as browserClientSource,i as coreframeManagedDevPlugin};
152
+ `;export{c as browserClientSource,r as coreframeManagedDevPlugin};
package/dist/preset.js CHANGED
@@ -1 +1 @@
1
- import{coreframeAssetsPlugin as e}from"./assets.js";import{coreframeIconsPlugin as t}from"./icons.js";import{coreframeManagedDevPlugin as n}from"./managed-dev.js";function r(){return[e(),...t(),n()]}export{r as coreframeVitePreset};
1
+ import{coreframeAssetsPlugin as e}from"./assets.js";import{coreframeDashboardPlugin as t}from"./dashboard.js";import{coreframeIconsPlugin as n}from"./icons.js";import{coreframeManagedDevPlugin as r}from"./managed-dev.js";function i(){return[e(),...n(),r(),t()]}export{i as coreframeVitePreset};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreframe/vite",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/airlock-labs/coreframe.git",
@@ -19,6 +19,10 @@
19
19
  "types": "./dist/assets.d.ts",
20
20
  "default": "./dist/assets.js"
21
21
  },
22
+ "./dashboard": {
23
+ "types": "./dist/dashboard.d.ts",
24
+ "default": "./dist/dashboard.js"
25
+ },
22
26
  "./icons": {
23
27
  "types": "./dist/icons.d.ts",
24
28
  "default": "./dist/icons.js"
@@ -41,8 +45,9 @@
41
45
  "@svgr/core": "^8.1.0",
42
46
  "@svgr/plugin-jsx": "^8.1.0",
43
47
  "unplugin-icons": "^23.0.1",
48
+ "@coreframe/dashboard": "^0.0.0",
44
49
  "@coreframe/lib": "^0.1.4",
45
- "@coreframe/scripts": "^0.1.16"
50
+ "@coreframe/scripts": "^0.1.19"
46
51
  },
47
52
  "devDependencies": {
48
53
  "@types/node": "^26.1.0",