@doubao-dev/kit 0.8.0-rc.3 → 0.8.0-rc.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.
@@ -1,3 +1,3 @@
1
- import"node:module";import{realpathSync as e}from"node:fs";import t from"node:path";import r from"magic-string";import{parseSync as i,simple as o}from"../../../986~0.js";let n=new Set(["@doubao-dev/template","@byted-doubao-apps/template"]),a=new Set([...n].map(e=>`${e}/primitives`)),s=e=>`${e.ctxt??0}:${e.value}`,l={audio:"DoubaoAudio",button:"DoubaoButton",camera:"DoubaoCamera",canvas:"DoubaoCanvas",map:"DoubaoMap","map-marker":"DoubaoMapMarker",markdown:"DoubaoMarkdown","navigation-bar":"DoubaoNavigationBar","long-image":"DoubaoLongImage","movable-area":"DoubaoMovableArea","movable-view":"DoubaoMovableView",popup:"DoubaoPopup",radio:"DoubaoRadio","radio-group":"DoubaoRadioGroup","rich-text":"DoubaoRichText",slider:"DoubaoSlider",switch:"DoubaoSwitch",swiper:"DoubaoSwiper","swiper-item":"DoubaoSwiperItem","picker-column":"DoubaoPickerColumn","picker-divider":"DoubaoPickerDivider","picker-view":"DoubaoPickerView","theme-provider":"DoubaoThemeProvider",video:"DoubaoVideo","web-view":"DoubaoWebView",image:"DoubaoImage",input:"DoubaoInput",list:"DoubaoList","scroll-view":"DoubaoScrollView",svg:"DoubaoSvg",text:"DoubaoText",textarea:"DoubaoTextArea",view:"DoubaoView"};function p(e){return"Identifier"===e.type&&e.value in l?e.value:null}function u(e,t,r,i,o){if("Identifier"!==t.type)return;let n=o(t.span.start-i),a=o(t.span.end-i);e.overwrite(n,a,r)}function c(r){try{return e(r)}catch{return t.resolve(r)}}export default function(e){let t=this.async();try{let{frameworkPackage:d="@byted-doubao-apps/framework",widgetEntryPaths:f=[]}=this.getOptions(),y=new r(e),m=i(e,{syntax:"typescript",tsx:!0,decorators:!0}),g=function(e){let t=0;for(;t<e.length;){let r=e[t];if(" "===r||" "===r||"\n"===r||"\r"===r||"\f"===r){t+=1;continue}if("/"===r&&"/"===e[t+1]){for(t+=2;t<e.length&&"\n"!==e[t];)t+=1;continue}if("/"===r&&"*"===e[t+1]){for(t+=2;t<e.length&&("*"!==e[t]||"/"!==e[t+1]);)t+=1;t<e.length&&(t+=2);continue}break}return Buffer.byteLength(e.slice(0,t))}(e),b=Math.max(0,m.span.start-g),x=function(e){let t=new Map([[0,0]]),r=0,i=0;for(let o of e)r+=Buffer.byteLength(o),i+=o.length,t.set(r,i);return e=>{let r=t.get(e);if(void 0===r)throw Error(`无法将字节偏移量 ${e} 映射为字符串索引`);return r}}(e),h=[];for(let t of function(e,t={}){let r=new Map,i=new Map,l=new Map,p=[],u=new Set;for(let t of e.body)if("ImportDeclaration"===t.type&&!t.typeOnly)for(let e of t.specifiers)"ImportSpecifier"!==e.type||e.isTypeOnly?"ImportNamespaceSpecifier"===e.type&&i.set(s(e.local),{source:t.source.value,name:"*"}):i.set(s(e.local),{source:t.source.value,name:e.imported?.value??e.local.value});function c(e){"Identifier"===e.type?l.delete(s(e)):"MemberExpression"===e.type&&c(e.object)}function d(e,t=new Set){if(t.has(e))return e;switch(t.add(e),e.type){case"Identifier":{let r=l.get(s(e));return r?d(r,t):e}case"MemberExpression":{let r=e.property,i="Identifier"===r.type?r.value:"Computed"===r.type&&"StringLiteral"===r.expression.type?r.expression.value:void 0;if(void 0===i)return e;let o=d(e.object,t);if("ObjectExpression"!==o.type)return e;let n=b(o).get(i);return n?d(n,t):e}case"ParenthesisExpression":case"TsAsExpression":case"TsSatisfiesExpression":case"TsTypeAssertion":case"TsNonNullExpression":return d(e.expression,t);default:return e}}function f(e,t=new Set){if("Identifier"===e.type){if(t.has(s(e)))return;t.add(s(e));let r=i.get(s(e));if(r)return r;let o=d(e);return o!==e?f(o,t):void 0}if("JSXMemberExpression"===e.type||"MemberExpression"===e.type){let r=f(e.object,t);if(r?.name==="*"&&"Identifier"===e.property.type)return{source:r.source,name:e.property.value}}}function y(e,t,r){if(!("span"in e))return;let i=`${e.span.start}:${t}:${r}`;u.has(i)||(u.add(i),p.push({span:e.span,field:t,message:r}))}o(e,{FunctionDeclaration(e){r.set(s(e.identifier),e)},VariableDeclaration(e){if("const"===e.kind)for(let t of e.declarations)"Identifier"===t.id.type&&t.init&&l.set(s(t.id),t.init)}}),o(e,{AssignmentExpression(e){("Identifier"===e.left.type||"MemberExpression"===e.left.type)&&c(e.left)},UpdateExpression(e){c(e.argument)},CallExpression(e){"MemberExpression"===e.callee.type&&"Identifier"===e.callee.property.type&&["push","pop","shift","unshift","splice","fill","copyWithin","reverse","sort"].includes(e.callee.property.value)&&c(e.callee.object)}});let m=new Set,g=new WeakSet;function b(e,t=new Set){let r=new Map,i=d(e);if(t.has(i)||m.has(i)||"ObjectExpression"!==i.type)return g.add(r),r;for(let e of(m.add(i),t.add(i),i.properties))if("SpreadElement"===e.type){let i=d(e.arguments);if("ObjectExpression"!==i.type)r.clear(),g.add(r);else{let e=b(i,new Set(t));for(let[t,i]of(g.has(e)&&(r.clear(),g.add(r)),e))r.set(t,i)}}else"Identifier"===e.type?r.set(e.value,e):"KeyValueProperty"===e.type&&("Identifier"===e.key.type||"StringLiteral"===e.key.type?r.set(e.key.value,e.value):(r.clear(),g.add(r)));return m.delete(i),r}function x(e,t,r=new Set){let i=d(e);if(r.has(i))return;let o=new Set(r).add(i);"ConditionalExpression"===i.type?(x(i.consequent,t,o),x(i.alternate,t,o)):"BinaryExpression"===i.type&&"&&"===i.operator?x(i.right,t,o):"BinaryExpression"===i.type&&("||"===i.operator||"??"===i.operator)?(x(i.left,t,o),x(i.right,t,o)):t(i)}function h(e,t,r){x(e,e=>{if("NullLiteral"!==e.type&&("BooleanLiteral"!==e.type||e.value)&&("text"!==t||"StringLiteral"!==e.type&&"NumericLiteral"!==e.type)){if("JSXElement"===e.type){let r=e.opening.name,i=f(r),o=e.children.some(e=>"JSXText"!==e.type||e.value.trim()),n=i&&a.has(i.source)&&"text"===t&&["Title","Tag"].includes(i.name),s="image"===t&&"Identifier"===r.type&&["image","svg"].includes(r.value);if(!o&&(n||s))return}else if(!["JSXFragment","ArrayExpression","ObjectExpression","BooleanLiteral","StringLiteral","NumericLiteral"].includes(e.type))return;else if("config"===t&&"JSXFragment"!==e.type&&"ArrayExpression"!==e.type)return;y(e,r,`仅支持 ${"text"===t?"string / number / Tag / Title":"image"===t?"image / svg":"标准配置(price 也支持 string / number)"},不支持业务组件、fragment、包装节点或复合 JSX。`)}})}function v(e,t,r=new Set){x(e,e=>{if(r.has(e))return;let i=new Set(r).add(e);if("ArrayExpression"===e.type)for(let r of e.elements)r&&(r.spread?v(r.expression,t,i):x(r.expression,t));else if("CallExpression"===e.type&&"MemberExpression"===e.callee.type&&"Identifier"===e.callee.property.type&&"map"===e.callee.property.value){let r=e.arguments[0]?.expression;r?.type==="ArrowFunctionExpression"&&"BlockStatement"!==r.body.type&&x(r.body,t)}})}if(o(e,{JSXElement(e){let t=f(e.opening.name);if(!t||!(n.has(t.source)&&["ContentCard","CouponCard","TransitCard","CheckoutCard","CompositeCard","PriceActionCard","AskHumanCard","MapCard"].includes(t.name)||a.has(t.source)&&["Title","Tag","Price","Icon","OptionGroup"].includes(t.name)))return;let r=new Map;for(let t of e.opening.attributes)if("SpreadElement"===t.type){let e=d(t.arguments);if("ObjectExpression"!==e.type)r.clear();else{let t=b(e);for(let[e,i]of(g.has(t)&&r.clear(),t))r.set(e,i)}}else if("Identifier"===t.name.type&&t.value){let e=t.value;"JSXExpressionContainer"===e.type&&"JSXEmptyExpression"!==e.expression.type?r.set(t.name.value,e.expression):"StringLiteral"===e.type&&r.set(t.name.value,e)}!function e(t,r,i=r){var o;let n="CheckoutCard"===r?"productItems":"items",a=t.get(n);a&&(o=`${i}.${n}`,v(a,e=>{for(let[t,i]of b(e)){let e=`${o}[].${t}`;"ContentCard"===r&&["title","subtitle","description"].includes(t)||"TransitCard"===r&&"title"===t?h(i,"text",e):"ContentCard"===r&&"thumbnail"===t||"CheckoutCard"===r&&"image"===t?h(i,"image",e):("ContentCard"===r&&"action"===t||"TransitCard"===r&&"price"===t)&&h(i,"config",e)}})),"CompositeCard"===r&&t.has("sections")&&v(t.get("sections"),t=>{let r=b(t),o=r.get("type"),n=o&&d(o),a=r.get("props");if(n?.type==="StringLiteral"&&a){let t={content:"ContentCard",transit:"TransitCard","option-group":"OptionGroup"}[n.value];t&&e(b(a),t,`${i}.sections[${n.value}].props`)}})}(r,t.name)}}),t.checkWidgetRoot){let t=new Set,i=new Set,o=new Set(["@doubao-dev/framework","@byted-doubao-apps/framework"]),a=new Set(["ContentCard","CouponCard","TransitCard","CheckoutCard","CompositeCard","PriceActionCard","AskHumanCard","MapCard"]);function w(e){if(!t.has(e)&&e.body){if(t.add(e),"BlockStatement"!==e.body.type)return void E(e.body);!function e(t){if(t&&"object"==typeof t){if(Array.isArray(t))return void t.forEach(e);if("ReturnStatement"===t.type){t.argument&&E(t.argument);return}["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression","MethodProperty","ClassDeclaration","ClassExpression"].includes(String(t.type))||Object.values(t).forEach(e)}}(e.body)}}function E(e){x(e,e=>{if(!i.has(e)&&(i.add(e),"NullLiteral"!==e.type&&("BooleanLiteral"!==e.type||e.value)))if("FunctionExpression"===e.type||"ArrowFunctionExpression"===e.type)w(e);else if("Identifier"===e.type){let t=r.get(s(e));t&&w(t)}else if("CallExpression"===e.type){if("Super"===e.callee.type||"Import"===e.callee.type)return;let t=f(e.callee);if(t?.name==="defineWidget"&&o.has(t.source)){let t=e.arguments[0]?.expression;t&&function(e){let t=d(e),r=b(t).get("render");if(r&&E(r),"ObjectExpression"===t.type)for(let e of t.properties)"MethodProperty"===e.type&&("Identifier"===e.key.type||"StringLiteral"===e.key.type)&&"render"===e.key.value&&w(e)}(t)}else if(t&&["memo","forwardRef"].includes(t.name)&&(o.has(t.source)||["react","@lynx-js/react"].includes(t.source))){let t=e.arguments[0]?.expression;t&&E(t)}else{let t=d(e.callee);if("FunctionExpression"===t.type||"ArrowFunctionExpression"===t.type)w(t);else if("Identifier"===t.type){let e=r.get(s(t));e&&w(e)}}}else if("JSXElement"===e.type){let t=e.opening.name,i=f(t);if(i&&n.has(i.source)&&a.has(i.name))return;if("Identifier"===t.type&&!/^[a-z]/.test(t.value)){let e=r.get(s(t)),i=d(t);if(e)return void w(e);if("FunctionExpression"===i.type||"ArrowFunctionExpression"===i.type||"CallExpression"===i.type)return void E(i)}y(e,"widget.root","Widget 最外层必须直接渲染模板卡片,不能套 view、scroll-view、fragment 或其他包装节点。")}else["JSXFragment","ArrayExpression","StringLiteral","NumericLiteral","BooleanLiteral"].includes(e.type)&&y(e,"widget.root","Widget 最外层必须直接渲染一张模板卡片。")})}for(let t of e.body)if("ExportDefaultExpression"===t.type)E(t.expression);else if("ExportDefaultDeclaration"===t.type&&"FunctionExpression"===t.decl.type)w(t.decl);else if("ExportNamedDeclaration"===t.type&&!t.source&&!t.typeOnly)for(let e of t.specifiers)"ExportSpecifier"===e.type&&e.exported?.value==="default"&&"Identifier"===e.orig.type&&E(e.orig)}return p}(m,{checkWidgetRoot:f.some(e=>c(e)===c(this.resourcePath))})){let r=x(t.span.start-b),i=e.slice(0,r),o=i.split("\n").length,n=r-i.lastIndexOf("\n");h.push({rule_id:"widget.root"===t.field?"template.root":"template.content",severity:"warning",file:this.resourcePath,line:o,column:n,field:t.field,message:t.message})}let v=this._module;v?.buildInfo&&(v.buildInfo.cardDiagnostics=h);let w=new Set;if(o(m,{JSXOpeningElement(e){let t=p(e.name);if(!t)return;let r=l[t];u(y,e.name,r,b,x),w.add(r)},JSXClosingElement(e){let t=p(e.name);if(!t)return;let r=l[t];u(y,e.name,r,b,x),w.add(r)}}),w.size>0){let e=Array.from(w).map(e=>{let t=e.replace("Doubao","");return`${t} as ${e}`}).join(", "),t=`import { ${e} } from '${d}/components';
2
- `;y.prepend(t)}if(y.hasChanged()){let e=y.toString(),r=y.generateMap({includeContent:!0,hires:!0,source:this.resourcePath,file:this.resourcePath});t(null,e,r)}else t(null,e)}catch(r){t(null,e)}};
1
+ import"node:module";import{realpathSync as e}from"node:fs";import t from"node:path";import r from"magic-string";import{parseSync as o,simple as i}from"../../../986~0.js";let n=new Set(["@doubao-dev/template","@byted-doubao-apps/template"]),a=new Set([...n].map(e=>`${e}/primitives`)),s=e=>`${e.ctxt??0}:${e.value}`,l={audio:"DoubaoAudio",button:"DoubaoButton",camera:"DoubaoCamera",canvas:"DoubaoCanvas",map:"DoubaoMap","map-marker":"DoubaoMapMarker",markdown:"DoubaoMarkdown","navigation-bar":"DoubaoNavigationBar","long-image":"DoubaoLongImage","movable-area":"DoubaoMovableArea","movable-view":"DoubaoMovableView",popup:"DoubaoPopup",radio:"DoubaoRadio","radio-group":"DoubaoRadioGroup","rich-text":"DoubaoRichText",slider:"DoubaoSlider",switch:"DoubaoSwitch",swiper:"DoubaoSwiper","swiper-item":"DoubaoSwiperItem","picker-column":"DoubaoPickerColumn","picker-divider":"DoubaoPickerDivider","picker-view":"DoubaoPickerView","theme-provider":"DoubaoThemeProvider",video:"DoubaoVideo","web-view":"DoubaoWebView",image:"DoubaoImage",input:"DoubaoInput",list:"DoubaoList","scroll-view":"DoubaoScrollView",svg:"DoubaoSvg",text:"DoubaoText",textarea:"DoubaoTextArea",view:"DoubaoView"};function p(e){return"Identifier"===e.type&&e.value in l?e.value:null}function u(e,t,r,o,i){if("Identifier"!==t.type)return;let n=i(t.span.start-o),a=i(t.span.end-o);e.overwrite(n,a,r)}function c(r){try{return e(r)}catch{return t.resolve(r)}}export default function(e){let t=this.async();try{let{frameworkPackage:d="@byted-doubao-apps/framework",widgetEntryPaths:f=[]}=this.getOptions(),m=new r(e),y=o(e,{syntax:"typescript",tsx:!0,decorators:!0}),g=function(e){let t=0;for(;t<e.length;){let r=e[t];if(" "===r||" "===r||"\n"===r||"\r"===r||"\f"===r){t+=1;continue}if("/"===r&&"/"===e[t+1]){for(t+=2;t<e.length&&"\n"!==e[t];)t+=1;continue}if("/"===r&&"*"===e[t+1]){for(t+=2;t<e.length&&("*"!==e[t]||"/"!==e[t+1]);)t+=1;t<e.length&&(t+=2);continue}break}return Buffer.byteLength(e.slice(0,t))}(e),b=Math.max(0,y.span.start-g),x=function(e){let t=new Map([[0,0]]),r=0,o=0;for(let i of e)r+=Buffer.byteLength(i),o+=i.length,t.set(r,o);return e=>{let r=t.get(e);if(void 0===r)throw Error(`无法将字节偏移量 ${e} 映射为字符串索引`);return r}}(e),h=[],v=new Set;for(let t of function(e,t={}){let r=new Map,o=new Map,l=new Map,p=[],u=new Set;for(let t of e.body)if("ImportDeclaration"===t.type&&!t.typeOnly)for(let e of t.specifiers)"ImportSpecifier"!==e.type||e.isTypeOnly?"ImportDefaultSpecifier"===e.type?o.set(s(e.local),{source:t.source.value,name:"default"}):"ImportNamespaceSpecifier"===e.type&&o.set(s(e.local),{source:t.source.value,name:"*"}):o.set(s(e.local),{source:t.source.value,name:e.imported?.value??e.local.value});function c(e){"Identifier"===e.type?l.delete(s(e)):"MemberExpression"===e.type&&c(e.object)}function d(e,t=new Set){if(t.has(e))return e;switch(t.add(e),e.type){case"Identifier":{let r=l.get(s(e));return r?d(r,t):e}case"MemberExpression":{let r=e.property,o="Identifier"===r.type?r.value:"Computed"===r.type&&"StringLiteral"===r.expression.type?r.expression.value:void 0;if(void 0===o)return e;let i=d(e.object,t);if("ObjectExpression"!==i.type)return e;let n=b(i).get(o);return n?d(n,t):e}case"ParenthesisExpression":case"TsAsExpression":case"TsSatisfiesExpression":case"TsTypeAssertion":case"TsNonNullExpression":return d(e.expression,t);default:return e}}function f(e,t=new Set){if("Identifier"===e.type){if(t.has(s(e)))return;t.add(s(e));let r=o.get(s(e));if(r)return r;let i=d(e);return i!==e?f(i,t):void 0}if("JSXMemberExpression"===e.type||"MemberExpression"===e.type){let r=f(e.object,t);if(r?.name==="*"&&"Identifier"===e.property.type)return{source:r.source,name:e.property.value}}}function m(e,t,r,o){if(!("span"in e))return;let i=`${e.span.start}:${t}:${r}`;u.has(i)||(u.add(i),p.push({span:e.span,field:t,message:r,...o?{ruleId:o}:{}}))}i(e,{FunctionDeclaration(e){r.set(s(e.identifier),e)},VariableDeclaration(e){if("const"===e.kind)for(let t of e.declarations)"Identifier"===t.id.type&&t.init&&l.set(s(t.id),t.init)}}),i(e,{AssignmentExpression(e){("Identifier"===e.left.type||"MemberExpression"===e.left.type)&&c(e.left)},UpdateExpression(e){c(e.argument)},CallExpression(e){"MemberExpression"===e.callee.type&&"Identifier"===e.callee.property.type&&["push","pop","shift","unshift","splice","fill","copyWithin","reverse","sort"].includes(e.callee.property.value)&&c(e.callee.object)}});let y=new Set,g=new WeakSet;function b(e,t=new Set){let r=new Map,o=d(e);if(t.has(o)||y.has(o)||"ObjectExpression"!==o.type)return g.add(r),r;for(let e of(y.add(o),t.add(o),o.properties))if("SpreadElement"===e.type){let o=d(e.arguments);if("ObjectExpression"!==o.type)r.clear(),g.add(r);else{let e=b(o,new Set(t));for(let[t,o]of(g.has(e)&&(r.clear(),g.add(r)),e))r.set(t,o)}}else"Identifier"===e.type?r.set(e.value,e):"KeyValueProperty"===e.type&&("Identifier"===e.key.type||"StringLiteral"===e.key.type?r.set(e.key.value,e.value):(r.clear(),g.add(r)));return y.delete(o),r}function x(e,t,r=new Set){let o=d(e);if(r.has(o))return;let i=new Set(r).add(o);"ConditionalExpression"===o.type?(x(o.consequent,t,i),x(o.alternate,t,i)):"BinaryExpression"===o.type&&"&&"===o.operator?x(o.right,t,i):"BinaryExpression"===o.type&&("||"===o.operator||"??"===o.operator)?(x(o.left,t,i),x(o.right,t,i)):t(o)}function h(e,t,r){x(e,e=>{if("NullLiteral"!==e.type&&("BooleanLiteral"!==e.type||e.value)&&("text"!==t||"StringLiteral"!==e.type&&"NumericLiteral"!==e.type)){if("JSXElement"===e.type){let r=e.opening.name,o=f(r),i=e.children.some(e=>"JSXText"!==e.type||e.value.trim()),n=o&&a.has(o.source)&&"text"===t&&["Title","Tag"].includes(o.name),s="image"===t&&"Identifier"===r.type&&["image","svg"].includes(r.value);if(!i&&(n||s))return}else if(!["JSXFragment","ArrayExpression","ObjectExpression","BooleanLiteral","StringLiteral","NumericLiteral"].includes(e.type))return;else if("config"===t&&"JSXFragment"!==e.type&&"ArrayExpression"!==e.type)return;m(e,r,`仅支持 ${"text"===t?"string / number / Tag / Title":"image"===t?"image / svg":"标准配置(price 也支持 string / number)"},不支持业务组件、fragment、包装节点或复合 JSX。`)}})}function v(e,t,r=new Set){x(e,e=>{if(r.has(e))return;let o=new Set(r).add(e);if("ArrayExpression"===e.type)for(let r of e.elements)r&&(r.spread?v(r.expression,t,o):x(r.expression,t));else if("CallExpression"===e.type&&"MemberExpression"===e.callee.type&&"Identifier"===e.callee.property.type&&"map"===e.callee.property.value){let r=e.arguments[0]?.expression;r?.type==="ArrowFunctionExpression"&&"BlockStatement"!==r.body.type&&x(r.body,t)}})}if(i(e,{JSXElement(e){let r=f(e.opening.name);if(!r||!(n.has(r.source)&&["ContentCard","CouponCard","TransitCard","CheckoutCard","CompositeCard","PriceActionCard","AskHumanCard","MapCard"].includes(r.name)||a.has(r.source)&&["Title","Tag","Price","Icon","OptionGroup","Checkbox","Agreement"].includes(r.name)))return;let o=new Map;for(let t of e.opening.attributes)if("SpreadElement"===t.type){let e=d(t.arguments);if("ObjectExpression"!==e.type)o.clear();else{let t=b(e);for(let[e,r]of(g.has(t)&&o.clear(),t))o.set(e,r)}}else if("Identifier"===t.name.type&&t.value){let e=t.value;"JSXExpressionContainer"===e.type&&"JSXEmptyExpression"!==e.expression.type?o.set(t.name.value,e.expression):"StringLiteral"===e.type&&o.set(t.name.value,e)}let i=function e(r,o,i=o){var s;let l=!1,p="CheckoutCard"===o?"productItems":"items",u=r.get(p);return u&&(s=`${i}.${p}`,v(u,e=>{for(let[t,r]of b(e)){let e=`${s}[].${t}`;"ContentCard"===o&&["title","subtitle","description"].includes(t)||"TransitCard"===o&&"title"===t?h(r,"text",e):"ContentCard"===o&&"thumbnail"===t||"CheckoutCard"===o&&"image"===t?h(r,"image",e):("ContentCard"===o&&"action"===t||"TransitCard"===o&&"price"===t)&&h(r,"config",e)}})),"CompositeCard"===o&&r.has("sections")&&v(r.get("sections"),r=>{let o=b(r),s=o.get("type"),p=s&&d(s),u=o.get("props");if(p?.type==="StringLiteral"&&"custom"===p.value){l=!0;let e=o.get("content");e&&x(e,e=>{if("JSXElement"===e.type){let r=f(e.opening.name);!r||n.has(r.source)||a.has(r.source)||t.onCustomSectionImport?.(r.source)}})}if(p?.type==="StringLiteral"&&u){let t={content:"ContentCard",transit:"TransitCard","option-group":"OptionGroup"}[p.value];t&&e(b(u),t,`${i}.sections[${p.value}].props`)}}),l}(o,r.name);"CompositeCard"===r.name&&m(e,"CompositeCard",`CompositeCard 支持组合内容模块,构建检查无法自动判断最终效果是否符合豆包卡片设计规范。请在交付前检查整体布局、视觉层级、交互及各状态。${i?"自定义内容及其样式也需符合规范,且不得覆盖模板外壳、Header 和 Footer。":""}`,i?"template.composite.design.custom":"template.composite.design")}}),t.checkWidgetRoot){let t=new Set,o=new Set,i=new Set(["@doubao-dev/framework","@byted-doubao-apps/framework"]),a=new Set(["ContentCard","CouponCard","TransitCard","CheckoutCard","CompositeCard","PriceActionCard","AskHumanCard","MapCard"]);function C(e){if(!t.has(e)&&e.body){if(t.add(e),"BlockStatement"!==e.body.type)return void S(e.body);!function e(t){if(t&&"object"==typeof t){if(Array.isArray(t))return void t.forEach(e);if("ReturnStatement"===t.type){t.argument&&S(t.argument);return}["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression","MethodProperty","ClassDeclaration","ClassExpression"].includes(String(t.type))||Object.values(t).forEach(e)}}(e.body)}}function S(e){x(e,e=>{if(!o.has(e)&&(o.add(e),"NullLiteral"!==e.type&&("BooleanLiteral"!==e.type||e.value)))if("FunctionExpression"===e.type||"ArrowFunctionExpression"===e.type)C(e);else if("Identifier"===e.type){let t=r.get(s(e));t&&C(t)}else if("CallExpression"===e.type){if("Super"===e.callee.type||"Import"===e.callee.type)return;let t=f(e.callee);if(t?.name==="defineWidget"&&i.has(t.source)){let t=e.arguments[0]?.expression;t&&function(e){let t=d(e),r=b(t).get("render");if(r&&S(r),"ObjectExpression"===t.type)for(let e of t.properties)"MethodProperty"===e.type&&("Identifier"===e.key.type||"StringLiteral"===e.key.type)&&"render"===e.key.value&&C(e)}(t)}else if(t&&["memo","forwardRef"].includes(t.name)&&(i.has(t.source)||["react","@lynx-js/react"].includes(t.source))){let t=e.arguments[0]?.expression;t&&S(t)}else{let t=d(e.callee);if("FunctionExpression"===t.type||"ArrowFunctionExpression"===t.type)C(t);else if("Identifier"===t.type){let e=r.get(s(t));e&&C(e)}}}else if("JSXElement"===e.type){let t=e.opening.name,o=f(t);if(o&&n.has(o.source)&&a.has(o.name))return;if("Identifier"===t.type&&!/^[a-z]/.test(t.value)){let e=r.get(s(t)),o=d(t);if(e)return void C(e);if("FunctionExpression"===o.type||"ArrowFunctionExpression"===o.type||"CallExpression"===o.type)return void S(o)}m(e,"widget.root","Widget 最外层必须直接渲染模板卡片,不能套 view、scroll-view、fragment 或其他包装节点。")}else["JSXFragment","ArrayExpression","StringLiteral","NumericLiteral","BooleanLiteral"].includes(e.type)&&m(e,"widget.root","Widget 最外层必须直接渲染一张模板卡片。")})}for(let t of e.body)if("ExportDefaultExpression"===t.type)S(t.expression);else if("ExportDefaultDeclaration"===t.type&&"FunctionExpression"===t.decl.type)C(t.decl);else if("ExportNamedDeclaration"===t.type&&!t.source&&!t.typeOnly)for(let e of t.specifiers)"ExportSpecifier"===e.type&&e.exported?.value==="default"&&"Identifier"===e.orig.type&&S(e.orig)}return p}(y,{onCustomSectionImport:e=>v.add(e),checkWidgetRoot:f.some(e=>c(e)===c(this.resourcePath))})){let r=x(t.span.start-b),o=e.slice(0,r),i=o.split("\n").length,n=r-o.lastIndexOf("\n");h.push({rule_id:t.ruleId??("widget.root"===t.field?"template.root":"template.content"),severity:"warning",file:this.resourcePath,line:i,column:n,field:t.field,message:t.message})}let C=this._module;C?.buildInfo&&(C.buildInfo.cardDiagnostics=h,C.buildInfo.cardCustomSectionImports=[...v]);let S=new Set;if(i(y,{JSXOpeningElement(e){let t=p(e.name);if(!t)return;let r=l[t];u(m,e.name,r,b,x),S.add(r)},JSXClosingElement(e){let t=p(e.name);if(!t)return;let r=l[t];u(m,e.name,r,b,x),S.add(r)}}),S.size>0){let e=Array.from(S).map(e=>{let t=e.replace("Doubao","");return`${t} as ${e}`}).join(", "),t=`import { ${e} } from '${d}/components';
2
+ `;m.prepend(t)}if(m.hasChanged()){let e=m.toString(),r=m.generateMap({includeContent:!0,hires:!0,source:this.resourcePath,file:this.resourcePath});t(null,e,r)}else t(null,e)}catch(r){t(null,e)}};
3
3
  //# sourceMappingURL=index.js.map
