feat:debug support multi entry and fix some bugs

This commit is contained in:
pengfeizhou
2021-02-24 19:13:19 +08:00
committed by osborn
parent 0e7f68a2c2
commit d56281a77f
6 changed files with 51 additions and 31 deletions

View File

@@ -4347,26 +4347,33 @@ function initNativeEnvironment(source) {
});
});
}
const entryHooks = [];
global$2.Entry = function () {
var _a, _b, _c;
if (!!contextId) {
return Reflect.apply(jsObtainEntry(contextId), doric, arguments);
}
else {
const jsFile = (_c = (_b = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").map(e => e.match(/at\s__decorate\s\((.*?)\)/)).find(e => !!e)) === null || _b === void 0 ? void 0 : _b[1].match(/(.*?\.js)/)) === null || _c === void 0 ? void 0 : _c[1];
console.log(new Error().stack);
const jsFile = (_c = (_b = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").map(e => e.match(/at\s__decorate.*?\s\((.*?)\)/)).find(e => !!e)) === null || _b === void 0 ? void 0 : _b[1].match(/(.*?\.js)/)) === null || _c === void 0 ? void 0 : _c[1];
if (!jsFile) {
throw new Error("Cannot find debugging file");
}
const source = path__default['default'].basename(jsFile);
const args = arguments;
console.log(`Debugging ${source}`);
initNativeEnvironment(source).then(ret => {
contextId = ret;
console.log("debugging context id: " + contextId);
global$2.context = jsObtainContext(contextId);
entryHooks.push((contextId) => {
Reflect.apply(jsObtainEntry(contextId), doric, args);
});
return arguments[0];
if (entryHooks.length <= 1) {
const source = path__default['default'].basename(jsFile);
console.log(`Debugging ${source}`);
initNativeEnvironment(source).then(ret => {
contextId = ret;
console.log("debugging context id: " + contextId);
global$2.context = jsObtainContext(contextId);
entryHooks.forEach(e => e(contextId));
});
return arguments[0];
}
}
};
global$2.injectGlobal = (objName, obj) => {

View File

@@ -136,27 +136,33 @@ async function initNativeEnvironment(source: string) {
})
}
const entryHooks: Function[] = []
global.Entry = function () {
if (!!contextId) {
return Reflect.apply(doric.jsObtainEntry(contextId), doric, arguments);
} else {
console.log(new Error().stack)
const jsFile = new Error().stack?.split("\n")
.map(e => e.match(/at\s__decorate\s\((.*?)\)/))
.map(e => e.match(/at\s__decorate.*?\s\((.*?)\)/))
.find(e => !!e)?.[1].match(/(.*?\.js)/)?.[1];
if (!jsFile) {
throw new Error("Cannot find debugging file");
}
const source = path.basename(jsFile)
const args = arguments
console.log(`Debugging ${source}`)
initNativeEnvironment(source).then(ret => {
contextId = ret;
console.log("debugging context id: " + contextId);
global.context = doric.jsObtainContext(contextId);
entryHooks.push((contextId: string) => {
Reflect.apply(doric.jsObtainEntry(contextId), doric, args);
});
return arguments[0];
})
if (entryHooks.length <= 1) {
const source = path.basename(jsFile)
console.log(`Debugging ${source}`)
initNativeEnvironment(source).then(ret => {
contextId = ret;
console.log("debugging context id: " + contextId);
global.context = doric.jsObtainContext(contextId);
entryHooks.forEach(e => e(contextId))
});
return arguments[0];
}
}
}

View File

@@ -147,26 +147,33 @@ function initNativeEnvironment(source) {
});
});
}
const entryHooks = [];
global.Entry = function () {
var _a, _b, _c;
if (!!contextId) {
return Reflect.apply(doric.jsObtainEntry(contextId), doric, arguments);
}
else {
const jsFile = (_c = (_b = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").map(e => e.match(/at\s__decorate\s\((.*?)\)/)).find(e => !!e)) === null || _b === void 0 ? void 0 : _b[1].match(/(.*?\.js)/)) === null || _c === void 0 ? void 0 : _c[1];
console.log(new Error().stack);
const jsFile = (_c = (_b = (_a = new Error().stack) === null || _a === void 0 ? void 0 : _a.split("\n").map(e => e.match(/at\s__decorate.*?\s\((.*?)\)/)).find(e => !!e)) === null || _b === void 0 ? void 0 : _b[1].match(/(.*?\.js)/)) === null || _c === void 0 ? void 0 : _c[1];
if (!jsFile) {
throw new Error("Cannot find debugging file");
}
const source = path.basename(jsFile);
const args = arguments;
console.log(`Debugging ${source}`);
initNativeEnvironment(source).then(ret => {
contextId = ret;
console.log("debugging context id: " + contextId);
global.context = doric.jsObtainContext(contextId);
entryHooks.push((contextId) => {
Reflect.apply(doric.jsObtainEntry(contextId), doric, args);
});
return arguments[0];
if (entryHooks.length <= 1) {
const source = path.basename(jsFile);
console.log(`Debugging ${source}`);
initNativeEnvironment(source).then(ret => {
contextId = ret;
console.log("debugging context id: " + contextId);
global.context = doric.jsObtainContext(contextId);
entryHooks.forEach(e => e(contextId));
});
return arguments[0];
}
}
};
global.injectGlobal = (objName, obj) => {