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
@@ -38,7 +38,7 @@ jobs:
|
||||
|
||||
- name: Cache dependencies
|
||||
if: startsWith(matrix.os, 'ubuntu') && matrix.deno == 'v1.x'
|
||||
run: deno cache --no-check --import-map=./www/import_map.json src/dev/deps.ts src/server/deps.ts www/main.ts
|
||||
run: deno cache --config=www/deno.json src/dev/deps.ts src/server/deps.ts www/main.ts
|
||||
|
||||
- name: Cache Chrome (Linux)
|
||||
if: startsWith(matrix.os, 'ubuntu')
|
||||
|
||||
+8
-1
@@ -3,7 +3,14 @@
|
||||
"tasks": {
|
||||
"start": "deno run -A --watch=static/,routes/ dev.ts"
|
||||
},
|
||||
"importMap": "./import_map.json",
|
||||
"imports": {
|
||||
"$fresh/": "../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.0.3",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
|
||||
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import config from "./deno.json" assert { type: "json" };
|
||||
import * as $0 from "./routes/index.tsx";
|
||||
import * as $$0 from "./islands/Counter.tsx";
|
||||
|
||||
@@ -14,7 +13,6 @@ const manifest = {
|
||||
"./islands/Counter.tsx": $$0,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
config,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"imports": {
|
||||
"$fresh/": "../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.0.3",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
|
||||
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3"
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ ENV DENO_DEPLOYMENT_ID=${GIT_REVISION}
|
||||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
RUN deno cache main.ts --import-map=import_map.json
|
||||
RUN deno cache main.ts
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
|
||||
@@ -28,14 +28,14 @@ below.
|
||||
To update your dependencies, you have two options:
|
||||
|
||||
- Run the fresh updater to update your project dependencies.
|
||||
- Manually update the dependency versions in your `import_map.json` file.
|
||||
- Manually update the dependency versions in your `deno.json` file.
|
||||
|
||||
### Auto updater
|
||||
|
||||
The auto updater is a command line tool that will update your project's
|
||||
`import_map.json` file to the latest versions of Fresh and its dependencies. It
|
||||
may also contain code mods for your project that will update your code to the
|
||||
latest recommended patterns for Fresh projects.
|
||||
`deno.json` file to the latest versions of Fresh and its dependencies. It may
|
||||
also contain code mods for your project that will update your code to the latest
|
||||
recommended patterns for Fresh projects.
|
||||
|
||||
To run the auto updater, run the following command from the root of your
|
||||
project:
|
||||
@@ -48,11 +48,10 @@ You will be prompted to confirm the changes that will be made to your project.
|
||||
|
||||
### Manual update
|
||||
|
||||
To manually update your project's dependencies, you can edit the
|
||||
`import_map.json` file in the root of your projects directory. Dependency
|
||||
versions are encoded into the URLs in this file. For example, here is how to
|
||||
update a project from Fresh 1.0.2 to 1.1.3, and update Preact to the latest
|
||||
version:
|
||||
To manually update your project's dependencies, you can edit the `deno.json`
|
||||
file in the root of your projects directory. Dependency versions are encoded
|
||||
into the URLs in this file. For example, here is how to update a project from
|
||||
Fresh 1.0.2 to 1.1.3, and update Preact to the latest version:
|
||||
|
||||
```diff
|
||||
{
|
||||
|
||||
@@ -30,15 +30,13 @@ files that are strictly necessary to run a fresh project:
|
||||
- **`fresh.gen.ts`**: This is the manifest file that contains information about
|
||||
your routes and islands. This file is automatically generated in development
|
||||
based on your `routes/` and `islands/` folders.
|
||||
- **`import_map.json`**: This is an [import map][import-map] that is used to
|
||||
manage dependencies for the project. This allows for easy importing and
|
||||
updating of dependencies.
|
||||
|
||||
A **`deno.json`** file is also created in the project directory. This file does
|
||||
two things:
|
||||
|
||||
- It tells Deno about the location of the import map, so that it can be loaded
|
||||
automatically.
|
||||
- It defines the "imports" field. This is an [import map][import-map] that is
|
||||
used to manage dependencies for the project. This allows for easy importing
|
||||
and updating of dependencies.
|
||||
- It registers a "start" [task][task-runner] to run the project without having
|
||||
to type a long `deno run` command.
|
||||
|
||||
|
||||
@@ -101,16 +101,6 @@ await Deno.writeTextFile(
|
||||
GITIGNORE,
|
||||
);
|
||||
|
||||
const importMap = { imports: {} as Record<string, string> };
|
||||
freshImports(importMap.imports);
|
||||
if (useTwind) twindImports(importMap.imports);
|
||||
dotenvImports(importMap.imports);
|
||||
const IMPORT_MAP_JSON = JSON.stringify(importMap, null, 2) + "\n";
|
||||
await Deno.writeTextFile(
|
||||
join(resolvedDirectory, "import_map.json"),
|
||||
IMPORT_MAP_JSON,
|
||||
);
|
||||
|
||||
const ROUTES_INDEX_TSX = `import { Head } from "$fresh/runtime.ts";
|
||||
import { useSignal } from "@preact/signals";
|
||||
import Counter from "../islands/Counter.tsx";
|
||||
@@ -310,12 +300,16 @@ const config = {
|
||||
tasks: {
|
||||
start: "deno run -A --watch=static/,routes/ dev.ts",
|
||||
},
|
||||
importMap: "./import_map.json",
|
||||
imports: {} as Record<string, string>,
|
||||
compilerOptions: {
|
||||
jsx: "react-jsx",
|
||||
jsxImportSource: "preact",
|
||||
},
|
||||
};
|
||||
freshImports(config.imports);
|
||||
if (useTwind) twindImports(config.imports);
|
||||
dotenvImports(config.imports);
|
||||
|
||||
const DENO_CONFIG = JSON.stringify(config, null, 2) + "\n";
|
||||
|
||||
await Deno.writeTextFile(join(resolvedDirectory, "deno.json"), DENO_CONFIG);
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
export {
|
||||
fromFileUrl,
|
||||
toFileUrl,
|
||||
} from "https://deno.land/std@0.189.0/path/mod.ts";
|
||||
export { escape as regexpEscape } from "https://deno.land/std@0.189.0/regexp/escape.ts";
|
||||
} from "https://deno.land/std@0.190.0/path/mod.ts";
|
||||
export { escape as regexpEscape } from "https://deno.land/std@0.190.0/regexp/escape.ts";
|
||||
|
||||
// -- esbuild --
|
||||
// @deno-types="https://deno.land/x/esbuild@v0.17.11/mod.d.ts"
|
||||
@@ -17,4 +17,4 @@ const esbuild: typeof esbuildWasm = Deno.run === undefined
|
||||
const esbuildWasmURL = new URL("./esbuild_v0.17.11.wasm", import.meta.url).href;
|
||||
export { esbuild, esbuildWasm as esbuildTypes, esbuildWasmURL };
|
||||
|
||||
export { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.7.0/mod.ts";
|
||||
export { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.7.2/mod.ts";
|
||||
|
||||
@@ -16,8 +16,8 @@ export interface EsbuildBuilderOptions {
|
||||
entrypoints: Record<string, string>;
|
||||
/** Whether or not this is a dev build. */
|
||||
dev: boolean;
|
||||
/** The import map URL. */
|
||||
importMapURL: URL;
|
||||
/** The path to the deno.json / deno.jsonc config file. */
|
||||
configPath: string;
|
||||
/** The JSX configuration. */
|
||||
jsxConfig: JSXConfig;
|
||||
}
|
||||
@@ -74,7 +74,7 @@ export class EsbuildBuilder implements Builder {
|
||||
|
||||
plugins: [
|
||||
buildIdPlugin(opts.buildID),
|
||||
...denoPlugins({ importMapURL: opts.importMapURL.href }),
|
||||
...denoPlugins({ configPath: opts.configPath }),
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
+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;
|
||||
|
||||
+50
-8
@@ -1,7 +1,10 @@
|
||||
import {
|
||||
ConnInfo,
|
||||
dirname,
|
||||
extname,
|
||||
fromFileUrl,
|
||||
join,
|
||||
JSONC,
|
||||
RequestHandler,
|
||||
Status,
|
||||
toFileUrl,
|
||||
@@ -10,7 +13,7 @@ import {
|
||||
} from "./deps.ts";
|
||||
import { h } from "preact";
|
||||
import * as router from "./router.ts";
|
||||
import { Manifest } from "./mod.ts";
|
||||
import { DenoConfig, Manifest } from "./mod.ts";
|
||||
import { ALIVE_URL, JS_PREFIX, REFRESH_JS_URL } from "./constants.ts";
|
||||
import { BUILD_ID } from "./build_id.ts";
|
||||
import DefaultErrorHandler from "./default_error_page.ts";
|
||||
@@ -47,6 +50,12 @@ interface RouterState {
|
||||
state: Record<string, unknown>;
|
||||
}
|
||||
|
||||
function isObject(value: unknown) {
|
||||
return typeof value === "object" &&
|
||||
!Array.isArray(value) &&
|
||||
value !== null;
|
||||
}
|
||||
|
||||
interface StaticFile {
|
||||
/** The URL to the static file on disk. */
|
||||
localUrl: URL;
|
||||
@@ -83,7 +92,7 @@ export class ServerContext {
|
||||
notFound: UnknownPage,
|
||||
error: ErrorPage,
|
||||
plugins: Plugin[],
|
||||
importMapURL: URL,
|
||||
configPath: string,
|
||||
jsxConfig: JSXConfig,
|
||||
) {
|
||||
this.#routes = routes;
|
||||
@@ -99,7 +108,7 @@ export class ServerContext {
|
||||
this.#builder = new EsbuildBuilder({
|
||||
buildID: BUILD_ID,
|
||||
entrypoints: collectEntrypoints(this.#dev, this.#islands, this.#plugins),
|
||||
importMapURL,
|
||||
configPath,
|
||||
dev: this.#dev,
|
||||
jsxConfig,
|
||||
});
|
||||
@@ -115,11 +124,14 @@ export class ServerContext {
|
||||
// Get the manifest' base URL.
|
||||
const baseUrl = new URL("./", manifest.baseUrl).href;
|
||||
|
||||
const config = manifest.config || { importMap: "./import_map.json" };
|
||||
if (typeof config.importMap !== "string") {
|
||||
throw new Error("deno.json must contain an 'importMap' property.");
|
||||
const { config, path: configPath } = await readDenoConfig(
|
||||
fromFileUrl(baseUrl),
|
||||
);
|
||||
if (typeof config.importMap !== "string" && !isObject(config.imports)) {
|
||||
throw new Error(
|
||||
"deno.json must contain an 'importMap' or 'imports' property.",
|
||||
);
|
||||
}
|
||||
const importMapURL = new URL(config.importMap, manifest.baseUrl);
|
||||
|
||||
config.compilerOptions ??= {};
|
||||
|
||||
@@ -318,7 +330,7 @@ export class ServerContext {
|
||||
notFound,
|
||||
error,
|
||||
opts.plugins ?? [],
|
||||
importMapURL,
|
||||
configPath,
|
||||
jsxConfig,
|
||||
);
|
||||
}
|
||||
@@ -937,3 +949,33 @@ function collectEntrypoints(
|
||||
|
||||
return entryPoints;
|
||||
}
|
||||
|
||||
async function readDenoConfig(
|
||||
directory: string,
|
||||
): Promise<{ config: DenoConfig; path: string }> {
|
||||
let dir = directory;
|
||||
while (true) {
|
||||
for (const name of ["deno.json", "deno.jsonc"]) {
|
||||
const path = join(dir, name);
|
||||
try {
|
||||
const file = await Deno.readTextFile(path);
|
||||
if (name.endsWith(".jsonc")) {
|
||||
return { config: JSONC.parse(file) as DenoConfig, path };
|
||||
} else {
|
||||
return { config: JSON.parse(file), path };
|
||||
}
|
||||
} catch (err) {
|
||||
if (!(err instanceof Deno.errors.NotFound)) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
const parent = dirname(dir);
|
||||
if (parent === dir) {
|
||||
throw new Error(
|
||||
`Could not find a deno.json file in the current directory or any parent directory.`,
|
||||
);
|
||||
}
|
||||
dir = parent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// -- std --
|
||||
export {
|
||||
dirname,
|
||||
extname,
|
||||
fromFileUrl,
|
||||
join,
|
||||
toFileUrl,
|
||||
} from "https://deno.land/std@0.190.0/path/mod.ts";
|
||||
export { walk } from "https://deno.land/std@0.190.0/fs/walk.ts";
|
||||
@@ -17,6 +19,7 @@ export {
|
||||
} from "https://deno.land/std@0.190.0/media_types/mod.ts";
|
||||
export { toHashString } from "https://deno.land/std@0.190.0/crypto/to_hash_string.ts";
|
||||
export { escape } from "https://deno.land/std@0.190.0/regexp/escape.ts";
|
||||
export * as JSONC from "https://deno.land/std@0.190.0/jsonc/mod.ts";
|
||||
|
||||
// -- esbuild --
|
||||
// @deno-types="https://deno.land/x/esbuild@v0.17.11/mod.d.ts"
|
||||
|
||||
+2
-2
@@ -47,11 +47,11 @@ export interface Manifest {
|
||||
>;
|
||||
islands: Record<string, IslandModule>;
|
||||
baseUrl: string;
|
||||
config?: DenoConfig;
|
||||
}
|
||||
|
||||
export interface DenoConfig {
|
||||
importMap: string;
|
||||
imports?: Record<string, string>;
|
||||
importMap?: string;
|
||||
compilerOptions?: {
|
||||
jsx?: string;
|
||||
jsxImportSource?: string;
|
||||
|
||||
+1
-13
@@ -65,7 +65,6 @@ Deno.test({
|
||||
"name": tmpDirName,
|
||||
"contents": [
|
||||
{ "type": "file", "name": "README.md" },
|
||||
{ "type": "file", "name": "import_map.json" },
|
||||
{ "type": "file", "name": "fresh.gen.ts" },
|
||||
{
|
||||
"type": "directory",
|
||||
@@ -204,7 +203,6 @@ Deno.test({
|
||||
"name": tmpDirName,
|
||||
"contents": [
|
||||
{ "type": "file", "name": "README.md" },
|
||||
{ "type": "file", "name": "import_map.json" },
|
||||
{ "type": "file", "name": "fresh.gen.ts" },
|
||||
{ "type": "file", "name": "twind.config.ts" },
|
||||
{
|
||||
@@ -422,20 +420,11 @@ Deno.test({
|
||||
|
||||
await cliProcess.output();
|
||||
|
||||
// "move deno.json and import_map.json one level up"
|
||||
// move deno.json one level up
|
||||
await Deno.rename(
|
||||
path.join(tmpDirName, "subdirectory", "subsubdirectory", "deno.json"),
|
||||
path.join(tmpDirName, "deno.json"),
|
||||
);
|
||||
await Deno.rename(
|
||||
path.join(
|
||||
tmpDirName,
|
||||
"subdirectory",
|
||||
"subsubdirectory",
|
||||
"import_map.json",
|
||||
),
|
||||
path.join(tmpDirName, "import_map.json"),
|
||||
);
|
||||
|
||||
const targetFileTree: FileTree[] = [
|
||||
{
|
||||
@@ -443,7 +432,6 @@ Deno.test({
|
||||
"name": tmpDirName,
|
||||
"contents": [
|
||||
{ "type": "file", "name": "deno.json" },
|
||||
{ "type": "file", "name": "import_map.json" },
|
||||
{
|
||||
"type": "directory",
|
||||
"name": "subdirectory",
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
{
|
||||
"lock": false,
|
||||
"importMap": "./import_map.json",
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.0.3",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
|
||||
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import config from "./deno.json" assert { type: "json" };
|
||||
import * as $0 from "./routes/[name].tsx";
|
||||
import * as $1 from "./routes/_404.tsx";
|
||||
import * as $2 from "./routes/_500.tsx";
|
||||
@@ -90,7 +89,6 @@ const manifest = {
|
||||
"./islands/kebab-case-counter-test.tsx": $$6,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
config,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.0.3",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
|
||||
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
{
|
||||
"importMap": "./import_map.json",
|
||||
"lock": false,
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.0.3"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import config from "./deno.json" assert { type: "json" };
|
||||
import * as $0 from "./routes/[...all].ts";
|
||||
import * as $1 from "./routes/index.tsx";
|
||||
|
||||
@@ -13,7 +12,6 @@ const manifest = {
|
||||
},
|
||||
islands: {},
|
||||
baseUrl: import.meta.url,
|
||||
config,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.0.3"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,9 @@
|
||||
{
|
||||
"lock": false,
|
||||
"importMap": "./import-map.json"
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/preact-render-to-string@6.0.3?external=preact"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import config from "./deno.json" assert { type: "json" };
|
||||
import * as $0 from "./routes/index.tsx";
|
||||
import * as $$0 from "./islands/Island.tsx";
|
||||
|
||||
@@ -14,7 +13,6 @@ const manifest = {
|
||||
"./islands/Island.tsx": $$0,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
config,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/preact-render-to-string@5.2.6?external=preact"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
{
|
||||
"lock": false,
|
||||
"importMap": "./import_map.json",
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.0.3"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import config from "./deno.json" assert { type: "json" };
|
||||
import * as $0 from "./routes/static.tsx";
|
||||
import * as $1 from "./routes/with-island.tsx";
|
||||
import * as $$0 from "./islands/Island.tsx";
|
||||
@@ -16,7 +15,6 @@ const manifest = {
|
||||
"./islands/Island.tsx": $$0,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
config,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.0.3"
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,14 @@
|
||||
"tasks": {
|
||||
"start": "deno run -A --watch=static/,routes/ dev.ts"
|
||||
},
|
||||
"importMap": "./import_map.json",
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.11.0",
|
||||
"preact/": "https://esm.sh/preact@10.11.0/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@5.2.4",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.0.3",
|
||||
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.0.1"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import config from "./deno.json" assert { type: "json" };
|
||||
import * as $0 from "./routes/check-duplication.tsx";
|
||||
import * as $1 from "./routes/insert-cssrules.tsx";
|
||||
import * as $2 from "./routes/static.tsx";
|
||||
@@ -20,7 +19,6 @@ const manifest = {
|
||||
"./islands/InsertCssrules.tsx": $$1,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
config,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.11.0",
|
||||
"preact/": "https://esm.sh/preact@10.11.0/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.0.3",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.0.3",
|
||||
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.0.1"
|
||||
}
|
||||
}
|
||||
@@ -27,24 +27,21 @@ const unresolvedDirectory = Deno.args[0];
|
||||
const resolvedDirectory = resolve(unresolvedDirectory);
|
||||
|
||||
// Update dependencies in the import map.
|
||||
const IMPORT_MAP_PATH = join(resolvedDirectory, "import_map.json");
|
||||
let importMapText = await Deno.readTextFile(IMPORT_MAP_PATH);
|
||||
const importMap = JSON.parse(importMapText);
|
||||
freshImports(importMap.imports);
|
||||
if (importMap.imports["twind"]) {
|
||||
twindImports(importMap.imports);
|
||||
const DENO_JSON_PATH = join(resolvedDirectory, "deno.json");
|
||||
let denoJsonText = await Deno.readTextFile(DENO_JSON_PATH);
|
||||
let denoJson = JSON.parse(denoJsonText);
|
||||
freshImports(denoJson.imports);
|
||||
if (denoJson.imports["twind"]) {
|
||||
twindImports(denoJson.imports);
|
||||
}
|
||||
importMapText = JSON.stringify(importMap, null, 2);
|
||||
await Deno.writeTextFile(IMPORT_MAP_PATH, importMapText);
|
||||
denoJsonText = JSON.stringify(denoJson, null, 2);
|
||||
await Deno.writeTextFile(DENO_JSON_PATH, denoJsonText);
|
||||
|
||||
// Code mod for classic JSX -> automatic JSX.
|
||||
const JSX_CODEMOD =
|
||||
`This project is using the classic JSX transform. Would you like to update to the
|
||||
automatic JSX transform? This will remove the /** @jsx h */ pragma from your
|
||||
source code and add the jsx: "react-jsx" compiler option to your deno.json file.`;
|
||||
const DENO_JSON_PATH = join(resolvedDirectory, "deno.json");
|
||||
let denoJsonText = await Deno.readTextFile(DENO_JSON_PATH);
|
||||
const denoJson = JSON.parse(denoJsonText);
|
||||
if (denoJson.compilerOptions?.jsx !== "react-jsx" && confirm(JSX_CODEMOD)) {
|
||||
console.log("Updating config file...");
|
||||
denoJson.compilerOptions = denoJson.compilerOptions || {};
|
||||
@@ -88,12 +85,12 @@ const TWIND_CODEMOD =
|
||||
`This project is using an old version of the twind integration. Would you like to
|
||||
update to the new twind plugin? This will remove the 'class={tw\`border\`}'
|
||||
boilerplate from your source code replace it with the simpler 'class="border"'.`;
|
||||
if (importMap.imports["@twind"] && confirm(TWIND_CODEMOD)) {
|
||||
await Deno.remove(join(resolvedDirectory, importMap.imports["@twind"]));
|
||||
if (denoJson.imports["@twind"] && confirm(TWIND_CODEMOD)) {
|
||||
await Deno.remove(join(resolvedDirectory, denoJson.imports["@twind"]));
|
||||
|
||||
delete importMap.imports["@twind"];
|
||||
importMapText = JSON.stringify(importMap, null, 2);
|
||||
await Deno.writeTextFile(IMPORT_MAP_PATH, importMapText);
|
||||
delete denoJson.imports["@twind"];
|
||||
denoJson = JSON.stringify(denoJson, null, 2);
|
||||
await Deno.writeTextFile(DENO_JSON_PATH, denoJson);
|
||||
|
||||
const MAIN_TS = `/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
|
||||
+12
-1
@@ -3,7 +3,18 @@
|
||||
"tasks": {
|
||||
"start": "deno run -A --watch=static/,routes/ dev.ts"
|
||||
},
|
||||
"importMap": "./import_map.json",
|
||||
"imports": {
|
||||
"$fresh/": "../",
|
||||
"twind": "https://esm.sh/twind@0.16.19",
|
||||
"twind/": "https://esm.sh/twind@0.16.19/",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.0.3",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
|
||||
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3",
|
||||
"$std/": "https://deno.land/std@0.190.0/",
|
||||
"$ga4": "https://raw.githubusercontent.com/denoland/ga4/main/mod.ts"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import config from "./deno.json" assert { type: "json" };
|
||||
import * as $0 from "./routes/_404.tsx";
|
||||
import * as $1 from "./routes/_500.tsx";
|
||||
import * as $2 from "./routes/_middleware.ts";
|
||||
@@ -40,7 +39,6 @@ const manifest = {
|
||||
"./islands/SearchButton.tsx": $$4,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
config,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"imports": {
|
||||
"$fresh/": "../",
|
||||
"twind": "https://esm.sh/twind@0.16.19",
|
||||
"twind/": "https://esm.sh/twind@0.16.19/",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.0.3",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
|
||||
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3",
|
||||
"$std/": "https://deno.land/std@0.190.0/",
|
||||
"$ga4": "https://raw.githubusercontent.com/denoland/ga4/main/mod.ts"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user