Socket
Socket
Sign inDemoInstall

@wessberg/rollup-plugin-ts

Package Overview
Dependencies
Maintainers
1
Versions
185
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wessberg/rollup-plugin-ts - npm Package Compare versions

Comparing version 0.0.43 to 0.0.44

3

dist/cjs/helpers.d.ts

@@ -45,2 +45,3 @@ import { InputOptions, OutputOptions } from "rollup";

* @param {string} root
* @param {boolean} useBabel
* @param {Partial<InputOptions>} [_rollupInputOptions]

@@ -50,3 +51,3 @@ * @param {Partial<OutputOptions>} [rollupOutputOptions]

*/
export declare function getForcedCompilerOptions(root: string, _rollupInputOptions?: Partial<InputOptions>, rollupOutputOptions?: Partial<OutputOptions>): Partial<CompilerOptions>;
export declare function getForcedCompilerOptions(root: string, useBabel: boolean, _rollupInputOptions?: Partial<InputOptions>, rollupOutputOptions?: Partial<OutputOptions>): Partial<CompilerOptions>;
/**

@@ -53,0 +54,0 @@ * Prints the given Diagnostic

@@ -112,2 +112,3 @@ "use strict";

* @param {string} root
* @param {boolean} useBabel
* @param {Partial<InputOptions>} [_rollupInputOptions]

@@ -117,5 +118,5 @@ * @param {Partial<OutputOptions>} [rollupOutputOptions]

*/
function getForcedCompilerOptions(root, _rollupInputOptions = {}, rollupOutputOptions = {}) {
function getForcedCompilerOptions(root, useBabel, _rollupInputOptions = {}, rollupOutputOptions = {}) {
const outDir = getDestinationDirectoryFromRollupOutputOptions(root, rollupOutputOptions);
return Object.assign({}, (rollupOutputOptions.format == null ? {} : { module: getModuleKindFromRollupFormat(rollupOutputOptions.format) }), (outDir == null ? {} : { outDir: outDir }), { baseUrl: "." });
return Object.assign({}, (rollupOutputOptions.format == null ? {} : { module: getModuleKindFromRollupFormat(rollupOutputOptions.format) }), (outDir == null ? {} : { outDir: outDir }), (useBabel ? { target: typescript_1.ScriptTarget.ESNext } : {}), { baseUrl: "." });
}

@@ -219,2 +220,3 @@ exports.getForcedCompilerOptions = getForcedCompilerOptions;

exports.getBabelOptions = getBabelOptions;
// And, babel minify will work on the entire thing
/**

@@ -221,0 +223,0 @@ * Returns true if the user has provided babel options to the plugin

@@ -19,4 +19,4 @@ import { SourceMap } from "rollup";

typescriptOptions: ParsedCommandLine;
inputSourceMap: SourceMap;
inputSourceMap?: SourceMap;
browserslist: Browserslist;
}

@@ -66,2 +66,7 @@ "use strict";

const tsFileToRawFileMap = new Map();
/**
* Holds true if babel should be used
* @type {boolean}
*/
const USE_BABEL = browserslist != null;
return {

@@ -73,2 +78,44 @@ name: PLUGIN_NAME,

/**
* Renders a chunk. If Babel transpilation is active, that's what we're gonna use
* @param {string} code
* @param {RenderedChunk} chunk
* @returns {Promise<object | void>}
*/
async renderChunk(code, chunk) {
if (!USE_BABEL)
return;
// Convert the file into a relative path
const relativePath = helpers_1.ensureRelative(root, chunk.fileName);
const relativeWithTsExtension = helpers_1.ensureTs(relativePath);
const mainEntry = helpers_1.isMainEntry(root, chunk.fileName, inputRollupOptions);
const emitResults = await new Promise((resolve, reject) => {
core_1.transform(code, helpers_1.getBabelOptions(Object.assign({ filename: chunk.fileName, relativeFilename: relativeWithTsExtension, typescriptOptions: typescriptOptions, browserslist: browserslist }, babel)), (err, result) => {
if (err != null)
return reject(err);
return resolve([
{
kind: i_typescript_language_service_emit_result_1.TypescriptLanguageServiceEmitResultKind.MAP,
fileName: chunk.fileName,
isMainEntry: mainEntry,
text: result.map
},
{
kind: i_typescript_language_service_emit_result_1.TypescriptLanguageServiceEmitResultKind.SOURCE,
fileName: chunk.fileName,
isMainEntry: mainEntry,
text: result.code
}
]);
});
});
// Find the emit result that references the source code
const sourceResult = emitResults.find(emitResult => emitResult.kind === i_typescript_language_service_emit_result_1.TypescriptLanguageServiceEmitResultKind.SOURCE);
// Find the emit result that references the SourceMap
const mapResult = emitResults.find(emitResult => emitResult.kind === i_typescript_language_service_emit_result_1.TypescriptLanguageServiceEmitResultKind.MAP);
return {
code: sourceResult.text,
map: mapResult.text
};
},
/**
* Invoked when a bundle has been generated

@@ -106,6 +153,6 @@ */

// If declarations should be emitted, make sure to do so
if (typescriptOptions != null && typescriptOptions.options.declaration != null && typescriptOptions.options.declaration) {
if (typescriptOptions.options.declaration != null && typescriptOptions.options.declaration) {
// Temporarily swap the CompilerOptions for the LanguageService
const oldOptions = languageServiceHost.getTypescriptOptions();
const declarationOptions = await helpers_1.resolveTypescriptOptions(root, tsconfig, helpers_1.getForcedCompilerOptions(root, inputRollupOptions, outputOptions));
const declarationOptions = await helpers_1.resolveTypescriptOptions(root, tsconfig, helpers_1.getForcedCompilerOptions(root, USE_BABEL, inputRollupOptions, outputOptions));
languageServiceHost.setTypescriptOptions(declarationOptions);

@@ -139,3 +186,3 @@ // Emit all declaration output files

if (typescriptOptions == null) {
typescriptOptions = await helpers_1.resolveTypescriptOptions(root, tsconfig, helpers_1.getForcedCompilerOptions(root, inputRollupOptions));
typescriptOptions = await helpers_1.resolveTypescriptOptions(root, tsconfig, helpers_1.getForcedCompilerOptions(root, USE_BABEL, inputRollupOptions));
}

@@ -164,41 +211,7 @@ // Assert that the file passes the filter

let emitResults;
// If a browserslist is given, use babel to transform the file, but first pass it through the Typescript LanguageService to strip type-only imports
if (browserslist != null) {
// Temporarily swap the CompilerOptions for the LanguageService
const oldOptions = languageServiceHost.getTypescriptOptions();
languageServiceHost.setTypescriptOptions(Object.assign({}, oldOptions, { options: Object.assign({}, oldOptions.options, { target: typescript_1.ScriptTarget.ESNext }) }));
// Emit all declaration output files
const emittedFiles = languageServiceHost.emit(relativeWithTsExtension);
// Find the emit result that references the source code
const typelessSourceResult = emittedFiles.find(emitResult => emitResult.kind === i_typescript_language_service_emit_result_1.TypescriptLanguageServiceEmitResultKind.SOURCE);
// Find the emit result that references the SourceMap
const typelessMapResult = emittedFiles.find(emitResult => emitResult.kind === i_typescript_language_service_emit_result_1.TypescriptLanguageServiceEmitResultKind.MAP);
// Reset the compilation settings
languageServiceHost.setTypescriptOptions(oldOptions);
emitResults = await new Promise((resolve, reject) => {
core_1.transform(typelessSourceResult == null ? code : typelessSourceResult.text, helpers_1.getBabelOptions(Object.assign({ filename: file, relativeFilename: relativeWithTsExtension, typescriptOptions: typescriptOptions, inputSourceMap: typelessMapResult == null ? undefined : JSON.parse(typelessMapResult.text), browserslist }, babel)), (err, result) => {
if (err != null)
return reject(err);
return resolve([
{
kind: i_typescript_language_service_emit_result_1.TypescriptLanguageServiceEmitResultKind.MAP,
fileName: file,
isMainEntry: mainEntry,
text: result.map
},
{
kind: i_typescript_language_service_emit_result_1.TypescriptLanguageServiceEmitResultKind.SOURCE,
fileName: file,
isMainEntry: mainEntry,
text: result.code
}
]);
});
});
}
// Otherwise, if the file shouldn't emit with Typescript, return undefined
else if (!shouldIncludeForTSEmit) {
if (!shouldIncludeForTSEmit) {
return undefined;
}
// Otherwise, use Typescript directly
// Run it through Typescript
else {

@@ -205,0 +218,0 @@ // Take all emit results for that file

@@ -45,2 +45,3 @@ import { InputOptions, OutputOptions } from "rollup";

* @param {string} root
* @param {boolean} useBabel
* @param {Partial<InputOptions>} [_rollupInputOptions]

@@ -50,3 +51,3 @@ * @param {Partial<OutputOptions>} [rollupOutputOptions]

*/
export declare function getForcedCompilerOptions(root: string, _rollupInputOptions?: Partial<InputOptions>, rollupOutputOptions?: Partial<OutputOptions>): Partial<CompilerOptions>;
export declare function getForcedCompilerOptions(root: string, useBabel: boolean, _rollupInputOptions?: Partial<InputOptions>, rollupOutputOptions?: Partial<OutputOptions>): Partial<CompilerOptions>;
/**

@@ -53,0 +54,0 @@ * Prints the given Diagnostic

import chalk from "chalk";
import { basename, dirname, isAbsolute, join, parse, relative } from "path";
import { DiagnosticCategory, findConfigFile, formatDiagnostic, ModuleKind, parseConfigFileTextToJson, parseJsonConfigFileContent, sys } from "typescript";
import { DiagnosticCategory, findConfigFile, formatDiagnostic, ModuleKind, parseConfigFileTextToJson, parseJsonConfigFileContent, sys, ScriptTarget } from "typescript";
import { DECLARATION_EXTENSION, DEFAULT_DESTINATION, JAVASCRIPT_EXTENSION, JSX_EXTENSION, MJS_EXTENSION, TSX_EXTENSION, TYPESCRIPT_EXTENSION } from "./constants";

@@ -105,2 +105,3 @@ // tslint:disable:no-any

* @param {string} root
* @param {boolean} useBabel
* @param {Partial<InputOptions>} [_rollupInputOptions]

@@ -110,5 +111,5 @@ * @param {Partial<OutputOptions>} [rollupOutputOptions]

*/
export function getForcedCompilerOptions(root, _rollupInputOptions = {}, rollupOutputOptions = {}) {
export function getForcedCompilerOptions(root, useBabel, _rollupInputOptions = {}, rollupOutputOptions = {}) {
const outDir = getDestinationDirectoryFromRollupOutputOptions(root, rollupOutputOptions);
return Object.assign({}, (rollupOutputOptions.format == null ? {} : { module: getModuleKindFromRollupFormat(rollupOutputOptions.format) }), (outDir == null ? {} : { outDir: outDir }), { baseUrl: "." });
return Object.assign({}, (rollupOutputOptions.format == null ? {} : { module: getModuleKindFromRollupFormat(rollupOutputOptions.format) }), (outDir == null ? {} : { outDir: outDir }), (useBabel ? { target: ScriptTarget.ESNext } : {}), { baseUrl: "." });
}

@@ -208,2 +209,3 @@ /**

}
// And, babel minify will work on the entire thing
/**

@@ -210,0 +212,0 @@ * Returns true if the user has provided babel options to the plugin

@@ -19,4 +19,4 @@ import { SourceMap } from "rollup";

typescriptOptions: ParsedCommandLine;
inputSourceMap: SourceMap;
inputSourceMap?: SourceMap;
browserslist: Browserslist;
}

@@ -7,3 +7,3 @@ // tslint:disable:no-any

import { createFilter } from "rollup-pluginutils";
import { nodeModuleNameResolver, ScriptTarget, sys } from "typescript";
import { nodeModuleNameResolver, sys } from "typescript";
import { DECLARATION_EXTENSION } from "./constants";

@@ -65,2 +65,7 @@ import { FormatHost } from "./format-host";

const tsFileToRawFileMap = new Map();
/**
* Holds true if babel should be used
* @type {boolean}
*/
const USE_BABEL = browserslist != null;
return {

@@ -72,2 +77,44 @@ name: PLUGIN_NAME,

/**
* Renders a chunk. If Babel transpilation is active, that's what we're gonna use
* @param {string} code
* @param {RenderedChunk} chunk
* @returns {Promise<object | void>}
*/
async renderChunk(code, chunk) {
if (!USE_BABEL)
return;
// Convert the file into a relative path
const relativePath = ensureRelative(root, chunk.fileName);
const relativeWithTsExtension = ensureTs(relativePath);
const mainEntry = isMainEntry(root, chunk.fileName, inputRollupOptions);
const emitResults = await new Promise((resolve, reject) => {
transform(code, getBabelOptions(Object.assign({ filename: chunk.fileName, relativeFilename: relativeWithTsExtension, typescriptOptions: typescriptOptions, browserslist: browserslist }, babel)), (err, result) => {
if (err != null)
return reject(err);
return resolve([
{
kind: TypescriptLanguageServiceEmitResultKind.MAP,
fileName: chunk.fileName,
isMainEntry: mainEntry,
text: result.map
},
{
kind: TypescriptLanguageServiceEmitResultKind.SOURCE,
fileName: chunk.fileName,
isMainEntry: mainEntry,
text: result.code
}
]);
});
});
// Find the emit result that references the source code
const sourceResult = emitResults.find(emitResult => emitResult.kind === TypescriptLanguageServiceEmitResultKind.SOURCE);
// Find the emit result that references the SourceMap
const mapResult = emitResults.find(emitResult => emitResult.kind === TypescriptLanguageServiceEmitResultKind.MAP);
return {
code: sourceResult.text,
map: mapResult.text
};
},
/**
* Invoked when a bundle has been generated

@@ -105,6 +152,6 @@ */

// If declarations should be emitted, make sure to do so
if (typescriptOptions != null && typescriptOptions.options.declaration != null && typescriptOptions.options.declaration) {
if (typescriptOptions.options.declaration != null && typescriptOptions.options.declaration) {
// Temporarily swap the CompilerOptions for the LanguageService
const oldOptions = languageServiceHost.getTypescriptOptions();
const declarationOptions = await resolveTypescriptOptions(root, tsconfig, getForcedCompilerOptions(root, inputRollupOptions, outputOptions));
const declarationOptions = await resolveTypescriptOptions(root, tsconfig, getForcedCompilerOptions(root, USE_BABEL, inputRollupOptions, outputOptions));
languageServiceHost.setTypescriptOptions(declarationOptions);

@@ -138,3 +185,3 @@ // Emit all declaration output files

if (typescriptOptions == null) {
typescriptOptions = await resolveTypescriptOptions(root, tsconfig, getForcedCompilerOptions(root, inputRollupOptions));
typescriptOptions = await resolveTypescriptOptions(root, tsconfig, getForcedCompilerOptions(root, USE_BABEL, inputRollupOptions));
}

@@ -163,41 +210,7 @@ // Assert that the file passes the filter

let emitResults;
// If a browserslist is given, use babel to transform the file, but first pass it through the Typescript LanguageService to strip type-only imports
if (browserslist != null) {
// Temporarily swap the CompilerOptions for the LanguageService
const oldOptions = languageServiceHost.getTypescriptOptions();
languageServiceHost.setTypescriptOptions(Object.assign({}, oldOptions, { options: Object.assign({}, oldOptions.options, { target: ScriptTarget.ESNext }) }));
// Emit all declaration output files
const emittedFiles = languageServiceHost.emit(relativeWithTsExtension);
// Find the emit result that references the source code
const typelessSourceResult = emittedFiles.find(emitResult => emitResult.kind === TypescriptLanguageServiceEmitResultKind.SOURCE);
// Find the emit result that references the SourceMap
const typelessMapResult = emittedFiles.find(emitResult => emitResult.kind === TypescriptLanguageServiceEmitResultKind.MAP);
// Reset the compilation settings
languageServiceHost.setTypescriptOptions(oldOptions);
emitResults = await new Promise((resolve, reject) => {
transform(typelessSourceResult == null ? code : typelessSourceResult.text, getBabelOptions(Object.assign({ filename: file, relativeFilename: relativeWithTsExtension, typescriptOptions: typescriptOptions, inputSourceMap: typelessMapResult == null ? undefined : JSON.parse(typelessMapResult.text), browserslist }, babel)), (err, result) => {
if (err != null)
return reject(err);
return resolve([
{
kind: TypescriptLanguageServiceEmitResultKind.MAP,
fileName: file,
isMainEntry: mainEntry,
text: result.map
},
{
kind: TypescriptLanguageServiceEmitResultKind.SOURCE,
fileName: file,
isMainEntry: mainEntry,
text: result.code
}
]);
});
});
}
// Otherwise, if the file shouldn't emit with Typescript, return undefined
else if (!shouldIncludeForTSEmit) {
if (!shouldIncludeForTSEmit) {
return undefined;
}
// Otherwise, use Typescript directly
// Run it through Typescript
else {

@@ -204,0 +217,0 @@ // Take all emit results for that file

{
"name": "@wessberg/rollup-plugin-ts",
"version": "0.0.43",
"version": "0.0.44",
"description": "A Rollup plugin for Typescript that respects Browserslists",

@@ -39,3 +39,3 @@ "scripts": {

"conventional-changelog-cli": "^2.0.5",
"husky": "^1.0.1",
"husky": "^1.1.1",
"npm-check-updates": "^2.14.2",

@@ -46,6 +46,6 @@ "tslint": "^5.11.0",

"dependencies": {
"@babel/core": "^7.1.0",
"@babel/core": "^7.1.2",
"@babel/plugin-proposal-async-generator-functions": "^7.1.0",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.2",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",

@@ -55,5 +55,5 @@ "@babel/plugin-proposal-optional-catch-binding": "^7.0.0",

"@babel/preset-env": "^7.1.0",
"@types/node": "^10.11.2",
"@types/node": "^10.11.4",
"chalk": "^2.4.1",
"rollup": "^0.66.2",
"rollup": "^0.66.4",
"rollup-pluginutils": "^2.3.3",

@@ -60,0 +60,0 @@ "tslib": "^1.9.3"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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