Skip to content

Commit

Permalink
feat(harmony): 区分x和非x独立har包编译产物
Browse files Browse the repository at this point in the history
  • Loading branch information
Wangyaqi committed Dec 30, 2024
1 parent 63dc91b commit 37db80a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
3 changes: 2 additions & 1 deletion packages/uni-app-harmony/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist/packages
dist/packages
dist-x/packages
6 changes: 5 additions & 1 deletion packages/uni-app-harmony/src/compiler/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ function genAppHarmonyUniModules(
extApiCodes.push(...registerProviderCodes)
}
importCodes.unshift(
`import { registerUniProvider, uni } from '@dcloudio/uni-app-runtime'`
`import { registerUniProvider, uni } from '${
process.env.UNI_APP_X !== 'true'
? '@dcloudio/uni-app-runtime'
: '@dcloudio/uni-app-x-runtime'
}'`
)

context.emitFile({
Expand Down
4 changes: 2 additions & 2 deletions packages/uni-app-harmony/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function generateExtApiSourceCode(isUniAppX = false) {
.map((key) => injects[key][1])
extApiStandaloneBuildJson.push({
input: path.resolve(extApiTempDir, extApi),
output: path.resolve(__dirname, `dist/packages/${extApi}`),
output: path.resolve(__dirname, isUniAppX ? 'dist-x' : 'dist', `packages/${extApi}`),
plugin: extApi,
type: standaloneExtApi.type,
apis,
Expand All @@ -276,7 +276,7 @@ function generateExtApiSourceCode(isUniAppX = false) {
const [_, service, provider] = extApi.split('-')
extApiStandaloneBuildJson.push({
input: path.resolve(extApiTempDir, extApi),
output: path.resolve(__dirname, `dist/packages/${extApi}`),
output: path.resolve(__dirname, isUniAppX ? 'dist-x' : 'dist', `packages/${extApi}`),
plugin: extApi,
type: standaloneExtApi.type,
provider,
Expand Down
25 changes: 15 additions & 10 deletions packages/uni-uts-v1/src/arkts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ export function mergeArkTSAutoImports(
return result
}

export function getArkTSAutoImports(): AutoImportOptions {
function getRuntimePackageName(isX = false) {
return isX ? '@dcloudio/uni-app-x-runtime' : '@dcloudio/uni-app-runtime'
}

export function getArkTSAutoImports(isX = false): AutoImportOptions {
const runtimePackageName = getRuntimePackageName(isX)
return mergeArkTSAutoImports(
{
'@dcloudio/uni-app-runtime': [
[runtimePackageName]: [
['defineAsyncApi'],
['defineSyncApi'],
['defineTaskApi'],
Expand Down Expand Up @@ -109,24 +114,24 @@ export async function compileArkTSExtApi(
rootDir: string,
pluginDir: string,
outputDir: string,
{ isExtApi, isOhpmPackage = false, transform }: ArkTSCompilerOptions
{ isExtApi, isX, isOhpmPackage = false, transform }: ArkTSCompilerOptions
): Promise<CompileResult | void> {
const filename = resolveAppHarmonyIndexFile(pluginDir)
if (!filename) {
return
}
const runtimePackageName = getRuntimePackageName(isX)

const { bundle, UTSTarget } = getUTSCompiler()
const pluginId = path.basename(pluginDir)
const outputUniModuleDir = outputDir

let autoImportExternals = getArkTSAutoImports()
let autoImportExternals = getArkTSAutoImports(isX)

if (isOhpmPackage) {
// 只保留uni-app-runtime
autoImportExternals = {
'@dcloudio/uni-app-runtime':
autoImportExternals['@dcloudio/uni-app-runtime'],
[runtimePackageName]: autoImportExternals[runtimePackageName],
}
}

Expand All @@ -136,7 +141,7 @@ export async function compileArkTSExtApi(
root: rootDir,
filename: resolveBundleInputFileName('app-harmony', filename),
paths: {
'@dcloudio/uni-runtime': '@dcloudio/uni-app-runtime',
'@dcloudio/uni-runtime': runtimePackageName,
},
parseOptions: {
tsx: true,
Expand Down Expand Up @@ -275,7 +280,7 @@ export async function compileArkTSExtApi(
buildOption: {
arkOptions: {
runtimeOnly: {
packages: ['@dcloudio/uni-app-runtime'],
packages: [runtimePackageName],
},
},
},
Expand Down Expand Up @@ -319,15 +324,15 @@ export default {

export async function compileArkTS(
pluginDir: string,
{ isExtApi, transform }: ArkTSCompilerOptions
{ isExtApi, isX, transform }: ArkTSCompilerOptions
): Promise<CompileResult | void> {
const inputDir = process.env.UNI_INPUT_DIR
const pluginId = path.basename(pluginDir)
return compileArkTSExtApi(
resolveBundleInputRoot('app-harmony', inputDir),
pluginDir,
resolveAppHarmonyUniModuleDir(pluginId),
{ isExtApi, transform }
{ isExtApi, isX, transform }
)
}

Expand Down
1 change: 1 addition & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ async function postBuildArkTS (isUniAppX = false) {
harBuildJson[i]
await compileArkTSExtApi(path.resolve(input, '..'), input, output, {
isExtApi: true,
isX: isUniAppX,
isOhpmPackage: true,
transform: {},
})
Expand Down

0 comments on commit 37db80a

Please sign in to comment.