mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
- fix for TS5052
- cleanup
This commit is contained in:
parent
c72a610400
commit
c501e1a34f
2
dist/get-options-overrides.d.ts
vendored
2
dist/get-options-overrides.d.ts
vendored
@ -1,3 +1,3 @@
|
||||
import { CompilerOptions } from "typescript";
|
||||
import { IOptions } from "./ioptions";
|
||||
export declare function getOptionsOverrides({useTsconfigDeclarationDir}: IOptions): CompilerOptions;
|
||||
export declare function getOptionsOverrides({useTsconfigDeclarationDir}: IOptions, tsConfigJson?: any): CompilerOptions;
|
||||
|
||||
23
dist/rollup-plugin-typescript2.cjs.js
vendored
23
dist/rollup-plugin-typescript2.cjs.js
vendored
@ -449,9 +449,10 @@ function printDiagnostics(context, diagnostics) {
|
||||
});
|
||||
}
|
||||
|
||||
function getOptionsOverrides(_a) {
|
||||
function getOptionsOverrides(_a, tsConfigJson) {
|
||||
var useTsconfigDeclarationDir = _a.useTsconfigDeclarationDir;
|
||||
return __assign({ module: typescript.ModuleKind.ES2015, noEmitHelpers: true, importHelpers: true, noResolve: false, outDir: process.cwd() }, (useTsconfigDeclarationDir ? {} : { declarationDir: process.cwd() }));
|
||||
var declaration = lodash.get(tsConfigJson, "compilerOptions.declaration", false);
|
||||
return __assign({ module: typescript.ModuleKind.ES2015, noEmitHelpers: true, importHelpers: true, noResolve: false, outDir: process.cwd() }, (!declaration || useTsconfigDeclarationDir ? {} : { declarationDir: process.cwd() }));
|
||||
}
|
||||
|
||||
function parseTsConfig(tsconfig, context, pluginOptions) {
|
||||
@ -464,7 +465,7 @@ function parseTsConfig(tsconfig, context, pluginOptions) {
|
||||
printDiagnostics(context, convertDiagnostic("config", [result.error]));
|
||||
throw new Error("failed to parse " + fileName);
|
||||
}
|
||||
return typescript.parseJsonConfigFileContent(result.config, typescript.sys, path.dirname(fileName), getOptionsOverrides(pluginOptions), fileName);
|
||||
return typescript.parseJsonConfigFileContent(result.config, typescript.sys, path.dirname(fileName), getOptionsOverrides(pluginOptions, result.config), fileName);
|
||||
}
|
||||
|
||||
// The injected id for helpers.
|
||||
@ -512,6 +513,7 @@ function typescript$1(options) {
|
||||
abortOnError: true,
|
||||
rollupCommonJSResolveHack: false,
|
||||
tsconfig: "tsconfig.json",
|
||||
useTsconfigDeclarationDir: false,
|
||||
});
|
||||
return {
|
||||
options: function (config) {
|
||||
@ -629,14 +631,17 @@ function typescript$1(options) {
|
||||
var baseDeclarationDir = parsedConfig.options.outDir;
|
||||
lodash.each(declarations, function (_a) {
|
||||
var name = _a.name, text = _a.text, writeByteOrderMark = _a.writeByteOrderMark;
|
||||
var writeToPath;
|
||||
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
|
||||
// use the path provided by Typescript's LanguageService.
|
||||
if (dest == null || pluginOptions.useTsconfigDeclarationDir)
|
||||
return typescript.sys.writeFile(name, text, writeByteOrderMark);
|
||||
// Otherwise, take the directory name from the path and make sure it is absolute.
|
||||
var destDirname = path.dirname(dest);
|
||||
var destDirectory = path.isAbsolute(dest) ? destDirname : path.join(process.cwd(), destDirname);
|
||||
var writeToPath = path.join(destDirectory, path.relative(baseDeclarationDir, name));
|
||||
if (!dest || pluginOptions.useTsconfigDeclarationDir)
|
||||
writeToPath = name;
|
||||
else {
|
||||
// Otherwise, take the directory name from the path and make sure it is absolute.
|
||||
var destDirname = path.dirname(dest);
|
||||
var destDirectory = path.isAbsolute(dest) ? destDirname : path.join(process.cwd(), destDirname);
|
||||
writeToPath = path.join(destDirectory, path.relative(baseDeclarationDir, name));
|
||||
}
|
||||
// Write the declaration file to disk.
|
||||
typescript.sys.writeFile(writeToPath, text, writeByteOrderMark);
|
||||
});
|
||||
|
||||
23
dist/rollup-plugin-typescript2.es.js
vendored
23
dist/rollup-plugin-typescript2.es.js
vendored
@ -448,9 +448,10 @@ function printDiagnostics(context, diagnostics) {
|
||||
});
|
||||
}
|
||||
|
||||
function getOptionsOverrides(_a) {
|
||||
function getOptionsOverrides(_a, tsConfigJson) {
|
||||
var useTsconfigDeclarationDir = _a.useTsconfigDeclarationDir;
|
||||
return __assign({ module: ModuleKind.ES2015, noEmitHelpers: true, importHelpers: true, noResolve: false, outDir: process.cwd() }, (useTsconfigDeclarationDir ? {} : { declarationDir: process.cwd() }));
|
||||
var declaration = get(tsConfigJson, "compilerOptions.declaration", false);
|
||||
return __assign({ module: ModuleKind.ES2015, noEmitHelpers: true, importHelpers: true, noResolve: false, outDir: process.cwd() }, (!declaration || useTsconfigDeclarationDir ? {} : { declarationDir: process.cwd() }));
|
||||
}
|
||||
|
||||
function parseTsConfig(tsconfig, context, pluginOptions) {
|
||||
@ -463,7 +464,7 @@ function parseTsConfig(tsconfig, context, pluginOptions) {
|
||||
printDiagnostics(context, convertDiagnostic("config", [result.error]));
|
||||
throw new Error("failed to parse " + fileName);
|
||||
}
|
||||
return parseJsonConfigFileContent(result.config, sys, dirname(fileName), getOptionsOverrides(pluginOptions), fileName);
|
||||
return parseJsonConfigFileContent(result.config, sys, dirname(fileName), getOptionsOverrides(pluginOptions, result.config), fileName);
|
||||
}
|
||||
|
||||
// The injected id for helpers.
|
||||
@ -511,6 +512,7 @@ function typescript$1(options) {
|
||||
abortOnError: true,
|
||||
rollupCommonJSResolveHack: false,
|
||||
tsconfig: "tsconfig.json",
|
||||
useTsconfigDeclarationDir: false,
|
||||
});
|
||||
return {
|
||||
options: function (config) {
|
||||
@ -628,14 +630,17 @@ function typescript$1(options) {
|
||||
var baseDeclarationDir = parsedConfig.options.outDir;
|
||||
each(declarations, function (_a) {
|
||||
var name = _a.name, text = _a.text, writeByteOrderMark = _a.writeByteOrderMark;
|
||||
var writeToPath;
|
||||
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
|
||||
// use the path provided by Typescript's LanguageService.
|
||||
if (dest == null || pluginOptions.useTsconfigDeclarationDir)
|
||||
return sys.writeFile(name, text, writeByteOrderMark);
|
||||
// Otherwise, take the directory name from the path and make sure it is absolute.
|
||||
var destDirname = dirname(dest);
|
||||
var destDirectory = isAbsolute(dest) ? destDirname : join(process.cwd(), destDirname);
|
||||
var writeToPath = join(destDirectory, relative(baseDeclarationDir, name));
|
||||
if (!dest || pluginOptions.useTsconfigDeclarationDir)
|
||||
writeToPath = name;
|
||||
else {
|
||||
// Otherwise, take the directory name from the path and make sure it is absolute.
|
||||
var destDirname = dirname(dest);
|
||||
var destDirectory = isAbsolute(dest) ? destDirname : join(process.cwd(), destDirname);
|
||||
writeToPath = join(destDirectory, relative(baseDeclarationDir, name));
|
||||
}
|
||||
// Write the declaration file to disk.
|
||||
sys.writeFile(writeToPath, text, writeByteOrderMark);
|
||||
});
|
||||
|
||||
@ -7,6 +7,7 @@ export default {
|
||||
|
||||
external: [
|
||||
'path',
|
||||
'fs',
|
||||
'fs-extra',
|
||||
'object-assign',
|
||||
'rollup-pluginutils',
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
import {CompilerOptions, ModuleKind} from "typescript";
|
||||
import {IOptions} from "./ioptions";
|
||||
import { CompilerOptions, ModuleKind } from "typescript";
|
||||
import { IOptions } from "./ioptions";
|
||||
import { get } from "lodash";
|
||||
|
||||
export function getOptionsOverrides({useTsconfigDeclarationDir}: IOptions): CompilerOptions {
|
||||
export function getOptionsOverrides({ useTsconfigDeclarationDir }: IOptions, tsConfigJson?: any): CompilerOptions
|
||||
{
|
||||
const declaration = get(tsConfigJson, "compilerOptions.declaration", false);
|
||||
return {
|
||||
module: ModuleKind.ES2015,
|
||||
noEmitHelpers: true,
|
||||
importHelpers: true,
|
||||
noResolve: false,
|
||||
outDir: process.cwd(),
|
||||
...(useTsconfigDeclarationDir ? {} : {declarationDir: process.cwd()}),
|
||||
...(!declaration || useTsconfigDeclarationDir ? {} : {declarationDir: process.cwd()}),
|
||||
};
|
||||
}
|
||||
|
||||
18
src/index.ts
18
src/index.ts
@ -51,6 +51,7 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
abortOnError: true,
|
||||
rollupCommonJSResolveHack: false,
|
||||
tsconfig: "tsconfig.json",
|
||||
useTsconfigDeclarationDir: false,
|
||||
});
|
||||
|
||||
return {
|
||||
@ -235,17 +236,22 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
|
||||
onwrite({dest}: IRollupOptions)
|
||||
{
|
||||
const baseDeclarationDir = parsedConfig.options.outDir as string;
|
||||
const baseDeclarationDir = parsedConfig.options.outDir;
|
||||
each(declarations, ({ name, text, writeByteOrderMark }) =>
|
||||
{
|
||||
let writeToPath: string;
|
||||
// If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options,
|
||||
// use the path provided by Typescript's LanguageService.
|
||||
if (dest == null || pluginOptions.useTsconfigDeclarationDir) return sys.writeFile(name, text, writeByteOrderMark);
|
||||
if (!dest || pluginOptions.useTsconfigDeclarationDir)
|
||||
writeToPath = name;
|
||||
else
|
||||
{
|
||||
// Otherwise, take the directory name from the path and make sure it is absolute.
|
||||
const destDirname = dirname(dest);
|
||||
const destDirectory = isAbsolute(dest) ? destDirname : join(process.cwd(), destDirname);
|
||||
writeToPath = join(destDirectory, relative(baseDeclarationDir!, name));
|
||||
}
|
||||
|
||||
// Otherwise, take the directory name from the path and make sure it is absolute.
|
||||
const destDirname = dirname(dest);
|
||||
const destDirectory = isAbsolute(dest) ? destDirname : join(process.cwd(), destDirname);
|
||||
const writeToPath = join(destDirectory, relative(baseDeclarationDir, name));
|
||||
// Write the declaration file to disk.
|
||||
sys.writeFile(writeToPath, text, writeByteOrderMark);
|
||||
});
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
export interface IRollupOptions {
|
||||
export interface IRollupOptions
|
||||
{
|
||||
dest?: string;
|
||||
}
|
||||
|
||||
@ -6,7 +6,8 @@ import {convertDiagnostic} from "./tscache";
|
||||
import {getOptionsOverrides} from "./get-options-overrides";
|
||||
import {IOptions} from "./ioptions";
|
||||
|
||||
export function parseTsConfig(tsconfig: string, context: IContext, pluginOptions: IOptions): ParsedCommandLine {
|
||||
export function parseTsConfig(tsconfig: string, context: IContext, pluginOptions: IOptions): ParsedCommandLine
|
||||
{
|
||||
const fileName = findConfigFile(process.cwd(), sys.fileExists, tsconfig);
|
||||
|
||||
if (!fileName)
|
||||
@ -20,5 +21,5 @@ export function parseTsConfig(tsconfig: string, context: IContext, pluginOptions
|
||||
throw new Error(`failed to parse ${fileName}`);
|
||||
}
|
||||
|
||||
return parseJsonConfigFileContent(result.config, sys, dirname(fileName), getOptionsOverrides(pluginOptions), fileName);
|
||||
return parseJsonConfigFileContent(result.config, sys, dirname(fileName), getOptionsOverrides(pluginOptions, result.config), fileName);
|
||||
}
|
||||
|
||||
@ -1,3 +1 @@
|
||||
export declare type Partial<T> = {
|
||||
[P in keyof T]?: T[P];
|
||||
};
|
||||
export declare type Partial<T> = { [P in keyof T]?: T[P]; };
|
||||
|
||||
@ -15,8 +15,7 @@
|
||||
"strictNullChecks": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noImplicitReturns": true,
|
||||
"declaration": true,
|
||||
"declarationDir": "./dist"
|
||||
"declaration": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user