@xaendar/build-tools 0.9.4 → 0.9.6
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 +12 -10
- package/package.json +3 -3
package/dist/build-tools.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import{isValidCustomElementName as
|
|
2
|
-
${
|
|
3
|
-
${
|
|
4
|
-
|
|
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 F,extname as le,resolve as W}from"path";import{findConfigFile as pe,parseJsonConfigFileContent as ge,readConfigFile as ue,sys as O}from"typescript";var L=/\.xd\.component\.ts$/;import{statSync as U}from"fs";import{createDocumentRegistry as J,createLanguageService as B,getDefaultLibFilePath as q,ScriptSnapshot as R,sys as m}from"typescript";var g=new Map,T=new Map,v=new Set,x,S;function D(t){let e=S&&JSON.stringify(S)!==JSON.stringify(t);return x&&e&&P(),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 R.fromString(r.content);if(!m.fileExists(e))return;let s=m.readFile(e);if(s!==void 0)return R.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 P(){x.dispose(),x=void 0,S=void 0,g.clear(),T.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 T.set(t,r),r}catch{return T.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 M(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 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()}import{writeFileSync as me}from"fs";function ze(){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(!L.test(i))return null;try{fe(n,i)}catch(c){return typeof c=="string"&&s(c),null}let o=ye(n),{templatePath:a,stylePath:l}=de(n,F(i));if(!a||!t.fileExists(a))return this.warn(`Could not find template at ${a}`),null;this.addWatchFile(a),H(a,i);let h=t.readFile(a);if(h===void 0)return this.warn(`Could not read template at ${a}`),null;let d;l&&t.fileExists(l)&&(this.addWatchFile(l),d=t.readFile(l));let y,p,u=d?`__${o}_sheet`:void 0;try{let c=await se(h,F(i),u);y=c.javascript,p=c.typescript}catch(c){return typeof c=="string"&&s(`Failed to compile template
|
|
2
|
+
${a}:
|
|
3
|
+
${c}`),null}let f;try{f=Se(he(n,y,u,d))}catch(c){return typeof c=="string"&&s(c),null}e??=ve(F(i)),V(i);let b=`${i}.__typecheck__.ts`,E=$e(o,i,p.text);I(b,E.code),me(b,E.code);let _=D(e).getSemanticDiagnostics(b);if(_.length){let c=ie(h);for(let w=0;w<_.length;w++)s(`Failed to compile template
|
|
4
|
+
${a}:
|
|
5
|
+
${Ce(_[w],E.bodyLineOffset,p.mappingTable,c)}`)}return{code:f}},watchChange(n,i){if(i.event==="delete"){if(L.test(n))M(`${n}.__typecheck__.ts`),k(n);else if(n.endsWith(".html")){let o=j(n);o&&(M(`${o}.__typecheck__.ts`),A(n))}}},configureServer(n){r=n.config?.logger,n.httpServer?.on("close",()=>{N(),P(),r=void 0})}}}function fe(t,e){let r=/selector:\s*('[^']*'|"[^"]*"|\[[^\]]*\])/,s=t.match(r);if(!s)throw`No selector found in component ${e}
|
|
6
|
+
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]):[ne(n,1,-1)];for(let o=0;o<i.length;o++){let a=i[o];if(!re(a))throw`Invalid custom element name "${a}" in component ${e}`}}function de(t,e){let r=t.match(/templateUrl\s*:\s*["'](.+?)["']/)?.[1],s=t.match(/styleUrl\s*:\s*["'](.+?)["']/)?.[1];return{templatePath:r?W(e,r):void 0,stylePath:s?W(e,s):void 0}}function he(t,e,r,s){let n=s?.trim().length?xe(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 a=["effect","_if","_switch","_for","Context","_iterationVariables","_renderElement","_renderText","_renderLiteralText","createElement","createSVGElement","createMATHMLElement"],l=new Set,h=/import\s*\{([^}]+)\}\s*from\s*['"][^'"]+['"]/g,d;for(;(d=h.exec(i))!==null;){let p=d[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
|
-
${i}`),i.replace(o,(
|
|
8
|
+
${i}`),i.replace(o,(p,u,f)=>`${e}
|
|
7
9
|
static {
|
|
8
|
-
${
|
|
9
|
-
}`)}function
|
|
10
|
-
`)}function
|
|
11
|
-
export $2`)}function
|
|
12
|
-
`)}function
|
|
10
|
+
${u}${f}();
|
|
11
|
+
}`)}function ye(t){return t.match(/class\s+(\w+)\s+extends/)?.[1]??"__Component"}function xe(t,e){let r=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${");return[`const ${t} = new CSSStyleSheet();`,`${t}.replaceSync(\`${r}\`);`,""].join(`
|
|
12
|
+
`)}function Se(t){return t.replace(/^export\s+(@\w+[\s\S]*?)\s+(class\s)/gm,`$1
|
|
13
|
+
export $2`)}function ve(t){let e=pe(t,O.fileExists,"tsconfig.json");if(!e)return{};let r=ue(e,O.readFile);return ge(r.config,O,F(e)).options}function $e(t,e,r){let s=`./${ce(e,le(e))}`,n=[`import { ${t} } from '${s}';`,"",`declare const root: ${t};`,""];return{code:[...n,r].join(`
|
|
14
|
+
`),bodyLineOffset:n.length}}function Ce(t,e,r,s){let n=typeof t.messageText=="string"?t.messageText:t.messageText.messageText;if(!t.file||t.start===void 0)return n;let i=t.file.getLineAndCharacterOfPosition(t.start),o=i.line-e;if(o<0)return`(shim ${i.line+1}:${i.character+1}) - ${n}`;let a=ae(r,{line:o,character:i.character});if(!a)return`(shim ${i.line+1}:${i.character+1}) - ${n}`;let l=oe(s,a.start);return`${l.line+1}:${l.character+1} - ${n}`}export{ze as xaendarPlugin};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xaendar/build-tools",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
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.
|
|
19
|
-
"@xaendar/compiler": "0.9.
|
|
18
|
+
"@xaendar/common": "0.9.6",
|
|
19
|
+
"@xaendar/compiler": "0.9.6",
|
|
20
20
|
"vite": "^8.2.1",
|
|
21
21
|
"typescript": "^6.0.3"
|
|
22
22
|
}
|