Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add module: 'ES2022', support newer moduleResolution kinds, support cts + mts #447

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [12.x, 14.x, 16.x, 18.x]
node-version: [18.x]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ This also allows for passing in different `tsconfig` files depending on your bui

### Some compiler options have more than one compatible value

* `module`: defaults to `ES2015`. Other valid values are `ES2020` and `ESNext` (required for dynamic imports, see [#54](https://github.com/ezolenko/rollup-plugin-typescript2/issues/54)).
* `module`: defaults to `ES2015`. Other valid values are `ES2020`, `ES2022` and `ESNext` (required for dynamic imports, see [#54](https://github.com/ezolenko/rollup-plugin-typescript2/issues/54)).

### Some options need additional configuration on plugin side

Expand Down Expand Up @@ -152,11 +152,11 @@ See [#108](https://github.com/ezolenko/rollup-plugin-typescript2/issues/108)
Path to cache.
Defaults to a folder in `node_modules`.

* `include`: `[ "*.ts+(|x)", "**/*.ts+(|x)" ]`
* `include`: `[ "*.ts+(|x)", "**/*.ts+(|x)", "**/*.cts", "**/*.mts" ]`

By default compiles all `.ts` and `.tsx` files with TypeScript.

* `exclude`: `[ "*.d.ts", "**/*.d.ts" ]`
* `exclude`: `[ "*.d.ts", "**/*.d.ts", "**/*.d.cts", "**/*.d.mts" ]`

But excludes type definitions.

Expand Down
8 changes: 4 additions & 4 deletions __tests__/context.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jest, test, expect } from "@jest/globals";

import { makeContext } from "./fixtures/context";
import { RollupContext } from "../src/context";
import { RollupContext, VerbosityLevel } from "../src/context";

(global as any).console = {
warn: jest.fn(),
Expand All @@ -11,7 +11,7 @@ import { RollupContext } from "../src/context";

test("RollupContext", () => {
const innerContext = makeContext();
const context = new RollupContext(5, false, innerContext);
const context = new RollupContext(VerbosityLevel.Debug + 1, false, innerContext);

context.warn("test");
expect(innerContext.warn).toHaveBeenLastCalledWith("test");
Expand Down Expand Up @@ -52,7 +52,7 @@ test("RollupContext with 0 verbosity", () => {

test("RollupContext.error + debug negative verbosity", () => {
const innerContext = makeContext();
const context = new RollupContext(-100, true, innerContext);
const context = new RollupContext(VerbosityLevel.Error - 1, true, innerContext);

context.error("verbosity is too low here");
expect(innerContext.error).not.toBeCalled();
Expand All @@ -62,7 +62,7 @@ test("RollupContext.error + debug negative verbosity", () => {

test("RollupContext.error with bail", () => {
const innerContext = makeContext();
const context = new RollupContext(5, true, innerContext);
const context = new RollupContext(VerbosityLevel.Debug, true, innerContext);

context.error("bail");
expect(innerContext.error).toHaveBeenLastCalledWith("bail");
Expand Down
5 changes: 4 additions & 1 deletion __tests__/get-options-overrides.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const forcedOptions: ts.CompilerOptions = {
allowNonTsExtensions: true,
importHelpers: true,
inlineSourceMap: false,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
noEmit: false,
noEmitOnError: false,
noEmitHelpers: false,
Expand Down Expand Up @@ -51,6 +50,7 @@ test("getOptionsOverrides - preParsedTsConfig", () => {
declarationDir: undefined,
module: ts.ModuleKind.ES2015,
sourceRoot: undefined,
moduleResolution: ts.ModuleResolutionKind.Node10,
});
});

Expand All @@ -67,6 +67,7 @@ test("getOptionsOverrides - preParsedTsConfig with options.module", () => {
...forcedOptions,
declarationDir: undefined,
sourceRoot: undefined,
moduleResolution: ts.ModuleResolutionKind.Node10,
});
});

Expand All @@ -78,6 +79,7 @@ test("getOptionsOverrides - with declaration", () => {
...forcedOptions,
module: ts.ModuleKind.ES2015,
sourceRoot: undefined,
moduleResolution: ts.ModuleResolutionKind.Node10,
});
});

Expand All @@ -94,6 +96,7 @@ test("getOptionsOverrides - with sourceMap", () => {
...forcedOptions,
declarationDir: undefined,
module: ts.ModuleKind.ES2015,
moduleResolution: ts.ModuleResolutionKind.Node10,
});
});

Expand Down
10 changes: 0 additions & 10 deletions __tests__/integration/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ export async function genBundle (inputArgs: Params) {
const bundle = await rollup(createInput(inputArgs));
const esm = await bundle.generate(createOutput(inputArgs.testDir));

// Rollup has some deprecated properties like `get isAsset`, so enumerating them with, e.g. `.toEqual`, causes a bunch of warnings to be output
// delete the `isAsset` property for (much) cleaner logs
const { output: files } = esm;
for (const file of files) {
if ("isAsset" in file) {
const optIsAsset = file as Partial<Pick<OutputAsset, "isAsset">> & Omit<OutputAsset, "isAsset">;
delete optIsAsset["isAsset"];
}
}

return esm;
}

Expand Down
38 changes: 19 additions & 19 deletions dist/context.d.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { PluginContext } from "rollup";
export declare enum VerbosityLevel {
Error = 0,
Warning = 1,
Info = 2,
Debug = 3
}
/** cannot be used in options hook (which does not have this.warn and this.error), but can be in other hooks */
export declare class RollupContext {
private verbosity;
private bail;
private context;
private prefix;
constructor(verbosity: VerbosityLevel, bail: boolean, context: PluginContext, prefix?: string);
warn(message: string | (() => string)): void;
error(message: string | (() => string)): void | never;
info(message: string | (() => string)): void;
debug(message: string | (() => string)): void;
}
import { PluginContext } from "rollup";
export declare enum VerbosityLevel {
Error = 0,
Warning = 1,
Info = 2,
Debug = 3
}
/** cannot be used in options hook (which does not have this.warn and this.error), but can be in other hooks */
export declare class RollupContext {
private verbosity;
private bail;
private context;
private prefix;
constructor(verbosity: VerbosityLevel, bail: boolean, context: PluginContext, prefix?: string);
warn(message: string | (() => string)): void;
error(message: string | (() => string)): void | never;
info(message: string | (() => string)): void;
debug(message: string | (() => string)): void;
}
//# sourceMappingURL=context.d.ts.map
18 changes: 9 additions & 9 deletions dist/diagnostics-format-host.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// <reference types="node" />
import * as path from "path";
import * as tsTypes from "typescript";
export declare class FormatHost implements tsTypes.FormatDiagnosticsHost {
getCurrentDirectory(): string;
getCanonicalFileName: typeof path.normalize;
getNewLine: () => string;
}
export declare const formatHost: FormatHost;
/// <reference types="node" />
import * as path from "path";
import * as tsTypes from "typescript";
export declare class FormatHost implements tsTypes.FormatDiagnosticsHost {
getCurrentDirectory(): string;
getCanonicalFileName: typeof path.normalize;
getNewLine: () => string;
}
export declare const formatHost: FormatHost;
//# sourceMappingURL=diagnostics-format-host.d.ts.map
24 changes: 12 additions & 12 deletions dist/diagnostics.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as tsTypes from "typescript";
import { RollupContext } from "./context";
export interface IDiagnostics {
flatMessage: string;
formatted: string;
fileLine?: string;
category: tsTypes.DiagnosticCategory;
code: number;
type: string;
}
export declare function convertDiagnostic(type: string, data: tsTypes.Diagnostic[]): IDiagnostics[];
export declare function printDiagnostics(context: RollupContext, diagnostics: IDiagnostics[], pretty?: boolean): void;
import * as tsTypes from "typescript";
import { RollupContext } from "./context";
export interface IDiagnostics {
flatMessage: string;
formatted: string;
fileLine?: string;
category: tsTypes.DiagnosticCategory;
code: number;
type: string;
}
export declare function convertDiagnostic(type: string, data: tsTypes.Diagnostic[]): IDiagnostics[];
export declare function printDiagnostics(context: RollupContext, diagnostics: IDiagnostics[], pretty?: boolean): void;
//# sourceMappingURL=diagnostics.d.ts.map
10 changes: 5 additions & 5 deletions dist/get-options-overrides.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as tsTypes from "typescript";
import { IOptions } from "./ioptions";
import { RollupContext } from "./context";
export declare function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot }: IOptions, preParsedTsconfig?: tsTypes.ParsedCommandLine): tsTypes.CompilerOptions;
export declare function createFilter(context: RollupContext, pluginOptions: IOptions, parsedConfig: tsTypes.ParsedCommandLine): (id: unknown) => boolean;
import * as tsTypes from "typescript";
import { IOptions } from "./ioptions";
import { RollupContext } from "./context";
export declare function getOptionsOverrides({ useTsconfigDeclarationDir, cacheRoot }: IOptions, preParsedTsconfig?: tsTypes.ParsedCommandLine): tsTypes.CompilerOptions;
export declare function createFilter(context: RollupContext, pluginOptions: IOptions, parsedConfig: tsTypes.ParsedCommandLine): (id: unknown) => boolean;
//# sourceMappingURL=get-options-overrides.d.ts.map
68 changes: 34 additions & 34 deletions dist/host.d.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import * as tsTypes from "typescript";
import { TransformerFactoryCreator } from "./ioptions";
export declare class LanguageServiceHost implements tsTypes.LanguageServiceHost {
private parsedConfig;
private transformers;
private cwd;
private snapshots;
private versions;
private service?;
private fileNames;
constructor(parsedConfig: tsTypes.ParsedCommandLine, transformers: TransformerFactoryCreator[], cwd: string);
reset(): void;
setLanguageService(service: tsTypes.LanguageService): void;
setSnapshot(fileName: string, source: string): tsTypes.IScriptSnapshot;
getScriptSnapshot(fileName: string): tsTypes.IScriptSnapshot | undefined;
getScriptFileNames: () => string[];
getScriptVersion(fileName: string): string;
getCustomTransformers(): tsTypes.CustomTransformers | undefined;
getCompilationSettings: () => tsTypes.CompilerOptions;
getTypeRootsVersion: () => number;
getCurrentDirectory: () => string;
useCaseSensitiveFileNames: () => boolean;
getDefaultLibFileName: typeof tsTypes.getDefaultLibFilePath;
readDirectory: (path: string, extensions?: readonly string[] | undefined, exclude?: readonly string[] | undefined, include?: readonly string[] | undefined, depth?: number | undefined) => string[];
readFile: (path: string, encoding?: string | undefined) => string | undefined;
fileExists: (path: string) => boolean;
directoryExists: (path: string) => boolean;
getDirectories: (path: string) => string[];
realpath: (path: string) => string;
trace: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
}
import * as tsTypes from "typescript";
import { TransformerFactoryCreator } from "./ioptions";
export declare class LanguageServiceHost implements tsTypes.LanguageServiceHost {
private parsedConfig;
private transformers;
private cwd;
private snapshots;
private versions;
private service?;
private fileNames;
constructor(parsedConfig: tsTypes.ParsedCommandLine, transformers: TransformerFactoryCreator[], cwd: string);
reset(): void;
setLanguageService(service: tsTypes.LanguageService): void;
setSnapshot(fileName: string, source: string): tsTypes.IScriptSnapshot;
getScriptSnapshot(fileName: string): tsTypes.IScriptSnapshot | undefined;
getScriptFileNames: () => string[];
getScriptVersion(fileName: string): string;
getCustomTransformers(): tsTypes.CustomTransformers | undefined;
getCompilationSettings: () => tsTypes.CompilerOptions;
getTypeRootsVersion: () => number;
getCurrentDirectory: () => string;
useCaseSensitiveFileNames: () => boolean;
getDefaultLibFileName: typeof tsTypes.getDefaultLibFilePath;
readDirectory: (path: string, extensions?: readonly string[] | undefined, exclude?: readonly string[] | undefined, include?: readonly string[] | undefined, depth?: number | undefined) => string[];
readFile: (path: string, encoding?: string | undefined) => string | undefined;
fileExists: (path: string) => boolean;
directoryExists: (path: string) => boolean;
getDirectories: (path: string) => string[];
realpath: (path: string) => string;
trace: {
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
};
}
//# sourceMappingURL=host.d.ts.map
18 changes: 9 additions & 9 deletions dist/icache.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export interface ICache<DataType> {
exists(name: string): boolean;
path(name: string): string;
match(names: string[]): boolean;
read(name: string): DataType | null | undefined;
write(name: string, data: DataType): void;
touch(name: string): void;
roll(): void;
}
export interface ICache<DataType> {
exists(name: string): boolean;
path(name: string): string;
match(names: string[]): boolean;
read(name: string): DataType | null | undefined;
write(name: string, data: DataType): void;
touch(name: string): void;
roll(): void;
}
//# sourceMappingURL=icache.d.ts.map
12 changes: 6 additions & 6 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PluginImpl } from "rollup";
import { IOptions } from "./ioptions";
declare type RPT2Options = Partial<IOptions>;
export { RPT2Options };
declare const typescript: PluginImpl<RPT2Options>;
export default typescript;
import { PluginImpl } from "rollup";
import { IOptions } from "./ioptions";
type RPT2Options = Partial<IOptions>;
export { RPT2Options };
declare const typescript: PluginImpl<RPT2Options>;
export default typescript;
//# sourceMappingURL=index.d.ts.map
2 changes: 1 addition & 1 deletion dist/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 27 additions & 27 deletions dist/ioptions.d.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import * as tsTypes from "typescript";
import { tsModule } from "./tsproxy";
export interface ICustomTransformer {
before?: tsTypes.TransformerFactory<tsTypes.SourceFile>;
after?: tsTypes.TransformerFactory<tsTypes.SourceFile>;
afterDeclarations?: tsTypes.TransformerFactory<tsTypes.Bundle | tsTypes.SourceFile>;
}
export declare type TransformerFactoryCreator = (ls: tsTypes.LanguageService) => tsTypes.CustomTransformers | ICustomTransformer;
export interface IOptions {
cwd: string;
include: string | string[];
exclude: string | string[];
check: boolean;
verbosity: number;
clean: boolean;
cacheRoot: string;
abortOnError: boolean;
rollupCommonJSResolveHack: boolean;
tsconfig?: string;
useTsconfigDeclarationDir: boolean;
typescript: typeof tsModule;
tsconfigOverride: any;
transformers: TransformerFactoryCreator[];
tsconfigDefaults: any;
sourceMapCallback: (id: string, map: string) => void;
objectHashIgnoreUnknownHack: boolean;
}
import * as tsTypes from "typescript";
import { tsModule } from "./tsproxy";
export interface ICustomTransformer {
before?: tsTypes.TransformerFactory<tsTypes.SourceFile>;
after?: tsTypes.TransformerFactory<tsTypes.SourceFile>;
afterDeclarations?: tsTypes.TransformerFactory<tsTypes.Bundle | tsTypes.SourceFile>;
}
export type TransformerFactoryCreator = (ls: tsTypes.LanguageService) => tsTypes.CustomTransformers | ICustomTransformer;
export interface IOptions {
cwd: string;
include: string | string[];
exclude: string | string[];
check: boolean;
verbosity: number;
clean: boolean;
cacheRoot: string;
abortOnError: boolean;
rollupCommonJSResolveHack: boolean;
tsconfig?: string;
useTsconfigDeclarationDir: boolean;
typescript: typeof tsModule;
tsconfigOverride: any;
transformers: TransformerFactoryCreator[];
tsconfigDefaults: any;
sourceMapCallback: (id: string, map: string) => void;
objectHashIgnoreUnknownHack: boolean;
}
//# sourceMappingURL=ioptions.d.ts.map
Loading