summaryrefslogtreecommitdiff
path: root/cli/proc_state.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-01-25 21:13:40 +0100
committerGitHub <noreply@github.com>2023-01-25 21:13:40 +0100
commitc6c8c91a6e4b7a2b6eed02d3e2f5db25c124d9a0 (patch)
tree1fe8e9ab2175154d44e78d153dd760e56dc1c860 /cli/proc_state.rs
parentb5b4887c4a5fefdeb5592ebaadcc941281d0c4d5 (diff)
feat: embed import map in the config file (#17478)
This commit changes handling of config file to enable specifying "imports" and "scopes" objects effectively making the configuration file an import map. "imports" and "scopes" take precedence over "importMap" configuration, but have lower priority than "--importmap" CLI flag. Co-authored-by: David Sherret <dsherret@users.noreply.github.com> Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'cli/proc_state.rs')
-rw-r--r--cli/proc_state.rs47
1 files changed, 4 insertions, 43 deletions
diff --git a/cli/proc_state.rs b/cli/proc_state.rs
index fd5ad4840..e979ffd6b 100644
--- a/cli/proc_state.rs
+++ b/cli/proc_state.rs
@@ -43,7 +43,6 @@ use deno_core::futures;
use deno_core::parking_lot::Mutex;
use deno_core::parking_lot::RwLock;
use deno_core::resolve_url_or_path;
-use deno_core::url::Url;
use deno_core::CompiledWasmModuleStore;
use deno_core::ModuleSpecifier;
use deno_core::SharedArrayBufferStore;
@@ -206,25 +205,11 @@ impl ProcState {
)?;
let lockfile = cli_options.maybe_lock_file();
- let maybe_import_map_specifier =
- cli_options.resolve_import_map_specifier()?;
-
- let maybe_import_map =
- if let Some(import_map_specifier) = maybe_import_map_specifier {
- let file = file_fetcher
- .fetch(&import_map_specifier, PermissionsContainer::allow_all())
- .await
- .context(format!(
- "Unable to load '{}' import map",
- import_map_specifier
- ))?;
- let import_map =
- import_map_from_text(&import_map_specifier, &file.source)?;
- Some(Arc::new(import_map))
- } else {
- None
- };
+ let maybe_import_map = cli_options
+ .resolve_import_map(&file_fetcher)
+ .await?
+ .map(Arc::new);
let maybe_inspector_server =
cli_options.resolve_inspector_server().map(Arc::new);
@@ -765,30 +750,6 @@ impl ProcState {
}
}
-pub fn import_map_from_text(
- specifier: &Url,
- json_text: &str,
-) -> Result<ImportMap, AnyError> {
- debug_assert!(
- !specifier.as_str().contains("../"),
- "Import map specifier incorrectly contained ../: {}",
- specifier.as_str()
- );
- let result = import_map::parse_from_json(specifier, json_text)?;
- if !result.diagnostics.is_empty() {
- warn!(
- "Import map diagnostics:\n{}",
- result
- .diagnostics
- .into_iter()
- .map(|d| format!(" - {}", d))
- .collect::<Vec<_>>()
- .join("\n")
- );
- }
- Ok(result.import_map)
-}
-
#[derive(Clone, Debug)]
struct FileWatcherReporter {
sender: tokio::sync::mpsc::UnboundedSender<Vec<PathBuf>>,