@modern-js/app-tools 2.57.0 → 2.57.1-alpha.1

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.
Files changed (57) 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 +19 -0
  5. package/dist/cjs/commands/dev.js +9 -0
  6. package/dist/cjs/commands/index.js +8 -8
  7. package/dist/cjs/esm/esbuild-loader.mjs +20 -0
  8. package/dist/cjs/esm/register-esm.mjs +65 -0
  9. package/dist/cjs/esm/ts-node-loader.mjs +21 -0
  10. package/dist/cjs/esm/utils.mjs +28 -0
  11. package/dist/cjs/index.js +1 -1
  12. package/dist/cjs/plugins/analyze/index.js +3 -3
  13. package/dist/cjs/plugins/deploy/dependencies/index.js +1 -0
  14. package/dist/cjs/plugins/deploy/dependencies/utils.js +12 -1
  15. package/dist/cjs/plugins/deploy/platforms/netlify-entry-cjs.js +1 -0
  16. package/dist/cjs/plugins/deploy/platforms/netlify-entry-mjs.js +10 -0
  17. package/dist/cjs/plugins/deploy/platforms/netlify.js +9 -2
  18. package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +26 -0
  19. package/dist/cjs/plugins/deploy/platforms/node.js +9 -2
  20. package/dist/cjs/utils/loadPlugins.js +1 -1
  21. package/dist/cjs/utils/register.js +38 -22
  22. package/dist/esm/builder/generator/getBuilderEnvironments.js +0 -2
  23. package/dist/esm/builder/generator/index.js +1 -1
  24. package/dist/esm/builder/index.js +2 -2
  25. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +1 -1
  26. package/dist/esm/commands/build.js +9 -16
  27. package/dist/esm/commands/dev.js +37 -55
  28. package/dist/esm/commands/index.js +6 -6
  29. package/dist/esm/custom-loader.mjs +41 -0
  30. package/dist/esm/index.js +42 -1
  31. package/dist/esm/plugins/analyze/index.js +4 -3
  32. package/dist/esm/plugins/deploy/dependencies/index.js +2 -3
  33. package/dist/esm/register-esm.mjs +22 -0
  34. package/dist/esm/utils/createServer.js +1 -1
  35. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +1 -1
  36. package/dist/esm-node/builder/generator/index.js +1 -1
  37. package/dist/esm-node/builder/index.js +2 -2
  38. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +1 -1
  39. package/dist/esm-node/commands/build.js +0 -3
  40. package/dist/esm-node/commands/dev.js +16 -24
  41. package/dist/esm-node/commands/index.js +6 -6
  42. package/dist/esm-node/esm/esbuild-loader.js +39 -0
  43. package/dist/esm-node/esm/register-esm.js +39 -0
  44. package/dist/esm-node/esm/ts-node-loader.js +42 -0
  45. package/dist/esm-node/index.js +17 -1
  46. package/dist/esm-node/plugins/analyze/index.js +4 -3
  47. package/dist/esm-node/plugins/deploy/dependencies/index.js +1 -2
  48. package/dist/esm-node/utils/createServer.js +1 -1
  49. package/dist/types/builder/index.d.ts +1 -1
  50. package/dist/types/esm/esbuild-loader.d.mts +6 -0
  51. package/dist/types/esm/register-esm.d.mts +5 -0
  52. package/dist/types/esm/ts-node-loader.d.mts +6 -0
  53. package/dist/types/esm/utils.d.mts +6 -0
  54. package/dist/types/plugins/deploy/platforms/netlify-entry-cjs.d.ts +0 -0
  55. package/dist/types/plugins/deploy/platforms/netlify-entry-mjs.d.ts +1 -0
  56. package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +1 -2
  57. package/package.json +8 -8
@@ -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)
@@ -8,7 +8,6 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
8
8
  const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
9
9
  const fileTrace = await traceFiles(entryFiles.concat(includeEntries), serverRootDir, base);
10
10
  const currentProjectModules = path.join(appDir, "node_modules");
11
- const dependencySearchRoot = path.resolve(appDir, "../../../../../../");
12
11
  const tracedFiles = Object.fromEntries(await Promise.all([
13
12
  ...fileTrace.reasons.entries()
14
13
  ].map(async ([_path, reasons]) => {
@@ -39,7 +38,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
39
38
  const packageJsonPath = match ? path.join(match[0], "package.json") : await pkgUp({
40
39
  cwd: path.dirname(filePath)
41
40
  });
42
- if (packageJsonPath === null || packageJsonPath === void 0 ? void 0 : packageJsonPath.startsWith(dependencySearchRoot)) {
41
+ if (packageJsonPath) {
43
42
  const packageJson = await fse.readJSON(packageJsonPath);
44
43
  pkgPath = baseDir = path.dirname(packageJsonPath);
45
44
  subpath = path.relative(baseDir, filePath);
@@ -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 +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';
@@ -1,2 +1 @@
1
- declare function _default(request: any, context: any): Promise<any>;
2
- export default _default;
1
+ export function createHandler(): Promise<any>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.57.0",
18
+ "version": "2.57.1-alpha.1",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -90,30 +90,30 @@
90
90
  "@modern-js/core": "2.57.0",
91
91
  "@modern-js/node-bundle-require": "2.57.0",
92
92
  "@modern-js/plugin": "2.57.0",
93
- "@modern-js/plugin-data-loader": "2.57.0",
94
93
  "@modern-js/plugin-i18n": "2.57.0",
95
- "@modern-js/plugin-lint": "2.57.0",
96
94
  "@modern-js/prod-server": "2.57.0",
97
95
  "@modern-js/rsbuild-plugin-esbuild": "2.57.0",
98
- "@modern-js/server-utils": "2.57.0",
99
96
  "@modern-js/server": "2.57.0",
97
+ "@modern-js/plugin-lint": "2.57.0",
100
98
  "@modern-js/server-core": "2.57.0",
99
+ "@modern-js/server-utils": "2.57.0",
101
100
  "@modern-js/types": "2.57.0",
101
+ "@modern-js/utils": "2.57.0",
102
102
  "@modern-js/uni-builder": "2.57.0",
103
- "@modern-js/utils": "2.57.0"
103
+ "@modern-js/plugin-data-loader": "2.57.0"
104
104
  },
105
105
  "devDependencies": {
106
106
  "@rsbuild/plugin-swc": "1.0.1-beta.3",
107
107
  "@types/babel__traverse": "7.18.5",
108
108
  "@types/jest": "^29",
109
- "@types/node": "^14",
109
+ "@types/node": "^16",
110
110
  "jest": "^29",
111
111
  "ts-node": "^10.9.1",
112
112
  "tsconfig-paths": "^4.2.0",
113
113
  "typescript": "^5",
114
114
  "webpack": "^5.93.0",
115
- "@scripts/jest-config": "2.57.0",
116
- "@scripts/build": "2.57.0"
115
+ "@scripts/build": "2.57.0",
116
+ "@scripts/jest-config": "2.57.0"
117
117
  },
118
118
  "sideEffects": false,
119
119
  "publishConfig": {