@amaster.ai/vite-plugins 1.1.47 → 1.1.49
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 +14 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +14 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -209,6 +209,8 @@ declare function taroJsxDevSourcePlugin(): Plugin;
|
|
|
209
209
|
declare function remapJsxDevSourceLocations(code: string, rawMap: any | null | undefined): string | null;
|
|
210
210
|
declare function jsxSourceMapRemapPlugin(): Plugin;
|
|
211
211
|
|
|
212
|
+
declare function taroH5HistoryFallbackPlugin(): Plugin;
|
|
213
|
+
|
|
212
214
|
/**
|
|
213
215
|
* Vite plugin: JSX Source Tagger
|
|
214
216
|
* Intercepts react/jsx-dev-runtime to add source information to DOM elements
|
|
@@ -263,6 +265,11 @@ interface DevToolsOptions {
|
|
|
263
265
|
* 默认:./tailwind.config.ts
|
|
264
266
|
*/
|
|
265
267
|
tailwindConfigPath?: string;
|
|
268
|
+
/**
|
|
269
|
+
* Taro H5 history fallback for exact page routes.
|
|
270
|
+
* 默认:Taro 项目启用;传 false 可关闭。
|
|
271
|
+
*/
|
|
272
|
+
taroH5HistoryFallback?: boolean;
|
|
266
273
|
}
|
|
267
274
|
/**
|
|
268
275
|
* 开发工具插件集合,简化调用,vite.config.ts 直接 devTools() 即可
|
|
@@ -297,4 +304,4 @@ interface DevToolsOptions {
|
|
|
297
304
|
*/
|
|
298
305
|
declare function devTools(options?: DevToolsOptions): Plugin[];
|
|
299
306
|
|
|
300
|
-
export { type DevToolsOptions, type Rpx2pxPluginOptions, type TaroStyleAdapterOptions, devTools as default, editorBridgePlugin, injectAmasterEnv, injectTaroEnv, jsxInlineStyleRpxPlugin, jsxSourceMapRemapPlugin, jsxSourceTaggerPlugin, remapJsxDevSourceLocations, routesExposePlugin, rpx2pxPlugin, tailwindConfigSyncPlugin, taroJsxDevSourcePlugin, taroStyleAdapterPlugin, transformJsxInlineStyleRpx };
|
|
307
|
+
export { type DevToolsOptions, type Rpx2pxPluginOptions, type TaroStyleAdapterOptions, devTools as default, editorBridgePlugin, injectAmasterEnv, injectTaroEnv, jsxInlineStyleRpxPlugin, jsxSourceMapRemapPlugin, jsxSourceTaggerPlugin, remapJsxDevSourceLocations, routesExposePlugin, rpx2pxPlugin, tailwindConfigSyncPlugin, taroH5HistoryFallbackPlugin, taroJsxDevSourcePlugin, taroStyleAdapterPlugin, transformJsxInlineStyleRpx };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import v,{readFileSync}from'fs';import
|
|
2
|
-
export default {};`}function D(){let e=false;return {name:"vite-plugin-editor-bridge",configResolved(
|
|
1
|
+
import v,{readFileSync}from'fs';import g,{dirname,resolve}from'path';import {fileURLToPath}from'url';import I from'process';import w from'fs/promises';import q from'@babel/generator';import {parse}from'@babel/parser';import F from'@babel/traverse';import {TraceMap,originalPositionFor}from'@jridgewell/trace-mapping';import {createRequire}from'module';var re=fileURLToPath(import.meta.url),ne=dirname(re),k="@amaster/bridge-monitor",N="\0"+k,h=null;function oe(){if(h)return h;try{let e=resolve(ne,"../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 se(){return '<script type="module" src="/@id/@amaster/bridge-monitor"></script>'}function ie(e){return oe().replace(/__SESSION_KEY__/g,e)+`
|
|
2
|
+
export default {};`}function D(){let e=false;return {name:"vite-plugin-editor-bridge",configResolved(t){e=t.command==="serve";},resolveId(t){if(t===k)return N},load(t){if(t===N){let r=process.env.VITE_AMASTER_KEY||"";return ie(r)}},transformIndexHtml(t){if(!e)return t;let r=se();return t.replace("</body>",`${r}</body>`)}}}function B(e){let t=false,r=e?.routesFilePath||"src/routes.tsx";return {name:"vite-plugin-routes-expose",enforce:"post",configResolved(n){t=n.command==="serve";},transform(n,o){if(!t||!o.endsWith(r))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 M(){let e="",
|
|
8
|
+
`,map:null}}catch{return null}}}}function M(){let e="",t=`
|
|
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(
|
|
816
|
-
`):d&&typeof d=="object"&&(
|
|
817
|
-
`,"utf-8"),o.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":
|
|
815
|
+
</script>`;return {name:"vite-plugin-browser-logs",configResolved(r){let n=I.env.WORKSPACE_DIR;if(n)e=g.join(n,"browser.log");else {let o=r.root||I.cwd();for(;o!==g.dirname(o)&&!v.existsSync(g.join(o,"package.json"));)o=g.dirname(o);e=g.join(o,"browser.log");}},configureServer(r){r.middlewares.use((n,o,s)=>{if(n.url==="/__browser__"&&n.method==="POST"){let i=n.headers.origin||"*",c="";n.on("data",l=>{c+=l.toString();}),n.on("end",()=>{try{let l=c,d;try{d=JSON.parse(c);}catch{d=null;}Array.isArray(d)?l=d.map(a=>JSON.stringify(a)).join(`
|
|
816
|
+
`):d&&typeof d=="object"&&(l=JSON.stringify(d));let u=g.dirname(e);v.existsSync(u)||v.mkdirSync(u,{recursive:!0}),v.appendFileSync(e,`${l}
|
|
817
|
+
`,"utf-8"),o.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:!0}));}catch(l){console.error("[BrowserLogs] Write error:",l),o.writeHead(500,{"Content-Type":"application/json","Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:false,error:String(l)}));}});}else if(n.url==="/__browser__"&&n.method==="OPTIONS"){let i=n.headers.origin||"*";o.writeHead(204,{"Access-Control-Allow-Origin":i,"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 i=n.headers.origin||"*";o.writeHead(405,{"Content-Type":"application/json","Access-Control-Allow-Origin":i}),o.end(JSON.stringify({error:"Method not allowed"}));}else s();}),console.log("[BrowserLogs] Logs will be written to:",e);},transformIndexHtml(r){return r.replace(/<head([^>]*)>/i,`<head$1>${t}`)}}}var ae=`
|
|
818
818
|
import * as React from "react";
|
|
819
819
|
import * as ReactJSXDevRuntime from "react/jsx-dev-runtime";
|
|
820
820
|
|
|
@@ -996,7 +996,7 @@ 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 _(e={}){let
|
|
999
|
+
`;function _(e={}){let t=false,r="";return {name:"vite-plugin-jsx-source-tagger",enforce:"pre",configResolved(n){t=n.command==="serve",r=e.projectRoot||n.root;},resolveId(n,o){return t&&n==="react/jsx-dev-runtime"&&!o?.includes("\0jsx-source")?"\0jsx-source/jsx-dev-runtime":null},load(n){return t&&n==="\0jsx-source/jsx-dev-runtime"?ae.replace('const PROJECT_ROOT = "";',`const PROJECT_ROOT = ${JSON.stringify(r)};`):null}}}function R(e){let t="",r=false,n=null,o=null,s=e?.configPath||"./tailwind.config.ts",i="@amaster/tailwind-config",c="\0"+i,l=async()=>{let u=g.resolve(t,s);try{return await w.access(u),u}catch{if(s.endsWith(".ts")){let a=u.replace(/\.ts$/,".js");try{return await w.access(a),a}catch{return null}}else if(s.endsWith(".js")){let a=u.replace(/\.js$/,".ts");try{return await w.access(a),a}catch{return null}}return null}},d=async u=>{try{let a=await l();if(!a)return null;if(u){let L=await u.ssrLoadModule(a);return n=L.default||L,n}let p=await import(`file://${a}?t=${Date.now()}`);return n=p.default||p,n}catch(a){return console.error("[tailwind-config-sync] Failed to generate config:",a),null}};return {name:"vite-plugin-tailwind-config-sync",configResolved(u){t=u.root,r=u.command==="serve";},async buildStart(){r&&await d();},resolveId(u){if(u===i)return c},async load(u){if(u===c)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 = [];
|
|
@@ -1033,14 +1033,14 @@ export function onUpdate(fn) {
|
|
|
1033
1033
|
};
|
|
1034
1034
|
export default tailwindConfigCurrent;
|
|
1035
1035
|
|
|
1036
|
-
`:"export default null;"},configureServer(
|
|
1036
|
+
`:"export default null;"},configureServer(u){r&&(o=u,(async()=>{try{let a=await l();a&&u.watcher.add(a);}catch{}})());},async handleHotUpdate({file:u,server:a}){let f=await l();if(!f||g.normalize(u)!==g.normalize(f))return;let p=a.moduleGraph.getModuleById(f);p&&a.moduleGraph.invalidateModule(p),await d(a);let y=a.moduleGraph.getModuleById(c);return y?(a.moduleGraph.invalidateModule(y),[y]):[]}}}function O(e={}){let{designWidth:t=375,maxWidth:r=750,baseFontSize:n=12,minRootSize:o=12,maxRootSize:s=24}=e;return {name:"vite-plugin-taro-style-adapter",apply:"serve",transformIndexHtml(i){let c=`
|
|
1037
1037
|
<script data-taro-flexible="true">
|
|
1038
1038
|
(function() {
|
|
1039
|
-
var designWidth = ${
|
|
1040
|
-
var maxWidth = ${
|
|
1039
|
+
var designWidth = ${t};
|
|
1040
|
+
var maxWidth = ${r};
|
|
1041
1041
|
var baseFontSize = ${n};
|
|
1042
1042
|
var minRootSize = ${o};
|
|
1043
|
-
var maxRootSize = ${
|
|
1043
|
+
var maxRootSize = ${s};
|
|
1044
1044
|
|
|
1045
1045
|
function setRootFontSize() {
|
|
1046
1046
|
var docEl = document.documentElement;
|
|
@@ -1074,7 +1074,7 @@ export default tailwindConfigCurrent;
|
|
|
1074
1074
|
document.addEventListener('DOMContentLoaded', setRootFontSize);
|
|
1075
1075
|
})();
|
|
1076
1076
|
</script>
|
|
1077
|
-
`;return
|
|
1077
|
+
`;return i.replace("</head>",`${c}
|
|
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,6 @@ export default tailwindConfigCurrent;
|
|
|
1120
1120
|
object-fit: contain;
|
|
1121
1121
|
}
|
|
1122
1122
|
</style>
|
|
1123
|
-
</head>`)}}}function S(e={}){let{ratio:
|
|
1123
|
+
</head>`)}}}function S(e={}){let{ratio:t=2}=e;return {postcssPlugin:"postcss-rpx2px",Declaration(r){r.value?.includes("rpx")&&(r.value=r.value.replace(/(-?\d*\.?\d+)rpx/gi,(n,o)=>{let s=parseFloat(o)/t;return s===0?"0":`${s}px`}));}}}S.postcss=true;var le=/(-?\d*\.?\d+)rpx/gi,ce=q.default??q,de=F.default??F;function P(e,t){return e.replace(le,(r,n)=>{let o=Number.parseFloat(n)/t;return o===0?"0":`${o}px`})}function pe(e,t){if(!e.value.includes("rpx"))return false;let r=P(e.value,t);return r===e.value?false:(e.value=r,e.extra?.raw&&(e.extra.rawValue=r,e.extra.raw=JSON.stringify(r)),true)}function fe(e,t){let r=e.value.raw;if(!r.includes("rpx"))return false;let n=P(r,t),o=e.value.cooked==null?void 0:P(e.value.cooked,t);return n===r&&o===e.value.cooked?false:(e.value.raw=n,e.value.cooked=o,true)}function ge(e){return e.name.type==="JSXIdentifier"&&e.name.name==="style"}function me(e,t){let r=false;return e.traverse({StringLiteral(n){pe(n.node,t)&&(r=true);},TemplateElement(n){fe(n.node,t)&&(r=true);}}),r}function U(e,t=2){let r=parse(e,{sourceType:"module",plugins:["jsx","typescript"],errorRecovery:true}),n=false;return de(r,{JSXAttribute(o){if(!ge(o.node)||o.node.value?.type!=="JSXExpressionContainer")return;let s=o.get("value");s.isJSXExpressionContainer()&&me(s,t)&&(n=true);}}),n?{changed:true,code:ce(r,{retainLines:true,decoratorsBeforeExport:true,jsescOption:{minimal:true}},e).code}:{changed:false,code:e}}function T(e={}){let{ratio:t=2}=e;return {name:"vite-plugin-jsx-inline-style-rpx",enforce:"pre",transform(r,n){if(process.env.TARO_ENV!=="h5"||!/\.[jt]sx($|\?)/.test(n))return null;let o=U(r,t);return o.changed?{code:o.code,map:null}:null}}}function C(){return {name:"vite-plugin-taro-jsx-dev-source",apply:"serve",enforce:"post",config(e){let t=typeof e.esbuild=="object"&&e.esbuild?e.esbuild:{};e.esbuild={...t,jsxDev:true};}}}var Se=F.default??F;function be(e){return e.split("?",1)[0]||e}function xe(e){let t=be(e);return /\.[cm]?[jt]sx$/.test(t)&&!t.includes("/node_modules/")}function W(e){let t=e.key;return t.type==="Identifier"?t.name:t.type==="StringLiteral"?t.value:""}function m(e,t){return e.properties.find(r=>r.type==="ObjectProperty"&&W(r)===t)}function b(e){return e?.value.type==="NumericLiteral"}function _e(e){return e?.value.type==="StringLiteral"}function we(e){return e.type==="Identifier"&&e.name==="jsxDEV"}function Ee(e){return W(e)==="children"}function Re(e){let t=e.arguments[1];if(t?.type==="ObjectExpression"){let r=t.properties.find(n=>n.type==="ObjectProperty"&&!Ee(n));if(r)return r.value}return e.callee}function Oe(e){return e.type!=="ObjectExpression"?false:_e(m(e,"fileName"))&&b(m(e,"lineNumber"))&&b(m(e,"columnNumber"))}function J(e,t,r){t.value===r||t.start==null||t.end==null||e.push({start:t.start,end:t.end,value:String(r)});}function Pe(e,t){return t.sort((r,n)=>n.start-r.start).reduce((r,n)=>r.slice(0,n.start)+n.value+r.slice(n.end),e)}function X(e,t){if(!t||!e.includes("jsxDEV"))return null;let r=new TraceMap(t),n=[],o;try{o=parse(e,{sourceType:"module",plugins:["jsx","typescript"]});}catch{return null}return Se(o,{CallExpression(s){let i=s.node;if(!we(i.callee))return;let c=i.arguments[4];if(!c||c.type==="SpreadElement"||c.type==="ArgumentPlaceholder"||!Oe(c))return;let l=Re(i);if(!l.loc)return;let d=originalPositionFor(r,{line:l.loc.start.line,column:l.loc.start.column});if(d.line==null||d.column==null)return;let u=m(c,"lineNumber"),a=m(c,"columnNumber");!b(u)||!b(a)||(J(n,u.value,d.line),J(n,a.value,d.column+1));}}),n.length===0?null:Pe(e,n)}function A(){let e=false;return {name:"vite-plugin-jsx-source-map-remap",enforce:"post",configResolved(t){e=t.command==="serve";},transform(t,r){if(!e||!xe(r))return null;let n=this.getCombinedSourcemap;if(typeof n!="function")return null;let o=n.call(this);if(!o||!o.mappings)return null;let s=X(t,o);return s?{code:s,map:o}:null}}}var Ae="src/app.config.ts",je=createRequire(import.meta.url),{parse:Ie}=je("@babel/parser");function j(){let e=new Set;return {name:"amaster-taro-h5-history-fallback",apply:"serve",configureServer(t){e.size===0&&(e=De()),e.size!==0&&t.middlewares.use((r,n,o)=>{let s=Le(r,e);if(!s){o();return}n.statusCode=302,n.setHeader("Location",s),n.end();});}}}function Le(e,t){let r=(e.method||"GET").toUpperCase();if(r!=="GET"&&r!=="HEAD")return null;let n=Fe(e.url||"/");if(!n||!qe(e.headers||{}))return null;let o=Y(n.pathname);return t.has(o)?Ue(o,n.search):null}function Ne(e,t="app.config.ts"){let n=Ie(e,{sourceType:"module",sourceFilename:t,plugins:["typescript","jsx"]}).program,o=Array.isArray(n.body)?n.body:[],s=new Map;for(let l of o){if(l.type!=="VariableDeclaration")continue;let d=Array.isArray(l.declarations)?l.declarations:[];for(let u of d){let a=u.id,f=u.init;if(!x(a)||!$(f))continue;let p=K(f);p&&s.set(a.name,p);}}let i=[],c=ke(o);if(c){let l=He(c,"pages");if($(l))return i=K(l)||[],i;if(x(l)){let d=l.name;i=s.get(typeof d=="string"?d:"")||[];}}return i}function ke(e){for(let t of e){if(t.type!=="ExportDefaultDeclaration")continue;let r=t.declaration;if(r?.type==="ObjectExpression")return r;if(r?.type!=="CallExpression")return null;let n=r.callee;if(!x(n,"defineAppConfig"))return null;let s=(Array.isArray(r.arguments)?r.arguments:[])[0];return Me(s)?s:null}return null}function De(){let e=g.resolve(process.cwd(),Ae);if(!v.existsSync(e))return new Set;let t=v.readFileSync(e,"utf8");return Be(Ne(t,e))}function Be(e){return new Set((e||[]).map(Y).filter(Boolean))}function Y(e){return e.trim().replace(/^\/+/,"").replace(/\/+$/,"")}function K(e){let t=[],r=Array.isArray(e.elements)?e.elements:[];for(let n of r){if(!n||n.type!=="StringLiteral")return null;t.push(n.value);}return t}function He(e,t){let r=Array.isArray(e.properties)?e.properties:[];for(let n of r){if(n.type!=="ObjectProperty")continue;let o=n.key;if(x(o)&&o.name===t||o?.type==="StringLiteral"&&o.value===t)return n.value||null}return null}function x(e,t){return e?.type==="Identifier"&&(t?e.name===t:true)}function $(e){return e?.type==="ArrayExpression"}function Me(e){return e?.type==="ObjectExpression"}function qe(e){let t=Q(e,"sec-fetch-dest");if(t&&t!=="document"&&t!=="iframe")return false;let r=Q(e,"accept");return r?r.includes("text/html")||r.includes("application/xhtml+xml"):true}function Q(e,t){let r=e[t]||e[t.toLowerCase()]||e[t.toUpperCase()];return Array.isArray(r)?r.join(","):r||""}function Fe(e){try{let t=new URL(e,"http://amaster.local");return t.pathname=decodeURIComponent(t.pathname),t}catch{return null}}function Ue(e,t){return `/#${`/${e}${t||""}`}`}function ze(e={}){let{additional:t=[],autoInjectTaroApp:r=true,autoInjectVite:n=true}=e,o={},s=new Set(t);return r&&Object.keys(process.env).forEach(i=>{i.startsWith("TARO_APP_")&&s.add(i);}),n&&Object.keys(process.env).forEach(i=>{i.startsWith("VITE_")&&s.add(i);}),s.forEach(i=>{let c=process.env[i]||"";o[`process.env.${i}`]=JSON.stringify(c);}),o}function Je(){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 t=e.isTaro??I.env.TARO_ENV==="h5",r=[D(),B()];return e.jsxSourceTagger!==false&&r.push(_({projectRoot:t?I.cwd():void 0})),e.tailwindConfigSync!==false&&r.push(R({configPath:e.tailwindConfigPath})),t&&(e.taroH5HistoryFallback!==false&&r.unshift(j()),e.jsxSourceTagger!==false&&(r.push(C()),r.push(A())),r.unshift(T()),r.unshift(O(e.styleAdapter)),r.unshift({name:"dev-postcss-rpx2px-plugin",apply:"serve",config(n){typeof n.css?.postcss=="object"&&n.css?.postcss.plugins?.unshift(S());}})),I.env.WORKSPACE_GIT_REPO&&r.push(M()),r}
|
|
1124
|
+
export{We as default,D as editorBridgePlugin,Je as injectAmasterEnv,ze as injectTaroEnv,T as jsxInlineStyleRpxPlugin,A as jsxSourceMapRemapPlugin,_ as jsxSourceTaggerPlugin,X as remapJsxDevSourceLocations,B as routesExposePlugin,S as rpx2pxPlugin,R as tailwindConfigSyncPlugin,j as taroH5HistoryFallbackPlugin,C as taroJsxDevSourcePlugin,O as taroStyleAdapterPlugin,U as transformJsxInlineStyleRpx};//# sourceMappingURL=index.js.map
|
|
1124
1125
|
//# sourceMappingURL=index.js.map
|