write out DTS file structure

This commit is contained in:
Bryan Ross 2017-05-29 08:47:37 -06:00
parent a355b88b04
commit b948b49d75
5 changed files with 1183 additions and 1139 deletions

View File

@ -71,7 +71,12 @@ 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`.
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`.
### 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).
### Watch mode

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -152,6 +152,8 @@ export default function typescript(options: IOptions)
let noErrors = true;
const declarations: ts.OutputFile[] = [];
// printing compiler option errors
if (options.check)
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()));
@ -249,10 +251,12 @@ export default function typescript(options: IOptions)
const transpiled = _.find(output.outputFiles, (entry) => _.endsWith(entry.name, ".js") );
const map = _.find(output.outputFiles, (entry) => _.endsWith(entry.name, ".map") );
const dts = _.find(output.outputFiles, (entry) => _.endsWith(entry.name, ".d.ts"));
return {
code: transpiled ? transpiled.text : undefined,
map: map ? JSON.parse(map.text) : { mappings: "" },
dts,
};
});
@ -275,6 +279,10 @@ export default function typescript(options: IOptions)
printDiagnostics(contextWrapper, diagnostics);
}
if (result && result.dts) {
declarations.push(result.dts);
}
return result;
},
@ -311,5 +319,11 @@ export default function typescript(options: IOptions)
round++;
},
onwrite() {
declarations.forEach(({ name, text, writeByteOrderMark }) => {
ts.sys.writeFile(name, text, writeByteOrderMark);
});
},
};
}

View File

@ -12,6 +12,7 @@ export interface ICode
{
code: string | undefined;
map: string | undefined;
dts?: ts.OutputFile | undefined;
}
interface INodeLabel