Skip to content

Commit 3ef65ec

Browse files
authored
fix(typescript): prepare for Rollup 3 (#1282)
BREAKING CHANGES: Requires Node 14
1 parent 33cf1ff commit 3ef65ec

20 files changed

+95
-102
lines changed

packages/typescript/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
## Requirements
1515

16-
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).
16+
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).
1717

1818
## Install
1919

packages/typescript/ava.config.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/typescript/ava.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../shared/ava.config.mjs

packages/typescript/package.json

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313
"author": "Oskar Segersvärd",
1414
"homepage": "https://github.com/rollup/plugins/tree/master/packages/typescript/#readme",
1515
"bugs": "https://github.com/rollup/plugins/issues",
16-
"main": "dist/index.js",
17-
"module": "dist/index.es.js",
16+
"main": "./dist/cjs/index.js",
17+
"module": "./dist/es/index.js",
18+
"exports": {
19+
"types": "./types/index.d.ts",
20+
"import": "./dist/es/index.js",
21+
"default": "./dist/cjs/index.js"
22+
},
1823
"engines": {
19-
"node": ">=8.0.0"
24+
"node": ">=14.0.0"
2025
},
2126
"scripts": {
2227
"build": "rollup -c",
@@ -34,6 +39,7 @@
3439
},
3540
"files": [
3641
"dist",
42+
"!dist/**/*.map",
3743
"types",
3844
"README.md",
3945
"LICENSE"
@@ -45,27 +51,29 @@
4551
"es2015"
4652
],
4753
"peerDependencies": {
48-
"rollup": "^2.14.0",
54+
"rollup": "^2.14.0||^3.0.0",
4955
"tslib": "*",
5056
"typescript": ">=3.7.0"
5157
},
5258
"peerDependenciesMeta": {
59+
"rollup": {
60+
"optional": true
61+
},
5362
"tslib": {
5463
"optional": true
5564
}
5665
},
5766
"dependencies": {
58-
"@rollup/pluginutils": "^3.1.0",
59-
"resolve": "^1.17.0"
67+
"@rollup/pluginutils": "^4.2.1",
68+
"resolve": "^1.22.1"
6069
},
6170
"devDependencies": {
6271
"@rollup/plugin-buble": "^0.21.3",
63-
"@rollup/plugin-commonjs": "^11.1.0",
64-
"@rollup/plugin-typescript": "^5.0.2",
65-
"@types/node": "^10.0.0",
72+
"@rollup/plugin-commonjs": "^22.0.2",
73+
"@types/node": "^14.18.30",
6674
"buble": "^0.20.0",
6775
"rollup": "^2.67.3",
68-
"typescript": "^4.7.3"
76+
"typescript": "^4.8.3"
6977
},
70-
"types": "types/index.d.ts"
78+
"types": "./types/index.d.ts"
7179
}

packages/typescript/rollup.config.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/typescript/rollup.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { readFileSync } from 'fs';
2+
3+
import { createConfig } from '../../shared/rollup.config.mjs';
4+
5+
export default createConfig({
6+
pkg: JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'))
7+
});

packages/typescript/src/customTransformers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BuilderProgram, CustomTransformers, Program, TypeChecker } from 'typescript';
22

3-
import { CustomTransformerFactories, TransformerStage, TransformerFactory } from '../types';
3+
import type { CustomTransformerFactories, TransformerStage, TransformerFactory } from '../types';
44

