@amaster.ai/vite-plugins 1.1.20 → 1.1.22
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/index.cjs +13 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +13 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default {};`}function
|
|
1
|
+
import v,{readFileSync}from'fs';import p,{dirname,resolve}from'path';import {fileURLToPath}from'url';import j from'process';import x from'fs/promises';import q from'@babel/generator';import {parse}from'@babel/parser';import H from'@babel/traverse';import {TraceMap,originalPositionFor}from'@jridgewell/trace-mapping';var $=fileURLToPath(import.meta.url),Q=dirname($),L="@amaster/bridge-monitor",I="\0"+L,h=null;function Y(){if(h)return h;try{let e=resolve(Q,"../dist/bridge-module.global.js");return h=readFileSync(e,"utf-8"),h}catch(e){return console.warn("[editor-bridge] Failed to load pre-built bridge module:",e),""}}function G(){return '<script type="module" src="/@id/@amaster/bridge-monitor"></script>'}function Z(e){return Y().replace(/__SESSION_KEY__/g,e)+`
|
|
2
|
+
export default {};`}function D(){let e=false;return {name:"vite-plugin-editor-bridge",configResolved(r){e=r.command==="serve";},resolveId(r){if(r===L)return I},load(r){if(r===I){let t=process.env.VITE_AMASTER_KEY||"";return Z(t)}},transformIndexHtml(r){if(!e)return r;let t=G();return r.replace("</body>",`${t}</body>`)}}}function k(e){let r=false,t=e?.routesFilePath||"src/routes.tsx";return {name:"vite-plugin-routes-expose",enforce:"post",configResolved(n){r=n.command==="serve";},transform(n,o){if(!r||!o.endsWith(t))return null;try{return n.includes("window.__APP_ROUTES__")?null:{code:`${n}
|
|
3
3
|
|
|
4
4
|
// Development mode: Expose routes to window.__APP_ROUTES__
|
|
5
5
|
if (typeof window !== 'undefined') {
|
|
6
6
|
window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];
|
|
7
7
|
}
|
|
8
|
-
`,map:null}}catch{return null}}}}function
|
|
8
|
+
`,map:null}}catch{return null}}}}function M(){let e="",r=`
|
|
9
9
|
<script>
|
|
10
10
|
(function() {
|
|
11
11
|
'use strict';
|
|
@@ -812,9 +812,9 @@ if (typeof window !== 'undefined') {
|
|
|
812
812
|
|
|
813
813
|
originalConsole.log('[BrowserLogs] Log collection started');
|
|
814
814
|
})();
|
|
815
|
-
</script>`;return {name:"vite-plugin-browser-logs",configResolved(t){let
|
|
816
|
-
`):d&&typeof d=="object"&&(
|
|
817
|
-
`,"utf-8"),o.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":a,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:!0}));}catch(
|
|
815
|
+
</script>`;return {name:"vite-plugin-browser-logs",configResolved(t){let n=j.env.WORKSPACE_DIR;if(n)e=p.join(n,"browser.log");else {let o=t.root||j.cwd();for(;o!==p.dirname(o)&&!v.existsSync(p.join(o,"package.json"));)o=p.dirname(o);e=p.join(o,"browser.log");}},configureServer(t){t.middlewares.use((n,o,u)=>{if(n.url==="/__browser__"&&n.method==="POST"){let a=n.headers.origin||"*",l="";n.on("data",c=>{l+=c.toString();}),n.on("end",()=>{try{let c=l,d;try{d=JSON.parse(l);}catch{d=null;}Array.isArray(d)?c=d.map(s=>JSON.stringify(s)).join(`
|
|
816
|
+
`):d&&typeof d=="object"&&(c=JSON.stringify(d));let i=p.dirname(e);v.existsSync(i)||v.mkdirSync(i,{recursive:!0}),v.appendFileSync(e,`${c}
|
|
817
|
+
`,"utf-8"),o.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":a,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:!0}));}catch(c){console.error("[BrowserLogs] Write error:",c),o.writeHead(500,{"Content-Type":"application/json","Access-Control-Allow-Origin":a,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:false,error:String(c)}));}});}else if(n.url==="/__browser__"&&n.method==="OPTIONS"){let a=n.headers.origin||"*";o.writeHead(204,{"Access-Control-Allow-Origin":a,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type","Access-Control-Max-Age":"86400"}),o.end();}else if(n.url==="/__browser__"){let a=n.headers.origin||"*";o.writeHead(405,{"Content-Type":"application/json","Access-Control-Allow-Origin":a}),o.end(JSON.stringify({error:"Method not allowed"}));}else u();}),console.log("[BrowserLogs] Logs will be written to:",e);},transformIndexHtml(t){return t.replace(/<head([^>]*)>/i,`<head$1>${r}`)}}}var ee=`
|
|
818
818
|
import * as React from "react";
|
|
819
819
|
import * as ReactJSXDevRuntime from "react/jsx-dev-runtime";
|
|
820
820
|
|
|
@@ -996,14 +996,14 @@ export function jsxDEV(type, props, key, isStatic, source, self) {
|
|
|
996
996
|
|
|
997
997
|
return _jsxDEV(type, props, key, isStatic, source, self);
|
|
998
998
|
}
|
|
999
|
-
`;function
|
|
999
|
+
`;function _(e={}){let r=false,t="";return {name:"vite-plugin-jsx-source-tagger",enforce:"pre",configResolved(n){r=n.command==="serve",t=e.projectRoot||n.root;},resolveId(n,o){return r&&n==="react/jsx-dev-runtime"&&!o?.includes("\0jsx-source")?"\0jsx-source/jsx-dev-runtime":null},load(n){return r&&n==="\0jsx-source/jsx-dev-runtime"?ee.replace('const PROJECT_ROOT = "";',`const PROJECT_ROOT = ${JSON.stringify(t)};`):null}}}function E(e){let r="",t=false,n=null,o=null,u=e?.configPath||"./tailwind.config.ts",a="@amaster/tailwind-config",l="\0"+a,c=async()=>{let i=p.resolve(r,u);try{return await x.access(i),i}catch{if(u.endsWith(".ts")){let s=i.replace(/\.ts$/,".js");try{return await x.access(s),s}catch{return null}}else if(u.endsWith(".js")){let s=i.replace(/\.js$/,".ts");try{return await x.access(s),s}catch{return null}}return null}},d=async i=>{try{let s=await c();if(!s)return null;if(i){let A=await i.ssrLoadModule(s);return n=A.default||A,n}let f=await import(`file://${s}?t=${Date.now()}`);return n=f.default||f,n}catch(s){return console.error("[tailwind-config-sync] Failed to generate config:",s),null}};return {name:"vite-plugin-tailwind-config-sync",configResolved(i){r=i.root,t=i.command==="serve";},async buildStart(){t&&await d();},resolveId(i){if(i===a)return l},async load(i){if(i===l)return await d(o),n?`
|
|
1000
1000
|
// Use global variable to persist callbacks and current config across HMR updates
|
|
1001
1001
|
if (!window.__tailwindConfigCallbacks) {
|
|
1002
1002
|
window.__tailwindConfigCallbacks = [];
|
|
1003
1003
|
}
|
|
1004
1004
|
|
|
1005
1005
|
// Always update current config with the latest from server
|
|
1006
|
-
let tailwindConfigCurrent = ${JSON.stringify(
|
|
1006
|
+
let tailwindConfigCurrent = ${JSON.stringify(n)};
|
|
1007
1007
|
|
|
1008
1008
|
if (import.meta.hot) {
|
|
1009
1009
|
// Accept self updates
|
|
@@ -1033,12 +1033,12 @@ export function onUpdate(fn) {
|
|
|
1033
1033
|
};
|
|
1034
1034
|
export default tailwindConfigCurrent;
|
|
1035
1035
|
|
|
1036
|
-
`:"export default null;"},configureServer(i){t&&(o=i,(async()=>{try{let s=await
|
|
1036
|
+
`:"export default null;"},configureServer(i){t&&(o=i,(async()=>{try{let s=await c();s&&i.watcher.add(s);}catch{}})());},async handleHotUpdate({file:i,server:s}){let m=await c();if(!m||p.normalize(i)!==p.normalize(m))return;let f=s.moduleGraph.getModuleById(m);f&&s.moduleGraph.invalidateModule(f),await d(s);let y=s.moduleGraph.getModuleById(l);return y?(s.moduleGraph.invalidateModule(y),[y]):[]}}}function R(e={}){let{designWidth:r=375,maxWidth:t=750,baseFontSize:n=12,minRootSize:o=12,maxRootSize:u=24}=e;return {name:"vite-plugin-taro-style-adapter",apply:"serve",transformIndexHtml(a){let l=`
|
|
1037
1037
|
<script data-taro-flexible="true">
|
|
1038
1038
|
(function() {
|
|
1039
|
-
var designWidth = ${
|
|
1039
|
+
var designWidth = ${r};
|
|
1040
1040
|
var maxWidth = ${t};
|
|
1041
|
-
var baseFontSize = ${
|
|
1041
|
+
var baseFontSize = ${n};
|
|
1042
1042
|
var minRootSize = ${o};
|
|
1043
1043
|
var maxRootSize = ${u};
|
|
1044
1044
|
|
|
@@ -1074,7 +1074,7 @@ export default tailwindConfigCurrent;
|
|
|
1074
1074
|
document.addEventListener('DOMContentLoaded', setRootFontSize);
|
|
1075
1075
|
})();
|
|
1076
1076
|
</script>
|
|
1077
|
-
`;return a.replace("</head>",`${
|
|
1077
|
+
`;return a.replace("</head>",`${l}
|
|
1078
1078
|
<style data-taro-adapter="true">
|
|
1079
1079
|
/* \u4EC5 H5 \u751F\u6548\uFF1A\u9690\u85CF Taro \u9875\u9762\u5BB9\u5668\u6EDA\u52A8\u6761\uFF0C\u4F46\u4ECD\u53EF\u6EDA\u52A8 */
|
|
1080
1080
|
.taro_page {
|
|
@@ -1120,5 +1120,5 @@ export default tailwindConfigCurrent;
|
|
|
1120
1120
|
object-fit: contain;
|
|
1121
1121
|
}
|
|
1122
1122
|
</style>
|
|
1123
|
-
</head>`)}}}function
|
|
1123
|
+
</head>`)}}}function S(e={}){let{ratio:r=2}=e;return {postcssPlugin:"postcss-rpx2px",Declaration(t){t.value?.includes("rpx")&&(t.value=t.value.replace(/(-?\d*\.?\d+)rpx/gi,(n,o)=>{let u=parseFloat(o)/r;return u===0?"0":`${u}px`}));}}}S.postcss=true;var te=/(-?\d*\.?\d+)rpx/gi,ne=q.default??q,oe=H.default??H;function O(e,r){return e.replace(te,(t,n)=>{let o=Number.parseFloat(n)/r;return o===0?"0":`${o}px`})}function se(e,r){if(!e.value.includes("rpx"))return false;let t=O(e.value,r);return t===e.value?false:(e.value=t,e.extra?.raw&&(e.extra.rawValue=t,e.extra.raw=JSON.stringify(t)),true)}function ie(e,r){let t=e.value.raw;if(!t.includes("rpx"))return false;let n=O(t,r),o=e.value.cooked==null?void 0:O(e.value.cooked,r);return n===t&&o===e.value.cooked?false:(e.value.raw=n,e.value.cooked=o,true)}function ae(e){return e.name.type==="JSXIdentifier"&&e.name.name==="style"}function ue(e,r){let t=false;return e.traverse({StringLiteral(n){se(n.node,r)&&(t=true);},TemplateElement(n){ie(n.node,r)&&(t=true);}}),t}function B(e,r=2){let t=parse(e,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:true}),n=false;return oe(t,{JSXAttribute(o){if(!ae(o.node)||o.node.value?.type!=="JSXExpressionContainer")return;let u=o.get("value");u.isJSXExpressionContainer()&&ue(u,r)&&(n=true);}}),n?{changed:true,code:ne(t,{retainLines:true,decoratorsBeforeExport:true,jsescOption:{minimal:true}},e).code}:{changed:false,code:e}}function T(e={}){let{ratio:r=2}=e;return {name:"vite-plugin-jsx-inline-style-rpx",enforce:"pre",transform(t,n){if(process.env.TARO_ENV!=="h5"||!/\.[jt]sx($|\?)/.test(n))return null;let o=B(t,r);return o.changed?{code:o.code,map:null}:null}}}function P(){return {name:"vite-plugin-taro-jsx-dev-source",apply:"serve",enforce:"post",config(e){let r=typeof e.esbuild=="object"&&e.esbuild?e.esbuild:{};e.esbuild={...r,jsxDev:true};}}}var pe=H.default??H;function fe(e){return e.split("?",1)[0]||e}function ge(e){let r=fe(e);return /\.[cm]?[jt]sx$/.test(r)&&!r.includes("/node_modules/")}function z(e){let r=e.key;return r.type==="Identifier"?r.name:r.type==="StringLiteral"?r.value:""}function g(e,r){return e.properties.find(t=>t.type==="ObjectProperty"&&z(t)===r)}function b(e){return e?.value.type==="NumericLiteral"}function me(e){return e?.value.type==="StringLiteral"}function ye(e){return e.type==="Identifier"&&e.name==="jsxDEV"}function he(e){return z(e)==="children"}function ve(e){let r=e.arguments[1];if(r?.type==="ObjectExpression"){let t=r.properties.find(n=>n.type==="ObjectProperty"&&!he(n));if(t)return t.value}return e.callee}function Se(e){return e.type!=="ObjectExpression"?false:me(g(e,"fileName"))&&b(g(e,"lineNumber"))&&b(g(e,"columnNumber"))}function U(e,r,t){r.value===t||r.start==null||r.end==null||e.push({start:r.start,end:r.end,value:String(t)});}function be(e,r){return r.sort((t,n)=>n.start-t.start).reduce((t,n)=>t.slice(0,n.start)+n.value+t.slice(n.end),e)}function J(e,r){if(!r||!e.includes("jsxDEV"))return null;let t=new TraceMap(r),n=[],o;try{o=parse(e,{sourceType:"module",plugins:["jsx","typescript"]});}catch{return null}return pe(o,{CallExpression(u){let a=u.node;if(!ye(a.callee))return;let l=a.arguments[4];if(!l||l.type==="SpreadElement"||l.type==="ArgumentPlaceholder"||!Se(l))return;let c=ve(a);if(!c.loc)return;let d=originalPositionFor(t,{line:c.loc.start.line,column:c.loc.start.column});if(d.line==null||d.column==null)return;let i=g(l,"lineNumber"),s=g(l,"columnNumber");!b(i)||!b(s)||(U(n,i.value,d.line),U(n,s.value,d.column+1));}}),n.length===0?null:be(e,n)}function C(){let e=false;return {name:"vite-plugin-jsx-source-map-remap",enforce:"post",configResolved(r){e=r.command==="serve";},transform(r,t){if(!e||!ge(t))return null;let n=this.getCombinedSourcemap;if(typeof n!="function")return null;let o=n.call(this);if(!o||!o.mappings)return null;let u=J(r,o);return u?{code:u,map:o}:null}}}function _e(e={}){let{additional:r=[],autoInjectTaroApp:t=true,autoInjectVite:n=true}=e,o={},u=new Set(r);return t&&Object.keys(process.env).forEach(a=>{a.startsWith("TARO_APP_")&&u.add(a);}),n&&Object.keys(process.env).forEach(a=>{a.startsWith("VITE_")&&u.add(a);}),u.forEach(a=>{let l=process.env[a]||"";o[`process.env.${a}`]=JSON.stringify(l);}),o}function xe(){return {"process.env.TARO_APP_API_BASE_URL":JSON.stringify(process.env.TARO_APP_API_BASE_URL||""),"process.env.VITE_API_BASE_URL":JSON.stringify(process.env.VITE_API_BASE_URL||""),"process.env.API_BASE_URL":JSON.stringify(process.env.API_BASE_URL||"")}}function we(e={}){let r=e.isTaro??j.env.TARO_ENV==="h5",t=[D(),k()];return e.jsxSourceTagger!==false&&t.push(_({projectRoot:r?j.cwd():void 0})),e.tailwindConfigSync!==false&&t.push(E({configPath:e.tailwindConfigPath})),r&&(e.jsxSourceTagger!==false&&(t.push(P()),t.push(C())),t.unshift(T()),t.unshift(R(e.styleAdapter)),t.unshift({name:"dev-postcss-rpx2px-plugin",apply:"serve",config(n){typeof n.css?.postcss=="object"&&n.css?.postcss.plugins?.unshift(S());}})),j.env.WORKSPACE_GIT_REPO&&t.push(M()),t}export{we as default,D as editorBridgePlugin,xe as injectAmasterEnv,_e as injectTaroEnv,T as jsxInlineStyleRpxPlugin,C as jsxSourceMapRemapPlugin,_ as jsxSourceTaggerPlugin,J as remapJsxDevSourceLocations,k as routesExposePlugin,S as rpx2pxPlugin,E as tailwindConfigSyncPlugin,P as taroJsxDevSourcePlugin,R as taroStyleAdapterPlugin,B as transformJsxInlineStyleRpx};//# sourceMappingURL=index.js.map
|
|
1124
1124
|
//# sourceMappingURL=index.js.map
|