Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rollup/plugin-typescript

Package Overview
Dependencies
Maintainers
4
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rollup/plugin-typescript - npm Package Compare versions

Comparing version 6.1.0 to 8.0.0

42

CHANGELOG.md
# @rollup/plugin-typescript ChangeLog
## v8.0.0
_2020-11-30_
### Breaking Changes
- fix: pick up new files in watch mode (#657)
### Bugfixes
- fix: add missing imports (#633)
- fix: normalize returned module ids (#653)
### Features
- feat: Implement cached incremental code (#535)
### Updates
- docs: fix minor markdown syntax in transformers-section (#624)
## v7.0.0
_2020-11-30_
### Breaking Changes
- fix: pick up new files in watch mode (#657)
### Bugfixes
- fix: add missing imports (#633)
- fix: normalize returned module ids (#653)
### Features
- feat: Implement cached incremental code (#535)
### Updates
- docs: fix minor markdown syntax in transformers-section (#624)
## v6.1.0

@@ -4,0 +46,0 @@

84

dist/index.es.js

@@ -1,2 +0,2 @@

import { resolve, dirname, relative, win32, posix } from 'path';
import path, { resolve, dirname, relative, win32, posix, normalize } from 'path';
import { createFilter } from '@rollup/pluginutils';

@@ -6,3 +6,3 @@ import * as defaultTs from 'typescript';

import resolveId from 'resolve';
import { readFileSync } from 'fs';
import fs, { readFileSync } from 'fs';

@@ -99,5 +99,6 @@ /**

function getPluginOptions(options) {
const { include, exclude, tsconfig, typescript, tslib, transformers } = options, compilerOptions = __rest(options, ["include", "exclude", "tsconfig", "typescript", "tslib", "transformers"]);
const { cacheDir, exclude, include, transformers, tsconfig, tslib, typescript } = options, compilerOptions = __rest(options, ["cacheDir", "exclude", "include", "transformers", "tsconfig", "tslib", "typescript"]);
const filter = createFilter(include || ['*.ts+(|x)', '**/*.ts+(|x)'], exclude);
return {
cacheDir,
filter,

@@ -386,2 +387,21 @@ tsconfig,

/**
* Returns the content of a filename either from the current
* typescript compiler instance or from the cached content.
* @param fileName The filename for the contents to retrieve
* @param emittedFiles The files emitted in the current typescript instance
* @param tsCache A cache to files cached by Typescript
*/
function getEmittedFile(fileName, emittedFiles, tsCache) {
let code;
if (fileName) {
if (emittedFiles.has(fileName)) {
code = emittedFiles.get(fileName);
}
else {
code = tsCache.getCached(fileName);
}
}
return code;
}
/**
* Finds the corresponding emitted Javascript files for a given Typescript file.

@@ -392,3 +412,3 @@ * @param id Path to the Typescript file.

*/
function findTypescriptOutput(ts, parsedOptions, id, emittedFiles) {
function findTypescriptOutput(ts, parsedOptions, id, emittedFiles, tsCache) {
const emittedFileNames = ts.getOutputFileNames(parsedOptions, id, !ts.sys.useCaseSensitiveFileNames);

@@ -398,4 +418,4 @@ const codeFile = emittedFileNames.find(isCodeOutputFile);

return {
code: emittedFiles.get(codeFile),
map: emittedFiles.get(mapFile),
code: getEmittedFile(codeFile, emittedFiles, tsCache),
map: getEmittedFile(mapFile, emittedFiles, tsCache),
declarations: emittedFileNames.filter((name) => name !== codeFile && name !== mapFile)

@@ -591,4 +611,38 @@ };

/** Creates the folders needed given a path to a file to be saved*/
const createFileFolder = (filePath) => {
const folderPath = path.dirname(filePath);
fs.mkdirSync(folderPath, { recursive: true });
};
class TSCache {
constructor(cacheFolder = '.rollup.cache') {
this._cacheFolder = cacheFolder;
}
/** Returns the path to the cached file */
cachedFilename(fileName) {
return path.join(this._cacheFolder, fileName.replace(/^([A-Z]+):/, '$1'));
}
/** Emits a file in the cache folder */
cacheCode(fileName, code) {
const cachedPath = this.cachedFilename(fileName);
createFileFolder(cachedPath);
fs.writeFileSync(cachedPath, code);
}
/** Checks if a file is in the cache */
isCached(fileName) {
return fs.existsSync(this.cachedFilename(fileName));
}
/** Read a file from the cache given the output name*/
getCached(fileName) {
let code;
if (this.isCached(fileName)) {
code = fs.readFileSync(this.cachedFilename(fileName), { encoding: 'utf-8' });
}
return code;
}
}
function typescript(options = {}) {
const { filter, tsconfig, compilerOptions, tslib, typescript: ts, transformers } = getPluginOptions(options);
const { cacheDir, compilerOptions, filter, transformers, tsconfig, tslib, typescript: ts } = getPluginOptions(options);
const tsCache = new TSCache(cacheDir);
const emittedFiles = new Map();

@@ -615,2 +669,5 @@ const watchProgramHelper = new WatchProgramHelper();

writeFile(fileName, data) {
if (parsedOptions.options.composite || parsedOptions.options.incremental) {
tsCache.cacheCode(fileName, data);
}
emittedFiles.set(fileName, data);

@@ -653,3 +710,3 @@ },

return null;
return resolved.resolvedFileName;
return normalize(resolved.resolvedFileName);
}

@@ -662,3 +719,8 @@ return null;

await watchProgramHelper.wait();
const output = findTypescriptOutput(ts, parsedOptions, id, emittedFiles);
const fileName = normalizePath(id);
if (!parsedOptions.fileNames.includes(fileName)) {
// Discovered new file that was not known when originally parsing the TypeScript config
parsedOptions.fileNames.push(fileName);
}
const output = findTypescriptOutput(ts, parsedOptions, id, emittedFiles, tsCache);
return output.code != null ? output : null;

@@ -668,5 +730,5 @@ },

parsedOptions.fileNames.forEach((fileName) => {
const output = findTypescriptOutput(ts, parsedOptions, fileName, emittedFiles);
const output = findTypescriptOutput(ts, parsedOptions, fileName, emittedFiles, tsCache);
output.declarations.forEach((id) => {
const code = emittedFiles.get(id);
const code = getEmittedFile(id, emittedFiles, tsCache);
if (!code)

@@ -673,0 +735,0 @@ return;

@@ -31,4 +31,6 @@ 'use strict';

var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
var defaultTs__namespace = /*#__PURE__*/_interopNamespace(defaultTs);
var resolveId__default = /*#__PURE__*/_interopDefaultLegacy(resolveId);
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

@@ -125,5 +127,6 @@ /**

function getPluginOptions(options) {
const { include, exclude, tsconfig, typescript, tslib, transformers } = options, compilerOptions = __rest(options, ["include", "exclude", "tsconfig", "typescript", "tslib", "transformers"]);
const { cacheDir, exclude, include, transformers, tsconfig, tslib, typescript } = options, compilerOptions = __rest(options, ["cacheDir", "exclude", "include", "transformers", "tsconfig", "tslib", "typescript"]);
const filter = pluginutils.createFilter(include || ['*.ts+(|x)', '**/*.ts+(|x)'], exclude);
return {
cacheDir,
filter,

@@ -412,2 +415,21 @@ tsconfig,

/**
* Returns the content of a filename either from the current
* typescript compiler instance or from the cached content.
* @param fileName The filename for the contents to retrieve
* @param emittedFiles The files emitted in the current typescript instance
* @param tsCache A cache to files cached by Typescript
*/
function getEmittedFile(fileName, emittedFiles, tsCache) {
let code;
if (fileName) {
if (emittedFiles.has(fileName)) {
code = emittedFiles.get(fileName);
}
else {
code = tsCache.getCached(fileName);
}
}
return code;
}
/**
* Finds the corresponding emitted Javascript files for a given Typescript file.

@@ -418,3 +440,3 @@ * @param id Path to the Typescript file.

*/
function findTypescriptOutput(ts, parsedOptions, id, emittedFiles) {
function findTypescriptOutput(ts, parsedOptions, id, emittedFiles, tsCache) {
const emittedFileNames = ts.getOutputFileNames(parsedOptions, id, !ts.sys.useCaseSensitiveFileNames);

@@ -424,4 +446,4 @@ const codeFile = emittedFileNames.find(isCodeOutputFile);

return {
code: emittedFiles.get(codeFile),
map: emittedFiles.get(mapFile),
code: getEmittedFile(codeFile, emittedFiles, tsCache),
map: getEmittedFile(mapFile, emittedFiles, tsCache),
declarations: emittedFileNames.filter((name) => name !== codeFile && name !== mapFile)

@@ -617,4 +639,38 @@ };

/** Creates the folders needed given a path to a file to be saved*/
const createFileFolder = (filePath) => {
const folderPath = path__default['default'].dirname(filePath);
fs__default['default'].mkdirSync(folderPath, { recursive: true });
};
class TSCache {
constructor(cacheFolder = '.rollup.cache') {
this._cacheFolder = cacheFolder;
}
/** Returns the path to the cached file */
cachedFilename(fileName) {
return path__default['default'].join(this._cacheFolder, fileName.replace(/^([A-Z]+):/, '$1'));
}
/** Emits a file in the cache folder */
cacheCode(fileName, code) {
const cachedPath = this.cachedFilename(fileName);
createFileFolder(cachedPath);
fs__default['default'].writeFileSync(cachedPath, code);
}
/** Checks if a file is in the cache */
isCached(fileName) {
return fs__default['default'].existsSync(this.cachedFilename(fileName));
}
/** Read a file from the cache given the output name*/
getCached(fileName) {
let code;
if (this.isCached(fileName)) {
code = fs__default['default'].readFileSync(this.cachedFilename(fileName), { encoding: 'utf-8' });
}
return code;
}
}
function typescript(options = {}) {
const { filter, tsconfig, compilerOptions, tslib, typescript: ts, transformers } = getPluginOptions(options);
const { cacheDir, compilerOptions, filter, transformers, tsconfig, tslib, typescript: ts } = getPluginOptions(options);
const tsCache = new TSCache(cacheDir);
const emittedFiles = new Map();

@@ -641,2 +697,5 @@ const watchProgramHelper = new WatchProgramHelper();

writeFile(fileName, data) {
if (parsedOptions.options.composite || parsedOptions.options.incremental) {
tsCache.cacheCode(fileName, data);
}
emittedFiles.set(fileName, data);

@@ -679,3 +738,3 @@ },

return null;
return resolved.resolvedFileName;
return path.normalize(resolved.resolvedFileName);
}

@@ -688,3 +747,8 @@ return null;

await watchProgramHelper.wait();
const output = findTypescriptOutput(ts, parsedOptions, id, emittedFiles);
const fileName = normalizePath(id);
if (!parsedOptions.fileNames.includes(fileName)) {
// Discovered new file that was not known when originally parsing the TypeScript config
parsedOptions.fileNames.push(fileName);
}
const output = findTypescriptOutput(ts, parsedOptions, id, emittedFiles, tsCache);
return output.code != null ? output : null;

@@ -694,5 +758,5 @@ },

parsedOptions.fileNames.forEach((fileName) => {
const output = findTypescriptOutput(ts, parsedOptions, fileName, emittedFiles);
const output = findTypescriptOutput(ts, parsedOptions, fileName, emittedFiles, tsCache);
output.declarations.forEach((id) => {
const code = emittedFiles.get(id);
const code = getEmittedFile(id, emittedFiles, tsCache);
if (!code)

@@ -699,0 +763,0 @@ return;

2

package.json
{
"name": "@rollup/plugin-typescript",
"version": "6.1.0",
"version": "8.0.0",
"publishConfig": {

@@ -5,0 +5,0 @@ "access": "public"

@@ -124,10 +124,10 @@ [npm]: https://img.shields.io/npm/v/@rollup/plugin-typescript

- **after**: transformers will execute after the TypeScript transformers on transpiled code
**afterDeclarations**: transformers will execute after declaration file generation allowing to modify existing declaration files
- **afterDeclarations**: transformers will execute after declaration file generation allowing to modify existing declaration files
Supported transformer factories:
- all **build in** TypeScript custom transformer factories:
- all **built-in** TypeScript custom transformer factories:
- `import(‘typescript’).TransformerFactory` annotated **TransformerFactory** bellow
- `import(‘typescript’).CustomTransformerFactory` annotated **CustomTransformerFactory** bellow
- `import('typescript').TransformerFactory` annotated **TransformerFactory** bellow
- `import('typescript').CustomTransformerFactory` annotated **CustomTransformerFactory** bellow

@@ -192,2 +192,17 @@ - **ProgramTransformerFactory** represents a transformer factory allowing the resulting transformer to grab a reference to the **Program** instance

### `cacheDir`
Type: `String`<br>
Default: _.rollup.cache_
When compiling with `incremental` or `composite` options the plugin will
store compiled files in this folder. This allows the use of incremental
compilation.
```js
typescript({
cacheDir: '.rollup.tscache'
});
```
### Typescript compiler options

@@ -194,0 +209,0 @@

import { FilterPattern } from '@rollup/pluginutils';
import { Plugin } from 'rollup';
import { CompilerOptions, CustomTransformers } from 'typescript';
import { CompilerOptions, CustomTransformers, Program, TypeChecker } from 'typescript';
export interface RollupTypescriptPluginOptions {
/**
* If using incremental this is the folder where the cached
* files will be created and kept for Typescript incremental
* compilation.
*/
cacheDir?: string;
/**
* Determine which files are transpiled by Typescript (all `.ts` and

@@ -8,0 +14,0 @@ * `.tsx` files by default).

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc