From 2e7f4f905b46342aa80dd37c232272d63ac4c2b9 Mon Sep 17 00:00:00 2001 From: ADNY <66500121+ErKeLost@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:36:22 +0800 Subject: [PATCH] chore: remove `query_string` when `emit_file` to `resource_map` in `plugin_static_assets` (#1746) * chore: remove query when emit_file to source_map in plugin_static_assets * chore: update test --- .changeset/mighty-hairs-warn.md | 5 +++++ .changeset/thick-bats-provide.md | 5 +++++ .../absolute_public_path/lit_str/output.js | 4 ++-- .../relative_public_path/tip/complate/output.js | 4 ++-- .../relative_public_path/tip/normal/output.js | 6 +++--- .../relative_public_path/tip/tip_star_star/output.js | 4 ++-- crates/plugin_static_assets/src/lib.rs | 6 +++++- js-plugins/dts/src/context.ts | 1 - 8 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 .changeset/mighty-hairs-warn.md create mode 100644 .changeset/thick-bats-provide.md diff --git a/.changeset/mighty-hairs-warn.md b/.changeset/mighty-hairs-warn.md new file mode 100644 index 000000000..362a601d6 --- /dev/null +++ b/.changeset/mighty-hairs-warn.md @@ -0,0 +1,5 @@ +--- +"@farmfe/js-plugin-dts": patch +--- + +remove console diff --git a/.changeset/thick-bats-provide.md b/.changeset/thick-bats-provide.md new file mode 100644 index 000000000..4706a3a5a --- /dev/null +++ b/.changeset/thick-bats-provide.md @@ -0,0 +1,5 @@ +--- +"@farmfe/core": patch +--- + +plugin_static_assets emit resource_map remove query diff --git a/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/absolute_public_path/lit_str/output.js b/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/absolute_public_path/lit_str/output.js index 35846f8cf..986117116 100644 --- a/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/absolute_public_path/lit_str/output.js +++ b/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/absolute_public_path/lit_str/output.js @@ -1,4 +1,4 @@ -//foo-276e63.txt?url: +//foo-276e63.txt: foo //index.js: @@ -79,4 +79,4 @@ module._m(exports); exports.default = "/foo-276e63.txt?url"; } -,});window['__farm_default_namespace__'].__farm_module_system__.setInitialLoadedResources([]);window['__farm_default_namespace__'].__farm_module_system__.setDynamicModuleResourcesMap([],{ });var farmModuleSystem = window['__farm_default_namespace__'].__farm_module_system__;farmModuleSystem.bootstrap();var entry = farmModuleSystem.require("b5d64806"); \ No newline at end of file +,});window['__farm_default_namespace__'].__farm_module_system__.setInitialLoadedResources([]);window['__farm_default_namespace__'].__farm_module_system__.setDynamicModuleResourcesMap([],{ });var farmModuleSystem = window['__farm_default_namespace__'].__farm_module_system__;farmModuleSystem.bootstrap();var entry = farmModuleSystem.require("b5d64806"); diff --git a/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/relative_public_path/tip/complate/output.js b/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/relative_public_path/tip/complate/output.js index 6b650d84c..b1f5c09b3 100644 --- a/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/relative_public_path/tip/complate/output.js +++ b/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/relative_public_path/tip/complate/output.js @@ -1,4 +1,4 @@ -//foo_bar-47689c.txt?url: +//foo_bar-47689c.txt: foo_bar //index.js: @@ -90,4 +90,4 @@ "./foo/bar/foo_bar.txt": module.f(_f_foo_bar) }["./foo/**/*/**"], module.meta.url); } -,});window['__farm_default_namespace__'].__farm_module_system__.setInitialLoadedResources([]);window['__farm_default_namespace__'].__farm_module_system__.setDynamicModuleResourcesMap([],{ });var farmModuleSystem = window['__farm_default_namespace__'].__farm_module_system__;farmModuleSystem.bootstrap();var entry = farmModuleSystem.require("b5d64806"); \ No newline at end of file +,});window['__farm_default_namespace__'].__farm_module_system__.setInitialLoadedResources([]);window['__farm_default_namespace__'].__farm_module_system__.setDynamicModuleResourcesMap([],{ });var farmModuleSystem = window['__farm_default_namespace__'].__farm_module_system__;farmModuleSystem.bootstrap();var entry = farmModuleSystem.require("b5d64806"); diff --git a/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/relative_public_path/tip/normal/output.js b/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/relative_public_path/tip/normal/output.js index 22c85ee01..8510f2177 100644 --- a/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/relative_public_path/tip/normal/output.js +++ b/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/relative_public_path/tip/normal/output.js @@ -1,7 +1,7 @@ -//bar-a57e94.txt?url: +//bar-a57e94.txt: bar -//foo-8bdf4c.txt?url: +//foo-8bdf4c.txt: foo //index.js: @@ -94,4 +94,4 @@ "./foo/foo.txt": module.f(_f_foo) }[`./foo/${foo}`], module.meta.url)); } -,});window['__farm_default_namespace__'].__farm_module_system__.setInitialLoadedResources([]);window['__farm_default_namespace__'].__farm_module_system__.setDynamicModuleResourcesMap([],{ });var farmModuleSystem = window['__farm_default_namespace__'].__farm_module_system__;farmModuleSystem.bootstrap();var entry = farmModuleSystem.require("b5d64806"); \ No newline at end of file +,});window['__farm_default_namespace__'].__farm_module_system__.setInitialLoadedResources([]);window['__farm_default_namespace__'].__farm_module_system__.setDynamicModuleResourcesMap([],{ });var farmModuleSystem = window['__farm_default_namespace__'].__farm_module_system__;farmModuleSystem.bootstrap();var entry = farmModuleSystem.require("b5d64806"); diff --git a/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/relative_public_path/tip/tip_star_star/output.js b/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/relative_public_path/tip/tip_star_star/output.js index 91c4c9517..c7430691c 100644 --- a/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/relative_public_path/tip/tip_star_star/output.js +++ b/crates/compiler/tests/fixtures/script/import_meta_url_with_URL/relative_public_path/tip/tip_star_star/output.js @@ -1,4 +1,4 @@ -//foo-8bdf4c.txt?url: +//foo-8bdf4c.txt: foo //index.js: @@ -79,4 +79,4 @@ "./foo/foo.txt": module.f(_f_foo) }[`./foo/*`], module.meta.url)); } -,});window['__farm_default_namespace__'].__farm_module_system__.setInitialLoadedResources([]);window['__farm_default_namespace__'].__farm_module_system__.setDynamicModuleResourcesMap([],{ });var farmModuleSystem = window['__farm_default_namespace__'].__farm_module_system__;farmModuleSystem.bootstrap();var entry = farmModuleSystem.require("b5d64806"); \ No newline at end of file +,});window['__farm_default_namespace__'].__farm_module_system__.setInitialLoadedResources([]);window['__farm_default_namespace__'].__farm_module_system__.setDynamicModuleResourcesMap([],{ });var farmModuleSystem = window['__farm_default_namespace__'].__farm_module_system__;farmModuleSystem.bootstrap();var entry = farmModuleSystem.require("b5d64806"); diff --git a/crates/plugin_static_assets/src/lib.rs b/crates/plugin_static_assets/src/lib.rs index e3d256083..f69f6bc8f 100644 --- a/crates/plugin_static_assets/src/lib.rs +++ b/crates/plugin_static_assets/src/lib.rs @@ -74,6 +74,10 @@ impl FarmPluginStaticAssets { ) } } + + fn remove_resource_name_query(name: &str) -> String { + name.split('?').next().unwrap_or(name).to_string() + } } impl Plugin for FarmPluginStaticAssets { @@ -239,7 +243,7 @@ impl Plugin for FarmPluginStaticAssets { context.emit_file(EmitFileParams { resolved_path: param.module_id.clone(), - name: resource_name, + name: Self::remove_resource_name_query(&resource_name), content: bytes, resource_type: ResourceType::Asset(ext.to_string()), }); diff --git a/js-plugins/dts/src/context.ts b/js-plugins/dts/src/context.ts index 48062166f..0fabba9ff 100644 --- a/js-plugins/dts/src/context.ts +++ b/js-plugins/dts/src/context.ts @@ -170,7 +170,6 @@ export default class Context { })) ) .concat(dtsOutputFiles); - console.log('outputFiles', outputFiles, this.options.outputDir); let entryRoot = this.options.entryRoot ?? ''; entryRoot = entryRoot ||