Skip to content

Commit 2d78ee6

Browse files
authored
fix: properties of build meta should be optional when sending to dll plugin from javascript (#12070)
fix: should be optional when sending js build meta to dll plugin
1 parent 46a54da commit 2d78ee6

File tree

15 files changed

+60
-53
lines changed

15 files changed

+60
-53
lines changed

crates/node_binding/napi-binding.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,11 @@ export interface JsBeforeEmitData {
707707
}
708708

709709
export interface JsBuildMeta {
710-
strictEsmModule: boolean
711-
hasTopLevelAwait: boolean
712-
esm: boolean
713-
exportsType: 'unset' | 'default' | 'namespace' | 'flagged' | 'dynamic'
714-
defaultObject: 'false' | 'redirect' | JsBuildMetaDefaultObjectRedirectWarn
710+
strictEsmModule?: boolean
711+
hasTopLevelAwait?: boolean
712+
esm?: boolean
713+
exportsType?: undefined | 'unset' | 'default' | 'namespace' | 'flagged' | 'dynamic'
714+
defaultObject?: undefined | 'false' | 'redirect' | JsBuildMetaDefaultObjectRedirectWarn
715715
sideEffectFree?: boolean
716716
exportsFinalName?: Array<[string, string]> | undefined
717717
}

crates/rspack_binding_api/src/module.rs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -783,13 +783,13 @@ impl From<JsAddingRuntimeModule> for RuntimeModuleFromJs {
783783

784784
#[napi(object, object_to_js = false)]
785785
pub struct JsBuildMeta {
786-
pub strict_esm_module: bool,
787-
pub has_top_level_await: bool,
788-
pub esm: bool,
789-
#[napi(ts_type = "'unset' | 'default' | 'namespace' | 'flagged' | 'dynamic'")]
790-
pub exports_type: String,
791-
#[napi(ts_type = "'false' | 'redirect' | JsBuildMetaDefaultObjectRedirectWarn")]
792-
pub default_object: JsBuildMetaDefaultObject,
786+
pub strict_esm_module: Option<bool>,
787+
pub has_top_level_await: Option<bool>,
788+
pub esm: Option<bool>,
789+
#[napi(ts_type = "undefined | 'unset' | 'default' | 'namespace' | 'flagged' | 'dynamic'")]
790+
pub exports_type: Option<String>,
791+
#[napi(ts_type = "undefined | 'false' | 'redirect' | JsBuildMetaDefaultObjectRedirectWarn")]
792+
pub default_object: Option<JsBuildMetaDefaultObject>,
793793
pub side_effect_free: Option<bool>,
794794
#[napi(ts_type = "Array<[string, string]> | undefined")]
795795
pub exports_final_name: Option<Vec<Vec<String>>>,
@@ -807,24 +807,32 @@ impl From<JsBuildMeta> for BuildMeta {
807807
exports_type: raw_exports_type,
808808
} = value;
809809

810-
let default_object = match raw_default_object {
811-
Either::A(s) => match s.as_str() {
812-
"false" => BuildMetaDefaultObject::False,
813-
"redirect" => BuildMetaDefaultObject::Redirect,
814-
_ => unreachable!(),
815-
},
816-
Either::B(default_object) => BuildMetaDefaultObject::RedirectWarn {
817-
ignore: default_object.redirect_warn.ignore,
818-
},
810+
let default_object = if let Some(raw_default_object) = raw_default_object {
811+
match raw_default_object {
812+
Either::A(s) => match s.as_str() {
813+
"false" => BuildMetaDefaultObject::False,
814+
"redirect" => BuildMetaDefaultObject::Redirect,
815+
_ => unreachable!(),
816+
},
817+
Either::B(default_object) => BuildMetaDefaultObject::RedirectWarn {
818+
ignore: default_object.redirect_warn.ignore,
819+
},
820+
}
821+
} else {
822+
BuildMetaDefaultObject::False
819823
};
820824

821-
let exports_type = match raw_exports_type.as_str() {
822-
"unset" => BuildMetaExportsType::Unset,
823-
"default" => BuildMetaExportsType::Default,
824-
"namespace" => BuildMetaExportsType::Namespace,
825-
"flagged" => BuildMetaExportsType::Flagged,
826-
"dynamic" => BuildMetaExportsType::Dynamic,
827-
_ => unreachable!(),
825+
let exports_type = if let Some(raw_exports_type) = raw_exports_type {
826+
match raw_exports_type.as_str() {
827+
"unset" => BuildMetaExportsType::Unset,
828+
"default" => BuildMetaExportsType::Default,
829+
"namespace" => BuildMetaExportsType::Namespace,
830+
"flagged" => BuildMetaExportsType::Flagged,
831+
"dynamic" => BuildMetaExportsType::Dynamic,
832+
_ => unreachable!(),
833+
}
834+
} else {
835+
BuildMetaExportsType::Unset
828836
};
829837

830838
let exports_final_name = raw_exports_final_name.map(|exports_name| {
@@ -845,9 +853,9 @@ impl From<JsBuildMeta> for BuildMeta {
845853
});
846854

847855
Self {
848-
strict_esm_module,
849-
has_top_level_await,
850-
esm,
856+
strict_esm_module: strict_esm_module.unwrap_or_default(),
857+
has_top_level_await: has_top_level_await.unwrap_or_default(),
858+
esm: esm.unwrap_or_default(),
851859
exports_type,
852860
default_object,
853861
side_effect_free,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
module.exports = () => "FIXME: should not bail for optional modules, can be fixed by https://github.com/web-infra-dev/rspack/pull/10351, but it is too dirty"
2+
module.exports = () => "TODO: should not bail for optional modules, can be fixed by https://github.com/web-infra-dev/rspack/pull/10351, but it is too dirty"

tests/rspack-test/configCases/require/module-require/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { createRequire as __createRequire, builtinModules } from "module";
33

44
it("should evaluate require/createRequire", () => {
55
expect(
6-
(function() { return typeof _createRequire; }).toString()
6+
(function () { return typeof _createRequire; }).toString()
77
).toBe('function() { return "function"; }');
88
expect(
9-
(function() { if (typeof _createRequire); }).toString()
9+
(function () { if (typeof _createRequire); }).toString()
1010
).toBe('function() { if (true); }');
1111
const require = __createRequire(import.meta.url);
1212
expect(
13-
(function() { return typeof require; }).toString()
13+
(function () { return typeof require; }).toString()
1414
).toBe('function() { return "function"; }');
1515
expect(
16-
(function() { if (typeof require); }).toString()
16+
(function () { if (typeof require); }).toString()
1717
).toBe('function() { if (true); }');
1818
});
1919

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
module.exports = () => "FIXME: missing warnings"
2+
module.exports = () => "TODO: support parsing createRequire in CommonJsImportsParserPlugin"

tests/rspack-test/configCases/resolve-merging/override/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ it("should allow to override in loader", () => {
3535
});
3636

3737
it("should allow to use custom dependencyType", () => {
38-
expect(d).toBe("style");
39-
expect(e).toBe("default");
38+
// TODO: should support using custom dependencyType in loaderContext.getResolve
39+
// expect(d).toBe("style");
40+
// expect(e).toBe("default");
4041
});
4142

4243
it("should allow to alias 'byDependency'", () => {

tests/rspack-test/configCases/resolve-merging/override/test.filter.js

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
module.exports = () => "FIXME: expect loader not matched"
2+
module.exports = () => "TODO: support rule match by compiler name"

tests/rspack-test/configCases/rule-set/custom/rspack.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module.exports = {
77
use: function (data) {
88
return {
99
loader: "./loader",
10+
// DIFF: need to use ident to identify the loader options
11+
ident: data.resource,
1012
options: {
1113
resource: data.resource.replace(/^.*[\\/]/g, ""),
1214
resourceQuery: data.resourceQuery,

tests/rspack-test/configCases/rule-set/custom/test.filter.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)