Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Commit

Permalink
fix: document is not found when generate pha manifest (#360)
Browse files Browse the repository at this point in the history
* fix: document is not found when generate pha manifest

* chore: fix test case
  • Loading branch information
ClarkXia authored Jul 14, 2022
1 parent c18cc8c commit 1bc10c5
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { defineConfig } from '@ice/app';
import pha from '@ice/plugin-pha';

export default defineConfig({
plugins: [pha()],
plugins: [pha({ template: true })],
});
1 change: 1 addition & 0 deletions packages/plugin-pha/src/generateManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Options {
outputDir: string;
parseOptions: Partial<ParseOptions>;
compiler: Compiler;
compileTask?: () => Promise<{ serverEntry: string}>;
}

export async function getAppWorkerContent(
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-pha/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function getDevPath(url: string): string {
return url.startsWith('http') ? `${new URL(url).origin}/` : url;
}

const plugin: Plugin<PluginOptions> = ({ onGetConfig, onHook, context, generator }, options) => {
const plugin: Plugin<PluginOptions> = ({ onGetConfig, onHook, context, generator, serverCompileTask }, options) => {
const { template } = options || {};
const { command, rootDir } = context;

Expand Down Expand Up @@ -118,6 +118,7 @@ const plugin: Plugin<PluginOptions> = ({ onGetConfig, onHook, context, generator
compiler,
rootDir,
outputDir,
compileTask: () => serverCompileTask.get(),
parseOptions: {
publicPath,
urlPrefix,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-pha/src/manifestHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async function getPageConfig(routeId: string, configEntry: string): Promise<Mixe
async function renderPageDocument(routeId: string, serverEntry: string): Promise<string> {
const serverContext = {
req: {
url: routeId,
url: `/${routeId}`,
},
};
const serverModule = await import(serverEntry);
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-pha/src/phaMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function sendResponse(res: ServerResponse, content: string, mime: string): void
const createPHAMiddleware = ({
rootDir,
outputDir,
compileTask,
parseOptions,
compiler,
}: Options): ExpressRequestHandler => {
Expand All @@ -25,7 +26,7 @@ const createPHAMiddleware = ({
const requestAppWorker = req.url === '/app-worker.js';
if (requestManifest || requestAppWorker) {
// Get serverEntry from middleware of server-compile.
const { serverEntry } = req as any;
const { serverEntry } = await compileTask();
const [manifestEntry, routesConfigEntry] = await compileEntires(compiler, { rootDir, outputDir });
let manifest: Manifest = (await import(manifestEntry)).default;
const appWorkerPath = getAppWorkerUrl(manifest, path.join(rootDir, 'src'));
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-pha/tests/manifestHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ describe('parse manifest', () => {
template: true,
});

expect(manifest?.pages![0].document).toBe('<html><body>home-document</body></html>');
expect(manifest?.pages![1].document).toBe('<html><body>about-document</body></html>');
expect(manifest?.pages![2]?.frames![0].document).toBe('<html><body>home-document</body></html>');
expect(manifest?.pages![0].document).toBe('<html><body>/home-document</body></html>');
expect(manifest?.pages![1].document).toBe('<html><body>/about-document</body></html>');
expect(manifest?.pages![2]?.frames![0].document).toBe('<html><body>/home-document</body></html>');
});


Expand Down Expand Up @@ -387,7 +387,7 @@ describe('parse manifest', () => {
const manifest = await parseManifest(phaManifest, options);

expect(manifest.pages![0]?.tab_header?.url).toBe('https://url-prefix.com/header');
expect(manifest.pages![0]?.tab_header?.html).toBe('<html><body>header-document</body></html>');
expect(manifest.pages![0]?.tab_header?.html).toBe('<html><body>/header-document</body></html>');
expect(manifest?.tab_bar?.url).toBe('https://url-prefix.com/CustomTabBar');
});

Expand Down

0 comments on commit 1bc10c5

Please sign in to comment.