mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
Remove `module.register()` (DEP0205), the `--experimental-loader` and `--loader` flags, and the machinery that supported them: the loader hooks worker thread, the hooks proxy, the async module customization hook chains for resolving and loading, the internal worker class used to run the loader thread, and the asynchronous module job linking. Module customization is now provided only by `module.registerHooks()`, which runs synchronously on the thread that loads the modules. As the loader thread no longer exists, the ES module loader always loads and links modules synchronously, so the code that handled promises and the re-invented `require()` for imported CommonJS customized by the async module customization hooks is removed too. `import()` still defers evaluation of the module to a later microtask, as before. `worker_threads.isInternalThread` is kept for compatibility and is now always `false`; removing it is left for a future semver-major change. The `ERR_ASYNC_LOADER_REQUEST_NEVER_SETTLED` and `ERR_LOADER_CHAIN_INCOMPLETE` error codes are no longer used and are documented as removed. Tests that exist only to exercise the async module customization hooks are removed. Assisted-by: Claude Signed-off-by: Geoffrey Booth <webadmin@geoffreybooth.com> PR-URL: https://github.com/nodejs/node/pull/67090 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ilyas Shabi <ilyasshabi94@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me>
163 lines
4.8 KiB
JavaScript
163 lines
4.8 KiB
JavaScript
import * as common from '../common/index.mjs';
|
|
|
|
import assert from 'node:assert';
|
|
import { existsSync } from 'node:fs';
|
|
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
|
|
// This tests that `make doc` generates the JSON documentation properly.
|
|
// Note that for this test to pass, `make doc` must be run first.
|
|
|
|
if (common.isWindows) {
|
|
common.skip('`make doc` does not run on Windows');
|
|
}
|
|
|
|
function validateModule(module) {
|
|
assert.strictEqual(typeof module, 'object');
|
|
assert.strictEqual(module.type, 'module');
|
|
assert.ok(module.name);
|
|
assert.ok(module.textRaw);
|
|
}
|
|
|
|
function validateMisc(misc) {
|
|
assert.strictEqual(typeof misc, 'object');
|
|
assert.strictEqual(misc.type, 'misc');
|
|
assert.ok(misc.name);
|
|
assert.strictEqual(typeof misc.name, 'string');
|
|
assert.ok(misc.textRaw);
|
|
assert.strictEqual(typeof misc.textRaw, 'string');
|
|
}
|
|
|
|
let numberOfDeprecatedSections = 0;
|
|
let numberOfRemovedAPIs = 0;
|
|
|
|
const metaExpectedKeys = new Set([
|
|
'added',
|
|
'changes',
|
|
'deprecated',
|
|
'napiVersion',
|
|
'removed',
|
|
]);
|
|
|
|
function validateMeta(meta) {
|
|
assert.partialDeepStrictEqual(metaExpectedKeys, new Set(Object.keys(meta)));
|
|
assert.ok(!Object.hasOwn(meta, 'added') || Array.isArray(meta.added) || typeof meta.added === 'string');
|
|
if (meta.deprecated) {
|
|
numberOfDeprecatedSections++;
|
|
assert.ok(Array.isArray(meta.deprecated) || typeof meta.deprecated === 'string');
|
|
}
|
|
if (meta.removed) {
|
|
numberOfRemovedAPIs++;
|
|
assert.ok(Array.isArray(meta.removed) || typeof meta.removed === 'string');
|
|
}
|
|
|
|
assert.ok(!Object.hasOwn(meta, 'napiVersion') || Number(meta.napiVersion));
|
|
assert.ok(Array.isArray(meta.changes));
|
|
}
|
|
|
|
function findAllKeys(obj, allKeys = new Set()) {
|
|
for (const [key, value] of Object.entries(obj)) {
|
|
if (Number.isNaN(Number(key))) allKeys.add(key);
|
|
if (typeof value === 'object') findAllKeys(value, allKeys);
|
|
|
|
if (key === 'miscs') {
|
|
assert.ok(Array.isArray(value));
|
|
assert.ok(value.length);
|
|
value.forEach(validateMisc);
|
|
} else if (key === 'modules') {
|
|
assert.ok(Array.isArray(value));
|
|
assert.ok(value.length);
|
|
value.forEach(validateModule);
|
|
} else if (key === 'meta') {
|
|
validateMeta(value);
|
|
}
|
|
}
|
|
return allKeys;
|
|
}
|
|
|
|
const allExpectedKeys = new Set([
|
|
'added',
|
|
'changes',
|
|
'classes',
|
|
'classMethods',
|
|
'commit',
|
|
'ctors',
|
|
'default',
|
|
'deprecated',
|
|
'desc',
|
|
'description',
|
|
'displayName',
|
|
'events',
|
|
'examples',
|
|
'globals',
|
|
'introduced_in',
|
|
'meta',
|
|
'methods',
|
|
'miscs',
|
|
'modules',
|
|
'name',
|
|
'napiVersion',
|
|
'optional',
|
|
'options',
|
|
'params',
|
|
'pr-url',
|
|
'properties',
|
|
'removed',
|
|
'return',
|
|
'shortDesc',
|
|
'signatures',
|
|
'source',
|
|
'stability',
|
|
'stabilityText',
|
|
'textRaw',
|
|
'type',
|
|
'version',
|
|
]);
|
|
|
|
for await (const dirent of await fs.opendir(new URL('../../out/doc/api/', import.meta.url))) {
|
|
if (!dirent.name.endsWith('.md')) continue;
|
|
|
|
const jsonPath = path.join(dirent.parentPath, dirent.name.slice(0, -2) + 'json');
|
|
const expectedSource = `doc/api/${dirent.name}`;
|
|
if (dirent.name === 'quic.md') {
|
|
assert.ok(!existsSync(jsonPath)); // QUIC documentation is not public yet
|
|
continue;
|
|
}
|
|
|
|
console.log('testing', jsonPath, 'based on', expectedSource);
|
|
|
|
const fileContent = await fs.readFile(jsonPath, 'utf8');
|
|
// A proxy to check if the file is human readable is to count if it contains
|
|
// at least 3 line return.
|
|
assert.strictEqual(fileContent.split('\n', 3).length, 3);
|
|
|
|
const json = JSON.parse(fileContent);
|
|
|
|
assert.strictEqual(json.type, 'module');
|
|
assert.strictEqual(json.source, expectedSource);
|
|
if (dirent.name !== 'index.md') {
|
|
assert.ok(json.introduced_in || Object.values(json).at(-1)?.[0].introduced_in);
|
|
}
|
|
assert.deepStrictEqual(Object.keys(json), ['type', 'source', ...({
|
|
'addons.md': ['introduced_in', 'miscs'],
|
|
'cli.md': ['introduced_in', 'miscs'],
|
|
'debugger.md': ['introduced_in', 'stability', 'stabilityText', 'miscs'],
|
|
'deprecations.md': ['introduced_in', 'miscs'],
|
|
'documentation.md': ['introduced_in', 'miscs'],
|
|
'errors.md': ['introduced_in', 'classes', 'miscs'],
|
|
'esm.md': ['introduced_in', 'meta', 'stability', 'stabilityText', 'properties', 'miscs'],
|
|
'globals.md': ['introduced_in', 'stability', 'stabilityText', 'classes', 'methods', 'miscs'],
|
|
'index.md': [],
|
|
'intl.md': ['introduced_in', 'miscs'],
|
|
'n-api.md': ['introduced_in', 'stability', 'stabilityText', 'miscs'],
|
|
'packages.md': ['introduced_in', 'meta', 'miscs'],
|
|
'process.md': ['globals'],
|
|
'report.md': ['introduced_in', 'meta', 'stability', 'stabilityText', 'miscs'],
|
|
}[dirent.name] ?? ['modules'])]);
|
|
|
|
assert.partialDeepStrictEqual(allExpectedKeys, findAllKeys(json));
|
|
}
|
|
|
|
assert.strictEqual(numberOfDeprecatedSections, 47); // Increase this number every time a new API is deprecated.
|
|
assert.strictEqual(numberOfRemovedAPIs, 49); // Increase this number every time a section is marked as removed.
|