@modern-js/runtime 3.1.3 → 3.1.5

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.
@@ -38,6 +38,11 @@ __webpack_require__.d(__webpack_exports__, {
38
38
  const external_path_namespaceObject = require("path");
39
39
  var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
40
40
  const utils_namespaceObject = require("@modern-js/utils");
41
+ const normalizeChunkId = (id)=>'string' == typeof id && /^\d+$/.test(id) ? Number(id) : id;
42
+ const normalizeChunkGroup = (group)=>({
43
+ ...group,
44
+ chunks: (group.chunks || []).map(normalizeChunkId)
45
+ });
41
46
  class LoadablePlugin {
42
47
  apply(compiler) {
43
48
  this.compiler = compiler;
@@ -66,13 +71,19 @@ class LoadablePlugin {
66
71
  outputPath: true,
67
72
  publicPath: true
68
73
  });
74
+ const namedChunkGroups = {};
75
+ for (const [name, group] of Object.entries(stats.namedChunkGroups || {}))namedChunkGroups[name] = normalizeChunkGroup(group);
76
+ const entrypoints = {};
77
+ for (const [name, ep] of Object.entries(stats.entrypoints || {}))entrypoints[name] = normalizeChunkGroup(ep);
69
78
  const output = {
70
79
  ...stats,
80
+ namedChunkGroups,
81
+ entrypoints,
71
82
  generator: 'loadable-components',
72
83
  chunks: [
73
84
  ...stats.chunks || []
74
85
  ].map((chunk)=>({
75
- id: chunk.id,
86
+ id: normalizeChunkId(chunk.id),
76
87
  files: [
77
88
  ...chunk.files || []
78
89
  ]
@@ -93,7 +93,7 @@ const entryForCSRWithRSC = ({ metaName, entryName, urlPath = '/', mountId = 'roo
93
93
 
94
94
  setServerCallback(callServer);
95
95
 
96
- const handleRedirectResponse = (res: Response) => {
96
+ const handleRedirectResponse = (res) => {
97
97
  const { headers } = res;
98
98
  const location = headers.get('X-Modernjs-Redirect');
99
99
  const baseUrl = headers.get('X-Modernjs-BaseUrl');
@@ -189,7 +189,7 @@ const runtimeGlobalContextForRSCServer = ({ metaName })=>`
189
189
  import { setGlobalContext } from '@${metaName}/runtime/context';
190
190
  import AppProxy from './AppProxy';
191
191
 
192
- const DefaultRoot = ({ children }: { children?: ReactNode }) =>
192
+ const DefaultRoot = ({ children }) =>
193
193
  createElement(Fragment, null, children);
194
194
 
195
195
 
@@ -212,7 +212,7 @@ const runtimeGlobalContextForRSCClient = ({ metaName, customEntry })=>`
212
212
 
213
213
  ${customEntry ? 'setServerCallback(callServer);' : ''}
214
214
 
215
- ${customEntry ? `const handleRedirectResponse = (res: Response) => {
215
+ ${customEntry ? `const handleRedirectResponse = (res) => {
216
216
  const { headers } = res;
217
217
  const location = headers.get('X-Modernjs-Redirect');
218
218
  const baseUrl = headers.get('X-Modernjs-BaseUrl');
@@ -237,7 +237,7 @@ const runtimeGlobalContextForRSCClient = ({ metaName, customEntry })=>`
237
237
  callServer: callServer,
238
238
  })`};` : ''}
239
239
 
240
- const DefaultRoot = ({ children }: { children?: ReactNode }) =>
240
+ const DefaultRoot = ({ children }) =>
241
241
  createElement(Fragment, null, children);
242
242
 
243
243
  ${customEntry ? 'const RSCRoot = () => createElement(RscClientRoot, { rscPayload: data });' : ''}
@@ -48,8 +48,8 @@ var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namesp
48
48
  const external_path_namespaceObject = require("path");
49
49
  var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
50
50
  const utils_namespaceObject = require("@modern-js/utils");
51
+ const core_namespaceObject = require("@swc/core");
51
52
  const external_es_module_lexer_namespaceObject = require("es-module-lexer");
52
- const external_esbuild_namespaceObject = require("esbuild");
53
53
  const external_constants_js_namespaceObject = require("../constants.js");
54
54
  const walkDirectory = (dir)=>external_fs_default().readdirSync(dir).reduce((previous, filename)=>{
55
55
  const filePath = external_path_default().join(dir, filename);
@@ -79,13 +79,30 @@ const replaceWithAlias = (base, filePath, alias)=>{
79
79
  const parseModule = async ({ source, filename })=>{
80
80
  let content = source;
81
81
  if (utils_namespaceObject.JS_EXTENSIONS.some((ext)=>filename.endsWith(ext))) {
82
- const result = await (0, external_esbuild_namespaceObject.transform)(content, {
83
- loader: external_path_default().extname(filename).slice(1),
84
- format: 'esm',
85
- tsconfigRaw: {
86
- compilerOptions: {
87
- experimentalDecorators: true
88
- }
82
+ const ext = external_path_default().extname(filename);
83
+ const isTs = '.ts' === ext || '.tsx' === ext;
84
+ const isJsx = '.jsx' === ext || '.tsx' === ext;
85
+ const result = await (0, core_namespaceObject.transform)(content, {
86
+ filename,
87
+ isModule: true,
88
+ module: {
89
+ type: 'es6'
90
+ },
91
+ jsc: {
92
+ parser: isTs ? {
93
+ syntax: "typescript",
94
+ tsx: isJsx,
95
+ decorators: true
96
+ } : {
97
+ syntax: "ecmascript",
98
+ jsx: isJsx,
99
+ decorators: true
100
+ },
101
+ transform: {
102
+ legacyDecorator: true
103
+ },
104
+ target: 'es2022',
105
+ keepClassNames: true
89
106
  }
90
107
  });
91
108
  content = result.code;
@@ -1,5 +1,10 @@
1
1
  import path_0 from "path";
2
2
  import { fs } from "@modern-js/utils";
3
+ const normalizeChunkId = (id)=>'string' == typeof id && /^\d+$/.test(id) ? Number(id) : id;
4
+ const normalizeChunkGroup = (group)=>({
5
+ ...group,
6
+ chunks: (group.chunks || []).map(normalizeChunkId)
7
+ });
3
8
  class LoadablePlugin {
4
9
  apply(compiler) {
5
10
  this.compiler = compiler;
@@ -28,13 +33,19 @@ class LoadablePlugin {
28
33
  outputPath: true,
29
34
  publicPath: true
30
35
  });
36
+ const namedChunkGroups = {};
37
+ for (const [name, group] of Object.entries(stats.namedChunkGroups || {}))namedChunkGroups[name] = normalizeChunkGroup(group);
38
+ const entrypoints = {};
39
+ for (const [name, ep] of Object.entries(stats.entrypoints || {}))entrypoints[name] = normalizeChunkGroup(ep);
31
40
  const output = {
32
41
  ...stats,
42
+ namedChunkGroups,
43
+ entrypoints,
33
44
  generator: 'loadable-components',
34
45
  chunks: [
35
46
  ...stats.chunks || []
36
47
  ].map((chunk)=>({
37
- id: chunk.id,
48
+ id: normalizeChunkId(chunk.id),
38
49
  files: [
39
50
  ...chunk.files || []
40
51
  ]
@@ -48,7 +48,7 @@ const entryForCSRWithRSC = ({ metaName, entryName, urlPath = '/', mountId = 'roo
48
48
 
49
49
  setServerCallback(callServer);
50
50
 
51
- const handleRedirectResponse = (res: Response) => {
51
+ const handleRedirectResponse = (res) => {
52
52
  const { headers } = res;
53
53
  const location = headers.get('X-Modernjs-Redirect');
54
54
  const baseUrl = headers.get('X-Modernjs-BaseUrl');
@@ -144,7 +144,7 @@ const runtimeGlobalContextForRSCServer = ({ metaName })=>`
144
144
  import { setGlobalContext } from '@${metaName}/runtime/context';
145
145
  import AppProxy from './AppProxy';
146
146
 
147
- const DefaultRoot = ({ children }: { children?: ReactNode }) =>
147
+ const DefaultRoot = ({ children }) =>
148
148
  createElement(Fragment, null, children);
149
149
 
150
150
 
@@ -167,7 +167,7 @@ const runtimeGlobalContextForRSCClient = ({ metaName, customEntry })=>`
167
167
 
168
168
  ${customEntry ? 'setServerCallback(callServer);' : ''}
169
169
 
170
- ${customEntry ? `const handleRedirectResponse = (res: Response) => {
170
+ ${customEntry ? `const handleRedirectResponse = (res) => {
171
171
  const { headers } = res;
172
172
  const location = headers.get('X-Modernjs-Redirect');
173
173
  const baseUrl = headers.get('X-Modernjs-BaseUrl');
@@ -192,7 +192,7 @@ const runtimeGlobalContextForRSCClient = ({ metaName, customEntry })=>`
192
192
  callServer: callServer,
193
193
  })`};` : ''}
194
194
 
195
- const DefaultRoot = ({ children }: { children?: ReactNode }) =>
195
+ const DefaultRoot = ({ children }) =>
196
196
  createElement(Fragment, null, children);
197
197
 
198
198
  ${customEntry ? 'const RSCRoot = () => createElement(RscClientRoot, { rscPayload: data });' : ''}
@@ -1,8 +1,8 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
3
  import { JS_EXTENSIONS, fs as utils_fs, normalizeToPosixPath } from "@modern-js/utils";
4
+ import { transform } from "@swc/core";
4
5
  import { parse } from "es-module-lexer";
5
- import { transform } from "esbuild";
6
6
  import { ACTION_EXPORT_NAME, LOADER_EXPORT_NAME } from "../constants.mjs";
7
7
  const walkDirectory = (dir)=>fs.readdirSync(dir).reduce((previous, filename)=>{
8
8
  const filePath = path.join(dir, filename);
@@ -32,13 +32,30 @@ const replaceWithAlias = (base, filePath, alias)=>{
32
32
  const parseModule = async ({ source, filename })=>{
33
33
  let content = source;
34
34
  if (JS_EXTENSIONS.some((ext)=>filename.endsWith(ext))) {
35
+ const ext = path.extname(filename);
36
+ const isTs = '.ts' === ext || '.tsx' === ext;
37
+ const isJsx = '.jsx' === ext || '.tsx' === ext;
35
38
  const result = await transform(content, {
36
- loader: path.extname(filename).slice(1),
37
- format: 'esm',
38
- tsconfigRaw: {
39
- compilerOptions: {
40
- experimentalDecorators: true
41
- }
39
+ filename,
40
+ isModule: true,
41
+ module: {
42
+ type: 'es6'
43
+ },
44
+ jsc: {
45
+ parser: isTs ? {
46
+ syntax: "typescript",
47
+ tsx: isJsx,
48
+ decorators: true
49
+ } : {
50
+ syntax: "ecmascript",
51
+ jsx: isJsx,
52
+ decorators: true
53
+ },
54
+ transform: {
55
+ legacyDecorator: true
56
+ },
57
+ target: 'es2022',
58
+ keepClassNames: true
42
59
  }
43
60
  });
44
61
  content = result.code;
@@ -1,6 +1,11 @@
1
1
  import "node:module";
2
2
  import path_0 from "path";
3
3
  import { fs } from "@modern-js/utils";
4
+ const normalizeChunkId = (id)=>'string' == typeof id && /^\d+$/.test(id) ? Number(id) : id;
5
+ const normalizeChunkGroup = (group)=>({
6
+ ...group,
7
+ chunks: (group.chunks || []).map(normalizeChunkId)
8
+ });
4
9
  class LoadablePlugin {
5
10
  apply(compiler) {
6
11
  this.compiler = compiler;
@@ -29,13 +34,19 @@ class LoadablePlugin {
29
34
  outputPath: true,
30
35
  publicPath: true
31
36
  });
37
+ const namedChunkGroups = {};
38
+ for (const [name, group] of Object.entries(stats.namedChunkGroups || {}))namedChunkGroups[name] = normalizeChunkGroup(group);
39
+ const entrypoints = {};
40
+ for (const [name, ep] of Object.entries(stats.entrypoints || {}))entrypoints[name] = normalizeChunkGroup(ep);
32
41
  const output = {
33
42
  ...stats,
43
+ namedChunkGroups,
44
+ entrypoints,
34
45
  generator: 'loadable-components',
35
46
  chunks: [
36
47
  ...stats.chunks || []
37
48
  ].map((chunk)=>({
38
- id: chunk.id,
49
+ id: normalizeChunkId(chunk.id),
39
50
  files: [
40
51
  ...chunk.files || []
41
52
  ]
@@ -49,7 +49,7 @@ const entryForCSRWithRSC = ({ metaName, entryName, urlPath = '/', mountId = 'roo
49
49
 
50
50
  setServerCallback(callServer);
51
51
 
52
- const handleRedirectResponse = (res: Response) => {
52
+ const handleRedirectResponse = (res) => {
53
53
  const { headers } = res;
54
54
  const location = headers.get('X-Modernjs-Redirect');
55
55
  const baseUrl = headers.get('X-Modernjs-BaseUrl');
@@ -145,7 +145,7 @@ const runtimeGlobalContextForRSCServer = ({ metaName })=>`
145
145
  import { setGlobalContext } from '@${metaName}/runtime/context';
146
146
  import AppProxy from './AppProxy';
147
147
 
148
- const DefaultRoot = ({ children }: { children?: ReactNode }) =>
148
+ const DefaultRoot = ({ children }) =>
149
149
  createElement(Fragment, null, children);
150
150
 
151
151
 
@@ -168,7 +168,7 @@ const runtimeGlobalContextForRSCClient = ({ metaName, customEntry })=>`
168
168
 
169
169
  ${customEntry ? 'setServerCallback(callServer);' : ''}
170
170
 
171
- ${customEntry ? `const handleRedirectResponse = (res: Response) => {
171
+ ${customEntry ? `const handleRedirectResponse = (res) => {
172
172
  const { headers } = res;
173
173
  const location = headers.get('X-Modernjs-Redirect');
174
174
  const baseUrl = headers.get('X-Modernjs-BaseUrl');
@@ -193,7 +193,7 @@ const runtimeGlobalContextForRSCClient = ({ metaName, customEntry })=>`
193
193
  callServer: callServer,
194
194
  })`};` : ''}
195
195
 
196
- const DefaultRoot = ({ children }: { children?: ReactNode }) =>
196
+ const DefaultRoot = ({ children }) =>
197
197
  createElement(Fragment, null, children);
198
198
 
199
199
  ${customEntry ? 'const RSCRoot = () => createElement(RscClientRoot, { rscPayload: data });' : ''}
@@ -2,8 +2,8 @@ import "node:module";
2
2
  import fs from "fs";
3
3
  import path from "path";
4
4
  import { JS_EXTENSIONS, fs as utils_fs, normalizeToPosixPath } from "@modern-js/utils";
5
+ import { transform } from "@swc/core";
5
6
  import { parse } from "es-module-lexer";
6
- import { transform } from "esbuild";
7
7
  import { ACTION_EXPORT_NAME, LOADER_EXPORT_NAME } from "../constants.mjs";
8
8
  const walkDirectory = (dir)=>fs.readdirSync(dir).reduce((previous, filename)=>{
9
9
  const filePath = path.join(dir, filename);
@@ -33,13 +33,30 @@ const replaceWithAlias = (base, filePath, alias)=>{
33
33
  const parseModule = async ({ source, filename })=>{
34
34
  let content = source;
35
35
  if (JS_EXTENSIONS.some((ext)=>filename.endsWith(ext))) {
36
+ const ext = path.extname(filename);
37
+ const isTs = '.ts' === ext || '.tsx' === ext;
38
+ const isJsx = '.jsx' === ext || '.tsx' === ext;
36
39
  const result = await transform(content, {
37
- loader: path.extname(filename).slice(1),
38
- format: 'esm',
39
- tsconfigRaw: {
40
- compilerOptions: {
41
- experimentalDecorators: true
42
- }
40
+ filename,
41
+ isModule: true,
42
+ module: {
43
+ type: 'es6'
44
+ },
45
+ jsc: {
46
+ parser: isTs ? {
47
+ syntax: "typescript",
48
+ tsx: isJsx,
49
+ decorators: true
50
+ } : {
51
+ syntax: "ecmascript",
52
+ jsx: isJsx,
53
+ decorators: true
54
+ },
55
+ transform: {
56
+ legacyDecorator: true
57
+ },
58
+ target: 'es2022',
59
+ keepClassNames: true
43
60
  }
44
61
  });
45
62
  content = result.code;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.1.3",
18
+ "version": "3.1.5",
19
19
  "engines": {
20
20
  "node": ">=20"
21
21
  },
@@ -204,23 +204,23 @@
204
204
  "@loadable/component": "5.16.7",
205
205
  "@loadable/server": "5.16.7",
206
206
  "@swc/helpers": "^0.5.17",
207
+ "@swc/core": "1.15.11",
207
208
  "@swc/plugin-loadable-components": "^11.5.0",
208
209
  "@types/loadable__component": "^5.13.10",
209
210
  "@types/react-helmet": "^6.1.11",
210
211
  "cookie": "0.7.2",
211
212
  "entities": "^7.0.1",
212
213
  "es-module-lexer": "^1.7.0",
213
- "esbuild": "0.25.5",
214
214
  "invariant": "^2.2.4",
215
215
  "isbot": "3.8.0",
216
216
  "react-helmet": "^6.1.0",
217
217
  "react-is": "^18.3.1",
218
- "@modern-js/plugin": "3.1.3",
219
- "@modern-js/runtime-utils": "3.1.3",
220
- "@modern-js/render": "3.1.3",
221
- "@modern-js/plugin-data-loader": "3.1.3",
222
- "@modern-js/utils": "3.1.3",
223
- "@modern-js/types": "3.1.3"
218
+ "@modern-js/render": "3.1.5",
219
+ "@modern-js/plugin": "3.1.5",
220
+ "@modern-js/plugin-data-loader": "3.1.5",
221
+ "@modern-js/runtime-utils": "3.1.5",
222
+ "@modern-js/types": "3.1.5",
223
+ "@modern-js/utils": "3.1.5"
224
224
  },
225
225
  "peerDependencies": {
226
226
  "react": ">=17.0.2",
@@ -228,8 +228,8 @@
228
228
  },
229
229
  "devDependencies": {
230
230
  "@remix-run/web-fetch": "^4.1.3",
231
- "@rsbuild/core": "2.0.0-rc.0",
232
- "@rslib/core": "0.21.0",
231
+ "@rsbuild/core": "2.0.0",
232
+ "@rslib/core": "0.21.2",
233
233
  "@testing-library/dom": "^10.4.1",
234
234
  "@testing-library/react": "^16.3.2",
235
235
  "@types/cookie": "0.6.0",
@@ -240,9 +240,9 @@
240
240
  "react-dom": "^19.2.4",
241
241
  "ts-node": "^10.9.2",
242
242
  "typescript": "^5",
243
- "@modern-js/app-tools": "3.1.3",
244
243
  "@modern-js/rslib": "2.68.10",
245
- "@scripts/rstest-config": "2.66.0"
244
+ "@scripts/rstest-config": "2.66.0",
245
+ "@modern-js/app-tools": "3.1.5"
246
246
  },
247
247
  "sideEffects": false,
248
248
  "publishConfig": {