@modern-js/app-tools 2.57.2-alpha.0 → 2.58.1-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. package/dist/cjs/builder/builder-webpack/index.js +1 -1
  2. package/dist/cjs/builder/generator/index.js +2 -2
  3. package/dist/cjs/builder/index.js +2 -2
  4. package/dist/cjs/commands/build.js +0 -19
  5. package/dist/cjs/commands/dev.js +0 -9
  6. package/dist/cjs/commands/index.js +8 -8
  7. package/dist/cjs/index.js +1 -1
  8. package/dist/cjs/plugins/analyze/index.js +3 -3
  9. package/dist/cjs/plugins/deploy/dependencies/index.js +12 -2
  10. package/dist/cjs/plugins/deploy/dependencies/utils.js +73 -13
  11. package/dist/cjs/plugins/deploy/platforms/netlify.js +5 -14
  12. package/dist/cjs/plugins/deploy/platforms/{netlify-handler.js → netlifyEntry.js} +4 -6
  13. package/dist/cjs/plugins/deploy/platforms/node.js +4 -13
  14. package/dist/cjs/plugins/deploy/platforms/vercel.js +5 -14
  15. package/dist/cjs/plugins/deploy/platforms/{vercel-handler.js → vercelEntry.js} +1 -27
  16. package/dist/cjs/utils/config.js +7 -23
  17. package/dist/cjs/utils/loadPlugins.js +1 -1
  18. package/dist/cjs/utils/register.js +22 -49
  19. package/dist/esm/builder/builder-rspack/adapterCopy.js +4 -3
  20. package/dist/esm/builder/generator/getBuilderEnvironments.js +2 -0
  21. package/dist/esm/builder/generator/index.js +1 -1
  22. package/dist/esm/builder/index.js +2 -2
  23. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +1 -1
  24. package/dist/esm/commands/build.js +16 -9
  25. package/dist/esm/commands/dev.js +55 -37
  26. package/dist/esm/commands/index.js +7 -7
  27. package/dist/esm/index.js +1 -42
  28. package/dist/esm/plugins/analyze/index.js +10 -6
  29. package/dist/esm/plugins/deploy/dependencies/index.js +28 -8
  30. package/dist/esm/plugins/deploy/dependencies/utils.js +290 -10
  31. package/dist/esm/utils/config.js +6 -21
  32. package/dist/esm/utils/createServer.js +1 -1
  33. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +2 -2
  34. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +1 -1
  35. package/dist/esm-node/builder/generator/index.js +1 -1
  36. package/dist/esm-node/builder/index.js +2 -2
  37. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +1 -1
  38. package/dist/esm-node/commands/build.js +3 -0
  39. package/dist/esm-node/commands/dev.js +24 -16
  40. package/dist/esm-node/commands/index.js +7 -7
  41. package/dist/esm-node/index.js +1 -17
  42. package/dist/esm-node/plugins/analyze/index.js +7 -5
  43. package/dist/esm-node/plugins/deploy/dependencies/index.js +26 -7
  44. package/dist/esm-node/plugins/deploy/dependencies/utils.js +83 -3
  45. package/dist/esm-node/utils/config.js +5 -20
  46. package/dist/esm-node/utils/createServer.js +1 -1
  47. package/dist/types/builder/index.d.ts +1 -1
  48. package/dist/types/plugins/deploy/dependencies/index.d.ts +5 -3
  49. package/dist/types/plugins/deploy/dependencies/utils.d.ts +7 -1
  50. package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
  51. package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +2 -0
  52. package/dist/types/utils/config.d.ts +0 -5
  53. package/package.json +23 -21
  54. package/dist/cjs/esm/esbuild-loader.mjs +0 -20
  55. package/dist/cjs/esm/register-esm.mjs +0 -65
  56. package/dist/cjs/esm/ts-node-loader.mjs +0 -21
  57. package/dist/cjs/esm/utils.mjs +0 -43
  58. package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +0 -3
  59. package/dist/cjs/plugins/deploy/platforms/netlify-entry.mjs +0 -1
  60. package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +0 -3
  61. package/dist/cjs/plugins/deploy/platforms/vercel-entry.mjs +0 -3
  62. package/dist/esm/custom-loader.mjs +0 -41
  63. package/dist/esm/register-esm.mjs +0 -22
  64. package/dist/esm-node/esm/esbuild-loader.js +0 -39
  65. package/dist/esm-node/esm/register-esm.js +0 -39
  66. package/dist/esm-node/esm/ts-node-loader.js +0 -42
  67. package/dist/types/esm/esbuild-loader.d.mts +0 -6
  68. package/dist/types/esm/register-esm.d.mts +0 -5
  69. package/dist/types/esm/ts-node-loader.d.mts +0 -6
  70. package/dist/types/esm/utils.d.mts +0 -6
  71. package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +0 -1
  72. package/dist/types/plugins/deploy/platforms/netlify-entry.d.mts +0 -1
  73. package/dist/types/plugins/deploy/platforms/netlify-handler.d.cts +0 -1
  74. package/dist/types/plugins/deploy/platforms/vercel-entry.d.cts +0 -2
  75. package/dist/types/plugins/deploy/platforms/vercel-entry.d.mts +0 -2
  76. package/dist/types/plugins/deploy/platforms/vercel-handler.d.cts +0 -1
  77. /package/dist/cjs/plugins/deploy/platforms/{node-entry.js → nodeEntry.js} +0 -0
  78. /package/dist/types/plugins/deploy/platforms/{node-entry.d.ts → nodeEntry.d.ts} +0 -0
@@ -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.js");
8
+ const { dev } = await import("./dev");
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.js");
31
+ const { build } = await import("./build");
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.js");
50
+ const { start } = await import("./serve");
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.js");
57
+ const { build } = await import("./build");
58
58
  await build(api);
59
59
  }
60
- const { deploy } = await import("./deploy.js");
60
+ const { deploy } = await import("./deploy");
61
61
  await deploy(api, options);
62
62
  process.exit(0);
63
63
  });
@@ -71,8 +71,8 @@ const newCommand = (program, locale) => {
71
71
  });
72
72
  };
73
73
  const inspectCommand = (program, api) => {
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.js");
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");
76
76
  inspect(api, options);
77
77
  });
78
78
  };
@@ -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, fs, NESTED_ROUTE_SPEC_FILE } from "@modern-js/utils";
3
+ import { cleanRequireCache, emptyDir, getCommand, getArgv } 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,7 +47,6 @@ const appTools = (options = {
47
47
  ...appContext,
48
48
  toolsType: "app-tools"
49
49
  });
50
- const nestedRoutes = {};
51
50
  const locale = getLocaleLanguage();
52
51
  i18n.changeLanguage({
53
52
  locale
@@ -112,21 +111,6 @@ const appTools = (options = {
112
111
  cleanRequireCache([
113
112
  require.resolve("./plugins/analyze")
114
113
  ]);
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
- };
130
114
  }
131
115
  };
132
116
  }
@@ -7,7 +7,6 @@ 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";
11
10
  const debug = createDebugger("plugin-analyze");
12
11
  var analyze_default = ({ bundler }) => ({
13
12
  name: "@modern-js/plugin-analyze",
@@ -45,9 +44,9 @@ var analyze_default = ({ bundler }) => ({
45
44
  return;
46
45
  }
47
46
  const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
48
- compatibleRequire(path.join(__dirname, "./getBundleEntry.js")),
49
- compatibleRequire(path.join(__dirname, "./getServerRoutes.js")),
50
- compatibleRequire(path.join(__dirname, "./getHtmlTemplate.js"))
47
+ import("./getBundleEntry"),
48
+ import("./getServerRoutes"),
49
+ import("./getHtmlTemplate")
51
50
  ]);
52
51
  const { entrypoints } = await hookRunners.modifyEntrypoints({
53
52
  entrypoints: await getBundleEntry(hookRunners, appContext, resolvedConfig)
@@ -100,7 +99,10 @@ var analyze_default = ({ bundler }) => ({
100
99
  normalizedConfig,
101
100
  appContext
102
101
  });
103
- builder.onBeforeBuild(async ({ bundlerConfigs }) => {
102
+ builder.onBeforeBuild(async ({ bundlerConfigs, isFirstCompile }) => {
103
+ if (!isFirstCompile) {
104
+ return;
105
+ }
104
106
  const hookRunners2 = api.useHookRunners();
105
107
  await generateRoutes(appContext);
106
108
  await hookRunners2.beforeBuild({
@@ -2,12 +2,28 @@ import path from "node:path";
2
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
- import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
6
- const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage }) => {
5
+ import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive, isSubPath } from "./utils";
6
+ import { nodeFileTrace } from "@vercel/nft";
7
+ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage, cacheOptions = {
8
+ cacheDir: ".modern-js/deploy",
9
+ fileCache: true,
10
+ analysisCache: true
11
+ }, traceOptions }) => {
7
12
  const base = "/";
13
+ const startTime = Date.now();
8
14
  const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
9
- const fileTrace = await traceFiles(entryFiles.concat(includeEntries), serverRootDir, base);
15
+ const fileTrace = await traceFiles({
16
+ entryFiles: entryFiles.concat(includeEntries),
17
+ serverRootDir,
18
+ cacheOptions: {
19
+ ...cacheOptions,
20
+ cacheDir: path.resolve(appDir, cacheOptions.cacheDir)
21
+ },
22
+ base,
23
+ traceOptions
24
+ });
10
25
  const currentProjectModules = path.join(appDir, "node_modules");
26
+ const dependencySearchRoot = path.resolve(appDir, "../../../../../../");
11
27
  const tracedFiles = Object.fromEntries(await Promise.all([
12
28
  ...fileTrace.reasons.entries()
13
29
  ].map(async ([_path, reasons]) => {
@@ -15,7 +31,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
15
31
  return;
16
32
  }
17
33
  const filePath = await resolveTracedPath(base, _path);
18
- if (filePath.startsWith(serverRootDir) || filePath.startsWith(appDir) && !filePath.startsWith(currentProjectModules)) {
34
+ if (isSubPath(serverRootDir, filePath) || isSubPath(appDir, filePath) && !isSubPath(currentProjectModules, filePath)) {
19
35
  return;
20
36
  }
21
37
  if (!await isFile(filePath)) {
@@ -38,7 +54,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
38
54
  const packageJsonPath = match ? path.join(match[0], "package.json") : await pkgUp({
39
55
  cwd: path.dirname(filePath)
40
56
  });
41
- if (packageJsonPath) {
57
+ if (packageJsonPath && isSubPath(dependencySearchRoot, packageJsonPath)) {
42
58
  const packageJson = await fse.readJSON(packageJsonPath);
43
59
  pkgPath = baseDir = path.dirname(packageJsonPath);
44
60
  subpath = path.relative(baseDir, filePath);
@@ -55,7 +71,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
55
71
  path: filePath,
56
72
  parents,
57
73
  isDirectDep: parents.some((parent) => {
58
- return parent.startsWith(appDir) && !parent.startsWith(currentProjectModules);
74
+ return isSubPath(appDir, parent) && !isSubPath(currentProjectModules, parent);
59
75
  }),
60
76
  subpath,
61
77
  pkgName,
@@ -187,7 +203,10 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
187
203
  };
188
204
  const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
189
205
  await fse.writeJSON(outputPkgPath, finalPkgJson);
206
+ const endTime = Date.now();
207
+ console.log("handleDependencies cost:", endTime - startTime);
190
208
  };
191
209
  export {
192
- handleDependencies
210
+ handleDependencies,
211
+ nodeFileTrace
193
212
  };
@@ -98,17 +98,97 @@ const findPackageParents = (pkg, version, tracedFiles) => {
98
98
  ];
99
99
  return parentPkgs.filter((parentPkg) => parentPkg);
100
100
  };
101
- const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
102
- return await nodeFileTrace(entryFiles, {
101
+ async function serializeMap(map) {
102
+ const resolvedMap = /* @__PURE__ */ new Map();
103
+ await Promise.all(Array.from(map.entries()).map(async ([key, value]) => {
104
+ resolvedMap.set(key, value instanceof Promise ? await Promise.resolve(value) : value);
105
+ }));
106
+ return JSON.stringify(resolvedMap, (key, value) => {
107
+ if (value instanceof Map) {
108
+ return {
109
+ dataType: "Map",
110
+ value: Array.from(value.entries())
111
+ };
112
+ }
113
+ if (value instanceof Set) {
114
+ return {
115
+ dataType: "Set",
116
+ value: Array.from(value)
117
+ };
118
+ }
119
+ return value;
120
+ });
121
+ }
122
+ function deserializeMap(serializedData) {
123
+ return JSON.parse(serializedData, (key, value) => {
124
+ if (value && value.dataType === "Map") {
125
+ return new Map(value.value);
126
+ }
127
+ if (value && value.dataType === "Set") {
128
+ return new Set(value.value);
129
+ }
130
+ return value;
131
+ });
132
+ }
133
+ const traceFiles = async ({ entryFiles, serverRootDir, base = "/", cacheOptions, traceOptions }) => {
134
+ const { cacheDir, fileCache: enableFileCache, analysisCache: enableAnalysisCache } = cacheOptions;
135
+ const analysisCacheFile = path.join(cacheDir, "analysis-cache.json");
136
+ const fileCacheFile = path.join(cacheDir, "file-cache.json");
137
+ const cache = /* @__PURE__ */ Object.create(null);
138
+ if (enableAnalysisCache && await fse.pathExists(analysisCacheFile)) {
139
+ const analysisCache2 = (await fse.readFile(analysisCacheFile)).toString();
140
+ cache.analysisCache = deserializeMap(analysisCache2);
141
+ }
142
+ if (enableFileCache && await fse.pathExists(fileCacheFile)) {
143
+ const fileCache2 = (await fse.readFile(fileCacheFile)).toString();
144
+ cache.fileCache = deserializeMap(fileCache2);
145
+ }
146
+ const res = await nodeFileTrace(entryFiles, {
103
147
  base,
104
- processCwd: serverRootDir
148
+ processCwd: serverRootDir,
149
+ cache,
150
+ ...traceOptions
105
151
  });
152
+ const { analysisCache, fileCache } = cache;
153
+ if (analysisCache || fileCache) {
154
+ await fse.ensureDir(cacheDir);
155
+ if (analysisCache) {
156
+ const newAnalysisCache = new Map(analysisCache);
157
+ for (const key of newAnalysisCache.keys()) {
158
+ if (!key.includes("node_modules/")) {
159
+ newAnalysisCache.delete(key);
160
+ }
161
+ }
162
+ fse.writeFile(analysisCacheFile, await serializeMap(newAnalysisCache));
163
+ }
164
+ if (fileCache) {
165
+ const newFileCache = new Map(fileCache);
166
+ for (const key of newFileCache.keys()) {
167
+ if (!key.includes("node_modules/")) {
168
+ newFileCache.delete(key);
169
+ }
170
+ }
171
+ console.time("111");
172
+ fse.writeFile(fileCacheFile, await serializeMap(newFileCache));
173
+ console.timeEnd("111");
174
+ }
175
+ }
176
+ console.log("ffffffff", __filename);
177
+ return res;
106
178
  };
107
179
  const resolveTracedPath = async (base, p) => fse.realpath(path.resolve(base, p));
180
+ const isSubPath = (parentPath, childPath) => {
181
+ if (!parentPath || !childPath) {
182
+ return false;
183
+ }
184
+ const relative = path.relative(parentPath, childPath);
185
+ return relative && !relative.startsWith("..");
186
+ };
108
187
  export {
109
188
  findEntryFiles,
110
189
  findPackageParents,
111
190
  isFile,
191
+ isSubPath,
112
192
  linkPackage,
113
193
  readDirRecursive,
114
194
  resolveTracedPath,
@@ -1,6 +1,7 @@
1
1
  import * as path from "path";
2
2
  import { bundle } from "@modern-js/node-bundle-require";
3
3
  import { fs, getServerConfig, ensureAbsolutePath, OUTPUT_CONFIG_FILE, CONFIG_FILE_EXTENSIONS } from "@modern-js/utils";
4
+ import { stringify } from "flatted";
4
5
  const defineServerConfig = (config) => config;
5
6
  const buildServerConfig = async ({ appDirectory, distDirectory, configFile, options, watch }) => {
6
7
  const configFilePath = await getServerConfig(appDirectory, configFile);
@@ -33,32 +34,16 @@ const buildServerConfig = async ({ appDirectory, distDirectory, configFile, opti
33
34
  });
34
35
  }
35
36
  };
36
- const safeReplacer = () => {
37
- const cache = [];
38
- const keyCache = [];
39
- return function(key, value) {
40
- if (typeof value === "object" && value !== null) {
41
- const index = cache.indexOf(value);
42
- if (index !== -1) {
43
- return `[Circular ${keyCache[index]}]`;
44
- }
45
- cache.push(value);
46
- keyCache.push(key || "root");
47
- }
48
- return value;
49
- };
50
- };
51
37
  const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
52
38
  var _resolvedConfig_output_distPath;
53
39
  const outputPath = ensureAbsolutePath(appDirectory, path.join(((_resolvedConfig_output_distPath = resolvedConfig.output.distPath) === null || _resolvedConfig_output_distPath === void 0 ? void 0 : _resolvedConfig_output_distPath.root) || "./dist", OUTPUT_CONFIG_FILE));
54
- await fs.writeJSON(outputPath, resolvedConfig, {
55
- spaces: 2,
56
- replacer: safeReplacer()
40
+ const output = stringify(resolvedConfig);
41
+ await fs.writeFile(outputPath, output, {
42
+ encoding: "utf-8"
57
43
  });
58
44
  };
59
45
  export {
60
46
  buildServerConfig,
61
47
  defineServerConfig,
62
- emitResolvedConfig,
63
- safeReplacer
48
+ emitResolvedConfig
64
49
  };
@@ -15,7 +15,7 @@ const createServer = async (options) => {
15
15
  if (server) {
16
16
  server.close();
17
17
  }
18
- server = await createDevServer(options, applyPlugins);
18
+ server = (await createDevServer(options, applyPlugins)).server;
19
19
  return server;
20
20
  };
21
21
  export {
@@ -1 +1 @@
1
- export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack/index.js").createRspackBuilderForModern>;
1
+ export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack").createRspackBuilderForModern>;
@@ -1,20 +1,22 @@
1
1
  import type { PackageJson } from 'pkg-types';
2
2
  import type { NodeFileTraceOptions } from '@vercel/nft';
3
- import { traceFiles as defaultTraceFiles } from './utils';
3
+ import { traceFiles as defaultTraceFiles, CacheOptions } from './utils';
4
4
  export type { NodeFileTraceOptions } from '@vercel/nft';
5
5
  export { nodeFileTrace } from '@vercel/nft';
6
- export declare const handleDependencies: ({ appDir, serverRootDir, includeEntries, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, traceOptions, }: {
6
+ export declare const handleDependencies: ({ appDir, serverRootDir, includeEntries, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, cacheOptions, traceOptions, }: {
7
7
  appDir: string;
8
8
  serverRootDir: string;
9
9
  includeEntries: string[];
10
- traceFiles?: (({ entryFiles, serverRootDir, base, traceOptions, }: {
10
+ traceFiles?: (({ entryFiles, serverRootDir, base, cacheOptions, traceOptions, }: {
11
11
  entryFiles: string[];
12
12
  serverRootDir: string;
13
13
  base?: string | undefined;
14
+ cacheOptions: CacheOptions;
14
15
  traceOptions?: NodeFileTraceOptions | undefined;
15
16
  }) => Promise<import("@vercel/nft").NodeFileTraceResult>) | undefined;
16
17
  entryFilter?: ((filePath: string) => boolean) | undefined;
17
18
  modifyPackageJson?: ((pkgJson: PackageJson) => PackageJson) | undefined;
18
19
  copyWholePackage?: ((pkgName: string) => boolean) | undefined;
20
+ cacheOptions?: CacheOptions | undefined;
19
21
  traceOptions?: NodeFileTraceOptions | undefined;
20
22
  }) => Promise<void>;
@@ -33,10 +33,16 @@ export declare const readDirRecursive: (dir: string, options?: ReadDirOptions) =
33
33
  export declare const isFile: (file: string) => Promise<boolean>;
34
34
  export declare const findEntryFiles: (rootDir: string, entryFilter?: ((filePath: string) => boolean) | undefined) => Promise<string[]>;
35
35
  export declare const findPackageParents: (pkg: TracedPackage, version: string, tracedFiles: Record<string, TracedFile>) => string[];
36
- export declare const traceFiles: ({ entryFiles, serverRootDir, base, traceOptions, }: {
36
+ export interface CacheOptions {
37
+ fileCache: boolean;
38
+ analysisCache: boolean;
39
+ cacheDir: string;
40
+ }
41
+ export declare const traceFiles: ({ entryFiles, serverRootDir, base, cacheOptions, traceOptions, }: {
37
42
  entryFiles: string[];
38
43
  serverRootDir: string;
39
44
  base?: string | undefined;
45
+ cacheOptions: CacheOptions;
40
46
  traceOptions?: NodeFileTraceOptions | undefined;
41
47
  }) => Promise<import("@vercel/nft").NodeFileTraceResult>;
42
48
  export declare const resolveTracedPath: (base: string, p: string) => Promise<string>;
@@ -0,0 +1,2 @@
1
+ declare function _default(request: any, context: any): Promise<any>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare function _exports(req: any, res: any): Promise<any>;
2
+ export = _exports;
@@ -9,9 +9,4 @@ export declare const buildServerConfig: ({ appDirectory, distDirectory, configFi
9
9
  options?: Parameters<typeof bundle>[1];
10
10
  watch?: boolean | undefined;
11
11
  }) => Promise<void>;
12
- /**
13
- *
14
- * 处理循环引用的 replacer
15
- */
16
- export declare const safeReplacer: () => (key: string, value: unknown) => unknown;
17
12
  export declare const emitResolvedConfig: (appDirectory: string, resolvedConfig: AppNormalizedConfig<'shared'>) => Promise<void>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.57.2-alpha.0",
18
+ "version": "2.58.1-alpha.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -77,43 +77,45 @@
77
77
  "@babel/parser": "^7.22.15",
78
78
  "@babel/traverse": "^7.23.2",
79
79
  "@babel/types": "^7.24.7",
80
- "@rsbuild/plugin-node-polyfill": "1.0.3",
81
- "@rsbuild/core": "1.0.1-beta.9",
80
+ "@rsbuild/core": "1.0.1-beta.10",
81
+ "@rsbuild/plugin-node-polyfill": "1.0.4",
82
82
  "@swc/helpers": "0.5.3",
83
+ "@ungap/structured-clone": "^1.2.0",
83
84
  "@vercel/nft": "^0.26.4",
84
85
  "es-module-lexer": "^1.1.0",
85
86
  "esbuild": "0.17.19",
86
87
  "esbuild-register": "^3.5.0",
88
+ "flatted": "^3.2.9",
87
89
  "mlly": "^1.6.1",
88
90
  "pkg-types": "^1.1.0",
89
91
  "std-env": "^3.7.0",
90
- "@modern-js/core": "2.57.1",
91
- "@modern-js/node-bundle-require": "2.57.1",
92
- "@modern-js/plugin-data-loader": "2.57.1",
93
- "@modern-js/plugin-i18n": "2.57.1",
94
- "@modern-js/plugin": "2.57.1",
95
- "@modern-js/rsbuild-plugin-esbuild": "2.57.1",
96
- "@modern-js/server": "2.57.1",
97
- "@modern-js/plugin-lint": "2.57.1",
98
- "@modern-js/server-core": "2.57.1",
99
- "@modern-js/server-utils": "2.57.1",
100
- "@modern-js/types": "2.57.1",
101
- "@modern-js/utils": "2.57.1",
102
- "@modern-js/prod-server": "2.57.1",
103
- "@modern-js/uni-builder": "2.57.1"
92
+ "@modern-js/core": "2.58.0",
93
+ "@modern-js/node-bundle-require": "2.58.0",
94
+ "@modern-js/plugin": "2.58.0",
95
+ "@modern-js/plugin-i18n": "2.58.0",
96
+ "@modern-js/plugin-lint": "2.58.0",
97
+ "@modern-js/server-core": "2.58.0",
98
+ "@modern-js/rsbuild-plugin-esbuild": "2.58.0",
99
+ "@modern-js/types": "2.58.0",
100
+ "@modern-js/server": "2.58.0",
101
+ "@modern-js/utils": "2.58.0",
102
+ "@modern-js/uni-builder": "2.58.0",
103
+ "@modern-js/prod-server": "2.58.0",
104
+ "@modern-js/server-utils": "2.58.0",
105
+ "@modern-js/plugin-data-loader": "2.58.0"
104
106
  },
105
107
  "devDependencies": {
106
- "@rsbuild/plugin-swc": "1.0.1-beta.9",
108
+ "@rsbuild/plugin-swc": "1.0.1-beta.10",
107
109
  "@types/babel__traverse": "7.18.5",
108
110
  "@types/jest": "^29",
109
- "@types/node": "^16",
111
+ "@types/node": "^14",
110
112
  "jest": "^29",
111
113
  "ts-node": "^10.9.1",
112
114
  "tsconfig-paths": "^4.2.0",
113
115
  "typescript": "^5",
114
116
  "webpack": "^5.93.0",
115
- "@scripts/jest-config": "2.57.1",
116
- "@scripts/build": "2.57.1"
117
+ "@scripts/build": "2.58.0",
118
+ "@scripts/jest-config": "2.58.0"
117
119
  },
118
120
  "sideEffects": false,
119
121
  "publishConfig": {
@@ -1,20 +0,0 @@
1
- import { pathToFileURL } from 'url';
2
- import { createMatchPath } from './utils.mjs';
3
-
4
- let matchPath;
5
- export async function initialize({ appDir, alias, tsconfigPath }) {
6
- matchPath = createMatchPath({
7
- alias,
8
- appDir,
9
- tsconfigPath,
10
- });
11
- }
12
-
13
- export function resolve(specifier, context, defaultResolve) {
14
- const match = matchPath(specifier);
15
- return match
16
- ? defaultResolve(pathToFileURL(match).href, context)
17
- : defaultResolve(specifier, context);
18
- }
19
-
20
- export { load } from 'esbuild-register/loader';
@@ -1,65 +0,0 @@
1
- import path from 'node:path';
2
- import { fs, readTsConfigByFile } from '@modern-js/utils';
3
-
4
- const checkDep = async dep => {
5
- try {
6
- await import(dep);
7
- return true;
8
- } catch (error) {
9
- return false;
10
- }
11
- };
12
-
13
- export const registerEsm = async ({ appDir, distDir, alias }) => {
14
- const nodeVersion = process.versions.node;
15
- const versionArr = nodeVersion.split('.').map(Number);
16
- if (versionArr[0] < 18 || (versionArr[0] === 18 && versionArr[1] < 19)) {
17
- throw new Error(
18
- `The node version of the esm project must be greater than 18.19.0, current version is ${nodeVersion}`,
19
- );
20
- }
21
- const hasTsNode = await checkDep('ts-node');
22
- const TS_CONFIG_FILENAME = `tsconfig.json`;
23
- const tsconfigPath = path.resolve(appDir, TS_CONFIG_FILENAME);
24
- const hasTsconfig = await fs.pathExists(tsconfigPath);
25
- const { register } = await import('node:module');
26
- if (hasTsNode && hasTsconfig) {
27
- // These can be overridden by ts-node options in tsconfig.json
28
- process.env.TS_NODE_TRANSPILE_ONLY = true;
29
- process.env.TS_NODE_PROJECT = tsconfigPath;
30
- process.env.TS_NODE_SCOPE = true;
31
- process.env.TS_NODE_FILES = true;
32
- process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${path.relative(
33
- appDir,
34
- distDir,
35
- )}/`;
36
- register('./ts-node-loader.mjs', import.meta.url, {
37
- data: {
38
- appDir,
39
- distDir,
40
- alias,
41
- tsconfigPath,
42
- },
43
- });
44
- } else {
45
- process.env.MODERN_NODE_LOADER = 'esbuild';
46
- let tsConfig = {};
47
- if (hasTsconfig) {
48
- tsConfig = readTsConfigByFile(tsconfigPath);
49
- }
50
- const esbuildRegister = await import('esbuild-register/dist/node');
51
- esbuildRegister.register({
52
- tsconfigRaw: hasTsconfig ? tsConfig : undefined,
53
- hookIgnoreNodeModules: true,
54
- hookMatcher: fileName => !fileName.startsWith(distDir),
55
- });
56
- register('./esbuild-loader.mjs', import.meta.url, {
57
- data: {
58
- appDir,
59
- distDir,
60
- alias,
61
- tsconfigPath,
62
- },
63
- });
64
- }
65
- };
@@ -1,21 +0,0 @@
1
- import { pathToFileURL } from 'url';
2
- import { resolve as tsNodeResolve } from 'ts-node/esm';
3
- import { createMatchPath } from './utils.mjs';
4
-
5
- let matchPath;
6
- export async function initialize({ appDir, alias, tsconfigPath }) {
7
- matchPath = createMatchPath({
8
- alias,
9
- appDir,
10
- tsconfigPath,
11
- });
12
- }
13
-
14
- export function resolve(specifier, context, defaultResolve) {
15
- const match = matchPath(specifier);
16
- return match
17
- ? tsNodeResolve(pathToFileURL(match).href, context, defaultResolve)
18
- : tsNodeResolve(specifier, context, defaultResolve);
19
- }
20
-
21
- export { transformSource, load } from 'ts-node/esm';
@@ -1,43 +0,0 @@
1
- import path from 'path';
2
- import { createRequire } from 'module';
3
- import tsConfigPaths from '@modern-js/utils/tsconfig-paths';
4
- import { getAliasConfig } from '@modern-js/utils';
5
-
6
- const require = createRequire(import.meta.url);
7
- export function createMatchPath({ alias, appDir, tsconfigPath }) {
8
- const aliasConfig = getAliasConfig(alias, {
9
- appDirectory: appDir,
10
- tsconfigPath,
11
- });
12
-
13
- const { paths = {}, absoluteBaseUrl = './' } = aliasConfig;
14
-
15
- const tsPaths = Object.keys(paths).reduce((o, key) => {
16
- let tsPath = paths[key];
17
- // Do some special handling for Modern.js's internal alias, we can drop it in the next version
18
- if (
19
- typeof tsPath === 'string' &&
20
- key.startsWith('@') &&
21
- tsPath.startsWith('@')
22
- ) {
23
- try {
24
- tsPath = require.resolve(tsPath, {
25
- paths: [appDir],
26
- });
27
- } catch {}
28
- }
29
-
30
- if (typeof tsPath === 'string' && path.isAbsolute(tsPath)) {
31
- tsPath = path.relative(absoluteBaseUrl, tsPath);
32
- }
33
- if (typeof tsPath === 'string') {
34
- tsPath = [tsPath];
35
- }
36
- return {
37
- ...o,
38
- [`${key}`]: tsPath,
39
- };
40
- }, {});
41
-
42
- return tsConfigPaths.createMatchPath(absoluteBaseUrl, tsPaths);
43
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- const { handler } = require("./netlify-handler");
3
- module.exports.default = handler;
@@ -1 +0,0 @@
1
- export { handler as default } from './netlify-handler.cjs';