package/dist/cli/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import"node:module";import{logger as e}from"@rsbuild/core";import o from"chalk";import{Option as a,program as r}from"commander";import{package_namespaceObject as t,dev as n,cliLogger as i,deploy as p,build as c,analyze as s}from"../277~0.js";import{selectDevServerHost as d}from"../427~0.js";function l(){if(!process.env.NODE_ENV){let e=process.argv[2];process.env.NODE_ENV=["build","package","deploy","analyze","perf"].includes(e)?"production":"development"}i.greet(`Doubao Apps SDK v${t.rE}`)}async function m(e){let{devtools:o,host:a,...r}=e,t={...r,host:!0===a?await d():a};return o?{...t,debugDriver:"devtools"}:t}function u(e){return e.option("-c --config <config>","specify the configuration file, can be a relative or absolute path").option("--env-mode <mode>","specify the env mode to load the `.env.[mode]` file"),e}function v(t=process.cwd(),i={},d="0.8.0-rc.3"){r.name("doubao").usage("<command> [options]").version(d),u(r.command("dev")).description("starting the dev server...").option("--host [host]","listen hostname or IP; omit value to select an address interactively").option("--devtools","use DevTools debug driver").action(async o=>{try{await n(await m(o))}catch(o){e.error("Failed to dev"),e.error(o),process.exit(1)}}),u(r.command("build")).description("starting build the applet").option("-a --archive","Archive all package",!1).addOption(Object.assign(new a("--channel <string>","Need channel name"),{short:"-ch",flags:"-ch --channel <string>"})).action(async o=>{try{await c(o)}catch(o){e.error("Failed to build"),e.error(o),process.exit(1)}}),u(r.command("analyze")).description("analyze the applet package").action(async a=>{try{await s(a)}catch(a){e.error(o.red("Failed to analyze")),e.error(a),process.exit(1)}}),u(r.command("deploy")).option("--token <token>","developer open build token for Doubao Apps Platform deploy").option("--app-name, --appName <appName>","app name for Doubao Apps Platform deploy").option("--app-icon, --appIcon <appIcon>","app icon for Doubao Apps Platform deploy").option("--version-tag, --versionTag <versionTag>","version tag for Doubao Apps Platform deploy").description("build and upload the app package").action(async a=>{try{await p({...a,build:!0})}catch(a){e.error(o.red("Failed to deploy")),e.error(a),process.exit(1)}}),r.parse()}export{l as prepareCli,v as runCli};
1
+ import"node:module";import{logger as e}from"@rsbuild/core";import o from"chalk";import{Option as a,program as r}from"commander";import{package_namespaceObject as t,dev as n,cliLogger as i,deploy as p,build as c,analyze as s}from"../277~0.js";import{selectDevServerHost as d}from"../427~0.js";function l(){if(!process.env.NODE_ENV){let e=process.argv[2];process.env.NODE_ENV=["build","package","deploy","analyze","perf"].includes(e)?"production":"development"}i.greet(`Doubao Apps SDK v${t.rE}`)}async function m(e){let{devtools:o,host:a,...r}=e,t={...r,host:!0===a?await d():a};return o?{...t,debugDriver:"devtools"}:t}function u(e){return e.option("-c --config <config>","specify the configuration file, can be a relative or absolute path").option("--env-mode <mode>","specify the env mode to load the `.env.[mode]` file"),e}function v(t=process.cwd(),i={},d="0.8.0-rc.4"){r.name("doubao").usage("<command> [options]").version(d),u(r.command("dev")).description("starting the dev server...").option("--host [host]","listen hostname or IP; omit value to select an address interactively").option("--devtools","use DevTools debug driver").action(async o=>{try{await n(await m(o))}catch(o){e.error("Failed to dev"),e.error(o),process.exit(1)}}),u(r.command("build")).description("starting build the applet").option("-a --archive","Archive all package",!1).addOption(Object.assign(new a("--channel <string>","Need channel name"),{short:"-ch",flags:"-ch --channel <string>"})).action(async o=>{try{await c(o)}catch(o){e.error("Failed to build"),e.error(o),process.exit(1)}}),u(r.command("analyze")).description("analyze the applet package").action(async a=>{try{await s(a)}catch(a){e.error(o.red("Failed to analyze")),e.error(a),process.exit(1)}}),u(r.command("deploy")).option("--token <token>","developer open build token for Doubao Apps Platform deploy").option("--app-name, --appName <appName>","app name for Doubao Apps Platform deploy").option("--app-icon, --appIcon <appIcon>","app icon for Doubao Apps Platform deploy").option("--version-tag, --versionTag <versionTag>","version tag for Doubao Apps Platform deploy").description("build and upload the app package").action(async a=>{try{await p({...a,build:!0})}catch(a){e.error(o.red("Failed to deploy")),e.error(a),process.exit(1)}}),r.parse()}export{l as prepareCli,v as runCli};
2
2
  //# sourceMappingURL=index.js.map
package/dist/sdk.d.ts CHANGED
@@ -736,6 +736,7 @@ declare class SandboxRuntime {
736
736
  sandboxCsrPem?: string | undefined;
737
737
  fileSystemNamespace: string;
738
738
  sandboxSessionAvailable: boolean;
739
+ sandboxSessionError: Pick<SandboxSessionCreationError, "message" | "category" | "logId"> | undefined;
739
740
  sandboxAppId: string;
740
741
  sandboxCsrRequired: boolean;
741
742
  sandboxCsrUploaded: boolean;
@@ -786,12 +787,19 @@ declare type SandboxRuntimeState = {
786
787
  sandboxProjectId: string;
787
788
  sandboxSessionAppId?: string;
788
789
  sandboxSessionId: string;
790
+ sandboxSessionError?: Pick<SandboxSessionCreationError, 'category' | 'message' | 'logId'>;
789
791
  sandboxTargetOrigin?: string;
790
792
  simulatorBusinessTemplatesPath?: string;
791
793
  simulatorManifestReader?: () => string;
792
794
  simulatorManifestPath?: string;
793
795
  };
794
796
 
797
+ declare class SandboxSessionCreationError extends Error {
798
+ readonly category: 'local' | 'network' | 'platform';
799
+ readonly logId?: string | undefined;
800
+ constructor(message: string, category: 'local' | 'network' | 'platform', logId?: string | undefined);
801
+ }
802
+
795
803
  declare type SandboxSessionIdentity = {
796
804
  appId: string;
797
805
  sessionId: string;