Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

fix: fix "ERROR in Must have a source file to refactor." error from ngCompilerPlugin on test command #859

Merged
merged 1 commit into from
Apr 12, 2019

Conversation

Fatme
Copy link
Contributor

@Fatme Fatme commented Apr 11, 2019

The "ERROR in Must have a source file to refactor." error is thrown when tns test android --path <projectPath> --bundle command is executed.
This error is thrown from AngularCompilerPlugin when the path to main.ts file is not correct. We provided the path to main.ts file here. As this path is built using path.resolve and appPath is relative path, the resulting path is still not an absolute path. In this case NodeJS uses current working directory as described here. In other words, in this case resolve(appPath, entryModule) is equal to join(process.cwd(), appPath, entryModule).

NativeScript CLI starts 2 webpack processes on test command - one from nativescript-dev-webpack plugin and another one from karma-webpack plugin.
When the webpack process is started from nativescript-dev-webpack plugin, cwd is explicitly set here. So, the result from resolve(appPath, entryModule) is correct and AngularCompilerPlugin is happy.
When the webpack process is started from karma-webpack plugin, cwd is not set anywhere, so the default value is used. It is fine and works as expected when test command is executed from project directory regardless if --path option is provided. It is not fine and the error is thrown in following cases:

  • When test command is executed with --path option from folder different from project directory
  • When test command is executed from CI where cwd is explicitly provided

PR Checklist

What is the current behavior?

What is the new behavior?

Fixes/Implements/Closes #[Issue Number].

@ghost ghost assigned Fatme Apr 11, 2019
@cla-bot cla-bot bot added the cla: yes label Apr 11, 2019
@ghost ghost added new PR review labels Apr 11, 2019
@dtopuzov
Copy link
Contributor

test package_version#latest branch#release

@Fatme Fatme merged commit 196d977 into release Apr 12, 2019
@ghost ghost removed new PR review labels Apr 12, 2019
@Fatme Fatme deleted the fatme/fix-ng-compiler-error branch April 12, 2019 01:12
Fatme pushed a commit that referenced this pull request Apr 12, 2019
* release: cut the 0.21.0 release

* fix: add support for ts files on test command when `--bundle` is provided (#848)

Rel to:
NativeScript/nativescript-cli#4477
NativeScript/nativescript-cli#1798

* fix: use correct slashes on windows (#851)

* fix: fix "ERROR in Must have a source file to refactor." error from ngCompilerPlugin on `test` command (#859)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants