mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
Added options to respect declarationDir from tsconfig
This commit is contained in:
parent
1c1e7a7c81
commit
a6f75b4f11
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -1,5 +0,0 @@
|
||||
{
|
||||
"editor.tabSize": 4,
|
||||
"editor.useTabStops": true,
|
||||
"editor.dragAndDrop": true
|
||||
}
|
||||
@ -45,7 +45,8 @@ The following compiler options are forced though:
|
||||
* `noEmitHelpers`: true
|
||||
* `importHelpers`: true
|
||||
* `noResolve`: false
|
||||
* `outDir`: `process.cwd()`
|
||||
* `outDir`: `process.cwd()`,
|
||||
* (`declarationDir`: `process.cwd()`) (*only if `useTsconfigDeclarationDir is false in the plugin options*)
|
||||
|
||||
You will need to set `"moduleResolution": "node"` in `tsconfig.json` if typescript complains about missing `tslib`. See [#12](https://github.com/ezolenko/rollup-plugin-typescript2/issues/12) and [#14](https://github.com/ezolenko/rollup-plugin-typescript2/issues/14).
|
||||
|
||||
@ -89,10 +90,15 @@ Plugin takes following options:
|
||||
* `rollupCommonJSResolveHack`: false
|
||||
|
||||
On windows typescript resolver favors POSIX path, while commonjs plugin (and maybe others?) uses native path as module id. This can result in `namedExports` being ignored if rollup happened to use typescript's resolution. Set to true to pass resolved module path through `resolve()` to match up with `rollup-plugin-commonjs`.
|
||||
|
||||
* `useTsconfigDeclarationDir`: false
|
||||
|
||||
If true, declaration files will be emitted in the directory given in the tsconfig. If false, the declaration files will be placed inside the destination directory given in the Rollup configuration.
|
||||
|
||||
### Declarations
|
||||
|
||||
This plugin respects `declaration: true` in your `tsconfig.json` file. When set, it will emit `*.d.ts` files for your bundle. The resulting file(s) can then be used with the `types` property in your `package.json` file as described [here](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html).
|
||||
By default, the declaration files will be located in the same directory as the generated Rollup bundle. If you want to override this behavior and instead use the declarationDir
|
||||
|
||||
### Watch mode
|
||||
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
import {CompilerOptions, ModuleKind} from "typescript";
|
||||
import {IOptions} from "./ioptions";
|
||||
|
||||
export function getOptionsOverrides(): CompilerOptions {
|
||||
export function getOptionsOverrides({useTsconfigDeclarationDir}: IOptions): CompilerOptions {
|
||||
return {
|
||||
module: ModuleKind.ES2015,
|
||||
noEmitHelpers: true,
|
||||
importHelpers: true,
|
||||
noResolve: false,
|
||||
outDir: process.cwd(),
|
||||
...(useTsconfigDeclarationDir ? {} : {declarationDir: process.cwd()}),
|
||||
};
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@ import {join, relative, dirname} from "path";
|
||||
|
||||
// tslint:disable-next-line:no-var-requires
|
||||
const createFilter = require("rollup-pluginutils").createFilter;
|
||||
// tslint:enable-next-line:no-var-requires
|
||||
let watchMode = false;
|
||||
let round = 0;
|
||||
let targetCount = 0;
|
||||
@ -66,7 +67,7 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
|
||||
filter = createFilter(pluginOptions.include, pluginOptions.exclude);
|
||||
|
||||
parsedConfig = parseTsConfig(pluginOptions.tsconfig, context);
|
||||
parsedConfig = parseTsConfig(pluginOptions.tsconfig, context, pluginOptions);
|
||||
|
||||
servicesHost = new LanguageServiceHost(parsedConfig);
|
||||
|
||||
@ -240,8 +241,7 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
const baseDeclarationDir = parsedConfig.options.outDir as string;
|
||||
each(declarations, ({ name, text, writeByteOrderMark }) =>
|
||||
{
|
||||
const relativeFromBaseDeclarationDir = relative(baseDeclarationDir, name);
|
||||
const writeToPath = join(destDirectory, relativeFromBaseDeclarationDir);
|
||||
const writeToPath = pluginOptions.useTsconfigDeclarationDir ? name : join(destDirectory, relative(baseDeclarationDir, name));
|
||||
sys.writeFile(writeToPath, text, writeByteOrderMark);
|
||||
});
|
||||
},
|
||||
|
||||
@ -9,4 +9,5 @@ export interface IOptions
|
||||
abortOnError: boolean;
|
||||
rollupCommonJSResolveHack: boolean;
|
||||
tsconfig: string;
|
||||
useTsconfigDeclarationDir: boolean;
|
||||
}
|
||||
|
||||
@ -4,8 +4,9 @@ import {dirname} from "path";
|
||||
import {printDiagnostics} from "./print-diagnostics";
|
||||
import {convertDiagnostic} from "./tscache";
|
||||
import {getOptionsOverrides} from "./get-options-overrides";
|
||||
import {IOptions} from "./ioptions";
|
||||
|
||||
export function parseTsConfig(tsconfig: string, context: IContext): ParsedCommandLine {
|
||||
export function parseTsConfig(tsconfig: string, context: IContext, pluginOptions: IOptions): ParsedCommandLine {
|
||||
const fileName = findConfigFile(process.cwd(), sys.fileExists, tsconfig);
|
||||
|
||||
if (!fileName)
|
||||
@ -19,5 +20,5 @@ export function parseTsConfig(tsconfig: string, context: IContext): ParsedComman
|
||||
throw new Error(`failed to parse ${fileName}`);
|
||||
}
|
||||
|
||||
return parseJsonConfigFileContent(result.config, sys, dirname(fileName), getOptionsOverrides(), fileName);
|
||||
return parseJsonConfigFileContent(result.config, sys, dirname(fileName), getOptionsOverrides(pluginOptions), fileName);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user