mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
This commit is contained in:
commit
8bee8e9541
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
/node_modules
|
||||
/npm-debug.log
|
||||
/typings
|
||||
/.rpt2_cache
|
||||
/.rpt2_cache
|
||||
/.vscode
|
||||
22
README.md
22
README.md
@ -5,7 +5,7 @@
|
||||

|
||||
[](https://app.codeship.com/projects/207445)
|
||||
|
||||
Rollup plugin for typescript with compiler errors.
|
||||
Rollup plugin for typescript with compiler errors.
|
||||
|
||||
This is a rewrite of original rollup-plugin-typescript, starting and borrowing from [this fork](https://github.com/alexlur/rollup-plugin-typescript).
|
||||
|
||||
@ -26,9 +26,21 @@ export default {
|
||||
}
|
||||
```
|
||||
|
||||
The plugin depends on existence of `tsconfig.json` file. All compiler options and file lists are loaded from that.
|
||||
The plugin inherits all compiler options and file lists from your `tsconfig.json` file.
|
||||
If your tsconfig has another name or another relative path from the root directory, you can pass in a custom path:
|
||||
|
||||
Following compiler options are forced though:
|
||||
```js
|
||||
// ...
|
||||
plugins: [
|
||||
typescript({
|
||||
tsconfig: "other_dir/tsconfig.json"
|
||||
})
|
||||
]
|
||||
```
|
||||
|
||||
This also allows for passing in different tsconfig files depending on your build target.
|
||||
|
||||
The following compiler options are forced though:
|
||||
* `module`: es2015
|
||||
* `noEmitHelpers`: true
|
||||
* `importHelpers`: true
|
||||
@ -38,6 +50,10 @@ You will need to set `"moduleResolution": "node"` in `tsconfig.json` if typescri
|
||||
|
||||
Plugin takes following options:
|
||||
|
||||
* `tsconfig`: "tsconfig.json"
|
||||
|
||||
Override this if your tsconfig has another name or relative location from the project directory.
|
||||
|
||||
* `check`: true
|
||||
|
||||
Set to false to avoid doing any diagnostic checks on the code.
|
||||
|
||||
50
dist/context.d.ts
vendored
50
dist/context.d.ts
vendored
@ -1,25 +1,25 @@
|
||||
export interface IRollupContext {
|
||||
warn(message: string): void;
|
||||
error(message: string): void;
|
||||
}
|
||||
export interface IContext {
|
||||
warn(message: string): void;
|
||||
error(message: string): void;
|
||||
info(message: string): void;
|
||||
debug(message: string): void;
|
||||
}
|
||||
export declare enum VerbosityLevel {
|
||||
Error = 0,
|
||||
Warning = 1,
|
||||
Info = 2,
|
||||
Debug = 3,
|
||||
}
|
||||
export declare class ConsoleContext implements IContext {
|
||||
private verbosity;
|
||||
private prefix;
|
||||
constructor(verbosity: VerbosityLevel, prefix?: string);
|
||||
warn(message: string): void;
|
||||
error(message: string): void;
|
||||
info(message: string): void;
|
||||
debug(message: string): void;
|
||||
}
|
||||
export interface IRollupContext {
|
||||
warn(message: string): void;
|
||||
error(message: string): void;
|
||||
}
|
||||
export interface IContext {
|
||||
warn(message: string): void;
|
||||
error(message: string): void;
|
||||
info(message: string): void;
|
||||
debug(message: string): void;
|
||||
}
|
||||
export declare enum VerbosityLevel {
|
||||
Error = 0,
|
||||
Warning = 1,
|
||||
Info = 2,
|
||||
Debug = 3,
|
||||
}
|
||||
export declare class ConsoleContext implements IContext {
|
||||
private verbosity;
|
||||
private prefix;
|
||||
constructor(verbosity: VerbosityLevel, prefix?: string);
|
||||
warn(message: string): void;
|
||||
error(message: string): void;
|
||||
info(message: string): void;
|
||||
debug(message: string): void;
|
||||
}
|
||||
|
||||
34
dist/host.d.ts
vendored
34
dist/host.d.ts
vendored
@ -1,17 +1,17 @@
|
||||
import * as ts from "typescript";
|
||||
export declare class LanguageServiceHost implements ts.LanguageServiceHost {
|
||||
private parsedConfig;
|
||||
private cwd;
|
||||
private snapshots;
|
||||
private versions;
|
||||
constructor(parsedConfig: ts.ParsedCommandLine);
|
||||
reset(): void;
|
||||
setSnapshot(fileName: string, data: string): ts.IScriptSnapshot;
|
||||
getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined;
|
||||
getCurrentDirectory(): string;
|
||||
getScriptVersion(fileName: string): string;
|
||||
getScriptFileNames(): string[];
|
||||
getCompilationSettings(): ts.CompilerOptions;
|
||||
getDefaultLibFileName(opts: ts.CompilerOptions): string;
|
||||
private normalize(fileName);
|
||||
}
|
||||
import * as ts from "typescript";
|
||||
export declare class LanguageServiceHost implements ts.LanguageServiceHost {
|
||||
private parsedConfig;
|
||||
private cwd;
|
||||
private snapshots;
|
||||
private versions;
|
||||
constructor(parsedConfig: ts.ParsedCommandLine);
|
||||
reset(): void;
|
||||
setSnapshot(fileName: string, data: string): ts.IScriptSnapshot;
|
||||
getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined;
|
||||
getCurrentDirectory(): string;
|
||||
getScriptVersion(fileName: string): string;
|
||||
getScriptFileNames(): string[];
|
||||
getCompilationSettings(): ts.CompilerOptions;
|
||||
getDefaultLibFileName(opts: ts.CompilerOptions): string;
|
||||
private normalize(fileName);
|
||||
}
|
||||
|
||||
41
dist/index.d.ts
vendored
41
dist/index.d.ts
vendored
@ -1,20 +1,21 @@
|
||||
import { IRollupContext } from "./context";
|
||||
import { ICode } from "./tscache";
|
||||
export interface IOptions {
|
||||
include: string;
|
||||
exclude: string;
|
||||
check: boolean;
|
||||
verbosity: number;
|
||||
clean: boolean;
|
||||
cacheRoot: string;
|
||||
abortOnError: boolean;
|
||||
rollupCommonJSResolveHack: boolean;
|
||||
}
|
||||
export default function typescript(options: IOptions): {
|
||||
options(config: any): void;
|
||||
resolveId(importee: string, importer: string): string | null;
|
||||
load(id: string): string | undefined;
|
||||
transform(this: IRollupContext, code: string, id: string): ICode | undefined;
|
||||
ongenerate(bundleOptions: any): void;
|
||||
onwrite(): void;
|
||||
};
|
||||
import { IRollupContext } from "./context";
|
||||
import { ICode } from "./tscache";
|
||||
export interface IOptions {
|
||||
include: string;
|
||||
exclude: string;
|
||||
check: boolean;
|
||||
verbosity: number;
|
||||
clean: boolean;
|
||||
cacheRoot: string;
|
||||
abortOnError: boolean;
|
||||
rollupCommonJSResolveHack: boolean;
|
||||
tsconfig: string;
|
||||
}
|
||||
export default function typescript(options: IOptions): {
|
||||
options(config: any): void;
|
||||
resolveId(importee: string, importer: string): string | null;
|
||||
load(id: string): string | undefined;
|
||||
transform(this: IRollupContext, code: string, id: string): ICode | undefined;
|
||||
ongenerate(bundleOptions: any): void;
|
||||
onwrite(): void;
|
||||
};
|
||||
|
||||
72
dist/rollingcache.d.ts
vendored
72
dist/rollingcache.d.ts
vendored
@ -1,36 +1,36 @@
|
||||
import { ICache } from "./icache";
|
||||
/**
|
||||
* Saves data in new cache folder or reads it from old one.
|
||||
* Avoids perpetually growing cache and situations when things need to consider changed and then reverted data to be changed.
|
||||
*/
|
||||
export declare class RollingCache<DataType> implements ICache<DataType> {
|
||||
private cacheRoot;
|
||||
private checkNewCache;
|
||||
private oldCacheRoot;
|
||||
private newCacheRoot;
|
||||
private rolled;
|
||||
/**
|
||||
* @param cacheRoot: root folder for the cache
|
||||
* @param checkNewCache: whether to also look in new cache when reading from cache
|
||||
*/
|
||||
constructor(cacheRoot: string, checkNewCache: boolean);
|
||||
/**
|
||||
* @returns true if name exist in old cache (or either old of new cache if checkNewCache is true)
|
||||
*/
|
||||
exists(name: string): boolean;
|
||||
path(name: string): string;
|
||||
/**
|
||||
* @returns true if old cache contains all names and nothing more
|
||||
*/
|
||||
match(names: string[]): boolean;
|
||||
/**
|
||||
* @returns data for name, must exist in old cache (or either old of new cache if checkNewCache is true)
|
||||
*/
|
||||
read(name: string): DataType;
|
||||
write(name: string, data: DataType): void;
|
||||
touch(name: string): void;
|
||||
/**
|
||||
* clears old cache and moves new in its place
|
||||
*/
|
||||
roll(): void;
|
||||
}
|
||||
import { ICache } from "./icache";
|
||||
/**
|
||||
* Saves data in new cache folder or reads it from old one.
|
||||
* Avoids perpetually growing cache and situations when things need to consider changed and then reverted data to be changed.
|
||||
*/
|
||||
export declare class RollingCache<DataType> implements ICache<DataType> {
|
||||
private cacheRoot;
|
||||
private checkNewCache;
|
||||
private oldCacheRoot;
|
||||
private newCacheRoot;
|
||||
private rolled;
|
||||
/**
|
||||
* @param cacheRoot: root folder for the cache
|
||||
* @param checkNewCache: whether to also look in new cache when reading from cache
|
||||
*/
|
||||
constructor(cacheRoot: string, checkNewCache: boolean);
|
||||
/**
|
||||
* @returns true if name exist in old cache (or either old of new cache if checkNewCache is true)
|
||||
*/
|
||||
exists(name: string): boolean;
|
||||
path(name: string): string;
|
||||
/**
|
||||
* @returns true if old cache contains all names and nothing more
|
||||
*/
|
||||
match(names: string[]): boolean;
|
||||
/**
|
||||
* @returns data for name, must exist in old cache (or either old of new cache if checkNewCache is true)
|
||||
*/
|
||||
read(name: string): DataType;
|
||||
write(name: string, data: DataType): void;
|
||||
touch(name: string): void;
|
||||
/**
|
||||
* clears old cache and moves new in its place
|
||||
*/
|
||||
roll(): void;
|
||||
}
|
||||
|
||||
9
dist/rollup-plugin-typescript2.cjs.js
vendored
9
dist/rollup-plugin-typescript2.cjs.js
vendored
@ -418,10 +418,10 @@ catch (e) {
|
||||
console.warn("Error loading `tslib` helper library.");
|
||||
throw e;
|
||||
}
|
||||
function parseTsConfig(context) {
|
||||
var fileName = ts.findConfigFile(process.cwd(), ts.sys.fileExists, "tsconfig.json");
|
||||
function parseTsConfig(tsconfig, context) {
|
||||
var fileName = ts.findConfigFile(process.cwd(), ts.sys.fileExists, tsconfig);
|
||||
if (!fileName)
|
||||
throw new Error("couldn't find 'tsconfig.json' in " + process.cwd());
|
||||
throw new Error("couldn't find '" + tsconfig + "' in " + process.cwd());
|
||||
var text = ts.sys.readFile(fileName);
|
||||
var result = ts.parseConfigFileTextToJson(fileName, text);
|
||||
if (result.error) {
|
||||
@ -473,6 +473,7 @@ function typescript(options) {
|
||||
exclude: ["*.d.ts", "**/*.d.ts"],
|
||||
abortOnError: true,
|
||||
rollupCommonJSResolveHack: false,
|
||||
tsconfig: "tsconfig.json"
|
||||
});
|
||||
var rollupConfig;
|
||||
var watchMode = false;
|
||||
@ -482,7 +483,7 @@ function typescript(options) {
|
||||
context.info("Typescript version: " + ts.version);
|
||||
context.debug("Options: " + JSON.stringify(options, undefined, 4));
|
||||
var filter$$1 = createFilter(options.include, options.exclude);
|
||||
var parsedConfig = parseTsConfig(context);
|
||||
var parsedConfig = parseTsConfig(options.tsconfig, context);
|
||||
var servicesHost = new LanguageServiceHost(parsedConfig);
|
||||
var service = ts.createLanguageService(servicesHost, ts.createDocumentRegistry());
|
||||
var _cache;
|
||||
|
||||
9
dist/rollup-plugin-typescript2.es.js
vendored
9
dist/rollup-plugin-typescript2.es.js
vendored
@ -424,10 +424,10 @@ catch (e) {
|
||||
console.warn("Error loading `tslib` helper library.");
|
||||
throw e;
|
||||
}
|
||||
function parseTsConfig(context) {
|
||||
var fileName = findConfigFile(process.cwd(), sys.fileExists, "tsconfig.json");
|
||||
function parseTsConfig(tsconfig, context) {
|
||||
var fileName = findConfigFile(process.cwd(), sys.fileExists, tsconfig);
|
||||
if (!fileName)
|
||||
throw new Error("couldn't find 'tsconfig.json' in " + process.cwd());
|
||||
throw new Error("couldn't find '" + tsconfig + "' in " + process.cwd());
|
||||
var text = sys.readFile(fileName);
|
||||
var result = parseConfigFileTextToJson(fileName, text);
|
||||
if (result.error) {
|
||||
@ -479,6 +479,7 @@ function typescript(options) {
|
||||
exclude: ["*.d.ts", "**/*.d.ts"],
|
||||
abortOnError: true,
|
||||
rollupCommonJSResolveHack: false,
|
||||
tsconfig: "tsconfig.json"
|
||||
});
|
||||
var rollupConfig;
|
||||
var watchMode = false;
|
||||
@ -488,7 +489,7 @@ function typescript(options) {
|
||||
context.info("Typescript version: " + version);
|
||||
context.debug("Options: " + JSON.stringify(options, undefined, 4));
|
||||
var filter$$1 = createFilter(options.include, options.exclude);
|
||||
var parsedConfig = parseTsConfig(context);
|
||||
var parsedConfig = parseTsConfig(options.tsconfig, context);
|
||||
var servicesHost = new LanguageServiceHost(parsedConfig);
|
||||
var service = createLanguageService(servicesHost, createDocumentRegistry());
|
||||
var _cache;
|
||||
|
||||
26
dist/rollupcontext.d.ts
vendored
26
dist/rollupcontext.d.ts
vendored
@ -1,13 +1,13 @@
|
||||
import { IContext, IRollupContext, VerbosityLevel } from "./context";
|
||||
export declare class RollupContext implements IContext {
|
||||
private verbosity;
|
||||
private bail;
|
||||
private context;
|
||||
private prefix;
|
||||
private hasContext;
|
||||
constructor(verbosity: VerbosityLevel, bail: boolean, context: IRollupContext, prefix?: string);
|
||||
warn(message: string): void;
|
||||
error(message: string): void;
|
||||
info(message: string): void;
|
||||
debug(message: string): void;
|
||||
}
|
||||
import { IContext, IRollupContext, VerbosityLevel } from "./context";
|
||||
export declare class RollupContext implements IContext {
|
||||
private verbosity;
|
||||
private bail;
|
||||
private context;
|
||||
private prefix;
|
||||
private hasContext;
|
||||
constructor(verbosity: VerbosityLevel, bail: boolean, context: IRollupContext, prefix?: string);
|
||||
warn(message: string): void;
|
||||
error(message: string): void;
|
||||
info(message: string): void;
|
||||
debug(message: string): void;
|
||||
}
|
||||
|
||||
88
dist/tscache.d.ts
vendored
88
dist/tscache.d.ts
vendored
@ -1,44 +1,44 @@
|
||||
import { IContext } from "./context";
|
||||
import * as ts from "typescript";
|
||||
export interface ICode {
|
||||
code: string | undefined;
|
||||
map: string | undefined;
|
||||
dts?: ts.OutputFile | undefined;
|
||||
}
|
||||
export interface IDiagnostics {
|
||||
flatMessage: string;
|
||||
fileLine?: string;
|
||||
category: ts.DiagnosticCategory;
|
||||
code: number;
|
||||
type: string;
|
||||
}
|
||||
export declare function convertDiagnostic(type: string, data: ts.Diagnostic[]): IDiagnostics[];
|
||||
export declare class TsCache {
|
||||
private host;
|
||||
private options;
|
||||
private rollupConfig;
|
||||
private context;
|
||||
private cacheVersion;
|
||||
private dependencyTree;
|
||||
private ambientTypes;
|
||||
private ambientTypesDirty;
|
||||
private cacheDir;
|
||||
private codeCache;
|
||||
private typesCache;
|
||||
private semanticDiagnosticsCache;
|
||||
private syntacticDiagnosticsCache;
|
||||
constructor(host: ts.LanguageServiceHost, cache: string, options: ts.CompilerOptions, rollupConfig: any, rootFilenames: string[], context: IContext);
|
||||
clean(): void;
|
||||
setDependency(importee: string, importer: string): void;
|
||||
walkTree(cb: (id: string) => void | false): void;
|
||||
done(): void;
|
||||
getCompiled(id: string, snapshot: ts.IScriptSnapshot, transform: () => ICode | undefined): ICode | undefined;
|
||||
getSyntacticDiagnostics(id: string, snapshot: ts.IScriptSnapshot, check: () => ts.Diagnostic[]): IDiagnostics[];
|
||||
getSemanticDiagnostics(id: string, snapshot: ts.IScriptSnapshot, check: () => ts.Diagnostic[]): IDiagnostics[];
|
||||
private checkAmbientTypes();
|
||||
private getDiagnostics(type, cache, id, snapshot, check);
|
||||
private init();
|
||||
private markAsDirty(id, _snapshot);
|
||||
private isDirty(id, _snapshot, checkImports);
|
||||
private makeName(id, snapshot);
|
||||
}
|
||||
import { IContext } from "./context";
|
||||
import * as ts from "typescript";
|
||||
export interface ICode {
|
||||
code: string | undefined;
|
||||
map: string | undefined;
|
||||
dts?: ts.OutputFile | undefined;
|
||||
}
|
||||
export interface IDiagnostics {
|
||||
flatMessage: string;
|
||||
fileLine?: string;
|
||||
category: ts.DiagnosticCategory;
|
||||
code: number;
|
||||
type: string;
|
||||
}
|
||||
export declare function convertDiagnostic(type: string, data: ts.Diagnostic[]): IDiagnostics[];
|
||||
export declare class TsCache {
|
||||
private host;
|
||||
private options;
|
||||
private rollupConfig;
|
||||
private context;
|
||||
private cacheVersion;
|
||||
private dependencyTree;
|
||||
private ambientTypes;
|
||||
private ambientTypesDirty;
|
||||
private cacheDir;
|
||||
private codeCache;
|
||||
private typesCache;
|
||||
private semanticDiagnosticsCache;
|
||||
private syntacticDiagnosticsCache;
|
||||
constructor(host: ts.LanguageServiceHost, cache: string, options: ts.CompilerOptions, rollupConfig: any, rootFilenames: string[], context: IContext);
|
||||
clean(): void;
|
||||
setDependency(importee: string, importer: string): void;
|
||||
walkTree(cb: (id: string) => void | false): void;
|
||||
done(): void;
|
||||
getCompiled(id: string, snapshot: ts.IScriptSnapshot, transform: () => ICode | undefined): ICode | undefined;
|
||||
getSyntacticDiagnostics(id: string, snapshot: ts.IScriptSnapshot, check: () => ts.Diagnostic[]): IDiagnostics[];
|
||||
getSemanticDiagnostics(id: string, snapshot: ts.IScriptSnapshot, check: () => ts.Diagnostic[]): IDiagnostics[];
|
||||
private checkAmbientTypes();
|
||||
private getDiagnostics(type, cache, id, snapshot, check);
|
||||
private init();
|
||||
private markAsDirty(id, _snapshot);
|
||||
private isDirty(id, _snapshot, checkImports);
|
||||
private makeName(id, snapshot);
|
||||
}
|
||||
|
||||
10
src/index.ts
10
src/index.ts
@ -36,12 +36,12 @@ try
|
||||
throw e;
|
||||
}
|
||||
|
||||
function parseTsConfig(context: IContext)
|
||||
function parseTsConfig(tsconfig: string, context: IContext)
|
||||
{
|
||||
const fileName = ts.findConfigFile(process.cwd(), ts.sys.fileExists, "tsconfig.json");
|
||||
const fileName = ts.findConfigFile(process.cwd(), ts.sys.fileExists, tsconfig);
|
||||
|
||||
if (!fileName)
|
||||
throw new Error(`couldn't find 'tsconfig.json' in ${process.cwd()}`);
|
||||
throw new Error(`couldn't find '${tsconfig}' in ${process.cwd()}`);
|
||||
|
||||
const text = ts.sys.readFile(fileName);
|
||||
const result = ts.parseConfigFileTextToJson(fileName, text);
|
||||
@ -104,6 +104,7 @@ export interface IOptions
|
||||
cacheRoot: string;
|
||||
abortOnError: boolean;
|
||||
rollupCommonJSResolveHack: boolean;
|
||||
tsconfig: string;
|
||||
}
|
||||
|
||||
export default function typescript(options: IOptions)
|
||||
@ -120,6 +121,7 @@ export default function typescript(options: IOptions)
|
||||
exclude: [ "*.d.ts", "**/*.d.ts" ],
|
||||
abortOnError: true,
|
||||
rollupCommonJSResolveHack: false,
|
||||
tsconfig: "tsconfig.json"
|
||||
});
|
||||
|
||||
let rollupConfig: any;
|
||||
@ -135,7 +137,7 @@ export default function typescript(options: IOptions)
|
||||
|
||||
const filter = createFilter(options.include, options.exclude);
|
||||
|
||||
const parsedConfig = parseTsConfig(context);
|
||||
const parsedConfig = parseTsConfig(options.tsconfig, context);
|
||||
|
||||
const servicesHost = new LanguageServiceHost(parsedConfig);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user