Skip to content

feat(compiler): build() 支持自定义小程序文件扩展名(fileTypes 选项)#248

Merged
dos1in merged 2 commits into
didi:mainfrom
EchoTechFE:feat/dialect-file-types
Jun 15, 2026
Merged

feat(compiler): build() 支持自定义小程序文件扩展名(fileTypes 选项)#248
dos1in merged 2 commits into
didi:mainfrom
EchoTechFE:feat/dialect-file-types

Conversation

@lbb00

@lbb00 lbb00 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

做了什么

build() 增加 options.fileTypes,允许在内置 wx*(.wxml/.wxss/.wxs)、dd*(.ddml/.ddss) 之上追加自定义文件扩展名,使其等价编译。通用能力,无品牌耦合。

build(target, work, useAppIdDir, {
  fileTypes: {
    template:   ['xxml'],  // → view.js
    style:      ['xxss'],  // → style.css
    viewScript: ['xxs'],   // .xxs 文件 + 内联 <xxs module> 标签
  },
})
  • 自定义扩展名自动归一化(补点/小写/去重,仅允许 [a-z0-9_-],不得占用内置或 .js/.ts/.json)。
  • 完全向后兼容:不传 fileTypes 行为不变;内置 wx/dd 永远保留、仅追加。
  • 指令(:if/:for/:key 等)按后缀匹配,自定义前缀(如 xx:if)也能正常编译。
  • CLI 暂不开放对应 flag,本次仅扩编程 API。

顺带修复(与本改动共用 getter,故一并提交)

  • transTagWxs 原「无 <wxs> 才回退 <dds>」会漏编同时含两种标签的文件。
  • npm 文件白名单漏 .ddml/.ddss/.sass、且含编译器不支持的 .styl
  • loadWxsModule 旧的 _wxs_ 路径片段判定只对 scoped 包放在 wxs/ 目录的 .wxs 生效,改用 wxsFilePathMap 定位。

测试

新增 custom-file-types.spec + npm-view-script-custom-loading.spec;全量 vitest 260 passed,oxlint 干净。

@lbb00

lbb00 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

补一个 chore(lint) 提交:components/__tests__/button-style-specificity.spec 在单引号串里断言字面 template-literal 子串,触发 oxlint no-template-curly-in-string(与本特性无关,全树 lint 既有问题)。加了行内 disable(${type} 是有意字面量),现 oxlint 全树 0 error。

Comment thread fe/packages/components/__tests__/button-style-specificity.spec.js Outdated
@lbb00 lbb00 force-pushed the feat/dialect-file-types branch 2 times, most recently from 9beaee3 to 8236cc1 Compare June 15, 2026 08:13
lbb00 and others added 2 commits June 15, 2026 16:18
通过 build() 的 options.fileTypes 在内置 wx/dd 系之上追加自定义模板/样式/视图脚本扩展名(如 .qdml/.qdss/.qds 及内联 <qds> 标签),编译时与对应内置类型等价处理。

- env.js:compilerOptions 单例 + 归一化(补点/小写/去重,拒绝路径分隔符与选择器元字符)+ 4 个 getter;storeInfo 按本次重建防跨构建串用,resetStoreInfo 还原 worker 上下文
- 消费点改读 getter:模板/样式查找、视图脚本文件扫描与路径剥除、内联标签取并集(修「无 wxs 才回退 dds」漏编译)、npm 白名单对齐补 .ddml/.ddss/.sass、compatibility 动态豁免视图脚本标签
- loadWxsModule 改用 wxsFilePathMap 判定,不再依赖 _wxs_ 路径片段(自定义扩展名/非 wxs 目录的 .wxs 不再漏编译)

测试:custom-file-types.spec(单元+集成+元字符/泄漏反证)、npm-view-script-custom-loading.spec;vitest 258 passed。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
button-style-specificity.spec 在单引号串里断言字面 template-literal 子串,
触发 oxlint no-template-curly-in-string。改用转义的模板字符串
`\`dd-button--\${type}\``(值不变、不插值,规则不再误报),无需 disable 注释。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lbb00 lbb00 force-pushed the feat/dialect-file-types branch from 8236cc1 to 18ee953 Compare June 15, 2026 08:18
@dos1in dos1in merged commit 701c253 into didi:main Jun 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants