Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compat): Node CJS and ESM resolvers #12424

Merged
merged 44 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
29883b3
temp
bartlomieju Oct 10, 2021
9200bb2
parse_package_name
bartlomieju Oct 11, 2021
becf749
module_resolve
bartlomieju Oct 12, 2021
96a84d3
package_exports_resolve
bartlomieju Oct 12, 2021
371ffcc
resolve_package_target_string
bartlomieju Oct 12, 2021
0f62c43
Merge branch 'main' into compat_node_resolver
bartlomieju Oct 12, 2021
dfd1190
node_resolve
bartlomieju Oct 12, 2021
6954cf6
chalk example working
bartlomieju Oct 12, 2021
a0b1ba6
legacy_main_resolve
bartlomieju Oct 13, 2021
5d41393
pass conditions
bartlomieju Oct 13, 2021
03ef6f7
rename, remove debug prints
bartlomieju Oct 13, 2021
ccf73ec
clippy
bartlomieju Oct 13, 2021
34bb541
add tests
ry Oct 13, 2021
bea885a
add deep test
ry Oct 13, 2021
bba059a
fmt
ry Oct 13, 2021
89e11b3
remove import map
bartlomieju Oct 13, 2021
349804c
port errors
bartlomieju Oct 13, 2021
be08d09
lint
bartlomieju Oct 13, 2021
fe5460f
revert pub modifiers, rename module
bartlomieju Oct 13, 2021
ef6f6d3
fix tests
bartlomieju Oct 13, 2021
28efb3e
add helpers
bartlomieju Oct 13, 2021
13079df
finish resolve_package_target_string
bartlomieju Oct 14, 2021
57f3323
err_package_not_exported
bartlomieju Oct 14, 2021
8e0a80b
add missing methods
bartlomieju Oct 14, 2021
efdfd6a
add error code
bartlomieju Oct 14, 2021
3696f95
reset CI
bartlomieju Oct 14, 2021
a12f3e9
add CJS resolver
bartlomieju Oct 15, 2021
adb3fc4
reorganize code
bartlomieju Oct 16, 2021
f2104fa
add deno condition
bartlomieju Oct 16, 2021
c1c49d0
use raw.githubusercontent.com
bartlomieju Oct 16, 2021
6d9b808
Merge branch 'main' into compat_node_resolver
bartlomieju Oct 16, 2021
4c855f2
don't require --allow-net permission for compat mode
bartlomieju Oct 17, 2021
43984e4
add test for conditional exports
bartlomieju Oct 17, 2021
cfb47bd
update reference to deno_std
bartlomieju Oct 18, 2021
b583bd7
Merge branch 'main' into compat_node_resolver
ry Oct 18, 2021
62dd1c6
small clean ups
ry Oct 18, 2021
b32b4cd
add test_is_relative_specifier
ry Oct 18, 2021
09e9dae
review comments
bartlomieju Oct 18, 2021
8c39946
fix test
bartlomieju Oct 18, 2021
a3f6a61
Merge branch 'main' into compat_node_resolver
bartlomieju Oct 18, 2021
f357f98
fix test
bartlomieju Oct 18, 2021
fa59547
Escape injected string.
dsherret Oct 18, 2021
cb1652c
Escape other injected single quote string too.
dsherret Oct 18, 2021
f6686da
Remove accidental println
dsherret Oct 18, 2021
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
88 changes: 0 additions & 88 deletions cli/compat.rs

This file was deleted.

145 changes: 145 additions & 0 deletions cli/compat/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.

use deno_core::error::generic_error;
use deno_core::error::type_error;
use deno_core::error::AnyError;
use deno_core::url::Url;

pub(crate) fn err_invalid_module_specifier(
request: &str,
reason: &str,
maybe_base: Option<String>,
) -> AnyError {
let mut msg = format!(
"[ERR_INVALID_MODULE_SPECIFIER] Invalid module \"{}\" {}",
request, reason
);

if let Some(base) = maybe_base {
msg = format!("{} imported from {}", msg, base);
}

type_error(msg)
}

pub(crate) fn err_invalid_package_config(
path: &str,
maybe_base: Option<String>,
maybe_message: Option<String>,
) -> AnyError {
let mut msg = format!(
"[ERR_INVALID_PACKAGE_CONFIG] Invalid package config {}",
path
);

if let Some(base) = maybe_base {
msg = format!("{} while importing {}", msg, base);
}

if let Some(message) = maybe_message {
msg = format!("{}. {}", msg, message);
}

generic_error(msg)
}

pub(crate) fn err_module_not_found(
path: &str,
base: &str,
typ: &str,
) -> AnyError {
generic_error(format!(
"[ERR_MODULE_NOT_FOUND] Cannot find {} '{}' imported from {}",
typ, path, base
))
}

pub(crate) fn err_unsupported_dir_import(path: &str, base: &str) -> AnyError {
generic_error(format!("[ERR_UNSUPPORTED_DIR_IMPORT] Directory import '{}' is not supported resolving ES modules imported from {}", path, base))
}

pub(crate) fn err_unsupported_esm_url_scheme(url: &Url) -> AnyError {
let mut msg =
"[ERR_UNSUPPORTED_ESM_URL_SCHEME] Only file and data URLS are supported by the default ESM loader"
.to_string();

if cfg!(window) && url.scheme().len() == 2 {
msg = format!(
"{}. On Windows, absolute path must be valid file:// URLs",
msg
);
}

msg = format!("{}. Received protocol '{}'", msg, url.scheme());
generic_error(msg)
}

pub(crate) fn err_invalid_package_target(
pkg_path: String,
key: String,
target: String,
is_import: bool,
maybe_base: Option<String>,
) -> AnyError {
let rel_error = !is_import && !target.is_empty() && !target.starts_with("./");
let mut msg = "[ERR_INVALID_PACKAGE_TARGET]".to_string();

if key == "." {
assert!(!is_import);
msg = format!("{} Invalid \"exports\" main target {} defined in the package config {}package.json", msg, target, pkg_path)
} else {
let ie = if is_import { "imports" } else { "exports" };
msg = format!("{} Invalid \"{}\" target {} defined for '{}' in the package config {}package.json", msg, ie, target, key, pkg_path)
};

if let Some(base) = maybe_base {
msg = format!("{} imported from {}", msg, base);
};
if rel_error {
msg = format!("{}; target must start with \"./\"", msg);
}

generic_error(msg)
}

pub(crate) fn err_package_path_not_exported(
pkg_path: String,
subpath: String,
maybe_base: Option<String>,
) -> AnyError {
let mut msg = "[ERR_PACKAGE_PATH_NOT_EXPORTED]".to_string();

if subpath == "." {
msg = format!(
"{} No \"exports\" main defined in {}package.json",
msg, pkg_path
);
} else {
msg = format!("{} Package subpath \'{}\' is not defined by \"exports\" in {}package.json", msg, subpath, pkg_path);
};

if let Some(base) = maybe_base {
msg = format!("{} imported from {}", msg, base);
}

generic_error(msg)
}

pub(crate) fn err_package_import_not_defined(
specifier: &str,
package_path: Option<String>,
base: &str,
) -> AnyError {
let mut msg = format!(
"[ERR_PACKAGE_IMPORT_NOT_DEFINED] Package import specifier \"{}\" is not defined in",
specifier
);

if let Some(package_path) = package_path {
msg = format!("{} in package {}package.json", msg, package_path);
}

msg = format!("{} imported from {}", msg, base);

type_error(msg)
}
Loading