Skip to content

Commit

Permalink
fix(devtools): compatible with latest rsdoctor manifest (#5763)
Browse files Browse the repository at this point in the history
  • Loading branch information
Asuka109 committed May 22, 2024
1 parent cf59f2a commit e435bb3
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 137 deletions.
4 changes: 2 additions & 2 deletions packages/devtools/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
"flatted": "^3.2.9",
"ws": "^8.13.0",
"cookie-es": "^1.0.0",
"@rsdoctor/types": "^0.1.3",
"@rsdoctor/utils": "^0.1.3"
"@rsdoctor/types": "^0.2.4",
"@rsdoctor/utils": "^0.2.4"
},
"devDependencies": {
"@babel/core": "^7.23.2",
Expand Down
1 change: 1 addition & 0 deletions packages/devtools/plugin/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const devtoolsPlugin = (
watcher.on('unlink', refreshStoragePreset);
},
modifyFileSystemRoutes: rpc.hooks.modifyFileSystemRoutes,
afterCreateCompiler: rpc.hooks.afterCreateCompiler,
beforeRestart() {
closeWatcher();
return new Promise((resolve, reject) =>
Expand Down
24 changes: 21 additions & 3 deletions packages/devtools/plugin/src/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,19 @@ export const setupClientConnection = async (
clientRpcOptions,
);

let _pendingCompiler = 0;
const resolveRsdoctorManifest = async () => {
_pendingCompiler -= 1;
if (_pendingCompiler === 0) {
try {
const doctor = await getDoctorOverview(await $state.framework.context);
$resolvers.doctor.resolve(doctor);
} catch (err) {
$resolvers.doctor.resolve(undefined);
}
}
};

const hooks: InjectedHooks = {
prepare() {
const frameworkContext = {
Expand All @@ -240,14 +253,19 @@ export const setupClientConnection = async (
$resolvers.framework.config.transformed.resolve(
api.useResolvedConfigContext(),
);
getDoctorOverview(frameworkContext)
.then(doctor => $resolvers.doctor.resolve(doctor))
.catch(() => $resolvers.doctor.resolve(undefined));
},
modifyFileSystemRoutes({ entrypoint, routes }) {
$state.fileSystemRoutes[entrypoint.entryName] = _.cloneDeep(routes);
return { entrypoint, routes };
},
afterCreateCompiler({ compiler }) {
if (!compiler) return;
_pendingCompiler += 1;
compiler.hooks.done.tap(
{ name: '@modern-js/plugin-devtools', stage: 4000 },
() => resolveRsdoctorManifest(),
);
},
};

const builderPlugin: RsbuildPlugin = {
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools/plugin/src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ export type Hooks = BaseHooks<any> & AppToolsHooks<any>;

export type InjectedHooks = Pick<
ToThreads<Hooks>,
'prepare' | 'modifyFileSystemRoutes'
'prepare' | 'modifyFileSystemRoutes' | 'afterCreateCompiler'
>;
Loading

0 comments on commit e435bb3

Please sign in to comment.