提交 047085f2 编写于 作者: fxy060608's avatar fxy060608

wip(x-web): 准备迁移 api

上级 247be76e
......@@ -52,6 +52,8 @@
"acorn-loose": "^8.2.1",
"acorn-walk": "^8.2.0",
"estree-walker": "^2.0.2",
"fast-glob": "^3.2.11",
"fs-extra": "^10.0.0",
"vue": "3.4.21"
}
}
......@@ -82,8 +82,17 @@ export * from './view/components'
export * from './view/bridge'
//#if _NEW_X_
export * from './x/service/api'
export * from './x/service/api/uni'
//#endif
//#if !_NEW_X_
export * from './service/api'
// @ts-expect-error
export * from './service/api/uni'
//#endif
export * from './service/bridge'
export { getApp, getCurrentPages } from './framework'
......
// @ts-expect-error
export * from '@dcloudio/uni-ext-api/uni-getLaunchOptionsSync'
import * as api from './index'
export const uni = api
import fs from 'fs-extra'
import path from 'path'
import { defineConfig } from 'vite'
import { type Plugin, defineConfig } from 'vite'
import { sync } from 'fast-glob'
import jscc from 'rollup-plugin-jscc'
import strip from '@rollup/plugin-strip'
import replace from '@rollup/plugin-replace'
......@@ -39,6 +41,7 @@ const rollupPlugins = [
// 该插件限制了不能以__开头
_NODE_JS_: FORMAT === 'cjs' ? 1 : 0,
_X_: isX ? 1 : 0,
_NEW_X_: isX && process.env.UNI_APP_EXT_API_DIR ? 1 : 0,
},
}),
]
......@@ -105,6 +108,7 @@ export default defineConfig({
],
},
plugins: [
...(isX && process.env.UNI_APP_EXT_API_DIR ? [uts2ts()] : []),
vue({
template: {
compilerOptions: {
......@@ -168,3 +172,84 @@ export default defineConfig({
},
},
})
// if (!process.env.UNI_APP_EXT_API_DIR) {
// console.error(`UNI_APP_EXT_API_DIR is not defined`)
// process.exit(0)
// }
const extApiDirTemp = path.resolve(__dirname, 'temp', 'uni-ext-api')
function checkExtApiDir(name: string) {
if (fs.existsSync(path.resolve(extApiDirTemp, name))) {
return
}
const extApiDir = path.resolve(process.env.UNI_APP_EXT_API_DIR!)
// 拷贝到临时目录
fs.copySync(path.resolve(extApiDir, name), path.resolve(extApiDirTemp, name))
// 重命名后缀
sync('**/*.uts', {
absolute: true,
cwd: path.resolve(extApiDirTemp, name),
}).forEach((file) => {
fs.renameSync(file, file + '.ts')
})
}
function resolveExtApi(name: string) {
checkExtApiDir(name)
const filename = path.resolve(
extApiDirTemp,
name,
'utssdk',
'app-android',
'index.uts.ts'
)
return fs.existsSync(filename)
? filename
: path.resolve(extApiDirTemp, name, 'utssdk', 'index.uts.ts')
}
function uts2ts(): Plugin {
return {
name: 'uts2ts',
config() {
return {
resolve: {
extensions: [
'.mjs',
'.js',
'.mts',
'.ts',
'.jsx',
'.tsx',
'.json',
'.uts.ts',
],
alias: [
{
find: '@dcloudio/uni-runtime',
replacement: resolve('../uni-runtime/src/index.ts'),
},
{
find: /^@dcloudio\/uni-ext-api\/(.*)/,
replacement: '$1',
customResolver(source) {
return resolveExtApi(source)
},
},
],
},
}
},
buildStart() {
// 清理临时目录
fs.emptyDirSync(extApiDirTemp)
},
buildEnd() {
// 清理临时目录
fs.emptyDirSync(extApiDirTemp)
},
}
}
export { isFunction, isString } from '@vue/shared'
export const __uniConfig = global.__uniConfig
lockfileVersion: '6.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
overrides:
'@babel/plugin-transform-block-scoping': 7.19.4
......@@ -55,6 +59,9 @@ importers:
'@rollup/plugin-terser':
specifier: ^0.2.1
version: 0.2.1(rollup@4.14.2)
'@types/fs-extra':
specifier: ^9.0.13
version: 9.0.13
'@types/jest':
specifier: ^29.2.3
version: 29.5.12
......@@ -100,6 +107,9 @@ importers:
cypress:
specifier: ^10.7.0
version: 10.11.0
dotenv:
specifier: ^16.4.5
version: 16.4.5
enquirer:
specifier: ^2.3.6
version: 2.4.1
......@@ -950,6 +960,12 @@ importers:
estree-walker:
specifier: ^2.0.2
version: 2.0.2
fast-glob:
specifier: ^3.2.11
version: 3.3.2
fs-extra:
specifier: ^10.0.0
version: 10.1.0
vue:
specifier: 3.4.21
version: 3.4.21(typescript@5.3.2)
......@@ -6386,6 +6402,11 @@ packages:
webidl-conversions: 5.0.0
dev: false
/dotenv@16.4.5:
resolution: {integrity: sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==}
engines: {node: '>=12'}
dev: true
/ecc-jsbn@0.1.2:
resolution: {integrity: sha512-eh9O+hwRHNbG4BLTjEl3nw044CkGm5X6LoaCf7LPp7UU8Qrt47JYNi6nPX8xjW97TKGKm1ouctg0QSpZe9qrnw==}
dependencies:
......@@ -11487,7 +11508,3 @@ packages:
optionalDependencies:
commander: 9.5.0
dev: true
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
......@@ -4,6 +4,10 @@ const colors = require('picocolors')
const execa = require('execa')
const { spawn } = require('child_process')
const { config } = require('dotenv')
config()
const { extract } = require('./apiExtractor')
const { targets: allTargets, fuzzyMatchTarget, priority } = require('./utils')
......@@ -20,7 +24,7 @@ const transpileOnly = args.transpileOnly
run()
async function run () {
async function run() {
if (!targets.length) {
await buildAll(allTargets)
} else {
......@@ -28,7 +32,7 @@ async function run () {
}
}
function buildWithChildProcess (target) {
function buildWithChildProcess(target) {
const args = [__filename, target]
devOnly && args.push('-d')
isRelease && args.push('--release')
......@@ -48,7 +52,7 @@ function buildWithChildProcess (target) {
})
}
function getTargetGroup (targets) {
function getTargetGroup(targets) {
const group = {}
for (let i = 0; i < targets.length; i++) {
const target = targets[i]
......@@ -62,7 +66,7 @@ function getTargetGroup (targets) {
return group
}
async function buildAll (targets) {
async function buildAll(targets) {
if (!multiProcess) {
for (const target of targets) {
try {
......@@ -92,7 +96,7 @@ async function buildAll (targets) {
}
}
async function build (target) {
async function build(target) {
console.log(`\n${colors.bold(target)}:`)
const pkgDir = path.resolve(`packages/${target}`)
const pkg = require(`${pkgDir}/package.json`)
......@@ -155,7 +159,11 @@ async function build (target) {
['build', '--config', path.resolve(pkgDir, 'vite.config.ts')],
{
stdio: 'inherit',
env: Object.assign({ FORMAT: 'es', UNI_APP_X: 'true' }, process.env, env),
env: Object.assign(
{ FORMAT: 'es', UNI_APP_X: 'true' },
process.env,
env
),
cwd: pkgDir,
}
)
......@@ -164,7 +172,11 @@ async function build (target) {
['build', '--config', path.resolve(pkgDir, 'vite.config.ts')],
{
stdio: 'inherit',
env: Object.assign({ FORMAT: 'cjs', UNI_APP_X: 'true' }, process.env, env),
env: Object.assign(
{ FORMAT: 'cjs', UNI_APP_X: 'true' },
process.env,
env
),
cwd: pkgDir,
}
)
......@@ -200,7 +212,12 @@ async function build (target) {
[
'-c',
'--environment',
[`NODE_ENV:${env}`, types ? `TYPES:true` : ``, `TARGET:${target}`, transpileOnly ? `TRANSPILE_ONLY:true` : ``]
[
`NODE_ENV:${env}`,
types ? `TYPES:true` : ``,
`TARGET:${target}`,
transpileOnly ? `TRANSPILE_ONLY:true` : ``,
]
.filter(Boolean)
.join(','),
],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册