@modern-js/runtime 2.23.1 → 2.24.0

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,21 @@
1
1
  # @modern-js/runtime
2
2
 
3
+ ## 2.24.0
4
+
5
+ ### Patch Changes
6
+
7
+ - c882fbd: feat: support config main entry name
8
+
9
+ feat: 支持配置主入口名称
10
+
11
+ - 56693a3: fix(plugin-ssr): ssr script、link should add some attrs, like ["defer", "crossorigin"]
12
+ fix(plugin-ssr): ssr script,link 标签应该添加像 ["defer", "crossorigin"] 属性
13
+ - Updated dependencies [c882fbd]
14
+ - Updated dependencies [4a82c3b]
15
+ - @modern-js/types@2.24.0
16
+ - @modern-js/utils@2.24.0
17
+ - @modern-js/plugin@2.24.0
18
+
3
19
  ## 2.23.1
4
20
 
5
21
  ### Patch Changes
@@ -54,10 +54,10 @@ const _default = () => {
54
54
  ];
55
55
  },
56
56
  modifyEntryImports({ entrypoint, imports }) {
57
- const { entryName, fileSystemRoutes } = entrypoint;
57
+ const { entryName, isMainEntry, fileSystemRoutes } = entrypoint;
58
58
  const userConfig = api.useResolvedConfigContext();
59
59
  const { packageName } = api.useAppContext();
60
- const runtimeConfig = (0, _utils.getEntryOptions)(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
60
+ const runtimeConfig = (0, _utils.getEntryOptions)(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
61
61
  runtimeConfigMap.set(entryName, runtimeConfig);
62
62
  if (runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) {
63
63
  if (!(0, _utils.isRouterV5)(userConfig)) {
@@ -93,14 +93,14 @@ const _default = () => {
93
93
  };
94
94
  },
95
95
  modifyEntryImports({ entrypoint, imports }) {
96
- const { entryName, fileSystemRoutes } = entrypoint;
96
+ const { entryName, isMainEntry, fileSystemRoutes } = entrypoint;
97
97
  const userConfig = api.useResolvedConfigContext();
98
98
  const { packageName, entrypoints } = api.useAppContext();
99
99
  pluginsExportsUtils.addExport(`export { default as ssr } from '@modern-js/runtime/ssr'`);
100
- const ssrConfig = (0, _utils.getEntryOptions)(entryName, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
100
+ const ssrConfig = (0, _utils.getEntryOptions)(entryName, isMainEntry, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
101
101
  if (typeof ssrConfig === "object" && ssrConfig.mode === "stream") {
102
102
  var _ref;
103
- const runtimeConfig = (0, _utils.getEntryOptions)(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
103
+ const runtimeConfig = (0, _utils.getEntryOptions)(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
104
104
  if (((_ref = runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) === null || _ref === void 0 ? void 0 : _ref.mode) === "react-router-5") {
105
105
  throw new Error(`router v5 plugin doesn't support streaming SSR, check your config 'runtime.router'`);
106
106
  }
@@ -128,11 +128,15 @@ const _default = () => {
128
128
  modifyEntryRuntimePlugins({ entrypoint, plugins, bundlerConfigs }) {
129
129
  if (ssrConfigMap.get(entrypoint.entryName)) {
130
130
  var _bundlerConfigs_find, _bundlerConfigs_find_output;
131
- const chunkLoadingGlobal = (_bundlerConfigs_find = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : bundlerConfigs.find((config) => config.name === "client")) === null || _bundlerConfigs_find === void 0 ? void 0 : (_bundlerConfigs_find_output = _bundlerConfigs_find.output) === null || _bundlerConfigs_find_output === void 0 ? void 0 : _bundlerConfigs_find_output.chunkLoadingGlobal;
131
+ const chunkLoadingGlobal = (_bundlerConfigs_find = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : bundlerConfigs.find((config2) => config2.name === "client")) === null || _bundlerConfigs_find === void 0 ? void 0 : (_bundlerConfigs_find_output = _bundlerConfigs_find.output) === null || _bundlerConfigs_find_output === void 0 ? void 0 : _bundlerConfigs_find_output.chunkLoadingGlobal;
132
+ const config = api.useResolvedConfigContext();
133
+ const { crossorigin, scriptLoading } = config.html;
132
134
  plugins.push({
133
135
  name: PLUGIN_IDENTIFIER,
134
136
  options: JSON.stringify({
135
137
  ...ssrConfigMap.get(entrypoint.entryName) || {},
138
+ crossorigin,
139
+ scriptLoading,
136
140
  chunkLoadingGlobal
137
141
  })
138
142
  });
@@ -33,18 +33,26 @@ const toHtml = (jsx, renderer, next) => {
33
33
  chunksMap.js = (chunksMap.js || "") + (0, _utils1.getLoadableScripts)(extractor);
34
34
  for (const v of chunks) {
35
35
  const fileType = extname(v.url).slice(1);
36
+ const attributes = {};
37
+ const { crossorigin, scriptLoading = "defer" } = config;
38
+ if (crossorigin && (0, _utils.isCrossOrigin)(v.url, host)) {
39
+ attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
40
+ }
41
+ switch (scriptLoading) {
42
+ case "defer":
43
+ attributes.defer = true;
44
+ break;
45
+ case "module":
46
+ attributes.type = "module";
47
+ break;
48
+ default:
49
+ }
36
50
  if (fileType === "js") {
37
- const attributes = {
38
- nonce
39
- };
40
- const { crossorigin } = config;
41
- if (crossorigin && (0, _utils.isCrossOrigin)(v.url, host)) {
42
- attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
43
- }
51
+ attributes.nonce = nonce;
44
52
  const attrsStr = (0, _utils1.attributesToString)(attributes);
45
53
  chunksMap[fileType] += `<script${attrsStr} src="${v.url}"></script>`;
46
54
  } else if (fileType === "css") {
47
- chunksMap[fileType] += `<link href="${v.url}" rel="stylesheet" />`;
55
+ chunksMap[fileType] += `<link${attributes} href="${v.url}" rel="stylesheet" />`;
48
56
  }
49
57
  }
50
58
  return html;
@@ -33,10 +33,10 @@ const _default = () => {
33
33
  },
34
34
  modifyEntryImports({ entrypoint, imports }) {
35
35
  var _getEntryOptions;
36
- const { entryName } = entrypoint;
36
+ const { entryName, isMainEntry } = entrypoint;
37
37
  const userConfig = api.useResolvedConfigContext();
38
38
  const { packageName } = api.useAppContext();
39
- const stateConfig = (_getEntryOptions = (0, _utils.getEntryOptions)(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
39
+ const stateConfig = (_getEntryOptions = (0, _utils.getEntryOptions)(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
40
40
  stateConfigMap.set(entryName, stateConfig);
41
41
  if (stateConfig) {
42
42
  imports.push({
@@ -47,10 +47,10 @@ export default function() {
47
47
  },
48
48
  modifyEntryImports: function modifyEntryImports(param) {
49
49
  var entrypoint = param.entrypoint, imports = param.imports;
50
- var entryName = entrypoint.entryName, fileSystemRoutes = entrypoint.fileSystemRoutes;
50
+ var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry, fileSystemRoutes = entrypoint.fileSystemRoutes;
51
51
  var userConfig = api.useResolvedConfigContext();
52
52
  var packageName = api.useAppContext().packageName;
53
- var runtimeConfig = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
53
+ var runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
54
54
  runtimeConfigMap.set(entryName, runtimeConfig);
55
55
  if (runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) {
56
56
  if (!isV5(userConfig)) {
@@ -106,14 +106,14 @@ export default function() {
106
106
  },
107
107
  modifyEntryImports: function modifyEntryImports(param) {
108
108
  var entrypoint = param.entrypoint, imports = param.imports;
109
- var entryName = entrypoint.entryName, fileSystemRoutes = entrypoint.fileSystemRoutes;
109
+ var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry, fileSystemRoutes = entrypoint.fileSystemRoutes;
110
110
  var userConfig = api.useResolvedConfigContext();
111
111
  var _api_useAppContext = api.useAppContext(), packageName = _api_useAppContext.packageName, entrypoints = _api_useAppContext.entrypoints;
112
112
  pluginsExportsUtils.addExport("export { default as ssr } from '@modern-js/runtime/ssr'");
113
- var ssrConfig = getEntryOptions(entryName, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
113
+ var ssrConfig = getEntryOptions(entryName, isMainEntry, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
114
114
  if (typeof ssrConfig === "object" && ssrConfig.mode === "stream") {
115
115
  var _ref;
116
- var runtimeConfig = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
116
+ var runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
117
117
  if (((_ref = runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) === null || _ref === void 0 ? void 0 : _ref.mode) === "react-router-5") {
118
118
  throw new Error("router v5 plugin doesn't support streaming SSR, check your config 'runtime.router'");
119
119
  }
@@ -142,12 +142,16 @@ export default function() {
142
142
  var entrypoint = param.entrypoint, plugins = param.plugins, bundlerConfigs = param.bundlerConfigs;
143
143
  if (ssrConfigMap.get(entrypoint.entryName)) {
144
144
  var _bundlerConfigs_find, _bundlerConfigs_find_output;
145
- var chunkLoadingGlobal = (_bundlerConfigs_find = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : bundlerConfigs.find(function(config) {
146
- return config.name === "client";
145
+ var chunkLoadingGlobal = (_bundlerConfigs_find = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : bundlerConfigs.find(function(config2) {
146
+ return config2.name === "client";
147
147
  })) === null || _bundlerConfigs_find === void 0 ? void 0 : (_bundlerConfigs_find_output = _bundlerConfigs_find.output) === null || _bundlerConfigs_find_output === void 0 ? void 0 : _bundlerConfigs_find_output.chunkLoadingGlobal;
148
+ var config = api.useResolvedConfigContext();
149
+ var _config_html = config.html, crossorigin = _config_html.crossorigin, scriptLoading = _config_html.scriptLoading;
148
150
  plugins.push({
149
151
  name: PLUGIN_IDENTIFIER,
150
152
  options: JSON.stringify(_object_spread_props(_object_spread({}, ssrConfigMap.get(entrypoint.entryName) || {}), {
153
+ crossorigin: crossorigin,
154
+ scriptLoading: scriptLoading,
151
155
  chunkLoadingGlobal: chunkLoadingGlobal
152
156
  }))
153
157
  });
@@ -26,18 +26,26 @@ export var toHtml = function(jsx, renderer, next) {
26
26
  for (var _iterator = chunks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
27
27
  var v = _step.value;
28
28
  var fileType = extname(v.url).slice(1);
29
+ var attributes = {};
30
+ var crossorigin = config.crossorigin, _config_scriptLoading = config.scriptLoading, scriptLoading = _config_scriptLoading === void 0 ? "defer" : _config_scriptLoading;
31
+ if (crossorigin && isCrossOrigin(v.url, host)) {
32
+ attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
33
+ }
34
+ switch (scriptLoading) {
35
+ case "defer":
36
+ attributes.defer = true;
37
+ break;
38
+ case "module":
39
+ attributes.type = "module";
40
+ break;
41
+ default:
42
+ }
29
43
  if (fileType === "js") {
30
- var attributes = {
31
- nonce: nonce
32
- };
33
- var crossorigin = config.crossorigin;
34
- if (crossorigin && isCrossOrigin(v.url, host)) {
35
- attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
36
- }
44
+ attributes.nonce = nonce;
37
45
  var attrsStr = attributesToString(attributes);
38
46
  chunksMap[fileType] += "<script".concat(attrsStr, ' src="').concat(v.url, '"></script>');
39
47
  } else if (fileType === "css") {
40
- chunksMap[fileType] += '<link href="'.concat(v.url, '" rel="stylesheet" />');
48
+ chunksMap[fileType] += "<link".concat(attributes, ' href="').concat(v.url, '" rel="stylesheet" />');
41
49
  }
42
50
  }
43
51
  } catch (err) {
@@ -24,10 +24,10 @@ export default function() {
24
24
  modifyEntryImports: function modifyEntryImports(param) {
25
25
  var entrypoint = param.entrypoint, imports = param.imports;
26
26
  var _getEntryOptions;
27
- var entryName = entrypoint.entryName;
27
+ var entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry;
28
28
  var userConfig = api.useResolvedConfigContext();
29
29
  var packageName = api.useAppContext().packageName;
30
- var stateConfig = (_getEntryOptions = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
30
+ var stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
31
31
  stateConfigMap.set(entryName, stateConfig);
32
32
  if (stateConfig) {
33
33
  imports.push({
@@ -44,10 +44,10 @@ export default () => {
44
44
  ];
45
45
  },
46
46
  modifyEntryImports({ entrypoint, imports }) {
47
- const { entryName, fileSystemRoutes } = entrypoint;
47
+ const { entryName, isMainEntry, fileSystemRoutes } = entrypoint;
48
48
  const userConfig = api.useResolvedConfigContext();
49
49
  const { packageName } = api.useAppContext();
50
- const runtimeConfig = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
50
+ const runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
51
51
  runtimeConfigMap.set(entryName, runtimeConfig);
52
52
  if (runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) {
53
53
  if (!isV5(userConfig)) {
@@ -82,14 +82,14 @@ export default () => {
82
82
  };
83
83
  },
84
84
  modifyEntryImports({ entrypoint, imports }) {
85
- const { entryName, fileSystemRoutes } = entrypoint;
85
+ const { entryName, isMainEntry, fileSystemRoutes } = entrypoint;
86
86
  const userConfig = api.useResolvedConfigContext();
87
87
  const { packageName, entrypoints } = api.useAppContext();
88
88
  pluginsExportsUtils.addExport(`export { default as ssr } from '@modern-js/runtime/ssr'`);
89
- const ssrConfig = getEntryOptions(entryName, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
89
+ const ssrConfig = getEntryOptions(entryName, isMainEntry, userConfig.server.ssr, userConfig.server.ssrByEntries, packageName);
90
90
  if (typeof ssrConfig === "object" && ssrConfig.mode === "stream") {
91
91
  var _ref;
92
- const runtimeConfig = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName);
92
+ const runtimeConfig = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName);
93
93
  if (((_ref = runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.router) === null || _ref === void 0 ? void 0 : _ref.mode) === "react-router-5") {
94
94
  throw new Error(`router v5 plugin doesn't support streaming SSR, check your config 'runtime.router'`);
95
95
  }
@@ -117,11 +117,15 @@ export default () => {
117
117
  modifyEntryRuntimePlugins({ entrypoint, plugins, bundlerConfigs }) {
118
118
  if (ssrConfigMap.get(entrypoint.entryName)) {
119
119
  var _bundlerConfigs_find, _bundlerConfigs_find_output;
120
- const chunkLoadingGlobal = (_bundlerConfigs_find = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : bundlerConfigs.find((config) => config.name === "client")) === null || _bundlerConfigs_find === void 0 ? void 0 : (_bundlerConfigs_find_output = _bundlerConfigs_find.output) === null || _bundlerConfigs_find_output === void 0 ? void 0 : _bundlerConfigs_find_output.chunkLoadingGlobal;
120
+ const chunkLoadingGlobal = (_bundlerConfigs_find = bundlerConfigs === null || bundlerConfigs === void 0 ? void 0 : bundlerConfigs.find((config2) => config2.name === "client")) === null || _bundlerConfigs_find === void 0 ? void 0 : (_bundlerConfigs_find_output = _bundlerConfigs_find.output) === null || _bundlerConfigs_find_output === void 0 ? void 0 : _bundlerConfigs_find_output.chunkLoadingGlobal;
121
+ const config = api.useResolvedConfigContext();
122
+ const { crossorigin, scriptLoading } = config.html;
121
123
  plugins.push({
122
124
  name: PLUGIN_IDENTIFIER,
123
125
  options: JSON.stringify({
124
126
  ...ssrConfigMap.get(entrypoint.entryName) || {},
127
+ crossorigin,
128
+ scriptLoading,
125
129
  chunkLoadingGlobal
126
130
  })
127
131
  });
@@ -23,18 +23,26 @@ export const toHtml = (jsx, renderer, next) => {
23
23
  chunksMap.js = (chunksMap.js || "") + getLoadableScripts(extractor);
24
24
  for (const v of chunks) {
25
25
  const fileType = extname(v.url).slice(1);
26
+ const attributes = {};
27
+ const { crossorigin, scriptLoading = "defer" } = config;
28
+ if (crossorigin && isCrossOrigin(v.url, host)) {
29
+ attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
30
+ }
31
+ switch (scriptLoading) {
32
+ case "defer":
33
+ attributes.defer = true;
34
+ break;
35
+ case "module":
36
+ attributes.type = "module";
37
+ break;
38
+ default:
39
+ }
26
40
  if (fileType === "js") {
27
- const attributes = {
28
- nonce
29
- };
30
- const { crossorigin } = config;
31
- if (crossorigin && isCrossOrigin(v.url, host)) {
32
- attributes.crossorigin = crossorigin === true ? "anonymous" : crossorigin;
33
- }
41
+ attributes.nonce = nonce;
34
42
  const attrsStr = attributesToString(attributes);
35
43
  chunksMap[fileType] += `<script${attrsStr} src="${v.url}"></script>`;
36
44
  } else if (fileType === "css") {
37
- chunksMap[fileType] += `<link href="${v.url}" rel="stylesheet" />`;
45
+ chunksMap[fileType] += `<link${attributes} href="${v.url}" rel="stylesheet" />`;
38
46
  }
39
47
  }
40
48
  return html;
@@ -23,10 +23,10 @@ export default () => {
23
23
  },
24
24
  modifyEntryImports({ entrypoint, imports }) {
25
25
  var _getEntryOptions;
26
- const { entryName } = entrypoint;
26
+ const { entryName, isMainEntry } = entrypoint;
27
27
  const userConfig = api.useResolvedConfigContext();
28
28
  const { packageName } = api.useAppContext();
29
- const stateConfig = (_getEntryOptions = getEntryOptions(entryName, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
29
+ const stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
30
30
  stateConfigMap.set(entryName, stateConfig);
31
31
  if (stateConfig) {
32
32
  imports.push({
@@ -7,6 +7,7 @@ export type ModernSSRReactComponent = React.ComponentType<any>;
7
7
  export { RuntimeContext, RenderLevel };
8
8
  export type SSRPluginConfig = {
9
9
  crossorigin?: boolean | 'anonymous' | 'use-credentials';
10
+ scriptLoading?: 'defer' | 'blocking' | 'module';
10
11
  chunkLoadingGlobal?: string;
11
12
  } & Exclude<ServerUserConfig['ssr'], boolean>;
12
13
  export type ServerRenderOptions = {
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.23.1",
18
+ "version": "2.24.0",
19
19
  "engines": {
20
20
  "node": ">=14.17.6"
21
21
  },
@@ -169,9 +169,9 @@
169
169
  "redux-logger": "^3.0.6",
170
170
  "styled-components": "^5.3.1",
171
171
  "@swc/helpers": "0.5.1",
172
- "@modern-js/plugin": "2.23.1",
173
- "@modern-js/types": "2.23.1",
174
- "@modern-js/utils": "2.23.1"
172
+ "@modern-js/plugin": "2.24.0",
173
+ "@modern-js/utils": "2.24.0",
174
+ "@modern-js/types": "2.24.0"
175
175
  },
176
176
  "peerDependencies": {
177
177
  "react": ">=17",
@@ -192,11 +192,11 @@
192
192
  "ts-jest": "^29.1.0",
193
193
  "typescript": "^5",
194
194
  "webpack": "^5.82.1",
195
- "@modern-js/app-tools": "2.23.1",
196
- "@modern-js/core": "2.23.1",
197
- "@modern-js/server-core": "2.23.1",
198
- "@scripts/build": "2.23.1",
199
- "@scripts/jest-config": "2.23.1"
195
+ "@modern-js/app-tools": "2.24.0",
196
+ "@modern-js/core": "2.24.0",
197
+ "@modern-js/server-core": "2.24.0",
198
+ "@scripts/build": "2.24.0",
199
+ "@scripts/jest-config": "2.24.0"
200
200
  },
201
201
  "sideEffects": false,
202
202
  "modernConfig": {},