-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: update ESM hook examples esm: fix unsafe primordial doc: fix ESM example linting esm: allow source of type ArrayBuffer doc: update ESM hook changelog to include resolve format esm: allow all ArrayBuffers and TypedArrays for load hook source doc: tidy code & API docs doc: convert ESM source table header from Title Case to Sentence case doc: add detailed explanation for getPackageType esm: add caveat that ESMLoader::import() must NOT be renamed esm: tidy code declaration of getFormat protocolHandlers doc: correct ESM doc link (bad conflict resolution) doc: update ESM hook limitation for CJS esm: tweak preload description doc: update ESM getPackageType() example explanation PR-URL: #37468 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
- Loading branch information
1 parent
1ef2cf8
commit 3743406
Showing
46 changed files
with
971 additions
and
545 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
const { defaultGetFormat } = require('internal/modules/esm/get_format'); | ||
const { defaultGetSource } = require('internal/modules/esm/get_source'); | ||
const { translators } = require('internal/modules/esm/translators'); | ||
|
||
async function defaultLoad(url, context) { | ||
let { | ||
format, | ||
source, | ||
} = context; | ||
|
||
if (!translators.has(format)) format = defaultGetFormat(url); | ||
|
||
if ( | ||
format === 'builtin' || | ||
format === 'commonjs' | ||
) { | ||
source = null; | ||
} else if (source == null) { | ||
source = await defaultGetSource(url, { format }); | ||
} | ||
|
||
return { | ||
format, | ||
source, | ||
}; | ||
} | ||
|
||
module.exports = { | ||
defaultLoad, | ||
}; |
Oops, something went wrong.