mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
Create `lib/internal/modules` and restructure the module loaders to make the purpose of those files clearer. Also make it clear in the code that the object exported by `lib/internal/modules/cjs/loader.js` is `CJSModule` instead of the ambiguous `Module`. Before: ``` lib ├── ... ├── internal │ ├── loaders │ │ ├── CreateDynamicModule.js │ │ ├── DefaultResolve.js │ │ ├── Loader.js │ │ ├── ModuleJob.js │ │ ├── ModuleMap.js │ │ ├── ModuleWrap.js │ │ └── Translators.js │ └── module.js └── module.js ``` After: ``` lib ├── ... ├── internal │ ├── ... │ └── modules │ ├── cjs │ │ ├── helpers.js │ │ └── loader.js │ └── esm │ ├── CreateDynamicModule.js │ ├── DefaultResolve.js │ ├── Loader.js │ ├── ModuleJob.js │ ├── ModuleMap.js │ └── Translators.js └── module.js # deleted in this commit to work with git file mode ``` Backport-PR-URL: https://github.com/nodejs/node/pull/19374 PR-URL: https://github.com/nodejs/node/pull/19177 Refs: https://github.com/nodejs/node/pull/19112 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
'use strict';
|
|
// Flags: --expose-internals
|
|
|
|
// This test ensures that the type checking of ModuleMap throws
|
|
// errors appropriately
|
|
|
|
const common = require('../common');
|
|
|
|
const { URL } = require('url');
|
|
const Loader = require('internal/modules/esm/Loader');
|
|
const ModuleMap = require('internal/modules/esm/ModuleMap');
|
|
const ModuleJob = require('internal/modules/esm/ModuleJob');
|
|
const createDynamicModule = require('internal/modules/esm/CreateDynamicModule');
|
|
|
|
const stubModuleUrl = new URL('file://tmp/test');
|
|
const stubModule = createDynamicModule(['default'], stubModuleUrl);
|
|
const loader = new Loader();
|
|
const moduleMap = new ModuleMap();
|
|
const moduleJob = new ModuleJob(loader, stubModule.module,
|
|
() => new Promise(() => {}));
|
|
|
|
common.expectsError(
|
|
() => moduleMap.get(1),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
message: 'The "url" argument must be of type string'
|
|
}
|
|
);
|
|
|
|
common.expectsError(
|
|
() => moduleMap.set(1, moduleJob),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
message: 'The "url" argument must be of type string'
|
|
}
|
|
);
|
|
|
|
common.expectsError(
|
|
() => moduleMap.set('somestring', 'notamodulejob'),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
message: 'The "job" argument must be of type ModuleJob'
|
|
}
|
|
);
|
|
|
|
common.expectsError(
|
|
() => moduleMap.has(1),
|
|
{
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError,
|
|
message: 'The "url" argument must be of type string'
|
|
}
|
|
);
|