mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
Declarations will now be placed within the 'dest' folder and shadow the filename of the bundle
This commit is contained in:
parent
c4c3a5dd81
commit
919f72ba51
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,4 +2,5 @@
|
||||
/npm-debug.log
|
||||
/typings
|
||||
/.rpt2_cache
|
||||
/.vscode
|
||||
/.vscode
|
||||
/.idea
|
||||
3
dist/index.d.ts
vendored
3
dist/index.d.ts
vendored
@ -1,5 +1,6 @@
|
||||
import { IRollupContext } from "./context";
|
||||
import { ICode } from "./tscache";
|
||||
import { IRollupOptions } from "./irollup-options";
|
||||
export interface IOptions {
|
||||
include?: string;
|
||||
exclude?: string;
|
||||
@ -17,5 +18,5 @@ export default function typescript(options?: IOptions): {
|
||||
load(id: string): string | undefined;
|
||||
transform(this: IRollupContext, code: string, id: string): ICode | undefined;
|
||||
ongenerate(bundleOptions: any): void;
|
||||
onwrite(): void;
|
||||
onwrite({dest}: IRollupOptions): void;
|
||||
};
|
||||
|
||||
28
dist/rollup-plugin-typescript2.cjs.js
vendored
28
dist/rollup-plugin-typescript2.cjs.js
vendored
@ -337,10 +337,10 @@ var TsCache = (function () {
|
||||
this.context.debug(" cache: '" + this.codeCache.path(name) + "'");
|
||||
if (!this.codeCache.exists(name) || this.isDirty(id, snapshot, false)) {
|
||||
this.context.debug(colors.yellow(" cache miss"));
|
||||
var data_1 = transform();
|
||||
this.codeCache.write(name, data_1);
|
||||
var transformedData = transform();
|
||||
this.codeCache.write(name, transformedData);
|
||||
this.markAsDirty(id, snapshot);
|
||||
return data_1;
|
||||
return transformedData;
|
||||
}
|
||||
this.context.debug(colors.green(" cache hit"));
|
||||
var data = this.codeCache.read(name);
|
||||
@ -372,10 +372,10 @@ var TsCache = (function () {
|
||||
this.context.debug(" cache: '" + cache.path(name) + "'");
|
||||
if (!cache.exists(name) || this.isDirty(id, snapshot, true)) {
|
||||
this.context.debug(colors.yellow(" cache miss"));
|
||||
var data_2 = convertDiagnostic(type, check());
|
||||
cache.write(name, data_2);
|
||||
var data_1 = convertDiagnostic(type, check());
|
||||
cache.write(name, data_1);
|
||||
this.markAsDirty(id, snapshot);
|
||||
return data_2;
|
||||
return data_1;
|
||||
}
|
||||
this.context.debug(colors.green(" cache hit"));
|
||||
var data = cache.read(name);
|
||||
@ -621,10 +621,22 @@ function typescript(options) {
|
||||
cache().done();
|
||||
round++;
|
||||
},
|
||||
onwrite: function () {
|
||||
onwrite: function (_a) {
|
||||
var dest = _a.dest;
|
||||
// Expect the destination path given in the rollup bundle to be a relative path (if given). Join it with process.cwd()
|
||||
var bundleDirectory = dest == null ? null : path.join(process.cwd(), path.dirname(dest));
|
||||
var bundleName = dest == null ? null : path.basename(dest);
|
||||
var bundleExt = dest == null ? null : path.extname(dest);
|
||||
_.each(declarations, function (_a) {
|
||||
var name = _a.name, text = _a.text, writeByteOrderMark = _a.writeByteOrderMark;
|
||||
ts.sys.writeFile(name, text, writeByteOrderMark);
|
||||
// If no 'dest' is given, the bundle has no directory, name or extension. In that case, use the default declaration path given by Typescript.
|
||||
if (bundleName == null || bundleExt == null || bundleDirectory == null)
|
||||
return ts.sys.writeFile(name, text, writeByteOrderMark);
|
||||
// Otherwise, try to play nice with the destination from the rollup config.
|
||||
// Make sure that the declaration file has the same name as the bundle (but a different extension)
|
||||
var declarationName = bundleExt === "" ? bundleName + ".d.ts" : bundleName.slice(0, bundleName.indexOf(bundleExt)) + ".d.ts";
|
||||
var declarationFilepath = path.join(bundleDirectory, declarationName);
|
||||
ts.sys.writeFile(declarationFilepath, text, writeByteOrderMark);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
30
dist/rollup-plugin-typescript2.es.js
vendored
30
dist/rollup-plugin-typescript2.es.js
vendored
@ -11,7 +11,7 @@ import { sha1 } from 'object-hash';
|
||||
import * as hash from 'object-hash';
|
||||
import { blue, green, red, white, yellow } from 'colors/safe';
|
||||
import * as colors from 'colors/safe';
|
||||
import { dirname } from 'path';
|
||||
import { basename, dirname, extname, join } from 'path';
|
||||
import * as path from 'path';
|
||||
import { sync } from 'resolve';
|
||||
import * as resolve from 'resolve';
|
||||
@ -343,10 +343,10 @@ var TsCache = (function () {
|
||||
this.context.debug(" cache: '" + this.codeCache.path(name) + "'");
|
||||
if (!this.codeCache.exists(name) || this.isDirty(id, snapshot, false)) {
|
||||
this.context.debug(yellow(" cache miss"));
|
||||
var data_1 = transform();
|
||||
this.codeCache.write(name, data_1);
|
||||
var transformedData = transform();
|
||||
this.codeCache.write(name, transformedData);
|
||||
this.markAsDirty(id, snapshot);
|
||||
return data_1;
|
||||
return transformedData;
|
||||
}
|
||||
this.context.debug(green(" cache hit"));
|
||||
var data = this.codeCache.read(name);
|
||||
@ -378,10 +378,10 @@ var TsCache = (function () {
|
||||
this.context.debug(" cache: '" + cache.path(name) + "'");
|
||||
if (!cache.exists(name) || this.isDirty(id, snapshot, true)) {
|
||||
this.context.debug(yellow(" cache miss"));
|
||||
var data_2 = convertDiagnostic(type, check());
|
||||
cache.write(name, data_2);
|
||||
var data_1 = convertDiagnostic(type, check());
|
||||
cache.write(name, data_1);
|
||||
this.markAsDirty(id, snapshot);
|
||||
return data_2;
|
||||
return data_1;
|
||||
}
|
||||
this.context.debug(green(" cache hit"));
|
||||
var data = cache.read(name);
|
||||
@ -627,10 +627,22 @@ function typescript(options) {
|
||||
cache().done();
|
||||
round++;
|
||||
},
|
||||
onwrite: function () {
|
||||
onwrite: function (_a) {
|
||||
var dest = _a.dest;
|
||||
// Expect the destination path given in the rollup bundle to be a relative path (if given). Join it with process.cwd()
|
||||
var bundleDirectory = dest == null ? null : join(process.cwd(), dirname(dest));
|
||||
var bundleName = dest == null ? null : basename(dest);
|
||||
var bundleExt = dest == null ? null : extname(dest);
|
||||
each(declarations, function (_a) {
|
||||
var name = _a.name, text = _a.text, writeByteOrderMark = _a.writeByteOrderMark;
|
||||
sys.writeFile(name, text, writeByteOrderMark);
|
||||
// If no 'dest' is given, the bundle has no directory, name or extension. In that case, use the default declaration path given by Typescript.
|
||||
if (bundleName == null || bundleExt == null || bundleDirectory == null)
|
||||
return sys.writeFile(name, text, writeByteOrderMark);
|
||||
// Otherwise, try to play nice with the destination from the rollup config.
|
||||
// Make sure that the declaration file has the same name as the bundle (but a different extension)
|
||||
var declarationName = bundleExt === "" ? bundleName + ".d.ts" : bundleName.slice(0, bundleName.indexOf(bundleExt)) + ".d.ts";
|
||||
var declarationFilepath = join(bundleDirectory, declarationName);
|
||||
sys.writeFile(declarationFilepath, text, writeByteOrderMark);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
18
src/index.ts
18
src/index.ts
@ -3,11 +3,13 @@ import { IContext, ConsoleContext, IRollupContext, VerbosityLevel } from "./cont
|
||||
import { LanguageServiceHost } from "./host";
|
||||
import { TsCache, convertDiagnostic, ICode, IDiagnostics } from "./tscache";
|
||||
import * as ts from "typescript";
|
||||
import {basename, dirname, extname, join} from "path";
|
||||
import * as fs from "fs-extra";
|
||||
import * as path from "path";
|
||||
import * as _ from "lodash";
|
||||
import * as colors from "colors/safe";
|
||||
import * as resolve from "resolve";
|
||||
import { IRollupOptions } from "./irollup-options";
|
||||
|
||||
// tslint:disable-next-line:no-var-requires
|
||||
const createFilter = require("rollup-pluginutils").createFilter;
|
||||
@ -324,11 +326,23 @@ export default function typescript(options?: IOptions)
|
||||
round++;
|
||||
},
|
||||
|
||||
onwrite()
|
||||
onwrite({dest}: IRollupOptions)
|
||||
{
|
||||
// Expect the destination path given in the rollup bundle to be a relative path (if given). Join it with process.cwd()
|
||||
const bundleDirectory = dest == null ? null : join(process.cwd(), dirname(dest));
|
||||
const bundleName = dest == null ? null : basename(dest);
|
||||
const bundleExt = dest == null ? null : extname(dest);
|
||||
_.each(declarations, ({ name, text, writeByteOrderMark }) =>
|
||||
{
|
||||
ts.sys.writeFile(name, text, writeByteOrderMark);
|
||||
// If no 'dest' is given, the bundle has no directory, name or extension. In that case, use the default declaration path given by Typescript.
|
||||
if (bundleName == null || bundleExt == null || bundleDirectory == null) return ts.sys.writeFile(name, text, writeByteOrderMark);
|
||||
|
||||
// Otherwise, try to play nice with the destination from the rollup config.
|
||||
// Make sure that the declaration file has the same name as the bundle (but a different extension)
|
||||
const declarationName = bundleExt === "" ? `${bundleName}.d.ts` : `${bundleName.slice(0, bundleName.indexOf(bundleExt))}.d.ts`;
|
||||
const declarationFilepath = join(bundleDirectory, declarationName);
|
||||
|
||||
ts.sys.writeFile(declarationFilepath, text, writeByteOrderMark);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
3
src/irollup-options.ts
Normal file
3
src/irollup-options.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export interface IRollupOptions {
|
||||
dest?: string;
|
||||
}
|
||||
@ -148,10 +148,10 @@ export class TsCache
|
||||
{
|
||||
this.context.debug(colors.yellow(" cache miss"));
|
||||
|
||||
const data = transform();
|
||||
this.codeCache.write(name, data);
|
||||
const transformedData = transform();
|
||||
this.codeCache.write(name, transformedData);
|
||||
this.markAsDirty(id, snapshot);
|
||||
return data;
|
||||
return transformedData;
|
||||
}
|
||||
|
||||
this.context.debug(colors.green(" cache hit"));
|
||||
@ -200,10 +200,10 @@ export class TsCache
|
||||
{
|
||||
this.context.debug(colors.yellow(" cache miss"));
|
||||
|
||||
const data = convertDiagnostic(type, check());
|
||||
cache.write(name, data);
|
||||
const convertedData = convertDiagnostic(type, check());
|
||||
cache.write(name, convertedData);
|
||||
this.markAsDirty(id, snapshot);
|
||||
return data;
|
||||
return convertedData;
|
||||
}
|
||||
|
||||
this.context.debug(colors.green(" cache hit"));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user