Merge branch 'master' of gitee.com:openharmony/developtools_ace-ets2bundle into master23

Change-Id: Ic85df20498a78edbfed9f0946083f599e7b17313
This commit is contained in:
houhaoyu
2022-09-02 20:24:32 +08:00
50 changed files with 504 additions and 182 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "SideBarContainer",
"attrs": [
"showSideBar", "controlButton", "showControlButton", "onChange", "sideBarWidth", "minSideBarWidth", "maxSideBarWidth", "autoHide"
"showSideBar", "controlButton", "showControlButton", "onChange", "sideBarWidth", "minSideBarWidth", "maxSideBarWidth", "autoHide", "sideBarPosition"
]
}
+1 -1
View File
@@ -9,6 +9,6 @@
"domStorageAccess", "imageAccess", "mixedMode", "zoomAccess", "geolocationAccess", "javaScriptProxy",
"userAgent", "onConfirm", "onConsole", "onErrorReceive", "onHttpErrorReceive", "onDownloadStart", "fileFromUrlAccess",
"webDebuggingAccess", "onShowFileSelector", "initialScale", "onResourceLoad", "onScaleChange", "onHttpAuthRequest",
"onPermissionRequest", "onContextMenuShow", "textZoomRatio", "onScroll"
"onPermissionRequest", "onContextMenuShow", "textZoomRatio", "onScroll", "mediaPlayGestureAccess"
]
}
+1
View File
@@ -374,6 +374,7 @@ function loadModuleInfo(projectConfig, envArgs) {
projectConfig.modulePathMap = buildJsonInfo.modulePathMap;
projectConfig.isOhosTest = buildJsonInfo.isOhosTest;
projectConfig.processTs = false;
projectConfig.processMergeabc = false;
projectConfig.buildArkMode = envArgs.buildMode;
if (buildJsonInfo.compileMode === 'esmodule') {
projectConfig.nodeModulesPath = buildJsonInfo.nodeModulesPath;
+11
View File
@@ -253,6 +253,17 @@ export class ResultStates {
}
this.printResult();
});
compiler.hooks.watchRun.tap('Listening State', (compiler: Compiler) => {
if (compiler.modifiedFiles) {
const isTsAndEtsFile: boolean = [...compiler.modifiedFiles].some((item: string) => {
return /.(ts|ets)$/.test(item);
});
if (!isTsAndEtsFile) {
process.env.watchTs = 'end';
}
}
});
}
private judgeFileShouldResolved(file: string, shouldResolvedFiles: Set<string>): void {
+4 -5
View File
@@ -15,7 +15,6 @@
import * as childProcess from 'child_process';
import * as process from 'process';
import * as fs from 'fs';
import cluster from 'cluster';
import { logger } from './compile_info';
import {
@@ -31,9 +30,9 @@ const reset: string = '\u001b[39m';
function js2abcByWorkers(jsonInput: string, cmd: string): Promise<void> {
const inputPaths: any = JSON.parse(jsonInput);
for (let i = 0; i < inputPaths.length; ++i) {
const input: string = inputPaths[i].path;
const input: string = inputPaths[i].path.replace(/\.temp\.js$/, "_.js");
const cacheOutputPath: string = inputPaths[i].cacheOutputPath;
const cacheAbcFilePath: string = cacheOutputPath.replace(/\_.js$/, ".abc");
const cacheAbcFilePath: string = cacheOutputPath.replace(/\.temp\.js$/, ".abc");
const singleCmd: any = `${cmd} "${cacheOutputPath}" -o "${cacheAbcFilePath}" --source-file "${input}"`;
logger.debug('gen abc cmd is: ', singleCmd, ' ,file size is:', inputPaths[i].size, ' byte');
try {
@@ -50,9 +49,9 @@ function js2abcByWorkers(jsonInput: string, cmd: string): Promise<void> {
function es2abcByWorkers(jsonInput: string, cmd: string): Promise<void> {
const inputPaths: any = JSON.parse(jsonInput);
for (let i = 0; i < inputPaths.length; ++i) {
const input: string = inputPaths[i].path;
const input: string = inputPaths[i].path.replace(/\.temp\.js$/, "_.js");
const cacheOutputPath: string = inputPaths[i].cacheOutputPath;
const cacheAbcFilePath: string = cacheOutputPath.replace(/\_.js$/, ".abc");
const cacheAbcFilePath: string = cacheOutputPath.replace(/\.temp\.js$/, ".abc");
const singleCmd: any = `${cmd} "${cacheOutputPath}" --output "${cacheAbcFilePath}" --source-file "${input}"`;
logger.debug('gen abc cmd is: ', singleCmd, ' ,file size is:', inputPaths[i].size, ' byte');
try {
+133 -62
View File
@@ -44,15 +44,17 @@ import {
EXTNAME_MJS,
EXTNAME_CJS,
EXTNAME_D_TS,
EXTNAME_ABC,
FAIL,
EXTNAME_JS_MAP,
TS2ABC,
ES2ABC,
TEMPORARY
TEMPORARY,
SUCCESS,
MODULELIST_JSON
} from './pre_define';
import { getOhmUrlByFilepath } from './resolve_ohm_url';
import { generateMergedAbc } from './gen_merged_abc';
const firstFileEXT: string = '_.js';
const genAbcScript: string = 'gen_abc.js';
const genModuleAbcScript: string = 'gen_module_abc.js';
let output: string;
@@ -78,6 +80,7 @@ let entryInfos: Map<string, EntryInfo> = new Map<string, EntryInfo>();
let hashJsonObject = {};
let moduleHashJsonObject = {};
let buildPathInfo: string = '';
let buildMapFileList: Array<string> = [];
const red: string = '\u001b[31m';
const reset: string = '\u001b[39m';
@@ -85,12 +88,13 @@ const blue = '\u001b[34m';
const hashFile: string = 'gen_hash.json';
const ARK: string = '/ark/';
class ModuleInfo {
export class ModuleInfo {
filePath: string;
tempFilePath: string;
buildFilePath: string;
abcFilePath: string;
isCommonJs: boolean;
recordName: string;
constructor(filePath: string, tempFilePath: string, buildFilePath: string, abcFilePath: string, isCommonJs: boolean) {
this.filePath = filePath;
@@ -98,10 +102,11 @@ class ModuleInfo {
this.buildFilePath = buildFilePath;
this.abcFilePath = abcFilePath;
this.isCommonJs = isCommonJs;
this.recordName = getOhmUrlByFilepath(filePath);
}
}
class EntryInfo {
export class EntryInfo {
npmInfo: string;
abcFileName: string;
buildPath: string;
@@ -142,6 +147,17 @@ export class GenAbcPlugin {
return;
}
// case ESMODULE
// | --- merge -- debug -- not removeDir
// | --- merge -- release -- removeDir
// | --- unmerge -- removeDir
if (projectConfig.compileMode === ESMODULE) {
if (!projectConfig.processMergeabc || projectConfig.buildArkMode !== 'debug') {
removeDir(output);
removeDir(projectConfig.nodeModulesPath);
}
}
compiler.hooks.compilation.tap('GenAbcPlugin', (compilation) => {
if (projectConfig.compileMode === JSBUNDLE || projectConfig.compileMode === undefined) {
return;
@@ -167,13 +183,12 @@ export class GenAbcPlugin {
if (projectConfig.compileMode === ESMODULE) {
return;
}
removeDir(output);
Object.keys(compilation.assets).forEach(key => {
// choose *.js
if (output && path.extname(key) === EXTNAME_JS) {
const newContent: string = compilation.assets[key].source();
const keyPath: string = key.replace(/\.js$/, firstFileEXT);
writeFileSync(newContent, path.resolve(output, keyPath), key);
const keyPath: string = key.replace(/\.js$/, ".temp.js");
writeFileSync(newContent, output, keyPath, key);
}
});
});
@@ -250,8 +265,7 @@ function processNodeModulesFile(filePath: string, tempFilePath: string, buildFil
moduleInfos.push(tempModuleInfo);
nodeModulesFile.push(tempFilePath);
}
return;
buildMapFileList.push(genSourceMapFileName(buildFilePath));
}
function processEtsModule(filePath: string, tempFilePath: string, buildFilePath: string, nodeModulesFile: Array<string>, module: any): void {
@@ -269,6 +283,7 @@ function processEtsModule(filePath: string, tempFilePath: string, buildFilePath:
const tempModuleInfo: ModuleInfo = new ModuleInfo(filePath, tempFilePath, buildFilePath, abcFilePath, false);
moduleInfos.push(tempModuleInfo);
}
buildMapFileList.push(genSourceMapFileName(buildFilePath));
}
function processDtsModule(filePath: string, tempFilePath: string, buildFilePath: string, nodeModulesFile: Array<string>, module: any): void {
@@ -287,6 +302,7 @@ function processTsModule(filePath: string, tempFilePath: string, buildFilePath:
const tempModuleInfo: ModuleInfo = new ModuleInfo(filePath, tempFilePath, buildFilePath, abcFilePath, false);
moduleInfos.push(tempModuleInfo);
}
buildMapFileList.push(genSourceMapFileName(buildFilePath));
}
function processJsModule(filePath: string, tempFilePath: string, buildFilePath: string, nodeModulesFile: Array<string>, module: any): void {
@@ -304,6 +320,39 @@ function processJsModule(filePath: string, tempFilePath: string, buildFilePath:
const tempModuleInfo: ModuleInfo = new ModuleInfo(filePath, tempFilePath, buildFilePath, abcFilePath, false);
moduleInfos.push(tempModuleInfo);
}
buildMapFileList.push(genSourceMapFileName(buildFilePath));
}
function getCachedModuleList(): Array<string> {
const CACHED_MODULELIST_FILE: string = path.join(process.env.cachePath, MODULELIST_JSON);
if (!fs.existsSync(CACHED_MODULELIST_FILE)) {
return [];
}
const data: any = JSON.parse(fs.readFileSync(CACHED_MODULELIST_FILE).toString());
const moduleList: Array<string> = data.list;
return moduleList;
}
function updateCachedModuleList(moduleList: Array<string>): void {
const CACHED_MODULELIST_FILE: string = path.join(process.env.cachePath, MODULELIST_JSON);
let cachedJson: Object = {};
cachedJson["list"] = moduleList;
fs.writeFile(CACHED_MODULELIST_FILE, JSON.stringify(cachedJson, null, 2), 'utf-8',
(err)=>{
if (err) {
logger.error(red, `ETS:ERROR Failed to write module list.`, reset);
}
}
);
}
function eliminateUnusedFiles(moduleList: Array<string>): void{
let cachedModuleList: Array<string> = getCachedModuleList();
if (cachedModuleList.length !== 0) {
const eliminateFiles: Array<string> = cachedModuleList.filter(m => !moduleList.includes(m));
eliminateFiles.forEach((file) => {fs.unlinkSync(file);});
}
}
function handleFinishModules(modules, callback): any {
@@ -333,8 +382,16 @@ function handleFinishModules(modules, callback): any {
}
});
judgeModuleWorkersToGenAbc(invokeWorkersModuleToGenAbc);
processEntryToGenAbc(entryInfos);
if (projectConfig.processMergeabc) {
if (projectConfig.buildArkMode === 'debug') {
eliminateUnusedFiles(buildMapFileList);
updateCachedModuleList(buildMapFileList);
}
generateMergedAbc(moduleInfos, entryInfos);
} else {
judgeModuleWorkersToGenAbc(invokeWorkersModuleToGenAbc);
processEntryToGenAbc(entryInfos);
}
}
function processEntryToGenAbc(entryInfos: Map<string, EntryInfo>): void {
@@ -352,16 +409,15 @@ function processEntryToGenAbc(entryInfos: Map<string, EntryInfo>): void {
}
}
function writeFileSync(inputString: string, output: string, jsBundleFile: string): void {
function writeFileSync(inputString: string, buildPath: string, keyPath: string, jsBundleFile: string): void {
let output = path.resolve(buildPath, keyPath);
let parent: string = path.join(output, '..');
if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) {
mkDir(parent);
}
let buildParentPath: string = path.join(projectConfig.buildPath, '..');
let sufStr: string = output.replace(buildParentPath, '');
let cacheOutputPath: string = "";
if (process.env.cachePath) {
cacheOutputPath = path.join(process.env.cachePath, TEMPORARY, sufStr);
cacheOutputPath = path.join(process.env.cachePath, TEMPORARY, keyPath);
} else {
cacheOutputPath = output;
}
@@ -372,6 +428,8 @@ function writeFileSync(inputString: string, output: string, jsBundleFile: string
fs.writeFileSync(cacheOutputPath, inputString);
if (fs.existsSync(cacheOutputPath)) {
const fileSize: any = fs.statSync(cacheOutputPath).size;
output = toUnixPath(output);
cacheOutputPath = toUnixPath(cacheOutputPath);
intermediateJsBundle.push({path: output, size: fileSize, cacheOutputPath: cacheOutputPath});
} else {
logger.error(red, `ETS:ERROR Failed to convert file ${jsBundleFile} to bin. ${output} is lost`, reset);
@@ -425,12 +483,10 @@ function splitJsBundlesBySize(bundleArray: Array<File>, groupNumber: number): an
}
function invokeWorkersModuleToGenAbc(moduleInfos: Array<ModuleInfo>): void {
removeDir(buildPathInfo);
removeDir(projectConfig.nodeModulesPath);
invokeCluterModuleToAbc();
}
function initAbcEnv() : string[] {
export function initAbcEnv() : string[] {
let args: string[] = [];
if (process.env.panda === TS2ABC) {
let js2abc: string = path.join(arkDir, 'build', 'src', 'index.js');
@@ -462,6 +518,9 @@ function initAbcEnv() : string[] {
if (isDebug) {
args.push('--debug-info');
}
if (projectConfig.processMergeabc) {
args.push('--merge-abc');
}
} else {
logger.error(red, `ETS:ERROR please set panda module`, reset);
}
@@ -470,6 +529,9 @@ function initAbcEnv() : string[] {
}
function invokeCluterModuleToAbc(): void {
if (projectConfig.isPreview) {
process.exitCode = SUCCESS;
}
filterIntermediateModuleByHashJson(buildPathInfo, moduleInfos);
filterModuleInfos.forEach(moduleInfo => {
if (moduleInfo.isCommonJs) {
@@ -595,6 +657,9 @@ function judgeModuleWorkersToGenAbc(callback): void {
}
function invokeWorkersToGenAbc(): void {
if (projectConfig.isPreview) {
process.exitCode = SUCCESS;
}
let cmdPrefix: string = '';
let maxWorkerNumber: number = 3;
@@ -643,9 +708,9 @@ function invokeWorkersToGenAbc(): void {
}
count_++;
if (count_ === workerNumber) {
writeHashJson();
clearGlobalInfo();
// for preview of with incre compile
if (projectConfig.isPreview) {
processExtraAssetForBundle();
console.info(red, 'COMPILE RESULT:SUCCESS ', reset);
}
}
@@ -653,13 +718,14 @@ function invokeWorkersToGenAbc(): void {
});
process.on('exit', (code) => {
intermediateJsBundle.forEach((item) => {
const input = item.path;
if (fs.existsSync(input)) {
fs.unlinkSync(input);
}
});
// for build options
processExtraAssetForBundle();
});
// for preview of without incre compile
if (workerNumber === 0 && projectConfig.isPreview) {
processExtraAssetForBundle();
}
}
}
@@ -691,18 +757,18 @@ function filterIntermediateModuleByHashJson(buildPath: string, moduleInfos: Arra
filterModuleInfos = [];
for (let i = 0; i < moduleInfos.length; ++i) {
const input: string = moduleInfos[i].tempFilePath;
const abcPath: string = moduleInfos[i].abcFilePath;
let outputPath: string = moduleInfos[i].abcFilePath;
if (!fs.existsSync(input)) {
logger.error(red, `ETS:ERROR ${input} is lost`, reset);
process.exitCode = FAIL;
break;
}
if (fs.existsSync(abcPath)) {
if (fs.existsSync(outputPath)) {
const hashInputContentData: any = toHashData(input);
const hashAbcContentData: any = toHashData(abcPath);
if (jsonObject[input] === hashInputContentData && jsonObject[abcPath] === hashAbcContentData) {
const hashAbcContentData: any = toHashData(outputPath);
if (jsonObject[input] === hashInputContentData && jsonObject[outputPath] === hashAbcContentData) {
updateJsonObject[input] = hashInputContentData;
updateJsonObject[abcPath] = hashAbcContentData;
updateJsonObject[outputPath] = hashAbcContentData;
mkdirsSync(path.dirname(moduleInfos[i].buildFilePath));
if (projectConfig.buildArkMode === 'debug' && fs.existsSync(moduleInfos[i].tempFilePath)) {
fs.copyFileSync(moduleInfos[i].tempFilePath, moduleInfos[i].buildFilePath);
@@ -726,16 +792,16 @@ function filterIntermediateModuleByHashJson(buildPath: string, moduleInfos: Arra
function writeModuleHashJson(): void {
for (let i = 0; i < filterModuleInfos.length; ++i) {
const input: string = filterModuleInfos[i].tempFilePath;
const abcPath: string = filterModuleInfos[i].abcFilePath;
if (!fs.existsSync(input) || !fs.existsSync(abcPath)) {
let outputPath: string = filterModuleInfos[i].abcFilePath;
if (!fs.existsSync(input) || !fs.existsSync(outputPath)) {
logger.error(red, `ETS:ERROR ${input} is lost`, reset);
process.exitCode = FAIL;
break;
}
const hashInputContentData: any = toHashData(input);
const hashAbcContentData: any = toHashData(abcPath);
const hashAbcContentData: any = toHashData(outputPath);
moduleHashJsonObject[input] = hashInputContentData;
moduleHashJsonObject[abcPath] = hashAbcContentData;
moduleHashJsonObject[outputPath] = hashAbcContentData;
mkdirsSync(path.dirname(filterModuleInfos[i].buildFilePath));
if (projectConfig.buildArkMode === 'debug' && fs.existsSync(filterModuleInfos[i].tempFilePath)) {
fs.copyFileSync(filterModuleInfos[i].tempFilePath, filterModuleInfos[i].buildFilePath);
@@ -782,10 +848,8 @@ function filterIntermediateJsBundleByHashJson(buildPath: string, inputPaths: Fil
jsonObject = JSON.parse(jsonFile);
fileterIntermediateJsBundle = [];
for (let i = 0; i < inputPaths.length; ++i) {
const input: string = inputPaths[i].path;
const abcPath: string = input.replace(/_.js$/, EXTNAME_ABC);
const cacheOutputPath: string = inputPaths[i].cacheOutputPath;
const cacheAbcFilePath: string = cacheOutputPath.replace(/\_.js$/, '.abc');
const cacheAbcFilePath: string = cacheOutputPath.replace(/\.temp\.js$/, '.abc');
if (!fs.existsSync(cacheOutputPath)) {
logger.error(red, `ETS:ERROR ${cacheOutputPath} is lost`, reset);
process.exitCode = FAIL;
@@ -797,10 +861,6 @@ function filterIntermediateJsBundleByHashJson(buildPath: string, inputPaths: Fil
if (jsonObject[cacheOutputPath] === hashInputContentData && jsonObject[cacheAbcFilePath] === hashAbcContentData) {
updateJsonObject[cacheOutputPath] = hashInputContentData;
updateJsonObject[cacheAbcFilePath] = hashAbcContentData;
if (!fs.existsSync(abcPath)) {
mkdirsSync(path.dirname(abcPath));
fs.copyFileSync(cacheAbcFilePath, abcPath);
}
} else {
fileterIntermediateJsBundle.push(inputPaths[i]);
}
@@ -815,10 +875,8 @@ function filterIntermediateJsBundleByHashJson(buildPath: string, inputPaths: Fil
function writeHashJson(): void {
for (let i = 0; i < fileterIntermediateJsBundle.length; ++i) {
const input:string = fileterIntermediateJsBundle[i].path;
const abcPath: string = input.replace(/_.js$/, EXTNAME_ABC);
const cacheOutputPath: string = fileterIntermediateJsBundle[i].cacheOutputPath;
const cacheAbcFilePath: string = cacheOutputPath.replace(/\_.js$/, '.abc');
const cacheAbcFilePath: string = cacheOutputPath.replace(/\.temp\.js$/, '.abc');
if (!fs.existsSync(cacheOutputPath) || !fs.existsSync(cacheAbcFilePath)) {
logger.error(red, `ETS:ERROR ${cacheOutputPath} is lost`, reset);
process.exitCode = FAIL;
@@ -829,22 +887,6 @@ function writeHashJson(): void {
hashJsonObject[cacheOutputPath] = hashInputContentData;
hashJsonObject[cacheAbcFilePath] = hashAbcContentData;
}
for (let i = 0; i < intermediateJsBundle.length; ++i) {
const abcFile: string = intermediateJsBundle[i].path.replace(/\_.js$/, ".abc");
const cacheAbcFilePath: string = intermediateJsBundle[i].cacheOutputPath.replace(/\_.js$/, ".abc");
if (!fs.existsSync(cacheAbcFilePath)) {
logger.error(red, `ETS:ERROR ${cacheAbcFilePath} is lost`, reset);
process.exitCode = FAIL;
break;
}
if (!fs.existsSync(abcFile)) {
mkdirsSync(path.dirname(abcFile));
fs.copyFileSync(cacheAbcFilePath, abcFile);
}
if (fs.existsSync(intermediateJsBundle[i].path)) {
fs.unlinkSync(intermediateJsBundle[i].path);
}
}
const hashFilePath: string = genHashJsonPath(buildPathInfo);
if (hashFilePath.length === 0) {
return;
@@ -895,3 +937,32 @@ function checkNodeModules() {
return true;
}
function copyFileCachePathToBuildPath() {
for (let i = 0; i < intermediateJsBundle.length; ++i) {
const abcFile: string = intermediateJsBundle[i].path.replace(/\.temp\.js$/, ".abc");
const cacheOutputPath: string = intermediateJsBundle[i].cacheOutputPath;
const cacheAbcFilePath: string = intermediateJsBundle[i].cacheOutputPath.replace(/\.temp\.js$/, ".abc");
if (!fs.existsSync(cacheAbcFilePath)) {
logger.error(red, `ETS:ERROR ${cacheAbcFilePath} is lost`, reset);
break;
}
let parent: string = path.join(abcFile, '..');
if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) {
mkDir(parent);
}
// for preview mode, cache path and old abc file both exist, should copy abc file for updating
if (process.env.cachePath !== undefined) {
fs.copyFileSync(cacheAbcFilePath, abcFile);
}
if (process.env.cachePath === undefined && fs.existsSync(cacheOutputPath)) {
fs.unlinkSync(cacheOutputPath);
}
}
}
function processExtraAssetForBundle() {
writeHashJson();
copyFileCachePathToBuildPath();
clearGlobalInfo();
}
+88
View File
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2022 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 * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
import * as childProcess from 'child_process';
import * as process from 'process';
import { logger } from './compile_info';
import { projectConfig } from '../main';
import {
FAIL,
FILESINFO_TXT,
MODULES_ABC,
MODULES_CACHE,
NPMENTRIES_TXT,
NODE_MODULES
} from './pre_define';
import { EntryInfo, ModuleInfo, initAbcEnv } from './gen_abc_plugin';
import { mkdirsSync, toUnixPath } from './utils';
const red: string = '\u001b[31m';
const reset: string = '\u001b[39m';
function generateCompileFilesInfo(moduleInfos: Array<ModuleInfo>) {
const filesInfoPath: string = path.join(process.env.cachePath, FILESINFO_TXT);
let filesInfo: string = '';
moduleInfos.forEach(info => {
const moduleType: string = info.isCommonJs ? 'cjs' : 'esm';
filesInfo += `${info.tempFilePath};${info.recordName};${moduleType}\n`;
});
fs.writeFileSync(filesInfoPath, filesInfo, 'utf-8');
}
function generateNpmEntriesInfo(entryInfos: Map<string, EntryInfo>) {
const npmEntriesInfoPath: string = path.join(process.env.cachePath, NPMENTRIES_TXT);
let entriesInfo: string = '';
for (const value of entryInfos.values()) {
const buildPath: string = value.buildPath.replace(toUnixPath(projectConfig.nodeModulesPath), '');
const entryFile: string = toUnixPath(path.join(buildPath, value.entry));
const entry: string = entryFile.substring(0, entryFile.lastIndexOf('.'));
entriesInfo +=
`${toUnixPath(path.join(NODE_MODULES, buildPath))}:${toUnixPath(path.join(NODE_MODULES, entry))}\n`;
}
fs.writeFileSync(npmEntriesInfoPath, entriesInfo, 'utf-8');
}
export function generateMergedAbc(moduleInfos: Array<ModuleInfo>, entryInfos: Map<string, EntryInfo>) {
generateCompileFilesInfo(moduleInfos);
generateNpmEntriesInfo(entryInfos);
const filesInfoPath: string = path.join(process.env.cachePath, FILESINFO_TXT);
const npmEntriesInfoPath: string = path.join(process.env.cachePath, NPMENTRIES_TXT);
const cacheFilePath: string = path.join(process.env.cachePath, MODULES_CACHE);
const outputABCPath: string = path.join(projectConfig.buildPath, MODULES_ABC);
const fileThreads = os.cpus().length < 16 ? os.cpus().length : 16;
mkdirsSync(projectConfig.buildPath);
const gen_abc_cmd: string =
`${initAbcEnv().join(' ')} "@${filesInfoPath}" --npm-module-entry-list "${npmEntriesInfoPath}" --cache-file "${cacheFilePath}" --output "${outputABCPath}" --file-threads "${fileThreads}"`;
logger.debug('gen abc cmd is: ', gen_abc_cmd);
try {
const child = childProcess.exec(gen_abc_cmd);
child.on('exit', (code: any) => {
if (code === 1) {
logger.error(red, "ETS:ERROR failed to execute es2abc", reset);
}
});
child.on('error', (err: any) => {
logger.error(red, err.toString(), reset);
});
} catch (e) {
logger.error(red, `ETS:ERROR failed to generate abc with filesInfo ${filesInfoPath} `, reset);
process.exit(FAIL);
}
}
+1 -1
View File
@@ -60,7 +60,7 @@ function es2abcByWorkers(jsonInput: string, cmd: string): Promise<void> {
for (let i = 0; i < inputPaths.length; ++i) {
const input: string = inputPaths[i].tempFilePath;
const abcFile: string = input.replace(/\.js$/, '.abc');
const singleCmd: any = `${cmd} "${input}" --output "${abcFile}"`;
const singleCmd: any = `${cmd} "${input}" --output "${abcFile}" --source-file "${input}"`;
logger.debug('gen abc cmd is: ', singleCmd);
try {
childProcess.execSync(singleCmd);
+10 -4
View File
@@ -68,9 +68,8 @@ export const INITIALIZE_CONSUME_FUNCTION: string = 'initializeConsume';
export const ADD_PROVIDED_VAR: string = 'addProvidedVar';
export const APP_STORAGE: string = 'AppStorage';
export const APP_STORAGE_SET_AND_PROP: string = 'setAndProp';
export const APP_STORAGE_SET_AND_LINK: string = 'setAndLink';
export const APP_STORAGE_GET_OR_SET: string = 'GetOrCreate';
export const APP_STORAGE_SET_AND_PROP: string = 'SetAndProp';
export const APP_STORAGE_SET_AND_LINK: string = 'SetAndLink';
export const PAGE_ENTRY_FUNCTION_NAME: string = 'loadDocument';
export const STORE_PREVIEW_COMPONENTS: string = 'storePreviewComponents';
@@ -243,9 +242,15 @@ export const COMPONENT_TOGGLE: string = 'Toggle';
export const TTOGGLE_CHECKBOX: string = 'Checkbox';
export const TOGGLE_SWITCH: string = 'Switch';
export const ENTRY_TXT: string = 'entry.txt';
export const FILESINFO_TXT: string = 'filesInfo.txt';
export const NPMENTRIES_TXT: string = 'npmEntries.txt';
export const MODULES_CACHE: string = 'modules.cache';
export const MODULES_ABC: string = 'modules.abc';
export const MODULELIST_JSON: string = 'moduleList.json';
export const ESMODULE: string = 'esmodule';
export const JSBUNDLE: string = 'jsbundle';
export const ENTRY_TXT: string = 'entry.txt';
export const ARK: string = 'ark';
export const TEMPORARY: string = 'temporary';
export const MAIN: string = 'main';
@@ -260,6 +265,7 @@ export const EXTNAME_MJS: string = '.mjs';
export const EXTNAME_CJS: string = '.cjs';
export const EXTNAME_D_TS: string = '.d.ts';
export const EXTNAME_ABC: string = '.abc';
export const EXTNAME_PROTO_BIN: string = '.protoBin';
export const SUCCESS: number = 0;
export const FAIL: number = 1;
+20 -1
View File
@@ -60,7 +60,8 @@ import {
BIND_POPUP_SET,
$$,
PROPERTIES_ADD_DOUBLE_DOLLAR,
ATTRIBUTE_ID
ATTRIBUTE_ID,
RESOURCE
} from './pre_define';
import {
INNER_COMPONENT_NAMES,
@@ -413,6 +414,7 @@ function processInnerComponent(node: ts.ExpressionStatement, newStatements: ts.S
}
if (etsComponentResult.etsComponentNode.body && ts.isBlock(etsComponentResult.etsComponentNode.body)) {
if (res.isButton) {
checkButtonParamHasLabel(etsComponentResult.etsComponentNode, log);
if (projectConfig.isPreview) {
newStatements.splice(-2, 1, createComponent(node, COMPONENT_CREATE_CHILD_FUNCTION).newNode);
} else {
@@ -1385,3 +1387,20 @@ function checkEtsComponent(node: ts.ExpressionStatement, log: LogInfo[]): void {
);
}
}
function checkButtonParamHasLabel(node: ts.EtsComponentExpression, log: LogInfo[]): void {
if (node.arguments && node.arguments.length !== 0) {
for (let i = 0; i < node.arguments.length; i++) {
let argument: ts.Expression = node.arguments[i];
if (ts.isStringLiteral(argument) || (ts.isCallExpression(argument) && ts.isIdentifier(argument.expression) &&
(argument.expression.escapedText.toString() === RESOURCE))) {
log.push({
type: LogType.ERROR,
message: "The Button component with a label parameter can not have any child.",
pos: node.getStart(),
});
return;
}
}
}
}
@@ -168,5 +168,5 @@ export function addConstructor(ctorNode: any, watchMap: Map<string, ts.Node>,
ts.factory.createThis(), ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_UPDATE_PARAMS)),
undefined, [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARAMS)]));
return updateConstructor(updateConstructor(ctorNode, [], [callSuperStatement], true), [],
[updateWithValueParamsStatement, ...watchStatements], false, true, parentComponentName);
[...watchStatements, updateWithValueParamsStatement], false, true, parentComponentName);
}
+3 -6
View File
@@ -44,7 +44,6 @@ import {
APP_STORAGE,
APP_STORAGE_SET_AND_PROP,
APP_STORAGE_SET_AND_LINK,
APP_STORAGE_GET_OR_SET,
COMPONENT_CONSTRUCTOR_UNDEFINED,
SET_CONTROLLER_METHOD,
SET_CONTROLLER_CTR,
@@ -509,11 +508,9 @@ function updateStoragePropAndLinkProperty(node: ts.PropertyDeclaration, name: ts
return ts.factory.createExpressionStatement(ts.factory.createBinaryExpression(
createPropertyAccessExpressionWithThis(`__${name.getText()}`),
ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createCallExpression(
ts.factory.createPropertyAccessExpression(ts.factory.createCallExpression(
ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(APP_STORAGE),
ts.factory.createIdentifier(APP_STORAGE_GET_OR_SET)), undefined, []),
ts.factory.createIdentifier(setFuncName)), undefined, [node.decorators[0].expression.arguments[0],
node.initializer, ts.factory.createThis()])));
ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(APP_STORAGE),
ts.factory.createIdentifier(setFuncName)), undefined, [node.decorators[0].expression.arguments[0],
node.initializer, ts.factory.createThis(), ts.factory.createStringLiteral(name.getText())])));
} else {
validateAppStorageDecoractorsNonSingleKey(node, log);
}
+2 -2
View File
@@ -17,13 +17,13 @@ import ts from 'typescript';
import {
BUILD_ON
} from './pre_define';
import { writeFileSyncByNode } from './utils';
import { generateSourceFilesToTemporary } from './utils';
export function processJs(program: ts.Program, ut = false): Function {
return (context: ts.TransformationContext) => {
return (node: ts.SourceFile) => {
if (process.env.compiler === BUILD_ON) {
writeFileSyncByNode(node, false);
generateSourceFilesToTemporary(node);
return node;
} else {
return node;
+1 -1
View File
@@ -8,7 +8,7 @@ import {
module.exports = function processjs2file(source: string): string {
if (projectConfig.compileMode === ESMODULE && projectConfig.processTs === false
&& process.env.compilerType && process.env.compilerType === ARK) {
writeFileSyncByString(this.resourcePath, source, false);
writeFileSyncByString(this.resourcePath, source);
}
return source;
};
+39
View File
@@ -1,6 +1,8 @@
import * as fs from 'fs';
import * as path from 'path';
import { logger } from './compile_info';
import { NODE_MODULES, ONE, ZERO } from './pre_define';
import { toUnixPath, getPackageInfo } from './utils';
const { projectConfig } = require('../main');
const red: string = '\u001b[31m';
@@ -86,3 +88,40 @@ export function resolveSourceFile(ohmUrl: string): string {
return file;
}
export function getOhmUrlByFilepath(filePath: string): string {
let unixFilePath: string = toUnixPath(filePath);
unixFilePath = unixFilePath.substring(0, filePath.lastIndexOf('.')); // remove extension
const REG_PROJECT_SRC: RegExp = /(\S+)\/src\/(?:main|ohosTest)\/(ets|js)\/(\S+)/;
const packageInfo: string[] = getPackageInfo(projectConfig.aceModuleJsonPath);
const bundleName: string = packageInfo[0];
const moduleName: string = packageInfo[1];
const moduleRootPath: string = toUnixPath(projectConfig.modulePathMap[moduleName]);
const projectRootPath: string = toUnixPath(projectConfig.projectRootPath);
// case1: /entry/src/main/ets/xxx/yyy
// case2: /node_modules/xxx/yyy
// case3: /entry/node_modules/xxx/yyy
const projectFilePath: string = unixFilePath.replace(projectRootPath, '');
const result: RegExpMatchArray | null = projectFilePath.match(REG_PROJECT_SRC);
if (result && result[1].indexOf(NODE_MODULES) === -1) {
return `${bundleName}/${moduleName}/${result[2]}/${result[3]}`;
}
if (projectFilePath.indexOf(NODE_MODULES) !== -1) {
const tryProjectNPM: string = toUnixPath(path.join(projectRootPath, NODE_MODULES));
if (unixFilePath.indexOf(tryProjectNPM) !== -1) {
return unixFilePath.replace(tryProjectNPM, `${NODE_MODULES}/${ONE}`);
}
const tryModuleNPM: string = toUnixPath(path.join(moduleRootPath, NODE_MODULES));
if (unixFilePath.indexOf(tryModuleNPM) !== -1) {
return unixFilePath.replace(tryModuleNPM, `${NODE_MODULES}/${ZERO}`);
}
}
logger.error(red, `ETS:ERROR Failed to get an resolved OhmUrl by filepath "${filePath}"`, reset);
return filePath;
}
+92 -22
View File
@@ -33,7 +33,8 @@ import {
EXTNAME_ABC,
EXTNAME_ETS,
EXTNAME_TS_MAP,
EXTNAME_JS_MAP
EXTNAME_JS_MAP,
ESMODULE
} from './pre_define';
export enum LogType {
@@ -261,7 +262,7 @@ export function writeFileSync(filePath: string, content: string): void {
fs.writeFileSync(filePath, content);
}
export function genTemporaryPath(filePath: string, projectPath: string, buildPath: string, toTsFile: boolean = true): string {
export function genTemporaryPath(filePath: string, projectPath: string, buildPath: string): string {
filePath = toUnixPath(filePath);
if (filePath.endsWith(EXTNAME_MJS)) {
filePath = filePath.replace(/\.mjs$/, EXTNAME_JS);
@@ -270,19 +271,17 @@ export function genTemporaryPath(filePath: string, projectPath: string, buildPat
filePath = filePath.replace(/\.cjs$/, EXTNAME_JS);
}
projectPath = toUnixPath(projectPath);
const hapPath: string = toUnixPath(projectConfig.projectRootPath);
const tempFilePath: string = filePath.replace(hapPath, '');
if (checkNodeModulesFile(filePath, projectPath)) {
const fakeNodeModulesPath: string = toUnixPath(path.resolve(projectConfig.projectRootPath, NODE_MODULES));
const dataTmps: string[] = tempFilePath.split(NODE_MODULES);
const fakeNodeModulesPath: string = toUnixPath(path.join(projectConfig.projectRootPath, NODE_MODULES));
let output: string = '';
if (filePath.indexOf(fakeNodeModulesPath) === -1) {
const sufStr: string = dataTmps[dataTmps.length - 1];
const hapPath: string = toUnixPath(projectConfig.projectRootPath);
const tempFilePath: string = filePath.replace(hapPath, '');
const sufStr: string = tempFilePath.substring(tempFilePath.indexOf(NODE_MODULES) + NODE_MODULES.length + 1);
output = path.join(buildPath, TEMPORARY, NODE_MODULES, MAIN, sufStr);
} else {
const sufStr: string = dataTmps[dataTmps.length - 1];
output = path.join(buildPath, TEMPORARY, NODE_MODULES, AUXILIARY, sufStr);
output = filePath.replace(fakeNodeModulesPath, path.join(buildPath, TEMPORARY, NODE_MODULES, AUXILIARY));
}
return output;
}
@@ -296,7 +295,7 @@ export function genTemporaryPath(filePath: string, projectPath: string, buildPat
return '';
}
export function genBuildPath(filePath: string, projectPath: string, buildPath: string, toTsFile: boolean = true): string {
export function genBuildPath(filePath: string, projectPath: string, buildPath: string): string {
filePath = toUnixPath(filePath);
if (filePath.endsWith(EXTNAME_MJS)) {
filePath = filePath.replace(/\.mjs$/, EXTNAME_JS);
@@ -305,20 +304,18 @@ export function genBuildPath(filePath: string, projectPath: string, buildPath: s
filePath = filePath.replace(/\.cjs$/, EXTNAME_JS);
}
projectPath = toUnixPath(projectPath);
const hapPath: string = toUnixPath(projectConfig.projectRootPath);
const tempFilePath: string = filePath.replace(hapPath, '');
if (checkNodeModulesFile(filePath, projectPath)) {
filePath = toUnixPath(filePath);
const fakeNodeModulesPath: string = toUnixPath(path.resolve(projectConfig.projectRootPath, NODE_MODULES));
const dataTmps: string[] = tempFilePath.split(NODE_MODULES);
const fakeNodeModulesPath: string = toUnixPath(path.join(projectConfig.projectRootPath, NODE_MODULES));
let output: string = '';
if (filePath.indexOf(fakeNodeModulesPath) === -1) {
const sufStr: string = dataTmps[dataTmps.length - 1];
const hapPath: string = toUnixPath(projectConfig.projectRootPath);
const tempFilePath: string = filePath.replace(hapPath, '');
const sufStr: string = tempFilePath.substring(tempFilePath.indexOf(NODE_MODULES) + NODE_MODULES.length + 1);
output = path.join(projectConfig.nodeModulesPath, ZERO, sufStr);
} else {
const sufStr: string = dataTmps[dataTmps.length - 1];
output = path.join(projectConfig.nodeModulesPath, ONE, sufStr);
output = filePath.replace(fakeNodeModulesPath, path.join(projectConfig.nodeModulesPath, ONE));
}
return output;
}
@@ -367,16 +364,89 @@ export function mkdirsSync(dirname: string): boolean {
return false;
}
export function writeFileSyncByString(sourcePath: string, sourceCode: string, toTsFile: boolean): void {
const temporaryFile: string = genTemporaryPath(sourcePath, projectConfig.projectPath, process.env.cachePath, toTsFile);
if (temporaryFile.length === 0) {
export function writeFileSyncByString(sourcePath: string, sourceCode: string): void {
const jsFilePath: string = genTemporaryPath(sourcePath, projectConfig.projectPath, process.env.cachePath);
if (jsFilePath.length === 0) {
return;
}
mkdirsSync(path.dirname(temporaryFile));
fs.writeFileSync(temporaryFile, sourceCode);
mkdirsSync(path.dirname(jsFilePath));
fs.writeFileSync(jsFilePath, sourceCode);
return;
}
export const packageCollection: Map<string, Array<string>> = new Map();
export function getPackageInfo(configFile: string): Array<string> {
if (packageCollection.has(configFile)) {
return packageCollection.get(configFile);
}
const data: any = JSON.parse(fs.readFileSync(configFile).toString());
const bundleName: string = data.app.bundleName;
const moduleName: string = data.module.name;
packageCollection.set(configFile, [bundleName, moduleName]);
return [bundleName, moduleName];
}
function replaceRelativeDependency(item:string, moduleRequest: string, sourcePath: string): string {
if (sourcePath && projectConfig.compileMode === ESMODULE) {
const filePath: string = path.resolve(path.dirname(sourcePath), moduleRequest);
const result: RegExpMatchArray | null = filePath.match(/(\S+)(\/|\\)src(\/|\\)(?:main|ohosTest)(\/|\\)(ets|js)(\/|\\)(\S+)/);
if (result && projectConfig.aceModuleJsonPath) {
const npmModuleIdx: number = result[1].search(/(\/|\\)node_modules(\/|\\)/);
const projectRootPath: string = projectConfig.projectRootPath;
if (npmModuleIdx === -1 || npmModuleIdx === projectRootPath.search(/(\/|\\)node_modules(\/|\\)/)) {
const packageInfo: string[] = getPackageInfo(projectConfig.aceModuleJsonPath);
const bundleName: string = packageInfo[0];
const moduleName: string = packageInfo[1];
moduleRequest = `@bundle:${bundleName}/${moduleName}/${result[5]}/${toUnixPath(result[7])}`;
item = item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"');
}
}
}
return item;
}
function generateSourceMap(jsFilePath: string, sourceMapContent: string): void {
let buildFilePath: string = genBuildPath(jsFilePath, projectConfig.projectPath, projectConfig.buildPath);
if (buildFilePath.length === 0) {
return;
}
if (buildFilePath.endsWith(EXTNAME_ETS)) {
buildFilePath = buildFilePath.replace(/\.ets$/, EXTNAME_JS);
} else {
buildFilePath = buildFilePath.replace(/\.ts$/, EXTNAME_JS);
}
let buildSourceMapFile: string = genSourceMapFileName(buildFilePath);
mkdirsSync(path.dirname(buildSourceMapFile));
fs.writeFileSync(buildSourceMapFile, sourceMapContent);
}
export function generateSourceFilesToTemporary(node: ts.SourceFile): void {
const mixedInfo: {content: string, sourceMapContent: string} = genContentAndSourceMapInfo(node, false);
let jsFilePath: string = genTemporaryPath(node.fileName, projectConfig.projectPath, process.env.cachePath);
if (jsFilePath.length === 0) {
return;
}
if (jsFilePath.endsWith(EXTNAME_ETS)) {
jsFilePath = jsFilePath.replace(/\.ets$/, EXTNAME_JS);
} else {
jsFilePath = jsFilePath.replace(/\.ts$/, EXTNAME_JS);
}
let sourceMapFile: string = genSourceMapFileName(jsFilePath);
mkdirsSync(path.dirname(jsFilePath));
if (sourceMapFile.length > 0 && projectConfig.buildArkMode === 'debug') {
mixedInfo.content += '\n' + "//# sourceMappingURL=" + path.basename(sourceMapFile);
generateSourceMap(node.fileName, mixedInfo.sourceMapContent);
}
// replace relative moduleSpecifier with ohmURl
const REG_RELATIVE_DEPENDENCY: RegExp = /(?:import|from)(?:\s*)['"]((?:\.\/|\.\.\/).*)['"]/g;
mixedInfo.content = mixedInfo.content.replace(REG_RELATIVE_DEPENDENCY, (item, moduleRequest)=>{
return replaceRelativeDependency(item, moduleRequest, node.fileName);
});
fs.writeFileSync(jsFilePath, mixedInfo.content);
}
export function writeFileSyncByNode(node: ts.SourceFile, toTsFile: boolean): void {
if (toTsFile) {
const newStatements: ts.Node[] = [];
+1 -36
View File
@@ -70,7 +70,7 @@ import {
componentInfo,
addLog,
hasDecorator,
toUnixPath
getPackageInfo
} from './utils';
import { projectConfig, abilityPagesFullPath } from '../main';
import { collectExtend } from './process_ui_syntax';
@@ -135,7 +135,6 @@ export const localStoragePropCollection: Map<string, Map<string, Set<string>>> =
export const isStaticViewCollection: Map<string, boolean> = new Map();
export const packageCollection: Map<string, Array<string>> = new Map();
export const useOSFiles: Set<string> = new Set();
export const sourcemapNamesCollection: Map<string, Map<string, string>> = new Map();
export const originalImportNamesMap: Map<string, string> = new Map();
@@ -841,17 +840,6 @@ export function preprocessNewExtend(content: string, extendCollection?: Set<stri
});
}
function getPackageInfo(configFile: string): Array<string> {
if (packageCollection.has(configFile)) {
return packageCollection.get(configFile);
}
const data: any = JSON.parse(fs.readFileSync(configFile).toString());
const bundleName: string = data.app.bundleName;
const moduleName: string = data.module.name;
packageCollection.set(configFile, [bundleName, moduleName]);
return [bundleName, moduleName];
}
function replaceSystemApi(item: string, systemValue: string, moduleType: string, systemKey: string): string {
if (NATIVE_MODULE.has(`${moduleType}.${systemKey}`)) {
item = `var ${systemValue} = globalThis.requireNativeModule('${moduleType}.${systemKey}')`;
@@ -967,26 +955,6 @@ function replaceOhmUrl(isSystemModule: boolean, item: string, importValue: strin
return item;
}
function replaceRelativePath(item:string, moduleRequest: string, sourcePath: string): string {
// Do not replace relativePath to ohmUrl when building bundle
if (sourcePath && projectConfig.compileMode === ESMODULE) {
const filePath: string = path.resolve(path.dirname(sourcePath), moduleRequest);
const result: RegExpMatchArray | null = filePath.match(/(\S+)(\/|\\)src(\/|\\)(?:main|ohosTest)(\/|\\)(ets|js)(\/|\\)(\S+)/);
if (result && projectConfig.aceModuleJsonPath) {
const npmModuleIdx: number = result[1].search(/(\/|\\)node_modules(\/|\\)/);
const projectRootPath: string = projectConfig.projectRootPath;
if (npmModuleIdx == -1 || npmModuleIdx == projectRootPath.search(/(\/|\\)node_modules(\/|\\)/)) {
const packageInfo: string[] = getPackageInfo(projectConfig.aceModuleJsonPath);
const bundleName: string = packageInfo[0];
const moduleName: string = packageInfo[1];
moduleRequest = `@bundle:${bundleName}/${moduleName}/${result[5]}/${toUnixPath(result[7])}`;
item = item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"');
}
}
}
return item;
}
export function processSystemApi(content: string, isProcessAllowList: boolean = false,
sourcePath: string = null, isSystemModule: boolean = false): string {
if (isProcessAllowList && projectConfig.compileMode === ESMODULE) {
@@ -1028,14 +996,11 @@ export function processSystemApi(content: string, isProcessAllowList: boolean =
const moduleType: string = result[1];
const apiName: string = result[2];
return replaceSystemApi(item, importValue, moduleType, apiName);
} else if (/^(\.|\.\.)\//.test(moduleRequest)) { // relativePath
return replaceRelativePath(item, moduleRequest, sourcePath);
} else if (/^lib(\S+)\.so$/.test(moduleRequest)) { // libxxx.so
const result: RegExpMatchArray = moduleRequest.match(/^lib(\S+)\.so$/);
const libSoKey: string = result[1];
return replaceLibSo(importValue, libSoKey, sourcePath);
}
// node_modules
return item;
});
return processInnerModule(processedContent, systemValueCollection);
+2 -1
View File
@@ -36,7 +36,8 @@ import hello from 'libhello.so'
import world = require('libworld.so')`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "importSystemApi_" + ++__generate__Id;
}
@@ -74,7 +74,8 @@ struct HomeComponent {
}`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "$$_component_" + ++__generate__Id;
}
@@ -46,7 +46,8 @@ struct Banner {
}`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "custom_component_" + ++__generate__Id;
}
@@ -37,7 +37,8 @@ struct LongPressGestureExample {
}`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "longPressGesture_" + ++__generate__Id;
}
@@ -45,7 +45,8 @@ struct PanGestureExample {
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "panGestrue_" + ++__generate__Id;
}
@@ -41,7 +41,8 @@ struct PinchGestureExample {
}`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "pinchGesture_" + ++__generate__Id;
}
@@ -41,7 +41,8 @@ struct RotationGestureExample {
}`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "rotationGesture_" + ++__generate__Id;
}
@@ -39,7 +39,8 @@ struct SwipeGestureExample {
}`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "swipeGesture_" + ++__generate__Id;
}
@@ -35,7 +35,8 @@ struct TapGestureExample {
}`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "tapGesture_" + ++__generate__Id;
}
@@ -102,7 +102,8 @@ struct MyComponent {
}`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "forEach_" + ++__generate__Id;
}
@@ -107,7 +107,8 @@ struct MyComponent {
}`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "lazyForEach_" + ++__generate__Id;
}
@@ -34,7 +34,8 @@ struct ButtonExample {
}
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "button_" + ++__generate__Id;
}
@@ -58,7 +58,8 @@ struct TransitionExample {
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "animateTo_" + ++__generate__Id;
}
@@ -46,7 +46,8 @@ struct PageTransitionExample1 {
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "pageTransition_" + ++__generate__Id;
}
@@ -142,7 +142,8 @@ struct MyComponent {
}
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "@builder_" + ++__generate__Id;
}
@@ -38,7 +38,8 @@ struct TestPage{
}
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "@builderWithLinkData_" + ++__generate__Id;
}
@@ -99,7 +99,8 @@ struct CustomDialogUser {
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "@customDialog_" + ++__generate__Id;
}
@@ -54,7 +54,8 @@ struct FancyUse {
}
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "@extend_" + ++__generate__Id;
}
@@ -37,7 +37,8 @@ struct HomePreviewComponent_Preview {
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "@preview_" + ++__generate__Id;
}
@@ -54,7 +54,8 @@ struct FancyUse {
}`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "@styles_" + ++__generate__Id;
}
@@ -48,7 +48,8 @@ struct MyComponent {
}
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "@storageLink_" + ++__generate__Id;
}
@@ -57,8 +58,8 @@ let envLang = AppStorage.Prop('languageCode');
class MyComponent extends View {
constructor(compilerAssignedUniqueChildId, parent, params) {
super(compilerAssignedUniqueChildId, parent);
this.__varA = AppStorage.GetOrCreate().setAndLink('varA', 2, this);
this.__lang = AppStorage.GetOrCreate().setAndProp('languageCode', 'en', this);
this.__varA = AppStorage.SetAndLink('varA', 2, this, "varA");
this.__lang = AppStorage.SetAndProp('languageCode', 'en', this, "lang");
this.label = 'count';
this.updateWithValueParams(params);
}
@@ -48,7 +48,8 @@ struct MyComponent {
}
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "@storageProp_" + ++__generate__Id;
}
@@ -57,8 +58,8 @@ let envLang = AppStorage.Prop('languageCode');
class MyComponent extends View {
constructor(compilerAssignedUniqueChildId, parent, params) {
super(compilerAssignedUniqueChildId, parent);
this.__varA = AppStorage.GetOrCreate().setAndLink('varA', 2, this);
this.__lang = AppStorage.GetOrCreate().setAndProp('languageCode', 'en', this);
this.__varA = AppStorage.SetAndLink('varA', 2, this, "varA");
this.__lang = AppStorage.SetAndProp('languageCode', 'en', this, "lang");
this.label = 'count';
this.updateWithValueParams(params);
}
@@ -48,7 +48,8 @@ struct MyComponent {
}
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "appStorage_" + ++__generate__Id;
}
@@ -57,8 +58,8 @@ let envLang = AppStorage.Prop('languageCode');
class MyComponent extends View {
constructor(compilerAssignedUniqueChildId, parent, params) {
super(compilerAssignedUniqueChildId, parent);
this.__varA = AppStorage.GetOrCreate().setAndLink('varA', 2, this);
this.__lang = AppStorage.GetOrCreate().setAndProp('languageCode', 'en', this);
this.__varA = AppStorage.SetAndLink('varA', 2, this, "varA");
this.__lang = AppStorage.SetAndProp('languageCode', 'en', this, "lang");
this.label = 'count';
this.updateWithValueParams(params);
}
@@ -43,7 +43,8 @@ struct LocalStorageComponent {
}
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "localStorage_" + ++__generate__Id;
}
@@ -68,7 +68,8 @@ struct linkPage {
}
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "@link_" + ++__generate__Id;
}
@@ -64,7 +64,8 @@ struct PageComponent {
}
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "@prop_" + ++__generate__Id;
}
@@ -56,7 +56,8 @@ struct EntryComponent {
}
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "@state_" + ++__generate__Id;
}
@@ -59,7 +59,8 @@ struct CompC {
}
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "@consume_@provide_" + ++__generate__Id;
}
@@ -57,7 +57,8 @@ struct ViewB {
}
`
exports.expectResult =
`var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
`"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -65,7 +65,8 @@ struct CompA {
}
`
exports.expectResult =
`let __generate__Id = 0;
`"use strict";
let __generate__Id = 0;
function generateId() {
return "@watch_" + ++__generate__Id;
}
@@ -76,9 +77,9 @@ class CompA extends View {
this.__totalPurchase = new ObservedPropertySimple(0, this, "totalPurchase");
this.__defArray = new ObservedPropertyObject(['c', 'g', 't', 'z'], this, "defArray");
this.__resultTip = new ObservedPropertySimple('', this, "resultTip");
this.updateWithValueParams(params);
this.declareWatch("shopBasket", this.onBasketUpdated);
this.declareWatch("defArray", this.onPutItem);
this.updateWithValueParams(params);
}
updateWithValueParams(params) {
if (params.shopBasket !== undefined) {
+2 -1
View File
@@ -582,7 +582,8 @@
"typeRoots": [],
"lib": [
"es2020"
]
],
"alwaysStrict": true
},
"exclude": [
"node_modules"
+2 -1
View File
@@ -582,7 +582,8 @@
"typeRoots": [],
"lib": [
"es2020"
]
],
"alwaysStrict": true
},
"exclude": [
"node_modules"
+24
View File
@@ -17,6 +17,7 @@ const path = require('path');
const fs = require('fs');
const CopyPlugin = require('copy-webpack-plugin');
const Webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const { GenAbcPlugin } = require('./lib/gen_abc_plugin');
const { OHMResolverPlugin } = require('./lib/resolve_ohm_url');
const buildPipeServer = require('./server/build_pipe_server');
@@ -344,6 +345,28 @@ function setGenAbcPlugin(env, config) {
}
}
function setCleanWebpackPlugin(workerFile, config) {
if (projectConfig.compileMode === 'esmodule') {
return;
}
let cleanPath = [];
cleanPath.push(projectConfig.buildPath);
if (workerFile) {
let workerFilesPath = Object.keys(workerFile);
for (let workerFilePath of workerFilesPath) {
cleanPath.push(path.join(projectConfig.buildPath, workerFilePath, '..'));
}
}
config.plugins.push(
new CleanWebpackPlugin({
dry: false,
dangerouslyAllowCleanPatternsOutsideProject: true,
cleanOnceBeforeBuildPatterns: cleanPath
})
);
}
module.exports = (env, argv) => {
const config = {};
setProjectConfig(env);
@@ -354,6 +377,7 @@ module.exports = (env, argv) => {
const workerFile = readWorkerFile();
setOptimizationConfig(config, workerFile);
setCopyPluginConfig(config);
setCleanWebpackPlugin(workerFile, config);
if (env.isPreview !== "true") {
loadWorker(projectConfig, workerFile);