Comparing version 1.6.7 to 1.6.8
@@ -919,23 +919,49 @@ 'use strict'; | ||
}; | ||
const esmEnvCode = (env, bridge) => { | ||
if (env) { | ||
let str = 'var '; | ||
for (const key in env) { | ||
str += `${key}=globalThis.${bridge}.${key},`; | ||
} | ||
return str.slice(0, -1) + ';'; | ||
} | ||
return ''; | ||
}; | ||
function exec(code, type, options) { | ||
if (type === 'esm:data') { | ||
const id = `data:text/javascript;charset=utf-8,${encodeURIComponent(code)}`; | ||
return (0, eval)(inlineString(`import("${id}")`)); | ||
} else if (type === 'esm:blob') { | ||
const id = URL.createObjectURL( | ||
new Blob([code], { type: 'text/javascript' }), | ||
const { env, sourceUrl, useStrict } = options || {}; | ||
const sourceCode = sourceUrl ? `\n//# sourceURL=${sourceUrl}\n` : '\n'; | ||
if (type && type.startsWith('esm')) { | ||
const bridge = `__aidlyExec${random(10000)}__`; | ||
const esmCode = `${esmEnvCode(env, bridge)}${code}${sourceCode}`; | ||
const id = | ||
type === 'esm:data' | ||
? `data:text/javascript;charset=utf-8,${encodeURIComponent(esmCode)}` | ||
: URL.createObjectURL(new Blob([esmCode], { type: 'text/javascript' })); | ||
try { | ||
if (env) globalThis[bridge] = env; | ||
return (0, eval)(inlineString(`import("${id}")`)).finally(() => { | ||
delete globalThis[bridge]; | ||
}); | ||
} catch (e) { | ||
delete globalThis[bridge]; | ||
throw e; | ||
} | ||
} else { | ||
const keys = Object.keys(env || {}); | ||
const values = keys.map((key) => env[key]); | ||
const paramsCode = keys.join(','); | ||
const strictCode = useStrict ? '"use strict";' : ''; | ||
const cjsCode = type === 'cjs' ? 'module,exports,' : ''; | ||
const fn = (0, eval)( | ||
inlineString( | ||
`(()=>function _$c_(${cjsCode}${paramsCode}){${strictCode}${code}${sourceCode}})();`, | ||
), | ||
); | ||
return (0, eval)(inlineString(`import("${id}")`)); | ||
if (type === 'cjs') { | ||
const ms = { exports: Object.create(null) }; | ||
fn(ms, ms.exports, ...values); | ||
return ms.exports; | ||
} | ||
return fn(...values); | ||
} | ||
const { require, useStrict } = options || {}; | ||
const strictCode = useStrict ? '"use strict";' : ''; | ||
code = `function _$c_(module,exports,require){${strictCode}${code}\n}`; | ||
const fn = (0, eval)(inlineString(`(()=>${code})()`)); | ||
if (type === 'cjs') { | ||
const ms = { exports: Object.create(null) }; | ||
fn(ms, ms.exports, require); | ||
return ms.exports; | ||
} else { | ||
fn(); | ||
} | ||
} | ||
@@ -942,0 +968,0 @@ const isLegalExpressions = (input) => { |
@@ -917,23 +917,49 @@ export { Queue } from 'small-queue'; | ||
}; | ||
const esmEnvCode = (env, bridge) => { | ||
if (env) { | ||
let str = 'var '; | ||
for (const key in env) { | ||
str += `${key}=globalThis.${bridge}.${key},`; | ||
} | ||
return str.slice(0, -1) + ';'; | ||
} | ||
return ''; | ||
}; | ||
function exec(code, type, options) { | ||
if (type === 'esm:data') { | ||
const id = `data:text/javascript;charset=utf-8,${encodeURIComponent(code)}`; | ||
return (0, eval)(inlineString(`import("${id}")`)); | ||
} else if (type === 'esm:blob') { | ||
const id = URL.createObjectURL( | ||
new Blob([code], { type: 'text/javascript' }), | ||
const { env, sourceUrl, useStrict } = options || {}; | ||
const sourceCode = sourceUrl ? `\n//# sourceURL=${sourceUrl}\n` : '\n'; | ||
if (type && type.startsWith('esm')) { | ||
const bridge = `__aidlyExec${random(10000)}__`; | ||
const esmCode = `${esmEnvCode(env, bridge)}${code}${sourceCode}`; | ||
const id = | ||
type === 'esm:data' | ||
? `data:text/javascript;charset=utf-8,${encodeURIComponent(esmCode)}` | ||
: URL.createObjectURL(new Blob([esmCode], { type: 'text/javascript' })); | ||
try { | ||
if (env) globalThis[bridge] = env; | ||
return (0, eval)(inlineString(`import("${id}")`)).finally(() => { | ||
delete globalThis[bridge]; | ||
}); | ||
} catch (e) { | ||
delete globalThis[bridge]; | ||
throw e; | ||
} | ||
} else { | ||
const keys = Object.keys(env || {}); | ||
const values = keys.map((key) => env[key]); | ||
const paramsCode = keys.join(','); | ||
const strictCode = useStrict ? '"use strict";' : ''; | ||
const cjsCode = type === 'cjs' ? 'module,exports,' : ''; | ||
const fn = (0, eval)( | ||
inlineString( | ||
`(()=>function _$c_(${cjsCode}${paramsCode}){${strictCode}${code}${sourceCode}})();`, | ||
), | ||
); | ||
return (0, eval)(inlineString(`import("${id}")`)); | ||
if (type === 'cjs') { | ||
const ms = { exports: Object.create(null) }; | ||
fn(ms, ms.exports, ...values); | ||
return ms.exports; | ||
} | ||
return fn(...values); | ||
} | ||
const { require, useStrict } = options || {}; | ||
const strictCode = useStrict ? '"use strict";' : ''; | ||
code = `function _$c_(module,exports,require){${strictCode}${code}\n}`; | ||
const fn = (0, eval)(inlineString(`(()=>${code})()`)); | ||
if (type === 'cjs') { | ||
const ms = { exports: Object.create(null) }; | ||
fn(ms, ms.exports, require); | ||
return ms.exports; | ||
} else { | ||
fn(); | ||
} | ||
} | ||
@@ -940,0 +966,0 @@ const isLegalExpressions = (input) => { |
@@ -976,25 +976,51 @@ (function (global, factory) { | ||
}; | ||
const esmEnvCode = (env, bridge) => { | ||
if (env) { | ||
let str = 'var '; | ||
for (const key in env) { | ||
str += `${key}=globalThis.${bridge}.${key},`; | ||
} | ||
return str.slice(0, -1) + ';'; | ||
} | ||
return ''; | ||
}; | ||
function exec(code, type, options) { | ||
if (type === 'esm:data') { | ||
const id = `data:text/javascript;charset=utf-8,${encodeURIComponent( | ||
code, | ||
)}`; | ||
return (0, eval)(inlineString(`import("${id}")`)); | ||
} else if (type === 'esm:blob') { | ||
const id = URL.createObjectURL( | ||
new Blob([code], { type: 'text/javascript' }), | ||
const { env, sourceUrl, useStrict } = options || {}; | ||
const sourceCode = sourceUrl ? `\n//# sourceURL=${sourceUrl}\n` : '\n'; | ||
if (type && type.startsWith('esm')) { | ||
const bridge = `__aidlyExec${random(10000)}__`; | ||
const esmCode = `${esmEnvCode(env, bridge)}${code}${sourceCode}`; | ||
const id = | ||
type === 'esm:data' | ||
? `data:text/javascript;charset=utf-8,${encodeURIComponent(esmCode)}` | ||
: URL.createObjectURL( | ||
new Blob([esmCode], { type: 'text/javascript' }), | ||
); | ||
try { | ||
if (env) globalThis[bridge] = env; | ||
return (0, eval)(inlineString(`import("${id}")`)).finally(() => { | ||
delete globalThis[bridge]; | ||
}); | ||
} catch (e) { | ||
delete globalThis[bridge]; | ||
throw e; | ||
} | ||
} else { | ||
const keys = Object.keys(env || {}); | ||
const values = keys.map((key) => env[key]); | ||
const paramsCode = keys.join(','); | ||
const strictCode = useStrict ? '"use strict";' : ''; | ||
const cjsCode = type === 'cjs' ? 'module,exports,' : ''; | ||
const fn = (0, eval)( | ||
inlineString( | ||
`(()=>function _$c_(${cjsCode}${paramsCode}){${strictCode}${code}${sourceCode}})();`, | ||
), | ||
); | ||
return (0, eval)(inlineString(`import("${id}")`)); | ||
if (type === 'cjs') { | ||
const ms = { exports: Object.create(null) }; | ||
fn(ms, ms.exports, ...values); | ||
return ms.exports; | ||
} | ||
return fn(...values); | ||
} | ||
const { require, useStrict } = options || {}; | ||
const strictCode = useStrict ? '"use strict";' : ''; | ||
code = `function _$c_(module,exports,require){${strictCode}${code}\n}`; | ||
const fn = (0, eval)(inlineString(`(()=>${code})()`)); | ||
if (type === 'cjs') { | ||
const ms = { exports: Object.create(null) }; | ||
fn(ms, ms.exports, require); | ||
return ms.exports; | ||
} else { | ||
fn(); | ||
} | ||
} | ||
@@ -1001,0 +1027,0 @@ const isLegalExpressions = (input) => { |
@@ -1,6 +0,7 @@ | ||
export declare const inlineString: (code: string) => string; | ||
export interface ExecOptions { | ||
useStrict?: boolean; | ||
require?: (id: string, ...args: Array<unknown>) => unknown; | ||
sourceUrl?: string; | ||
env?: Record<string, unknown>; | ||
} | ||
export declare const inlineString: (code: string) => string; | ||
export declare function exec<T = unknown, U extends never = never>( | ||
@@ -10,3 +11,3 @@ code: string, | ||
options?: ExecOptions, | ||
): void; | ||
): unknown; | ||
export declare function exec<T = unknown, U extends null = null>( | ||
@@ -16,3 +17,3 @@ code: string, | ||
options?: ExecOptions, | ||
): void; | ||
): unknown; | ||
export declare function exec<T = unknown, U extends 'cjs' = 'cjs'>( | ||
@@ -19,0 +20,0 @@ code: string, |
{ | ||
"name": "aidly", | ||
"version": "1.6.7", | ||
"version": "1.6.8", | ||
"description": "Tool library.", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
263565
8437
9