Skip to content

Commit 1235f70

Browse files
committed
chore: update
1 parent 21028d1 commit 1235f70

File tree

15 files changed

+141
-25
lines changed

15 files changed

+141
-25
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/node_binding/binding.d.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,17 @@ export interface JsTap {
11061106
stage: number
11071107
}
11081108

1109+
export interface NodeFsStats {
1110+
isFile: boolean
1111+
isDirectory: boolean
1112+
isSymlink: boolean
1113+
atimeMs: number
1114+
mtimeMs: number
1115+
ctimeMs: number
1116+
birthtimeMs: number
1117+
size: number
1118+
}
1119+
11091120
export interface PathWithInfo {
11101121
path: string
11111122
info: JsAssetInfo
@@ -2131,3 +2142,23 @@ export interface RegisterJsTaps {
21312142
registerHtmlPluginBeforeEmitTaps: (stages: Array<number>) => Array<{ function: ((arg: JsBeforeEmitData) => JsBeforeEmitData); stage: number; }>
21322143
registerHtmlPluginAfterEmitTaps: (stages: Array<number>) => Array<{ function: ((arg: JsAfterEmitData) => JsAfterEmitData); stage: number; }>
21332144
}
2145+
2146+
export interface ThreadsafeNodeFS {
2147+
writeFile: (name: string, content: Buffer) => Promise<void>
2148+
removeFile: (name: string) => Promise<void>
2149+
mkdir: (name: string) => Promise<void>
2150+
mkdirp: (name: string) => Promise<string | void>
2151+
removeDirAll: (name: string) => Promise<string | void>
2152+
readDir: (name: string) => Promise<string[] | void>
2153+
readFile: (name: string) => Promise<Buffer | string | void>
2154+
stat: (name: string) => Promise<NodeFsStats | void>
2155+
lstat: (name: string) => Promise<NodeFsStats | void>
2156+
open: (name: string, flags: string) => Promise<number | void>
2157+
rename: (from: string, to: string) => Promise<void>
2158+
close: (fd: number) => Promise<void>
2159+
write: (fd: number, content: Buffer, position: number) => Promise<number | void>
2160+
writeAll: (fd: number, content: Buffer) => Promise<number | void>
2161+
read: (fd: number, length: number, position: number) => Promise<Buffer | void>
2162+
readUntil: (fd: number, code: number, position: number) => Promise<Buffer | void>
2163+
readToEnd: (fd: number, position: number) => Promise<Buffer | void>
2164+
}

crates/rspack_plugin_asset/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ version = "0.2.0"
99

1010
[dependencies]
1111
async-trait = { workspace = true }
12-
cow-utils = { workspace = true }
1312
mime_guess = { workspace = true }
1413
rayon = { workspace = true }
1514
rspack_base64 = { workspace = true }

crates/rspack_plugin_asset/src/asset_exports_dependency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rspack_core::{
66
};
77

88
#[cacheable]
9-
#[derive(Debug, Clone)]
9+
#[derive(Debug, Clone, Default)]
1010
pub struct AssetExportsDependency {
1111
id: DependencyId,
1212
}

crates/rspack_plugin_asset/src/lib.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -562,19 +562,16 @@ impl ParserAndGenerator for AssetParserAndGenerator {
562562

563563
if experimental_lib_preserve_import {
564564
let is_module = compilation.options.output.module;
565-
if is_module {
566-
if let Some(ref mut scope) = generate_context.concatenation_scope {
567-
scope.register_namespace_export(NAMESPACE_OBJECT_EXPORT);
565+
if let Some(ref mut scope) = generate_context.concatenation_scope {
566+
scope.register_namespace_export(NAMESPACE_OBJECT_EXPORT);
567+
if is_module {
568568
return Ok(
569569
RawStringSource::from(format!(
570570
r#"import {NAMESPACE_OBJECT_EXPORT} from {exported_content};"#
571571
))
572572
.boxed(),
573573
);
574-
}
575-
} else {
576-
if let Some(ref mut scope) = generate_context.concatenation_scope {
577-
scope.register_namespace_export(NAMESPACE_OBJECT_EXPORT);
574+
} else {
578575
let supports_const = compilation.options.output.environment.supports_const();
579576
let declaration_kind = if supports_const { "const" } else { "var" };
580577
return Ok(
@@ -583,15 +580,15 @@ impl ParserAndGenerator for AssetParserAndGenerator {
583580
))
584581
.boxed(),
585582
);
586-
} else {
587-
generate_context
588-
.runtime_requirements
589-
.insert(RuntimeGlobals::MODULE);
590-
return Ok(
591-
RawStringSource::from(format!(r#"module.exports = require({exported_content});"#))
592-
.boxed(),
593-
);
594583
}
584+
} else {
585+
generate_context
586+
.runtime_requirements
587+
.insert(RuntimeGlobals::MODULE);
588+
return Ok(
589+
RawStringSource::from(format!(r#"module.exports = require({exported_content});"#))
590+
.boxed(),
591+
);
595592
}
596593
};
597594

crates/rspack_plugin_javascript/src/plugin/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@ impl JsPlugin {
800800
})
801801
}
802802

803+
#[allow(clippy::too_many_arguments)]
803804
pub fn get_renamed_inline_module(
804805
&self,
805806
all_modules: &[&BoxModule],

crates/rspack_plugin_javascript/src/runtime.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ pub fn render_module(
106106
.match_indices(AUTO_PUBLIC_PATH_PLACEHOLDER)
107107
.map(|(index, _)| (index, index + len))
108108
.collect();
109-
dbg!(&auto_public_path_matches);
110109
if !auto_public_path_matches.is_empty() {
111110
let mut replace = ReplaceSource::new(origin_source.clone());
112111
for (start, end) in auto_public_path_matches {
113-
let relative = PublicPath::render_auto_public_path(compilation, output_path);
112+
let mut relative = PublicPath::render_auto_public_path(compilation, output_path);
113+
if relative.is_empty() {
114+
relative = String::from("./");
115+
}
114116
replace.replace(start as u32, end as u32, &relative, None);
115117
}
116118
RenderSource {
76.3 KB
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import IMG from "./img.png";
2+
IMG;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const assert = require("assert");
2+
3+
/** @type {import("@rspack/core").Configuration} */
4+
module.exports = {
5+
context: __dirname,
6+
entry: {
7+
index: './img.png'
8+
},
9+
module: {
10+
rules: [
11+
{
12+
test: /\.png$/,
13+
type: "asset/resource",
14+
generator: {
15+
experimentalLibPreserveImport: true
16+
}
17+
}
18+
]
19+
},
20+
plugins: [
21+
new (class {
22+
apply(compiler) {
23+
compiler.hooks.compilation.tap("MyPlugin", compilation => {
24+
compilation.hooks.processAssets.tap("MyPlugin", assets => {
25+
let list = Object.keys(assets);
26+
const js = list.find(item => item.endsWith("js"));
27+
const jsContent = assets[js].source().toString();
28+
console.log(jsContent)
29+
assert(/require\(['"]\.\/(\w*)\.png['"]\)/.test(jsContent))
30+
})
31+
});
32+
}
33+
})()
34+
]
35+
};

0 commit comments

Comments
 (0)