Skip to content

Commit b6adb0f

Browse files
author
Maël Nison
committed
Implements a "normalize-options" pseudo-hook
1 parent 0a8fc9f commit b6adb0f

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

lib/async.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var fs = require('fs');
33
var path = require('path');
44
var caller = require('./caller.js');
55
var nodeModulesPaths = require('./node-modules-paths.js');
6+
var normalizeOptions = require('./normalize-options.js');
67

78
var defaultIsFile = function isFile(file, cb) {
89
fs.stat(file, function (err, stat) {
@@ -38,6 +39,8 @@ module.exports = function resolve(x, options, callback) {
3839
});
3940
}
4041

42+
opts = normalizeOptions(x, opts);
43+
4144
var isFile = opts.isFile || defaultIsFile;
4245
var isDirectory = opts.isDirectory || defaultIsDir;
4346
var readFile = opts.readFile || fs.readFile;

lib/normalize-options.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = function (x, opts) {
2+
/**
3+
* This file is purposefully a passthrough. It's expected that third-party
4+
* environments will override it at runtime in order to inject special logic
5+
* into `resolve` (by manipulating the options). One such example is the PnP
6+
* code path in Yarn.
7+
*/
8+
9+
return opts;
10+
};

lib/sync.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var fs = require('fs');
33
var path = require('path');
44
var caller = require('./caller.js');
55
var nodeModulesPaths = require('./node-modules-paths.js');
6+
var normalizeOptions = require('./normalize-options.js');
67

78
var defaultIsFile = function isFile(file) {
89
try {
@@ -28,7 +29,8 @@ module.exports = function (x, options) {
2829
if (typeof x !== 'string') {
2930
throw new TypeError('Path must be a string.');
3031
}
31-
var opts = options || {};
32+
var opts = normalizeOptions(x, options || {});
33+
3234
var isFile = opts.isFile || defaultIsFile;
3335
var isDirectory = opts.isDirectory || defaultIsDir;
3436
var readFileSync = opts.readFileSync || fs.readFileSync;

0 commit comments

Comments
 (0)