@xaendar/build-tools 0.7.2 → 0.7.3
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/build-tools.js +7 -7
- package/package.json +3 -3
package/dist/build-tools.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{isValidCustomElementName as
|
|
2
|
-
Make sure the class has a @WebComponent decorator with a valid selector property`);let
|
|
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
|
-
${
|
|
4
|
+
${s}`),s.replace(i,(a,h,x)=>`${t}
|
|
5
5
|
static {
|
|
6
|
-
${
|
|
7
|
-
}`)}function
|
|
8
|
-
`)}function
|
|
9
|
-
export $2`)}export{
|
|
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.
|
|
3
|
+
"version": "0.7.3",
|
|
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.
|
|
19
|
-
"@xaendar/compiler": "0.7.
|
|
18
|
+
"@xaendar/common": "0.7.3",
|
|
19
|
+
"@xaendar/compiler": "0.7.3",
|
|
20
20
|
"vite": "^8.1.3"
|
|
21
21
|
}
|
|
22
22
|
}
|