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 module-alias work in cli mode #76

Merged
merged 2 commits into from
Oct 1, 2019
Merged

Conversation

Kehrlann
Copy link
Collaborator

@Kehrlann Kehrlann commented Sep 30, 2019

Fixes #65

It builds on top of @dgobaud's PR, and adds tests.

There might be some rare cases when you want to use module-alias while running in a REPL (e.g. $ node -i). In that case, require.main is undefined.

This means introducing a way of having "require.main" undefined in our module. The require function is different between the test module and the module under test, so we can't just do require.main = null in the test function, as it won't affect the "require" function of the prod code. So we need to introduce a helper function for evaluating require.main, and inject a flag in the test module when running the tests.

dgobaud and others added 2 commits September 30, 2019 21:10
require.main is undefined when running from cli - don't use unless it exists
- This require introducing a way of having "require.main" undefined
  in our module. The require function is different between the test
  module and the module under test, so we can't just do
  `require.main = null`
  in the test function, as it won't affect the "require" function
  of the prod code. So we need to introduce a helper function for
  evaluating require.main, and injact a flag in the test module
  when running the tests.
@ilearnio
Copy link
Owner

ilearnio commented Oct 1, 2019

Awesome stuff! Thanks @Kehrlann!

@ilearnio ilearnio merged commit 652604b into dev Oct 1, 2019
@ilearnio ilearnio deleted the feature/work-in-cli-mode branch October 1, 2019 11:22
@ilearnio
Copy link
Owner

ilearnio commented Oct 1, 2019

Published as v2.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants