fs: move fs/promises to fs.promises

PR-URL: https://github.com/nodejs/node/pull/20504
Refs: https://github.com/nodejs/TSC/issues/389
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
This commit is contained in:
cjihrig 2018-05-03 14:40:48 -04:00
parent 0452f1152c
commit 975f6c1f70
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
25 changed files with 50 additions and 37 deletions

View File

@ -1,7 +1,7 @@
'use strict';
const common = require('../common');
const fsPromises = require('fs/promises');
const fsPromises = require('fs').promises;
const bench = common.createBenchmark(main, {
n: [20e4],

View File

@ -3382,9 +3382,9 @@ Synchronous versions of [`fs.write()`][]. Returns the number of bytes written.
> Stability: 1 - Experimental
The `fs/promises` API provides an alternative set of asynchronous file system
The `fs.promises` API provides an alternative set of asynchronous file system
methods that return `Promise` objects rather than using callbacks. The
API is accessible via `require('fs/promises')`.
API is accessible via `require('fs').promises`.
### class: FileHandle
<!-- YAML

View File

@ -45,7 +45,8 @@ const { Readable, Writable } = require('stream');
const EventEmitter = require('events');
const { FSReqWrap, statValues, kFsStatsFieldsLength } = binding;
const { FSEvent } = process.binding('fs_event_wrap');
const internalFS = require('internal/fs');
const promises = require('internal/fs/promises');
const internalFS = require('internal/fs/utils');
const { getPathFromURL } = require('internal/url');
const internalUtil = require('internal/util');
const {
@ -74,6 +75,21 @@ const {
validateUint32
} = require('internal/validators');
let warn = true;
Object.defineProperty(fs, 'promises', {
configurable: true,
enumerable: true,
get() {
if (warn) {
warn = false;
process.emitWarning('The fs.promises API is experimental',
'ExperimentalWarning');
}
return promises;
}
});
Object.defineProperty(exports, 'constants', {
configurable: false,
enumerable: true,

View File

@ -1,8 +1,5 @@
'use strict';
process.emitWarning('The fs/promises API is experimental',
'ExperimentalWarning');
const {
F_OK,
O_SYMLINK,
@ -34,7 +31,7 @@ const {
validateOffsetLengthRead,
validateOffsetLengthWrite,
validatePath
} = require('internal/fs');
} = require('internal/fs/utils');
const {
isUint32,
validateInt32,

View File

@ -28,7 +28,7 @@ const { getURLFromFilePath } = require('internal/url');
const vm = require('vm');
const assert = require('assert').ok;
const fs = require('fs');
const internalFS = require('internal/fs');
const internalFS = require('internal/fs/utils');
const path = require('path');
const {
internalModuleReadJSON,

View File

@ -2,7 +2,7 @@
const { URL } = require('url');
const CJSmodule = require('internal/modules/cjs/loader');
const internalFS = require('internal/fs');
const internalFS = require('internal/fs/utils');
const { NativeModule, internalBinding } = require('internal/bootstrap/loaders');
const { extname } = require('path');
const { realpathSync } = require('fs');

View File

@ -158,7 +158,7 @@ function createWritableStdioStream(fd) {
break;
case 'FILE':
var fs = require('internal/fs');
var fs = require('internal/fs/utils');
stream = new fs.SyncWriteStream(fd, { autoClose: false });
stream._type = 'fs';
break;

View File

@ -39,7 +39,6 @@
'lib/domain.js',
'lib/events.js',
'lib/fs.js',
'lib/fs/promises.js',
'lib/http.js',
'lib/http2.js',
'lib/_http_agent.js',
@ -103,7 +102,8 @@
'lib/internal/errors.js',
'lib/internal/fixed_queue.js',
'lib/internal/freelist.js',
'lib/internal/fs.js',
'lib/internal/fs/promises.js',
'lib/internal/fs/utils.js',
'lib/internal/http.js',
'lib/internal/inspector_async_hook.js',
'lib/internal/linkedlist.js',

View File

@ -5,7 +5,7 @@ const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = process.binding('fs');
const { stringToFlags } = require('internal/fs');
const { stringToFlags } = require('internal/fs/utils');
// Verifies that the FileHandle object is garbage collected and that a
// warning is emitted if it is not closed.

View File

@ -39,7 +39,7 @@ const O_DSYNC = fs.constants.O_DSYNC || 0;
const O_TRUNC = fs.constants.O_TRUNC || 0;
const O_WRONLY = fs.constants.O_WRONLY || 0;
const { stringToFlags } = require('internal/fs');
const { stringToFlags } = require('internal/fs/utils');
assert.strictEqual(stringToFlags('r'), O_RDONLY);
assert.strictEqual(stringToFlags('r+'), O_RDWR);

View File

@ -2,11 +2,11 @@
const common = require('../common');
// The following tests validate base functionality for the fs/promises
// The following tests validate base functionality for the fs.promises
// FileHandle.appendFile method.
const fs = require('fs');
const { open } = require('fs/promises');
const { open } = fs.promises;
const path = require('path');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');

View File

@ -2,11 +2,11 @@
const common = require('../common');
// The following tests validate base functionality for the fs/promises
// The following tests validate base functionality for the fs.promises
// FileHandle.chmod method.
const fs = require('fs');
const { open } = require('fs/promises');
const { open } = fs.promises;
const path = require('path');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');

View File

@ -2,11 +2,11 @@
const common = require('../common');
// The following tests validate base functionality for the fs/promises
// The following tests validate base functionality for the fs.promises
// FileHandle.read method.
const fs = require('fs');
const { open } = require('fs/promises');
const { open } = fs.promises;
const path = require('path');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');

View File

@ -2,11 +2,11 @@
const common = require('../common');
// The following tests validate base functionality for the fs/promises
// The following tests validate base functionality for the fs.promises
// FileHandle.readFile method.
const fs = require('fs');
const { open } = require('fs/promises');
const { open } = fs.promises;
const path = require('path');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');

View File

@ -2,10 +2,10 @@
const common = require('../common');
// The following tests validate base functionality for the fs/promises
// The following tests validate base functionality for the fs.promises
// FileHandle.stat method.
const { open } = require('fs/promises');
const { open } = require('fs').promises;
const path = require('path');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');

View File

@ -2,11 +2,11 @@
const common = require('../common');
// The following tests validate base functionality for the fs/promises
// The following tests validate base functionality for the fs.promises
// FileHandle.read method.
const fs = require('fs');
const { open } = require('fs/promises');
const { open } = fs.promises;
const path = require('path');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');

View File

@ -2,11 +2,11 @@
const common = require('../common');
// The following tests validate base functionality for the fs/promises
// The following tests validate base functionality for the fs.promises
// FileHandle.readFile method.
const fs = require('fs');
const { open } = require('fs/promises');
const { open } = fs.promises;
const path = require('path');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');

View File

@ -4,7 +4,7 @@ const common = require('../common');
const assert = require('assert');
const path = require('path');
const { writeFile, readFile } = require('fs/promises');
const { writeFile, readFile } = require('fs').promises;
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

View File

@ -2,7 +2,7 @@
const common = require('../common');
const fs = require('fs');
const fsPromises = require('fs/promises');
const fsPromises = fs.promises;
const path = require('path');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');

View File

@ -5,7 +5,7 @@ const assert = require('assert');
const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const path = require('path');
const fsPromises = require('fs/promises');
const fsPromises = require('fs').promises;
const {
access,
chmod,

View File

@ -6,8 +6,8 @@ const stream = require('stream');
const fs = require('fs');
const path = require('path');
// require('internal/fs').SyncWriteStream is used as a stdio implementation
// when stdout/stderr point to files.
// require('internal/fs/utils').SyncWriteStream is used as a stdio
// implementation when stdout/stderr point to files.
if (process.argv[2] === 'child') {
// Note: Calling console.log() is part of this test as it exercises the

View File

@ -5,7 +5,7 @@ const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const SyncWriteStream = require('internal/fs').SyncWriteStream;
const SyncWriteStream = require('internal/fs/utils').SyncWriteStream;
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

View File

@ -2,7 +2,7 @@
'use strict';
const common = require('../common');
const fs = require('internal/fs');
const fs = require('internal/fs/utils');
// Valid encodings and no args should not throw.
fs.assertEncoding();

View File

@ -3,7 +3,7 @@
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const fsPromises = require('fs/promises');
const fsPromises = fs.promises;
const net = require('net');
const providers = Object.assign({}, process.binding('async_wrap').Providers);
const fixtures = require('../common/fixtures');