-
-
Notifications
You must be signed in to change notification settings - Fork 187
Implements useProcessResolution
#170
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
Changes from all commits
e011edc
5f11711
109f275
5797755
5655d0a
c9faab9
9daf6b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var path = require('path'); | ||
|
||
module.exports = function processResolution(opts) { | ||
if (process.versions.pnp) { | ||
var pnp = require('pnpapi'); | ||
|
||
opts.preserveSymlinks = true; | ||
opts.skipNodeModules = true; | ||
opts.paths = function (basedir, opts) { | ||
if (!opts || !opts.request) { | ||
throw new Error('Missing request option'); | ||
} | ||
|
||
// Extract the name of the package being requested (1=full name, 2=scope name, 3=local name) | ||
var parts = opts.request.match(/^((?:(@[^/]+)\/)?([^/]+))/); | ||
|
||
// This is guaranteed to return the path to the "package.json" file from the given package | ||
var manifestPath = pnp.resolveToUnqualified(parts[1] + '/package.json', basedir); | ||
|
||
// The first dirname strips the package.json, the second strips the local named folder | ||
var nodeModules = path.dirname(path.dirname(manifestPath)); | ||
|
||
// Strips the scope named folder if needed | ||
if (parts[2]) { | ||
nodeModules = path.dirname(nodeModules); | ||
} | ||
|
||
return [nodeModules]; | ||
}; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,11 @@ var nodeModulesPaths = require('../lib/node-modules-paths'); | |
|
||
var verifyDirs = function verifyDirs(t, start, dirs, moduleDirectories, paths) { | ||
var moduleDirs = [].concat(moduleDirectories || 'node_modules'); | ||
if (paths) { | ||
for (var k = 0; k < paths.length; ++k) { | ||
moduleDirs.push(path.basename(paths[k])); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems like a behavior change - the test is now using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only one test was using the path parameter previously and it was providing straight folder names ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair, but why is the basename change needed? Was it incorrect for the test to omit it previously (and there weren't enough test cases to demonstrate that)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, missed the comment, my bad! The basename change was needed because the previous testcases were only using |
||
} | ||
} | ||
|
||
var foundModuleDirs = {}; | ||
var uniqueDirs = {}; | ||
|
@@ -20,7 +25,7 @@ var verifyDirs = function verifyDirs(t, start, dirs, moduleDirectories, paths) { | |
} | ||
t.equal(keys(parsedDirs).length >= start.split(path.sep).length, true, 'there are >= dirs than "start" has'); | ||
var foundModuleDirNames = keys(foundModuleDirs); | ||
t.deepEqual(foundModuleDirNames, moduleDirs.concat(paths || []), 'all desired module dirs were found'); | ||
t.deepEqual(foundModuleDirNames, moduleDirs, 'all desired module dirs were found'); | ||
t.equal(keys(uniqueDirs).length, dirs.length, 'all dirs provided were unique'); | ||
|
||
var counts = {}; | ||
|
@@ -49,7 +54,16 @@ test('node-modules-paths', function (t) { | |
t.end(); | ||
}); | ||
|
||
t.test('with paths option', function (t) { | ||
t.test('with skipNodeModules=true option', function (t) { | ||
var start = path.join(__dirname, 'resolver'); | ||
var dirs = nodeModulesPaths(start, { skipNodeModules: true }); | ||
|
||
t.deepEqual(dirs, [], 'no node_modules was computed'); | ||
|
||
t.end(); | ||
}); | ||
|
||
t.test('with paths=array option', function (t) { | ||
var start = path.join(__dirname, 'resolver'); | ||
var paths = ['a', 'b']; | ||
var dirs = nodeModulesPaths(start, { paths: paths }); | ||
|
@@ -59,6 +73,19 @@ test('node-modules-paths', function (t) { | |
t.end(); | ||
}); | ||
|
||
t.test('with paths=function option', function (t) { | ||
var paths = function paths(absoluteStart, opts) { | ||
return [path.join(absoluteStart, 'not node modules', opts.request)]; | ||
}; | ||
|
||
var start = path.join(__dirname, 'resolver'); | ||
var dirs = nodeModulesPaths(start, { paths: paths, request: 'pkg' }); | ||
|
||
verifyDirs(t, start, dirs, null, [path.join(start, 'not node modules', 'pkg')]); | ||
|
||
t.end(); | ||
}); | ||
|
||
t.test('with moduleDirectory option', function (t) { | ||
var start = path.join(__dirname, 'resolver'); | ||
var moduleDirectory = 'not node modules'; | ||
|
Uh oh!
There was an error while loading. Please reload this page.