@xaendar/build-tools 0.9.3 → 0.9.4
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 +10 -10
- package/package.json +4 -4
package/dist/build-tools.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import{isValidCustomElementName as ee}from"@xaendar/common";import{compile as
|
|
2
|
-
${
|
|
3
|
-
${
|
|
4
|
-
Make sure the class has a @WebComponent decorator with a valid selector property
|
|
1
|
+
import{isValidCustomElementName as ee,slice as te}from"@xaendar/common";import{compile as re}from"@xaendar/compiler";import{basename as ne,dirname as $,extname as ie,resolve as A}from"path";import{findConfigFile as se,parseJsonConfigFileContent as oe,readConfigFile as ae,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 D,sys as u}from"typescript";var g=new Map,_=new Map,v=new Set,y,x;function P(t){let e=x&&JSON.stringify(x)!==JSON.stringify(t);return y&&e&&w(),x=t,y??=U(B(()=>[...v]),W()),y}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 D.fromString(r.content);if(!u.fileExists(e))return;let s=u.readFile(e);if(s!==void 0)return D.fromString(s)},getCurrentDirectory:()=>process.cwd(),getCompilationSettings:()=>x??{},getDefaultLibFileName:e=>J(e),fileExists(e){return g.has(e)||u.fileExists(e)},readFile(e){let r=g.get(e);return r?r.content:u.readFile(e)},readDirectory:u.readDirectory,directoryExists:u.directoryExists,getDirectories:u.getDirectories,realpath:u.realpath}}function w(){y.dispose(),y=void 0,x=void 0,g.clear(),_.clear(),v.clear()}function O(t){v.add(t)}function R(t){v.delete(t)}function q(t){try{let e=N(t),r=String(e.mtimeMs);return _.set(t,r),r}catch{return _.get(t)??"0"}}function V(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 z,readdirSync as G,readFileSync as X,realpathSync as K,statSync as Q}from"fs";import{dirname as Y,resolve as Z}from"path";var C=class{readFile(e){try{return X(e,"utf-8")}catch{return}}fileExists(e){return z(e)}resolvePath(e,r){return Z(Y(e),r)}getDirectoryEntries(e){try{return G(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 F=new Map;function k(t,e){F.set(t,e)}function I(t){return F.get(t)}function H(t){F.delete(t)}function j(){F.clear()}function Ae(){let t=new C,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{le(n,i)}catch(a){return typeof a=="string"&&s(a),null}let o=pe(n),{templatePath:l,stylePath:m}=ce(n,$(i));if(!l||!t.fileExists(l))return this.warn(`Could not find template at ${l}`),null;this.addWatchFile(l),k(l,i);let S=t.readFile(l);if(S===void 0)return this.warn(`Could not read template at ${l}`),null;let d;m&&t.fileExists(m)&&(this.addWatchFile(m),d=t.readFile(m));let h,c,p=d?`__${o}_sheet`:void 0;try{let a=await re(S,$(i),p);h=a.javascript,c=a.typescript}catch(a){return typeof a=="string"&&s(`Failed to compile template
|
|
2
|
+
${l}:
|
|
3
|
+
${a}`),null}let f;try{f=me(ge(n,h,p,d))}catch(a){return typeof a=="string"&&s(a),null}e??=fe($(i)),O(i);let M=`${i}.__typecheck__.ts`;V(M,de(o,i,c));let T=P(e).getSemanticDiagnostics(M);for(let a=0;a<T.length;a++)s(he(l,T[a]));return{code:f}},watchChange(n,i){if(i.event==="delete"){if(E.test(n))b(`${n}.__typecheck__.ts`),R(n);else if(n.endsWith(".html")){let o=I(n);o&&(b(`${o}.__typecheck__.ts`),H(n))}}},configureServer(n){r=n.config?.logger,n.httpServer?.on("close",()=>{j(),w(),r=void 0})}}}function le(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]):[te(n,1,-1)];for(let o=0;o<i.length;o++){let l=i[o];if(!ee(l))throw`Invalid custom element name "${l}" 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?A(e,r):void 0,stylePath:s?A(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"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"],m=new Set,S=/import\s*\{([^}]+)\}\s*from\s*['"][^'"]+['"]/g,d;for(;(d=S.exec(i))!==null;){let c=d[1]?.split(",");if(c)for(let p=0;p<c.length;p++){let f=c[p].trim().split(/\s+as\s+/)[0]?.trim();f&&m.add(f)}}let h=l.filter(c=>!m.has(c));return h.length&&(i=`import { ${h.join(", ")} } from '@xaendar/core';
|
|
5
5
|
|
|
6
|
-
${i}`),i.replace(o,(c,
|
|
6
|
+
${i}`),i.replace(o,(c,p,f)=>`${e}
|
|
7
7
|
static {
|
|
8
|
-
${
|
|
9
|
-
}`)}function
|
|
10
|
-
`)}function
|
|
11
|
-
export $2`)}function
|
|
12
|
-
`)}function
|
|
8
|
+
${p}${f}();
|
|
9
|
+
}`)}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(`
|
|
10
|
+
`)}function me(t){return t.replace(/^export\s+(@\w+[\s\S]*?)\s+(class\s)/gm,`$1
|
|
11
|
+
export $2`)}function fe(t){let e=se(t,L.fileExists,"tsconfig.json");if(!e)return{};let r=ae(e,L.readFile);return oe(r.config,L,$(e)).options}function de(t,e,r){let s=`./${ne(e,ie(e))}`;return[`import { ${t} } from '${s}';`,"",`declare const root: ${t};`,"",r].join(`
|
|
12
|
+
`)}function he(t,e){let r=ye(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 ye(t){return typeof t.messageText=="string"?t.messageText:t.messageText.messageText}export{Ae 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.4",
|
|
4
4
|
"description": "A library containing build tools for Xaendar framework",
|
|
5
5
|
"author": "Kaitenjo",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,9 +15,9 @@
|
|
|
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.
|
|
20
|
-
"vite": "^8.1
|
|
18
|
+
"@xaendar/common": "0.9.4",
|
|
19
|
+
"@xaendar/compiler": "0.9.4",
|
|
20
|
+
"vite": "^8.2.1",
|
|
21
21
|
"typescript": "^6.0.3"
|
|
22
22
|
}
|
|
23
23
|
}
|