Skip to content

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

@novemberborn

Description

@novemberborn

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions