@modern-js/app-tools 2.57.1-beta.2 → 2.57.2-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. package/dist/cjs/builder/builder-rspack/adapterCopy.js +2 -2
  2. package/dist/cjs/builder/builder-webpack/index.js +1 -1
  3. package/dist/cjs/builder/generator/index.js +2 -2
  4. package/dist/cjs/builder/index.js +2 -2
  5. package/dist/cjs/commands/build.js +19 -0
  6. package/dist/cjs/commands/dev.js +9 -0
  7. package/dist/cjs/commands/index.js +9 -9
  8. package/dist/cjs/esm/esbuild-loader.mjs +20 -0
  9. package/dist/cjs/esm/register-esm.mjs +65 -0
  10. package/dist/cjs/esm/ts-node-loader.mjs +21 -0
  11. package/dist/cjs/esm/utils.mjs +43 -0
  12. package/dist/cjs/index.js +1 -1
  13. package/dist/cjs/plugins/analyze/index.js +7 -4
  14. package/dist/cjs/plugins/deploy/dependencies/index.js +4 -3
  15. package/dist/cjs/plugins/deploy/dependencies/utils.js +20 -0
  16. package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +3 -0
  17. package/dist/cjs/plugins/deploy/platforms/netlify-entry.mjs +1 -0
  18. package/dist/cjs/plugins/deploy/platforms/{netlifyEntry.js → netlify-handler.js} +6 -4
  19. package/dist/cjs/plugins/deploy/platforms/netlify.js +14 -5
  20. package/dist/cjs/plugins/deploy/platforms/node.js +13 -4
  21. package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +3 -0
  22. package/dist/cjs/plugins/deploy/platforms/vercel-entry.mjs +3 -0
  23. package/dist/cjs/plugins/deploy/platforms/{vercelEntry.js → vercel-handler.js} +27 -1
  24. package/dist/cjs/plugins/deploy/platforms/vercel.js +14 -5
  25. package/dist/cjs/utils/config.js +1 -1
  26. package/dist/cjs/utils/loadPlugins.js +1 -1
  27. package/dist/cjs/utils/register.js +49 -22
  28. package/dist/esm/builder/generator/getBuilderEnvironments.js +0 -2
  29. package/dist/esm/builder/generator/index.js +1 -1
  30. package/dist/esm/builder/index.js +2 -2
  31. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +1 -1
  32. package/dist/esm/commands/build.js +9 -16
  33. package/dist/esm/commands/dev.js +37 -55
  34. package/dist/esm/commands/index.js +6 -6
  35. package/dist/esm/custom-loader.mjs +41 -0
  36. package/dist/esm/index.js +42 -1
  37. package/dist/esm/plugins/analyze/index.js +4 -3
  38. package/dist/esm/plugins/deploy/dependencies/index.js +5 -13
  39. package/dist/esm/plugins/deploy/dependencies/utils.js +7 -7
  40. package/dist/esm/register-esm.mjs +22 -0
  41. package/dist/esm/utils/createServer.js +1 -1
  42. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +1 -1
  43. package/dist/esm-node/builder/generator/index.js +1 -1
  44. package/dist/esm-node/builder/index.js +2 -2
  45. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +1 -1
  46. package/dist/esm-node/commands/build.js +0 -3
  47. package/dist/esm-node/commands/dev.js +16 -24
  48. package/dist/esm-node/commands/index.js +6 -6
  49. package/dist/esm-node/esm/esbuild-loader.js +39 -0
  50. package/dist/esm-node/esm/register-esm.js +39 -0
  51. package/dist/esm-node/esm/ts-node-loader.js +42 -0
  52. package/dist/esm-node/index.js +17 -1
  53. package/dist/esm-node/plugins/analyze/index.js +4 -3
  54. package/dist/esm-node/plugins/deploy/dependencies/index.js +4 -12
  55. package/dist/esm-node/plugins/deploy/dependencies/utils.js +2 -3
  56. package/dist/esm-node/utils/createServer.js +1 -1
  57. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +1 -1
  58. package/dist/types/builder/index.d.ts +1 -1
  59. package/dist/types/esm/esbuild-loader.d.mts +6 -0
  60. package/dist/types/esm/register-esm.d.mts +5 -0
  61. package/dist/types/esm/ts-node-loader.d.mts +6 -0
  62. package/dist/types/esm/utils.d.mts +6 -0
  63. package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -0
  64. package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +1 -0
  65. package/dist/types/plugins/deploy/platforms/netlify-entry.d.mts +1 -0
  66. package/dist/types/plugins/deploy/platforms/netlify-handler.d.cts +1 -0
  67. package/dist/types/plugins/deploy/platforms/vercel-entry.d.cts +2 -0
  68. package/dist/types/plugins/deploy/platforms/vercel-entry.d.mts +2 -0
  69. package/dist/types/plugins/deploy/platforms/vercel-handler.d.cts +1 -0
  70. package/package.json +20 -20
  71. package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +0 -2
  72. package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +0 -2
  73. /package/dist/cjs/plugins/deploy/platforms/{nodeEntry.js → node-entry.js} +0 -0
  74. /package/dist/types/plugins/deploy/platforms/{nodeEntry.d.ts → node-entry.d.ts} +0 -0
@@ -8,14 +8,13 @@ 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
- import { nodeFileTrace } from "@vercel/nft";
12
11
  var handleDependencies = function() {
13
12
  var _ref = _async_to_generator(function(param) {
14
- var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, traceOptions, 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;
13
+ var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, base, entryFiles, fileTrace, currentProjectModules, 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;
15
14
  return _ts_generator(this, function(_state) {
16
15
  switch (_state.label) {
17
16
  case 0:
18
- appDir = param.appDir, serverRootDir = param.serverRootDir, includeEntries = param.includeEntries, _param_traceFiles = param.traceFiles, traceFiles = _param_traceFiles === void 0 ? defaultTraceFiles : _param_traceFiles, entryFilter = param.entryFilter, modifyPackageJson = param.modifyPackageJson, copyWholePackage = param.copyWholePackage, traceOptions = param.traceOptions;
17
+ appDir = param.appDir, serverRootDir = param.serverRootDir, includeEntries = param.includeEntries, _param_traceFiles = param.traceFiles, traceFiles = _param_traceFiles === void 0 ? defaultTraceFiles : _param_traceFiles, entryFilter = param.entryFilter, modifyPackageJson = param.modifyPackageJson, copyWholePackage = param.copyWholePackage;
19
18
  base = "/";
20
19
  return [
21
20
  4,
@@ -25,17 +24,11 @@ var handleDependencies = function() {
25
24
  entryFiles = _state.sent();
26
25
  return [
27
26
  4,
28
- traceFiles({
29
- entryFiles: entryFiles.concat(includeEntries),
30
- serverRootDir,
31
- base,
32
- traceOptions
33
- })
27
+ traceFiles(entryFiles.concat(includeEntries), serverRootDir, base)
34
28
  ];
35
29
  case 2:
36
30
  fileTrace = _state.sent();
37
31
  currentProjectModules = path.join(appDir, "node_modules");
38
- dependencySearchRoot = path.resolve(appDir, "../../../../../../");
39
32
  _ = Object.fromEntries;
40
33
  return [
41
34
  4,
@@ -112,7 +105,7 @@ var handleDependencies = function() {
112
105
  _state2.label = 6;
113
106
  case 6:
114
107
  packageJsonPath = _tmp;
115
- if (!(packageJsonPath === null || packageJsonPath === void 0 ? void 0 : packageJsonPath.startsWith(dependencySearchRoot)))
108
+ if (!packageJsonPath)
116
109
  return [
117
110
  3,
118
111
  8
@@ -609,6 +602,5 @@ var handleDependencies = function() {
609
602
  };
610
603
  }();
611
604
  export {
612
- handleDependencies,
613
- nodeFileTrace
605
+ handleDependencies
614
606
  };
@@ -1,5 +1,4 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
2
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
4
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
4
  import path from "path";
@@ -336,18 +335,19 @@ var findPackageParents = function(pkg, version, tracedFiles) {
336
335
  });
337
336
  };
338
337
  var traceFiles = function() {
339
- var _ref = _async_to_generator(function(param) {
340
- var entryFiles, serverRootDir, _param_base, base, traceOptions;
338
+ var _ref = _async_to_generator(function(entryFiles, serverRootDir) {
339
+ var base;
340
+ var _arguments = arguments;
341
341
  return _ts_generator(this, function(_state) {
342
342
  switch (_state.label) {
343
343
  case 0:
344
- entryFiles = param.entryFiles, serverRootDir = param.serverRootDir, _param_base = param.base, base = _param_base === void 0 ? "/" : _param_base, traceOptions = param.traceOptions;
344
+ base = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : "/";
345
345
  return [
346
346
  4,
347
- nodeFileTrace(entryFiles, _object_spread({
347
+ nodeFileTrace(entryFiles, {
348
348
  base,
349
349
  processCwd: serverRootDir
350
- }, traceOptions))
350
+ })
351
351
  ];
352
352
  case 1:
353
353
  return [
@@ -357,7 +357,7 @@ var traceFiles = function() {
357
357
  }
358
358
  });
359
359
  });
360
- return function traceFiles2(_) {
360
+ return function traceFiles2(entryFiles, serverRootDir) {
361
361
  return _ref.apply(this, arguments);
362
362
  };
363
363
  }();
@@ -0,0 +1,22 @@
1
+ import { register } from 'node:module';
2
+ import path from 'node:path';
3
+
4
+ export const registerEsm = async ({
5
+ appDir,
6
+ distDir,
7
+ alias
8
+ }) => {
9
+ // These can be overridden by ts-node options in tsconfig.json
10
+ process.env.TS_NODE_TRANSPILE_ONLY = true;
11
+ process.env.TS_NODE_PROJECT = path.join(appDir, 'tsconfig.json');
12
+ process.env.TS_NODE_SCOPE = true;
13
+ process.env.TS_NODE_FILES = true;
14
+ process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${path.relative(appDir, distDir)}/`
15
+ register('./custom-loader.mjs', import.meta.url, {
16
+ data: {
17
+ appDir,
18
+ distDir,
19
+ alias
20
+ }
21
+ });
22
+ };
@@ -38,7 +38,7 @@ var createServer = function() {
38
38
  createDevServer(options, applyPlugins)
39
39
  ];
40
40
  case 1:
41
- server = _state.sent().server;
41
+ server = _state.sent();
42
42
  return [
43
43
  2,
44
44
  server
@@ -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")).map((entry2) => entry2.replace("bootstrap.jsx", "bootstrap.server.jsx"));
22
+ serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx"));
23
23
  }
24
24
  const environments = {
25
25
  web: {
@@ -17,7 +17,7 @@ async function generateBuilder(options, bundlerType) {
17
17
  return builder;
18
18
  }
19
19
  async function applyBuilderPlugins(builder, options) {
20
- const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await import("../shared/builderPlugins");
20
+ const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await import("../shared/builderPlugins/index.js");
21
21
  builder.addPlugins([
22
22
  builderPluginAdapterBasic(),
23
23
  builderPluginAdapterSSR(options),
@@ -1,9 +1,9 @@
1
1
  async function createBuilderGenerator(bundler) {
2
2
  if (bundler === "rspack") {
3
- const { createRspackBuilderForModern } = await import("./builder-rspack");
3
+ const { createRspackBuilderForModern } = await import("./builder-rspack/index.js");
4
4
  return createRspackBuilderForModern;
5
5
  }
6
- const { createWebpackBuilderForModern } = await import("./builder-webpack");
6
+ const { createWebpackBuilderForModern } = await import("./builder-webpack/index.js");
7
7
  return createWebpackBuilderForModern;
8
8
  }
9
9
  export {
@@ -24,7 +24,7 @@ function applyNodeCompat(isServiceWorker, chain) {
24
24
  ".node.ts",
25
25
  ".node.tsx",
26
26
  ".server.js",
27
- ".server.jsx",
27
+ ".server.ts",
28
28
  ".server.ts",
29
29
  ".server.tsx"
30
30
  ];
@@ -3,9 +3,7 @@ import { logger } from "@modern-js/utils";
3
3
  import { loadServerPlugins } from "../utils/loadPlugins";
4
4
  import { generateRoutes } from "../utils/routes";
5
5
  import { buildServerConfig } from "../utils/config";
6
- import { registerCompiler } from "../utils/register";
7
6
  const build = async (api, options) => {
8
- var _resolvedConfig_source;
9
7
  if (options === null || options === void 0 ? void 0 : options.analyze) {
10
8
  process.env.BUNDLE_ANALYZE = "true";
11
9
  }
@@ -13,7 +11,6 @@ const build = async (api, options) => {
13
11
  const appContext = api.useAppContext();
14
12
  const hookRunners = api.useHookRunners();
15
13
  await loadServerPlugins(api, appContext.appDirectory, appContext.metaName);
16
- await registerCompiler(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias);
17
14
  const { apiOnly } = appContext;
18
15
  if (apiOnly) {
19
16
  const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
@@ -1,23 +1,27 @@
1
1
  import path from "node:path";
2
2
  import { ResolvedConfigContext } from "@modern-js/core";
3
- import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils";
3
+ import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta } from "@modern-js/utils";
4
4
  import { createDevServer } from "@modern-js/server";
5
5
  import { applyPlugins } from "@modern-js/prod-server";
6
6
  import { loadServerPlugins } from "../utils/loadPlugins";
7
- import { registerCompiler } from "../utils/register";
8
7
  import { printInstructions } from "../utils/printInstructions";
9
8
  import { setServer } from "../utils/createServer";
10
9
  import { generateRoutes } from "../utils/routes";
11
10
  import { buildServerConfig } from "../utils/config";
12
- const dev = async (api, options, devServerOptions) => {
13
- var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev;
11
+ const dev = async (api, options, devServerOptions = {}) => {
12
+ var _normalizedConfig_source, _normalizedConfig_tools;
14
13
  if (options.analyze) {
15
14
  process.env.BUNDLE_ANALYZE = "true";
16
15
  }
17
16
  let normalizedConfig = api.useResolvedConfigContext();
18
17
  const appContext = api.useAppContext();
19
18
  const hookRunners = api.useHookRunners();
20
- await registerCompiler(appContext.appDirectory, appContext.distDirectory, normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias);
19
+ const { registerEsm } = await import("../esm/register-esm.mjs");
20
+ await registerEsm({
21
+ appDir: appContext.appDirectory,
22
+ distDir: appContext.distDirectory,
23
+ alias: (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias
24
+ });
21
25
  normalizedConfig = {
22
26
  ...normalizedConfig,
23
27
  cliOptions: options
@@ -60,32 +64,20 @@ const dev = async (api, options, devServerOptions) => {
60
64
  plugins: pluginInstances,
61
65
  ...devServerOptions
62
66
  };
63
- const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
64
67
  if (apiOnly) {
65
- const { server } = await createDevServer({
66
- ...serverOptions,
67
- runCompile: false
68
- }, (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins);
69
- server.listen({
68
+ var _normalizedConfig_dev;
69
+ const app = await createDevServer(serverOptions, applyPlugins);
70
+ const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
71
+ app.listen({
70
72
  port,
71
73
  host
72
74
  }, () => {
73
75
  printInstructions(hookRunners, appContext, normalizedConfig);
74
76
  });
75
77
  } else {
76
- const { server, afterListen } = await createDevServer({
77
- ...serverOptions,
78
- builder: appContext.builder
79
- }, (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins);
80
- server.listen({
81
- port,
82
- host
83
- }, async (err) => {
84
- if (err) {
85
- logger.error("Occur error %s, when start dev server", err);
86
- }
87
- logger.debug("listen dev server done");
88
- await afterListen();
78
+ const { server } = await appContext.builder.startDevServer({
79
+ serverOptions,
80
+ applyPlugins
89
81
  });
90
82
  setServer(server);
91
83
  }
@@ -5,7 +5,7 @@ const devCommand = async (program, api) => {
5
5
  const runner = api.useHookRunners();
6
6
  const devToolMetas = await runner.registerDev();
7
7
  const devProgram = program.command("dev").alias("start").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("--web-only", i18n.t(localeKeys.command.dev.webOnly)).action(async (options) => {
8
- const { dev } = await import("./dev");
8
+ const { dev } = await import("./dev.js");
9
9
  await dev(api, options);
10
10
  });
11
11
  for (const meta of devToolMetas) {
@@ -28,7 +28,7 @@ const buildCommand = async (program, api) => {
28
28
  const runner = api.useHookRunners();
29
29
  const platformBuilders = await runner.registerBuildPlatform();
30
30
  const buildProgram = program.command("build").usage("[options]").description(i18n.t(localeKeys.command.build.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).action(async (options) => {
31
- const { build } = await import("./build");
31
+ const { build } = await import("./build.js");
32
32
  await build(api, options);
33
33
  });
34
34
  for (const platformBuilder of platformBuilders) {
@@ -47,17 +47,17 @@ const buildCommand = async (program, api) => {
47
47
  };
48
48
  const serverCommand = (program, api) => {
49
49
  program.command("serve").usage("[options]").description(i18n.t(localeKeys.command.serve.describe)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async () => {
50
- const { start } = await import("./serve");
50
+ const { start } = await import("./serve.js");
51
51
  await start(api);
52
52
  });
53
53
  };
54
54
  const deployCommand = (program, api) => {
55
55
  program.command("deploy").usage("[options]").option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-s --skip-build", i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options) => {
56
56
  if (!options.skipBuild) {
57
- const { build } = await import("./build");
57
+ const { build } = await import("./build.js");
58
58
  await build(api);
59
59
  }
60
- const { deploy } = await import("./deploy");
60
+ const { deploy } = await import("./deploy.js");
61
61
  await deploy(api, options);
62
62
  process.exit(0);
63
63
  });
@@ -72,7 +72,7 @@ const newCommand = (program, locale) => {
72
72
  };
73
73
  const inspectCommand = (program, api) => {
74
74
  program.command("inspect").description("inspect the internal configs").option(`--env <env>`, i18n.t(localeKeys.command.inspect.env), "development").option("--output <output>", i18n.t(localeKeys.command.inspect.output), "/").option("--verbose", i18n.t(localeKeys.command.inspect.verbose)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).action(async (options) => {
75
- const { inspect } = await import("./inspect");
75
+ const { inspect } = await import("./inspect.js");
76
76
  inspect(api, options);
77
77
  });
78
78
  };
@@ -0,0 +1,39 @@
1
+ import { pathToFileURL } from "url";
2
+ import * as tsConfigPaths from "@modern-js/utils/tsconfig-paths";
3
+ import { getAliasConfig } from "@modern-js/utils";
4
+ import path from "path";
5
+ let matchPath;
6
+ function initialize({ appDir, alias }) {
7
+ const TS_CONFIG_FILENAME = `tsconfig.json`;
8
+ const aliasConfig = getAliasConfig(alias, {
9
+ appDirectory: appDir,
10
+ tsconfigPath: path.resolve(appDir, TS_CONFIG_FILENAME)
11
+ });
12
+ const { paths = {}, absoluteBaseUrl = "./" } = aliasConfig;
13
+ const tsPaths = Object.keys(paths).reduce((o, key) => {
14
+ let tsPath = paths[key];
15
+ if (typeof tsPath === "string" && path.isAbsolute(tsPath)) {
16
+ tsPath = path.relative(absoluteBaseUrl, tsPath);
17
+ }
18
+ if (typeof tsPath === "string") {
19
+ tsPath = [
20
+ tsPath
21
+ ];
22
+ }
23
+ return {
24
+ ...o,
25
+ [`${key}`]: tsPath
26
+ };
27
+ }, {});
28
+ matchPath = tsConfigPaths.createMatchPath(absoluteBaseUrl, tsPaths);
29
+ }
30
+ function resolve(specifier, context, defaultResolve) {
31
+ const match = matchPath(specifier);
32
+ return match ? defaultResolve(pathToFileURL(match).href, context) : defaultResolve(specifier, context);
33
+ }
34
+ import { load } from "esbuild-register/loader";
35
+ export {
36
+ initialize,
37
+ load,
38
+ resolve
39
+ };
@@ -0,0 +1,39 @@
1
+ const import_meta = {};
2
+ import { register } from "node:module";
3
+ import path from "node:path";
4
+ const checkDep = async (dep) => {
5
+ try {
6
+ await import(dep);
7
+ return true;
8
+ } catch (error) {
9
+ return false;
10
+ }
11
+ };
12
+ const registerEsm = async ({ appDir, distDir, alias }) => {
13
+ const hasTsNode = await checkDep("ts-node");
14
+ if (hasTsNode) {
15
+ process.env.TS_NODE_TRANSPILE_ONLY = true;
16
+ process.env.TS_NODE_PROJECT = path.join(appDir, "tsconfig.json");
17
+ process.env.TS_NODE_SCOPE = true;
18
+ process.env.TS_NODE_FILES = true;
19
+ process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${path.relative(appDir, distDir)}/`;
20
+ register("./ts-node-loader.mjs", import_meta.url, {
21
+ data: {
22
+ appDir,
23
+ distDir,
24
+ alias
25
+ }
26
+ });
27
+ } else {
28
+ register("./esbuild-loader.mjs", import_meta.url, {
29
+ data: {
30
+ appDir,
31
+ distDir,
32
+ alias
33
+ }
34
+ });
35
+ }
36
+ };
37
+ export {
38
+ registerEsm
39
+ };
@@ -0,0 +1,42 @@
1
+ import { pathToFileURL } from "url";
2
+ import { resolve as tsNodeResolve } from "ts-node/esm";
3
+ import * as tsConfigPaths from "@modern-js/utils/tsconfig-paths";
4
+ import { getAliasConfig } from "@modern-js/utils";
5
+ import path from "path";
6
+ console.log("ttttttttttttt", tsConfigPaths);
7
+ let matchPath;
8
+ function initialize({ appDir, alias }) {
9
+ const TS_CONFIG_FILENAME = `tsconfig.json`;
10
+ const aliasConfig = getAliasConfig(alias, {
11
+ appDirectory: appDir,
12
+ tsconfigPath: path.resolve(appDir, TS_CONFIG_FILENAME)
13
+ });
14
+ const { paths = {}, absoluteBaseUrl = "./" } = aliasConfig;
15
+ const tsPaths = Object.keys(paths).reduce((o, key) => {
16
+ let tsPath = paths[key];
17
+ if (typeof tsPath === "string" && path.isAbsolute(tsPath)) {
18
+ tsPath = path.relative(absoluteBaseUrl, tsPath);
19
+ }
20
+ if (typeof tsPath === "string") {
21
+ tsPath = [
22
+ tsPath
23
+ ];
24
+ }
25
+ return {
26
+ ...o,
27
+ [`${key}`]: tsPath
28
+ };
29
+ }, {});
30
+ matchPath = tsConfigPaths.createMatchPath(absoluteBaseUrl, tsPaths);
31
+ }
32
+ function resolve(specifier, context, defaultResolve) {
33
+ const match = matchPath(specifier);
34
+ return match ? tsNodeResolve(pathToFileURL(match).href, context, defaultResolve) : tsNodeResolve(specifier, context, defaultResolve);
35
+ }
36
+ import { transformSource, load } from "ts-node/esm";
37
+ export {
38
+ initialize,
39
+ load,
40
+ resolve,
41
+ transformSource
42
+ };
@@ -1,6 +1,6 @@
1
1
  import path from "path";
2
2
  import { lintPlugin } from "@modern-js/plugin-lint";
3
- import { cleanRequireCache, emptyDir, getCommand, getArgv } from "@modern-js/utils";
3
+ import { cleanRequireCache, emptyDir, getCommand, getArgv, fs, NESTED_ROUTE_SPEC_FILE } from "@modern-js/utils";
4
4
  import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
5
5
  import initializePlugin from "./plugins/initialize";
6
6
  import analyzePlugin from "./plugins/analyze";
@@ -47,6 +47,7 @@ const appTools = (options = {
47
47
  ...appContext,
48
48
  toolsType: "app-tools"
49
49
  });
50
+ const nestedRoutes = {};
50
51
  const locale = getLocaleLanguage();
51
52
  i18n.changeLanguage({
52
53
  locale
@@ -111,6 +112,21 @@ const appTools = (options = {
111
112
  cleanRequireCache([
112
113
  require.resolve("./plugins/analyze")
113
114
  ]);
115
+ },
116
+ async modifyFileSystemRoutes({ entrypoint, routes }) {
117
+ nestedRoutes[entrypoint.entryName] = routes;
118
+ return {
119
+ entrypoint,
120
+ routes
121
+ };
122
+ },
123
+ async beforeGenerateRoutes({ entrypoint, code }) {
124
+ const { distDirectory } = api.useAppContext();
125
+ await fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutes);
126
+ return {
127
+ entrypoint,
128
+ code
129
+ };
114
130
  }
115
131
  };
116
132
  }
@@ -7,6 +7,7 @@ import { getSelectedEntries } from "../../utils/getSelectedEntries";
7
7
  import { initialNormalizedConfig } from "../../config";
8
8
  import { createBuilderGenerator } from "../../builder";
9
9
  import { checkIsBuildCommands } from "./utils";
10
+ import { compatibleRequire } from "@modern-js/utils";
10
11
  const debug = createDebugger("plugin-analyze");
11
12
  var analyze_default = ({ bundler }) => ({
12
13
  name: "@modern-js/plugin-analyze",
@@ -44,9 +45,9 @@ var analyze_default = ({ bundler }) => ({
44
45
  return;
45
46
  }
46
47
  const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
47
- import("./getBundleEntry"),
48
- import("./getServerRoutes"),
49
- import("./getHtmlTemplate")
48
+ compatibleRequire(path.join(__dirname, "./getBundleEntry.js")),
49
+ compatibleRequire(path.join(__dirname, "./getServerRoutes.js")),
50
+ compatibleRequire(path.join(__dirname, "./getHtmlTemplate.js"))
50
51
  ]);
51
52
  const { entrypoints } = await hookRunners.modifyEntrypoints({
52
53
  entrypoints: await getBundleEntry(hookRunners, appContext, resolvedConfig)
@@ -3,18 +3,11 @@ 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
- import { nodeFileTrace } from "@vercel/nft";
7
- const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage, traceOptions }) => {
6
+ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage }) => {
8
7
  const base = "/";
9
8
  const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
10
- const fileTrace = await traceFiles({
11
- entryFiles: entryFiles.concat(includeEntries),
12
- serverRootDir,
13
- base,
14
- traceOptions
15
- });
9
+ const fileTrace = await traceFiles(entryFiles.concat(includeEntries), serverRootDir, base);
16
10
  const currentProjectModules = path.join(appDir, "node_modules");
17
- const dependencySearchRoot = path.resolve(appDir, "../../../../../../");
18
11
  const tracedFiles = Object.fromEntries(await Promise.all([
19
12
  ...fileTrace.reasons.entries()
20
13
  ].map(async ([_path, reasons]) => {
@@ -45,7 +38,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
45
38
  const packageJsonPath = match ? path.join(match[0], "package.json") : await pkgUp({
46
39
  cwd: path.dirname(filePath)
47
40
  });
48
- if (packageJsonPath === null || packageJsonPath === void 0 ? void 0 : packageJsonPath.startsWith(dependencySearchRoot)) {
41
+ if (packageJsonPath) {
49
42
  const packageJson = await fse.readJSON(packageJsonPath);
50
43
  pkgPath = baseDir = path.dirname(packageJsonPath);
51
44
  subpath = path.relative(baseDir, filePath);
@@ -196,6 +189,5 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
196
189
  await fse.writeJSON(outputPkgPath, finalPkgJson);
197
190
  };
198
191
  export {
199
- handleDependencies,
200
- nodeFileTrace
192
+ handleDependencies
201
193
  };
@@ -98,11 +98,10 @@ const findPackageParents = (pkg, version, tracedFiles) => {
98
98
  ];
99
99
  return parentPkgs.filter((parentPkg) => parentPkg);
100
100
  };
101
- const traceFiles = async ({ entryFiles, serverRootDir, base = "/", traceOptions }) => {
101
+ const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
102
102
  return await nodeFileTrace(entryFiles, {
103
103
  base,
104
- processCwd: serverRootDir,
105
- ...traceOptions
104
+ processCwd: serverRootDir
106
105
  });
107
106
  };
108
107
  const resolveTracedPath = async (base, p) => fse.realpath(path.resolve(base, p));
@@ -15,7 +15,7 @@ const createServer = async (options) => {
15
15
  if (server) {
16
16
  server.close();
17
17
  }
18
- server = (await createDevServer(options, applyPlugins)).server;
18
+ server = await createDevServer(options, applyPlugins);
19
19
  return server;
20
20
  };
21
21
  export {
@@ -1,5 +1,5 @@
1
1
  import type { IAppContext } from '@modern-js/core';
2
2
  import type { AppNormalizedConfig } from '../../types';
3
3
  export declare function getBuilderEnvironments(normalizedConfig: AppNormalizedConfig<'shared'>, appContext: IAppContext): {
4
- [name: string]: import("@rsbuild/core/dist-types/types").EnvironmentConfig;
4
+ [name: string]: import("@rsbuild/core").EnvironmentConfig;
5
5
  };
@@ -1 +1 @@
1
- export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack").createRspackBuilderForModern>;
1
+ export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack/index.js").createRspackBuilderForModern>;
@@ -0,0 +1,6 @@
1
+ export function initialize({ appDir, alias, tsconfigPath }: {
2
+ appDir: any;
3
+ alias: any;
4
+ tsconfigPath: any;
5
+ }): Promise<void>;
6
+ export function resolve(specifier: any, context: any, defaultResolve: any): any;
@@ -0,0 +1,5 @@
1
+ export function registerEsm({ appDir, distDir, alias }: {
2
+ appDir: any;
3
+ distDir: any;
4
+ alias: any;
5
+ }): Promise<void>;
@@ -0,0 +1,6 @@
1
+ export function initialize({ appDir, alias, tsconfigPath }: {
2
+ appDir: any;
3
+ alias: any;
4
+ tsconfigPath: any;
5
+ }): Promise<void>;
6
+ export function resolve(specifier: any, context: any, defaultResolve: any): any;
@@ -0,0 +1,6 @@
1
+ export function createMatchPath({ alias, appDir, tsconfigPath }: {
2
+ alias: any;
3
+ appDir: any;
4
+ tsconfigPath: any;
5
+ }): tsConfigPaths.MatchPath;
6
+ import tsConfigPaths from '@modern-js/utils/tsconfig-paths';
@@ -40,4 +40,5 @@ export declare const traceFiles: ({ entryFiles, serverRootDir, base, traceOption
40
40
  traceOptions?: NodeFileTraceOptions | undefined;
41
41
  }) => Promise<import("@vercel/nft").NodeFileTraceResult>;
42
42
  export declare const resolveTracedPath: (base: string, p: string) => Promise<string>;
43
+ export declare const isSubPath: (parentPath: string, childPath: string) => boolean | "";
43
44
  export {};
@@ -0,0 +1 @@
1
+ export default handler;
@@ -0,0 +1 @@
1
+ export { handler as default } from "./netlify-handler.cjs";
@@ -0,0 +1 @@
1
+ export function handler(request: any, context: any): Promise<any>;
@@ -0,0 +1,2 @@
1
+ export = handler;
2
+ import { handler } from "./vercel-handler.cjs";
@@ -0,0 +1,2 @@
1
+ export default handler;
2
+ import { handler } from './vercel-handler.cjs';
@@ -0,0 +1 @@
1
+ export function handler(req: any, res: any): Promise<any>;