module.syncBuiltinESMExports()
添加于:v12.12.0
module.syncBuiltinESMExports()
方法更新内置 ES Modules 的所有实时绑定以匹配 CommonJS 导出的属性。它不会在 ES Modules 中添加或删除导出的名称。
const fs = require('node:fs');
const assert = require('node:assert');
const { syncBuiltinESMExports } = require('node:module');
fs.readFile = newAPI;
delete fs.readFileSync;
function newAPI() {
// ...
}
fs.newAPI = newAPI;
syncBuiltinESMExports();
import('node:fs').then((esmFS) => {
// It syncs the existing readFile property with the new value
assert.strictEqual(esmFS.readFile, newAPI);
// readFileSync has been deleted from the required fs
assert.strictEqual('readFileSync' in fs, false);
// syncBuiltinESMExports() does not remove readFileSync from esmFS
assert.strictEqual('readFileSync' in esmFS, true);
// syncBuiltinESMExports() does not add names
assert.strictEqual(esmFS.newAPI, undefined);
});
相关用法
- Node.js module.builtinModules用法及代码示例
- Node.js module.exports用法及代码示例
- Node.js module.createRequire(filename)用法及代码示例
- Node.js http.IncomingMessage message.rawHeaders用法及代码示例
- Node.js http.IncomingMessage message.url用法及代码示例
- Node.js http.IncomingMessage message.complete用法及代码示例
- Node.js http.IncomingMessage message.headers用法及代码示例
- Node.js ServerHttp2Stream http2stream.pushStream(headers[, options], callback)用法及代码示例
- Node.js http2.Http2ServerRequest request.url用法及代码示例
- Node.js request.socket用法及代码示例
- Node.js assert.notEqual(actual, expected[, message])用法及代码示例
- Node.js tlsSocket.authorized用法及代码示例
- Node.js zlib.deflateRaw()用法及代码示例
- Node.js Console用法及代码示例
- Node.js GM transparent()用法及代码示例
- Node.js URL.protocol用法及代码示例
- Node.js http.Agent.reuseSocket(socket, request)用法及代码示例
- Node.js fs.filehandle.datasync()用法及代码示例
- Node.js socket.bind()用法及代码示例
- Node.js v8.getHeapSpaceStatistics()用法及代码示例
- Node.js http2session.destroyed用法及代码示例
- Node.js http.ServerResponse response.statusCode用法及代码示例
- Node.js Buffer buf.writeBigUInt64BE(value[, offset])用法及代码示例
- Node.js Http2ServerResponse.finished用法及代码示例
- Node.js Http2Stream close用法及代码示例
注:本文由纯净天空筛选整理自nodejs.org大神的英文原创作品 module.syncBuiltinESMExports()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。