@xaendar/build-tools 0.7.18 → 0.7.20
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 +8 -7
- package/package.json +5 -4
package/dist/build-tools.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import{isValidCustomElementName as
|
|
2
|
-
Make sure the class has a @WebComponent decorator with a valid selector property`);let
|
|
1
|
+
import{isValidCustomElementName as Z}from"@xaendar/common";import{compile as ee}from"@xaendar/compiler";import{basename as te,dirname as _,extname as re,resolve as I}from"path";import{findConfigFile as ne,parseJsonConfigFileContent as ie,readConfigFile as se,sys as w}from"typescript";var F=/\.xd\.component\.ts$/;import{statSync as j}from"fs";import{createDocumentRegistry as A,createLanguageService as N,getDefaultLibFilePath as W,ScriptSnapshot as D,sys as g}from"typescript";var l=new Map,$=new Map,x=new Set,f,d;function T(t){let e=d&&JSON.stringify(d)!==JSON.stringify(t);return f&&e&&C(),d=t,f??=N(U(()=>[...x]),A()),f}function U(t){return{getScriptFileNames:()=>[...t(),...l.keys()],getScriptVersion(e){let r=l.get(e);return r?String(r.version):J(e)},getScriptSnapshot(e){let r=l.get(e);if(r)return D.fromString(r.content);if(!g.fileExists(e))return;let n=g.readFile(e);if(n!==void 0)return D.fromString(n)},getCurrentDirectory:()=>process.cwd(),getCompilationSettings:()=>d??{},getDefaultLibFileName:e=>W(e),fileExists(e){return l.has(e)||g.fileExists(e)},readFile(e){let r=l.get(e);return r?r.content:g.readFile(e)},readDirectory:g.readDirectory,directoryExists:g.directoryExists,getDirectories:g.getDirectories,realpath:g.realpath}}function C(){f.dispose(),f=void 0,d=void 0,l.clear(),$.clear(),x.clear()}function M(t){x.add(t)}function L(t){x.delete(t)}function J(t){try{let e=j(t),r=String(e.mtimeMs);return $.set(t,r),r}catch{return $.get(t)??"0"}}function P(t,e){let r=l.get(t);r?.content!==e&&l.set(t,{content:e,version:(r?.version??0)+1})}function E(t){l.delete(t)}import{existsSync as B,readdirSync as q,readFileSync as z,realpathSync as G,statSync as K}from"fs";import{dirname as Q,resolve as Y}from"path";var S=class{readFile(e){try{return z(e,"utf-8")}catch{return}}fileExists(e){return B(e)}resolvePath(e,r){return Y(Q(e),r)}getDirectoryEntries(e){try{return q(e)}catch{return[]}}isDirectory(e){try{return K(e).isDirectory()}catch{return!1}}getRealPath(e){try{return G(e)}catch{return e}}getCurrentDirectory(){return process.cwd()}};var v=new Map;function O(t,e){v.set(t,e)}function R(t){return v.get(t)}function V(t){v.delete(t)}function k(){v.clear()}function He(){let t=new S,e;return{name:"xaendar",async transform(r,n){if(!F.test(n))return null;oe(r,n);let s=le(n),{templatePath:i,stylePath:o}=ae(r,_(n));if(!i||!t.fileExists(i))return this.warn(`Xaendar: could not find template at ${i}`),null;this.addWatchFile(i),O(i,n);let h=t.readFile(i);if(h===void 0)return this.warn(`Xaendar: could not read template at ${i}`),null;let p;o&&t.fileExists(o)&&(this.addWatchFile(o),p=t.readFile(o));let y,u,m=p?`__${s}_sheet`:void 0;try{let c=ee(h,s,m);y=c.javascript,u=c.typescript}catch(c){this.error(`Xaendar: failed to compile template ${i}: ${String(c)}`)}let a;try{a=pe(ce(r,y,m,p))}catch(c){this.error(String(c))}if(u){e??=ue(_(n)),M(n);let c=`${n}.__typecheck__.ts`;P(c,me(s,n,u));let X=T(e).getSemanticDiagnostics(c);for(let H of X)this.warn(`Xaendar: ${fe(H)}`)}return{code:a}},watchChange(r,n){if(n.event==="delete"){if(F.test(r))E(`${r}.__typecheck__.ts`),L(r);else if(r.endsWith(".html")){let s=R(r);s&&(E(`${s}.__typecheck__.ts`),V(r))}}},configureServer(r){r.httpServer?.on("close",()=>{k(),C()})}}}function oe(t,e){let r=/selector:\s*('[^']*'|"[^"]*"|\[[^\]]*\])/,n=t.match(r);if(!n)throw new Error(`Xaendar: no selector found in component ${e}
|
|
2
|
+
Make sure the class has a @WebComponent decorator with a valid selector property`);let s=n[1],i=s.startsWith("[")?[...s.matchAll(/'([^']*)'|"([^"]*)"/g)].map(o=>o[1]??o[2]):[s.slice(1,-1)];for(let o of i)if(!Z(o))throw new Error(`Xaendar: invalid custom element name "${o}" in component ${e}`)}function ae(t,e){let r=t.match(/templateUrl\s*:\s*["'](.+?)["']/)?.[1],n=t.match(/styleUrl\s*:\s*["'](.+?)["']/)?.[1];return{templatePath:r?I(e,r):void 0,stylePath:n?I(e,n):void 0}}function ce(t,e,r,n){let s=n?.trim().length?ge(r,n):"",i=t;s&&(i=i.replace(/^(class\s+\w+\s+extends)/m,`${s}$1`));let o=/static\s*\{\s*\n(\s*)(\w+)\(\);\s*\n\s*\}/;if(!o.test(i))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 h=["effect","_if","_switch","_for","Context","_iterationVariables","_renderElement","_renderText","_renderLiteralText","createElement","createSVGElement","createMATHMLElement"],p=new Set,y=/import\s*\{([^}]+)\}\s*from\s*['"][^'"]+['"]/g,u;for(;(u=y.exec(i))!==null;)u[1]?.split(",").map(a=>a.trim().split(/\s+as\s+/)[0]?.trim()).filter(a=>!!a).forEach(a=>p.add(a));let m=h.filter(a=>!p.has(a));return m.length&&(i=`import { ${m.join(", ")} } from '@xaendar/core';
|
|
3
3
|
|
|
4
|
-
${
|
|
4
|
+
${i}`),i.replace(o,(a,c,b)=>`${e}
|
|
5
5
|
static {
|
|
6
|
-
${
|
|
7
|
-
}`)}function
|
|
8
|
-
`)}function
|
|
9
|
-
export $2`)}
|
|
6
|
+
${c}${b}();
|
|
7
|
+
}`)}function le(t){return t.match(/class\s+(\w+)\s+extends/)?.[1]??"__Component"}function ge(t,e){let r=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${");return[`const ${t} = new CSSStyleSheet();`,`${t}.replaceSync(\`${r}\`);`,""].join(`
|
|
8
|
+
`)}function pe(t){return t.replace(/^export\s+(@\w+[\s\S]*?)\s+(class\s)/gm,`$1
|
|
9
|
+
export $2`)}function ue(t){let e=ne(t,w.fileExists,"tsconfig.json");if(!e)return{};let r=se(e,w.readFile);return ie(r.config,w,_(e)).options}function me(t,e,r){let n=`./${te(e,re(e))}`;return[`import { ${t} } from '${n}';`,"",`declare const root: ${t};`,"",r].join(`
|
|
10
|
+
`)}function fe(t){let e=de(t);if(t.file&&t.start!==void 0){let{line:r,character:n}=t.file.getLineAndCharacterOfPosition(t.start);return`${t.file.fileName}:${r+1}:${n+1} - ${e}`}return e}function de(t){return typeof t.messageText=="string"?t.messageText:t.messageText.messageText}export{He 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.20",
|
|
4
4
|
"description": "A library containing build tools for Xaendar framework",
|
|
5
5
|
"author": "Kaitenjo",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,8 +15,9 @@
|
|
|
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.
|
|
20
|
-
"vite": "^8.1.
|
|
18
|
+
"@xaendar/common": "0.7.20",
|
|
19
|
+
"@xaendar/compiler": "0.7.20",
|
|
20
|
+
"vite": "^8.1.5",
|
|
21
|
+
"typescript": "^6.0.3"
|
|
21
22
|
}
|
|
22
23
|
}
|