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

Crash when using custom extensions outside of Babel pipeline with enhancement compilation disabled #1836

Closed
novemberborn opened this issue Jun 11, 2018 · 0 comments · Fixed by #1840
Assignees
Labels
bug current functionality does not work as desired help wanted scope:internals
Milestone

Comments

@novemberborn
Copy link
Member

From #1822 (comment):

  "ava": {
    "compileEnhancements": false,
    "extensions": [
      "ts"
    ],
    "require": [
      "ts-node/register",
      "tsconfig-paths/register"
    ]
  },

Because of how ts is specified, AVA won't apply its Babel pipeline to it. However, note that the babel option is not disabled.

The logic in these lines is broken:

const {projectDir, babelConfig} = this.options;
const compileEnhancements = this.options.compileEnhancements !== false;
const precompileFull = babelConfig ?
  babelPipeline.build(projectDir, cacheDir, babelConfig, compileEnhancements) :
  filename => {
    throw new Error(`Cannot apply full precompilation, possible bad usage: ${filename}`);
  };
const precompileEnhancementsOnly = compileEnhancements && this.options.extensions.enhancementsOnly.length > 0 ?
  babelPipeline.build(projectDir, cacheDir, null, compileEnhancements) :
  filename => {
    throw new Error(`Cannot apply enhancement-only precompilation, possible bad usage: ${filename}`);
  };


this._precompiler = {
  cacheDir,
  enabled: babelConfig || compileEnhancements,
  precompileEnhancementsOnly,
  precompileFull
};

Note how this._precompiler.enabled ends up being true. However precompileEnhancementsOnly is set to a function that always throws. Consequently, when compiling TypeScript files, precompileEnhancementsOnly is called and AVA crashes.

I think the logic should be such that a () => null function is when compileEnhancements is false, and the error-throwing function is used when it's not and this.options.extensions.enhancementsOnly.length is 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug current functionality does not work as desired help wanted scope:internals
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant