Skip to content

Commit ed95ca3

Browse files
committed
build: 支持转换 importModule 语句多行
1 parent 5580d32 commit ed95ca3

File tree

4 files changed

+47
-21
lines changed

4 files changed

+47
-21
lines changed

babel.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
module.exports = {
2-
plugins: ['@babel/plugin-syntax-top-level-await']
2+
plugins: [
3+
'@babel/plugin-syntax-top-level-await',
4+
'@babel/plugin-syntax-import-assertions'
5+
]
36
}

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@
2727
"devDependencies": {
2828
"@babel/core": "^7.14.0",
2929
"@babel/eslint-parser": "^7.13.14",
30+
"@babel/plugin-syntax-import-assertions": "^7.22.5",
3031
"@babel/plugin-syntax-top-level-await": "^7.12.13",
31-
"@types/node": "^17.0.23",
32+
"@types/node": "^18.14.6",
3233
"@types/scriptable-ios": "^1.7.0",
3334
"eslint": "^7.26.0",
3435
"eslint-config-standard": "^16.0.2",
3536
"eslint-plugin-import": "^2.22.1",
3637
"eslint-plugin-node": "^11.1.0",
3738
"eslint-plugin-promise": "^4.3.1",
3839
"glob": "^7.2.0",
39-
"rollup": "^2.45.2",
40-
"rollup-plugin-serve": "^1.1.0"
40+
"rollup": "^3.29.2",
41+
"rollup-plugin-serve": "^2.0.2"
4142
}
4243
}

pnpm-lock.yaml

+33-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.js rollup.config.mjs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import path from 'path'
22
import glob from 'glob'
33
import serve from 'rollup-plugin-serve'
4-
import { version } from './package.json'
4+
import pkg from './package.json' assert { type: 'json' }
55

6+
const { version } = pkg
67
console.info(`Scriptable Template v${version}\r\n`)
78

89
const config = {
@@ -93,6 +94,10 @@ for (const filename of files) {
9394
return `import ${imported.replace(/:/g, ' as ')} from "./${moduleName}"`
9495
}
9596
)
97+
.replace(
98+
/(?:let|const)\s*{([\s\S]*?)\}\s*=\s*(?:importModule|require)\('(.*?)'\)/,
99+
"import {$1} from '$2'"
100+
)
96101
}
97102
}
98103
]

0 commit comments

Comments
 (0)