Skip to content

Commit

Permalink
✨ add beforeExec hook (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuitos authored Aug 25, 2020
1 parent 76df4b3 commit 4fd57a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type ExecScriptsOpts = Pick<ImportEntryOpts, 'fetch'> & {
strictGlobal?: boolean;
success?: CallableFunction;
error?: CallableFunction;
beforeExec?: CallableFunction;
}

export type Entry = string | { styles?: string[], scripts?: string[], html?: string };
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,17 @@ const supportsUserTiming =
export function execScripts(entry, scripts, proxy = window, opts = {}) {
const {
fetch = defaultFetch, strictGlobal = false, success, error = () => {
}, beforeExec = () => {
},
} = opts;

return getExternalScripts(scripts, fetch, error)
.then(scriptsText => {

const geval = eval;
const geval = (code) => {
beforeExec();
(0, eval)(code);
};

function exec(scriptSrc, inlineScript, resolve) {

Expand Down

0 comments on commit 4fd57a3

Please sign in to comment.