Skip to content

Commit 9c29354

Browse files
committed
fix: comments
1 parent d5bcdd5 commit 9c29354

File tree

16 files changed

+40
-28
lines changed

16 files changed

+40
-28
lines changed

packages/runtime/plugin-garfish/src/cli/code.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
import type { CollectAsyncHook } from '@modern-js/plugin-v2';
99
import type { Entrypoint } from '@modern-js/types';
1010
import { fs } from '@modern-js/utils';
11-
import type { AppendEntryCodeFn } from '.';
11+
import type { AppendEntryCodeFn } from './hooks';
1212
import * as template from './template';
1313
import { generateAsyncEntryCode } from './utils';
1414

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { Entrypoint } from '@modern-js/types';
2+
3+
export type AppendEntryCodeFn = (params: {
4+
entrypoint: Entrypoint;
5+
code: string;
6+
}) => string | Promise<string>;

packages/runtime/plugin-garfish/src/cli/index.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import type {
55
} from '@modern-js/app-tools';
66
import type { CliHookCallbacks, useConfigContext } from '@modern-js/core';
77
import { createCollectAsyncHook } from '@modern-js/plugin-v2';
8-
import type { Entrypoint } from '@modern-js/types';
98
import { createRuntimeExportsUtils, getEntryOptions } from '@modern-js/utils';
109
import { logger } from '../util';
1110
import { generateCode } from './code';
11+
import type { AppendEntryCodeFn } from './hooks';
1212
import { getRuntimeConfig, setRuntimeConfig } from './utils';
1313

1414
export type UseConfig = ReturnType<typeof useConfigContext>;
@@ -39,11 +39,6 @@ export function getDefaultMicroFrontedConfig(
3939
};
4040
}
4141

