Skip to content

Commit

Permalink
fix(devtools): failed to create manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
Asuka109 committed Jul 22, 2024
1 parent e33ee9a commit a5f945a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion packages/devtools/plugin/src/plugins/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import path from 'path';
import {
replacer,
RouteAsset,
type ExportedServerState,
type ServerManifest,
} from '@modern-js/devtools-kit/node';
import { fs, logger, nanoid } from '@modern-js/utils';
import createDeferred from 'p-defer';
import { joinURL } from 'ufo';
import { Plugin } from '../types';

declare global {
Expand All @@ -29,7 +31,21 @@ export const pluginManifest: Plugin = {
const routesManifestName = require.resolve(
'@modern-js/devtools-client/manifest',
);
const routesManifest = await fs.readJSON(routesManifestName);
const routesManifest: { routeAssets: Record<string, RouteAsset> } =
await fs.readJSON(routesManifestName);
const { http } = api.vars;
if (process.env.NODE_ENV !== 'production' && http) {
const assetPrefix = `http://localhost:${http.port}`;
for (const routeAsset of Object.values(routesManifest.routeAssets)) {
routeAsset.assets = routeAsset.assets?.map(asset =>
joinURL(assetPrefix, asset),
);
routeAsset.referenceCssAssets = routeAsset.referenceCssAssets?.map(
asset =>
typeof asset === 'string' ? joinURL(assetPrefix, asset) : asset,
) as [];
}
}
const manifest: ServerManifest = {
...(api.vars.state as ExportedServerState),
routeAssets: routesManifest.routeAssets,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/devtools/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('devtools dev', () => {
FAST_REFRESH: 'false',
},
);
const errors = [];
const errors: string[] = [];

const browser = await puppeteer.launch(launchOptions as any);
const page = await browser.newPage();
Expand Down

0 comments on commit a5f945a

Please sign in to comment.