Skip to content

Commit

Permalink
fix(typescript): prepare for Rollup 3 (#1282)
Browse files Browse the repository at this point in the history
BREAKING CHANGES: Requires Node 14
  • Loading branch information
lukastaegert authored Oct 10, 2022
1 parent 33cf1ff commit 3ef65ec
Show file tree
Hide file tree
Showing 20 changed files with 95 additions and 102 deletions.
2 changes: 1 addition & 1 deletion packages/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

## Requirements

This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v8.0.0+) and Rollup v1.20.0+. This plugin also requires at least [TypeScript 3.7](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html).
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v2.14.0+. This plugin also requires at least [TypeScript 3.7](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html).

## Install

Expand Down
1 change: 0 additions & 1 deletion packages/typescript/ava.config.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/typescript/ava.config.mjs
30 changes: 19 additions & 11 deletions packages/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
"author": "Oskar Segersvärd",
"homepage": "https://github.com/rollup/plugins/tree/master/packages/typescript/#readme",
"bugs": "https://github.com/rollup/plugins/issues",
"main": "dist/index.js",
"module": "dist/index.es.js",
"main": "./dist/cjs/index.js",
"module": "./dist/es/index.js",
"exports": {
"types": "./types/index.d.ts",
"import": "./dist/es/index.js",
"default": "./dist/cjs/index.js"
},
"engines": {
"node": ">=8.0.0"
"node": ">=14.0.0"
},
"scripts": {
"build": "rollup -c",
Expand All @@ -34,6 +39,7 @@
},
"files": [
"dist",
"!dist/**/*.map",
"types",
"README.md",
"LICENSE"
Expand All @@ -45,27 +51,29 @@
"es2015"
],
"peerDependencies": {
"rollup": "^2.14.0",
"rollup": "^2.14.0||^3.0.0",
"tslib": "*",
"typescript": ">=3.7.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
},
"tslib": {
"optional": true
}
},
"dependencies": {
"@rollup/pluginutils": "^3.1.0",
"resolve": "^1.17.0"
"@rollup/pluginutils": "^4.2.1",
"resolve": "^1.22.1"
},
"devDependencies": {
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-typescript": "^5.0.2",
"@types/node": "^10.0.0",
"@rollup/plugin-commonjs": "^22.0.2",
"@types/node": "^14.18.30",
"buble": "^0.20.0",
"rollup": "^2.67.3",
"typescript": "^4.7.3"
"typescript": "^4.8.3"
},
"types": "types/index.d.ts"
"types": "./types/index.d.ts"
}
15 changes: 0 additions & 15 deletions packages/typescript/rollup.config.js

This file was deleted.

7 changes: 7 additions & 0 deletions packages/typescript/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { readFileSync } from 'fs';

import { createConfig } from '../../shared/rollup.config.mjs';

export default createConfig({
pkg: JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'))
});
2 changes: 1 addition & 1 deletion packages/typescript/src/customTransformers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BuilderProgram, CustomTransformers, Program, TypeChecker } from 'typescript';

import { CustomTransformerFactories, TransformerStage, TransformerFactory } from '../types';
import type { CustomTransformerFactories, TransformerStage, TransformerFactory } from '../types';

/**
* Merges all received custom transformer definitions into a single CustomTransformers object
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript/src/diagnostics/toWarning.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollupLogProps } from 'rollup';
import { RollupWarning } from 'rollup';
import type { Diagnostic, FormatDiagnosticsHost } from 'typescript';

/**
Expand All @@ -13,7 +13,7 @@ export default function diagnosticToWarning(
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');

// Build a Rollup warning object from the diagnostics object.
const warning: RollupLogProps = {
const warning: RollupWarning = {
pluginCode,
message: `@rollup/plugin-typescript ${pluginCode}: ${message}`
};
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createFilter } from '@rollup/pluginutils';
import { Plugin, RollupOptions, SourceDescription } from 'rollup';
import type { Watch } from 'typescript';

import { RollupTypescriptOptions } from '../types';
import type { RollupTypescriptOptions } from '../types';

import createFormattingHost from './diagnostics/host';
import createModuleResolver from './moduleResolution';
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript/src/options/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { CompilerOptions } from 'typescript';

import { PartialCompilerOptions } from '../../types';
import type { PartialCompilerOptions } from '../../types';

export { EnumCompilerOptions, JsonCompilerOptions } from '../../types';
export type { EnumCompilerOptions, JsonCompilerOptions } from '../../types';
export { PartialCompilerOptions };

/** Typescript compiler options */
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/src/options/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as defaultTs from 'typescript';

