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: export realpathCacheKey from internal/fs #8862

Closed
Closed
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
6 changes: 1 addition & 5 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1455,10 +1455,6 @@ function encodeRealpathResult(result, options, err) {
}
}

// This is removed from the fs exports in lib/module.js in order to make
// sure that this stays internal.
const realpathCacheKey = fs.realpathCacheKey = Symbol('realpathCacheKey');

fs.realpathSync = function realpathSync(p, options) {
options = getOptions(options, {});
nullCheck(p);
Expand All @@ -1468,7 +1464,7 @@ fs.realpathSync = function realpathSync(p, options) {

const seenLinks = {};
const knownHard = {};
const cache = options[realpathCacheKey];
const cache = options[internalFS.realpathCacheKey];
const original = p;

const maybeCachedResult = cache && cache.get(p);
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,5 @@ SyncWriteStream.prototype.destroy = function() {
};

exports.SyncWriteStream = SyncWriteStream;

exports.realpathCacheKey = Symbol('realpathCacheKey');
6 changes: 2 additions & 4 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const internalModule = require('internal/module');
const vm = require('vm');
const assert = require('assert').ok;
const fs = require('fs');
const internalFS = require('internal/fs');
const path = require('path');
const internalModuleReadFile = process.binding('fs').internalModuleReadFile;
const internalModuleStat = process.binding('fs').internalModuleStat;
Expand Down Expand Up @@ -113,9 +114,6 @@ function tryPackage(requestPath, exts, isMain) {
// Set to an empty Map to reset.
const realpathCache = new Map();

const realpathCacheKey = fs.realpathCacheKey;
delete fs.realpathCacheKey;

// check if the file exists and is not a directory
// if using --preserve-symlinks and isMain is false,
// keep symlinks intact, otherwise resolve to the
Expand All @@ -130,7 +128,7 @@ function tryFile(requestPath, isMain) {

function toRealPath(requestPath) {
return fs.realpathSync(requestPath, {
[realpathCacheKey]: realpathCache
[internalFS.realpathCacheKey]: realpathCache
});
}

Expand Down