@xaendar/build-tools 0.9.5 → 0.9.7

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