@xaendar/build-tools 0.7.2 → 0.7.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.
@@ -1,9 +1,9 @@
1
- import{isValidCustomElementName as b}from"@xaendar/common";import{compile as E}from"@xaendar/compiler";import{dirname as S,resolve as d}from"path";var u=/\.xd\.component\.ts$/;import{existsSync as f,readdirSync as g,readFileSync as h,realpathSync as y,statSync as x}from"fs";import{dirname as $,resolve as w}from"path";var c=class{readFile(t){try{return h(t,"utf-8")}catch{return}}fileExists(t){return f(t)}resolvePath(t,n){return w($(t),n)}getDirectoryEntries(t){try{return g(t)}catch{return[]}}isDirectory(t){try{return x(t).isDirectory()}catch{return!1}}getRealPath(t){try{return y(t)}catch{return t}}getCurrentDirectory(){return process.cwd()}};function W(){let e=new c;return{name:"xaendar",transform(t,n){if(!u.test(n))return null;_(t,n);let{templatePath:r,stylePath:i}=P(t,S(n));if(!r||!e.fileExists(r))return this.warn(`Xaendar: could not find template at ${r}`),null;this.addWatchFile(r);let o=e.readFile(r);if(o===void 0)return this.warn(`Xaendar: could not read template at ${r}`),null;let s;i&&e.fileExists(i)&&(this.addWatchFile(i),s=e.readFile(i));let m,a=s?`__${F(n)}_sheet`:void 0;try{m=E(o,a)}catch(p){this.error(`Xaendar: failed to compile template ${r}: ${String(p)}`)}let l;try{l=N(C(t,m,a,s))}catch(p){this.error(String(p))}return{code:l}}}}function _(e,t){let n=/selector:\s*('[^']*'|"[^"]*"|\[[^\]]*\])/,r=e.match(n);if(!r)throw new Error(`Xaendar: no selector found in component ${t}
2
- Make sure the class has a @WebComponent decorator with a valid selector property`);let i=r[1],o=i.startsWith("[")?[...i.matchAll(/'([^']*)'|"([^"]*)"/g)].map(s=>s[1]??s[2]):[i.slice(1,-1)];for(let s of o)if(!b(s))throw new Error(`Xaendar: invalid custom element name "${s}" in component ${t}`)}function P(e,t){let n=e.match(/templateUrl\s*:\s*["'](.+?)["']/)?.[1],r=e.match(/styleUrl\s*:\s*["'](.+?)["']/)?.[1];return{templatePath:n?d(t,n):void 0,stylePath:r?d(t,r):void 0}}function C(e,t,n,r){let i=r?.trim().length?v(n,r):"",o=e;i&&(o=o.replace(/^(class\s+\w+\s+extends)/m,`${i}$1`));let s=/static\s*\{\s*\n(\s*)(\w+)\(\);\s*\n\s*\}/;if(!s.test(o))throw new Error("Xaendar: 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.");return o=`import { effect, _if, _switch, _for, Context, _iterationVariables, _renderElement, _renderText, _renderLiteralText } from '@xaendar/core';
1
+ import{isValidCustomElementName as P}from"@xaendar/common";import{compile as C}from"@xaendar/compiler";import{dirname as v,resolve as f}from"path";var g=/\.xd\.component\.ts$/;import{existsSync as y,readdirSync as $,readFileSync as w,realpathSync as E,statSync as b}from"fs";import{dirname as S,resolve as _}from"path";var u=class{readFile(t){try{return w(t,"utf-8")}catch{return}}fileExists(t){return y(t)}resolvePath(t,n){return _(S(t),n)}getDirectoryEntries(t){try{return $(t)}catch{return[]}}isDirectory(t){try{return b(t).isDirectory()}catch{return!1}}getRealPath(t){try{return E(t)}catch{return t}}getCurrentDirectory(){return process.cwd()}};function A(){let e=new u;return{name:"xaendar",transform(t,n){if(!g.test(n))return null;F(t,n);let{templatePath:r,stylePath:o}=N(t,v(n));if(!r||!e.fileExists(r))return this.warn(`Xaendar: could not find template at ${r}`),null;this.addWatchFile(r);let s=e.readFile(r);if(s===void 0)return this.warn(`Xaendar: could not read template at ${r}`),null;let i;o&&e.fileExists(o)&&(this.addWatchFile(o),i=e.readFile(o));let m,c=i?`__${M(n)}_sheet`:void 0;try{m=C(s,c)}catch(l){this.error(`Xaendar: failed to compile template ${r}: ${String(l)}`)}let p;try{p=D(R(t,m,c,i))}catch(l){this.error(String(l))}return{code:p}}}}function F(e,t){let n=/selector:\s*('[^']*'|"[^"]*"|\[[^\]]*\])/,r=e.match(n);if(!r)throw new Error(`Xaendar: no selector found in component ${t}
2
+ Make sure the class has a @WebComponent decorator with a valid selector property`);let o=r[1],s=o.startsWith("[")?[...o.matchAll(/'([^']*)'|"([^"]*)"/g)].map(i=>i[1]??i[2]):[o.slice(1,-1)];for(let i of s)if(!P(i))throw new Error(`Xaendar: invalid custom element name "${i}" in component ${t}`)}function N(e,t){let n=e.match(/templateUrl\s*:\s*["'](.+?)["']/)?.[1],r=e.match(/styleUrl\s*:\s*["'](.+?)["']/)?.[1];return{templatePath:n?f(t,n):void 0,stylePath:r?f(t,r):void 0}}function R(e,t,n,r){let o=r?.trim().length?X(n,r):"",s=e;o&&(s=s.replace(/^(class\s+\w+\s+extends)/m,`${o}$1`));let i=/static\s*\{\s*\n(\s*)(\w+)\(\);\s*\n\s*\}/;if(!i.test(s))throw new Error("Xaendar: 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 m=["effect","_if","_switch","_for","Context","_iterationVariables","_renderElement","_renderText","_renderLiteralText"],c=new Set,p=/import\s*\{([^}]+)\}\s*from\s*['"][^'"]+['"]/g,l;for(;(l=p.exec(s))!==null;)l[1]?.split(",").map(a=>a.trim().split(/\s+as\s+/)[0]?.trim()).filter(a=>!!a).forEach(a=>c.add(a));let d=m.filter(a=>!c.has(a));return d.length&&(s=`import { ${d.join(", ")} } from '@xaendar/core';
3
3
 
4
- ${o}`,o.replace(s,(m,a,l)=>`${t}
4
+ ${s}`),s.replace(i,(a,h,x)=>`${t}
5
5
  static {
6
- ${a}${l}();
7
- }`)}function F(e){return e.match(/class\s+(\w+)\s+extends/)?.[1]??"__Component"}function v(e,t){let n=t.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${");return[`const ${e} = new CSSStyleSheet();`,`${e}.replaceSync(\`${n}\`);`,""].join(`
8
- `)}function N(e){return e.replace(/^export\s+(@\w+[\s\S]*?)\s+(class\s)/gm,`$1
9
- export $2`)}export{W as xaendarPlugin};
6
+ ${h}${x}();
7
+ }`)}function M(e){return e.match(/class\s+(\w+)\s+extends/)?.[1]??"__Component"}function X(e,t){let n=t.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${");return[`const ${e} = new CSSStyleSheet();`,`${e}.replaceSync(\`${n}\`);`,""].join(`
8
+ `)}function D(e){return e.replace(/^export\s+(@\w+[\s\S]*?)\s+(class\s)/gm,`$1
9
+ export $2`)}export{A as xaendarPlugin};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaendar/build-tools",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "A library containing build tools for Xaendar framework",
5
5
  "author": "Kaitenjo",
6
6
  "license": "MIT",
@@ -15,8 +15,8 @@
15
15
  "main": "./dist/build-tools.js",
16
16
  "types": "./dist/build-tools.d.ts",
17
17
  "dependencies": {
18
- "@xaendar/common": "0.7.2",
19
- "@xaendar/compiler": "0.7.2",
18
+ "@xaendar/common": "0.7.4",
19
+ "@xaendar/compiler": "0.7.4",
20
20
  "vite": "^8.1.3"
21
21
  }
22
22
  }