Skip to content

Commit

Permalink
feat: provide type declaration for builtin:swc-loader (#6314)
Browse files Browse the repository at this point in the history
* feat: provide type declaration for builtin:swc-loader

* docs: add document

* fix: api.md

* fix: missing isModule

* fix: import type
  • Loading branch information
chenjiahan authored Apr 22, 2024
1 parent ef4201b commit 66d1ae6
Show file tree
Hide file tree
Showing 13 changed files with 804 additions and 45 deletions.
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

2 comments on commit 66d1ae6

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-04-22 72638cb) Current Change
10000_development-mode + exec 2.67 s ± 31 ms 2.7 s ± 26 ms +1.16 %
10000_development-mode_hmr + exec 685 ms ± 7.4 ms 690 ms ± 13 ms +0.74 %
10000_production-mode + exec 2.46 s ± 29 ms 2.49 s ± 22 ms +1.33 %
arco-pro_development-mode + exec 2.47 s ± 80 ms 2.51 s ± 51 ms +1.90 %
arco-pro_development-mode_hmr + exec 429 ms ± 1.3 ms 430 ms ± 1.9 ms +0.06 %
arco-pro_development-mode_hmr_intercept-plugin + exec 440 ms ± 4.1 ms 440 ms ± 5.6 ms +0.04 %
arco-pro_development-mode_intercept-plugin + exec 3.23 s ± 71 ms 3.25 s ± 48 ms +0.47 %
arco-pro_production-mode + exec 3.93 s ± 107 ms 3.96 s ± 81 ms +0.80 %
arco-pro_production-mode_intercept-plugin + exec 4.73 s ± 74 ms 4.76 s ± 122 ms +0.60 %
threejs_development-mode_10x + exec 2.05 s ± 21 ms 2.04 s ± 22 ms -0.41 %
threejs_development-mode_10x_hmr + exec 746 ms ± 11 ms 758 ms ± 14 ms +1.59 %
threejs_production-mode_10x + exec 5.16 s ± 40 ms 5.21 s ± 77 ms +0.95 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs, self-hosted, Linux, ci ✅ success
_selftest, ubuntu-latest ✅ success
nx, ubuntu-latest ✅ success
rspress, ubuntu-latest ✅ success
rsbuild, ubuntu-latest ✅ success
compat, ubuntu-latest ✅ success
examples, ubuntu-latest ✅ success

Please sign in to comment.