@xaendar/build-tools 0.7.41 → 0.8.0

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