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