feat: import fresh from fresh (#2479)
Instead of importing as `@fresh/core`.
This commit is contained in:
@@ -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}`;
|
||||
@@ -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();
|
||||
@@ -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();
|
||||
@@ -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),
|
||||
});
|
||||
}
|
||||
|
||||
+20
-20
@@ -82,7 +82,7 @@ Deno.test("update - 1.x project deno.json", async () => {
|
||||
expect(JSON.parse(files["/deno.json"]))
|
||||
.toEqual({
|
||||
imports: {
|
||||
"@fresh/core": `jsr:@fresh/core@^${FRESH_VERSION}`,
|
||||
"fresh": `jsr:@fresh/core@^${FRESH_VERSION}`,
|
||||
"@preact/signals": `npm:@preact/signals@^${PREACT_SIGNALS_VERSION}`,
|
||||
"preact": `npm:preact@^${PREACT_VERSION}`,
|
||||
},
|
||||
@@ -106,7 +106,7 @@ Deno.test("update - 1.x project deno.json with imports", async () => {
|
||||
expect(JSON.parse(files["/deno.json"]))
|
||||
.toEqual({
|
||||
imports: {
|
||||
"@fresh/core": `jsr:@fresh/core@^${FRESH_VERSION}`,
|
||||
"fresh": `jsr:@fresh/core@^${FRESH_VERSION}`,
|
||||
"@preact/signals": `npm:@preact/signals@^${PREACT_SIGNALS_VERSION}`,
|
||||
"preact": `npm:preact@^${PREACT_VERSION}`,
|
||||
},
|
||||
@@ -141,7 +141,7 @@ export async function handler(
|
||||
const files = await readFiles(dir);
|
||||
|
||||
expect(files["/routes/_middleware.ts"])
|
||||
.toEqual(`import { FreshContext } from "@fresh/core";
|
||||
.toEqual(`import { FreshContext } from "fresh";
|
||||
|
||||
interface State {
|
||||
data: string;
|
||||
@@ -174,7 +174,7 @@ Deno.test("update - 1.x project middlewares one arg", async () => {
|
||||
const files = await readFiles(dir);
|
||||
|
||||
expect(files["/routes/_middleware.ts"])
|
||||
.toEqual(`import { FreshContext } from "@fresh/core";
|
||||
.toEqual(`import { FreshContext } from "fresh";
|
||||
|
||||
export async function handler(ctx: FreshContext) {
|
||||
const req = ctx.req;
|
||||
@@ -199,12 +199,12 @@ export default function Foo(props: PageProps) {
|
||||
const files = await readFiles(dir);
|
||||
|
||||
expect(files["/routes/index.tsx"])
|
||||
.toEqual(`import { PageProps } from "@fresh/core";
|
||||
.toEqual(`import { PageProps } from "fresh";
|
||||
export default function Foo(props: PageProps) {
|
||||
return null;
|
||||
}`);
|
||||
expect(files["/routes/foo.tsx"])
|
||||
.toEqual(`import { asset, Head } from "@fresh/core/runtime";`);
|
||||
.toEqual(`import { asset, Head } from "fresh/runtime";`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -254,7 +254,7 @@ export const handler: Handlers = {
|
||||
const files = await readFiles(dir);
|
||||
|
||||
expect(files["/routes/index.tsx"])
|
||||
.toEqual(`import { Handlers } from "@fresh/core/compat";
|
||||
.toEqual(`import { Handlers } from "fresh/compat";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(ctx) {
|
||||
@@ -274,7 +274,7 @@ export const handler: Handlers = {
|
||||
},
|
||||
};`);
|
||||
expect(files["/routes/foo.tsx"])
|
||||
.toEqual(`import { Handlers } from "@fresh/core/compat";
|
||||
.toEqual(`import { Handlers } from "fresh/compat";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(ctx) {},
|
||||
@@ -285,7 +285,7 @@ export const handler: Handlers = {
|
||||
};`);
|
||||
|
||||
expect(files["/routes/name.tsx"])
|
||||
.toEqual(`import { Handlers } from "@fresh/core/compat";
|
||||
.toEqual(`import { Handlers } from "fresh/compat";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(ctx) {
|
||||
@@ -305,7 +305,7 @@ export const handler: Handlers = {
|
||||
},
|
||||
};`);
|
||||
expect(files["/routes/name-unused.tsx"])
|
||||
.toEqual(`import { Handlers } from "@fresh/core/compat";
|
||||
.toEqual(`import { Handlers } from "fresh/compat";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(ctx) {},
|
||||
@@ -393,7 +393,7 @@ Deno.test(
|
||||
await updateProject(dir);
|
||||
const files = await readFiles(dir);
|
||||
expect(files["/routes/index.tsx"])
|
||||
.toEqual(`import { FreshContext } from "@fresh/core";
|
||||
.toEqual(`import { FreshContext } from "fresh";
|
||||
|
||||
export const handler = {
|
||||
GET(ctx: FreshContext) {
|
||||
@@ -425,7 +425,7 @@ export const handler: Handlers = {
|
||||
await updateProject(dir);
|
||||
const files = await readFiles(dir);
|
||||
expect(files["/routes/index.tsx"])
|
||||
.toEqual(`import { Handlers } from "@fresh/core/compat";
|
||||
.toEqual(`import { Handlers } from "fresh/compat";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET({ params, render, info, req }) {
|
||||
@@ -470,7 +470,7 @@ export default defineRoute(async (req, ctx) => {
|
||||
const files = await readFiles(dir);
|
||||
|
||||
expect(files["/routes/_app.tsx"])
|
||||
.toEqual(`import { defineApp } from "@fresh/core/compat";
|
||||
.toEqual(`import { defineApp } from "fresh/compat";
|
||||
|
||||
export default defineApp(async (ctx) => {
|
||||
const req = ctx.req;
|
||||
@@ -478,7 +478,7 @@ export default defineApp(async (ctx) => {
|
||||
return null;
|
||||
});`);
|
||||
expect(files["/routes/_layout.tsx"])
|
||||
.toEqual(`import { defineLayout } from "@fresh/core/compat";
|
||||
.toEqual(`import { defineLayout } from "fresh/compat";
|
||||
|
||||
export default defineLayout(async (ctx) => {
|
||||
const req = ctx.req;
|
||||
@@ -486,7 +486,7 @@ export default defineLayout(async (ctx) => {
|
||||
return null;
|
||||
});`);
|
||||
expect(files["/routes/foo.tsx"])
|
||||
.toEqual(`import { defineRoute } from "@fresh/core/compat";
|
||||
.toEqual(`import { defineRoute } from "fresh/compat";
|
||||
|
||||
export default defineRoute(async (ctx) => {
|
||||
const req = ctx.req;
|
||||
@@ -517,7 +517,7 @@ Deno.test(
|
||||
await updateProject(dir);
|
||||
const files = await readFiles(dir);
|
||||
expect(files["/routes/index.tsx"])
|
||||
.toEqual(`import { FreshContext } from "@fresh/core";
|
||||
.toEqual(`import { FreshContext } from "fresh";
|
||||
|
||||
export default async function Index(ctx: FreshContext) {
|
||||
const req = ctx.req;
|
||||
@@ -557,7 +557,7 @@ export const handler: Handlers = {
|
||||
const files = await readFiles(dir);
|
||||
|
||||
expect(files["/routes/index.tsx"])
|
||||
.toEqual(`import { Handlers } from "@fresh/core";
|
||||
.toEqual(`import { Handlers } from "fresh";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(ctx) {
|
||||
@@ -594,7 +594,7 @@ export const handler: Handlers = {
|
||||
const files = await readFiles(dir);
|
||||
|
||||
expect(files["/routes/index.tsx"])
|
||||
.toEqual(`import { Handlers } from "@fresh/core";
|
||||
.toEqual(`import { Handlers } from "fresh";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(ctx) {
|
||||
@@ -629,7 +629,7 @@ export const handler: Handlers = {
|
||||
const files = await readFiles(dir);
|
||||
|
||||
expect(files["/routes/index.tsx"])
|
||||
.toEqual(`import { Handlers } from "@fresh/core";
|
||||
.toEqual(`import { Handlers } from "fresh";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET({ url, throw, info }) {
|
||||
@@ -677,7 +677,7 @@ Deno.test("update - island files", async () => {
|
||||
const files = await readFiles(dir);
|
||||
|
||||
expect(files["/islands/foo.tsx"]).toEqual(
|
||||
`import { IS_BROWSER } from "@fresh/core/runtime";`,
|
||||
`import { IS_BROWSER } from "fresh/runtime";`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user