Skip to content

Commit 65f0827

Browse files
Revert "fix(server): support non-function exports from island files (#1986)"
This reverts commit eb7f1c2.
1 parent 719c5f9 commit 65f0827

File tree

12 files changed

+18
-67
lines changed

12 files changed

+18
-67
lines changed

src/dev/mod.ts

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -107,44 +107,9 @@ function toImportSpecifier(file: string) {
107107
return specifier;
108108
}
109109

110-
async function islandImportLine(
111-
file: string,
112-
i: number,
113-
directory: string,
114-
): Promise<string> {
115-
const specifier = toImportSpecifier(file);
116-
const moduleURL = new URL(`file://${directory}/${specifier}`);
117-
const module = await import(moduleURL.href);
118-
const entries = Object.entries(module);
119-
120-
const allExportsAreComponents = entries.every(
121-
([, exportedEntity]) => typeof exportedEntity === "function",
122-
);
123-
124-
// if all exports are components, we can use the simple, existing form
125-
if (allExportsAreComponents) {
126-
return `${JSON.stringify(specifier)}: $$${i},`;
127-
}
128-
129-
// if not all exports are components, list the component exports explicitly
130-
const componentExports = entries
131-
.filter(([, exportedEntity]) => typeof exportedEntity === "function")
132-
.map(([exportName]) => exportName);
133-
134-
const exportsString = componentExports
135-
.map((exp) => `${exp}: $$${i}.${exp}`)
136-
.join(", ");
137-
138-
return `"${specifier}": { ${exportsString} },`;
139-
}
140-
141110
export async function generate(directory: string, manifest: Manifest) {
142111
const { routes, islands } = manifest;
143112

144-
const islandImports = await Promise.all(
145-
islands.map((file, i) => islandImportLine(file, i, directory)),
146-
);
147-
148113
const output = `// DO NOT EDIT. This file is generated by Fresh.
149114
// This file SHOULD be checked into source version control.
150115
// This file is automatically updated during development when running \`dev.ts\`.
@@ -162,7 +127,6 @@ ${
162127
)
163128
.join("\n")
164129
}
165-
import { Manifest } from "$fresh/server.ts";
166130
167131
const manifest = {
168132
routes: {
@@ -174,10 +138,15 @@ const manifest = {
174138
}
175139
},
176140
islands: {
177-
${islandImports.join("\n ")}
141+
${
142+
islands.map((file, i) =>
143+
`${JSON.stringify(`${toImportSpecifier(file)}`)}: $$${i},`
144+
)
145+
.join("\n ")
146+
}
178147
},
179148
baseUrl: import.meta.url,
180-
} satisfies Manifest;
149+
};
181150
182151
export default manifest;
183152
`;

tests/fixture/fresh.gen.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ import * as $$11 from "./islands/folder/subfolder/Counter.tsx";
8888
import * as $$12 from "./islands/kebab-case-counter-test.tsx";
8989
import * as $$13 from "./routes/route-groups-islands/(_islands)/Counter.tsx";
9090
import * as $$14 from "./routes/route-groups-islands/(_islands)/invalid.tsx";
91-
import { Manifest } from "$fresh/server.ts";
9291

9392
const manifest = {
9493
routes: {
@@ -169,11 +168,7 @@ const manifest = {
169168
"./islands/FormIsland.tsx": $$1,
170169
"./islands/Greeter.tsx": $$2,
171170
"./islands/HookIsland.tsx": $$3,
172-
"./islands/MultipleCounters.tsx": {
173-
CounterOne: $$4.CounterOne,
174-
CounterTwo: $$4.CounterTwo,
175-
default: $$4.default,
176-
},
171+
"./islands/MultipleCounters.tsx": $$4,
177172
"./islands/ReturningNull.tsx": $$5,
178173
"./islands/RootFragment.tsx": $$6,
179174
"./islands/RootFragmentWithConditionalFirst.tsx": $$7,
@@ -186,6 +181,6 @@ const manifest = {
186181
"./routes/route-groups-islands/(_islands)/invalid.tsx": $$14,
187182
},
188183
baseUrl: import.meta.url,
189-
} satisfies Manifest;
184+
};
190185

191186
export default manifest;

tests/fixture/islands/MultipleCounters.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ interface CounterProps {
66
id: string;
77
}
88

9-
export const thisShouldNotCauseProblems = 42;
10-
119
export default function CounterZero(props: CounterProps) {
1210
return (
1311
<div id={props.id}>

tests/fixture_build/fresh.gen.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import * as $0 from "./routes/index.tsx";
66
import * as $$0 from "./islands/Counter.tsx";
7-
import { Manifest } from "$fresh/server.ts";
87

98
const manifest = {
109
routes: {
@@ -14,6 +13,6 @@ const manifest = {
1413
"./islands/Counter.tsx": $$0,
1514
},
1615
baseUrl: import.meta.url,
17-
} satisfies Manifest;
16+
};
1817

1918
export default manifest;

tests/fixture_build_out_dir/fresh.gen.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import * as $0 from "./routes/index.tsx";
66
import * as $$0 from "./islands/Counter.tsx";
7-
import { Manifest } from "$fresh/server.ts";
87

98
const manifest = {
109
routes: {
@@ -14,6 +13,6 @@ const manifest = {
1413
"./islands/Counter.tsx": $$0,
1514
},
1615
baseUrl: import.meta.url,
17-
} satisfies Manifest;
16+
};
1817

1918
export default manifest;

tests/fixture_build_out_dir_sub/src/fresh.gen.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import * as $0 from "./routes/index.tsx";
66
import * as $$0 from "./islands/Counter.tsx";
7-
import { Manifest } from "$fresh/server.ts";
87

98
const manifest = {
109
routes: {
@@ -14,6 +13,6 @@ const manifest = {
1413
"./islands/Counter.tsx": $$0,
1514
},
1615
baseUrl: import.meta.url,
17-
} satisfies Manifest;
16+
};
1817

1918
export default manifest;

tests/fixture_build_out_dir_sub2/src/fresh.gen.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import * as $0 from "./routes/index.tsx";
66
import * as $$0 from "./islands/Counter.tsx";
7-
import { Manifest } from "$fresh/server.ts";
87

98
const manifest = {
109
routes: {
@@ -14,6 +13,6 @@ const manifest = {
1413
"./islands/Counter.tsx": $$0,
1514
},
1615
baseUrl: import.meta.url,
17-
} satisfies Manifest;
16+
};
1817

1918
export default manifest;

tests/fixture_build_sub_dir/src/fresh.gen.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import * as $0 from "./routes/index.tsx";
66
import * as $$0 from "./islands/Counter.tsx";
7-
import { Manifest } from "$fresh/server.ts";
87

98
const manifest = {
109
routes: {
@@ -14,6 +13,6 @@ const manifest = {
1413
"./islands/Counter.tsx": $$0,
1514
},
1615
baseUrl: import.meta.url,
17-
} satisfies Manifest;
16+
};
1817

1918
export default manifest;

tests/fixture_build_target/fresh.gen.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import * as $0 from "./routes/index.tsx";
66
import * as $$0 from "./islands/Counter.tsx";
7-
import { Manifest } from "$fresh/server.ts";
87

98
const manifest = {
109
routes: {
@@ -14,6 +13,6 @@ const manifest = {
1413
"./islands/Counter.tsx": $$0,
1514
},
1615
baseUrl: import.meta.url,
17-
} satisfies Manifest;
16+
};
1817

1918
export default manifest;

tests/fixture_config/fresh.gen.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44

55
import * as $0 from "./routes/index.tsx";
66

7-
import { Manifest } from "$fresh/server.ts";
8-
97
const manifest = {
108
routes: {
119
"./routes/index.tsx": $0,
1210
},
1311
islands: {},
1412
baseUrl: import.meta.url,
15-
} satisfies Manifest;
13+
};
1614

1715
export default manifest;

0 commit comments

Comments
 (0)