mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
Transformers (#74)
This commit is contained in:
parent
b349feed75
commit
9dd2f61b29
22
README.md
22
README.md
@ -128,6 +128,28 @@ See explanation for `rollupCommonJSResolveHack` option below.
|
||||
|
||||
When typescript version installed by the plugin (latest 2.x) is unacceptable, you can import your own typescript module and pass it in as `typescript: require("typescript")`. Must be 2.0+, things might break if transpiler interfaces changed enough from what the plugin was built against.
|
||||
|
||||
* `transformers`: `undefined`
|
||||
|
||||
**experimental**, typescript 2.4.1+
|
||||
|
||||
Transformers will likely be available in tsconfig eventually, so this is not a stable interface, see [Microsoft/TypeScript/issues/14419](https://github.com/Microsoft/TypeScript/issues/14419).
|
||||
|
||||
For example, integrating [kimamula/ts-transformer-keys](https://github.com/kimamula/ts-transformer-keys):
|
||||
|
||||
```js
|
||||
const keysTransformer = require('ts-transformer-keys/transformer').default;
|
||||
const transformers = (service) =>
|
||||
{
|
||||
before: [ keysTransformer(service.getProgram()) ],
|
||||
after: []
|
||||
};
|
||||
|
||||
// ...
|
||||
plugins: [
|
||||
typescript({ transformers })
|
||||
]
|
||||
```
|
||||
|
||||
### 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).
|
||||
|
||||
6
dist/host.d.ts
vendored
6
dist/host.d.ts
vendored
@ -1,11 +1,14 @@
|
||||
import * as tsTypes from "typescript";
|
||||
export declare class LanguageServiceHost implements tsTypes.LanguageServiceHost {
|
||||
private parsedConfig;
|
||||
private transformers;
|
||||
private cwd;
|
||||
private snapshots;
|
||||
private versions;
|
||||
constructor(parsedConfig: tsTypes.ParsedCommandLine);
|
||||
private service?;
|
||||
constructor(parsedConfig: tsTypes.ParsedCommandLine, transformers: (service: tsTypes.LanguageService) => tsTypes.CustomTransformers | undefined);
|
||||
reset(): void;
|
||||
setLanguageService(service: tsTypes.LanguageService): void;
|
||||
setSnapshot(fileName: string, data: string): tsTypes.IScriptSnapshot;
|
||||
getScriptSnapshot(fileName: string): tsTypes.IScriptSnapshot | undefined;
|
||||
getCurrentDirectory(): string;
|
||||
@ -20,4 +23,5 @@ export declare class LanguageServiceHost implements tsTypes.LanguageServiceHost
|
||||
getTypeRootsVersion(): number;
|
||||
directoryExists(directoryName: string): boolean;
|
||||
getDirectories(directoryName: string): string[];
|
||||
getCustomTransformers(): tsTypes.CustomTransformers | undefined;
|
||||
}
|
||||
|
||||
2
dist/ioptions.d.ts
vendored
2
dist/ioptions.d.ts
vendored
@ -1,4 +1,5 @@
|
||||
import { tsModule } from "./tsproxy";
|
||||
import * as tsTypes from "typescript";
|
||||
export interface IOptions {
|
||||
include: string | string[];
|
||||
exclude: string | string[];
|
||||
@ -12,6 +13,7 @@ export interface IOptions {
|
||||
useTsconfigDeclarationDir: boolean;
|
||||
typescript: typeof tsModule;
|
||||
tsconfigOverride: any;
|
||||
transformers: (service: tsTypes.LanguageService) => tsTypes.CustomTransformers;
|
||||
tsconfigDefaults: any;
|
||||
sourceMapCallback: (id: string, map: string) => void;
|
||||
}
|
||||
|
||||
15
dist/rollup-plugin-typescript2.cjs.js
vendored
15
dist/rollup-plugin-typescript2.cjs.js
vendored
@ -17244,8 +17244,9 @@ function normalize(fileName) {
|
||||
}
|
||||
|
||||
var LanguageServiceHost = /** @class */ (function () {
|
||||
function LanguageServiceHost(parsedConfig) {
|
||||
function LanguageServiceHost(parsedConfig, transformers) {
|
||||
this.parsedConfig = parsedConfig;
|
||||
this.transformers = transformers;
|
||||
this.cwd = process.cwd();
|
||||
this.snapshots = {};
|
||||
this.versions = {};
|
||||
@ -17254,6 +17255,9 @@ var LanguageServiceHost = /** @class */ (function () {
|
||||
this.snapshots = {};
|
||||
this.versions = {};
|
||||
};
|
||||
LanguageServiceHost.prototype.setLanguageService = function (service) {
|
||||
this.service = service;
|
||||
};
|
||||
LanguageServiceHost.prototype.setSnapshot = function (fileName, data) {
|
||||
fileName = normalize(fileName);
|
||||
var snapshot = tsModule.ScriptSnapshot.fromString(data);
|
||||
@ -17309,6 +17313,11 @@ var LanguageServiceHost = /** @class */ (function () {
|
||||
LanguageServiceHost.prototype.getDirectories = function (directoryName) {
|
||||
return tsModule.sys.getDirectories(directoryName);
|
||||
};
|
||||
LanguageServiceHost.prototype.getCustomTransformers = function () {
|
||||
if (this.service === undefined || this.transformers === undefined)
|
||||
return undefined;
|
||||
return this.transformers(this.service);
|
||||
};
|
||||
return LanguageServiceHost;
|
||||
}());
|
||||
|
||||
@ -19980,6 +19989,7 @@ function typescript(options) {
|
||||
tsconfig: undefined,
|
||||
useTsconfigDeclarationDir: false,
|
||||
tsconfigOverride: {},
|
||||
transformers: undefined,
|
||||
tsconfigDefaults: {},
|
||||
});
|
||||
setTypescriptModule(pluginOptions.typescript);
|
||||
@ -20024,8 +20034,9 @@ function typescript(options) {
|
||||
context.debug(function () { return "included:\n'" + JSON.stringify(pluginOptions.include, undefined, 4) + "'"; });
|
||||
context.debug(function () { return "excluded:\n'" + JSON.stringify(pluginOptions.exclude, undefined, 4) + "'"; });
|
||||
}
|
||||
servicesHost = new LanguageServiceHost(parsedConfig);
|
||||
servicesHost = new LanguageServiceHost(parsedConfig, pluginOptions.transformers);
|
||||
service = tsModule.createLanguageService(servicesHost, tsModule.createDocumentRegistry());
|
||||
servicesHost.setLanguageService(service);
|
||||
// printing compiler option errors
|
||||
if (pluginOptions.check)
|
||||
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()), parsedConfig.options.pretty === true);
|
||||
|
||||
2
dist/rollup-plugin-typescript2.cjs.js.map
vendored
2
dist/rollup-plugin-typescript2.cjs.js.map
vendored
File diff suppressed because one or more lines are too long
15
dist/rollup-plugin-typescript2.es.js
vendored
15
dist/rollup-plugin-typescript2.es.js
vendored
@ -17240,8 +17240,9 @@ function normalize$1(fileName) {
|
||||
}
|
||||
|
||||
var LanguageServiceHost = /** @class */ (function () {
|
||||
function LanguageServiceHost(parsedConfig) {
|
||||
function LanguageServiceHost(parsedConfig, transformers) {
|
||||
this.parsedConfig = parsedConfig;
|
||||
this.transformers = transformers;
|
||||
this.cwd = process.cwd();
|
||||
this.snapshots = {};
|
||||
this.versions = {};
|
||||
@ -17250,6 +17251,9 @@ var LanguageServiceHost = /** @class */ (function () {
|
||||
this.snapshots = {};
|
||||
this.versions = {};
|
||||
};
|
||||
LanguageServiceHost.prototype.setLanguageService = function (service) {
|
||||
this.service = service;
|
||||
};
|
||||
LanguageServiceHost.prototype.setSnapshot = function (fileName, data) {
|
||||
fileName = normalize$1(fileName);
|
||||
var snapshot = tsModule.ScriptSnapshot.fromString(data);
|
||||
@ -17305,6 +17309,11 @@ var LanguageServiceHost = /** @class */ (function () {
|
||||
LanguageServiceHost.prototype.getDirectories = function (directoryName) {
|
||||
return tsModule.sys.getDirectories(directoryName);
|
||||
};
|
||||
LanguageServiceHost.prototype.getCustomTransformers = function () {
|
||||
if (this.service === undefined || this.transformers === undefined)
|
||||
return undefined;
|
||||
return this.transformers(this.service);
|
||||
};
|
||||
return LanguageServiceHost;
|
||||
}());
|
||||
|
||||
@ -19976,6 +19985,7 @@ function typescript(options) {
|
||||
tsconfig: undefined,
|
||||
useTsconfigDeclarationDir: false,
|
||||
tsconfigOverride: {},
|
||||
transformers: undefined,
|
||||
tsconfigDefaults: {},
|
||||
});
|
||||
setTypescriptModule(pluginOptions.typescript);
|
||||
@ -20020,8 +20030,9 @@ function typescript(options) {
|
||||
context.debug(function () { return "included:\n'" + JSON.stringify(pluginOptions.include, undefined, 4) + "'"; });
|
||||
context.debug(function () { return "excluded:\n'" + JSON.stringify(pluginOptions.exclude, undefined, 4) + "'"; });
|
||||
}
|
||||
servicesHost = new LanguageServiceHost(parsedConfig);
|
||||
servicesHost = new LanguageServiceHost(parsedConfig, pluginOptions.transformers);
|
||||
service = tsModule.createLanguageService(servicesHost, tsModule.createDocumentRegistry());
|
||||
servicesHost.setLanguageService(service);
|
||||
// printing compiler option errors
|
||||
if (pluginOptions.check)
|
||||
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()), parsedConfig.options.pretty === true);
|
||||
|
||||
2
dist/rollup-plugin-typescript2.es.js.map
vendored
2
dist/rollup-plugin-typescript2.es.js.map
vendored
File diff suppressed because one or more lines are too long
16
src/host.ts
16
src/host.ts
@ -9,8 +9,9 @@ export class LanguageServiceHost implements tsTypes.LanguageServiceHost
|
||||
private cwd = process.cwd();
|
||||
private snapshots: { [fileName: string]: tsTypes.IScriptSnapshot } = {};
|
||||
private versions: { [fileName: string]: number } = {};
|
||||
private service?: tsTypes.LanguageService;
|
||||
|
||||
constructor(private parsedConfig: tsTypes.ParsedCommandLine)
|
||||
constructor(private parsedConfig: tsTypes.ParsedCommandLine, private transformers: (service: tsTypes.LanguageService) => tsTypes.CustomTransformers | undefined)
|
||||
{
|
||||
}
|
||||
|
||||
@ -20,6 +21,11 @@ export class LanguageServiceHost implements tsTypes.LanguageServiceHost
|
||||
this.versions = {};
|
||||
}
|
||||
|
||||
public setLanguageService(service: tsTypes.LanguageService)
|
||||
{
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public setSnapshot(fileName: string, data: string): tsTypes.IScriptSnapshot
|
||||
{
|
||||
fileName = normalize(fileName);
|
||||
@ -108,4 +114,12 @@ export class LanguageServiceHost implements tsTypes.LanguageServiceHost
|
||||
{
|
||||
return tsModule.sys.getDirectories(directoryName);
|
||||
}
|
||||
|
||||
public getCustomTransformers(): tsTypes.CustomTransformers | undefined
|
||||
{
|
||||
if (this.service === undefined || this.transformers === undefined)
|
||||
return undefined;
|
||||
|
||||
return this.transformers(this.service);
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,6 +56,7 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
tsconfig: undefined,
|
||||
useTsconfigDeclarationDir: false,
|
||||
tsconfigOverride: {},
|
||||
transformers: undefined,
|
||||
tsconfigDefaults: {},
|
||||
});
|
||||
|
||||
@ -119,9 +120,10 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
context.debug(() => `excluded:\n'${JSON.stringify(pluginOptions.exclude, undefined, 4)}'`);
|
||||
}
|
||||
|
||||
servicesHost = new LanguageServiceHost(parsedConfig);
|
||||
servicesHost = new LanguageServiceHost(parsedConfig, pluginOptions.transformers);
|
||||
|
||||
service = tsModule.createLanguageService(servicesHost, tsModule.createDocumentRegistry());
|
||||
servicesHost.setLanguageService(service);
|
||||
|
||||
// printing compiler option errors
|
||||
if (pluginOptions.check)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { tsModule } from "./tsproxy";
|
||||
import * as tsTypes from "typescript";
|
||||
|
||||
export interface IOptions
|
||||
{
|
||||
@ -14,6 +15,7 @@ export interface IOptions
|
||||
useTsconfigDeclarationDir: boolean;
|
||||
typescript: typeof tsModule;
|
||||
tsconfigOverride: any;
|
||||
transformers: (service: tsTypes.LanguageService) => tsTypes.CustomTransformers;
|
||||
tsconfigDefaults: any;
|
||||
sourceMapCallback: (id: string, map: string) => void;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user