@xaendar/build-tools 0.9.28 → 0.9.30

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.
@@ -1,7 +1,7 @@
1
- import{isValidCustomElementName as z,slice as L}from"@xaendar/common";import{compile as G,Cursor as U,extractSignalMembers as X,resolveTemplateSpan as q}from"@xaendar/compiler";import{createShim as J,disposeLanguageService as K,extractClassName as Q,extractDecoratorPaths as Y,getLanguageService as Z,loadCompilerOptions as ee,registerRealFile as te,removeRealFile as re,removeVirtualFile as T}from"@xaendar/language-core";import{dirname as $,resolve as ne}from"path";var b=/\.xd\.component\.ts$/;var y=new Map,v=new Map;function E(t,e){y.getOrInsert(t,new Set).add(e),v.getOrInsert(e,new Set).add(t)}function F(t){return y.get(t)??new Set}function C(t){let e=v.get(t);if(e)for(let s of e){let i=y.get(s);i&&(i.delete(t),i.size||y.delete(s))}v.delete(t)}function M(){y.clear(),v.clear()}import{existsSync as A,readdirSync as N,readFileSync as V,realpathSync as W,statSync as j}from"fs";import{dirname as B,resolve as H}from"path";var S=class{readFile(e){try{return V(e,"utf-8")}catch{return}}fileExists(e){return A(e)}resolvePath(e,s){return H(B(e),s)}getDirectoryEntries(e){try{return N(e)}catch{return[]}}isDirectory(e){try{return j(e).isDirectory()}catch{return!1}}getRealPath(e){try{return W(e)}catch{return e}}getCurrentDirectory(){return process.cwd()}};var h=new Map;function I(t,e){h.set(t,e)}function R(t){return h.get(t)}function O(t){h.delete(t)}function k(t){for(let[e,s]of h)s===t&&h.delete(e)}function D(){h.clear()}function Te(){let t=new S,e,s,i=r=>{let n=`\x1B[31m\rXaendar: ${r}\x1B[0m`;(s??console).error(n.replace(/^Error:\s*/,""))};return{name:"xaendar",async transform(r,n){if(!b.test(n))return null;try{oe(r,n)}catch(c){return typeof c=="string"&&i(c),null}let a=Q(r),{templatePath:o,stylePath:p}=Y(r,$(n));if(!o||!t.fileExists(o))return this.warn(`Could not find template at ${o}`),null;this.addWatchFile(o),I(o,n);let g=t.readFile(o);if(g===void 0)return this.warn(`Could not read template at ${o}`),null;C(n);for(let c of se(g,$(o)))t.fileExists(c)&&(this.addWatchFile(c),E(c,n));let f;p&&t.fileExists(p)&&(this.addWatchFile(p),f=t.readFile(p));let x,l,u=f?`__${a}_sheet`:void 0;try{let c=X(r,a,n),_=await G(g,{baseDir:$(o),cssVariableName:u,signals:c});x=_.javascript,l=_.typescript}catch(c){return i(`Failed to compile template - ${o}
2
- ${c instanceof Error?c.message:c}`),null}let m;try{m=ce(ie(r,x,u,f))}catch(c){return typeof c=="string"&&i(c),null}e??=ee($(n)),te(n);let d=J(new Map([[n,[a]]]),l),w=Z(e).getSemanticDiagnostics(d.path);for(let c=0;c<w.length;c++)i(`Failed to compile template - ${o}
3
- ${le(g,w[c],d.bodyLineOffset,l.mappingTable)}`);return w.length?null:{code:m}},watchChange(r,n){if(n.event==="delete"){if(b.test(r)){T(`${r}.__typecheck__.ts`),re(r),k(r);let a=F(r);for(let o of a)T(`${o}.__typecheck__.ts`),i(`Component "${r}" was deleted but is still imported by "${o}". Update its @import statement.`);C(r)}else if(r.endsWith(".html")){let a=R(r);a&&(T(`${a}.__typecheck__.ts`),O(r))}}},configureServer(r){s=r.config?.logger,r.httpServer?.on("close",()=>{D(),M(),K(),s=void 0})}}}function oe(t,e){let s=/selector:\s*('[^']*'|"[^"]*"|\[[^\]]*\])/,i=t.match(s);if(!i)throw`No selector found in component ${e}
4
- Make sure the class has a @WebComponent decorator with a valid selector property`;let r=i[1],n=r.startsWith("[")?[...r.matchAll(/'([^']*)'|"([^"]*)"/g)].map(a=>a[1]??a[2]):[L(r,1,-1)];for(let a=0;a<n.length;a++){let o=n[a];if(!z(o))throw`Invalid custom element name "${o}" in component ${e}`}}function se(t,e){let s=/@import\s*\{[^}]*\}\s*from\s*['"](.+?)['"]/g,i=new Array,r;for(;(r=s.exec(t))!==null;)i.push(ne(e,r[1]));return i}function ie(t,e,s,i){let r=i?.trim().length?ae(s,i):"",n=t;r&&(n=n.replace(/^(class\s+\w+\s+extends)/m,`${r}$1`));let a=/static\s*\{\s*\n(\s*)(\w+)\(\);\s*\n\s*\}/;if(!a.test(n))throw"Could not find the static initializer block in the transpiled output. Make sure @rolldown/plugin-babel with @babel/plugin-proposal-decorators runs before xaendarPlugin() in your Vite config.";let o=[{value:"effect",source:"@xaendar/core/signals"},{value:"_if",source:"@xaendar/core"},{value:"_switch",source:"@xaendar/core"},{value:"_for",source:"@xaendar/core"},{value:"Context",source:"@xaendar/core"},{value:"_iterationVariables",source:"@xaendar/core"},{value:"_renderElement",source:"@xaendar/core"},{value:"_renderText",source:"@xaendar/core"},{value:"_renderLiteralText",source:"@xaendar/core"},{value:"createElement",source:"@xaendar/core"},{value:"createSVGElement",source:"@xaendar/core"},{value:"createMATHMLElement",source:"@xaendar/core"}],p=new Array,g=/import\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]/g,f;for(;(f=g.exec(n))!==null;){let l=f[1]?.split(","),u=f[2];if(l)for(let m=0;m<l.length;m++){let d=l[m].trim().split(/\s+as\s+/)[0]?.trim();d&&p.push({value:d,source:u})}}let x=o.filter(l=>!p.some(u=>u.value===l.value&&u.source===l.source));if(x.length){let l=Map.groupBy(x,m=>m.source);n=`${Array.from(l,([m,d])=>`import { ${d.map(P=>P.value).join(", ")} } from '${m}';`).join(`
1
+ import{isValidCustomElementName as z,slice as D}from"@xaendar/common";import{compile as G,Cursor as U,extractSignalMembers as X,resolveTemplateSpan as q}from"@xaendar/compiler";import{createShim as J,disposeLanguageService as K,extractClassName as Q,extractDecoratorPaths as Y,getLanguageService as Z,loadCompilerOptions as ee,registerRealFile as te,removeRealFile as re,removeVirtualFile as T}from"@xaendar/language-core";import{dirname as $,resolve as ne}from"path";var w=/\.xd\.component\.ts$/;var y=new Map,v=new Map;function E(t,e){y.getOrInsert(t,new Set).add(e),v.getOrInsert(e,new Set).add(t)}function F(t){return y.get(t)??new Set}function C(t){let e=v.get(t);if(e)for(let s of e){let i=y.get(s);i&&(i.delete(t),i.size||y.delete(s))}v.delete(t)}function M(){y.clear(),v.clear()}import{existsSync as L,readdirSync as N,readFileSync as V,realpathSync as W,statSync as j}from"fs";import{dirname as B,resolve as H}from"path";var S=class{readFile(e){try{return V(e,"utf-8")}catch{return}}fileExists(e){return L(e)}resolvePath(e,s){return H(B(e),s)}getDirectoryEntries(e){try{return N(e)}catch{return[]}}isDirectory(e){try{return j(e).isDirectory()}catch{return!1}}getRealPath(e){try{return W(e)}catch{return e}}getCurrentDirectory(){return process.cwd()}};var h=new Map;function I(t,e){h.set(t,e)}function R(t){return h.get(t)}function A(t){h.delete(t)}function O(t){for(let[e,s]of h)s===t&&h.delete(e)}function k(){h.clear()}function Te(){let t=new S,e,s,i=r=>{let n=`\x1B[31m\rXaendar: ${r}\x1B[0m`;(s??console).error(n.replace(/^Error:\s*/,""))};return{name:"xaendar",async transform(r,n){if(!w.test(n))return null;try{oe(r,n)}catch(c){return typeof c=="string"&&i(c),null}let a=Q(r),{templatePath:o,stylePath:p}=Y(r,$(n));if(!o||!t.fileExists(o))return this.warn(`Could not find template at ${o}`),null;this.addWatchFile(o),I(o,n);let g=t.readFile(o);if(g===void 0)return this.warn(`Could not read template at ${o}`),null;C(n);for(let c of se(g,$(o)))t.fileExists(c)&&(this.addWatchFile(c),E(c,n));let f;p&&t.fileExists(p)&&(this.addWatchFile(p),f=t.readFile(p));let x,l,u=f?`__${a}_sheet`:void 0;try{let c=X(r,a,n),_=await G(g,{baseDir:$(o),cssVariableName:u,signals:c});x=_.javascript,l=_.typescript}catch(c){return i(`Failed to compile template - ${o}
2
+ ${c instanceof Error?c.message:c}`),null}let m;try{m=ce(ie(r,x,u,f))}catch(c){return typeof c=="string"&&i(c),null}e??=ee($(n)),te(n);let d=J(new Map([[n,[a]]]),l),b=Z(e).getSemanticDiagnostics(d.path);for(let c=0;c<b.length;c++)i(`Failed to compile template - ${o}
3
+ ${le(g,b[c],d.bodyLineOffset,l.mappingTable)}`);return b.length?null:{code:m}},watchChange(r,n){if(n.event==="delete"){if(w.test(r)){T(`${r}.__typecheck__.ts`),re(r),O(r);let a=F(r);for(let o of a)T(`${o}.__typecheck__.ts`),i(`Component "${r}" was deleted but is still imported by "${o}". Update its @import statement.`);C(r)}else if(r.endsWith(".html")){let a=R(r);a&&(T(`${a}.__typecheck__.ts`),A(r))}}},configureServer(r){s=r.config?.logger,r.httpServer?.on("close",()=>{k(),M(),K(),s=void 0})}}}function oe(t,e){let s=/selector:\s*('[^']*'|"[^"]*"|\[[^\]]*\])/,i=t.match(s);if(!i)throw`No selector found in component ${e}
4
+ Make sure the class has a @WebComponent decorator with a valid selector property`;let r=i[1],n=r.startsWith("[")?[...r.matchAll(/'([^']*)'|"([^"]*)"/g)].map(a=>a[1]??a[2]):[D(r,1,-1)];for(let a=0;a<n.length;a++){let o=n[a];if(!z(o))throw`Invalid custom element name "${o}" in component ${e}`}}function se(t,e){let s=/@import\s*\{[^}]*\}\s*from\s*['"](.+?)['"]/g,i=new Array,r;for(;(r=s.exec(t))!==null;)i.push(ne(e,r[1]));return i}function ie(t,e,s,i){let r=i?.trim().length?ae(s,i):"",n=t;r&&(n=n.replace(/^(class\s+\w+\s+extends)/m,`${r}$1`));let a=/static\s*\{\s*\n(\s*)(\w+)\(\);\s*\n\s*\}/;if(!a.test(n))throw"Could not find the static initializer block in the transpiled output. Make sure @rolldown/plugin-babel with @babel/plugin-proposal-decorators runs before xaendarPlugin() in your Vite config.";let o=[{value:"effect",source:"@xaendar/core/signals"},{value:"_if",source:"@xaendar/core"},{value:"_switch",source:"@xaendar/core"},{value:"_for",source:"@xaendar/core"},{value:"Context",source:"@xaendar/core"},{value:"_iterationVariables",source:"@xaendar/core"},{value:"_renderElement",source:"@xaendar/core"},{value:"_renderText",source:"@xaendar/core"},{value:"_renderLiteralText",source:"@xaendar/core"},{value:"createElement",source:"@xaendar/core"},{value:"createSVGElement",source:"@xaendar/core"},{value:"createMATHMLElement",source:"@xaendar/core"},{value:"bindAttribute",source:"@xaendar/core"},{value:"bindReactiveAttribute",source:"@xaendar/core"}],p=new Array,g=/import\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]/g,f;for(;(f=g.exec(n))!==null;){let l=f[1]?.split(","),u=f[2];if(l)for(let m=0;m<l.length;m++){let d=l[m].trim().split(/\s+as\s+/)[0]?.trim();d&&p.push({value:d,source:u})}}let x=o.filter(l=>!p.some(u=>u.value===l.value&&u.source===l.source));if(x.length){let l=Map.groupBy(x,m=>m.source);n=`${Array.from(l,([m,d])=>`import { ${d.map(P=>P.value).join(", ")} } from '${m}';`).join(`
5
5
  `)}
6
6
 
7
7
  ${n}`}return n.replace(a,(l,u,m)=>`${e}
@@ -10,4 +10,4 @@ ${u}${m}();
10
10
  }`)}function ae(t,e){let s=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${");return[`const ${t} = new CSSStyleSheet();`,`${t}.replaceSync(\`${s}\`);`,""].join(`
11
11
  `)}function ce(t){return t.replace(/^export\s+(@\w+[\s\S]*?)\s+(class\s)/gm,`$1
12
12
  export $2`)}function le(t,e,s,i){let r=typeof e.messageText=="string"?e.messageText:e.messageText.messageText,n=new U(t);if(!e.file||e.start===void 0)return r;let a=e.file.getLineAndCharacterOfPosition(e.start),o=a.line-s;if(o<0)return r;let p=q(i,{line:o,character:a.character});return p?`${n.getPositionFromCharacterIndex(p.start)} - ${r}
13
- ---> ${L(t,p.start,p.end)}`:r}export{Te as xaendarPlugin};
13
+ ---> ${D(t,p.start,p.end)}`:r}export{Te as xaendarPlugin};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaendar/build-tools",
3
- "version": "0.9.28",
3
+ "version": "0.9.30",
4
4
  "description": "A library containing build tools for Xaendar framework",
5
5
  "author": "Kaitenjo",
6
6
  "license": "MIT",
@@ -15,9 +15,9 @@
15
15
  "main": "./dist/build-tools.js",
16
16
  "types": "./dist/build-tools.d.ts",
17
17
  "dependencies": {
18
- "@xaendar/common": "0.9.28",
19
- "@xaendar/compiler": "0.9.28",
20
- "@xaendar/language-core": "0.9.28",
18
+ "@xaendar/common": "0.9.30",
19
+ "@xaendar/compiler": "0.9.30",
20
+ "@xaendar/language-core": "0.9.30",
21
21
  "typescript": "^6.0.3",
22
22
  "vite": "^8.2.2"
23
23
  }