@modern-js/app-tools 2.56.2-alpha.1 → 2.56.2

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.
@@ -42,7 +42,7 @@ function getBuilderEnvironments(normalizedConfig, appContext) {
42
42
  const serverEntries = {};
43
43
  for (const entry in entries) {
44
44
  const v = entries[entry];
45
- serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx"));
45
+ serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx")).map((entry2) => entry2.replace("bootstrap.jsx", "bootstrap.server.jsx"));
46
46
  }
47
47
  const environments = {
48
48
  web: {
@@ -57,7 +57,7 @@ function applyNodeCompat(isServiceWorker, chain) {
57
57
  ".node.ts",
58
58
  ".node.tsx",
59
59
  ".server.js",
60
- ".server.ts",
60
+ ".server.jsx",
61
61
  ".server.ts",
62
62
  ".server.tsx"
63
63
  ];
@@ -95,19 +95,22 @@ const dev = async (api, options, devServerOptions = {}) => {
95
95
  };
96
96
  if (apiOnly) {
97
97
  var _normalizedConfig_dev;
98
- const app = await (0, import_server.createDevServer)(serverOptions, import_prod_server.applyPlugins);
98
+ const server = await (0, import_server.createDevServer)({
99
+ ...serverOptions,
100
+ runCompile: false
101
+ }, import_prod_server.applyPlugins);
99
102
  const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || import_utils.DEFAULT_DEV_HOST;
100
- app.listen({
103
+ server.listen({
101
104
  port,
102
105
  host
103
106
  }, () => {
104
107
  (0, import_printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
105
108
  });
106
109
  } else {
107
- const { server } = await appContext.builder.startDevServer({
108
- serverOptions,
109
- applyPlugins: import_prod_server.applyPlugins
110
- });
110
+ const server = await (0, import_server.createDevServer)({
111
+ ...serverOptions,
112
+ builder: appContext.builder
113
+ }, import_prod_server.applyPlugins);
111
114
  (0, import_createServer.setServer)(server);
112
115
  }
113
116
  };
@@ -36,21 +36,12 @@ var import_utils = require("@modern-js/utils");
36
36
  var import_pkg_types = require("pkg-types");
37
37
  var import_mlly = require("mlly");
38
38
  var import_utils2 = require("./utils");
39
- const createGetMonoRoot = (appDir) => {
40
- let monorepoRoot;
41
- return () => {
42
- if (!monorepoRoot) {
43
- monorepoRoot = (0, import_utils.findMonorepoRoot)(appDir, 8);
44
- }
45
- return monorepoRoot;
46
- };
47
- };
48
39
  const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = import_utils2.traceFiles, entryFilter, modifyPackageJson, copyWholePackage }) => {
49
40
  const base = "/";
50
41
  const entryFiles = await (0, import_utils2.findEntryFiles)(serverRootDir, entryFilter);
51
42
  const fileTrace = await traceFiles(entryFiles.concat(includeEntries), serverRootDir, base);
52
43
  const currentProjectModules = import_node_path.default.join(appDir, "node_modules");
53
- const getMonorepoRoot = createGetMonoRoot(appDir);
44
+ const dependencySearchRoot = import_node_path.default.resolve(appDir, "../../../../../../");
54
45
  const tracedFiles = Object.fromEntries(await Promise.all([
55
46
  ...fileTrace.reasons.entries()
56
47
  ].map(async ([_path, reasons]) => {
@@ -78,14 +69,10 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
78
69
  const MODERN_UTILS_PATH = "packages/toolkit/utils";
79
70
  const MODERN_UTILS_PATH_REGEX = new RegExp(`(.*${MODERN_UTILS_PATH})`);
80
71
  const match = filePath.match(MODERN_UTILS_PATH_REGEX);
81
- const monorepoRoot = getMonorepoRoot();
82
72
  const packageJsonPath = match ? import_node_path.default.join(match[0], "package.json") : await (0, import_utils.pkgUp)({
83
73
  cwd: import_node_path.default.dirname(filePath)
84
74
  });
85
- if (packageJsonPath && monorepoRoot && packageJsonPath.startsWith(monorepoRoot)) {
86
- if (!match) {
87
- console.log("filePath", filePath, packageJsonPath);
88
- }
75
+ if (packageJsonPath === null || packageJsonPath === void 0 ? void 0 : packageJsonPath.startsWith(dependencySearchRoot)) {
89
76
  const packageJson = await import_utils.fs.readJSON(packageJsonPath);
90
77
  pkgPath = baseDir = import_node_path.default.dirname(packageJsonPath);
91
78
  subpath = import_node_path.default.relative(baseDir, filePath);
@@ -38,6 +38,8 @@ function getBuilderEnvironments(normalizedConfig, appContext) {
38
38
  var v = entries[entry1];
39
39
  serverEntries[entry1] = v.map(function(entry2) {
40
40
  return entry2.replace("index.jsx", "index.server.jsx");
41
+ }).map(function(entry2) {
42
+ return entry2.replace("bootstrap.jsx", "bootstrap.server.jsx");
41
43
  });
42
44
  }
43
45
  var environments = {
@@ -27,7 +27,7 @@ function applyNodeCompat(isServiceWorker, chain) {
27
27
  ".node.ts",
28
28
  ".node.tsx",
29
29
  ".server.js",
30
- ".server.ts",
30
+ ".server.jsx",
31
31
  ".server.ts",
32
32
  ".server.tsx"
33
33
  ];
@@ -15,7 +15,7 @@ import { generateRoutes } from "../utils/routes";
15
15
  import { buildServerConfig } from "../utils/config";
16
16
  var dev = function() {
17
17
  var _ref = _async_to_generator(function(api, options) {
18
- var devServerOptions, _normalizedConfig_source, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, meta, serverConfigPath, pluginInstances, serverOptions, _normalizedConfig_dev, app, host, server;
18
+ var devServerOptions, _normalizedConfig_source, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, meta, serverConfigPath, pluginInstances, serverOptions, _normalizedConfig_dev, server, host, server1;
19
19
  var _arguments = arguments;
20
20
  return _ts_generator(this, function(_state) {
21
21
  switch (_state.label) {
@@ -99,12 +99,14 @@ var dev = function() {
99
99
  ];
100
100
  return [
101
101
  4,
102
- createDevServer(serverOptions, applyPlugins)
102
+ createDevServer(_object_spread_props(_object_spread({}, serverOptions), {
103
+ runCompile: false
104
+ }), applyPlugins)
103
105
  ];
104
106
  case 6:
105
- app = _state.sent();
107
+ server = _state.sent();
106
108
  host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
107
- app.listen({
109
+ server.listen({
108
110
  port,
109
111
  host
110
112
  }, function() {
@@ -117,14 +119,13 @@ var dev = function() {
117
119
  case 7:
118
120
  return [
119
121
  4,
120
- appContext.builder.startDevServer({
121
- serverOptions,
122
- applyPlugins
123
- })
122
+ createDevServer(_object_spread_props(_object_spread({}, serverOptions), {
123
+ builder: appContext.builder
124
+ }), applyPlugins)
124
125
  ];
125
126
  case 8:
126
- server = _state.sent().server;
127
- setServer(server);
127
+ server1 = _state.sent();
128
+ setServer(server1);
128
129
  _state.label = 9;
129
130
  case 9:
130
131
  return [
@@ -4,22 +4,13 @@ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import { _ as _ts_values } from "@swc/helpers/_/_ts_values";
6
6
  import path from "node:path";
7
- import { findMonorepoRoot, fs as fse, pkgUp, semver } from "@modern-js/utils";
7
+ import { fs as fse, pkgUp, semver } from "@modern-js/utils";
8
8
  import { readPackageJSON } from "pkg-types";
9
9
  import { parseNodeModulePath } from "mlly";
10
10
  import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
11
- var createGetMonoRoot = function(appDir) {
12
- var monorepoRoot;
13
- return function() {
14
- if (!monorepoRoot) {
15
- monorepoRoot = findMonorepoRoot(appDir, 8);
16
- }
17
- return monorepoRoot;
18
- };
19
- };
20
11
  var handleDependencies = function() {
21
12
  var _ref = _async_to_generator(function(param) {
22
- var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, base, entryFiles, fileTrace, currentProjectModules, getMonorepoRoot, tracedFiles, _, tracedPackages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, tracedFile, pkgName, tracedPackage, pkgJSON, tracedPackageVersion, shouldCopyWholePackage, _tracedPackageVersion_files, allFiles, err, multiVersionPkgs, singleVersionPackages, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tracedPackage1, versions, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, version, projectPkgJson, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _loop, _iterator3, _step3, err, outputPkgPath, newPkgJson, finalPkgJson;
13
+ var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, base, entryFiles, fileTrace, currentProjectModules, dependencySearchRoot, tracedFiles, _, tracedPackages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, tracedFile, pkgName, tracedPackage, pkgJSON, tracedPackageVersion, shouldCopyWholePackage, _tracedPackageVersion_files, allFiles, err, multiVersionPkgs, singleVersionPackages, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tracedPackage1, versions, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, version, projectPkgJson, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _loop, _iterator3, _step3, err, outputPkgPath, newPkgJson, finalPkgJson;
23
14
  return _ts_generator(this, function(_state) {
24
15
  switch (_state.label) {
25
16
  case 0:
@@ -38,13 +29,13 @@ var handleDependencies = function() {
38
29
  case 2:
39
30
  fileTrace = _state.sent();
40
31
  currentProjectModules = path.join(appDir, "node_modules");
41
- getMonorepoRoot = createGetMonoRoot(appDir);
32
+ dependencySearchRoot = path.resolve(appDir, "../../../../../../");
42
33
  _ = Object.fromEntries;
43
34
  return [
44
35
  4,
45
36
  Promise.all(_to_consumable_array(fileTrace.reasons.entries()).map(function() {
46
37
  var _ref2 = _async_to_generator(function(param2) {
47
- var _param, _path, reasons, filePath, baseDir, pkgName2, subpath, pkgPath, parsed, MODERN_UTILS_PATH, MODERN_UTILS_PATH_REGEX, match, monorepoRoot, packageJsonPath, _tmp, packageJson, parents, tracedFile2;
38
+ var _param, _path, reasons, filePath, baseDir, pkgName2, subpath, pkgPath, parsed, MODERN_UTILS_PATH, MODERN_UTILS_PATH_REGEX, match, packageJsonPath, _tmp, packageJson, parents, tracedFile2;
48
39
  return _ts_generator(this, function(_state2) {
49
40
  switch (_state2.label) {
50
41
  case 0:
@@ -93,7 +84,6 @@ var handleDependencies = function() {
93
84
  MODERN_UTILS_PATH = "packages/toolkit/utils";
94
85
  MODERN_UTILS_PATH_REGEX = new RegExp("(.*".concat(MODERN_UTILS_PATH, ")"));
95
86
  match = filePath.match(MODERN_UTILS_PATH_REGEX);
96
- monorepoRoot = getMonorepoRoot();
97
87
  if (!match)
98
88
  return [
99
89
  3,
@@ -116,14 +106,11 @@ var handleDependencies = function() {
116
106
  _state2.label = 6;
117
107
  case 6:
118
108
  packageJsonPath = _tmp;
119
- if (!(packageJsonPath && monorepoRoot && packageJsonPath.startsWith(monorepoRoot)))
109
+ if (!(packageJsonPath === null || packageJsonPath === void 0 ? void 0 : packageJsonPath.startsWith(dependencySearchRoot)))
120
110
  return [
121
111
  3,
122
112
  8
123
113
  ];
124
- if (!match) {
125
- console.log("filePath", filePath, packageJsonPath);
126
- }
127
114
  return [
128
115
  4,
129
116
  fse.readJSON(packageJsonPath)
@@ -19,7 +19,7 @@ function getBuilderEnvironments(normalizedConfig, appContext) {
19
19
  const serverEntries = {};
20
20
  for (const entry in entries) {
21
21
  const v = entries[entry];
22
- serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx"));
22
+ serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx")).map((entry2) => entry2.replace("bootstrap.jsx", "bootstrap.server.jsx"));
23
23
  }
24
24
  const environments = {
25
25
  web: {
@@ -24,7 +24,7 @@ function applyNodeCompat(isServiceWorker, chain) {
24
24
  ".node.ts",
25
25
  ".node.tsx",
26
26
  ".server.js",
27
- ".server.ts",
27
+ ".server.jsx",
28
28
  ".server.ts",
29
29
  ".server.tsx"
30
30
  ];
@@ -62,19 +62,22 @@ const dev = async (api, options, devServerOptions = {}) => {
62
62
  };
63
63
  if (apiOnly) {
64
64
  var _normalizedConfig_dev;
65
- const app = await createDevServer(serverOptions, applyPlugins);
65
+ const server = await createDevServer({
66
+ ...serverOptions,
67
+ runCompile: false
68
+ }, applyPlugins);
66
69
  const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
67
- app.listen({
70
+ server.listen({
68
71
  port,
69
72
  host
70
73
  }, () => {
71
74
  printInstructions(hookRunners, appContext, normalizedConfig);
72
75
  });
73
76
  } else {
74
- const { server } = await appContext.builder.startDevServer({
75
- serverOptions,
76
- applyPlugins
77
- });
77
+ const server = await createDevServer({
78
+ ...serverOptions,
79
+ builder: appContext.builder
80
+ }, applyPlugins);
78
81
  setServer(server);
79
82
  }
80
83
  };
@@ -1,23 +1,14 @@
1
1
  import path from "node:path";
2
- import { findMonorepoRoot, fs as fse, pkgUp, semver } from "@modern-js/utils";
2
+ import { fs as fse, pkgUp, semver } from "@modern-js/utils";
3
3
  import { readPackageJSON } from "pkg-types";
4
4
  import { parseNodeModulePath } from "mlly";
5
5
  import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
6
- const createGetMonoRoot = (appDir) => {
7
- let monorepoRoot;
8
- return () => {
9
- if (!monorepoRoot) {
10
- monorepoRoot = findMonorepoRoot(appDir, 8);
11
- }
12
- return monorepoRoot;
13
- };
14
- };
15
6
  const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage }) => {
16
7
  const base = "/";
17
8
  const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
18
9
  const fileTrace = await traceFiles(entryFiles.concat(includeEntries), serverRootDir, base);
19
10
  const currentProjectModules = path.join(appDir, "node_modules");
20
- const getMonorepoRoot = createGetMonoRoot(appDir);
11
+ const dependencySearchRoot = path.resolve(appDir, "../../../../../../");
21
12
  const tracedFiles = Object.fromEntries(await Promise.all([
22
13
  ...fileTrace.reasons.entries()
23
14
  ].map(async ([_path, reasons]) => {
@@ -45,14 +36,10 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
45
36
  const MODERN_UTILS_PATH = "packages/toolkit/utils";
46
37
  const MODERN_UTILS_PATH_REGEX = new RegExp(`(.*${MODERN_UTILS_PATH})`);
47
38
  const match = filePath.match(MODERN_UTILS_PATH_REGEX);
48
- const monorepoRoot = getMonorepoRoot();
49
39
  const packageJsonPath = match ? path.join(match[0], "package.json") : await pkgUp({
50
40
  cwd: path.dirname(filePath)
51
41
  });
52
- if (packageJsonPath && monorepoRoot && packageJsonPath.startsWith(monorepoRoot)) {
53
- if (!match) {
54
- console.log("filePath", filePath, packageJsonPath);
55
- }
42
+ if (packageJsonPath === null || packageJsonPath === void 0 ? void 0 : packageJsonPath.startsWith(dependencySearchRoot)) {
56
43
  const packageJson = await fse.readJSON(packageJsonPath);
57
44
  pkgPath = baseDir = path.dirname(packageJsonPath);
58
45
  subpath = path.relative(baseDir, filePath);
@@ -1,4 +1,5 @@
1
1
  import { UnstableMiddleware, UnstableMiddlewareContext, UnstableNext } from '@modern-js/types';
2
+ export type { ServerPlugin } from '@modern-js/server-core';
2
3
  export type RenderMiddleware = UnstableMiddleware;
3
4
  export type RenderMiddlewareContext = UnstableMiddlewareContext;
4
5
  export type RenderNext = UnstableNext;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.56.2-alpha.1",
18
+ "version": "2.56.2",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -87,20 +87,20 @@
87
87
  "mlly": "^1.6.1",
88
88
  "pkg-types": "^1.1.0",
89
89
  "std-env": "^3.7.0",
90
- "@modern-js/node-bundle-require": "2.56.1",
91
- "@modern-js/core": "2.56.1",
92
- "@modern-js/plugin": "2.56.1",
93
- "@modern-js/plugin-i18n": "2.56.1",
94
- "@modern-js/plugin-lint": "2.56.1",
95
- "@modern-js/server": "2.56.1",
96
- "@modern-js/prod-server": "2.56.1",
97
- "@modern-js/server-core": "2.56.1",
98
- "@modern-js/utils": "2.56.1",
99
- "@modern-js/server-utils": "2.56.1",
100
- "@modern-js/types": "2.56.1",
101
- "@modern-js/uni-builder": "2.56.1",
102
- "@modern-js/rsbuild-plugin-esbuild": "2.56.1",
103
- "@modern-js/plugin-data-loader": "2.56.1"
90
+ "@modern-js/core": "2.56.2",
91
+ "@modern-js/node-bundle-require": "2.56.2",
92
+ "@modern-js/plugin": "2.56.2",
93
+ "@modern-js/plugin-data-loader": "2.56.2",
94
+ "@modern-js/plugin-i18n": "2.56.2",
95
+ "@modern-js/plugin-lint": "2.56.2",
96
+ "@modern-js/prod-server": "2.56.2",
97
+ "@modern-js/rsbuild-plugin-esbuild": "2.56.2",
98
+ "@modern-js/server": "2.56.2",
99
+ "@modern-js/server-core": "2.56.2",
100
+ "@modern-js/server-utils": "2.56.2",
101
+ "@modern-js/types": "2.56.2",
102
+ "@modern-js/utils": "2.56.2",
103
+ "@modern-js/uni-builder": "2.56.2"
104
104
  },
105
105
  "devDependencies": {
106
106
  "@rsbuild/plugin-swc": "1.0.1-beta.3",
@@ -112,8 +112,8 @@
112
112
  "tsconfig-paths": "^4.2.0",
113
113
  "typescript": "^5",
114
114
  "webpack": "^5.93.0",
115
- "@scripts/build": "2.56.1",
116
- "@scripts/jest-config": "2.56.1"
115
+ "@scripts/build": "2.56.2",
116
+ "@scripts/jest-config": "2.56.2"
117
117
  },
118
118
  "sideEffects": false,
119
119
  "publishConfig": {