diff options
author | cjihrig <cjihrig@gmail.com> | 2018-05-03 14:40:48 -0400 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2018-05-07 19:47:42 -0400 |
commit | 975f6c1f7077fd33db95eaeee6ccfa49e4a29348 (patch) | |
tree | edbc5ece189e5b3747d5bb659203b55c8dafa580 | |
parent | 0452f1152cb15db01631196e893b875332946b76 (diff) | |
download | node-new-975f6c1f7077fd33db95eaeee6ccfa49e4a29348.tar.gz |
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>
25 files changed, 50 insertions, 37 deletions
diff --git a/benchmark/fs/bench-stat-promise.js b/benchmark/fs/bench-stat-promise.js index b031745572..96c7058fa6 100644 --- a/benchmark/fs/bench-stat-promise.js +++ b/benchmark/fs/bench-stat-promise.js @@ -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], diff --git a/doc/api/fs.md b/doc/api/fs.md index bace6d9483..30d6729d48 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -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 @@ -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, diff --git a/lib/fs/promises.js b/lib/internal/fs/promises.js index 6ccff6933b..6b523473e4 100644 --- a/lib/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -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, diff --git a/lib/internal/fs.js b/lib/internal/fs/utils.js index 2f7a8d8ced..2f7a8d8ced 100644 --- a/lib/internal/fs.js +++ b/lib/internal/fs/utils.js diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 652378ad57..85ab3ab144 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -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, diff --git a/lib/internal/modules/esm/default_resolve.js b/lib/internal/modules/esm/default_resolve.js index 60516535e9..48d3ef73fd 100644 --- a/lib/internal/modules/esm/default_resolve.js +++ b/lib/internal/modules/esm/default_resolve.js @@ -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'); diff --git a/lib/internal/process/stdio.js b/lib/internal/process/stdio.js index 29aee7d09b..75ede6a8e7 100644 --- a/lib/internal/process/stdio.js +++ b/lib/internal/process/stdio.js @@ -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; @@ -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', diff --git a/test/parallel/test-fs-filehandle.js b/test/parallel/test-fs-filehandle.js index 8ddc11ec3e..84b462aa90 100644 --- a/test/parallel/test-fs-filehandle.js +++ b/test/parallel/test-fs-filehandle.js @@ -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. diff --git a/test/parallel/test-fs-open-flags.js b/test/parallel/test-fs-open-flags.js index 7f70885861..546d68e312 100644 --- a/test/parallel/test-fs-open-flags.js +++ b/test/parallel/test-fs-open-flags.js @@ -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); diff --git a/test/parallel/test-fs-promises-file-handle-append-file.js b/test/parallel/test-fs-promises-file-handle-append-file.js index 38336a2b43..7766ac4c90 100644 --- a/test/parallel/test-fs-promises-file-handle-append-file.js +++ b/test/parallel/test-fs-promises-file-handle-append-file.js @@ -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'); diff --git a/test/parallel/test-fs-promises-file-handle-chmod.js b/test/parallel/test-fs-promises-file-handle-chmod.js index c2a44fba7b..8b9d8b1c0d 100644 --- a/test/parallel/test-fs-promises-file-handle-chmod.js +++ b/test/parallel/test-fs-promises-file-handle-chmod.js @@ -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'); diff --git a/test/parallel/test-fs-promises-file-handle-read.js b/test/parallel/test-fs-promises-file-handle-read.js index 5a9bc4558c..a397b0e260 100644 --- a/test/parallel/test-fs-promises-file-handle-read.js +++ b/test/parallel/test-fs-promises-file-handle-read.js @@ -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'); diff --git a/test/parallel/test-fs-promises-file-handle-readFile.js b/test/parallel/test-fs-promises-file-handle-readFile.js index 9308c29909..316fd6581f 100644 --- a/test/parallel/test-fs-promises-file-handle-readFile.js +++ b/test/parallel/test-fs-promises-file-handle-readFile.js @@ -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'); diff --git a/test/parallel/test-fs-promises-file-handle-stat.js b/test/parallel/test-fs-promises-file-handle-stat.js index 22b9c6476a..7d44b8e3da 100644 --- a/test/parallel/test-fs-promises-file-handle-stat.js +++ b/test/parallel/test-fs-promises-file-handle-stat.js @@ -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'); diff --git a/test/parallel/test-fs-promises-file-handle-write.js b/test/parallel/test-fs-promises-file-handle-write.js index b5c83a1690..d7812745c5 100644 --- a/test/parallel/test-fs-promises-file-handle-write.js +++ b/test/parallel/test-fs-promises-file-handle-write.js @@ -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'); diff --git a/test/parallel/test-fs-promises-file-handle-writeFile.js b/test/parallel/test-fs-promises-file-handle-writeFile.js index 196b6f8db8..a53384cc22 100644 --- a/test/parallel/test-fs-promises-file-handle-writeFile.js +++ b/test/parallel/test-fs-promises-file-handle-writeFile.js @@ -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'); diff --git a/test/parallel/test-fs-promises-readfile.js b/test/parallel/test-fs-promises-readfile.js index 1bf49503c3..4334673c30 100644 --- a/test/parallel/test-fs-promises-readfile.js +++ b/test/parallel/test-fs-promises-readfile.js @@ -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(); diff --git a/test/parallel/test-fs-promises-writefile.js b/test/parallel/test-fs-promises-writefile.js index 280bce8642..1bb6945c67 100644 --- a/test/parallel/test-fs-promises-writefile.js +++ b/test/parallel/test-fs-promises-writefile.js @@ -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'); diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index ba3a91d5b3..43b5da7004 100644 --- a/test/parallel/test-fs-promises.js +++ b/test/parallel/test-fs-promises.js @@ -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, diff --git a/test/parallel/test-fs-syncwritestream.js b/test/parallel/test-fs-syncwritestream.js index a014277a6b..8fbe665a40 100644 --- a/test/parallel/test-fs-syncwritestream.js +++ b/test/parallel/test-fs-syncwritestream.js @@ -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 diff --git a/test/parallel/test-internal-fs-syncwritestream.js b/test/parallel/test-internal-fs-syncwritestream.js index c474d21cb4..c751baf555 100644 --- a/test/parallel/test-internal-fs-syncwritestream.js +++ b/test/parallel/test-internal-fs-syncwritestream.js @@ -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(); diff --git a/test/parallel/test-internal-fs.js b/test/parallel/test-internal-fs.js index 9bc0a98b09..2e47e2a382 100644 --- a/test/parallel/test-internal-fs.js +++ b/test/parallel/test-internal-fs.js @@ -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(); diff --git a/test/sequential/test-async-wrap-getasyncid.js b/test/sequential/test-async-wrap-getasyncid.js index 64c4fd5cd8..971296915c 100644 --- a/test/sequential/test-async-wrap-getasyncid.js +++ b/test/sequential/test-async-wrap-getasyncid.js @@ -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'); |