mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
parent
e6e72fb2b0
commit
b3e32e51a9
29
README.md
29
README.md
@ -27,7 +27,7 @@ export default {
|
||||
}
|
||||
```
|
||||
|
||||
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, see `tsconfig` and `tsconfigOverride` options below. This also allows for passing in different tsconfig files depending on your build target.
|
||||
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, see `tsconfigDefaults`, `tsconfig` and `tsconfigOverride` options below. This also allows for passing in different tsconfig files depending on your build target.
|
||||
|
||||
The following compiler options are forced though:
|
||||
|
||||
@ -42,24 +42,35 @@ The following compiler options are forced though:
|
||||
|
||||
### Plugin options
|
||||
|
||||
* `tsconfig`: "tsconfig.json"
|
||||
* `tsconfigDefaults`: `{}`
|
||||
|
||||
Override this if your tsconfig has another name or relative location from the project directory.
|
||||
The object passed as `tsconfigDefaults` will be merged with loaded `tsconfig.json`. Final config passed to typescript will be the result of values in `tsconfigDefaults` replaced by values in loaded `tsconfig.json`, replaced by values in `tsconfigOverride` and then replaced by hard `compilerOptions` overrides on top of that (see above).
|
||||
|
||||
* `tsconfigOverride`: `{}`
|
||||
|
||||
The object passed as `tsconfigOverride` will be merged with loaded tsconfig before parsing. Hard overrides (see above) will be applied on top of that. Theoretically you can put everything you would put in tsconfig proper.
|
||||
For simplicity and other tools' sake, try to minimize usage of defaults and overrides and keep everything in `tsconfig.json` file (tsconfigs can themselves be chained, so save some turtles).
|
||||
|
||||
```js
|
||||
let override = { compilerOptions: { declaration: true } };
|
||||
let defaults = { compilerOptions: { declaration: true } };
|
||||
let override = { compilerOptions: { declaration: false } };
|
||||
|
||||
// ...
|
||||
plugins: [
|
||||
typescript({ tsconfigOverride: override })
|
||||
typescript({
|
||||
tsconfigDefaults: defaults,
|
||||
tsconfig: "tsconfig.json",
|
||||
tsconfigOverride: override
|
||||
})
|
||||
]
|
||||
```
|
||||
|
||||
This is a [deep merge](https://lodash.com/docs/4.17.4#merge) (objects are merged, arrays are concatenated, primitives are replaced, etc), increase verbosity to 3 and look for `parsed tsconfig` if you get something unexpected.
|
||||
This is a [deep merge](https://lodash.com/docs/4.17.4#merge) (objects are merged, arrays are concatenated, primitives are replaced, etc), increase `verbosity` to 3 and look for `parsed tsconfig` if you get something unexpected.
|
||||
|
||||
* `tsconfig`: `undefined`
|
||||
|
||||
Path to `tsconfig.json`. Set this if your tsconfig has another name or relative location from the project directory. By default will try to load `./tsconfig.json`, but will not fail if file is missing unless the value is set explicitly.
|
||||
|
||||
* `tsconfigOverride`: `{}`
|
||||
|
||||
See `tsconfigDefaults`.
|
||||
|
||||
* `check`: true
|
||||
|
||||
|
||||
3
dist/ioptions.d.ts
vendored
3
dist/ioptions.d.ts
vendored
@ -8,8 +8,9 @@ export interface IOptions {
|
||||
cacheRoot: string;
|
||||
abortOnError: boolean;
|
||||
rollupCommonJSResolveHack: boolean;
|
||||
tsconfig: string;
|
||||
tsconfig?: string;
|
||||
useTsconfigDeclarationDir: boolean;
|
||||
typescript: typeof tsModule;
|
||||
tsconfigOverride: any;
|
||||
tsconfigDefaults: any;
|
||||
}
|
||||
|
||||
2
dist/parse-ts-config.d.ts
vendored
2
dist/parse-ts-config.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
import * as tsTypes from "typescript";
|
||||
import { IContext } from "./context";
|
||||
import { IOptions } from "./ioptions";
|
||||
export declare function parseTsConfig(tsconfig: string, context: IContext, pluginOptions: IOptions): tsTypes.ParsedCommandLine;
|
||||
export declare function parseTsConfig(context: IContext, pluginOptions: IOptions): tsTypes.ParsedCommandLine;
|
||||
|
||||
45
dist/rollup-plugin-typescript2.cjs.js
vendored
45
dist/rollup-plugin-typescript2.cjs.js
vendored
@ -19726,19 +19726,31 @@ function getOptionsOverrides(_a, tsConfigJson) {
|
||||
return overrides;
|
||||
}
|
||||
|
||||
function parseTsConfig(tsconfig, context, pluginOptions) {
|
||||
var fileName = tsModule.findConfigFile(process.cwd(), tsModule.sys.fileExists, tsconfig);
|
||||
if (!fileName)
|
||||
throw new Error("couldn't find '" + tsconfig + "' in " + process.cwd());
|
||||
var text = tsModule.sys.readFile(fileName);
|
||||
var result = tsModule.parseConfigFileTextToJson(fileName, text);
|
||||
if (result.error) {
|
||||
printDiagnostics(context, convertDiagnostic("config", [result.error]), lodash_1(result.config, "pretty", false));
|
||||
throw new Error("failed to parse " + fileName);
|
||||
function parseTsConfig(context, pluginOptions) {
|
||||
var fileName = tsModule.findConfigFile(process.cwd(), tsModule.sys.fileExists, pluginOptions.tsconfig);
|
||||
// if the value was provided, but no file, fail hard
|
||||
if (pluginOptions.tsconfig !== undefined && !fileName)
|
||||
throw new Error("failed to open '" + fileName + "'");
|
||||
var loadedConfig = {};
|
||||
var baseDir = process.cwd();
|
||||
var configFileName;
|
||||
if (fileName) {
|
||||
var text = tsModule.sys.readFile(fileName);
|
||||
if (text === undefined)
|
||||
throw new Error("failed to read '" + fileName + "'");
|
||||
var result = tsModule.parseConfigFileTextToJson(fileName, text);
|
||||
if (result.error !== undefined) {
|
||||
printDiagnostics(context, convertDiagnostic("config", [result.error]), lodash_1(result.config, "pretty", false));
|
||||
throw new Error("failed to parse '" + fileName + "'");
|
||||
}
|
||||
loadedConfig = result.config;
|
||||
baseDir = path.dirname(fileName);
|
||||
configFileName = fileName;
|
||||
}
|
||||
lodash_14(result.config, pluginOptions.tsconfigOverride);
|
||||
var compilerOptionsOverride = getOptionsOverrides(pluginOptions, result.config);
|
||||
var parsedTsConfig = tsModule.parseJsonConfigFileContent(result.config, tsModule.sys, path.dirname(fileName), compilerOptionsOverride, fileName);
|
||||
var mergedConfig = {};
|
||||
lodash_14(mergedConfig, pluginOptions.tsconfigDefaults, loadedConfig, pluginOptions.tsconfigOverride);
|
||||
var compilerOptionsOverride = getOptionsOverrides(pluginOptions, mergedConfig);
|
||||
var parsedTsConfig = tsModule.parseJsonConfigFileContent(mergedConfig, tsModule.sys, baseDir, compilerOptionsOverride, configFileName);
|
||||
context.debug("built-in options overrides: " + JSON.stringify(compilerOptionsOverride, undefined, 4));
|
||||
context.debug("parsed tsconfig: " + JSON.stringify(parsedTsConfig, undefined, 4));
|
||||
return parsedTsConfig;
|
||||
@ -19787,10 +19799,11 @@ function typescript(options) {
|
||||
exclude: ["*.d.ts", "**/*.d.ts"],
|
||||
abortOnError: true,
|
||||
rollupCommonJSResolveHack: false,
|
||||
tsconfig: "tsconfig.json",
|
||||
useTsconfigDeclarationDir: false,
|
||||
typescript: require("typescript"),
|
||||
tsconfig: undefined,
|
||||
useTsconfigDeclarationDir: false,
|
||||
tsconfigOverride: {},
|
||||
tsconfigDefaults: {},
|
||||
});
|
||||
setTypescriptModule(pluginOptions.typescript);
|
||||
return {
|
||||
@ -19799,13 +19812,13 @@ function typescript(options) {
|
||||
rollupOptions = __assign({}, config);
|
||||
context = new ConsoleContext(pluginOptions.verbosity, "rpt2: ");
|
||||
context.info("typescript version: " + tsModule.version);
|
||||
context.info("rollup-plugin-typescript2 version: 0.10.1");
|
||||
context.info("rollup-plugin-typescript2 version: 0.11.0");
|
||||
context.debug(function () { return "plugin options:\n" + JSON.stringify(pluginOptions, function (key, value) { return key === "typescript" ? "version " + value.version : value; }, 4); });
|
||||
context.debug(function () { return "rollup config:\n" + JSON.stringify(rollupOptions, undefined, 4); });
|
||||
watchMode = process.env.ROLLUP_WATCH === "true";
|
||||
if (watchMode)
|
||||
context.info("running in watch mode");
|
||||
parsedConfig = parseTsConfig(pluginOptions.tsconfig, context, pluginOptions);
|
||||
parsedConfig = parseTsConfig(context, pluginOptions);
|
||||
if (parsedConfig.options.rootDirs) {
|
||||
var included_1 = lodash_16(parsedConfig.options.rootDirs)
|
||||
.flatMap(function (root) {
|
||||
|
||||
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
45
dist/rollup-plugin-typescript2.es.js
vendored
45
dist/rollup-plugin-typescript2.es.js
vendored
@ -19722,19 +19722,31 @@ function getOptionsOverrides(_a, tsConfigJson) {
|
||||
return overrides;
|
||||
}
|
||||
|
||||
function parseTsConfig(tsconfig, context, pluginOptions) {
|
||||
var fileName = tsModule.findConfigFile(process.cwd(), tsModule.sys.fileExists, tsconfig);
|
||||
if (!fileName)
|
||||
throw new Error("couldn't find '" + tsconfig + "' in " + process.cwd());
|
||||
var text = tsModule.sys.readFile(fileName);
|
||||
var result = tsModule.parseConfigFileTextToJson(fileName, text);
|
||||
if (result.error) {
|
||||
printDiagnostics(context, convertDiagnostic("config", [result.error]), lodash_1(result.config, "pretty", false));
|
||||
throw new Error("failed to parse " + fileName);
|
||||
function parseTsConfig(context, pluginOptions) {
|
||||
var fileName = tsModule.findConfigFile(process.cwd(), tsModule.sys.fileExists, pluginOptions.tsconfig);
|
||||
// if the value was provided, but no file, fail hard
|
||||
if (pluginOptions.tsconfig !== undefined && !fileName)
|
||||
throw new Error("failed to open '" + fileName + "'");
|
||||
var loadedConfig = {};
|
||||
var baseDir = process.cwd();
|
||||
var configFileName;
|
||||
if (fileName) {
|
||||
var text = tsModule.sys.readFile(fileName);
|
||||
if (text === undefined)
|
||||
throw new Error("failed to read '" + fileName + "'");
|
||||
var result = tsModule.parseConfigFileTextToJson(fileName, text);
|
||||
if (result.error !== undefined) {
|
||||
printDiagnostics(context, convertDiagnostic("config", [result.error]), lodash_1(result.config, "pretty", false));
|
||||
throw new Error("failed to parse '" + fileName + "'");
|
||||
}
|
||||
loadedConfig = result.config;
|
||||
baseDir = dirname(fileName);
|
||||
configFileName = fileName;
|
||||
}
|
||||
lodash_14(result.config, pluginOptions.tsconfigOverride);
|
||||
var compilerOptionsOverride = getOptionsOverrides(pluginOptions, result.config);
|
||||
var parsedTsConfig = tsModule.parseJsonConfigFileContent(result.config, tsModule.sys, dirname(fileName), compilerOptionsOverride, fileName);
|
||||
var mergedConfig = {};
|
||||
lodash_14(mergedConfig, pluginOptions.tsconfigDefaults, loadedConfig, pluginOptions.tsconfigOverride);
|
||||
var compilerOptionsOverride = getOptionsOverrides(pluginOptions, mergedConfig);
|
||||
var parsedTsConfig = tsModule.parseJsonConfigFileContent(mergedConfig, tsModule.sys, baseDir, compilerOptionsOverride, configFileName);
|
||||
context.debug("built-in options overrides: " + JSON.stringify(compilerOptionsOverride, undefined, 4));
|
||||
context.debug("parsed tsconfig: " + JSON.stringify(parsedTsConfig, undefined, 4));
|
||||
return parsedTsConfig;
|
||||
@ -19783,10 +19795,11 @@ function typescript(options) {
|
||||
exclude: ["*.d.ts", "**/*.d.ts"],
|
||||
abortOnError: true,
|
||||
rollupCommonJSResolveHack: false,
|
||||
tsconfig: "tsconfig.json",
|
||||
useTsconfigDeclarationDir: false,
|
||||
typescript: require("typescript"),
|
||||
tsconfig: undefined,
|
||||
useTsconfigDeclarationDir: false,
|
||||
tsconfigOverride: {},
|
||||
tsconfigDefaults: {},
|
||||
});
|
||||
setTypescriptModule(pluginOptions.typescript);
|
||||
return {
|
||||
@ -19795,13 +19808,13 @@ function typescript(options) {
|
||||
rollupOptions = __assign({}, config);
|
||||
context = new ConsoleContext(pluginOptions.verbosity, "rpt2: ");
|
||||
context.info("typescript version: " + tsModule.version);
|
||||
context.info("rollup-plugin-typescript2 version: 0.10.1");
|
||||
context.info("rollup-plugin-typescript2 version: 0.11.0");
|
||||
context.debug(function () { return "plugin options:\n" + JSON.stringify(pluginOptions, function (key, value) { return key === "typescript" ? "version " + value.version : value; }, 4); });
|
||||
context.debug(function () { return "rollup config:\n" + JSON.stringify(rollupOptions, undefined, 4); });
|
||||
watchMode = process.env.ROLLUP_WATCH === "true";
|
||||
if (watchMode)
|
||||
context.info("running in watch mode");
|
||||
parsedConfig = parseTsConfig(pluginOptions.tsconfig, context, pluginOptions);
|
||||
parsedConfig = parseTsConfig(context, pluginOptions);
|
||||
if (parsedConfig.options.rootDirs) {
|
||||
var included_1 = lodash_16(parsedConfig.options.rootDirs)
|
||||
.flatMap(function (root) {
|
||||
|
||||
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
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rollup-plugin-typescript2",
|
||||
"version": "0.10.1",
|
||||
"version": "0.11.0",
|
||||
"description": "Seamless integration between Rollup and TypeScript. Now with errors.",
|
||||
"main": "dist/rollup-plugin-typescript2.cjs.js",
|
||||
"module": "dist/rollup-plugin-typescript2.es.js",
|
||||
|
||||
@ -52,10 +52,11 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
exclude: ["*.d.ts", "**/*.d.ts"],
|
||||
abortOnError: true,
|
||||
rollupCommonJSResolveHack: false,
|
||||
tsconfig: "tsconfig.json",
|
||||
useTsconfigDeclarationDir: false,
|
||||
typescript: require("typescript"),
|
||||
tsconfig: undefined,
|
||||
useTsconfigDeclarationDir: false,
|
||||
tsconfigOverride: {},
|
||||
tsconfigDefaults: {},
|
||||
});
|
||||
|
||||
setTypescriptModule(pluginOptions.typescript);
|
||||
@ -79,7 +80,7 @@ export default function typescript(options?: Partial<IOptions>)
|
||||
if (watchMode)
|
||||
context.info(`running in watch mode`);
|
||||
|
||||
parsedConfig = parseTsConfig(pluginOptions.tsconfig, context, pluginOptions);
|
||||
parsedConfig = parseTsConfig(context, pluginOptions);
|
||||
|
||||
if (parsedConfig.options.rootDirs)
|
||||
{
|
||||
|
||||
@ -10,8 +10,9 @@ export interface IOptions
|
||||
cacheRoot: string;
|
||||
abortOnError: boolean;
|
||||
rollupCommonJSResolveHack: boolean;
|
||||
tsconfig: string;
|
||||
tsconfig?: string;
|
||||
useTsconfigDeclarationDir: boolean;
|
||||
typescript: typeof tsModule;
|
||||
tsconfigOverride: any;
|
||||
tsconfigDefaults: any;
|
||||
}
|
||||
|
||||
@ -8,26 +8,41 @@ import { getOptionsOverrides } from "./get-options-overrides";
|
||||
import { IOptions } from "./ioptions";
|
||||
import * as _ from "lodash";
|
||||
|
||||
export function parseTsConfig(tsconfig: string, context: IContext, pluginOptions: IOptions): tsTypes.ParsedCommandLine
|
||||
export function parseTsConfig(context: IContext, pluginOptions: IOptions): tsTypes.ParsedCommandLine
|
||||
{
|
||||
const fileName = tsModule.findConfigFile(process.cwd(), tsModule.sys.fileExists, tsconfig);
|
||||
const fileName = tsModule.findConfigFile(process.cwd(), tsModule.sys.fileExists, pluginOptions.tsconfig);
|
||||
|
||||
if (!fileName)
|
||||
throw new Error(`couldn't find '${tsconfig}' in ${process.cwd()}`);
|
||||
// if the value was provided, but no file, fail hard
|
||||
if (pluginOptions.tsconfig !== undefined && !fileName)
|
||||
throw new Error(`failed to open '${fileName}'`);
|
||||
|
||||
const text = tsModule.sys.readFile(fileName);
|
||||
const result = tsModule.parseConfigFileTextToJson(fileName, text!);
|
||||
|
||||
if (result.error)
|
||||
let loadedConfig: any = {};
|
||||
let baseDir = process.cwd();
|
||||
let configFileName;
|
||||
if (fileName)
|
||||
{
|
||||
printDiagnostics(context, convertDiagnostic("config", [result.error]), _.get(result.config, "pretty", false));
|
||||
throw new Error(`failed to parse ${fileName}`);
|
||||
const text = tsModule.sys.readFile(fileName);
|
||||
if (text === undefined)
|
||||
throw new Error(`failed to read '${fileName}'`);
|
||||
|
||||
const result = tsModule.parseConfigFileTextToJson(fileName, text);
|
||||
|
||||
if (result.error !== undefined)
|
||||
{
|
||||
printDiagnostics(context, convertDiagnostic("config", [result.error]), _.get(result.config, "pretty", false));
|
||||
throw new Error(`failed to parse '${fileName}'`);
|
||||
}
|
||||
|
||||
loadedConfig = result.config;
|
||||
baseDir = dirname(fileName);
|
||||
configFileName = fileName;
|
||||
}
|
||||
|
||||
_.merge(result.config, pluginOptions.tsconfigOverride);
|
||||
const mergedConfig = {};
|
||||
_.merge(mergedConfig, pluginOptions.tsconfigDefaults, loadedConfig, pluginOptions.tsconfigOverride);
|
||||
|
||||
const compilerOptionsOverride = getOptionsOverrides(pluginOptions, result.config);
|
||||
const parsedTsConfig = tsModule.parseJsonConfigFileContent(result.config, tsModule.sys, dirname(fileName), compilerOptionsOverride, fileName);
|
||||
const compilerOptionsOverride = getOptionsOverrides(pluginOptions, mergedConfig);
|
||||
const parsedTsConfig = tsModule.parseJsonConfigFileContent(mergedConfig, tsModule.sys, baseDir, compilerOptionsOverride, configFileName);
|
||||
|
||||
context.debug(`built-in options overrides: ${JSON.stringify(compilerOptionsOverride, undefined, 4)}`);
|
||||
context.debug(`parsed tsconfig: ${JSON.stringify(parsedTsConfig, undefined, 4)}`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user