-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #221 from supabase/support-import-maps-for-eszip-b…
…undle feat: add support for import maps in generated eszips
- Loading branch information
Showing
12 changed files
with
111 additions
and
55 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use anyhow::{anyhow, Error}; | ||
use deno_core::url::Url; | ||
use import_map::{parse_from_json, ImportMap}; | ||
use module_fetcher::util::diagnostic::print_import_map_diagnostics; | ||
use std::fs; | ||
use std::path::Path; | ||
use urlencoding::decode; | ||
|
||
pub fn load_import_map(maybe_path: Option<String>) -> Result<Option<ImportMap>, Error> { | ||
if let Some(path_str) = maybe_path { | ||
let json_str; | ||
let base_url; | ||
|
||
// check if the path is a data URI (prefixed with data:) | ||
// the data URI takes the following format | ||
// data:{encodeURIComponent(mport_map.json)?{encodeURIComponent(base_path)} | ||
if path_str.starts_with("data:") { | ||
let data_uri = Url::parse(&path_str)?; | ||
json_str = decode(data_uri.path())?.into_owned(); | ||
base_url = | ||
Url::from_directory_path(decode(data_uri.query().unwrap_or(""))?.into_owned()) | ||
.map_err(|_| anyhow!("invalid import map base url"))?; | ||
} else { | ||
let path = Path::new(&path_str); | ||
let abs_path = std::env::current_dir().map(|p| p.join(path))?; | ||
json_str = fs::read_to_string(abs_path.clone())?; | ||
base_url = Url::from_directory_path(abs_path.parent().unwrap()) | ||
.map_err(|_| anyhow!("invalid import map base url"))?; | ||
} | ||
|
||
let result = parse_from_json(&base_url, json_str.as_str())?; | ||
print_import_map_diagnostics(&result.diagnostics); | ||
Ok(Some(result.import_map)) | ||
} else { | ||
Ok(None) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"imports": { | ||
"oak": "https://deno.land/x/[email protected]/mod.ts", | ||
"shared_cors": "./_shared/cors.ts", | ||
"express": "npm:[email protected]" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import express from "npm:express@4.18.2"; | ||
import express from 'express'; | ||
|
||
const app = express(); | ||
|
||
app.get("/", (req, res) => { | ||
res.send("Welcome to the Dinosaur API!"); | ||
app.get('/express', (req, res) => { | ||
res.send('Welcome to the Dinosaur API!'); | ||
}); | ||
|
||
app.listen(8000); | ||
app.listen(8000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters