@modern-js/runtime 3.1.2 → 3.1.4

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.
@@ -31,7 +31,9 @@ require("react");
31
31
  const external_Body_js_namespaceObject = require("./Body.js");
32
32
  const external_DocumentStructureContext_js_namespaceObject = require("./DocumentStructureContext.js");
33
33
  const external_Head_js_namespaceObject = require("./Head.js");
34
+ const external_Links_js_namespaceObject = require("./Links.js");
34
35
  const external_Root_js_namespaceObject = require("./Root.js");
36
+ const external_Scripts_js_namespaceObject = require("./Scripts.js");
35
37
  function findTargetChildByName(tag, children) {
36
38
  return children.find((item)=>getEleType(item) === tag);
37
39
  }
@@ -62,9 +64,9 @@ function findTargetElement(tag, children) {
62
64
  function Html(props) {
63
65
  const { children, ...rest } = props;
64
66
  const hasSetHead = Boolean(findTargetChildByComponent(external_Head_js_namespaceObject.Head, children) || findTargetChildByName('Head', children));
65
- const hasSetScripts = Boolean(findTargetElement('Scripts', children));
66
- const hasSetLinks = Boolean(findTargetElement('Links', children));
67
- const hasSetBody = Boolean(findTargetChildByComponent(external_Body_js_namespaceObject.Body, children) || findTargetChildByName('Body', children));
67
+ const hasSetScripts = Boolean(findTargetElementByComponent(external_Scripts_js_namespaceObject.Scripts, children) || findTargetChildByName('Scripts', children));
68
+ const hasSetLinks = Boolean(findTargetElementByComponent(external_Links_js_namespaceObject.Links, children) || findTargetChildByName('Links', children));
69
+ const hasSetBody = Boolean(findTargetElementByComponent(external_Body_js_namespaceObject.Body, children) || findTargetChildByName('Body', children));
68
70
  const hasSetRoot = Boolean(findTargetElementByComponent(external_Root_js_namespaceObject.Root, children) || findTargetChildByName('Root', children));
69
71
  const hasSetTitle = Boolean(findTargetElement('title', children));
70
72
  const notMissMustChild = [
@@ -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,9 +79,31 @@ 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'
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
106
+ }
85
107
  });
86
108
  content = result.code;
87
109
  }
@@ -3,7 +3,9 @@ import "react";
3
3
  import { Body } from "./Body.mjs";
4
4
  import { DocumentStructureContext } from "./DocumentStructureContext.mjs";
5
5
  import { Head } from "./Head.mjs";
6
+ import { Links } from "./Links.mjs";
6
7
  import { Root } from "./Root.mjs";
8
+ import { Scripts } from "./Scripts.mjs";
7
9
  function findTargetChildByName(tag, children) {
8
10
  return children.find((item)=>getEleType(item) === tag);
9
11
  }
@@ -34,9 +36,9 @@ function findTargetElement(tag, children) {
34
36
  function Html(props) {
35
37
  const { children, ...rest } = props;
36
38
  const hasSetHead = Boolean(findTargetChildByComponent(Head, children) || findTargetChildByName('Head', children));
37
- const hasSetScripts = Boolean(findTargetElement('Scripts', children));
38
- const hasSetLinks = Boolean(findTargetElement('Links', children));
39
- const hasSetBody = Boolean(findTargetChildByComponent(Body, children) || findTargetChildByName('Body', children));
39
+ const hasSetScripts = Boolean(findTargetElementByComponent(Scripts, children) || findTargetChildByName('Scripts', children));
40
+ const hasSetLinks = Boolean(findTargetElementByComponent(Links, children) || findTargetChildByName('Links', children));
41
+ const hasSetBody = Boolean(findTargetElementByComponent(Body, children) || findTargetChildByName('Body', children));
40
42
  const hasSetRoot = Boolean(findTargetElementByComponent(Root, children) || findTargetChildByName('Root', children));
41
43
  const hasSetTitle = Boolean(findTargetElement('title', children));
42
44
  const notMissMustChild = [
@@ -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,9 +32,31 @@ 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'
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
59
+ }
38
60
  });
39
61
  content = result.code;
40
62
  }
@@ -4,7 +4,9 @@ import "react";
4
4
  import { Body } from "./Body.mjs";
5
5
  import { DocumentStructureContext } from "./DocumentStructureContext.mjs";
6
6
  import { Head } from "./Head.mjs";
7
+ import { Links } from "./Links.mjs";
7
8
  import { Root } from "./Root.mjs";
9
+ import { Scripts } from "./Scripts.mjs";
8
10
  function findTargetChildByName(tag, children) {
9
11
  return children.find((item)=>getEleType(item) === tag);
10
12
  }
@@ -35,9 +37,9 @@ function findTargetElement(tag, children) {
35
37
  function Html(props) {
36
38
  const { children, ...rest } = props;
37
39
  const hasSetHead = Boolean(findTargetChildByComponent(Head, children) || findTargetChildByName('Head', children));
38
- const hasSetScripts = Boolean(findTargetElement('Scripts', children));
39
- const hasSetLinks = Boolean(findTargetElement('Links', children));
40
- const hasSetBody = Boolean(findTargetChildByComponent(Body, children) || findTargetChildByName('Body', children));
40
+ const hasSetScripts = Boolean(findTargetElementByComponent(Scripts, children) || findTargetChildByName('Scripts', children));
41
+ const hasSetLinks = Boolean(findTargetElementByComponent(Links, children) || findTargetChildByName('Links', children));
42
+ const hasSetBody = Boolean(findTargetElementByComponent(Body, children) || findTargetChildByName('Body', children));
41
43
  const hasSetRoot = Boolean(findTargetElementByComponent(Root, children) || findTargetChildByName('Root', children));
42
44
  const hasSetTitle = Boolean(findTargetElement('title', children));
43
45
  const notMissMustChild = [
@@ -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,9 +33,31 @@ 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'
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
60
+ }
39
61
  });
40
62
  content = result.code;
41
63
  }
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.1.2",
18
+ "version": "3.1.4",
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.2",
219
- "@modern-js/plugin-data-loader": "3.1.2",
220
- "@modern-js/render": "3.1.2",
221
- "@modern-js/runtime-utils": "3.1.2",
222
- "@modern-js/types": "3.1.2",
223
- "@modern-js/utils": "3.1.2"
218
+ "@modern-js/plugin": "3.1.4",
219
+ "@modern-js/plugin-data-loader": "3.1.4",
220
+ "@modern-js/runtime-utils": "3.1.4",
221
+ "@modern-js/types": "3.1.4",
222
+ "@modern-js/render": "3.1.4",
223
+ "@modern-js/utils": "3.1.4"
224
224
  },
225
225
  "peerDependencies": {
226
226
  "react": ">=17.0.2",
@@ -229,7 +229,7 @@
229
229
  "devDependencies": {
230
230
  "@remix-run/web-fetch": "^4.1.3",
231
231
  "@rsbuild/core": "2.0.0-rc.0",
232
- "@rslib/core": "0.20.3",
232
+ "@rslib/core": "0.21.0",
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.2",
244
243
  "@scripts/rstest-config": "2.66.0",
245
- "@modern-js/rslib": "2.68.10"
244
+ "@modern-js/rslib": "2.68.10",
245
+ "@modern-js/app-tools": "3.1.4"
246
246
  },
247
247
  "sideEffects": false,
248
248
  "publishConfig": {