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

Make --require relative to where the command is run. #346

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var figures = require('figures');
var globby = require('globby');
var chalk = require('chalk');
var fork = require('./lib/fork');
var resolveCwd = require('resolve-cwd');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this above fork.

var formatter = require('./lib/enhance-assert').formatter();

function Api(files, options) {
Expand All @@ -20,6 +21,8 @@ function Api(files, options) {

this.options = options || {};

this.options.require = (this.options.require || []).map(resolveCwd);

this.rejectionCount = 0;
this.exceptionCount = 0;
this.passCount = 0;
Expand Down
5 changes: 1 addition & 4 deletions lib/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ if (debug.enabled) {
// Bind globals first, before anything has a chance to interfere.
var globals = require('./globals');

var resolveCwd = require('resolve-cwd');
(opts.require || []).forEach(function (moduleId) {
require(resolveCwd(moduleId));
});
(opts.require || []).forEach(require);

var sourceMapCache = Object.create(null);

Expand Down
7 changes: 6 additions & 1 deletion test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,14 @@ test('test file in node_modules is ignored', function (t) {
test('Node.js-style --require CLI argument', function (t) {
t.plan(1);

var requirePath = path.relative(process.cwd(), path.join(__dirname, 'fixture', 'install-global.js'));
// `path` will use \\ to seperate paths on windows, but require doesn't.
requirePath = requirePath.split(path.sep).join('/');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't windows users be allowed to use \ as a path separator, since that is what they are used to?

Seems to me that

ava --require .\fixtures\install-global.js .\fixture\validate-installed-global.js

is the valid windows style alternative to

ava --require ./fixtures/install-global.js ./fixture/validate-installed-global.js

I would prefer it if AVA accepted either path separator and just normalized it internally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamestalmage: it's iffy, because node doesn't allow that (AFAIK), and 'require' doesn't allow that, so it would be a strange thing to do, but I'll add it if you really want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use \\ in require and --require, but it only works on Windows. So it won't be cross-platform. We could normalize internally, but do we really want to implement it differently than $ node --require?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sindresorhus: I'd say no, no you don't.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not suggesting we change the implementation. Just the line here in the test that normalizes the path to posix. We don't need to do that. And we want the test to fail if it doesn't allow windows users to use it. resolveCwd is going to end up normalizing it for the given operating system anyways.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamestalmage Oh, ok. I misunderstood. Agree with that.

@ariporad Can you update?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamestalmage, @sindresorhus: Ok, I removed that line.

requirePath = './' + requirePath;

var api = new Api(
[path.join(__dirname, 'fixture/validate-installed-global.js')],
{require: [path.join(__dirname, 'fixture', 'install-global.js')]}
{require: [requirePath]}
);

api.run()
Expand Down