Make module-alias work in cli mode by Kehrlann · Pull Request #76 · ilearnio/module-alias · GitHub
Skip to content

Make module-alias work in cli mode - #76

Merged
ilearnio merged 2 commits into
devfrom
feature/work-in-cli-mode
Oct 1, 2019
Merged

ilearnio merged 2 commits into
devfrom
feature/work-in-cli-mode

Conversation

@Kehrlann

@Kehrlann Kehrlann commented Sep 30, 2019 •

Copy link
Copy Markdown
Collaborator

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.
@Kehrlann
Kehrlann requested a review from ilearnio September 30, 2019 20:18
@ilearnio

ilearnio commented Oct 1, 2019

Copy link
Copy Markdown
Owner

@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

ilearnio commented Oct 1, 2019

Copy link
Copy Markdown
Owner

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