Skip to content

Commit

Permalink
fix onEmtry hook #72
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Sep 13, 2024
1 parent 0d557e2 commit 338e5e6
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 96 deletions.
52 changes: 32 additions & 20 deletions lib/v8/v8.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,6 @@ const initV8ListAndSourcemap = async (mcr, v8list) => {
// console.log(entry);
});

// onEntry hook
// after filter but before init, because id depends source and sourcePath
const onEntry = options.onEntry;
if (typeof onEntry === 'function') {
for (const entry of v8list) {
await onEntry(entry);
}
}

const sourcePathReplacer = getSourcePathReplacer(options);

const baseDir = options.baseDir;
Expand Down Expand Up @@ -231,6 +222,17 @@ const mergeJsFunctions = (itemList) => {
});
};

const onEntryHandler = async (entry, options) => {

// onEntry hook
// after filter but before init, because id depends source and sourcePath
const onEntry = options.onEntry;
if (typeof onEntry === 'function') {
await onEntry(entry);
}

};

const mergeV8Coverage = async (dataList, sourceCache, options) => {

let allList = [];
Expand Down Expand Up @@ -270,29 +272,39 @@ const mergeV8Coverage = async (dataList, sourceCache, options) => {
}
}

// first time filter for empty, (not for sources)
// empty and not in item map
const emptyList = allList.filter((it) => it.empty).filter((it) => !itemMap[it.id]);
const coverageMergedList = Object.values(itemMap);

// first time filter for empty (not for sources)
// empty and not in itemMap
// is empty but not source, means id is not right (without source)
// filter with sourcePath
const emptyList = allList.filter((it) => it.empty).filter((it) => {
return !coverageMergedList.find((m) => m.sourcePath === it.sourcePath);
});

// console.log(emptyList);

// empty list + merged list
const mergedList = emptyList.concat(Object.values(itemMap));
const mergedList = emptyList.concat(coverageMergedList);

// try to load coverage and source by id
for (const item of mergedList) {
const {
id, type, empty
} = item;
const { id, type } = item;
const json = sourceCache.get(id);
if (json) {
item.source = json.source;
item.sourceMap = json.sourceMap;
} else {
Util.logError(`Not found source data: ${Util.relativePath(item.sourcePath)}`);
item.source = '';
}

// before item.source.length to update source and sourceMap
await onEntryHandler(item, options);

// add empty coverage after merged
if (empty) {
if (item.empty) {

// update id for empty
// item.id = Util.calculateSha1(item.sourcePath + item.source);

if (type === 'js') {
item.functions = [{
functionName: '',
Expand Down
148 changes: 74 additions & 74 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"stylelint": "^16.9.0",
"stylelint-config-plus": "^1.1.3",
"supports-color": "^9.4.0",
"tsx": "^4.19.0",
"tsx": "^4.19.1",
"turbogrid": "^3.2.0",
"vine-ui": "^3.1.16",
"ws": "^8.18.0"
Expand Down
Loading

0 comments on commit 338e5e6

Please sign in to comment.