Skip to content

Commit

Permalink
fix(helper): 修复配置文件读取报错的问题,fix #12674
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen-jj authored and yoyo837 committed Dec 9, 2022
1 parent 6d44f6e commit 9b39818
Show file tree
Hide file tree
Showing 8 changed files with 2,269 additions and 6 deletions.
7 changes: 7 additions & 0 deletions packages/taro-helper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
swc/**/.cargo
swc/**/target/*
!swc/**/target/wasm32-wasi
swc/**/target/wasm32-wasi/*
!swc/**/target/wasm32-wasi/release
swc/**/target/wasm32-wasi/release/*
!swc/**/target/wasm32-wasi/release/*.wasm
3 changes: 2 additions & 1 deletion packages/taro-helper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"files": [
"index.js",
"dist",
"types"
"types",
"swc"
],
"keywords": [
"taro"
Expand Down
10 changes: 7 additions & 3 deletions packages/taro-helper/src/swcRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class InjectDefineConfigHeader extends Visitor {

interface ICreateSwcRegisterParam {
only
plugin?
plugins: [string, any][]
}

export default function createSwcRegister ({ only, plugin }: ICreateSwcRegisterParam) {
export default function createSwcRegister ({ only, plugins }: ICreateSwcRegisterParam) {
const config: Record<string, any> = {
only: Array.from(new Set([...only])),
jsc: {
Expand All @@ -38,7 +38,11 @@ export default function createSwcRegister ({ only, plugin }: ICreateSwcRegisterP
}
}

if (plugin) config.plugin = plugin
if (plugins) {
config.jsc.experimental = {
plugins
}
}

require('@swc/register')(config)
}
6 changes: 4 additions & 2 deletions packages/taro-helper/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
SCRIPT_EXT,
TARO_CONFIG_FOLDER
} from './constants'
import createSwcRegister, { InjectDefineConfigHeader } from './swcRegister'
import createSwcRegister from './swcRegister'
import { chalk } from './terminal'

const execSync = child_process.execSync
Expand Down Expand Up @@ -649,7 +649,9 @@ export function readConfig (configPath: string) {
configPath,
filepath => importPaths.includes(filepath)
],
plugin: m => new InjectDefineConfigHeader().visitProgram(m)
plugins: [
[path.resolve(__dirname, '../swc/plugin-define-config/target/wasm32-wasi/release/swc_plugin_define_config.wasm'), {}]
]
})

importPaths.concat([configPath]).forEach(item => {
Expand Down

0 comments on commit 9b39818

Please sign in to comment.