Skip to content
Draft
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
112 changes: 56 additions & 56 deletions crates/node_binding/napi-binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

/* -- banner.d.ts -- */
export type JsFilename =
| string
| ((pathData: JsPathData, assetInfo?: AssetInfo) => string);
| string
| ((pathData: JsPathData, assetInfo?: AssetInfo) => string);

export type RawLazyCompilationTest = RegExp | ((module: Module) => boolean);

Expand All @@ -26,45 +26,45 @@ export const COMMIT_CUSTOM_FIELDS_SYMBOL: unique symbol;
export const RUST_ERROR_SYMBOL: unique symbol;

interface KnownBuildInfo {
[BUILD_INFO_ASSETS_SYMBOL]: Assets,
[BUILD_INFO_FILE_DEPENDENCIES_SYMBOL]: string[],
[BUILD_INFO_CONTEXT_DEPENDENCIES_SYMBOL]: string[],
[BUILD_INFO_MISSING_DEPENDENCIES_SYMBOL]: string[],
[BUILD_INFO_BUILD_DEPENDENCIES_SYMBOL]: string[],
[COMMIT_CUSTOM_FIELDS_SYMBOL](): void;
[BUILD_INFO_ASSETS_SYMBOL]: Assets,
[BUILD_INFO_FILE_DEPENDENCIES_SYMBOL]: string[],
[BUILD_INFO_CONTEXT_DEPENDENCIES_SYMBOL]: string[],
[BUILD_INFO_MISSING_DEPENDENCIES_SYMBOL]: string[],
[BUILD_INFO_BUILD_DEPENDENCIES_SYMBOL]: string[],
[COMMIT_CUSTOM_FIELDS_SYMBOL](): void;
}

export type BuildInfo = KnownBuildInfo & Record<string, any>;

export interface Module {
[MODULE_IDENTIFIER_SYMBOL]: string;
readonly type: string;
get context(): string | undefined;
get layer(): string | undefined;
get factoryMeta(): JsFactoryMeta
set factoryMeta(factoryMeta: JsFactoryMeta);
get useSourceMap(): boolean;
get useSimpleSourceMap(): boolean;
buildInfo: BuildInfo;
buildMeta: Record<string, any>;
[MODULE_IDENTIFIER_SYMBOL]: string;
readonly type: string;
get context(): string | undefined;
get layer(): string | undefined;
get factoryMeta(): JsFactoryMeta
set factoryMeta(factoryMeta: JsFactoryMeta);
get useSourceMap(): boolean;
get useSimpleSourceMap(): boolean;
buildInfo: BuildInfo;
buildMeta: Record<string, any>;
}

interface NormalModuleConstructor {
new(): NormalModule;
readonly prototype: NormalModule;
new(): NormalModule;
readonly prototype: NormalModule;
}

export var NormalModule: NormalModuleConstructor;

export interface NormalModule extends Module {
readonly resource: string;
readonly request: string;
readonly userRequest: string;
readonly rawRequest: string;
readonly resourceResolveData: Readonly<JsResourceData> | undefined;
readonly loaders: JsLoaderItem[];
get matchResource(): string | undefined;
set matchResource(val: string | undefined);
readonly resource: string;
readonly request: string;
readonly userRequest: string;
readonly rawRequest: string;
readonly resourceResolveData: Readonly<JsResourceData> | undefined;
readonly loaders: JsLoaderItem[];
get matchResource(): string | undefined;
set matchResource(val: string | undefined);
}

export interface ConcatenatedModule extends Module {
Expand All @@ -74,19 +74,19 @@ export interface ContextModule extends Module {
}

export interface ExternalModule extends Module {
readonly userRequest: string;
readonly userRequest: string;
}

export interface RspackError extends Error {
name: string;
message: string;
details?: string;
module?: null | Module;
loc?: DependencyLocation;
file?: string;
stack?: string;
hideStack?: boolean;
error?: Error;
name: string;
message: string;
details?: string;
module?: null | Module;
loc?: DependencyLocation;
file?: string;
stack?: string;
hideStack?: boolean;
error?: Error;
}

export type DependencyLocation = SyntheticDependencyLocation | RealDependencyLocation;
Expand Down Expand Up @@ -386,7 +386,7 @@ export declare class JsExportsInfo {
isUsed(runtime: string | string[] | undefined): boolean
isModuleUsed(runtime: string | string[] | undefined): boolean
setUsedInUnknownWay(runtime: string | string[] | undefined): boolean
getUsed(name: string | string[], runtime: string | string[] | undefined): 0 | 1 | 2 | 3 | 4
getUsed(name: string | string[], runtime: string | string[] | undefined): 0 | 1 | 2 | 3 | 4
}

export declare class JsModuleGraph {
Expand Down Expand Up @@ -443,7 +443,7 @@ export declare class ModuleGraphConnection {

export declare class NativeWatcher {
constructor(options: NativeWatcherOptions)
watch(files: [Array<string>, Array<string>], directories: [Array<string>, Array<string>], missing: [Array<string>, Array<string>], callback: (err: Error | null, result: NativeWatchResult) => void, callbackUndelayed: (path: string) => void): void
watch(files: [Array<string>, Array<string>], directories: [Array<string>, Array<string>], missing: [Array<string>, Array<string>], callback: (err: Error | null, result: NativeWatchResult) => void, callbackUndelayed: (type: 'change' | 'remove', path: string, mtime?: number) => void): void
triggerEvent(kind: 'change' | 'remove' | 'create', path: string): void
/**
* # Safety
Expand Down Expand Up @@ -1969,7 +1969,7 @@ export interface RawCopyPattern {
* Allows to modify the file contents.
* @default undefined
*/
transform?: { transformer: (input: Buffer, absoluteFilename: string) => string | Buffer | Promise<string> | Promise<Buffer> } | ((input: Buffer, absoluteFilename: string) => string | Buffer | Promise<string> | Promise<Buffer>)
transform?: { transformer: (input: Buffer, absoluteFilename: string) => string | Buffer | Promise<string> | Promise<Buffer> } | ((input: Buffer, absoluteFilename: string) => string | Buffer | Promise<string> | Promise<Buffer>)
}

export interface RawCopyRspackPluginOptions {
Expand Down Expand Up @@ -2106,22 +2106,22 @@ export interface RawExperimentCacheOptionsPersistent {
export interface RawExperiments {
layers: boolean
topLevelAwait: boolean
incremental?: false | { [key: string]: boolean }
parallelCodeSplitting: boolean
rspackFuture?: RawRspackFuture
cache: boolean | { type: "persistent" } & RawExperimentCacheOptionsPersistent | { type: "memory" }
useInputFileSystem?: false | Array<RegExp>
css?: boolean
inlineConst: boolean
inlineEnum: boolean
typeReexportsPresence: boolean
lazyBarrel: boolean
incremental?: false | { [key: string]: boolean }
parallelCodeSplitting: boolean
rspackFuture?: RawRspackFuture
cache: boolean | { type: "persistent" } & RawExperimentCacheOptionsPersistent | { type: "memory" }
useInputFileSystem?: false | Array<RegExp>
css?: boolean
inlineConst: boolean
inlineEnum: boolean
typeReexportsPresence: boolean
lazyBarrel: boolean
}

export interface RawExperimentSnapshotOptions {
immutablePaths: Array<string|RegExp>
unmanagedPaths: Array<string|RegExp>
managedPaths: Array<string|RegExp>
immutablePaths: Array<string | RegExp>
unmanagedPaths: Array<string | RegExp>
managedPaths: Array<string | RegExp>
}

export interface RawExposeOptions {
Expand Down Expand Up @@ -2349,7 +2349,7 @@ export interface RawJsonParserOptions {
}

export interface RawLazyCompilationOption {
currentActiveModules: ((err: Error | null, ) => Set<string>)
currentActiveModules: ((err: Error | null,) => Set<string>)
test?: RawLazyCompilationTest
entries: boolean
imports: boolean
Expand Down Expand Up @@ -2857,7 +2857,7 @@ export interface RealDependencyLocation {
* Author Donny/강동윤
* Copyright (c)
*/
export declare function registerGlobalTrace(filter: string, layer: "logger" | "perfetto" , output: string): void
export declare function registerGlobalTrace(filter: string, layer: "logger" | "perfetto", output: string): void

export declare enum RegisterJsTapKind {
CompilerThisCompilation = 0,
Expand Down
28 changes: 21 additions & 7 deletions crates/rspack_binding_api/src/native_watcher.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::{
alloc::System,
Copy link
Preview

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The alloc::System import appears to be unused. This import should be removed to avoid clutter.

Suggested change
alloc::System,

Copilot uses AI. Check for mistakes.

boxed::Box,
path::{Path, PathBuf},
time::SystemTime,
};

use napi::bindgen_prelude::*;
use napi::{JsUndefined, bindgen_prelude::*};
Copy link
Preview

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The JsUndefined import appears to be unused. This import should be removed to avoid clutter.

Suggested change
use napi::{JsUndefined, bindgen_prelude::*};
use napi::bindgen_prelude::*;

Copilot uses AI. Check for mistakes.

use napi_derive::*;
use rspack_fs::{FsEventKind, FsWatcher, FsWatcherIgnored, FsWatcherOptions};
use rspack_paths::ArcPath;
Expand Down Expand Up @@ -78,7 +80,8 @@
missing: (Vec<String>, Vec<String>),
#[napi(ts_arg_type = "(err: Error | null, result: NativeWatchResult) => void")]
callback: Function<'static>,
#[napi(ts_arg_type = "(path: string) => void")] callback_undelayed: Function<'static>,
#[napi(ts_arg_type = "(type: 'change' | 'remove', path: string, mtime?: number) => void")]
callback_undelayed: Function<'static>,
env: Env,
) -> napi::Result<()> {
if self.closed {
Expand Down Expand Up @@ -215,10 +218,10 @@
}

struct JsEventHandlerUndelayed {
inner: napi::threadsafe_function::ThreadsafeFunction<

Check failure on line 221 in crates/rspack_binding_api/src/native_watcher.rs

View workflow job for this annotation

GitHub Actions / Run Rust Tests / Rust check

very complex type used. Consider factoring parts into `type` definitions
String,
(String, String, Option<u64>),
napi::Unknown<'static>,
String,
(String, String, Option<u64>),
Status,
false,
false,
Expand All @@ -229,7 +232,7 @@
impl JsEventHandlerUndelayed {
fn new(callback: Function<'static>) -> napi::Result<Self> {
let callback = callback
.build_threadsafe_function::<String>()
.build_threadsafe_function::<(String, String, Option<u64>)>()
.weak::<false>()
.max_queue_size::<1>()
.build_callback(
Expand All @@ -241,9 +244,20 @@
}

impl rspack_fs::EventHandler for JsEventHandlerUndelayed {
fn on_change(&self, changed_file: String) -> rspack_error::Result<()> {
fn on_change(&self, changed_file: String, mtime: Option<SystemTime>) -> rspack_error::Result<()> {
let mtime = mtime
.and_then(|m| m.duration_since(SystemTime::UNIX_EPOCH).ok())
.map(|d| d.as_millis() as u64);
self.inner.call(
changed_file,
("change".to_string(), changed_file, mtime).into(),

Check failure on line 252 in crates/rspack_binding_api/src/native_watcher.rs

View workflow job for this annotation

GitHub Actions / Run Rust Tests / Rust check

useless conversion to the same type: `(std::string::String, std::string::String, std::option::Option<u64>)`
napi::threadsafe_function::ThreadsafeFunctionCallMode::NonBlocking,
);
Ok(())
}

fn on_remove(&self, _removed_file: String) -> rspack_error::Result<()> {
self.inner.call(
("remove".to_string(), _removed_file, None).into(),

Check failure on line 260 in crates/rspack_binding_api/src/native_watcher.rs

View workflow job for this annotation

GitHub Actions / Run Rust Tests / Rust check

useless conversion to the same type: `(std::string::String, std::string::String, std::option::Option<u64>)`
napi::threadsafe_function::ThreadsafeFunctionCallMode::NonBlocking,
);
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_fs/src/watcher/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ fn create_execute_task(
let path = event.path.to_string_lossy().to_string();
match event.kind {
super::FsEventKind::Change | super::FsEventKind::Create => {
if event_handler.on_change(path).is_err() {
if event_handler.on_change(path, None).is_err() {
break;
}
}
super::FsEventKind::Remove => {
if event_handler.on_delete(path).is_err() {
if event_handler.on_remove(path).is_err() {
break;
}
}
Expand Down
10 changes: 7 additions & 3 deletions crates/rspack_fs/src/watcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod paths;
mod scanner;
mod trigger;

use std::sync::Arc;
use std::{sync::Arc, time::SystemTime};

use analyzer::{Analyzer, RecommendedAnalyzer};
use disk_watcher::DiskWatcher;
Expand Down Expand Up @@ -61,12 +61,16 @@ pub trait EventAggregateHandler {
/// It provides methods to handle changes and deletions of files.
pub trait EventHandler {
/// Handle a change in a file.
fn on_change(&self, _changed_file: String) -> rspack_error::Result<()> {
fn on_change(
&self,
_changed_file: String,
_mtime: Option<SystemTime>,
) -> rspack_error::Result<()> {
Ok(())
}

/// Handle a deletion of a file.
fn on_delete(&self, _deleted_file: String) -> rspack_error::Result<()> {
fn on_remove(&self, _removed_file: String) -> rspack_error::Result<()> {
Ok(())
}
}
Expand Down
12 changes: 12 additions & 0 deletions packages/rspack/etc/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8986,6 +8986,18 @@ type WatchFiles = {

// @public (undocumented)
interface WatchFileSystem {
// (undocumented)
emit?(event: 'change', filepath: string, mtime: number): boolean;
// (undocumented)
emit?(event: 'remove', filepath: string): boolean;
// (undocumented)
on?(event: 'change', listener: (filepath: string, mtime: number) => void): this;
// (undocumented)
on?(event: 'remove', listener: (filepath: string) => void): this;
// (undocumented)
once?(event: 'change', listener: (filepath: string, mtime: number) => void): this;
// (undocumented)
once?(event: 'remove', listener: (filepath: string) => void): this;
// (undocumented)
watch(files: Iterable<string> & {
added?: Iterable<String>;
Expand Down
Loading
Loading