Skip to content

Commit

Permalink
fix: Set configBase to the directory of the symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Kellen authored and phated committed Nov 22, 2021
1 parent f53b06a commit 1c76c99
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs');
const util = require('util');
const path = require('path');
const EE = require('events').EventEmitter;
Expand Down Expand Up @@ -124,7 +125,7 @@ Liftoff.prototype.buildEnvironment = function (opts) {
cwd: cwd,
require: preload,
configNameSearch: configNameSearch,
configPath: configPath,
configPath: configPath && fs.realpathSync(configPath), // resolve symlink
configBase: configBase,
modulePath: modulePath,
modulePackage: modulePackage||{}
Expand Down
3 changes: 1 addition & 2 deletions lib/find_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ module.exports = function (opts) {
}
// confirm the configPath exists and return an absolute path to it
if (fs.existsSync(configPath)) {
// traverse symlinks if needed
return fs.realpathSync(path.resolve(configPath));
return path.resolve(configPath);
}
return null;
};
15 changes: 15 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ describe('Liftoff', function () {
expect(app.buildEnvironment().cwd).to.equal(path.resolve('test/fixtures/search_path'));
});


it('should resolve symlinks if config is one', function () {
var env = app.buildEnvironment({
cwd: 'test/fixtures/symlink'
});
expect(env.configPath).to.equal(path.resolve('test/fixtures/mochafile.js'));
});

it('should set configBase to the folder of the symlink if configPath is a symlink', function () {
var env = app.buildEnvironment({
configPath: 'test/fixtures/symlink/mochafile.js'
});
expect(env.cwd).to.equal(path.resolve('test/fixtures/symlink'));
})

});

describe('launch', function () {
Expand Down
7 changes: 0 additions & 7 deletions test/lib/find_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,4 @@ describe('findConfig', function () {
})).to.equal(path.resolve('test/fixtures/search_path/mochafile.js'));
});

it('should traverse symlinks', function () {
expect(findConfig({
configNameSearch: ['mochafile.js'],
searchPaths: ['test/fixtures/symlink']
})).to.equal(path.resolve('test/fixtures/mochafile.js'));
});

});

0 comments on commit 1c76c99

Please sign in to comment.