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

feat: provide type declaration for builtin:swc-loader #6314

Merged
merged 8 commits into from
Apr 22, 2024
Merged
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
133 changes: 133 additions & 0 deletions packages/rspack/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import type { RawLibraryOptions } from '@rspack/binding';
import { RawLimitChunkCountPluginOptions } from '@rspack/binding';
import type { RawOptions } from '@rspack/binding';
import { RawProgressPluginOptions } from '@rspack/binding';
import type { RawReactOptions } from '@rspack/binding';
import type { RawRelayConfig } from '@rspack/binding';
import { RawSourceMapDevToolPluginOptions } from '@rspack/binding';
import { RawSwcJsMinimizerRspackPluginOptions } from '@rspack/binding';
import { ResolveRequest } from 'enhanced-resolve';
Expand Down Expand Up @@ -4889,6 +4891,133 @@ export type SwcJsMinimizerRspackPluginOptions = {
include?: MinifyConditions;
};

// @public (undocumented)
export interface SwcLoaderEnvConfig {
bugfixes?: boolean;
coreJs?: string;
// (undocumented)
debug?: boolean;
// (undocumented)
dynamicImport?: boolean;
// (undocumented)
exclude?: string[];
forceAllTransforms?: boolean;
// (undocumented)
include?: string[];
// (undocumented)
loose?: boolean;
// (undocumented)
mode?: "usage" | "entry";
// (undocumented)
path?: string;
// (undocumented)
shippedProposals?: boolean;
skip?: string[];
// (undocumented)
targets?: any;
}

// @public (undocumented)
export interface SwcLoaderEsParserConfig {
decorators?: boolean;
decoratorsBeforeExport?: boolean;
exportDefaultFrom?: boolean;
functionBind?: boolean;
importAssertions?: boolean;
jsx?: boolean;
// (undocumented)
syntax: "ecmascript";
}

// @public (undocumented)
export interface SwcLoaderJscConfig {
// (undocumented)
baseUrl?: string;
experimental?: {
optimizeHygiene?: boolean;
keepImportAttributes?: boolean;
emitAssertForImportAttributes?: boolean;
cacheRoot?: string;
plugins?: Array<[string, Record<string, any>]>;
disableBuiltinTransformsForInternalTesting?: boolean;
};
externalHelpers?: boolean;
keepClassNames?: boolean;
// (undocumented)
loose?: boolean;
parser?: SwcLoaderParserConfig;
// (undocumented)
paths?: {
[from: string]: [string];
};
// (undocumented)
preserveAllComments?: boolean;
// Warning: (ae-forgotten-export) The symbol "JscTarget" needs to be exported by the entry point index.d.ts
target?: JscTarget;
// (undocumented)
transform?: SwcLoaderTransformConfig;
}

// Warning: (ae-forgotten-export) The symbol "Es6Config" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "CommonJsConfig" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "UmdConfig" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "AmdConfig" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "NodeNextConfig" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "SystemjsConfig" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type SwcLoaderModuleConfig = Es6Config | CommonJsConfig | UmdConfig | AmdConfig | NodeNextConfig | SystemjsConfig;

// @public (undocumented)
export type SwcLoaderOptions = {
test?: string | string[];
exclude?: string | string[];
env?: SwcLoaderEnvConfig;
jsc?: SwcLoaderJscConfig;
module?: SwcLoaderModuleConfig;
minify?: boolean;
sourceMaps?: boolean;
inlineSourcesContent?: boolean;
isModule?: boolean | "unknown";
rspackExperiments?: {
relay?: RelayOptions;
emotion?: EmotionOptions;
import?: PluginImportOptions;
styledComponents?: StyledComponentsOptions;
};
};

// @public (undocumented)
export type SwcLoaderParserConfig = SwcLoaderTsParserConfig | SwcLoaderEsParserConfig;

// @public (undocumented)
export interface SwcLoaderTransformConfig {
// Warning: (ae-forgotten-export) The symbol "ConstModulesConfig" needs to be exported by the entry point index.d.ts
//
// (undocumented)
constModules?: ConstModulesConfig;
decoratorMetadata?: boolean;
decoratorVersion?: "2021-12" | "2022-03";
legacyDecorator?: boolean;
// Warning: (ae-forgotten-export) The symbol "OptimizerConfig" needs to be exported by the entry point index.d.ts
optimizer?: OptimizerConfig;
// Warning: (ae-forgotten-export) The symbol "ReactOptions" needs to be exported by the entry point index.d.ts
react?: ReactOptions;
// (undocumented)
treatConstEnumAsEnum?: boolean;
// (undocumented)
useDefineForClassFields?: boolean;
}

