Skip to content

Commit

Permalink
[fixes #24] support PNP and basedir slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Jun 3, 2021
1 parent 11c238b commit 1fe089b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ function resolvePackagePath(
cache = _cache;
}

if (baseDir.charAt(baseDir.length - 1) !== path.sep) {
baseDir = `${baseDir}${path.sep}`;
}

const key = target + '\x00' + baseDir;

let pkgPath;
Expand Down
23 changes: 23 additions & 0 deletions tests/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ describe('resolve-package-path', function () {
app.pkg.name;
app.pkg.scripts = {
test: 'node ./test.js',
'test:trailing-slash': 'node ./test-trailing-slash.js',
};
app.pkg.installConfig = {
pnp: true,
Expand All @@ -112,6 +113,16 @@ if (require('resolve-package-path')(process.argv[2], __dirname)) {
console.log('not-found');
process.exitCode = 1;
}`,
'test-trailing-slash.js': `
const assert = require('assert');
const rpp = require('resolve-package-path');
const path = require('path');
const emberSourceChannelUrlPath = path.dirname(rpp('ember-source-channel-url', '.'))
assert.equal(rpp('got', emberSourceChannelUrlPath),rpp('got', emberSourceChannelUrlPath + '/'));
assert.equal(typeof rpp('got', emberSourceChannelUrlPath), 'string');
`,
};
});

Expand All @@ -128,6 +139,7 @@ if (require('resolve-package-path')(process.argv[2], __dirname)) {
it('handles yarn pnp usage - package exists', function () {
let result = execa.sync('yarn', ['test', 'ember-source-channel-url'], {
cwd: app.baseDir,
reject: false,
});

expect(result.stdout.toString()).includes('found');
Expand All @@ -143,6 +155,17 @@ if (require('resolve-package-path')(process.argv[2], __dirname)) {
expect(result.stdout.toString()).includes('not-found');
expect(result.exitCode).to.eql(1);
});

describe('trailing-slash', function () {
it('handles missing trailing slash automagically', function () {
let result = execa.sync('yarn', ['test:trailing-slash'], {
cwd: app.baseDir,
reject: false,
});
expect(result.stderr).to.eql('');
expect(result.exitCode).to.eql(0, 'expected process to exit cleanly');
});
});
});
}

Expand Down

0 comments on commit 1fe089b

Please sign in to comment.