mirror of
https://gitee.com/openharmony/developtools_ace_ets2bundle
synced 2024-12-04 07:22:30 +00:00
fix revert arkoala
Signed-off-by: seaside_wu <wuhaibin5@huawei.com>
This commit is contained in:
parent
022099b7bf
commit
0e6382a00d
@ -975,9 +975,6 @@ function isPartialUpdate(metadata, moduleType) {
|
||||
if (item.name === 'SkipArkTSStaticBlocksCheck' && item.value === 'true') {
|
||||
partialUpdateConfig.skipArkTSStaticBlocksCheck = true;
|
||||
}
|
||||
if (item.name === 'ArkoalaPlugin' && item.value === 'true') {
|
||||
projectConfig.useArkoala = true;
|
||||
}
|
||||
if (item.name === 'UseTsHar' && item.value === 'true' && moduleType === 'har') {
|
||||
projectConfig.useTsHar = true;
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import type * as ts from 'typescript'
|
||||
import { reset, yellow } from '../ark_compiler/common/ark_define'
|
||||
|
||||
export interface ArkoalaPluginOptions {
|
||||
/**
|
||||
* Filter program source files which must be trnsformed with Arkoala plugins
|
||||
*
|
||||
* @param fileName Normalize source file path
|
||||
* @returns true if the given file must be transformed
|
||||
*/
|
||||
filter?: (fileName: string) => boolean;
|
||||
/**
|
||||
* Specify the root directory from which router path must be resolved
|
||||
* @default "."
|
||||
*/
|
||||
routerRootDir?: string;
|
||||
}
|
||||
|
||||
// This is an implementation stub, it should be replaced with arkoala-plugin.js from the Arkoala repo.
|
||||
export default function arkoalaProgramTransform(
|
||||
program: ts.Program,
|
||||
compilerHost: ts.CompilerHost | undefined,
|
||||
options: ArkoalaPluginOptions,
|
||||
extras: Object,
|
||||
): ts.Program {
|
||||
let [,,,] = [compilerHost, options, extras]
|
||||
console.warn(`${yellow}WARN: Arkoala plugin is missing in the current SDK. Source transformation will not be performed.${reset}`)
|
||||
return program
|
||||
}
|
@ -39,8 +39,7 @@ import {
|
||||
CompilationTimeStatistics,
|
||||
genLoaderOutPathOfHar,
|
||||
harFilesRecord,
|
||||
resetUtils,
|
||||
getResolveModules
|
||||
resetUtils
|
||||
} from '../../utils';
|
||||
import {
|
||||
preprocessExtend,
|
||||
@ -62,8 +61,7 @@ import {
|
||||
projectConfig,
|
||||
abilityPagesFullPath,
|
||||
globalProgram,
|
||||
resetMain,
|
||||
globalModulePaths
|
||||
resetMain
|
||||
} from '../../../main';
|
||||
import {
|
||||
appComponentCollection,
|
||||
@ -88,7 +86,6 @@ import {
|
||||
} from '../../process_kit_import';
|
||||
import { resetProcessComponentMember } from '../../process_component_member';
|
||||
import { mangleFilePath, resetObfuscation } from '../ark_compiler/common/ob_config_resolver';
|
||||
import arkoalaProgramTransform, { ArkoalaPluginOptions } from './arkoala-plugin';
|
||||
import processStructComponentV2 from '../../process_struct_componentV2';
|
||||
import { resetlogMessageCollection } from '../../log_message_collection';
|
||||
|
||||
@ -279,27 +276,6 @@ compilerHost.getCurrentDirectory = () => process.cwd();
|
||||
compilerHost.getDefaultLibFileName = options => ts.getDefaultLibFilePath(options);
|
||||
compilerHost.resolveTypeReferenceDirectives = resolveTypeReferenceDirectives;
|
||||
|
||||
const arkoalaTsProgramCache: WeakMap<ts.Program, ts.Program> = new WeakMap();
|
||||
|
||||
function getArkoalaTsProgram(program: ts.Program): ts.Program {
|
||||
let extendedProgram = arkoalaTsProgramCache.get(program);
|
||||
if (!extendedProgram) {
|
||||
const pluginOptions: ArkoalaPluginOptions = {};
|
||||
// This is a stub for the interface generated by ts-patch.
|
||||
// Probably we can use the reported diagnostics in the output
|
||||
const pluginTransformExtras: Object = {
|
||||
diagnostics: [],
|
||||
addDiagnostic(): number {return 0},
|
||||
removeDiagnostic(): void {},
|
||||
ts: ts,
|
||||
library: 'typescript',
|
||||
};
|
||||
extendedProgram = arkoalaProgramTransform(program, compilerHost, pluginOptions, pluginTransformExtras);
|
||||
arkoalaTsProgramCache.set(program, extendedProgram);
|
||||
}
|
||||
return extendedProgram;
|
||||
}
|
||||
|
||||
async function transform(code: string, id: string) {
|
||||
const compilationTime: CompilationTimeStatistics = new CompilationTimeStatistics(this.share, 'etsTransform', 'transform');
|
||||
if (!filter(id)) {
|
||||
@ -395,10 +371,6 @@ async function transform(code: string, id: string) {
|
||||
// use `try finally` to restore `noEmit` when error thrown by `processUISyntax` in preview mode
|
||||
try {
|
||||
startTimeStatisticsLocation(compilationTime ? compilationTime.tsProgramEmitTime : undefined);
|
||||
if (projectConfig.useArkoala) {
|
||||
tsProgram = getArkoalaTsProgram(tsProgram);
|
||||
targetSourceFile = tsProgram.getSourceFile(id);
|
||||
}
|
||||
tsProgram.emit(targetSourceFile, writeFile, undefined, undefined,
|
||||
{
|
||||
before: [
|
||||
@ -491,33 +463,6 @@ function resetEtsTransform(): void {
|
||||
};
|
||||
}
|
||||
|
||||
function findArkoalaRoot(): string {
|
||||
let arkoalaSdkRoot: string;
|
||||
if (process.env.ARKOALA_SDK_ROOT) {
|
||||
arkoalaSdkRoot = process.env.ARKOALA_SDK_ROOT;
|
||||
if (!isDir(arkoalaSdkRoot)) {
|
||||
throw new Error('Arkoala SDK not found in ' + arkoalaSdkRoot);
|
||||
}
|
||||
} else {
|
||||
const arkoalaPossiblePaths: string[] = globalModulePaths.map(dir => path.join(dir, '../../arkoala'));
|
||||
arkoalaSdkRoot = arkoalaPossiblePaths.find(possibleRootDir => isDir(possibleRootDir)) ?? '';
|
||||
if (!arkoalaSdkRoot) {
|
||||
throw new Error('Arkoala SDK not found in ' + arkoalaPossiblePaths.join(';'));
|
||||
}
|
||||
}
|
||||
|
||||
return arkoalaSdkRoot;
|
||||
}
|
||||
|
||||
function isDir(filePath: string): boolean {
|
||||
try {
|
||||
let stat: fs.Stats = fs.statSync(filePath);
|
||||
return stat.isDirectory();
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function setIncrementalFileInHar(cacheFilePath: string, buildFilePath: string, allFilesInHar: Map<string, string>): void {
|
||||
if (cacheFilePath.match(/\.d.e?ts$/)) {
|
||||
allFilesInHar.set(cacheFilePath, buildFilePath);
|
||||
|
Loading…
Reference in New Issue
Block a user