feat: support embedded import map in deno.json (#1188)
One can now inline the `imports` and `scopes` from the import map directly into deno.json. For new projects, `import_map.json` is not generated anymore. Co-authored-by: Luca Casonato <hello@lcas.dev>
This commit is contained in:
co-authored by
Luca Casonato
parent
3857a49f1c
commit
1b6678951a
+1
-36
@@ -1,12 +1,4 @@
|
||||
import {
|
||||
dirname,
|
||||
fromFileUrl,
|
||||
gte,
|
||||
join,
|
||||
relative,
|
||||
toFileUrl,
|
||||
walk,
|
||||
} from "./deps.ts";
|
||||
import { dirname, fromFileUrl, gte, join, toFileUrl, walk } from "./deps.ts";
|
||||
import { error } from "./error.ts";
|
||||
|
||||
const MIN_DENO_VERSION = "1.25.0";
|
||||
@@ -60,31 +52,6 @@ export async function collect(directory: string): Promise<Manifest> {
|
||||
return { routes, islands };
|
||||
}
|
||||
|
||||
async function findDenoConfig(directory: string) {
|
||||
let dir = directory;
|
||||
while (true) {
|
||||
const path = join(dir, "deno.json");
|
||||
try {
|
||||
await Deno.stat(path);
|
||||
break;
|
||||
} catch (err) {
|
||||
if (!(err instanceof Deno.errors.NotFound)) {
|
||||
throw err;
|
||||
}
|
||||
const parent = dirname(dir);
|
||||
if (parent === dir) {
|
||||
error(
|
||||
`Could not find a deno.json file in the current directory or any parent directory.`,
|
||||
);
|
||||
}
|
||||
dir = parent;
|
||||
}
|
||||
}
|
||||
|
||||
// convert into import path, would be cool if there is a stdlib function
|
||||
return `${relative(directory, dir).replace(/\\/g, "/") || "."}/deno.json`;
|
||||
}
|
||||
|
||||
export async function generate(directory: string, manifest: Manifest) {
|
||||
const { routes, islands } = manifest;
|
||||
|
||||
@@ -92,7 +59,6 @@ export async function generate(directory: string, manifest: Manifest) {
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running \`dev.ts\`.
|
||||
|
||||
import config from "${await findDenoConfig(directory)}" assert { type: "json" };
|
||||
${
|
||||
routes.map((file, i) => `import * as $${i} from "./routes${file}";`).join(
|
||||
"\n",
|
||||
@@ -117,7 +83,6 @@ const manifest = {
|
||||
}
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
config,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
|
||||
Reference in New Issue
Block a user