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: the missing part of loader #6753

Merged
merged 1 commit into from
Jun 12, 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
14 changes: 12 additions & 2 deletions Cargo.lock

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

91 changes: 33 additions & 58 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ export function __chunk_inner_is_only_initial(jsChunkUkey: number, compilation:

export function __entrypoint_inner_get_runtime_chunk(ukey: number, compilation: JsCompilation): JsChunk

export function __loader_item_debug(item: ExternalObject<'LoaderItem'>): string

export function __loader_item_get_loader_data(item: ExternalObject<'LoaderItem'>): any

export function __loader_item_get_normal_executed(item: ExternalObject<'LoaderItem'>): boolean

export function __loader_item_get_pitch_executed(item: ExternalObject<'LoaderItem'>): boolean

export function __loader_item_set_loader_data(item: ExternalObject<'LoaderItem'>, data: any): void

export function __loader_item_set_normal_executed(item: ExternalObject<'LoaderItem'>): void

export function __loader_item_set_pitch_executed(item: ExternalObject<'LoaderItem'>): void

export interface BuiltinPlugin {
name: BuiltinPluginName
options: unknown
Expand Down Expand Up @@ -357,66 +371,35 @@ export interface JsExecuteModuleResult {
}

export interface JsLoaderContext {
resourceData: Readonly<JsResourceData>
/** Will be deprecated. Use module.module_identifier instead */
_moduleIdentifier: Readonly<string>
_module: JsModule
hot: Readonly<boolean>
/** Content maybe empty in pitching stage */
content: null | Buffer
additionalData?: any
sourceMap?: Buffer
resource: string
resourcePath: string
resourceQuery?: string
resourceFragment?: string
cacheable: boolean
fileDependencies: Array<string>
contextDependencies: Array<string>
missingDependencies: Array<string>
buildDependencies: Array<string>
assetFilenames: Array<string>
currentLoader: string
isPitching: boolean
/**
* Loader index from JS.
* If loaders are dispatched by JS loader runner,
* then, this field is correspondence with loader index in JS side.
* It is useful when loader dispatched on JS side has an builtin loader, for example: builtin:swc-loader,
* Then this field will be used as an hack to test whether it should return an AST or string.
*/
loaderIndexFromJs?: number
/**
* Internal additional data, contains more than `String`
* @internal
*/
additionalDataExternal: ExternalObject<'AdditionalData'>
/**
* Internal loader context
* @internal
*/
contextExternal: ExternalObject<'LoaderRunnerContext'>
/**
* Internal loader diagnostic
* @internal
*/
diagnosticsExternal: ExternalObject<'Diagnostic[]'>
/** Will be deprecated. Use module.module_identifier instead */
_moduleIdentifier: string
_module: JsModule
hot: boolean
loaderItems: Array<JsLoaderItem>
loaderIndex: number
loaderState: Readonly<JsLoaderState>
}

/** Only for dts generation */
export interface JsLoaderResult {
/** Content in pitching stage can be empty */
content?: Buffer
fileDependencies: Array<string>
contextDependencies: Array<string>
missingDependencies: Array<string>
buildDependencies: Array<string>
assetFilenames: Array<string>
sourceMap?: Buffer
additionalData?: Buffer
additionalDataExternal: ExternalObject<'AdditionalData'>
cacheable: boolean
/** Used to instruct how rust loaders should execute */
isPitching: boolean
export interface JsLoaderItem {
request: string
type: string
inner: ExternalObject<'LoaderItem'>
}

export enum JsLoaderState {
Pitching = 'Pitching',
Normal = 'Normal'
}

export interface JsModule {
Expand Down Expand Up @@ -1100,7 +1083,7 @@ export interface RawModuleRule {
resourceFragment?: RawRuleSetCondition
descriptionData?: Record<string, RawRuleSetCondition>
sideEffects?: boolean
use?: RawModuleRuleUses
use?: RawModuleRuleUse[] | ((arg: RawFuncUseCtx) => RawModuleRuleUse[])
type?: string
parser?: RawParserOptions
generator?: RawGeneratorOptions
Expand Down Expand Up @@ -1129,12 +1112,6 @@ export interface RawModuleRuleUse {
options?: string
}

export interface RawModuleRuleUses {
type: "array" | "function"
arrayUse?: Array<RawModuleRuleUse>
funcUse?: (arg: RawFuncUseCtx) => RawModuleRuleUse[]
}

export interface RawNodeOption {
dirname: string
filename: string
Expand Down Expand Up @@ -1168,6 +1145,7 @@ export interface RawOptions {
node?: RawNodeOption
profile: boolean
bail: boolean
__references: Record<string, any>
}

export interface RawOutputOptions {
Expand Down Expand Up @@ -1486,9 +1464,6 @@ export interface RegisterJsTaps {
registerContextModuleFactoryAfterResolveTaps: (stages: Array<number>) => Array<{ function: ((arg: false | JsContextModuleFactoryAfterResolveData) => Promise<false | JsContextModuleFactoryAfterResolveData>); stage: number; }>
}

/** Builtin loader runner */
export function runBuiltinLoader(builtin: string, options: string | undefined | null, loaderContext: JsLoaderContext): Promise<JsLoaderContext>

export interface ThreadsafeNodeFS {
writeFile: (name: string, content: Buffer) => Promise<void> | void
removeFile: (name: string) => Promise<void> | void
Expand Down
2 changes: 0 additions & 2 deletions crates/node_binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ use rspack_error::Diagnostic;
use rspack_fs_node::{AsyncNodeWritableFileSystem, ThreadsafeNodeFS};

mod compiler;
mod loader;
mod panic;
mod plugins;

pub use loader::run_builtin_loader;
use plugins::*;
use rspack_binding_options::*;
use rspack_binding_values::*;
Expand Down
12 changes: 0 additions & 12 deletions crates/node_binding/src/loader.rs

This file was deleted.

1 change: 1 addition & 0 deletions crates/rspack_binding_options/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ rspack_loader_preact_refresh = { path = "../rspack_loader_preact_refres
rspack_loader_react_refresh = { path = "../rspack_loader_react_refresh" }
rspack_loader_runner = { path = "../rspack_loader_runner" }
rspack_loader_swc = { path = "../rspack_loader_swc" }
rspack_loader_testing = { path = "../rspack_loader_testing" }
rspack_napi = { path = "../rspack_napi" }
rspack_plugin_asset = { path = "../rspack_plugin_asset" }
rspack_plugin_banner = { path = "../rspack_plugin_banner" }
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_binding_options/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
mod options;
mod plugins;
pub use options::*;
pub(crate) use plugins::*;
5 changes: 4 additions & 1 deletion crates/rspack_binding_options/src/options/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use napi_derive::napi;
use rspack_core::{
CacheOptions, CompilerOptions, Context, Experiments, IncrementalRebuild,
IncrementalRebuildMakeState, ModuleOptions, OutputOptions, Target,
IncrementalRebuildMakeState, ModuleOptions, OutputOptions, References, Target,
};

mod raw_builtins;
Expand Down Expand Up @@ -58,6 +58,8 @@ pub struct RawOptions {
pub node: Option<RawNodeOption>,
pub profile: bool,
pub bail: bool,
#[napi(js_name = "__references", ts_type = "Record<string, any>")]
pub __references: References,
}

impl TryFrom<RawOptions> for CompilerOptions {
Expand Down Expand Up @@ -107,6 +109,7 @@ impl TryFrom<RawOptions> for CompilerOptions {
profile: value.profile,
bail: value.bail,
builtins: Default::default(),
__references: value.__references,
})
}
}
8 changes: 3 additions & 5 deletions crates/rspack_binding_options/src/options/raw_builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ use self::{
raw_size_limits::RawSizeLimitsPluginOptions,
};
use crate::{
plugins::{CssExtractRspackAdditionalDataPlugin, JsLoaderResolverPlugin},
plugins::{CssExtractRspackAdditionalDataPlugin, JsLoaderRspackPlugin},
JsLoaderRunner, RawDynamicEntryPluginOptions, RawEntryPluginOptions,
RawEvalDevToolModulePluginOptions, RawExternalItemWrapper, RawExternalsPluginOptions,
RawHttpExternalsRspackPluginOptions, RawSourceMapDevToolPluginOptions, RawSplitChunksOptions,
Expand Down Expand Up @@ -473,11 +473,9 @@ impl BuiltinPlugin {
.boxed();
plugins.push(plugin);
}
// rspack js adapter plugins
BuiltinPluginName::JsLoaderRspackPlugin => {
plugins.push(
JsLoaderResolverPlugin::new(downcast_into::<JsLoaderRunner>(self.options)?).boxed(),
);
plugins
.push(JsLoaderRspackPlugin::new(downcast_into::<JsLoaderRunner>(self.options)?).boxed());
}
BuiltinPluginName::LazyCompilationPlugin => {
let options = downcast_into::<RawLazyCompilationOption>(self.options)?;
Expand Down
Loading
Loading