55
/**
66
* Merges all received custom transformer definitions into a single CustomTransformers object

packages/typescript/src/diagnostics/toWarning.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RollupLogProps } from 'rollup';
1+
import { RollupWarning } from 'rollup';
22
import type { Diagnostic, FormatDiagnosticsHost } from 'typescript';
33

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

1515
// Build a Rollup warning object from the diagnostics object.
16-
const warning: RollupLogProps = {
16+
const warning: RollupWarning = {
1717
pluginCode,
1818
message: `@rollup/plugin-typescript ${pluginCode}: ${message}`
1919
};

packages/typescript/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createFilter } from '@rollup/pluginutils';
55
import { Plugin, RollupOptions, SourceDescription } from 'rollup';
66
import type { Watch } from 'typescript';
77

8-
import { RollupTypescriptOptions } from '../types';
8+
import type { RollupTypescriptOptions } from '../types';
99

1010
import createFormattingHost from './diagnostics/host';
1111
import createModuleResolver from './moduleResolution';

packages/typescript/src/options/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { CompilerOptions } from 'typescript';
22

3-
import { PartialCompilerOptions } from '../../types';
3+
import type { PartialCompilerOptions } from '../../types';
44

5-
export { EnumCompilerOptions, JsonCompilerOptions } from '../../types';
5+
export type { EnumCompilerOptions, JsonCompilerOptions } from '../../types';
66
export { PartialCompilerOptions };
77

88
/** Typescript compiler options */

packages/typescript/src/options/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as defaultTs from 'typescript';
22

3-
import { RollupTypescriptOptions, PartialCompilerOptions } from '../../types';
3+
import type { RollupTypescriptOptions, PartialCompilerOptions } from '../../types';
44
import { getTsLibPath } from '../tslib';
55

66
/**

packages/typescript/src/options/tsconfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
WatchOptions
1616
} from 'typescript';
1717

18-
import { RollupTypescriptOptions } from '../../types';
18+
import type { RollupTypescriptOptions } from '../../types';
1919
import diagnosticToWarning from '../diagnostics/toWarning';
2020

2121
import {

packages/typescript/src/watchProgram.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
WriteFileCallback
1111
} from 'typescript';
1212

13-
import { CustomTransformerFactories } from '../types';
13+
import type { CustomTransformerFactories } from '../types';
1414

1515
import { buildDiagnosticReporter } from './diagnostics/emit';
1616
import { DiagnosticsHost } from './diagnostics/host';

packages/typescript/test/declarations.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import test, { ExecutionContext } from 'ava';
1+
import test from 'ava';
2+
import type { ExecutionContext } from 'ava';
23
import { rollup } from 'rollup';
34

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

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

5253
t.deepEqual(
@@ -70,7 +71,7 @@ test.serial('supports creating declarations with non-default rootDir', async (t)
7071
});
7172
const output = await getCode(
7273
bundle,
73-
{ format: 'esm', dir: 'fixtures/declaration-root-dir/lib' },
74+
{ format: 'es', dir: 'fixtures/declaration-root-dir/lib' },
7475
true
7576
);
7677

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

9798
const output = await getCode(
9899
bundle,
99-
{ format: 'esm', dir: 'fixtures/export-interface-only/dist' },
100+
{ format: 'es', dir: 'fixtures/export-interface-only/dist' },
100101
true
101102
);
102103
const declaration = output[1].source as string;
@@ -128,7 +129,7 @@ test.serial('supports creating declaration files in declarationDir', async (t) =
128129
],
129130
onwarn
130131
});
131-
const output = await getCode(bundle, { format: 'esm', dir: 'fixtures/basic/dist' }, true);
132+
const output = await getCode(bundle, { format: 'es', dir: 'fixtures/basic/dist' }, true);
132133
const declaration = output[1].source as string;
133134

134135
t.deepEqual(
@@ -154,14 +155,14 @@ async function ensureOutDirWhenCreatingDeclarationFiles(
154155
onwarn
155156
});
156157
const caughtError = await t.throwsAsync(() =>
157-
getCode(bundle, { format: 'esm', dir: 'fixtures/basic/dist' }, true)
158+
getCode(bundle, { format: 'es', dir: 'fixtures/basic/dist' }, true)
158159
);
159160

160161
t.true(
161-
caughtError.message.includes(
162+
caughtError!.message.includes(
162163
`'outDir' or 'declarationDir' must be specified to generate declaration files`
163164
),
164-
`Unexpected error message: ${caughtError.message}`
165+
`Unexpected error message: ${caughtError!.message}`
165166
);
166167
}
167168

packages/typescript/test/fixtures/incremental-single/tsconfig.tsbuildinfo

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
16 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)