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>
30 lines
852 B
JavaScript
30 lines
852 B
JavaScript
'use strict';
|
|
|
|
// Flags: --expose-internals
|
|
|
|
const common = require('../common');
|
|
common.crashOnUnhandledRejection();
|
|
const assert = require('assert');
|
|
|
|
const ModuleWrap = require('internal/modules/esm/ModuleWrap');
|
|
const { getPromiseDetails, isPromise } = process.binding('util');
|
|
const setTimeoutAsync = require('util').promisify(setTimeout);
|
|
|
|
const foo = new ModuleWrap('export * from "bar"; 6;', 'foo');
|
|
const bar = new ModuleWrap('export const five = 5', 'bar');
|
|
|
|
(async () => {
|
|
const promises = foo.link(() => setTimeoutAsync(1000).then(() => bar));
|
|
assert.strictEqual(promises.length, 1);
|
|
assert(isPromise(promises[0]));
|
|
|
|
await Promise.all(promises);
|
|
|
|
assert.strictEqual(getPromiseDetails(promises[0])[1], bar);
|
|
|
|
foo.instantiate();
|
|
|
|
assert.strictEqual(await foo.evaluate(), 6);
|
|
assert.strictEqual(foo.namespace().five, 5);
|
|
})();
|