!3560 添加了//@ts-ignore,ts编译后落盘为js,但是在sourcemap中key没有使用正确的.js后缀

Merge pull request !3560 from 施涛/middle_path_fix
This commit is contained in:
openharmony_ci 2024-07-03 06:48:22 +00:00 committed by Gitee
commit 97a2aada88
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 77 additions and 1 deletions

View File

@ -117,7 +117,7 @@ export class SourceMapGenerator {
}
const dependencyPkgInfo = metaInfo['dependencyPkgInfo'];
let middlePath = this.getIntermediateModuleId(moduleId.replace(pkgPath + path.sep, ''));
let middlePath = this.getIntermediateModuleId(moduleId).replace(pkgPath + path.sep, '');
if (shouldObfuscateFileName) {
middlePath = mangleFilePath(middlePath);
}

View File

@ -28,6 +28,11 @@ import {
ENTRY_PACKAGE_NAME_DEFAULT,
ENTRY_MODULE_VERSION_DEFAULT
} from '../mock/rollup_mock/common';
import {
compilingEtsOrTsFiles,
hasTsNoCheckOrTsIgnoreFiles,
cleanUpFilesList
} from '../../../lib/fast_build/ark_compiler/utils';
const prefix = `${ENTRY_PACKAGE_NAME_DEFAULT}|${ENTRY_PACKAGE_NAME_DEFAULT}|${ENTRY_MODULE_VERSION_DEFAULT}|`;
let entryPkgInfo = `${ENTRY_PACKAGE_NAME_DEFAULT}|${ENTRY_MODULE_VERSION_DEFAULT}`;
@ -48,6 +53,7 @@ mocha.describe('test generate_sourcemap api', function () {
let pkgInfo = sourceMapGenerator.getPkgInfoByModuleId(moduleId);
expect(pkgInfo && pkgInfo.entry && pkgInfo.modulePath && pkgInfo.entry.name && pkgInfo.entry.version !== '' && pkgInfo.entry.version != undefined).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('1-2: test getPkgInfoByModuleId under build release', function () {
@ -57,6 +63,7 @@ mocha.describe('test generate_sourcemap api', function () {
let pkgInfo = sourceMapGenerator.getPkgInfoByModuleId(moduleId);
expect(pkgInfo && pkgInfo.entry && pkgInfo.modulePath && pkgInfo.entry.name && pkgInfo.entry.version !== '' && pkgInfo.entry.version != undefined).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('1-3: test getPkgInfoByModuleId under preview', function () {
@ -66,6 +73,7 @@ mocha.describe('test generate_sourcemap api', function () {
let pkgInfo = sourceMapGenerator.getPkgInfoByModuleId(moduleId);
expect(pkgInfo && pkgInfo.entry && pkgInfo.modulePath && pkgInfo.entry.name && pkgInfo.entry.version !== '' && pkgInfo.entry.version != undefined).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('1-4: test getPkgInfoByModuleId under hotReload', function () {
@ -75,6 +83,7 @@ mocha.describe('test generate_sourcemap api', function () {
let pkgInfo = sourceMapGenerator.getPkgInfoByModuleId(moduleId);
expect(pkgInfo && pkgInfo.entry && pkgInfo.modulePath && pkgInfo.entry.name && pkgInfo.entry.version !== '' && pkgInfo.entry.version != undefined).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('1-5: test getPkgInfoByModuleId with file name obfuscate', function () {
@ -84,6 +93,7 @@ mocha.describe('test generate_sourcemap api', function () {
let pkgInfo = sourceMapGenerator.getPkgInfoByModuleId(moduleId, true);
expect(pkgInfo && pkgInfo.entry && pkgInfo.modulePath && pkgInfo.entry.name && pkgInfo.entry.version !== '' && pkgInfo.entry.version != undefined).to.be.true;
expect(pkgInfo.modulePath == 'src/main/a/b.js').to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('2-1: test genKey under build debug', function () {
@ -94,6 +104,7 @@ mocha.describe('test generate_sourcemap api', function () {
let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
expect(genKey === expectKey).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('2-2: test genKey under build release', function () {
@ -104,6 +115,7 @@ mocha.describe('test generate_sourcemap api', function () {
let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
expect(genKey === expectKey).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('2-3: test genKey under preview', function () {
@ -114,6 +126,7 @@ mocha.describe('test generate_sourcemap api', function () {
let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
expect(genKey === expectKey).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('2-4: test genKey under hotReload', function () {
@ -124,6 +137,7 @@ mocha.describe('test generate_sourcemap api', function () {
let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
expect(genKey === expectKey).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('2-5: test genKey with file name obfuscate', function () {
@ -133,6 +147,7 @@ mocha.describe('test generate_sourcemap api', function () {
let genKey = sourceMapGenerator.genKey(moduleId, true);
let expectKey = 'entry|entry|1.0.0|src/main/a/b.js';
expect(genKey === expectKey).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('3-1: test updateSourceMap under build debug', function () {
@ -143,6 +158,7 @@ mocha.describe('test generate_sourcemap api', function () {
sourceMapGenerator.updateSourceMap(moduleId, sourceMapData);
let sourceMapDataGet = sourceMapGenerator.getSourceMap(moduleId);
expect(sourceMapData === sourceMapDataGet).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('3-2: test updateSourceMap under build release', function () {
@ -153,6 +169,7 @@ mocha.describe('test generate_sourcemap api', function () {
sourceMapGenerator.updateSourceMap(moduleId, sourceMapData);
let sourceMapDataGet = sourceMapGenerator.getSourceMap(moduleId);
expect(sourceMapData === sourceMapDataGet).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('3-3: test updateSourceMap under preview', function () {
@ -163,6 +180,7 @@ mocha.describe('test generate_sourcemap api', function () {
sourceMapGenerator.updateSourceMap(moduleId, sourceMapData);
let sourceMapDataGet = sourceMapGenerator.getSourceMap(moduleId);
expect(sourceMapData === sourceMapDataGet).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('3-4: test updateSourceMap under hotReload', function () {
@ -173,6 +191,7 @@ mocha.describe('test generate_sourcemap api', function () {
sourceMapGenerator.updateSourceMap(moduleId, sourceMapData);
let sourceMapDataGet = sourceMapGenerator.getSourceMap(moduleId);
expect(sourceMapData === sourceMapDataGet).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('4-1: test fillSourceMapPackageInfo under build debug', function () {
@ -183,6 +202,7 @@ mocha.describe('test generate_sourcemap api', function () {
let sourceMapData = {};
sourceMapGenerator.fillSourceMapPackageInfo(moduleId, sourceMapData);
expect(sourceMapData['entry-package-info'] && sourceMapData['entry-package-info'] === entryPkgInfo).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('4-2: test fillSourceMapPackageInfo under build release', function () {
@ -193,6 +213,7 @@ mocha.describe('test generate_sourcemap api', function () {
let sourceMapData = {};
sourceMapGenerator.fillSourceMapPackageInfo(moduleId, sourceMapData);
expect(sourceMapData['entry-package-info'] && sourceMapData['entry-package-info'] === entryPkgInfo).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('4-3: test fillSourceMapPackageInfo under preview', function () {
@ -203,6 +224,7 @@ mocha.describe('test generate_sourcemap api', function () {
let sourceMapData = {};
sourceMapGenerator.fillSourceMapPackageInfo(moduleId, sourceMapData);
expect(sourceMapData['entry-package-info'] && sourceMapData['entry-package-info'] === entryPkgInfo).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('4-4: test fillSourceMapPackageInfo under hotReload', function () {
@ -213,6 +235,60 @@ mocha.describe('test generate_sourcemap api', function () {
let sourceMapData = {};
sourceMapGenerator.fillSourceMapPackageInfo(moduleId, sourceMapData);
expect(sourceMapData['entry-package-info'] && sourceMapData['entry-package-info'] === entryPkgInfo).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('5-1: test genKey under build debug: arkProjectConfig.processTs is true', function () {
this.rollup.build();
this.rollup.share.arkProjectConfig.processTs = true;
const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
compilingEtsOrTsFiles.push(moduleId);
hasTsNoCheckOrTsIgnoreFiles.push(moduleId);
let genKey = sourceMapGenerator.genKey(moduleId);
cleanUpFilesList();
let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
expect(genKey === expectKey).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('5-2: test genKey under build release: arkProjectConfig.processTs is true', function () {
this.rollup.build(RELEASE);
const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
compilingEtsOrTsFiles.push(moduleId);
hasTsNoCheckOrTsIgnoreFiles.push(moduleId);
let genKey = sourceMapGenerator.genKey(moduleId);
cleanUpFilesList();
let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
expect(genKey === expectKey).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('5-3: test genKey under preview: arkProjectConfig.processTs is true', function () {
this.rollup.preview();
const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
compilingEtsOrTsFiles.push(moduleId);
hasTsNoCheckOrTsIgnoreFiles.push(moduleId);
let genKey = sourceMapGenerator.genKey(moduleId);
cleanUpFilesList();
let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
expect(genKey === expectKey).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
mocha.it('5-4: test genKey under hotReload: arkProjectConfig.processTs is true', function () {
this.rollup.hotReload();
const sourceMapGenerator: SourceMapGenerator = SourceMapGenerator.initInstance(this.rollup);
let moduleId = path.join(this.rollup.share.projectConfig.modulePath, ENTRYABILITY_TS_PATH_DEFAULT);
compilingEtsOrTsFiles.push(moduleId);
hasTsNoCheckOrTsIgnoreFiles.push(moduleId);
let genKey = sourceMapGenerator.genKey(moduleId);
cleanUpFilesList();
let expectKey = prefix + ENTRYABILITY_JS_PATH_DEFAULT.substring(1);
expect(genKey === expectKey).to.be.true;
SourceMapGenerator.cleanSourceMapObject();
});
});