@xaendar/build-tools 0.8.0 → 0.9.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.
- package/dist/build-tools.js +5 -5
- package/package.json +3 -3
package/dist/build-tools.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import{isValidCustomElementName as ee}from"@xaendar/common";import{compile as te}from"@xaendar/compiler";import{basename as re,dirname as
|
|
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?
|
|
1
|
+
import{isValidCustomElementName as ee}from"@xaendar/common";import{compile as te}from"@xaendar/compiler";import{basename as re,dirname as $,extname as ne,resolve as j}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 N}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 D(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):X(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 X(t){try{let e=N(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 C=new Map;function V(t,e){C.set(t,e)}function k(t){return C.get(t)}function I(t){C.delete(t)}function H(){C.clear()}function je(){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:a,stylePath:u}=ce(n,$(i));if(!a||!t.fileExists(a))return this.warn(`Could not find template at ${a}`),null;this.addWatchFile(a),V(a,i);let y=t.readFile(a);if(y===void 0)return this.warn(`Could not read template at ${a}`),null;let m;u&&t.fileExists(u)&&(this.addWatchFile(u),m=t.readFile(u));let f,c,x=m?`__${o}_sheet`:void 0;try{let l=await te(y,$(i),x);f=l.javascript,c=l.typescript}catch(l){return s(`Failed to compile template ${a}: ${String(l)}`),null}let S;try{S=ue(le(n,f,x,m))}catch(l){return s(String(l)),null}e??=me($(i)),P(i);let M=`${i}.__typecheck__.ts`;R(M,fe(o,i,c));let A=D(e).getSemanticDiagnostics(M);for(let l of A)s(de(a,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?j(e,r):void 0,stylePath:s?j(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("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"],u=new Set,y=/import\s*\{([^}]+)\}\s*from\s*['"][^'"]+['"]/g,m;for(;(m=y.exec(i))!==null;)m[1]?.split(",").map(c=>c.trim().split(/\s+as\s+/)[0]?.trim()).filter(c=>!!c).forEach(c=>u.add(c));let f=a.filter(c=>!u.has(c));return f.length&&(i=`import { ${f.join(", ")} } from '@xaendar/core';
|
|
3
3
|
|
|
4
|
-
${i}`),i.replace(o,(
|
|
4
|
+
${i}`),i.replace(o,(c,x,S)=>`${e}
|
|
5
5
|
static {
|
|
6
6
|
${x}${S}();
|
|
7
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
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
|
|
10
|
-
`)}function de(t){let
|
|
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,$(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,e){let r=he(e);if(e.file&&e.start!==void 0){let{line:s,character:n}=e.file.getLineAndCharacterOfPosition(e.start);return`${t}:${s+1}:${n+1} - ${r}`}return r}function he(t){return typeof t.messageText=="string"?t.messageText:t.messageText.messageText}export{je as xaendarPlugin};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xaendar/build-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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.
|
|
19
|
-
"@xaendar/compiler": "0.
|
|
18
|
+
"@xaendar/common": "0.9.0",
|
|
19
|
+
"@xaendar/compiler": "0.9.0",
|
|
20
20
|
"vite": "^8.1.5",
|
|
21
21
|
"typescript": "^6.0.3"
|
|
22
22
|
}
|