Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: move fs/promises to fs.promises #20504

Merged
merged 1 commit into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/fs/bench-stat-promise.js
Original file line number Diff line number Diff line change
@@ -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],
Expand Down
4 changes: 2 additions & 2 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions lib/fs/promises.js → lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict';

process.emitWarning('The fs/promises API is experimental',
'ExperimentalWarning');

const {
F_OK,
O_SYMLINK,
Expand Down Expand Up @@ -34,7 +31,7 @@ const {
validateOffsetLengthRead,
validateOffsetLengthWrite,
validatePath
} = require('internal/fs');
} = require('internal/fs/utils');
const {
isUint32,
validateInt32,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/modules/esm/default_resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/process/stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-filehandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-open-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-promises-file-handle-append-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-promises-file-handle-chmod.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-promises-file-handle-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-promises-file-handle-readFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-promises-file-handle-stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-promises-file-handle-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-promises-file-handle-writeFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-promises-readfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-promises-writefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-fs-syncwritestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-internal-fs-syncwritestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-internal-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-async-wrap-getasyncid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down