// @public (undocumented)
export interface SwcLoaderTsParserConfig {
decorators?: boolean;
dynamicImport?: boolean;
// (undocumented)
syntax: "typescript";
tsx?: boolean;
}

// Warning: (ae-forgotten-export) The symbol "target" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
Expand Down Expand Up @@ -5024,6 +5153,10 @@ export type WorkerPublicPath = z.infer<typeof workerPublicPath>;
// dist/NormalModuleFactory.d.ts:9:9 - (ae-forgotten-export) The symbol "ResourceDataWithData" needs to be exported by the entry point index.d.ts
// dist/NormalModuleFactory.d.ts:10:9 - (ae-forgotten-export) The symbol "ResolveData" needs to be exported by the entry point index.d.ts
// dist/NormalModuleFactory.d.ts:12:9 - (ae-forgotten-export) The symbol "NormalModuleCreateData" needs to be exported by the entry point index.d.ts
// dist/builtin-loader/swc/types.d.ts:457:9 - (ae-forgotten-export) The symbol "RelayOptions" needs to be exported by the entry point index.d.ts
// dist/builtin-loader/swc/types.d.ts:458:9 - (ae-forgotten-export) The symbol "EmotionOptions" needs to be exported by the entry point index.d.ts
// dist/builtin-loader/swc/types.d.ts:459:9 - (ae-forgotten-export) The symbol "PluginImportOptions" needs to be exported by the entry point index.d.ts
// dist/builtin-loader/swc/types.d.ts:460:9 - (ae-forgotten-export) The symbol "StyledComponentsOptions" needs to be exported by the entry point index.d.ts
// dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts:40:5 - (ae-forgotten-export) The symbol "ExtractCommentsOptions" needs to be exported by the entry point index.d.ts
// dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts:41:5 - (ae-forgotten-export) The symbol "TerserCompressOptions" needs to be exported by the entry point index.d.ts
// dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts:42:5 - (ae-forgotten-export) The symbol "TerserMangleOptions" needs to be exported by the entry point index.d.ts
Expand Down
11 changes: 11 additions & 0 deletions packages/rspack/src/builtin-loader/swc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ export type { RelayOptions } from "./relay";

export { resolvePluginImport } from "./pluginImport";
export type { PluginImportOptions } from "./pluginImport";

export type {
SwcLoaderOptions,
SwcLoaderEnvConfig,
SwcLoaderJscConfig,
SwcLoaderModuleConfig,
SwcLoaderParserConfig,
SwcLoaderEsParserConfig,
SwcLoaderTsParserConfig,
SwcLoaderTransformConfig
} from "./types";
6 changes: 3 additions & 3 deletions packages/rspack/src/builtin-loader/swc/pluginImport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RawPluginImportConfig } from "@rspack/binding";
import type { RawPluginImportConfig } from "@rspack/binding";

type PluginImportConfig = {
libraryName: string;
Expand All @@ -9,8 +9,8 @@ type PluginImportConfig = {
styleLibraryDirectory?: string;
camelToDashComponentName?: boolean;
transformToDefaultImport?: boolean;
ignoreEsComponent?: Array<string>;
ignoreStyleComponent?: Array<string>;
ignoreEsComponent?: string[];
ignoreStyleComponent?: string[];
};

type PluginImportOptions = PluginImportConfig[] | undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/builtin-loader/swc/react.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RawReactOptions } from "@rspack/binding";
import type { RawReactOptions } from "@rspack/binding";

function resolveReact(react: ReactOptions): RawReactOptions {
return react ?? {};
Expand Down
3 changes: 1 addition & 2 deletions packages/rspack/src/builtin-loader/swc/relay.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from "path";

import { RawRelayConfig } from "@rspack/binding";
import type { RawRelayConfig } from "@rspack/binding";

type RelayOptions = boolean | RawRelayConfig | undefined;

Expand Down
Loading
Loading