import { RollupTypescriptOptions, PartialCompilerOptions } from '../../types';
import type { RollupTypescriptOptions, PartialCompilerOptions } from '../../types';
import { getTsLibPath } from '../tslib';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/src/options/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
WatchOptions
} from 'typescript';

import { RollupTypescriptOptions } from '../../types';
import type { RollupTypescriptOptions } from '../../types';
import diagnosticToWarning from '../diagnostics/toWarning';

import {
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/src/watchProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
WriteFileCallback
} from 'typescript';

import { CustomTransformerFactories } from '../types';
import type { CustomTransformerFactories } from '../types';

import { buildDiagnosticReporter } from './diagnostics/emit';
import { DiagnosticsHost } from './diagnostics/host';
Expand Down
19 changes: 10 additions & 9 deletions packages/typescript/test/declarations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import test, { ExecutionContext } from 'ava';
import test from 'ava';
import type { ExecutionContext } from 'ava';
import { rollup } from 'rollup';

import typescript from '..';
Expand All @@ -22,7 +23,7 @@ test.serial('supports creating declaration files', async (t) => {
],
onwarn
});
const output = await getCode(bundle, { format: 'esm', dir: 'fixtures/basic/dist' }, true);
const output = await getCode(bundle, { format: 'es', dir: 'fixtures/basic/dist' }, true);
const declaration = output[1].source as string;

t.deepEqual(
Expand All @@ -46,7 +47,7 @@ test.serial('supports creating declaration files in subfolder', async (t) => {
],
onwarn
});
const output = await getCode(bundle, { format: 'esm', dir: 'fixtures/basic/dist' }, true);
const output = await getCode(bundle, { format: 'es', dir: 'fixtures/basic/dist' }, true);
const declaration = output[1].source as string;

t.deepEqual(
Expand All @@ -70,7 +71,7 @@ test.serial('supports creating declarations with non-default rootDir', async (t)
});
const output = await getCode(
bundle,
{ format: 'esm', dir: 'fixtures/declaration-root-dir/lib' },
{ format: 'es', dir: 'fixtures/declaration-root-dir/lib' },
true
);

Expand All @@ -96,7 +97,7 @@ test.serial('supports creating declaration files for interface only source file'

const output = await getCode(
bundle,
{ format: 'esm', dir: 'fixtures/export-interface-only/dist' },
{ format: 'es', dir: 'fixtures/export-interface-only/dist' },
true
);
const declaration = output[1].source as string;
Expand Down Expand Up @@ -128,7 +129,7 @@ test.serial('supports creating declaration files in declarationDir', async (t) =
],
onwarn
});
const output = await getCode(bundle, { format: 'esm', dir: 'fixtures/basic/dist' }, true);
const output = await getCode(bundle, { format: 'es', dir: 'fixtures/basic/dist' }, true);
const declaration = output[1].source as string;

t.deepEqual(
Expand All @@ -154,14 +155,14 @@ async function ensureOutDirWhenCreatingDeclarationFiles(
onwarn
});
const caughtError = await t.throwsAsync(() =>
getCode(bundle, { format: 'esm', dir: 'fixtures/basic/dist' }, true)
getCode(bundle, { format: 'es', dir: 'fixtures/basic/dist' }, true)
);

t.true(
caughtError.message.includes(
caughtError!.message.includes(
`'outDir' or 'declarationDir' must be specified to generate declaration files`
),
`Unexpected error message: ${caughtError.message}`
`Unexpected error message: ${caughtError!.message}`
);
}

Expand Down

Large diffs are not rendered by default.

Binary file modified packages/typescript/test/snapshots/tslib.ts.snap
Binary file not shown.
Binary file modified packages/typescript/test/snapshots/warnings.ts.snap
Binary file not shown.
Loading

0 comments on commit 3ef65ec

Please sign in to comment.