@modern-js/runtime 1.16.0 → 1.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @modern-js/runtime
2
2
 
3
+ ## 1.16.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: runtime type
8
+
9
+ fix: 修复 runtime 类型定义
10
+
3
11
  ## 1.16.0
4
12
 
5
13
  ### Minor Changes
@@ -13,8 +13,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
13
13
  import React, { useContext, useMemo } from 'react';
14
14
  import defaultReactDOM from 'react-dom';
15
15
  import hoistNonReactStatics from 'hoist-non-react-statics';
16
+ import { RuntimeReactContext } from "../runtime-context";
16
17
  import { runtime } from "./plugin";
17
- import { RuntimeReactContext } from "./runtime-context";
18
18
  import { createLoaderManager } from "./loader/loaderManager";
19
19
  import { jsx as _jsx } from "react/jsx-runtime";
20
20
  const IS_REACT18 = process.env.IS_REACT18 === 'true';
@@ -2,6 +2,6 @@ export { createPlugin, createRuntime, runtime, registerInit, registerPrefetch }
2
2
  export { defineConfig, getConfig } from "./app-config";
3
3
  // compatible
4
4
  export * from "./compatible";
5
- export { RuntimeReactContext } from "./runtime-context";
5
+ export { RuntimeReactContext } from "../runtime-context";
6
6
  export * from "./loader";
7
7
  export * from '@modern-js/plugin';
@@ -6,7 +6,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
6
6
 
7
7
  import { useContext, useRef, useMemo, useState, useCallback, useEffect } from 'react';
8
8
  import invariant from 'invariant';
9
- import { RuntimeReactContext } from "../runtime-context";
9
+ import { RuntimeReactContext } from "../../runtime-context";
10
10
  import { LoaderStatus } from "./loaderManager";
11
11
 
