mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
- `noEmitOnError: true` acts like `noEmit: true` when there is an error
- this is problematic because it will then cause _all_ files to have
`emitSkipped` set to `true`, which this plugin interprets as a fatal
error
- meaning it will treat the first file it finds as having a fatal
error and then abort, but possibly without outputting any
diagnostics what-so-ever as the file with the error in it may not
yet have run through the `transform` hook
- i.e. an initial file that imports an erroring file at some point
in its import chain will cause rpt2 to abort, even if that
initial file _itself_ has no type-check/diagnostic issues
- bc TS does whole-program analysis after all
- this has only been reported as an issue once so far, probably because
it defaults to `false` in TS and, as such, is rarely used:
https://www.typescriptlang.org/tsconfig#noEmitOnError
- we usually have the opposite issue, people trying to set it to
`false` (i.e. the default) because they don't realize the
`abortOnError` option exists
- add `noEmitOnError: false` to the forced options list and tests too
- add it to the docs on what tsconfig options are forced
- and add a reference to the issue like the existing options
- also reference `abortOnError` since they're commonly associated with
each other and that plugin option is often missed (per above)
- briefly explain that `noEmit` and `noEmitOnError` are `false` because
Rollup controls emit settings in the context of this plugin, instead
of `tsc` etc
- should probably watch out for when new emit settings are added to
TS, as we may want to force most with the same reasoning
75 lines
2.6 KiB
TypeScript
75 lines
2.6 KiB
TypeScript
import * as path from "path";
|
|
import * as tsTypes from "typescript";
|
|
import { createFilter as createRollupFilter, normalizePath as normalize } from "@rollup/pluginutils";
|
|
|
|
import { tsModule } from "./tsproxy";
|
|
import { IOptions } from "./ioptions";
|
|
import { IContext } from "./context";
|
|
|
|
export function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot }: IOptions, preParsedTsconfig?: tsTypes.ParsedCommandLine): tsTypes.CompilerOptions
|
|
{
|
|
const overrides: tsTypes.CompilerOptions = {
|
|
noEmitHelpers: false,
|
|
importHelpers: true,
|
|
noResolve: false,
|
|
noEmit: false,
|
|
noEmitOnError: false,
|
|
inlineSourceMap: false,
|
|
outDir: normalize(`${cacheRoot}/placeholder`), // need an outdir that is different from source or tsconfig parsing trips up. https://github.com/Microsoft/TypeScript/issues/24715
|
|
moduleResolution: tsModule.ModuleResolutionKind.NodeJs,
|
|
allowNonTsExtensions: true,
|
|
};
|
|
|
|
if (preParsedTsconfig)
|
|
{
|
|
if (preParsedTsconfig.options.module === undefined)
|
|
overrides.module = tsModule.ModuleKind.ES2015;
|
|
|
|
// only set declarationDir if useTsconfigDeclarationDir is enabled
|
|
if (!useTsconfigDeclarationDir)
|
|
overrides.declarationDir = undefined;
|
|
|
|
// unsetting sourceRoot if sourceMap is not enabled (in case original tsconfig had inlineSourceMap set that is being unset and would cause TS5051)
|
|
const sourceMap = preParsedTsconfig.options.sourceMap;
|
|
if (!sourceMap)
|
|
overrides.sourceRoot = undefined;
|
|
}
|
|
|
|
return overrides;
|
|
}
|
|
|
|
function expandIncludeWithDirs(include: string | string[], dirs: string[])
|
|
{
|
|
const newDirs: string[] = [];
|
|
|
|
dirs.forEach(root => {
|
|
if (include instanceof Array)
|
|
include.forEach(x => newDirs.push(normalize(path.join(root, x))));
|
|
else
|
|
newDirs.push(normalize(path.join(root, include)));
|
|
});
|
|
return newDirs;
|
|
}
|
|
|
|
export function createFilter(context: IContext, pluginOptions: IOptions, parsedConfig: tsTypes.ParsedCommandLine)
|
|
{
|
|
let included = pluginOptions.include;
|
|
let excluded = pluginOptions.exclude;
|
|
|
|
if (parsedConfig.options.rootDirs)
|
|
{
|
|
included = expandIncludeWithDirs(included, parsedConfig.options.rootDirs);
|
|
excluded = expandIncludeWithDirs(excluded, parsedConfig.options.rootDirs);
|
|
}
|
|
|
|
if (parsedConfig.projectReferences)
|
|
{
|
|
included = expandIncludeWithDirs(included, parsedConfig.projectReferences.map((x) => x.path)).concat(included);
|
|
excluded = expandIncludeWithDirs(excluded, parsedConfig.projectReferences.map((x) => x.path)).concat(excluded);
|
|
}
|
|
|
|
context.debug(() => `included:\n${JSON.stringify(included, undefined, 4)}`);
|
|
context.debug(() => `excluded:\n${JSON.stringify(excluded, undefined, 4)}`);
|
|
return createRollupFilter(included, excluded, { resolve: parsedConfig.options.rootDir });
|
|
}
|