diff --git a/compiler/src/fast_build/ark_compiler/bundle/bundle_mode.ts b/compiler/src/fast_build/ark_compiler/bundle/bundle_mode.ts index e4c3200d556176382c43d30efb8a56033204c23f..0648f6fbc71e798728422c45eefe12b2deef7181 100644 --- a/compiler/src/fast_build/ark_compiler/bundle/bundle_mode.ts +++ b/compiler/src/fast_build/ark_compiler/bundle/bundle_mode.ts @@ -40,9 +40,7 @@ import { red, blue, FAIL, - reset, - TEMPORARY, - RELEASEASSETS + reset } from '../common/ark_define'; import { mkDir, @@ -185,7 +183,12 @@ export class BundleMode extends CommonMode { const cacheFilePath: string = info.cacheFilePath; const recordName: string = 'null_recordName'; const moduleType: string = 'script'; - const sourceFile: string = this.generateReleaseSourceFileName(cacheFilePath); + // In release mode, there are '.temp.js' and '.js' file in cache path, no js file in output path. + // In debug mode, '.temp.js' file is in cache path, and '.js' file is in output path. + // '.temp.js' file is the input of es2abc, and should be uesd as sourceFile here. However,in debug mode , + // using '.temp.js' file as sourceFile needs IDE to adapt, so use '.js' file in output path instead temporarily. + const sourceFile: string = isDebug(this.projectConfig) ? info.sourceFile.replace(/(.*)_/, '$1') : + cacheFilePath.replace(toUnixPath(this.projectConfig.projectRootPath) + '/', ''); const abcFilePath: string = changeFileExtension(cacheFilePath, EXTNAME_ABC); filesInfo += `${cacheFilePath};${recordName};${moduleType};${sourceFile};${abcFilePath}\n`; }); @@ -401,12 +404,4 @@ export class BundleMode extends CommonMode { fs.unlinkSync(this.hashJsonFilePath); } } - private generateReleaseSourceFileName(fileName: string): string { - let relativeFileName: string = fileName.replace(toUnixPath(this.projectConfig.cachePath) + '/', ''); - relativeFileName = relativeFileName.replace(TEMPORARY, RELEASEASSETS); - relativeFileName = changeFileExtension(relativeFileName, EXTNAME_JS, TEMP_JS); - const relativeCachePath: string = toUnixPath(this.projectConfig.cachePath.replace( - this.projectConfig.projectRootPath + path.sep, '')); - return relativeCachePath + '/' + relativeFileName; - } } diff --git a/compiler/src/fast_build/ark_compiler/common/ark_define.ts b/compiler/src/fast_build/ark_compiler/common/ark_define.ts index 371841190dabd0224d050e3fbacab411f8917c92..c6b3814e3ff5ce6a1971049ad0a8b65119e0062c 100644 --- a/compiler/src/fast_build/ark_compiler/common/ark_define.ts +++ b/compiler/src/fast_build/ark_compiler/common/ark_define.ts @@ -38,7 +38,6 @@ export const ESMODULE: string = 'esmodule'; export const JSBUNDLE: string = 'jsbundle'; export const ARK: string = 'ark'; export const TEMPORARY: string = 'temporary'; -export const RELEASEASSETS: string = 'releaseAssets'; export const MAIN: string = 'main'; export const AUXILIARY: string = 'auxiliary'; export const HAP_PACKAGE: string = '0'; diff --git a/compiler/test/ark_compiler_ut/bundle/bundle_mode.test.ts b/compiler/test/ark_compiler_ut/bundle/bundle_mode.test.ts index 8872a36dd0b2691e2742b75181a411ee98fbbfbe..833db55b47bc8b74eaa305cb89f7b32675d06f51 100644 --- a/compiler/test/ark_compiler_ut/bundle/bundle_mode.test.ts +++ b/compiler/test/ark_compiler_ut/bundle/bundle_mode.test.ts @@ -18,10 +18,17 @@ import mocha from 'mocha'; import sinon from 'sinon'; import fs from 'fs'; import cluster from 'cluster'; +import path from 'path'; import RollUpPluginMock from '../mock/rollup_mock/rollup_plugin_mock'; import { BundleMode } from '../../../lib/fast_build/ark_compiler/bundle/bundle_mode'; - +import { changeFileExtension } from '../../../lib/fast_build/ark_compiler/utils' +import { + DEBUG, + RELEASE, + TEMPORARY +} from '../../../lib/fast_build/ark_compiler/common/ark_define' +import { toUnixPath } from '../../../lib/utils' mocha.describe('test bundle_mode file api', function () { mocha.before(function () { @@ -191,4 +198,42 @@ mocha.describe('test bundle_mode file api', function () { 'Please try to rebuild the project')).to.be.true; stub.restore(); }); + + mocha.it('8-1: test sourceFile field of bundle mode in release', function () { + this.rollup.build(); + this.rollup.share.projectConfig.buildMode = RELEASE + const rollupBundleFileSet: Object = { + 'test.js': { + 'type': 'asset', + 'source': 'test' + } + }; + const bundleMode = new BundleMode(this.rollup, rollupBundleFileSet); + const filesinfo: string[] = fs.readFileSync(bundleMode.generateFileInfoOfBundle()).toString().split(";"); + // sourceFile is the 4th field in filesInfo + const sourceFile: string = filesinfo[3]; + const relativeCachePath: string = toUnixPath(bundleMode.projectConfig.cachePath.replace( + bundleMode.projectConfig.projectRootPath + path.sep, '')); + const buildDirArr: string[] = bundleMode.projectConfig.aceModuleBuild.split(path.sep); + const abilityDir: string = buildDirArr[buildDirArr.length - 1]; + + expect(sourceFile === path.join(relativeCachePath, TEMPORARY, abilityDir, 'test.temp.js')).to.be.true; + }); + + mocha.it('9-1: test sourceFile field of bundle mode in debug', function () { + this.rollup.build(); + this.rollup.share.projectConfig.buildMode = DEBUG + const rollupBundleFileSet: Object = { + 'test.js': { + 'type': 'asset', + 'source': 'test' + } + }; + const bundleMode = new BundleMode(this.rollup, rollupBundleFileSet); + const filesinfo: string[] = fs.readFileSync(bundleMode.generateFileInfoOfBundle()).toString().split(";"); + // sourceFile is the 4th field in filesInfo + const sourceFile: string = filesinfo[3]; + + expect(sourceFile === path.join(bundleMode.projectConfig.aceModuleBuild, 'test.js')).to.be.true; + }); }); \ No newline at end of file