42-
export type AppendEntryCodeFn = (params: {
43-
entrypoint: Entrypoint;
44-
code: string;
45-
}) => string | Promise<string>;
46-
4742
export const garfishPlugin = (): CliPluginFuture<AppTools<'shared'>> => ({
4843
name: '@modern-js/plugin-garfish',
4944
pre: ['@modern-js/runtime'],

packages/runtime/plugin-runtime/src/core/browser/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ export async function render(
8484
const context: RuntimeContext = getInitialContext();
8585
const runBeforeRender = async (context: RuntimeContext) => {
8686
const internalRuntimeContext = getGlobalInternalRuntimeContext();
87-
const api = internalRuntimeContext?.pluginAPI;
88-
api?.updateRuntimeContext(context);
89-
const hooks = internalRuntimeContext?.hooks;
87+
const api = internalRuntimeContext!.pluginAPI;
88+
api!.updateRuntimeContext(context);
89+
const hooks = internalRuntimeContext!.hooks;
9090
await hooks.onBeforeRender.call(context);
9191
const init = getGlobalAppInit();
9292
return init?.(context);

packages/runtime/plugin-runtime/src/core/compatible.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export const bootstrap: BootStrap = async (
108108
const hooks = internalRuntimeContext.hooks;
109109

110110
const context: RuntimeContext = getInitialContext();
111-
api?.updateRuntimeContext(context);
111+
api!.updateRuntimeContext(context);
112112

113113
const runBeforeRender = async (context: RuntimeContext) => {
114114
await hooks.onBeforeRender.call(context);

packages/runtime/plugin-runtime/src/core/plugin/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { InternalRuntimeContext, Plugin } from '@modern-js/plugin-v2';
1+
import type { Plugin } from '@modern-js/plugin-v2';
2+
import type { InternalRuntimeContext } from '@modern-js/plugin-v2/runtime';
23
import { runtime } from '@modern-js/plugin-v2/runtime';
34
import { merge } from '@modern-js/runtime-utils/merge';
45
import { compatPlugin } from '../compat';

packages/runtime/plugin-runtime/src/router/runtime/hooks.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import type { RuntimeContext } from '../../core';
55
// only for inhouse use
66
const modifyRoutes = createSyncHook<(routes: RouteObject[]) => RouteObject[]>();
77
const onBeforeCreateRoutes =
8-
createAsyncInterruptHook<
9-
(context: RuntimeContext, interrupt: (info: any) => any) => void
10-
>();
8+
createSyncHook<(context: RuntimeContext) => void>();
119

1210
export { modifyRoutes, onBeforeCreateRoutes };

packages/toolkit/plugin-v2/src/hooks.ts

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export function createAsyncInterruptHook<
2121
let interruptResult: any;
2222

2323
const interrupt = (info: any) => {
24-
console.log('===interrupt');
2524
interrupted = true;
2625
interruptResult = info;
2726
};

packages/toolkit/plugin-v2/src/runtime/api.ts

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export function initPluginAPI<Extends extends RuntimePluginExtends>({
7676
}
7777

7878
return {
79-
getRuntimeContext,
8079
updateRuntimeContext,
8180
getHooks,
8281
getRuntimeConfig,

packages/toolkit/plugin-v2/src/runtime/hooks.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ import {
44
createSyncHook,
55
} from '../hooks';
66
import type {
7+
Hooks,
78
ModifyRuntimeConfigFn,
89
OnBeforeRenderFn,
910
PickContextFn,
1011
WrapRootFn,
1112
} from '../types/runtime/hooks';
1213

13-
export function initHooks<RuntimeConfig, RuntimeContext>() {
14+
export function initHooks<RuntimeConfig, RuntimeContext>(): Hooks<
15+
RuntimeConfig,
16+
RuntimeContext
17+
> {
1418
return {
1519
onBeforeRender:
1620
createAsyncInterruptHook<OnBeforeRenderFn<RuntimeContext>>(),
@@ -20,7 +24,3 @@ export function initHooks<RuntimeConfig, RuntimeContext>() {
2024
createCollectSyncHook<ModifyRuntimeConfigFn<RuntimeConfig>>(),
2125
};
2226
}
23-
24-
export type Hooks<RuntimeConfig, RuntimeContext> = ReturnType<
25-
typeof initHooks<RuntimeConfig, RuntimeContext>
26-
>;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
export { initPluginAPI } from './api';
22
export { initRuntimeContext, createRuntimeContext } from './context';
3-
export { initHooks, type Hooks } from './hooks';
3+
export { initHooks } from './hooks';
44
export { runtime } from './run';
5+
export type {
6+
RuntimePluginAPI,
7+
RuntimeContext,
8+
InternalRuntimeContext,
9+
RuntimePlugin,
10+
RuntimePluginExtends,
11+
Hooks,
12+
} from '../types/runtime';

packages/toolkit/plugin-v2/src/runtime/run/create.ts

-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ export const createRuntime = <Extends extends RuntimePluginExtends>() => {
6060
}
6161

6262
return {
63-
init,
6463
run,
65-
getPrevInitOptions: () => initOptions,
6664
};
6765
};

packages/toolkit/plugin-v2/src/types/runtime/api.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { Hooks } from '../../runtime';
21
import type { PluginHookTap } from '../hooks';
32
import type { DeepPartial } from '../utils';
43
import type { RuntimeContext } from './context';
4+
import type { Hooks } from './hooks';
55
import type {
66
ModifyRuntimeConfigFn,
77
OnBeforeRenderFn,
@@ -11,7 +11,6 @@ import type {
1111
import type { RuntimePluginExtends } from './plugin';
1212

1313
export type RuntimePluginAPI<Extends extends RuntimePluginExtends> = Readonly<{
14-
getRuntimeContext: () => Readonly<RuntimeContext & Extends['extendContext']>;
1514
updateRuntimeContext: (updateContext: DeepPartial<RuntimeContext>) => void;
1615
getHooks: () => Readonly<
1716
Hooks<Extends['config'], RuntimeContext & Extends['extendContext']> &

packages/toolkit/plugin-v2/src/types/runtime/context.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Hooks } from '../../runtime/hooks';
21
import type { RuntimePluginAPI } from './api';
2+
import type { Hooks } from './hooks';
33
import type { RuntimePluginExtends } from './plugin';
44

55
export type RuntimeContext = {};

packages/toolkit/plugin-v2/src/types/runtime/hooks.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type React from 'react';
2+
import type { AsyncInterruptHook, CollectSyncHook, SyncHook } from '../hooks';
23

34
export type OnBeforeRenderFn<RuntimeContext> = (
45
context: RuntimeContext,
@@ -16,3 +17,10 @@ export type PickContextFn<RuntimeContext> = (
1617
export type ModifyRuntimeConfigFn<RuntimeConfig> = (
1718
config: RuntimeConfig,
1819
) => RuntimeConfig;
20+
21+
export type Hooks<RuntimeConfig, RuntimeContext> = {
22+
onBeforeRender: AsyncInterruptHook<OnBeforeRenderFn<RuntimeContext>>;
23+
wrapRoot: SyncHook<WrapRootFn>;
24+
pickContext: SyncHook<PickContextFn<RuntimeContext>>;
25+
modifyRuntimeConfig: CollectSyncHook<ModifyRuntimeConfigFn<RuntimeConfig>>;
26+
};
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export type { RuntimePluginAPI } from './api';
22
export type { RuntimeContext, InternalRuntimeContext } from './context';
33
export type { RuntimePlugin, RuntimePluginExtends } from './plugin';
4+
export type { Hooks } from './hooks';

0 commit comments

Comments
 (0)