Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension esm support #57

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/core/scriptLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ namespace AMDLoader {
interface INodeVMScriptOptions {
filename: string;
cachedData?: Buffer;
importModuleDynamically?: (specifier: string) => Promise<any>;
}

interface INodeVMScript {
Expand Down Expand Up @@ -452,7 +453,10 @@ namespace AMDLoader {
}

scriptSource = nodeInstrumenter(scriptSource, normalizedScriptSrc);
const scriptOpts: INodeVMScriptOptions = { filename: vmScriptPathOrUri, cachedData };
const scriptOpts: INodeVMScriptOptions = { filename: vmScriptPathOrUri, cachedData, importModuleDynamically: (specifier) => {
// @ts-ignore since dynamic imports require a module type to be set. Setting the AMD module type, however, is incompatible with the test suite
return import(specifier);
} };
const script = this._createAndEvalScript(moduleManager, scriptSource, scriptOpts, callback, errorback);

this._handleCachedData(script, scriptSource, cachedDataPath!, wantsCachedData && !cachedData, moduleManager);
Expand Down