12
12
  const useLoader = (loaderFn, options = {
@@ -28,7 +28,9 @@ const plugin = () => ({
28
28
  }
29
29
 
30
30
  if (!isBrowser()) {
31
- const html = await require("./serverRender").render(context, (context === null || context === void 0 ? void 0 : context.ssrContext.distDir) || path.join(process.cwd(), 'dist'), App);
31
+ var _context$ssrContext;
32
+
33
+ const html = await require("./serverRender").render(context, (context === null || context === void 0 ? void 0 : (_context$ssrContext = context.ssrContext) === null || _context$ssrContext === void 0 ? void 0 : _context$ssrContext.distDir) || path.join(process.cwd(), 'dist'), App);
32
34
  return html;
33
35
  }
34
36
 
@@ -51,6 +53,7 @@ const plugin = () => ({
51
53
  context,
52
54
  pickedContext
53
55
  }, next) => {
56
+ // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
54
57
  const {
55
58
  request,
56
59
  response
@@ -1,5 +1,4 @@
1
1
  import { run } from '@modern-js/utils/ssr';
2
- import { RuntimeContext } from "../../core";
3
2
  import { PreRender } from "../react/prerender";
4
3
  import SSREntry from "./entry";
5
4
  import { time } from "./measure";
@@ -11,9 +11,9 @@ var _reactDom = _interopRequireDefault(require("react-dom"));
11
11
 
12
12
  var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
13
13
 
14
- var _plugin = require("./plugin");
14
+ var _runtimeContext = require("../runtime-context");
15
15
 
16
- var _runtimeContext = require("./runtime-context");
16
+ var _plugin = require("./plugin");
17
17
 
18
18
  var _loaderManager = require("./loader/loaderManager");
19
19
 
@@ -80,7 +80,7 @@ Object.keys(_compatible).forEach(function (key) {
80
80
  });
81
81
  });
82
82
 
83
- var _runtimeContext = require("./runtime-context");
83
+ var _runtimeContext = require("../runtime-context");
84
84
 
85
85
  var _loader = require("./loader");
86
86
 
@@ -9,7 +9,7 @@ var _react = require("react");
9
9
 
10
10
  var _invariant = _interopRequireDefault(require("invariant"));
11
11
 
12
- var _runtimeContext = require("../runtime-context");
12
+ var _runtimeContext = require("../../runtime-context");
13
13
 
14
14
  var _loaderManager = require("./loaderManager");
15
15
 
@@ -54,7 +54,9 @@ const plugin = () => ({
54
54
  }
55
55
 
56
56
  if (!(0, _common.isBrowser)()) {
57
- const html = await require("./serverRender").render(context, (context === null || context === void 0 ? void 0 : context.ssrContext.distDir) || _path.default.join(process.cwd(), 'dist'), App);
57
+ var _context$ssrContext;
58
+
59
+ const html = await require("./serverRender").render(context, (context === null || context === void 0 ? void 0 : (_context$ssrContext = context.ssrContext) === null || _context$ssrContext === void 0 ? void 0 : _context$ssrContext.distDir) || _path.default.join(process.cwd(), 'dist'), App);
58
60
  return html;
59
61
  }
60
62
 
@@ -77,6 +79,7 @@ const plugin = () => ({
77
79
  context,
78
80
  pickedContext
79
81
  }, next) => {
82
+ // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
80
83
  const {
81
84
  request,
82
85
  response
@@ -7,8 +7,6 @@ exports.render = void 0;
7
7
 
8
8
  var _ssr = require("@modern-js/utils/ssr");
9
9
 
10
- var _core = require("../../core");
11
-
12
10
  var _prerender = require("../react/prerender");
13
11
 
14
12
  var _entry = _interopRequireDefault(require("./entry"));
@@ -7,8 +7,8 @@ var _excluded = ["context"];
7
7
  import React, { useContext, useMemo } from 'react';
8
8
  import defaultReactDOM from 'react-dom';
9
9
  import hoistNonReactStatics from 'hoist-non-react-statics';
10
+ import { RuntimeReactContext } from "../runtime-context";
10
11
  import { runtime } from "./plugin";
11
- import { RuntimeReactContext } from "./runtime-context";
12
12
  import { createLoaderManager } from "./loader/loaderManager";
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  var IS_REACT18 = process.env.IS_REACT18 === 'true';
@@ -2,6 +2,6 @@ export { createPlugin, createRuntime, runtime, registerInit, registerPrefetch }
2
2
  export { defineConfig, getConfig } from "./app-config";
3
3
  // compatible
4
4
  export * from "./compatible";
5
- export { RuntimeReactContext } from "./runtime-context";
5
+ export { RuntimeReactContext } from "../runtime-context";
6
6
  export * from "./loader";
7
7
  export * from '@modern-js/plugin';
@@ -2,7 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import { useContext, useRef, useMemo, useState, useCallback, useEffect } from 'react';
4
4
  import invariant from 'invariant';
5
- import { RuntimeReactContext } from "../runtime-context";
5
+ import { RuntimeReactContext } from "../../runtime-context";
6
6
  import { LoaderStatus } from "./loaderManager";
7
7
 
8
8
  var useLoader = function useLoader(loaderFn) {
@@ -19,7 +19,8 @@ var plugin = function plugin() {
19
19
  return {
20
20
  server: function () {
21
21
  var _server = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
22
- var App, context, html;
22
+ var App, context, _context$ssrContext, html;
23
+
23
24
  return _regeneratorRuntime().wrap(function _callee$(_context2) {
24
25
  while (1) {
25
26
  switch (_context2.prev = _context2.next) {
@@ -39,7 +40,7 @@ var plugin = function plugin() {
39
40
  }
40
41
 
41
42
  _context2.next = 5;
42
- return require("./serverRender").render(context, (context === null || context === void 0 ? void 0 : context.ssrContext.distDir) || path.join(process.cwd(), 'dist'), App);
43
+ return require("./serverRender").render(context, (context === null || context === void 0 ? void 0 : (_context$ssrContext = context.ssrContext) === null || _context$ssrContext === void 0 ? void 0 : _context$ssrContext.distDir) || path.join(process.cwd(), 'dist'), App);
43
44
 
44
45
  case 5:
45
46
  html = _context2.sent;
@@ -64,19 +65,21 @@ var plugin = function plugin() {
64
65
  }(),
65
66
  init: function init(_ref2, next) {
66
67
  var context = _ref2.context;
67
- var request = context.ssrContext.request;
68
+ var _ref3 = context.ssrContext,
69
+ request = _ref3.request;
68
70
  context.ssrContext.request = formatServer(request);
69
71
  return next({
70
72
  context: context
71
73
  });
72
74
  },
73
- pickContext: function pickContext(_ref3, next) {
74
- var context = _ref3.context,
75
- pickedContext = _ref3.pickedContext;
75
+ pickContext: function pickContext(_ref4, next) {
76
+ var context = _ref4.context,
77
+ pickedContext = _ref4.pickedContext;
76
78
 
77
- var _context$ssrContext = context === null || context === void 0 ? void 0 : context.ssrContext,
78
- request = _context$ssrContext.request,
79
- response = _context$ssrContext.response;
79
+ // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
80
+ var _ref5 = context === null || context === void 0 ? void 0 : context.ssrContext,
81
+ request = _ref5.request,
82
+ response = _ref5.response;
80
83
 
81
84
  var initialData = context.initialData;
82
85
  return next({
@@ -1,7 +1,6 @@
1
1
  import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  import { run } from '@modern-js/utils/ssr';
4
- import { RuntimeContext } from "../../core";
5
4
  import { PreRender } from "../react/prerender";
6
5
  import SSREntry from "./entry";
7
6
  import { time } from "./measure";
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
+ import { TRuntimeContext } from '../runtime-context';
2
3
  import { Plugin } from './plugin';
3
- import { TRuntimeContext } from './runtime-context';
4
4
  export declare type CreateAppOptions = {
5
5
  plugins: Plugin[];
6
6
  };
@@ -3,7 +3,7 @@ export type { Plugin } from './plugin';
3
3
  export { defineConfig, getConfig } from './app-config';
4
4
  export type { AppConfig } from './app-config';
5
5
  export * from './compatible';
6
- export type { TRuntimeContext, RuntimeContext } from './runtime-context';
7
- export { RuntimeReactContext } from './runtime-context';
6
+ export type { TRuntimeContext, RuntimeContext } from '../runtime-context';
7
+ export { RuntimeReactContext } from '../runtime-context';
8
8
  export * from './loader';
9
9
  export * from '@modern-js/plugin';
@@ -1,6 +1,6 @@
1
1
  import type React from 'react';
2
2
  import { Setup, ToThreads, CommonAPI, PluginOptions } from '@modern-js/plugin';
3
- import type { RuntimeContext, TRuntimeContext } from './runtime-context';
3
+ import type { RuntimeContext, TRuntimeContext } from '../runtime-context';
4
4
  export interface AppProps {}
5
5
  declare const runtimeHooks: {
6
6
  hoc: import("@modern-js/plugin").Pipeline<{
@@ -1,6 +1,7 @@
1
1
  import type { StateConfig } from './state';
2
2
  import type { RouterConfig } from './router';
3
- export type { Plugin, RuntimeContext, TRuntimeContext, AppConfig } from './core';
3
+ export type { Plugin, AppConfig } from './core';
4
+ export type { BaseRuntimeContext, RuntimeContext, BaseTRuntimeContext, TRuntimeContext } from './runtime-context';
4
5
  export { createApp, createPlugin, useLoader, bootstrap, RuntimeReactContext, registerPrefetch, defineConfig, registerInit, useRuntimeContext } from './core';
5
6
  export { StateConfig, RouterConfig };
6
7
  declare module './core' {
@@ -0,0 +1,24 @@
1
+ /// <reference types="react" />
2
+ import { Store } from '@modern-js-reduck/store';
3
+ import { createLoaderManager } from './core/loader/loaderManager';
4
+ import { runtime } from './core/plugin';
5
+ import { SSRServerContext } from './ssr/serverRender/type';
6
+ export interface BaseRuntimeContext {
7
+ loaderManager: ReturnType<typeof createLoaderManager>;
8
+ runner: ReturnType<typeof runtime.init>;
9
+ ssrContext?: SSRServerContext;
10
+ store?: Store;
11
+ }
12
+ export interface RuntimeContext extends BaseRuntimeContext {
13
+ [key: string]: any;
14
+ }
15
+ export declare const RuntimeReactContext: import("react").Context<RuntimeContext>;
16
+ export interface BaseTRuntimeContext {
17
+ initialData?: Record<string, unknown>;
18
+ request?: SSRServerContext['request'];
19
+ response?: SSRServerContext['response'];
20
+ store?: Store;
21
+ }
22
+ export interface TRuntimeContext extends BaseTRuntimeContext {
23
+ [key: string]: any;
24
+ }
@@ -1,13 +1,6 @@
1
1
  import type { Plugin } from '../core';
2
2
  import { RenderLevel, SSRServerContext } from './serverRender/type';
3
3
  declare module '../core' {
4
- interface RuntimeContext {
5
- ssrContext: SSRServerContext;
6
- }
7
- interface TRuntimeContext {
8
- request: SSRServerContext['request'];
9
- response: SSRServerContext['response'];
10
- }
11
4
  interface SSRContainer {
12
5
  renderLevel: RenderLevel;
13
6
  context?: SSRServerContext;
@@ -1,8 +1,3 @@
1
1
  import { RuntimeContext } from '../../core';
2
2
  import { ModernSSRReactComponent } from './type';
3
- declare module '@modern-js/runtime' {
4
- interface RuntimeContext {
5
- ssrContext?: any;
6
- }
7
- }
8
3
  export declare const render: (ctx: RuntimeContext, _: string | undefined, App: ModernSSRReactComponent) => Promise<string>;
@@ -1,12 +1,6 @@
1
- import { createStore, Store } from '@modern-js-reduck/store';
1
+ import { createStore } from '@modern-js-reduck/store';
2
2
  import type { Plugin } from '../../core';
3
3
  declare module '../../core' {
4
- interface RuntimeContext {
5
- store: Store;
6
- }
7
- interface TRuntimeContext {
8
- store: Store;
9
- }
10
4
  interface SSRData {
11
5
  storeState: any;
12
6
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.16.0",
14
+ "version": "1.16.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./type.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -1,13 +0,0 @@
1
- /// <reference types="react" />
2
- import { createLoaderManager } from './loader/loaderManager';
3
- import { runtime } from './plugin';
4
- export interface RuntimeContext {
5
- loaderManager: ReturnType<typeof createLoaderManager>;
6
- runner: ReturnType<typeof runtime.init>;
7
- [key: string]: any;
8
- }
9
- export declare const RuntimeReactContext: import("react").Context<RuntimeContext>;
10
- export interface TRuntimeContext {
11
- initialData?: Record<string, unknown>;
12
- [key: string]: any;
13
- }