Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 1 addition & 5 deletions crates/rspack_loader_swc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ impl SwcLoader {
if !is_typescript {
return;
}
let Some(options) = &self
.options_with_additional
.rspack_experiments
.collect_typescript_info
else {
let Some(options) = &self.options_with_additional.collect_typescript_info else {
return;
};
collected_ts_info = Some(collect_typescript_info(
Expand Down
9 changes: 6 additions & 3 deletions crates/rspack_loader_swc/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use swc_core::base::config::{
#[serde(rename_all = "camelCase", default)]
pub struct RawRspackExperiments {
pub import: Option<Vec<RawImportOptions>>,
pub collect_type_script_info: Option<RawCollectTypeScriptInfoOptions>,
}

#[derive(Default, Deserialize, Debug)]
Expand All @@ -27,7 +26,6 @@ pub struct RawCollectTypeScriptInfoOptions {
#[derive(Default, Debug)]
pub(crate) struct RspackExperiments {
pub(crate) import: Option<Vec<ImportOptions>>,
pub(crate) collect_typescript_info: Option<CollectTypeScriptInfoOptions>,
}

#[derive(Default, Debug)]
Expand All @@ -49,7 +47,6 @@ impl From<RawRspackExperiments> for RspackExperiments {
import: value
.import
.map(|i| i.into_iter().map(|v| v.into()).collect()),
collect_typescript_info: value.collect_type_script_info.map(|v| v.into()),
}
}
}
Expand Down Expand Up @@ -113,6 +110,9 @@ pub struct SwcLoaderJsOptions {
#[serde(default)]
pub source_map_ignore_list: Option<FilePattern>,

#[serde(default)]
pub collect_type_script_info: Option<RawCollectTypeScriptInfoOptions>,

#[serde(default)]
pub rspack_experiments: Option<RawRspackExperiments>,
}
Expand All @@ -123,6 +123,7 @@ pub(crate) struct SwcCompilerOptionsWithAdditional {
raw_options: String,
pub(crate) swc_options: Options,
pub(crate) rspack_experiments: RspackExperiments,
pub(crate) collect_typescript_info: Option<CollectTypeScriptInfoOptions>,
}

impl AsRefStrConverter for SwcCompilerOptionsWithAdditional {
Expand Down Expand Up @@ -156,6 +157,7 @@ impl TryFrom<&str> for SwcCompilerOptionsWithAdditional {
error,
is_module,
schema,
collect_type_script_info,
rspack_experiments,
source_map_ignore_list,
} = option;
Expand Down Expand Up @@ -191,6 +193,7 @@ impl TryFrom<&str> for SwcCompilerOptionsWithAdditional {
..serde_json::from_value(serde_json::Value::Object(Default::default()))?
},
rspack_experiments: rspack_experiments.unwrap_or_default().into(),
collect_typescript_info: collect_type_script_info.map(|v| v.into()),
})
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/rspack/etc/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7885,6 +7885,7 @@ export type SwcLoaderModuleConfig = ModuleConfig;
// @public (undocumented)
export type SwcLoaderOptions = Config_2 & {
isModule?: boolean | "unknown";
collectTypeScriptInfo?: CollectTypeScriptInfoOptions;
rspackExperiments?: {
import?: PluginImportOptions;
collectTypeScriptInfo?: CollectTypeScriptInfoOptions;
Expand Down
6 changes: 6 additions & 0 deletions packages/rspack/src/builtin-loader/swc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ export type SwcLoaderTsParserConfig = TsParserConfig;
export type SwcLoaderTransformConfig = TransformConfig;
export type SwcLoaderOptions = Config & {
isModule?: boolean | "unknown";
/**
* Collects information from TypeScript's AST for consumption by subsequent Rspack processes,
* providing better TypeScript development experience and smaller output bundle size.
*/
collectTypeScriptInfo?: CollectTypeScriptInfoOptions;
/**
* Experimental features provided by Rspack.
* @experimental
*/
rspackExperiments?: {
import?: PluginImportOptions;
/**
* @deprecated Use top-level `collectTypeScriptInfo` instead.
* Collects information from TypeScript's AST for consumption by subsequent Rspack processes,
* providing better TypeScript development experience and smaller output bundle size.
*/
Expand Down
21 changes: 18 additions & 3 deletions packages/rspack/src/config/adapterRuleUse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { type LoaderObject, parsePathQueryFragment } from "../loader-runner";
import type { Logger } from "../logging/Logger";
import type { Module } from "../Module";
import type { ResolveRequest } from "../Resolver";
import { isNil } from "../util";
import { deprecate, isNil } from "../util";
import type Hash from "../util/hash";
import type { RspackOptionsNormalized } from "./normalization";
import type {
Expand Down Expand Up @@ -499,6 +499,13 @@ const getSwcLoaderOptions: GetLoaderOptions = (options, _) => {
options.jsc.experimental ??= {};
options.jsc.experimental.disableAllLints ??= true;

// resolve top-level `collectTypeScriptInfo` options (stable API)
if (options.collectTypeScriptInfo) {
options.collectTypeScriptInfo = resolveCollectTypeScriptInfo(
options.collectTypeScriptInfo
);
}

// resolve `rspackExperiments.import` options
const { rspackExperiments } = options;
if (rspackExperiments) {
Expand All @@ -508,9 +515,17 @@ const getSwcLoaderOptions: GetLoaderOptions = (options, _) => {
);
}
if (rspackExperiments.collectTypeScriptInfo) {
rspackExperiments.collectTypeScriptInfo = resolveCollectTypeScriptInfo(
rspackExperiments.collectTypeScriptInfo
deprecate(
"`rspackExperiments.collectTypeScriptInfo` is deprecated and will be removed in Rspack v2.0. Use top-level `collectTypeScriptInfo` instead."
);
// If top-level is not set, use rspackExperiments config
if (!options.collectTypeScriptInfo) {
options.collectTypeScriptInfo = resolveCollectTypeScriptInfo(
rspackExperiments.collectTypeScriptInfo
);
}
// Remove from rspackExperiments to avoid duplication
delete rspackExperiments.collectTypeScriptInfo;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ function config(index, { concatenateModules } = {}) {
},
target: "esnext"
},
rspackExperiments: {
collectTypeScriptInfo: {
exportedEnum: true
}
collectTypeScriptInfo: {
exportedEnum: true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ module.exports = {
},
target: "esnext"
},
rspackExperiments: {
collectTypeScriptInfo: {
exportedEnum: true
}
collectTypeScriptInfo: {
exportedEnum: true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ module.exports = {
},
target: "esnext"
},
rspackExperiments: {
collectTypeScriptInfo: {
exportedEnum: "const-only"
}
collectTypeScriptInfo: {
exportedEnum: "const-only"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ module.exports = {
},
target: "esnext"
},
rspackExperiments: {
collectTypeScriptInfo: {
exportedEnum: true
}
collectTypeScriptInfo: {
exportedEnum: true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ module.exports = {
},
target: "esnext"
},
rspackExperiments: {
collectTypeScriptInfo: {
exportedEnum: true
}
collectTypeScriptInfo: {
exportedEnum: true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ module.exports = {
},
target: "esnext"
},
rspackExperiments: {
collectTypeScriptInfo: {
exportedEnum: true
}
collectTypeScriptInfo: {
exportedEnum: true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
entry: {
main: './index.js',
},
module: {
entry: {
main: './index.js',
},
module: {
rules: [
{
test: /\.ts/,
Expand All @@ -16,21 +16,19 @@ module.exports = {
syntax: "typescript",
}
},
rspackExperiments: {
collectTypeScriptInfo: {
exportedEnum: true,
},
collectTypeScriptInfo: {
exportedEnum: true,
},
},
},
],
},
],
},
optimization: {
concatenateModules: true,
},
experiments: {
inlineEnum: true,
}
},
optimization: {
concatenateModules: true,
},
experiments: {
inlineEnum: true,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ module.exports = {
},
target: "esnext"
},
rspackExperiments: {
collectTypeScriptInfo: {
exportedEnum: true
}
collectTypeScriptInfo: {
exportedEnum: true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ module.exports = {
},
target: "esnext"
},
rspackExperiments: {
collectTypeScriptInfo: {
exportedEnum: true
}
collectTypeScriptInfo: {
exportedEnum: true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ module.exports = {
},
target: "esnext"
},
rspackExperiments: {
collectTypeScriptInfo: {
exportedEnum: true
}
collectTypeScriptInfo: {
exportedEnum: true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ module.exports = /** @type {import("@rspack/core").Configuration} */ ({
syntax: "typescript"
}
},
rspackExperiments: {
collectTypeScriptInfo: {}
}
collectTypeScriptInfo: {}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ module.exports = /** @type {import("@rspack/core").Configuration} */ ({
syntax: "typescript"
}
},
rspackExperiments: {
collectTypeScriptInfo: {
typeExports: true
}
collectTypeScriptInfo: {
typeExports: true
}
}
}
Expand Down
31 changes: 29 additions & 2 deletions website/docs/en/config/deprecated-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@ This page lists configuration options that have been deprecated in Rspack.

These options are kept for backward compatibility only and should not be used in new projects.

## builtin:swc-loader rspackExperiments.collectTypeScriptInfo

<ApiMeta deprecatedVersion="1.7.0" />

Used to collect information from TypeScript's AST for consumption by subsequent Rspack processes.

:::warning
This configuration has been deprecated. Use top-level [`collectTypeScriptInfo`](/guide/features/builtin-swc-loader#collecttypescriptinfo) instead.

```diff
{
loader: 'builtin:swc-loader',
options: {
- rspackExperiments: {
- collectTypeScriptInfo: {
- exportedEnum: true,
- },
- },
+ collectTypeScriptInfo: {
+ exportedEnum: true,
+ },
},
}
```

:::

## experiments.topLevelAwait

- **Type:** `boolean`
Expand Down Expand Up @@ -125,7 +152,7 @@ This configuration has been deprecated and is no longer required. The inline exp
Used to enable inline optimization for TypeScript enums.

:::warning
This configuration has been deprecated and is no longer required. Inline enum optimization is now controlled by [`optimization.inlineExports`](/config/optimization#optimizationinlineexports) and [`builtin:swc-loader rspackExperiments.collectTypeScriptInfo.exportedEnum`](/guide/features/builtin-swc-loader#rspackexperimentscollecttypescriptinfoexportedenum).
This configuration has been deprecated and is no longer required. Inline enum optimization is now controlled by [`optimization.inlineExports`](/config/optimization#optimizationinlineexports) and [`builtin:swc-loader collectTypeScriptInfo.exportedEnum`](/guide/features/builtin-swc-loader#collecttypescriptinfoexportedenum).

Please refer to [inline enum example](https://github.com/rspack-contrib/rstack-examples/tree/main/rspack/inline-enum) for more details.
:::
Expand Down Expand Up @@ -159,7 +186,7 @@ For more details, see the [Lazy barrel guide](/guide/optimization/lazy-barrel).
Used to enable error tolerance for type re-exports.

:::warning
This configuration has been deprecated and is no longer required. Type re-exports presence checking is now controlled by [`module.parser.javascript.typeReexportsPresence`](/config/module#moduleparserjavascripttypereexportspresence) and [`builtin:swc-loader rspackExperiments.collectTypeScriptInfo.typeExports`](/guide/features/builtin-swc-loader#rspackexperimentscollecttypescriptinfotypeexports).
This configuration has been deprecated and is no longer required. Type re-exports presence checking is now controlled by [`module.parser.javascript.typeReexportsPresence`](/config/module#moduleparserjavascripttypereexportspresence) and [`builtin:swc-loader collectTypeScriptInfo.typeExports`](/guide/features/builtin-swc-loader#collecttypescriptinfotypeexports).

Please refer to [type reexports presence example](https://github.com/rspack-contrib/rstack-examples/tree/main/rspack/type-reexports-presence) for more details.
:::
Expand Down
Loading
Loading