Skip to content

Commit

Permalink
feat: import fresh from fresh (#2479)
Browse files Browse the repository at this point in the history
Instead of importing as `@fresh/core`.
  • Loading branch information
lucacasonato authored Jun 5, 2024
1 parent 19d3e45 commit c3ec742
Show file tree
Hide file tree
Showing 39 changed files with 89 additions and 89 deletions.
8 changes: 4 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"$marked-mangle": "https://esm.sh/marked-mangle@1.0.1",
"$std/": "https://deno.land/std@0.216.0/",
"@astral/astral": "jsr:@astral/astral@^0.4.0",
"@fresh/core": "./src/mod.ts",
"@fresh/core/compat": "./src/compat/mod.ts",
"@fresh/core/dev": "./src/dev/mod.ts",
"@fresh/core/runtime": "./src/runtime/shared.ts",
"fresh": "./src/mod.ts",
"fresh/compat": "./src/compat/mod.ts",
"fresh/dev": "./src/dev/mod.ts",
"fresh/runtime": "./src/runtime/shared.ts",
"@fresh/plugin-tailwind": "./plugin-tailwindcss/src/mod.ts",
"@luca/esbuild-deno-loader": "jsr:@luca/esbuild-deno-loader@^0.10.3",
"@preact/signals": "npm:@preact/signals@^1.2.3",
Expand Down
10 changes: 5 additions & 5 deletions docs/canary/examples/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ deno run -Ar jsr:@fresh/update

This will apply most API changes made in Fresh 2
[automatically](#automatic-updates) like changing `$fresh/server.ts` imports to
`@fresh/core`.
`fresh`.

## Getting `main.ts` and `dev.ts` ready

Expand Down Expand Up @@ -51,7 +51,7 @@ plugins like [tailwindcss](https://tailwindcss.com/).
The full `dev.ts` file for newly generated Fresh 2 projects looks like this:

```ts
import { Builder } from "@fresh/core/dev";
import { Builder } from "fresh/dev";
import { tailwind } from "@fresh/plugin-tailwind";
import { app } from "./main.ts";

Expand All @@ -78,7 +78,7 @@ Similarly, configuration related to running Fresh in production can be passed to

```ts
// main.ts
import { App, fsRoutes, staticFiles } from "@fresh/core";
import { App, fsRoutes, staticFiles } from "fresh";

export const app = new App()
// Add static file serving middleware
Expand Down Expand Up @@ -178,8 +178,8 @@ you can add if needed. This middleware can be used to ensure that URLs always
have a trailing slash at the end or that they will never have one.

```diff
- import { App, staticFiles } from "@fresh/core";
+ import { App, staticFiles, trailingSlashes } from "@fresh/core";
- import { App, staticFiles } from "fresh";
+ import { App, staticFiles, trailingSlashes } from "fresh";

export const app = new App({ root: import.meta.url })
.use(staticFiles())
Expand Down
10 changes: 5 additions & 5 deletions init/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ ${GRADIENT_CSS}
// Skip this and be silent if there is a network issue.
}

const MAIN_TS = `import { App, staticFiles, fsRoutes } from "@fresh/core";
const MAIN_TS = `import { App, staticFiles, fsRoutes } from "fresh";
import { State } from "./utils.ts";
export const app = new App<State>();
Expand Down Expand Up @@ -406,7 +406,7 @@ export function Button(props: ButtonProps) {
`;
await writeFile("components/Button.tsx", COMPONENTS_BUTTON_TSX);

const UTILS_TS = `import { createDefine } from "@fresh/core";
const UTILS_TS = `import { createDefine } from "fresh";
// deno-lint-ignore no-empty-interface
export interface State {}
Expand Down Expand Up @@ -444,7 +444,7 @@ export default define.page(function Home() {
})`;
await writeFile("routes/index.tsx", ROUTES_HOME);

const APP_WRAPPER = `import { type PageProps } from "@fresh/core";
const APP_WRAPPER = `import { type PageProps } from "fresh";
export default function App({ Component }: PageProps) {
return (
Expand Down Expand Up @@ -484,7 +484,7 @@ export default function Counter(props: CounterProps) {

const DEV_TS = `#!/usr/bin/env -S deno run -A --watch=static/,routes/
${useTailwind ? `import { tailwind } from "@fresh/plugin-tailwind";\n` : ""};
import { Builder } from "@fresh/core/dev";
import { Builder } from "fresh/dev";
import { app } from "./main.ts";
const builder = new Builder();
Expand Down Expand Up @@ -514,7 +514,7 @@ if (Deno.args.includes("build")) {
},
exclude: ["**/_fresh/*"],
imports: {
"@fresh/core": `jsr:@fresh/core@^${FRESH_VERSION}`,
"fresh": `jsr:@fresh/core@^${FRESH_VERSION}`,
"@fresh/plugin-tailwind":
`jsr:@fresh/plugin-tailwind@^${FRESH_TAILWIND_VERSION}`,
"preact": `npm:preact@^${PREACT_VERSION}`,
Expand Down
4 changes: 2 additions & 2 deletions init/src/init_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ async function patchProject(dir: string): Promise<void> {
);

json.imports = rootJson.imports;
json.imports["@fresh/core"] = "../src/mod.ts";
json.imports["@fresh/core/dev"] = "../src/dev/mod.ts";
json.imports["fresh"] = "../src/mod.ts";
json.imports["fresh/dev"] = "../src/dev/mod.ts";
json.imports["@fresh/plugin-tailwind"] = "../plugin-tailwindcss/mod.ts";

await Deno.writeTextFile(jsonPath, JSON.stringify(json, null, 2));
Expand Down
2 changes: 1 addition & 1 deletion plugin-tailwindcss/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A Tailwind CSS plugin to use in Fresh.
// dev.ts

import { tailwind } from "@fresh/plugin-tailwind";
import { FreshDevApp } from "@fresh/core/dev";
import { FreshDevApp } from "fresh/dev";
import { app } from "./main.ts";

const devApp = new FreshDevApp();
Expand Down
2 changes: 1 addition & 1 deletion plugin-tailwindcss/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
".": "./src/mod.ts"
},
"imports": {
"@fresh/core": "jsr:@fresh/core@^2.0.0-alpha.1",
"fresh": "jsr:@fresh/core@^2.0.0-alpha.1",
"@std/path": "jsr:@std/path@^0.221.0",
"autoprefixer": "npm:autoprefixer@10.4.17",
"cssnano": "npm:cssnano@6.0.3",
Expand Down
2 changes: 1 addition & 1 deletion plugin-tailwindcss/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cssnano from "cssnano";
import autoprefixer from "autoprefixer";
import * as path from "@std/path";
import type { TailwindPluginOptions } from "./types.ts";
import type { ResolvedFreshConfig } from "@fresh/core";
import type { ResolvedFreshConfig } from "fresh";

const CONFIG_EXTENSIONS = ["ts", "js", "mjs"];

Expand Down
4 changes: 2 additions & 2 deletions plugin-tailwindcss/src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { TailwindPluginOptions } from "./types.ts";
import { initTailwind } from "./compiler.ts";
import type { Builder } from "@fresh/core/dev";
import type { App } from "@fresh/core";
import type { Builder } from "fresh/dev";
import type { App } from "fresh";

export function tailwind<T>(
builder: Builder,
Expand Down
4 changes: 2 additions & 2 deletions src/context_test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "@std/expect";
import { FreshReqContext } from "./context.ts";
import { App } from "@fresh/core";
import { asset } from "@fresh/core/runtime";
import { App } from "fresh";
import { asset } from "fresh/runtime";
import { FakeServer } from "./test_utils.ts";
import { BUILD_ID } from "./runtime/build_id.ts";
import { parseHtml } from "../tests/test_utils.tsx";
Expand Down
4 changes: 2 additions & 2 deletions src/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface Define<State> {
* returned from the handler is of the correct type:
*
* ```ts
* import { page } from "@fresh/core";
* import { page } from "fresh";
* import { define } from "../utils.ts";
*
* export const handler = define.handlers<{ slug: string }>({
Expand Down Expand Up @@ -80,7 +80,7 @@ export interface Define<State> {
* return type of the handler method.
*
* ```ts
* import { page } from "@fresh/core";
* import { page } from "fresh";
* import { define } from "../utils.ts";
*
* export const handler = define.handlers({
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/static_files.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from "@std/path";
import { contentType as getContentType } from "@std/media-types/content-type";
import type { MiddlewareFn } from "@fresh/core";
import type { MiddlewareFn } from "fresh";
import { ASSET_CACHE_BUST_KEY } from "../runtime/shared_internal.tsx";
import { BUILD_ID } from "../runtime/build_id.ts";
import { getBuildCache } from "../context.ts";
Expand Down
4 changes: 2 additions & 2 deletions tests/active_links_test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, staticFiles } from "@fresh/core";
import { App, staticFiles } from "fresh";
import {
allIslandApp,
assertNotSelector,
Expand All @@ -14,7 +14,7 @@ import { SelfCounter } from "./fixtures_islands/SelfCounter.tsx";
import { PartialInIsland } from "./fixtures_islands/PartialInIsland.tsx";
import { JsonIsland } from "./fixtures_islands/JsonIsland.tsx";
import { FakeServer } from "../src/test_utils.ts";
import { Partial } from "@fresh/core/runtime";
import { Partial } from "fresh/runtime";
import { getBuildCache, setBuildCache } from "../src/app.ts";

await buildProd(allIslandApp);
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures_islands/NodeProcess.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect } from "preact/hooks";
import { useSignal } from "@preact/signals";
import { IS_BROWSER } from "@fresh/core/runtime";
import { IS_BROWSER } from "fresh/runtime";

export function NodeProcess() {
const active = useSignal(false);
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures_islands/PartialInIsland.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Partial } from "@fresh/core/runtime";
import { Partial } from "fresh/runtime";

export function PartialInIsland() {
return (
Expand Down
2 changes: 1 addition & 1 deletion tests/islands_test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, fsRoutes } from "@fresh/core";
import { App, fsRoutes } from "fresh";
import { Counter } from "./fixtures_islands/Counter.tsx";
import { IslandInIsland } from "./fixtures_islands/IslandInIsland.tsx";
import { JsonIsland } from "./fixtures_islands/JsonIsland.tsx";
Expand Down
4 changes: 2 additions & 2 deletions tests/partials_test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App, staticFiles } from "@fresh/core";
import { Partial } from "@fresh/core/runtime";
import { App, staticFiles } from "fresh";
import { Partial } from "fresh/runtime";
import {
allIslandApp,
assertMetaContent,
Expand Down
12 changes: 6 additions & 6 deletions update/src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function updateProject(dir: string) {
config.imports = {};
}

config.imports["@fresh/core"] = `jsr:@fresh/core@^${FRESH_VERSION}`;
config.imports["fresh"] = `jsr:@fresh/core@^${FRESH_VERSION}`;
config.imports["preact"] = `npm:preact@^${PREACT_VERSION}`;
config.imports["@preact/signals"] =
`npm:@preact/signals@^${PREACT_SIGNALS_VERSION}`;
Expand Down Expand Up @@ -233,7 +233,7 @@ async function updateFile(sourceFile: tsmorph.SourceFile): Promise<void> {
removeEmptyImport(d);
} else if (specifier === "$fresh/server.ts") {
hasCoreImport = true;
d.setModuleSpecifier("@fresh/core");
d.setModuleSpecifier("fresh");

for (const n of d.getNamedImports()) {
const name = n.getName();
Expand All @@ -252,7 +252,7 @@ async function updateFile(sourceFile: tsmorph.SourceFile): Promise<void> {
removeEmptyImport(d);
} else if (specifier === "$fresh/runtime.ts") {
hasRuntimeImport = true;
d.setModuleSpecifier("@fresh/core/runtime");
d.setModuleSpecifier("fresh/runtime");

for (const n of d.getNamedImports()) {
const name = n.getName();
Expand All @@ -270,19 +270,19 @@ async function updateFile(sourceFile: tsmorph.SourceFile): Promise<void> {

if (!hasCoreImport && newImports.core.size > 0) {
sourceFile.addImportDeclaration({
moduleSpecifier: "@fresh/core",
moduleSpecifier: "fresh",
namedImports: Array.from(newImports.core),
});
}
if (!hasRuntimeImport && newImports.runtime.size > 0) {
sourceFile.addImportDeclaration({
moduleSpecifier: "@fresh/core/runtime",
moduleSpecifier: "fresh/runtime",
namedImports: Array.from(newImports.core),
});
}
if (newImports.compat.size > 0) {
sourceFile.addImportDeclaration({
moduleSpecifier: "@fresh/core/compat",
moduleSpecifier: "fresh/compat",
namedImports: Array.from(newImports.compat),
});
}
Expand Down
Loading

0 comments on commit c3ec742

Please sign in to comment.