@rollup/plugin-typescript
Advanced tools
Comparing version 8.1.1 to 8.2.0
# @rollup/plugin-typescript ChangeLog | ||
## v8.2.0 | ||
_2021-02-14_ | ||
### Features | ||
- feat: error when no tsconfig and no rootDir (#794) | ||
- feat: better error when tslib is not installed (#793) | ||
- feat: warn when compilerOptions.module is not esnext (#788) | ||
### Updates | ||
- test: move declaration tests, use typescript (#791) | ||
- test: fix TypeScript src-dir test (#789) | ||
## v8.1.1 | ||
@@ -4,0 +19,0 @@ |
@@ -1,6 +0,6 @@ | ||
import path, { resolve, dirname, relative, win32, posix, normalize } from 'path'; | ||
import path, { resolve as resolve$1, dirname, relative, win32, posix, normalize } from 'path'; | ||
import { createFilter } from '@rollup/pluginutils'; | ||
import * as defaultTs from 'typescript'; | ||
import { DiagnosticCategory } from 'typescript'; | ||
import resolveId from 'resolve'; | ||
import { ModuleKind, DiagnosticCategory } from 'typescript'; | ||
import resolve from 'resolve'; | ||
import fs, { readFileSync } from 'fs'; | ||
@@ -79,9 +79,26 @@ | ||
const resolveIdAsync = (file, opts) => new Promise((fulfil, reject) => resolveId(file, opts, (err, contents) => (err || typeof contents === 'undefined' ? reject(err) : fulfil(contents)))); | ||
// const resolveIdAsync = (file: string, opts: AsyncOpts) => | ||
// new Promise<string>((fulfil, reject) => | ||
// resolveId(file, opts, (err, contents) => | ||
// err || typeof contents === 'undefined' ? reject(err) : fulfil(contents) | ||
// ) | ||
// ); | ||
const resolveId = (file, opts) => resolve.sync(file, opts); | ||
/** | ||
* Returns code asynchronously for the tslib helper library. | ||
*/ | ||
function getTsLibPath() { | ||
return resolveIdAsync('tslib/tslib.es6.js', { basedir: __dirname }); | ||
} | ||
const getTsLibPath = () => { | ||
// Note: This isn't preferable, but we've no other way to test this bit. Removing the tslib devDep | ||
// during the test run doesn't work due to the nature of the pnpm flat node_modules, and | ||
// other workspace dependencies that depenend upon tslib. | ||
try { | ||
// eslint-disable-next-line no-underscore-dangle | ||
return resolveId(process.env.__TSLIB_TEST_PATH__ || 'tslib/tslib.es6.js', { | ||
basedir: __dirname | ||
}); | ||
} | ||
catch (_) { | ||
return null; | ||
} | ||
}; | ||
@@ -98,3 +115,3 @@ /** | ||
*/ | ||
function getPluginOptions(options) { | ||
const getPluginOptions = (options) => { | ||
const { cacheDir, exclude, include, transformers, tsconfig, tslib, typescript } = options, compilerOptions = __rest(options, ["cacheDir", "exclude", "include", "transformers", "tsconfig", "tslib", "typescript"]); | ||
@@ -111,3 +128,3 @@ const filter = createFilter(include || ['*.ts+(|x)', '**/*.ts+(|x)'], exclude); | ||
}; | ||
} | ||
}; | ||
@@ -176,3 +193,3 @@ /** | ||
if (compilerOptions[pathProp]) { | ||
compilerOptions[pathProp] = resolve(relativeTo, compilerOptions[pathProp]); | ||
compilerOptions[pathProp] = resolve$1(relativeTo, compilerOptions[pathProp]); | ||
} | ||
@@ -233,3 +250,3 @@ } | ||
// Resolve path to file. `tsConfigOption` defaults to 'tsconfig.json'. | ||
const tsConfigPath = resolve(process.cwd(), relativePath || 'tsconfig.json'); | ||
const tsConfigPath = resolve$1(process.cwd(), relativePath || 'tsconfig.json'); | ||
if (!ts.sys.fileExists(tsConfigPath)) { | ||
@@ -422,2 +439,25 @@ if (relativePath) { | ||
const pluginName = '@rollup/plugin-typescript'; | ||
const moduleErrorMessage = ` | ||
${pluginName}: Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a | ||
"module" other than "esnext". Unless you know what you're doing, please change "module" to "esnext" | ||
in the target tsconfig.json file or plugin options.`.replace(/\n/g, ''); | ||
const rootDirErrorMessage = `${pluginName}: The "rootDir" or "rootDirs" option is required when the "tsconfig" option is not specified and "declaration" is "true".`; | ||
const tsLibErrorMessage = `${pluginName}: Could not find module 'tslib', which is required by this plugin. Is it installed?`; | ||
let undef; | ||
const validModules = [ModuleKind.ES2015, ModuleKind.ES2020, ModuleKind.ESNext, undef]; | ||
// eslint-disable-next-line import/prefer-default-export | ||
const preflight = ({ config, context, rollupOptions, tslib }) => { | ||
if (!validModules.includes(config.options.module)) { | ||
context.warn(moduleErrorMessage); | ||
} | ||
const { options } = config; | ||
if (options.declaration && !options.configFilePath && !options.rootDir && !options.rootDirs) { | ||
context.error(rootDirErrorMessage); | ||
} | ||
if (!rollupOptions.preserveModules && tslib === null) { | ||
context.error(tsLibErrorMessage); | ||
} | ||
}; | ||
// `Cannot compile modules into 'es6' when targeting 'ES5' or lower.` | ||
@@ -657,4 +697,5 @@ const CANNOT_COMPILE_ESM = 1204; | ||
name: 'typescript', | ||
buildStart() { | ||
buildStart(rollupOptions) { | ||
emitParsedOptionsErrors(ts, this, parsedOptions); | ||
preflight({ config: parsedOptions, context: this, rollupOptions, tslib }); | ||
// Fixes a memory leak https://github.com/rollup/plugins/issues/322 | ||
@@ -661,0 +702,0 @@ if (!program) { |
@@ -6,3 +6,3 @@ 'use strict'; | ||
var defaultTs = require('typescript'); | ||
var resolveId = require('resolve'); | ||
var resolve = require('resolve'); | ||
var fs = require('fs'); | ||
@@ -34,3 +34,3 @@ | ||
var defaultTs__namespace = /*#__PURE__*/_interopNamespace(defaultTs); | ||
var resolveId__default = /*#__PURE__*/_interopDefaultLegacy(resolveId); | ||
var resolve__default = /*#__PURE__*/_interopDefaultLegacy(resolve); | ||
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs); | ||
@@ -109,9 +109,26 @@ | ||
const resolveIdAsync = (file, opts) => new Promise((fulfil, reject) => resolveId__default['default'](file, opts, (err, contents) => (err || typeof contents === 'undefined' ? reject(err) : fulfil(contents)))); | ||
// const resolveIdAsync = (file: string, opts: AsyncOpts) => | ||
// new Promise<string>((fulfil, reject) => | ||
// resolveId(file, opts, (err, contents) => | ||
// err || typeof contents === 'undefined' ? reject(err) : fulfil(contents) | ||
// ) | ||
// ); | ||
const resolveId = (file, opts) => resolve__default['default'].sync(file, opts); | ||
/** | ||
* Returns code asynchronously for the tslib helper library. | ||
*/ | ||
function getTsLibPath() { | ||
return resolveIdAsync('tslib/tslib.es6.js', { basedir: __dirname }); | ||
} | ||
const getTsLibPath = () => { | ||
// Note: This isn't preferable, but we've no other way to test this bit. Removing the tslib devDep | ||
// during the test run doesn't work due to the nature of the pnpm flat node_modules, and | ||
// other workspace dependencies that depenend upon tslib. | ||
try { | ||
// eslint-disable-next-line no-underscore-dangle | ||
return resolveId(process.env.__TSLIB_TEST_PATH__ || 'tslib/tslib.es6.js', { | ||
basedir: __dirname | ||
}); | ||
} | ||
catch (_) { | ||
return null; | ||
} | ||
}; | ||
@@ -128,3 +145,3 @@ /** | ||
*/ | ||
function getPluginOptions(options) { | ||
const getPluginOptions = (options) => { | ||
const { cacheDir, exclude, include, transformers, tsconfig, tslib, typescript } = options, compilerOptions = __rest(options, ["cacheDir", "exclude", "include", "transformers", "tsconfig", "tslib", "typescript"]); | ||
@@ -141,3 +158,3 @@ const filter = pluginutils.createFilter(include || ['*.ts+(|x)', '**/*.ts+(|x)'], exclude); | ||
}; | ||
} | ||
}; | ||
@@ -450,2 +467,25 @@ /** | ||
const pluginName = '@rollup/plugin-typescript'; | ||
const moduleErrorMessage = ` | ||
${pluginName}: Rollup requires that TypeScript produces ES Modules. Unfortunately your configuration specifies a | ||
"module" other than "esnext". Unless you know what you're doing, please change "module" to "esnext" | ||
in the target tsconfig.json file or plugin options.`.replace(/\n/g, ''); | ||
const rootDirErrorMessage = `${pluginName}: The "rootDir" or "rootDirs" option is required when the "tsconfig" option is not specified and "declaration" is "true".`; | ||
const tsLibErrorMessage = `${pluginName}: Could not find module 'tslib', which is required by this plugin. Is it installed?`; | ||
let undef; | ||
const validModules = [defaultTs.ModuleKind.ES2015, defaultTs.ModuleKind.ES2020, defaultTs.ModuleKind.ESNext, undef]; | ||
// eslint-disable-next-line import/prefer-default-export | ||
const preflight = ({ config, context, rollupOptions, tslib }) => { | ||
if (!validModules.includes(config.options.module)) { | ||
context.warn(moduleErrorMessage); | ||
} | ||
const { options } = config; | ||
if (options.declaration && !options.configFilePath && !options.rootDir && !options.rootDirs) { | ||
context.error(rootDirErrorMessage); | ||
} | ||
if (!rollupOptions.preserveModules && tslib === null) { | ||
context.error(tsLibErrorMessage); | ||
} | ||
}; | ||
// `Cannot compile modules into 'es6' when targeting 'ES5' or lower.` | ||
@@ -685,4 +725,5 @@ const CANNOT_COMPILE_ESM = 1204; | ||
name: 'typescript', | ||
buildStart() { | ||
buildStart(rollupOptions) { | ||
emitParsedOptionsErrors(ts, this, parsedOptions); | ||
preflight({ config: parsedOptions, context: this, rollupOptions, tslib }); | ||
// Fixes a memory leak https://github.com/rollup/plugins/issues/322 | ||
@@ -689,0 +730,0 @@ if (!program) { |
{ | ||
"name": "@rollup/plugin-typescript", | ||
"version": "8.1.1", | ||
"version": "8.2.0", | ||
"publishConfig": { | ||
@@ -33,3 +33,4 @@ "access": "public" | ||
"pretest": "pnpm run build", | ||
"test": "ava" | ||
"test": "ava", | ||
"test:ts": "tsc --noEmit" | ||
}, | ||
@@ -66,21 +67,3 @@ "files": [ | ||
}, | ||
"types": "types/index.d.ts", | ||
"ava": { | ||
"babel": { | ||
"compileEnhancements": false | ||
}, | ||
"extensions": [ | ||
"ts" | ||
], | ||
"require": [ | ||
"ts-node/register" | ||
], | ||
"files": [ | ||
"!**/fixtures/**", | ||
"!**/output/**", | ||
"!**/helpers/**", | ||
"!**/recipes/**", | ||
"!**/types.ts" | ||
] | ||
} | ||
"types": "types/index.d.ts" | ||
} |
import { FilterPattern } from '@rollup/pluginutils'; | ||
import { Plugin } from 'rollup'; | ||
import { CompilerOptions, CustomTransformers, Program, TypeChecker } from 'typescript'; | ||
import { | ||
CompilerOptions, | ||
CompilerOptionsValue, | ||
CustomTransformers, | ||
Program, | ||
TsConfigSourceFile, | ||
TypeChecker | ||
} from 'typescript'; | ||
type ElementType<T extends Array<any> | undefined> = T extends (infer U)[] ? U : never; | ||
export type TransformerStage = keyof CustomTransformers; | ||
type StagedTransformerFactory<T extends TransformerStage> = ElementType<CustomTransformers[T]>; | ||
type TransformerFactory<T extends TransformerStage> = | ||
| StagedTransformerFactory<T> | ||
| ProgramTransformerFactory<T> | ||
| TypeCheckerTransformerFactory<T>; | ||
export type CustomTransformerFactories = { | ||
[stage in TransformerStage]?: Array<TransformerFactory<stage>>; | ||
}; | ||
interface ProgramTransformerFactory<T extends TransformerStage> { | ||
type: 'program'; | ||
factory(program: Program): StagedTransformerFactory<T>; | ||
} | ||
interface TypeCheckerTransformerFactory<T extends TransformerStage> { | ||
type: 'typeChecker'; | ||
factory(typeChecker: TypeChecker): StagedTransformerFactory<T>; | ||
} | ||
export interface RollupTypescriptPluginOptions { | ||
@@ -41,27 +73,6 @@ /** | ||
type ElementType<T extends Array<any> | undefined> = T extends (infer U)[] ? U : never; | ||
export type TransformerStage = keyof CustomTransformers; | ||
type StagedTransformerFactory<T extends TransformerStage> = ElementType<CustomTransformers[T]>; | ||
type TransformerFactory<T extends TransformerStage> = | ||
| StagedTransformerFactory<T> | ||
| ProgramTransformerFactory<T> | ||
| TypeCheckerTransformerFactory<T>; | ||
export type CustomTransformerFactories = { | ||
[stage in TransformerStage]?: Array<TransformerFactory<stage>>; | ||
}; | ||
interface ProgramTransformerFactory<T extends TransformerStage> { | ||
type: 'program'; | ||
factory(program: Program): StagedTransformerFactory<T>; | ||
export interface FlexibleCompilerOptions extends CompilerOptions { | ||
[option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined | any; | ||
} | ||
interface TypeCheckerTransformerFactory<T extends TransformerStage> { | ||
type: 'typeChecker'; | ||
factory(typeChecker: TypeChecker): StagedTransformerFactory<T>; | ||
} | ||
/** Properties of `CompilerOptions` that are normally enums */ | ||
@@ -71,7 +82,9 @@ export type EnumCompilerOptions = 'module' | 'moduleResolution' | 'newLine' | 'jsx' | 'target'; | ||
/** JSON representation of Typescript compiler options */ | ||
export type JsonCompilerOptions = Omit<CompilerOptions, EnumCompilerOptions> & | ||
export type JsonCompilerOptions = Omit<FlexibleCompilerOptions, EnumCompilerOptions> & | ||
Record<EnumCompilerOptions, string>; | ||
/** Compiler options set by the plugin user. */ | ||
export type PartialCompilerOptions = Partial<CompilerOptions> | Partial<JsonCompilerOptions>; | ||
export type PartialCompilerOptions = | ||
| Partial<FlexibleCompilerOptions> | ||
| Partial<JsonCompilerOptions>; | ||
@@ -78,0 +91,0 @@ export type RollupTypescriptOptions = RollupTypescriptPluginOptions & PartialCompilerOptions; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92425
1648
5