UNPKG

2.03 kBJavaScriptView Raw
1import path from 'path';
2import { commonTokens, tokens } from '@stryker-mutator/api/plugin';
3import { optionsPath } from '../utils/index.js';
4import { coreTokens } from '../di/index.js';
5import { objectUtils } from '../utils/object-utils.js';
6import { FileMatcher } from '../config/index.js';
7/**
8 * Disabled type checking by inserting `@ts-nocheck` atop TS/JS files and removing other @ts-xxx directives from comments:
9 * @see https://github.com/stryker-mutator/stryker-js/issues/2438
10 */
11export class DisableTypeChecksPreprocessor {
12 constructor(log, options, impl) {
13 this.log = log;
14 this.options = options;
15 this.impl = impl;
16 }
17 async preprocess(project) {
18 const matcher = new FileMatcher(this.options.disableTypeChecks);
19 let warningLogged = false;
20 await Promise.all(objectUtils.map(project.files, async (file, name) => {
21 if (matcher.matches(path.resolve(name))) {
22 try {
23 const { content } = await this.impl(await file.toInstrumenterFile(), { plugins: this.options.mutator.plugins });
24 file.setContent(content);
25 }
26 catch (err) {
27 if (objectUtils.isWarningEnabled('preprocessorErrors', this.options.warnings)) {
28 warningLogged = true;
29 this.log.warn(`Unable to disable type checking for file "${name}". Shouldn't type checking be disabled for this file? Consider configuring a more restrictive "${optionsPath('disableTypeChecks')}" settings (or turn it completely off with \`false\`)`, err);
30 }
31 }
32 }
33 }));
34 if (warningLogged) {
35 this.log.warn(`(disable "${optionsPath('warnings', 'preprocessorErrors')}" to ignore this warning`);
36 }
37 }
38}
39DisableTypeChecksPreprocessor.inject = tokens(commonTokens.logger, commonTokens.options, coreTokens.disableTypeChecksHelper);
40//# sourceMappingURL=disable-type-checks-preprocessor.js.map
\No newline at end of file