1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(workspace): provide workspace members as 'imports' in import map (#23492)

This commit changes the workspace support to provide all workspace
members to be available as imports based on their names and versions.

Closes https://github.com/denoland/deno/issues/23343
This commit is contained in:
Bartek Iwańczuk 2024-04-23 16:21:06 +01:00 committed by GitHub
parent b0d3b20f23
commit 35220f0069
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
45 changed files with 92 additions and 31 deletions

View file

@ -96,3 +96,32 @@ fn print_import_map_diagnostics(diagnostics: &[ImportMapDiagnostic]) {
);
}
}
pub fn enhance_import_map_value_with_workspace_members(
mut import_map_value: serde_json::Value,
workspace_members: &[deno_config::WorkspaceMemberConfig],
) -> serde_json::Value {
let mut imports =
if let Some(imports) = import_map_value.get("imports").as_ref() {
imports.as_object().unwrap().clone()
} else {
serde_json::Map::new()
};
for workspace_member in workspace_members {
let name = &workspace_member.package_name;
let version = &workspace_member.package_version;
// Don't override existings, explicit imports
if imports.contains_key(name) {
continue;
}
imports.insert(
name.to_string(),
serde_json::Value::String(format!("jsr:{}@^{}", name, version)),
);
}
import_map_value["imports"] = serde_json::Value::Object(imports);
::import_map::ext::expand_import_map_value(import_map_value)
}

View file

@ -67,6 +67,7 @@ use std::path::PathBuf;
use std::sync::Arc;
use thiserror::Error;
use crate::args::import_map::enhance_import_map_value_with_workspace_members;
use crate::file_fetcher::FileFetcher;
use crate::util::fs::canonicalize_path_maybe_not_exists;
use crate::version;
@ -975,6 +976,10 @@ impl CliOptions {
base_import_map_config,
children_configs,
);
let import_map = enhance_import_map_value_with_workspace_members(
import_map,
&workspace_config.members,
);
log::debug!(
"Workspace config generated this import map {}",
serde_json::to_string_pretty(&import_map).unwrap()

View file

@ -4918,35 +4918,6 @@ itest!(explicit_resource_management {
output: "run/explicit_resource_management/main.out",
});
itest!(workspaces_basic {
args: "run -L debug -A main.ts",
output: "run/workspaces/basic/main.out",
cwd: Some("run/workspaces/basic/"),
copy_temp_dir: Some("run/workspaces/basic/"),
envs: env_vars_for_npm_tests(),
http_server: true,
});
itest!(workspaces_member_outside_root_dir {
args: "run -A main.ts",
output: "run/workspaces/member_outside_root_dir/main.out",
cwd: Some("run/workspaces/member_outside_root_dir/"),
copy_temp_dir: Some("run/workspaces/member_outside_root_dir/"),
envs: env_vars_for_npm_tests(),
http_server: true,
exit_code: 1,
});
itest!(workspaces_nested_member {
args: "run -A main.ts",
output: "run/workspaces/nested_member/main.out",
cwd: Some("run/workspaces/nested_member/"),
copy_temp_dir: Some("run/workspaces/nested_member/"),
envs: env_vars_for_npm_tests(),
http_server: true,
exit_code: 1,
});
itest!(unsafe_proto {
args: "run -A run/unsafe_proto/main.js",
output: "run/unsafe_proto/main.out",

View file

@ -0,0 +1,5 @@
{
"args": "run -L debug -A main.ts",
"output": "main.out",
"tempDir": true
}

View file

@ -1,7 +1,11 @@
[WILDCARD]Workspace config generated this import map {
"imports": {
"chalk": "npm:chalk",
"chalk/": "npm:/chalk/"
"chalk/": "npm:/chalk/",
"qwerqwer": "jsr:qwerqwer@^0.0.0",
"qwerqwer/": "jsr:/qwerqwer@^0.0.0/",
"asdfasdfasdf": "jsr:asdfasdfasdf@^0.0.0",
"asdfasdfasdf/": "jsr:/asdfasdfasdf@^0.0.0/"
},
"scopes": {
"./foo/": {

View file

@ -0,0 +1,6 @@
{
"args": "run -A main.ts",
"output": "main.out",
"tempDir": true,
"exitCode": 1
}

View file

@ -0,0 +1,5 @@
{
"args": "run -A main.ts",
"output": "main.out",
"tempDir": true
}

View file

@ -0,0 +1,7 @@
{
"name": "@deno-test/bar",
"version": "0.0.1",
"exports": {
".": "./mod.ts"
}
}

View file

@ -0,0 +1 @@
export const value = 42;

View file

@ -0,0 +1,9 @@
{
"workspaces": [
"foo",
"bar"
],
"tasks": {
"dev": "deno run --watch main.ts"
}
}

View file

@ -0,0 +1,7 @@
{
"name": "@deno-test/foo",
"version": "0.0.1",
"exports": {
".": "./mod.ts"
}
}

View file

@ -0,0 +1 @@
export const value = 42;

View file

@ -0,0 +1 @@
[Module: null prototype] { value: 42 } [Module: null prototype] { value: 42 }

View file

@ -0,0 +1,4 @@
import * as foo from "@deno-test/foo";
import * as bar from "@deno-test/bar";
console.log(foo, bar);

View file

@ -0,0 +1,6 @@
{
"args": "run -A main.ts",
"output": "main.out",
"tempDir": true,
"exitCode": 1
}

View file

@ -213,7 +213,7 @@ async function ensureNoNewITests() {
"pm_tests.rs": 0,
"publish_tests.rs": 28,
"repl_tests.rs": 0,
"run_tests.rs": 382,
"run_tests.rs": 379,
"shared_library_tests.rs": 0,
"task_tests.rs": 30,
"test_tests.rs": 80,