@xaendar/build-tools 0.9.13 → 0.9.15

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