diff --git a/build-tools/delete_systemapi_plugin.js b/build-tools/delete_systemapi_plugin.js index 21b28b0f54590f42d4de8edb05307389174120ed..0a1e65a3a94cedbe2439562d5dc88ea5e3dd287d 100644 --- a/build-tools/delete_systemapi_plugin.js +++ b/build-tools/delete_systemapi_plugin.js @@ -18,11 +18,9 @@ const ts = require('typescript'); const commander = require('commander'); let sourceFile = null; -let lastNoteStr = ''; -let lastNodeName = ''; let etsType = 'ets'; let componentEtsFiles = []; -let componentEtsDeleteFiles = ['plugincomponent', 'uiextensioncomponent', 'effectcomponent', 'inspector']; +const componentEtsDeleteFiles = []; const referencesMap = new Map(); const referencesModuleMap = new Map(); const kitFileNeedDeleteMap = new Map(); @@ -80,7 +78,7 @@ function collectDeclaration(inputDir) { collectComponentEtsFiles(); readFile(inputDir, utFiles); // 读取文件 readFile(arktsPath, utFiles); // 读取文件 - tsTransform(utFiles, deleteSystemApi); + tsTransform(sortApiList(utFiles), deleteSystemApi); tsTransformKitFile(kitPath); } catch (error) { console.error('DELETE_SYSTEM_PLUGIN ERROR: ', error); @@ -325,6 +323,9 @@ function processFileNameWithoutExt(filePath) { */ function tsTransform(utFiles, callback) { utFiles.forEach((url) => { + if (!fs.existsSync(url)) { + return; + } const apiBaseName = path.basename(url); let content = fs.readFileSync(url, 'utf-8'); // 文件内容 let isTransformer = /\.d\.ts/.test(apiBaseName) || /\.d\.ets/.test(apiBaseName); @@ -445,6 +446,28 @@ function readFile(dir, utFiles) { } } +/** + * 修改特殊文件的执行时序 + * @param {string[]} params + * @returns {string[]} + */ +function sortApiList(apiFiles) { + const newApiFiles = []; + const specFileName = '@ohos.arkui.component.d.ets'; + let specApiFilePath = ''; + apiFiles.forEach(filePath => { + if (filePath.endsWith(specFileName)) { + specApiFilePath = filePath; + } else { + newApiFiles.push(filePath); + } + }); + if (specApiFilePath !== '') { + newApiFiles.push(specApiFilePath); + } + return newApiFiles; +} + function writeFile(url, data, option) { const urlPath = url.replace(/\.static\.d\.ets$/, '.d.ets'); const urlDirName = path.dirname(inputDir);