Socket
Socket
Sign inDemoInstall

rollup-plugin-dts

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-dts - npm Package Compare versions

Comparing version 2.0.1 to 3.0.0

21

CHANGELOG.md
# Changelog
## 3.0.0
**Compatibility Notice**:
This release targets **TypeScript 4.2**, **Rollup 2.40** and requires **Node 12**.
**Internal**:
- Switch Package to native ES modules, requiring Node 12.
- Modernize internal tooling.
- Circular import warnings are suppressed.
- Use `transform` instead of `load` hook.
**Thank you**:
Features, fixes and improvements in this release have been contributed by:
- [@marijnh](https://github.com/marijnh)
## 2.0.1
** Fixes**:
**Fixes**:

@@ -7,0 +26,0 @@ - When using code-splitting with multiple input files, type references directives will be correctly attached only to the output files that reference them.

428

dist/rollup-plugin-dts.js

@@ -1,15 +0,5 @@

'use strict';
import { resolve, dirname, basename } from 'path';
import ts from 'typescript';
import MagicString from 'magic-string';
Object.defineProperty(exports, '__esModule', { value: true });
var path = require('path');
var ts = require('typescript');
var MagicString = require('magic-string');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
var ts__default = /*#__PURE__*/_interopDefaultLegacy(ts);
var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
function getCodeFrame() {

@@ -20,4 +10,3 @@ try {

}
catch (_a) { }
// istanbul ignore next
catch { }
return undefined;

@@ -38,3 +27,2 @@ }

const code = sourceFile.getFullText();
// istanbul ignore else
const location = getLocation(node);

@@ -75,3 +63,3 @@ if (codeFrame) {

// remove them. Well, we do that hereā€¦
if (ts__default['default'].isEmptyStatement(node)) {
if (ts.isEmptyStatement(node)) {
namespaces.unshift({

@@ -87,5 +75,5 @@ name: "",

// which typescript does not like. So make sure to remove those here.
if ((ts__default['default'].isImportDeclaration(node) || ts__default['default'].isExportDeclaration(node)) &&
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) &&
node.moduleSpecifier &&
ts__default['default'].isStringLiteral(node.moduleSpecifier)) {
ts.isStringLiteral(node.moduleSpecifier)) {
let { text } = node.moduleSpecifier;

@@ -104,6 +92,6 @@ if (text.startsWith(".") && text.endsWith(".d.ts")) {

}
if (ts__default['default'].isClassDeclaration(node)) {
if (ts.isClassDeclaration(node)) {
items[node.name.getText()] = { type: "class", generics: node.typeParameters && node.typeParameters.length };
}
else if (ts__default['default'].isFunctionDeclaration(node)) {
else if (ts.isFunctionDeclaration(node)) {
// a function has generics, but these donā€™t need to be specified explicitly,

@@ -113,3 +101,3 @@ // since functions are treated as values.

}
else if (ts__default['default'].isInterfaceDeclaration(node)) {
else if (ts.isInterfaceDeclaration(node)) {
items[node.name.getText()] = {

@@ -120,12 +108,12 @@ type: "interface",

}
else if (ts__default['default'].isTypeAliasDeclaration(node)) {
else if (ts.isTypeAliasDeclaration(node)) {
items[node.name.getText()] = { type: "type", generics: node.typeParameters && node.typeParameters.length };
}
else if (ts__default['default'].isModuleDeclaration(node) && ts__default['default'].isIdentifier(node.name)) {
else if (ts.isModuleDeclaration(node) && ts.isIdentifier(node.name)) {
items[node.name.getText()] = { type: "namespace" };
}
else if (ts__default['default'].isEnumDeclaration(node)) {
else if (ts.isEnumDeclaration(node)) {
items[node.name.getText()] = { type: "enum" };
}
if (!ts__default['default'].isVariableStatement(node)) {
if (!ts.isVariableStatement(node)) {
continue;

@@ -139,3 +127,3 @@ }

const name = decl.name.getText();
if (!decl.initializer || !ts__default['default'].isCallExpression(decl.initializer)) {
if (!decl.initializer || !ts.isCallExpression(decl.initializer)) {
items[name] = { type: "var" };

@@ -146,3 +134,3 @@ continue;

if (!decl.initializer.expression.getFullText().includes("/*#__PURE__*/Object.freeze") ||
!ts__default['default'].isObjectLiteralExpression(obj)) {
!ts.isObjectLiteralExpression(obj)) {
continue;

@@ -152,5 +140,5 @@ }

for (const prop of obj.properties) {
if (!ts__default['default'].isPropertyAssignment(prop) ||
!ts__default['default'].isIdentifier(prop.name) ||
(prop.name.text !== "__proto__" && !ts__default['default'].isIdentifier(prop.initializer))) {
if (!ts.isPropertyAssignment(prop) ||
!ts.isIdentifier(prop.name) ||
(prop.name.text !== "__proto__" && !ts.isIdentifier(prop.initializer))) {
throw new UnsupportedSyntaxError(prop, "Expected a property assignment");

@@ -231,3 +219,3 @@ }

*/
function createProgram(node) {
function createProgram$1(node) {
return withStartEnd({

@@ -290,3 +278,3 @@ type: "Program",

type: "Identifier",
name: ts__default['default'].idText(id),
name: ts.idText(id),
}, id),

@@ -298,7 +286,7 @@ params: [],

function convertExpression(node) {
if (ts__default['default'].isLiteralExpression(node)) {
if (ts.isLiteralExpression(node)) {
return { type: "Literal", value: node.text };
}
if (ts__default['default'].isPropertyAccessExpression(node)) {
if (ts__default['default'].isPrivateIdentifier(node.name)) {
if (ts.isPropertyAccessExpression(node)) {
if (ts.isPrivateIdentifier(node.name)) {
throw new UnsupportedSyntaxError(node.name);

@@ -317,4 +305,3 @@ }

}
// istanbul ignore else
if (ts__default['default'].isIdentifier(node)) {
if (ts.isIdentifier(node)) {
return createIdentifier(node);

@@ -331,3 +318,3 @@ }

function matchesModifier(node, flags) {
const nodeFlags = ts__default['default'].getCombinedModifierFlags(node);
const nodeFlags = ts.getCombinedModifierFlags(node);
return (nodeFlags & flags) === flags;

@@ -350,3 +337,3 @@ }

function preProcess({ sourceFile }) {
const code = new MagicString__default['default'](sourceFile.getFullText());
const code = new MagicString(sourceFile.getFullText());
/** All the names that are declared in the `SourceFile`. */

@@ -373,12 +360,12 @@ const declaredNames = new Set();

for (const node of sourceFile.statements) {
if (ts__default['default'].isEmptyStatement(node)) {
if (ts.isEmptyStatement(node)) {
code.remove(node.getStart(), node.getEnd());
continue;
}
if (ts__default['default'].isEnumDeclaration(node) ||
ts__default['default'].isFunctionDeclaration(node) ||
ts__default['default'].isInterfaceDeclaration(node) ||
ts__default['default'].isClassDeclaration(node) ||
ts__default['default'].isTypeAliasDeclaration(node) ||
ts__default['default'].isModuleDeclaration(node)) {
if (ts.isEnumDeclaration(node) ||
ts.isFunctionDeclaration(node) ||
ts.isInterfaceDeclaration(node) ||
ts.isClassDeclaration(node) ||
ts.isTypeAliasDeclaration(node) ||
ts.isModuleDeclaration(node)) {
// collect the declared name

@@ -389,9 +376,9 @@ if (node.name) {

// collect the exported name, maybe as `default`.
if (matchesModifier(node, ts__default['default'].ModifierFlags.ExportDefault)) {
if (matchesModifier(node, ts.ModifierFlags.ExportDefault)) {
defaultExport = name;
}
else if (matchesModifier(node, ts__default['default'].ModifierFlags.Export)) {
else if (matchesModifier(node, ts.ModifierFlags.Export)) {
exportedNames.add(name);
}
if (!(node.flags & ts__default['default'].NodeFlags.GlobalAugmentation)) {
if (!(node.flags & ts.NodeFlags.GlobalAugmentation)) {
pushNamedNode(name, [getStart(node), getEnd(node)]);

@@ -402,8 +389,8 @@ }

}
else if (ts__default['default'].isVariableStatement(node)) {
else if (ts.isVariableStatement(node)) {
const { declarations } = node.declarationList;
// collect all the names, also check if they are exported
const isExport = matchesModifier(node, ts__default['default'].ModifierFlags.Export);
const isExport = matchesModifier(node, ts.ModifierFlags.Export);
for (const decl of node.declarationList.declarations) {
if (ts__default['default'].isIdentifier(decl.name)) {
if (ts.isIdentifier(decl.name)) {
const name = decl.name.getText();

@@ -420,3 +407,3 @@ declaredNames.add(name);

const decl = declarations[0];
if (ts__default['default'].isIdentifier(decl.name)) {
if (ts.isIdentifier(decl.name)) {
pushNamedNode(decl.name.getText(), [getStart(node), getEnd(node)]);

@@ -431,3 +418,3 @@ }

for (const decl of decls) {
if (ts__default['default'].isIdentifier(decl.name)) {
if (ts.isIdentifier(decl.name)) {
pushNamedNode(decl.name.getText(), [decl.getFullStart(), decl.getEnd()]);

@@ -439,11 +426,11 @@ }

const { flags } = node.declarationList;
const type = flags & ts__default['default'].NodeFlags.Let ? "let" : flags & ts__default['default'].NodeFlags.Const ? "const" : "var";
const type = flags & ts.NodeFlags.Let ? "let" : flags & ts.NodeFlags.Const ? "const" : "var";
const prefix = `declare ${type} `;
const list = node.declarationList
.getChildren()
.find((c) => c.kind === ts__default['default'].SyntaxKind.SyntaxList)
.find((c) => c.kind === ts.SyntaxKind.SyntaxList)
.getChildren();
let commaPos = 0;
for (const node of list) {
if (node.kind === ts__default['default'].SyntaxKind.CommaToken) {
if (node.kind === ts.SyntaxKind.CommaToken) {
commaPos = node.getStart();

@@ -479,7 +466,7 @@ code.remove(commaPos, node.getEnd());

checkInlineImport(node);
if (!matchesModifier(node, ts__default['default'].ModifierFlags.ExportDefault)) {
if (!matchesModifier(node, ts.ModifierFlags.ExportDefault)) {
continue;
}
// only function and class can be default exported, and be missing a name
if (ts__default['default'].isFunctionDeclaration(node) || ts__default['default'].isClassDeclaration(node)) {
if (ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) {
if (node.name) {

@@ -492,6 +479,6 @@ continue;

const children = node.getChildren();
const idx = children.findIndex((node) => node.kind === ts__default['default'].SyntaxKind.ClassKeyword || node.kind === ts__default['default'].SyntaxKind.FunctionKeyword);
const idx = children.findIndex((node) => node.kind === ts.SyntaxKind.ClassKeyword || node.kind === ts.SyntaxKind.FunctionKeyword);
const token = children[idx];
const nextToken = children[idx + 1];
const isPunctuation = nextToken.kind >= ts__default['default'].SyntaxKind.FirstPunctuation && nextToken.kind <= ts__default['default'].SyntaxKind.LastPunctuation;
const isPunctuation = nextToken.kind >= ts.SyntaxKind.FirstPunctuation && nextToken.kind <= ts.SyntaxKind.LastPunctuation;
if (isPunctuation) {

@@ -544,5 +531,5 @@ code.appendLeft(nextToken.getStart(), defaultExport);

function checkInlineImport(node) {
ts__default['default'].forEachChild(node, checkInlineImport);
if (ts__default['default'].isImportTypeNode(node)) {
if (!ts__default['default'].isLiteralTypeNode(node.argument) || !ts__default['default'].isStringLiteral(node.argument.literal)) {
ts.forEachChild(node, checkInlineImport);
if (ts.isImportTypeNode(node)) {
if (!ts.isLiteralTypeNode(node.argument) || !ts.isStringLiteral(node.argument.literal)) {
throw new UnsupportedSyntaxError(node, "inline imports should have a literal argument");

@@ -552,5 +539,5 @@ }

const children = node.getChildren();
const start = children.find((t) => t.kind === ts__default['default'].SyntaxKind.ImportKeyword).getStart();
const start = children.find((t) => t.kind === ts.SyntaxKind.ImportKeyword).getStart();
let end = node.getEnd();
const token = children.find((t) => t.kind === ts__default['default'].SyntaxKind.DotToken || t.kind === ts__default['default'].SyntaxKind.LessThanToken);
const token = children.find((t) => t.kind === ts.SyntaxKind.DotToken || t.kind === ts.SyntaxKind.LessThanToken);
if (token) {

@@ -600,14 +587,14 @@ end = token.getStart();

let hasDeclare = false;
const needsDeclare = ts__default['default'].isClassDeclaration(node) ||
ts__default['default'].isFunctionDeclaration(node) ||
ts__default['default'].isModuleDeclaration(node) ||
ts__default['default'].isVariableStatement(node);
const needsDeclare = ts.isClassDeclaration(node) ||
ts.isFunctionDeclaration(node) ||
ts.isModuleDeclaration(node) ||
ts.isVariableStatement(node);
for (const mod of (_a = node.modifiers) !== null && _a !== void 0 ? _a : []) {
switch (mod.kind) {
case ts__default['default'].SyntaxKind.ExportKeyword: // fall through
case ts__default['default'].SyntaxKind.DefaultKeyword:
case ts.SyntaxKind.ExportKeyword: // fall through
case ts.SyntaxKind.DefaultKeyword:
// TODO: be careful about that `+ 1`
code.remove(mod.getStart(), mod.getEnd() + 1);
break;
case ts__default['default'].SyntaxKind.DeclareKeyword:
case ts.SyntaxKind.DeclareKeyword:
hasDeclare = true;

@@ -634,5 +621,5 @@ }

const formatHost = {
getCurrentDirectory: () => ts__default['default'].sys.getCurrentDirectory(),
getNewLine: () => ts__default['default'].sys.newLine,
getCanonicalFileName: ts__default['default'].sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase(),
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
getNewLine: () => ts.sys.newLine,
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase(),
};

@@ -654,22 +641,22 @@ const OPTIONS_OVERRIDE = {

// Ensure we can parse the latest code
target: ts__default['default'].ScriptTarget.ESNext,
target: ts.ScriptTarget.ESNext,
};
function getCompilerOptions(input, overrideOptions) {
const compilerOptions = Object.assign(Object.assign({}, overrideOptions), OPTIONS_OVERRIDE);
let dirName = path.dirname(input);
const compilerOptions = { ...overrideOptions, ...OPTIONS_OVERRIDE };
let dirName = dirname(input);
let dtsFiles = [];
const configPath = ts__default['default'].findConfigFile(path.dirname(input), ts__default['default'].sys.fileExists);
const configPath = ts.findConfigFile(dirName, ts.sys.fileExists);
if (!configPath) {
return { dtsFiles, dirName, compilerOptions };
}
dirName = path.dirname(configPath);
const { config, error } = ts__default['default'].readConfigFile(configPath, ts__default['default'].sys.readFile);
dirName = dirname(configPath);
const { config, error } = ts.readConfigFile(configPath, ts.sys.readFile);
if (error) {
console.error(ts__default['default'].formatDiagnostic(error, formatHost));
console.error(ts.formatDiagnostic(error, formatHost));
return { dtsFiles, dirName, compilerOptions };
}
const { fileNames, options, errors } = ts__default['default'].parseJsonConfigFileContent(config, ts__default['default'].sys, dirName);
const { fileNames, options, errors } = ts.parseJsonConfigFileContent(config, ts.sys, dirName);
dtsFiles = fileNames.filter((name) => name.endsWith(dts));
if (errors.length) {
console.error(ts__default['default'].formatDiagnostics(errors, formatHost));
console.error(ts.formatDiagnostics(errors, formatHost));
return { dtsFiles, dirName, compilerOptions };

@@ -680,8 +667,11 @@ }

dirName,
compilerOptions: Object.assign(Object.assign({}, options), compilerOptions),
compilerOptions: {
...options,
...compilerOptions,
},
};
}
function createProgram$1(fileName, overrideOptions) {
function createProgram(fileName, overrideOptions) {
const { dtsFiles, compilerOptions } = getCompilerOptions(fileName, overrideOptions);
return ts__default['default'].createProgram([fileName].concat(Array.from(dtsFiles)), compilerOptions, ts__default['default'].createCompilerHost(compilerOptions, true));
return ts.createProgram([fileName].concat(Array.from(dtsFiles)), compilerOptions, ts.createCompilerHost(compilerOptions, true));
}

@@ -698,3 +688,3 @@ function createPrograms(input, overrideOptions) {

}
main = path.resolve(main);
main = resolve(main);
const options = getCompilerOptions(main, overrideOptions);

@@ -711,4 +701,4 @@ options.dtsFiles.forEach(dtsFiles.add, dtsFiles);

else {
const host = ts__default['default'].createCompilerHost(compilerOptions, true);
const program = ts__default['default'].createProgram(inputs.concat(Array.from(dtsFiles)), compilerOptions, host);
const host = ts.createCompilerHost(compilerOptions, true);
const program = ts.createProgram(inputs.concat(Array.from(dtsFiles)), compilerOptions, host);
programs.push(program);

@@ -720,4 +710,4 @@ inputs = [main];

if (inputs.length) {
const host = ts__default['default'].createCompilerHost(compilerOptions, true);
const program = ts__default['default'].createProgram(inputs.concat(Array.from(dtsFiles)), compilerOptions, host);
const host = ts.createCompilerHost(compilerOptions, true);
const program = ts.createProgram(inputs.concat(Array.from(dtsFiles)), compilerOptions, host);
programs.push(program);

@@ -729,17 +719,17 @@ }

const IGNORE_TYPENODES = new Set([
ts__default['default'].SyntaxKind.LiteralType,
ts__default['default'].SyntaxKind.VoidKeyword,
ts__default['default'].SyntaxKind.UnknownKeyword,
ts__default['default'].SyntaxKind.AnyKeyword,
ts__default['default'].SyntaxKind.BooleanKeyword,
ts__default['default'].SyntaxKind.NumberKeyword,
ts__default['default'].SyntaxKind.StringKeyword,
ts__default['default'].SyntaxKind.ObjectKeyword,
ts__default['default'].SyntaxKind.NullKeyword,
ts__default['default'].SyntaxKind.UndefinedKeyword,
ts__default['default'].SyntaxKind.SymbolKeyword,
ts__default['default'].SyntaxKind.NeverKeyword,
ts__default['default'].SyntaxKind.ThisKeyword,
ts__default['default'].SyntaxKind.ThisType,
ts__default['default'].SyntaxKind.BigIntKeyword,
ts.SyntaxKind.LiteralType,
ts.SyntaxKind.VoidKeyword,
ts.SyntaxKind.UnknownKeyword,
ts.SyntaxKind.AnyKeyword,
ts.SyntaxKind.BooleanKeyword,
ts.SyntaxKind.NumberKeyword,
ts.SyntaxKind.StringKeyword,
ts.SyntaxKind.ObjectKeyword,
ts.SyntaxKind.NullKeyword,
ts.SyntaxKind.UndefinedKeyword,
ts.SyntaxKind.SymbolKeyword,
ts.SyntaxKind.NeverKeyword,
ts.SyntaxKind.ThisKeyword,
ts.SyntaxKind.ThisType,
ts.SyntaxKind.BigIntKeyword,
]);

@@ -806,3 +796,3 @@ class DeclarationScope {

convertEntityName(node) {
if (ts__default['default'].isIdentifier(node)) {
if (ts.isIdentifier(node)) {
return createIdentifier(node);

@@ -820,9 +810,9 @@ }

// hm, we only care about property access expressions hereā€¦
if (!ts__default['default'].isIdentifier(node.expression) && !ts__default['default'].isPropertyAccessExpression(node.expression)) {
if (!ts.isIdentifier(node.expression) && !ts.isPropertyAccessExpression(node.expression)) {
throw new UnsupportedSyntaxError(node.expression);
}
if (ts__default['default'].isPrivateIdentifier(node.name)) {
if (ts.isPrivateIdentifier(node.name)) {
throw new UnsupportedSyntaxError(node.name);
}
let object = ts__default['default'].isIdentifier(node.expression)
let object = ts.isIdentifier(node.expression)
? createIdentifier(node.expression)

@@ -839,13 +829,13 @@ : this.convertPropertyAccess(node.expression);

convertComputedPropertyName(node) {
if (!node.name || !ts__default['default'].isComputedPropertyName(node.name)) {
if (!node.name || !ts.isComputedPropertyName(node.name)) {
return;
}
const { expression } = node.name;
if (ts__default['default'].isLiteralExpression(expression)) {
if (ts.isLiteralExpression(expression)) {
return;
}
if (ts__default['default'].isIdentifier(expression)) {
if (ts.isIdentifier(expression)) {
return this.pushReference(createIdentifier(expression));
}
if (ts__default['default'].isPropertyAccessExpression(expression)) {
if (ts.isPropertyAccessExpression(expression)) {
return this.pushReference(this.convertPropertyAccess(expression));

@@ -882,3 +872,3 @@ }

for (const node of members) {
if (ts__default['default'].isPropertyDeclaration(node) || ts__default['default'].isPropertySignature(node) || ts__default['default'].isIndexSignatureDeclaration(node)) {
if (ts.isPropertyDeclaration(node) || ts.isPropertySignature(node) || ts.isIndexSignatureDeclaration(node)) {
this.convertComputedPropertyName(node);

@@ -888,10 +878,9 @@ this.convertTypeNode(node.type);

}
// istanbul ignore else
if (ts__default['default'].isMethodDeclaration(node) ||
ts__default['default'].isMethodSignature(node) ||
ts__default['default'].isConstructorDeclaration(node) ||
ts__default['default'].isConstructSignatureDeclaration(node) ||
ts__default['default'].isCallSignatureDeclaration(node) ||
ts__default['default'].isGetAccessorDeclaration(node) ||
ts__default['default'].isSetAccessorDeclaration(node)) {
if (ts.isMethodDeclaration(node) ||
ts.isMethodSignature(node) ||
ts.isConstructorDeclaration(node) ||
ts.isConstructSignatureDeclaration(node) ||
ts.isCallSignatureDeclaration(node) ||
ts.isGetAccessorDeclaration(node) ||
ts.isSetAccessorDeclaration(node)) {
this.convertParametersAndType(node);

@@ -923,3 +912,3 @@ }

}
if (ts__default['default'].isTypeReferenceNode(node)) {
if (ts.isTypeReferenceNode(node)) {
this.pushReference(this.convertEntityName(node.typeName));

@@ -929,9 +918,9 @@ this.convertTypeArguments(node);

}
if (ts__default['default'].isTypeLiteralNode(node)) {
if (ts.isTypeLiteralNode(node)) {
return this.convertMembers(node.members);
}
if (ts__default['default'].isArrayTypeNode(node)) {
if (ts.isArrayTypeNode(node)) {
return this.convertTypeNode(node.elementType);
}
if (ts__default['default'].isTupleTypeNode(node)) {
if (ts.isTupleTypeNode(node)) {
for (const type of node.elements) {

@@ -942,9 +931,9 @@ this.convertTypeNode(type);

}
if (ts__default['default'].isNamedTupleMember(node) ||
ts__default['default'].isParenthesizedTypeNode(node) ||
ts__default['default'].isTypeOperatorNode(node) ||
ts__default['default'].isTypePredicateNode(node)) {
if (ts.isNamedTupleMember(node) ||
ts.isParenthesizedTypeNode(node) ||
ts.isTypeOperatorNode(node) ||
ts.isTypePredicateNode(node)) {
return this.convertTypeNode(node.type);
}
if (ts__default['default'].isUnionTypeNode(node) || ts__default['default'].isIntersectionTypeNode(node)) {
if (ts.isUnionTypeNode(node) || ts.isIntersectionTypeNode(node)) {
for (const type of node.types) {

@@ -955,3 +944,3 @@ this.convertTypeNode(type);

}
if (ts__default['default'].isMappedTypeNode(node)) {
if (ts.isMappedTypeNode(node)) {
const { typeParameter, type, nameType } = node;

@@ -968,3 +957,3 @@ this.convertTypeNode(typeParameter.constraint);

}
if (ts__default['default'].isConditionalTypeNode(node)) {
if (ts.isConditionalTypeNode(node)) {
this.convertTypeNode(node.checkType);

@@ -978,3 +967,3 @@ this.pushScope();

}
if (ts__default['default'].isIndexedAccessTypeNode(node)) {
if (ts.isIndexedAccessTypeNode(node)) {
this.convertTypeNode(node.objectType);

@@ -984,19 +973,19 @@ this.convertTypeNode(node.indexType);

}
if (ts__default['default'].isFunctionOrConstructorTypeNode(node)) {
if (ts.isFunctionOrConstructorTypeNode(node)) {
this.convertParametersAndType(node);
return;
}
if (ts__default['default'].isTypeQueryNode(node)) {
if (ts.isTypeQueryNode(node)) {
this.pushReference(this.convertEntityName(node.exprName));
return;
}
if (ts__default['default'].isRestTypeNode(node)) {
if (ts.isRestTypeNode(node)) {
this.convertTypeNode(node.type);
return;
}
if (ts__default['default'].isOptionalTypeNode(node)) {
if (ts.isOptionalTypeNode(node)) {
this.convertTypeNode(node.type);
return;
}
if (ts__default['default'].isTemplateLiteralTypeNode(node)) {
if (ts.isTemplateLiteralTypeNode(node)) {
for (const span of node.templateSpans) {

@@ -1007,4 +996,3 @@ this.convertTypeNode(span.type);

}
// istanbul ignore else
if (ts__default['default'].isInferTypeNode(node)) {
if (ts.isInferTypeNode(node)) {
this.pushTypeVariable(node.typeParameter.name);

@@ -1019,4 +1007,3 @@ return;

this.pushScope();
// istanbul ignore if
if (!node.body || !ts__default['default'].isModuleBlock(node.body)) {
if (!node.body || !ts.isModuleBlock(node.body)) {
throw new UnsupportedSyntaxError(node, `namespace must have a "ModuleBlock" body.`);

@@ -1027,10 +1014,9 @@ }

for (const stmt of statements) {
if (ts__default['default'].isEnumDeclaration(stmt) ||
ts__default['default'].isFunctionDeclaration(stmt) ||
ts__default['default'].isClassDeclaration(stmt) ||
ts__default['default'].isInterfaceDeclaration(stmt) ||
ts__default['default'].isTypeAliasDeclaration(stmt) ||
ts__default['default'].isModuleDeclaration(stmt)) {
// istanbul ignore else
if (stmt.name && ts__default['default'].isIdentifier(stmt.name)) {
if (ts.isEnumDeclaration(stmt) ||
ts.isFunctionDeclaration(stmt) ||
ts.isClassDeclaration(stmt) ||
ts.isInterfaceDeclaration(stmt) ||
ts.isTypeAliasDeclaration(stmt) ||
ts.isModuleDeclaration(stmt)) {
if (stmt.name && ts.isIdentifier(stmt.name)) {
this.pushTypeVariable(stmt.name);

@@ -1043,6 +1029,5 @@ }

}
if (ts__default['default'].isVariableStatement(stmt)) {
if (ts.isVariableStatement(stmt)) {
for (const decl of stmt.declarationList.declarations) {
// istanbul ignore else
if (ts__default['default'].isIdentifier(decl.name)) {
if (ts.isIdentifier(decl.name)) {
this.pushTypeVariable(decl.name);

@@ -1056,4 +1041,3 @@ }

}
// istanbul ignore else
if (ts__default['default'].isExportDeclaration(stmt)) ;
if (ts.isExportDeclaration(stmt)) ;
else {

@@ -1065,3 +1049,3 @@ throw new UnsupportedSyntaxError(stmt, `namespace child (hoisting) not supported yet`);

for (const stmt of statements) {
if (ts__default['default'].isVariableStatement(stmt)) {
if (ts.isVariableStatement(stmt)) {
for (const decl of stmt.declarationList.declarations) {

@@ -1074,7 +1058,7 @@ if (decl.type) {

}
if (ts__default['default'].isFunctionDeclaration(stmt)) {
if (ts.isFunctionDeclaration(stmt)) {
this.convertParametersAndType(stmt);
continue;
}
if (ts__default['default'].isInterfaceDeclaration(stmt) || ts__default['default'].isClassDeclaration(stmt)) {
if (ts.isInterfaceDeclaration(stmt) || ts.isClassDeclaration(stmt)) {
const typeVariables = this.convertTypeParameters(stmt.typeParameters);

@@ -1086,3 +1070,3 @@ this.convertHeritageClauses(stmt);

}
if (ts__default['default'].isTypeAliasDeclaration(stmt)) {
if (ts.isTypeAliasDeclaration(stmt)) {
const typeVariables = this.convertTypeParameters(stmt.typeParameters);

@@ -1093,14 +1077,13 @@ this.convertTypeNode(stmt.type);

}
if (ts__default['default'].isModuleDeclaration(stmt)) {
if (ts.isModuleDeclaration(stmt)) {
this.convertNamespace(stmt);
continue;
}
if (ts__default['default'].isEnumDeclaration(stmt)) {
if (ts.isEnumDeclaration(stmt)) {
// noop
continue;
}
// istanbul ignore else
if (ts__default['default'].isExportDeclaration(stmt)) {
if (ts.isExportDeclaration(stmt)) {
if (stmt.exportClause) {
if (ts__default['default'].isNamespaceExport(stmt.exportClause)) {
if (ts.isNamespaceExport(stmt.exportClause)) {
throw new UnsupportedSyntaxError(stmt.exportClause);

@@ -1128,3 +1111,3 @@ }

this.exports = new Set();
this.ast = createProgram(sourceFile);
this.ast = createProgram$1(sourceFile);
for (const stmt of sourceFile.statements) {

@@ -1174,29 +1157,28 @@ this.convertStatement(stmt);

convertStatement(node) {
if (ts__default['default'].isEnumDeclaration(node)) {
if (ts.isEnumDeclaration(node)) {
return this.convertEnumDeclaration(node);
}
if (ts__default['default'].isFunctionDeclaration(node)) {
if (ts.isFunctionDeclaration(node)) {
return this.convertFunctionDeclaration(node);
}
if (ts__default['default'].isInterfaceDeclaration(node) || ts__default['default'].isClassDeclaration(node)) {
if (ts.isInterfaceDeclaration(node) || ts.isClassDeclaration(node)) {
return this.convertClassOrInterfaceDeclaration(node);
}
if (ts__default['default'].isTypeAliasDeclaration(node)) {
if (ts.isTypeAliasDeclaration(node)) {
return this.convertTypeAliasDeclaration(node);
}
if (ts__default['default'].isVariableStatement(node)) {
if (ts.isVariableStatement(node)) {
return this.convertVariableStatement(node);
}
if (ts__default['default'].isExportDeclaration(node) || ts__default['default'].isExportAssignment(node)) {
if (ts.isExportDeclaration(node) || ts.isExportAssignment(node)) {
return this.convertExportDeclaration(node);
}
if (ts__default['default'].isModuleDeclaration(node)) {
if (ts.isModuleDeclaration(node)) {
return this.convertNamespaceDeclaration(node);
}
if (node.kind == ts__default['default'].SyntaxKind.NamespaceExportDeclaration) {
if (node.kind == ts.SyntaxKind.NamespaceExportDeclaration) {
// just ignore `export as namespace FOO` statementsā€¦
return this.removeStatement(node);
}
// istanbul ignore else
if (ts__default['default'].isImportDeclaration(node) || ts__default['default'].isImportEqualsDeclaration(node)) {
if (ts.isImportDeclaration(node) || ts.isImportEqualsDeclaration(node)) {
return this.convertImportDeclaration(node);

@@ -1219,4 +1201,4 @@ }

// the right thing and not rename theseā€¦
const isGlobalAugmentation = node.flags & ts__default['default'].NodeFlags.GlobalAugmentation;
if (isGlobalAugmentation || !ts__default['default'].isIdentifier(node.name)) {
const isGlobalAugmentation = node.flags & ts.NodeFlags.GlobalAugmentation;
if (isGlobalAugmentation || !ts.isIdentifier(node.name)) {
const scope = this.createDeclaration(node);

@@ -1235,3 +1217,2 @@ scope.convertNamespace(node);

convertFunctionDeclaration(node) {
// istanbul ignore if
if (!node.name) {

@@ -1245,3 +1226,2 @@ throw new UnsupportedSyntaxError(node, `FunctionDeclaration should have a name`);

convertClassOrInterfaceDeclaration(node) {
// istanbul ignore if
if (!node.name) {

@@ -1264,3 +1244,2 @@ throw new UnsupportedSyntaxError(node, `ClassDeclaration / InterfaceDeclaration should have a name`);

const { declarations } = node.declarationList;
// istanbul ignore if
if (declarations.length !== 1) {

@@ -1270,4 +1249,3 @@ throw new UnsupportedSyntaxError(node, `VariableStatement with more than one declaration not yet supported`);

for (const decl of declarations) {
// istanbul ignore if
if (!ts__default['default'].isIdentifier(decl.name)) {
if (!ts.isIdentifier(decl.name)) {
throw new UnsupportedSyntaxError(node, `VariableDeclaration must have a name`);

@@ -1280,3 +1258,3 @@ }

convertExportDeclaration(node) {
if (ts__default['default'].isExportAssignment(node)) {
if (ts.isExportAssignment(node)) {
this.pushStatement(withStartEnd({

@@ -1297,3 +1275,3 @@ type: "ExportDefaultDeclaration",

}
else if (ts__default['default'].isNamespaceExport(node.exportClause)) {
else if (ts.isNamespaceExport(node.exportClause)) {
// export * as name from './other'

@@ -1321,5 +1299,5 @@ this.pushStatement(withStartEnd({

convertImportDeclaration(node) {
if (ts__default['default'].isImportEqualsDeclaration(node)) {
if (ts.isImportEqualsDeclaration(node)) {
// assume its like `import default`
if (!ts__default['default'].isExternalModuleReference(node.moduleReference)) {
if (!ts.isExternalModuleReference(node.moduleReference)) {
throw new UnsupportedSyntaxError(node, "ImportEquals should have a literal source.");

@@ -1356,3 +1334,3 @@ }

convertNamedImportBindings(node) {
if (ts__default['default'].isNamedImports(node)) {
if (ts.isNamedImports(node)) {
return node.elements.map((el) => {

@@ -1391,3 +1369,3 @@ const local = createIdentifier(el.name);

let programs = [];
function getModule(fileName) {
function getModule(fileName, code) {
let source;

@@ -1398,5 +1376,3 @@ let program;

if (!programs.length && fileName.endsWith(dts)) {
const code = ts__default['default'].sys.readFile(fileName, "utf8");
if (code)
source = ts__default['default'].createSourceFile(fileName, code, ts__default['default'].ScriptTarget.Latest, true);
source = ts.createSourceFile(fileName, code, ts.ScriptTarget.Latest, true);
}

@@ -1407,4 +1383,4 @@ else {

program = programs.find((p) => (source = p.getSourceFile(fileName)));
if (!program && ts__default['default'].sys.fileExists(fileName)) {
programs.push((program = createProgram$1(fileName, compilerOptions)));
if (!program && ts.sys.fileExists(fileName)) {
programs.push((program = createProgram(fileName, compilerOptions)));
source = program.getSourceFile(fileName);

@@ -1420,3 +1396,3 @@ }

const code = preprocessed.code.toString();
input = ts__default['default'].createSourceFile(input.fileName, code, ts__default['default'].ScriptTarget.Latest, true);
input = ts.createSourceFile(input.fileName, code, ts.ScriptTarget.Latest, true);
const transformer = new Transformer(input);

@@ -1435,3 +1411,3 @@ const output = transformer.transform();

options(options) {
let { input = [] } = options;
let { input = [], onwarn } = options;
if (!Array.isArray(input)) {

@@ -1445,3 +1421,3 @@ input = typeof input === "string" ? [input] : Object.values(input);

for (const filename of input) {
const name = path__default['default'].basename(filename).replace(/((\.d)?\.(t|j)sx?)$/, "");
const name = basename(filename).replace(/((\.d)?\.(t|j)sx?)$/, "");
options.input[name] = filename;

@@ -1451,12 +1427,34 @@ }

programs = createPrograms(Object.values(input), compilerOptions);
return Object.assign(Object.assign({}, options), { treeshake: {
return {
...options,
onwarn(warning, warn) {
if (warning.code != "CIRCULAR_DEPENDENCY") {
if (onwarn)
onwarn(warning, warn);
else
warn(warning);
}
},
treeshake: {
moduleSideEffects: "no-external",
propertyReadSideEffects: true,
unknownGlobalSideEffects: false,
} });
},
};
},
outputOptions(options) {
return Object.assign(Object.assign({}, options), { chunkFileNames: options.chunkFileNames || "[name]-[hash]" + dts, entryFileNames: options.entryFileNames || "[name]" + dts, format: "es", exports: "named", compact: false, freeze: true, interop: false, namespaceToStringTag: false, strict: false });
return {
...options,
chunkFileNames: options.chunkFileNames || "[name]-[hash]" + dts,
entryFileNames: options.entryFileNames || "[name]" + dts,
format: "es",
exports: "named",
compact: false,
freeze: true,
interop: false,
namespaceToStringTag: false,
strict: false,
};
},
load(id) {
transform(code, id) {
if (!tsx.test(id)) {

@@ -1466,3 +1464,3 @@ return null;

if (id.endsWith(dts)) {
const { source } = getModule(id);
const { source } = getModule(id, code);
return source ? transformFile(source) : null;

@@ -1472,3 +1470,3 @@ }

const declarationId = id.replace(tsx, dts);
let module = getModule(declarationId);
let module = getModule(declarationId, code);
if (module.source) {

@@ -1478,3 +1476,3 @@ return transformFile(module.source);

// Generate in-memory ".d.ts" modules from ".tsx?" modules!
module = getModule(id);
module = getModule(id, code);
if (!module.source || !module.program) {

@@ -1485,3 +1483,3 @@ return null;

const { emitSkipped, diagnostics } = module.program.emit(module.source, (_, declarationText) => {
const source = ts__default['default'].createSourceFile(declarationId, declarationText, ts__default['default'].ScriptTarget.Latest, true);
const source = ts.createSourceFile(declarationId, declarationText, ts.ScriptTarget.Latest, true);
generated = transformFile(source);

@@ -1491,5 +1489,5 @@ }, undefined, // cancellationToken

if (emitSkipped) {
const errors = diagnostics.filter((diag) => diag.category === ts__default['default'].DiagnosticCategory.Error);
const errors = diagnostics.filter((diag) => diag.category === ts.DiagnosticCategory.Error);
if (errors.length) {
console.error(ts__default['default'].formatDiagnostics(errors, formatHost));
console.error(ts.formatDiagnostics(errors, formatHost));
this.error("Failed to compile. Check the logs above.");

@@ -1507,3 +1505,3 @@ }

// resolve this via typescript
const { resolvedModule } = ts__default['default'].nodeModuleNameResolver(source, importer, compilerOptions, ts__default['default'].sys);
const { resolvedModule } = ts.nodeModuleNameResolver(source, importer, compilerOptions, ts.sys);
if (!resolvedModule) {

@@ -1518,7 +1516,7 @@ return;

// using `path.resolve` here converts paths back to the system specific separators
return { id: path__default['default'].resolve(resolvedModule.resolvedFileName) };
return { id: resolve(resolvedModule.resolvedFileName) };
}
},
renderChunk(code, chunk) {
const source = ts__default['default'].createSourceFile(chunk.fileName, code, ts__default['default'].ScriptTarget.Latest, true);
const source = ts.createSourceFile(chunk.fileName, code, ts.ScriptTarget.Latest, true);
const fixer = new NamespaceFixer(source);

@@ -1544,2 +1542,2 @@ const typeReferences = new Set();

exports.default = plugin;
export default plugin;
{
"name": "rollup-plugin-dts",
"version": "2.0.1",
"description": "An experiment to generate .d.ts rollup files",
"version": "3.0.0",
"description": "A rollup plugin that will bundle up your .d.ts definition files.",
"keywords": [

@@ -24,5 +24,9 @@ "rollup-plugin",

"homepage": "https://github.com/Swatinem/rollup-plugin-dts#readme",
"main": "dist/rollup-plugin-dts.js",
"module": "dist/rollup-plugin-dts.mjs",
"types": "dist/rollup-plugin-dts.d.ts",
"engines": {
"node": ">=12"
},
"type": "module",
"main": "./dist/rollup-plugin-dts.js",
"exports": "./dist/rollup-plugin-dts.js",
"types": "./dist/rollup-plugin-dts.d.ts",
"sideEffects": false,

@@ -35,27 +39,7 @@ "files": [

"prebuild": "npm run clean",
"build": "tsc --project tsconfig.build.json && rollup -c",
"prepublishOnly": "npm run test && npm run build",
"build": "tsc && rollup -c .build/rollup.config.js",
"prepublishOnly": "npm run test",
"pretest": "npm run build",
"test": "jest --runInBand"
"test": "c8 node .build/tests/index.js"
},
"jest": {
"preset": "ts-jest/presets/js-with-ts",
"collectCoverage": true,
"coverageReporters": [
"html",
"json",
"text-summary"
],
"coveragePathIgnorePatterns": [
"tests",
"node_modules"
],
"testMatch": [
"**/?(*.)+(spec|test).(ts|tsx)"
],
"testPathIgnorePatterns": [
"/node_modules/",
"/testcases/"
]
},
"prettier": {

@@ -68,28 +52,22 @@ "printWidth": 120,

"@types/d3-drag": "^2.0.0",
"@types/estree": "0.0.45",
"@types/fs-extra": "^9.0.4",
"@types/jest": "^26.0.16",
"@types/node": "^14.14.10",
"@types/react": "^17.0.0",
"esm": "^3.2.25",
"fs-extra": "^9.0.1",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"react": "^17.0.1",
"@types/estree": "0.0.46",
"@types/fs-extra": "^9.0.8",
"@types/node": "^14.14.31",
"@types/react": "^17.0.2",
"c8": "^7.4.0",
"fs-extra": "^9.1.0",
"rimraf": "^3.0.2",
"rollup": "2.34.2",
"ts-jest": "^26.4.4",
"typescript": "4.1.2"
"rollup": "2.40.0",
"typescript": "4.2.3"
},
"peerDependencies": {
"rollup": "^2.34.2",
"typescript": "^4.1.2"
"rollup": "^2.40.0",
"typescript": "^4.2.3"
},
"optionalDependencies": {
"@babel/code-frame": "^7.10.4"
"@babel/code-frame": "^7.12.13"
},
"dependencies": {
"@babel/code-frame": "^7.10.4",
"magic-string": "^0.25.7"
}
}
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