-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
loader: return package format from defaultResolve if known
This is a proposed modification of defaultResolve to return the package format in case it has been found during package resolution. The format will be returned as described in the documentation: https://nodejs.org/api/esm.html#resolvespecifier-context-defaultresolve There is one new unit test as well: test/es-module/test-esm-resolve-type.js PR-URL: #40980 Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
- Loading branch information
1 parent
bbdcd05
commit f73728b
Showing
8 changed files
with
372 additions
and
50 deletions.
There are no files selected for viewing
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,41 @@ | ||
// Flags: --loader ./test/fixtures/es-module-loaders/hook-resolve-type.mjs | ||
import { allowGlobals } from '../common/index.mjs'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
import { strict as assert } from 'assert'; | ||
import * as fs from 'fs'; | ||
|
||
allowGlobals(global.getModuleTypeStats); | ||
|
||
const basePath = | ||
new URL('./node_modules/', import.meta.url); | ||
|
||
const rel = (file) => new URL(file, basePath); | ||
const createDir = (path) => { | ||
if (!fs.existsSync(path)) { | ||
fs.mkdirSync(path); | ||
} | ||
}; | ||
|
||
const moduleName = 'module-counter-by-type'; | ||
|
||
const moduleDir = rel(`${moduleName}`); | ||
createDir(basePath); | ||
createDir(moduleDir); | ||
fs.cpSync( | ||
fixtures.path('es-modules', moduleName), | ||
moduleDir, | ||
{ recursive: true } | ||
); | ||
|
||
const { importedESM: importedESMBefore, | ||
importedCJS: importedCJSBefore } = global.getModuleTypeStats(); | ||
|
||
import(`${moduleName}`).finally(() => { | ||
fs.rmSync(basePath, { recursive: true, force: true }); | ||
}); | ||
|
||
const { importedESM: importedESMAfter, | ||
importedCJS: importedCJSAfter } = global.getModuleTypeStats(); | ||
|
||
assert.strictEqual(importedESMBefore + 1, importedESMAfter); | ||
assert.strictEqual(importedCJSBefore, importedCJSAfter); |
Oops, something went wrong.