@modern-js/app-tools 2.54.6 → 2.56.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. package/dist/cjs/builder/generator/getBuilderEnvironments.js +84 -0
  2. package/dist/cjs/builder/generator/index.js +6 -5
  3. package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +7 -14
  4. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +8 -8
  5. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +6 -8
  6. package/dist/cjs/builder/shared/builderPlugins/adapterWorker.js +5 -3
  7. package/dist/cjs/commands/index.js +2 -2
  8. package/dist/cjs/commands/inspect.js +1 -2
  9. package/dist/cjs/commands/serve.js +1 -0
  10. package/dist/cjs/config/default.js +2 -2
  11. package/dist/cjs/config/legacy/createSourceConfig.js +2 -1
  12. package/dist/cjs/config/legacy/index.js +1 -0
  13. package/dist/cjs/hooks.js +2 -5
  14. package/dist/cjs/plugins/analyze/constants.js +3 -18
  15. package/dist/cjs/plugins/analyze/getBundleEntry.js +2 -1
  16. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +36 -11
  17. package/dist/cjs/plugins/analyze/index.js +7 -64
  18. package/dist/cjs/plugins/analyze/templates.js +2 -55
  19. package/dist/cjs/plugins/analyze/utils.js +0 -86
  20. package/dist/esm/builder/generator/{createBuilderOptions.js → getBuilderEnvironments.js} +43 -7
  21. package/dist/esm/builder/generator/index.js +9 -9
  22. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +7 -14
  23. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +8 -8
  24. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +6 -8
  25. package/dist/esm/builder/shared/builderPlugins/adapterWorker.js +6 -4
  26. package/dist/esm/commands/index.js +1 -1
  27. package/dist/esm/commands/inspect.js +1 -2
  28. package/dist/esm/commands/serve.js +1 -0
  29. package/dist/esm/config/default.js +2 -5
  30. package/dist/esm/config/legacy/createSourceConfig.js +2 -1
  31. package/dist/esm/config/legacy/index.js +1 -0
  32. package/dist/esm/hooks.js +2 -5
  33. package/dist/esm/plugins/analyze/constants.js +2 -12
  34. package/dist/esm/plugins/analyze/getBundleEntry.js +2 -1
  35. package/dist/esm/plugins/analyze/getFileSystemEntry.js +57 -14
  36. package/dist/esm/plugins/analyze/index.js +25 -128
  37. package/dist/esm/plugins/analyze/templates.js +1 -17
  38. package/dist/esm/plugins/analyze/utils.js +1 -87
  39. package/dist/esm-node/builder/generator/getBuilderEnvironments.js +60 -0
  40. package/dist/esm-node/builder/generator/index.js +6 -5
  41. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +7 -14
  42. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +7 -7
  43. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +5 -7
  44. package/dist/esm-node/builder/shared/builderPlugins/adapterWorker.js +5 -3
  45. package/dist/esm-node/commands/index.js +1 -1
  46. package/dist/esm-node/commands/inspect.js +1 -2
  47. package/dist/esm-node/commands/serve.js +1 -0
  48. package/dist/esm-node/config/default.js +2 -2
  49. package/dist/esm-node/config/legacy/createSourceConfig.js +2 -1
  50. package/dist/esm-node/config/legacy/index.js +1 -0
  51. package/dist/esm-node/hooks.js +2 -5
  52. package/dist/esm-node/plugins/analyze/constants.js +2 -12
  53. package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -1
  54. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +37 -12
  55. package/dist/esm-node/plugins/analyze/index.js +10 -67
  56. package/dist/esm-node/plugins/analyze/templates.js +1 -52
  57. package/dist/esm-node/plugins/analyze/utils.js +1 -86
  58. package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
  59. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +5 -0
  60. package/dist/types/builder/generator/index.d.ts +1 -2
  61. package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +1 -1
  62. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +1 -1
  63. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +1 -1
  64. package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +1 -1
  65. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -1
  66. package/dist/types/commands/inspect.d.ts +1 -1
  67. package/dist/types/plugins/analyze/constants.d.ts +1 -6
  68. package/dist/types/plugins/analyze/templates.d.ts +0 -14
  69. package/dist/types/plugins/analyze/utils.d.ts +0 -11
  70. package/dist/types/types/config/index.d.ts +2 -0
  71. package/dist/types/types/config/source.d.ts +11 -0
  72. package/dist/types/types/hooks.d.ts +7 -27
  73. package/dist/types/types/index.d.ts +1 -1
  74. package/dist/types/types/legacyConfig/output.d.ts +1 -1
  75. package/dist/types/types/legacyConfig/source.d.ts +4 -0
  76. package/dist/types/utils/register.d.ts +1 -1
  77. package/package.json +22 -23
  78. package/dist/cjs/builder/generator/createBuilderOptions.js +0 -50
  79. package/dist/cjs/builder/generator/getBuilderTargets.js +0 -42
  80. package/dist/cjs/plugins/analyze/generateCode.js +0 -185
  81. package/dist/esm/builder/generator/getBuilderTargets.js +0 -18
  82. package/dist/esm/plugins/analyze/generateCode.js +0 -296
  83. package/dist/esm-node/builder/generator/createBuilderOptions.js +0 -26
  84. package/dist/esm-node/builder/generator/getBuilderTargets.js +0 -18
  85. package/dist/esm-node/plugins/analyze/generateCode.js +0 -149
  86. package/dist/types/builder/generator/createBuilderOptions.d.ts +0 -4
  87. package/dist/types/builder/generator/getBuilderTargets.d.ts +0 -3
  88. package/dist/types/plugins/analyze/generateCode.d.ts +0 -16
@@ -1,4 +1,4 @@
1
- import { RsbuildPlugin } from '@rsbuild/shared';
1
+ import { RsbuildPlugin } from '@rsbuild/core';
2
2
  import type { Bundler } from '../../../types';
3
3
  import type { BuilderOptions } from '../types';
4
4
  export declare const builderPluginAdapterSSR: <B extends Bundler>(options: BuilderOptions<B>) => RsbuildPlugin;
@@ -1,2 +1,2 @@
1
- import { RsbuildPlugin } from '@rsbuild/shared';
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
2
  export declare const builderPluginAdapterWorker: () => RsbuildPlugin;
@@ -1,5 +1,5 @@
1
1
  import type { Rspack, webpack, HtmlWebpackPlugin } from '@modern-js/uni-builder';
2
- import type { ScriptLoading } from '@rsbuild/shared';
2
+ import type { ScriptLoading } from '@rsbuild/core';
3
3
  export interface RouteAssets {
4
4
  [routeId: string]: {
5
5
  chunkIds?: (string | number)[];
@@ -1,4 +1,4 @@
1
1
  import type { PluginAPI } from '@modern-js/core';
2
2
  import type { InspectOptions } from '../utils/types';
3
3
  import type { AppTools } from '../types';
4
- export declare const inspect: (api: PluginAPI<AppTools<'shared'>>, options: InspectOptions) => Promise<import("@rsbuild/shared").InspectConfigResult<"rspack">>;
4
+ export declare const inspect: (api: PluginAPI<AppTools<'shared'>>, options: InspectOptions) => Promise<import("@rsbuild/core").InspectConfigResult<"rspack">>;
@@ -1,9 +1,4 @@
1
1
  export declare const INDEX_FILE_NAME = "index";
2
- export declare const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
3
- export declare const ENTRY_POINT_FILE_NAME = "index.jsx";
4
- export declare const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
2
+ export declare const ENTRY_FILE_NAME = "entry";
5
3
  export declare const HTML_PARTIALS_FOLDER = "html";
6
4
  export declare const HTML_PARTIALS_EXTENSIONS: string[];
7
- export declare const APP_CONFIG_NAME = "config";
8
- export declare const APP_INIT_EXPORTED = "init";
9
- export declare const APP_INIT_IMPORTED = "appInit";
@@ -1,17 +1,3 @@
1
- import type { Entrypoint } from '@modern-js/types';
2
- import type { RuntimePlugin } from '../../types';
3
- export declare const index: ({ mountId, imports, renderFunction, exportStatement, }: {
4
- mountId: string;
5
- imports: string;
6
- exportStatement: string;
7
- renderFunction: string;
8
- }) => string;
9
- export declare const renderFunction: ({ plugins, customBootstrap, fileSystemRoutes, customRuntimeConfig, }: {
10
- plugins: RuntimePlugin[];
11
- customBootstrap?: string | false | undefined;
12
- customRuntimeConfig?: string | false | undefined;
13
- fileSystemRoutes: Entrypoint['fileSystemRoutes'];
14
- }) => string;
15
1
  export declare const html: (partials: {
16
2
  top: string[];
17
3
  head: string[];
@@ -1,15 +1,4 @@
1
- import type { Entrypoint } from '@modern-js/types';
2
- import type { ImportStatement } from '../../types';
3
1
  export declare const walkDirectory: (dir: string) => string[];
4
- export declare const getDefaultImports: ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias, runtimeConfigFile, customRuntimeConfig, }: {
5
- entrypoint: Entrypoint;
6
- srcDirectory: string;
7
- appDirectory: string;
8
- internalSrcAlias: string;
9
- internalDirAlias: string;
10
- runtimeConfigFile: string | false;
11
- customRuntimeConfig: string | false;
12
- }) => ImportStatement[];
13
2
  export declare const replaceWithAlias: (base: string, filePath: string, alias: string) => string;
14
3
  export declare const parseModule: ({ source, filename, }: {
15
4
  source: string;
@@ -1,5 +1,6 @@
1
1
  import type { ServerUserConfig, BffUserConfig } from '@modern-js/server-core';
2
2
  import type { UniBuilderPlugin } from '@modern-js/uni-builder';
3
+ import type { RsbuildConfig } from '@rsbuild/core';
3
4
  import type { Bundler } from '../utils';
4
5
  import type { OutputUserConfig } from './output';
5
6
  import type { SourceUserConfig } from './source';
@@ -40,6 +41,7 @@ export interface AppToolsUserConfig<B extends Bundler> {
40
41
  builderPlugins?: UniBuilderPlugin[];
41
42
  performance?: PerformanceUserConfig;
42
43
  devtools?: any;
44
+ environments?: RsbuildConfig['environments'];
43
45
  }
44
46
  interface SharedNormalizedConfig<RawConfig> {
45
47
  cliOptions?: Record<string, any>;
@@ -9,9 +9,15 @@ export type Entry = string | {
9
9
  */
10
10
  disableMount?: boolean;
11
11
  /**
12
+ * @deprecated
13
+ * Using customEntry instead.
12
14
  * Specify the file path of custom bootstrap.
13
15
  */
14
16
  customBootstrap?: string;
17
+ /**
18
+ * use src/{entryName}/entry.tsx to custom entry
19
+ */
20
+ customEntry?: boolean;
15
21
  };
16
22
  export type Entries = Record<string, Entry>;
17
23
  export interface SourceUserConfig extends NonNullable<UniBuilderConfig['source']> {
@@ -30,6 +36,11 @@ export interface SourceUserConfig extends NonNullable<UniBuilderConfig['source']
30
36
  * @default false
31
37
  */
32
38
  enableAsyncEntry?: boolean;
39
+ /**
40
+ * Enable use entry.tsx to custom entry
41
+ * @default false
42
+ */
43
+ enableCustomEntry?: boolean;
33
44
  /**
34
45
  * Used to disable the functionality of automatically identifying page entry points based on directory structure.
35
46
  * @default false
@@ -1,44 +1,21 @@
1
1
  import type { AsyncWaterfall, AsyncWorkflow, ParallelWorkflow } from '@modern-js/plugin';
2
2
  import type { Entrypoint, HtmlPartials, NestedRouteForCli, PageRoute, RouteLegacy, ServerPlugin, ServerRoute } from '@modern-js/types';
3
3
  import type { RegisterBuildPlatformResult, DevToolData } from '@modern-js/core';
4
- import type { Stats, MultiStats } from '@rsbuild/shared';
5
- import type { Rspack, webpack } from '@modern-js/uni-builder';
4
+ import type { Rspack, webpack, Stats, MultiStats } from '@modern-js/uni-builder';
6
5
  import { Bundler } from './utils';
7
6
  export interface ImportSpecifier {
8
7
  local?: string;
9
8
  imported?: string;
10
9
  }
11
- export interface ImportStatement {
12
- specifiers: ImportSpecifier[];
13
- value: string;
14
- initialize?: string;
15
- }
16
10
  export interface RuntimePlugin {
17
11
  name: string;
18
- options: string;
19
- args?: string;
12
+ path: string;
13
+ config: Record<string, any>;
20
14
  }
21
15
  export type AppToolsHooks<B extends Bundler = 'webpack'> = {
22
- modifyEntryExport: AsyncWaterfall<{
23
- entrypoint: Entrypoint;
24
- exportStatement: string;
25
- }>;
26
- modifyEntryImports: AsyncWaterfall<{
27
- imports: ImportStatement[];
28
- entrypoint: Entrypoint;
29
- }>;
30
- modifyEntryRuntimePlugins: AsyncWaterfall<{
16
+ _internalRuntimePlugins: AsyncWaterfall<{
31
17
  entrypoint: Entrypoint;
32
18
  plugins: RuntimePlugin[];
33
- bundlerConfigs?: B extends 'rspack' ? Rspack.Configuration[] : webpack.Configuration[];
34
- }>;
35
- modifyEntryRenderFunction: AsyncWaterfall<{
36
- entrypoint: Entrypoint;
37
- code: string;
38
- }>;
39
- modifyAsyncEntry: AsyncWaterfall<{
40
- entrypoint: Entrypoint;
41
- code: string;
42
19
  }>;
43
20
  modifyFileSystemRoutes: AsyncWaterfall<{
44
21
  entrypoint: Entrypoint;
@@ -54,6 +31,9 @@ export type AppToolsHooks<B extends Bundler = 'webpack'> = {
54
31
  path: string;
55
32
  entry: false | string;
56
33
  }>;
34
+ generateEntryCode: AsyncWorkflow<{
35
+ entrypoints: Entrypoint[];
36
+ }, void>;
57
37
  htmlPartials: AsyncWaterfall<{
58
38
  entrypoint: Entrypoint;
59
39
  partials: HtmlPartials;
@@ -8,7 +8,7 @@ export * from './config';
8
8
  export * from './legacyConfig';
9
9
  export type { webpack, Rspack } from '@modern-js/uni-builder';
10
10
  export type { Bundler } from './utils';
11
- export type { ServerUserConfig, ServerNormalizedConfig, BffUserConfig, BffNormalizedConfig, SSR, SSRByEntries, } from '@modern-js/server-core';
11
+ export type { ServerUserConfig, ServerNormalizedConfig, BffUserConfig, BffNormalizedConfig, SSR, SSRByEntries, Resource, Params, RequestHandlerConfig, LoaderContext, OnError, OnTiming, RequestHandlerOptions, RequestHandler, } from '@modern-js/server-core';
12
12
  export type { IAppContext, PluginAPI, CliPlugin, NormalizedConfig, UserConfig, } from '@modern-js/core';
13
13
  export type AppTools<B extends Bundler = 'webpack'> = {
14
14
  hooks: AppToolsHooks<B>;
@@ -1,4 +1,4 @@
1
- import type { MetaOptions } from '@rsbuild/shared';
1
+ import type { MetaOptions } from '@modern-js/uni-builder';
2
2
  import type { SSGConfig } from '../config';
3
3
  type CrossOrigin = 'anonymous' | 'use-credentials';
4
4
  export type OutputLegacyUserConfig = {
@@ -8,6 +8,10 @@ export type SourceLegacyUserConfig = {
8
8
  mainEntryName?: string;
9
9
  preEntry?: string | string[];
10
10
  enableAsyncEntry?: boolean;
11
+ /**
12
+ * support entry.tsx entry
13
+ */
14
+ enableCustomEntry?: boolean;
11
15
  disableDefaultEntries?: boolean;
12
16
  entriesDir?: string;
13
17
  configDir?: string;
@@ -1,3 +1,3 @@
1
1
  import { Alias } from '@modern-js/utils';
2
- import { ConfigChain } from '@rsbuild/shared';
2
+ import type { ConfigChain } from '@rsbuild/core';
3
3
  export declare const registerCompiler: (appDir: string | undefined, distDir: string, alias?: ConfigChain<Alias>) => Promise<void>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.54.6",
18
+ "version": "2.56.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -76,10 +76,9 @@
76
76
  "dependencies": {
77
77
  "@babel/parser": "^7.22.15",
78
78
  "@babel/traverse": "^7.23.2",
79
- "@babel/types": "^7.23.0",
80
- "@rsbuild/plugin-node-polyfill": "0.7.10",
81
- "@rsbuild/shared": "0.7.10",
82
- "@rsbuild/core": "0.7.10",
79
+ "@babel/types": "^7.24.7",
80
+ "@rsbuild/plugin-node-polyfill": "1.0.3",
81
+ "@rsbuild/core": "1.0.1-beta.3",
83
82
  "@swc/helpers": "0.5.3",
84
83
  "@vercel/nft": "^0.26.4",
85
84
  "es-module-lexer": "^1.1.0",
@@ -88,23 +87,23 @@
88
87
  "mlly": "^1.6.1",
89
88
  "pkg-types": "^1.1.0",
90
89
  "std-env": "^3.7.0",
91
- "@modern-js/node-bundle-require": "2.54.6",
92
- "@modern-js/core": "2.54.6",
93
- "@modern-js/plugin": "2.54.6",
94
- "@modern-js/plugin-data-loader": "2.54.6",
95
- "@modern-js/plugin-i18n": "2.54.6",
96
- "@modern-js/prod-server": "2.54.6",
97
- "@modern-js/plugin-lint": "2.54.6",
98
- "@modern-js/rsbuild-plugin-esbuild": "2.54.6",
99
- "@modern-js/server": "2.54.6",
100
- "@modern-js/types": "2.54.6",
101
- "@modern-js/server-core": "2.54.6",
102
- "@modern-js/server-utils": "2.54.6",
103
- "@modern-js/uni-builder": "2.54.6",
104
- "@modern-js/utils": "2.54.6"
90
+ "@modern-js/core": "2.56.0",
91
+ "@modern-js/node-bundle-require": "2.56.0",
92
+ "@modern-js/plugin": "2.56.0",
93
+ "@modern-js/plugin-data-loader": "2.56.0",
94
+ "@modern-js/plugin-i18n": "2.56.0",
95
+ "@modern-js/prod-server": "2.56.0",
96
+ "@modern-js/plugin-lint": "2.56.0",
97
+ "@modern-js/rsbuild-plugin-esbuild": "2.56.0",
98
+ "@modern-js/server": "2.56.0",
99
+ "@modern-js/server-core": "2.56.0",
100
+ "@modern-js/server-utils": "2.56.0",
101
+ "@modern-js/uni-builder": "2.56.0",
102
+ "@modern-js/types": "2.56.0",
103
+ "@modern-js/utils": "2.56.0"
105
104
  },
106
105
  "devDependencies": {
107
- "@rsbuild/plugin-swc": "0.7.10",
106
+ "@rsbuild/plugin-swc": "1.0.1-beta.3",
108
107
  "@types/babel__traverse": "7.18.5",
109
108
  "@types/jest": "^29",
110
109
  "@types/node": "^14",
@@ -112,9 +111,9 @@
112
111
  "ts-node": "^10.9.1",
113
112
  "tsconfig-paths": "^4.2.0",
114
113
  "typescript": "^5",
115
- "webpack": "^5.92.0",
116
- "@scripts/jest-config": "2.54.6",
117
- "@scripts/build": "2.54.6"
114
+ "webpack": "^5.93.0",
115
+ "@scripts/build": "2.56.0",
116
+ "@scripts/jest-config": "2.56.0"
118
117
  },
119
118
  "sideEffects": false,
120
119
  "publishConfig": {
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var createBuilderOptions_exports = {};
20
- __export(createBuilderOptions_exports, {
21
- createBuilderOptions: () => createBuilderOptions
22
- });
23
- module.exports = __toCommonJS(createBuilderOptions_exports);
24
- function createBuilderOptions(target, appContext) {
25
- const entries = {};
26
- const { entrypoints = [], checkedEntries } = appContext;
27
- for (const { entryName, internalEntry, entry } of entrypoints) {
28
- if (checkedEntries && !checkedEntries.includes(entryName)) {
29
- continue;
30
- }
31
- const finalEntry = internalEntry || entry;
32
- if (entryName in entries) {
33
- entries[entryName].push(finalEntry);
34
- } else {
35
- entries[entryName] = [
36
- finalEntry
37
- ];
38
- }
39
- }
40
- return {
41
- cwd: appContext.appDirectory,
42
- target,
43
- frameworkConfigPath: appContext.configFile || void 0,
44
- entry: entries
45
- };
46
- }
47
- // Annotate the CommonJS export names for ESM import in node:
48
- 0 && (module.exports = {
49
- createBuilderOptions
50
- });
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var getBuilderTargets_exports = {};
20
- __export(getBuilderTargets_exports, {
21
- getBuilderTargets: () => getBuilderTargets
22
- });
23
- module.exports = __toCommonJS(getBuilderTargets_exports);
24
- var import_utils = require("@modern-js/utils");
25
- function getBuilderTargets(normalizedConfig) {
26
- const targets = [
27
- "web"
28
- ];
29
- const useNodeTarget = (0, import_utils.isProd)() ? (0, import_utils.isUseSSRBundle)(normalizedConfig) : (0, import_utils.isSSR)(normalizedConfig);
30
- if (useNodeTarget) {
31
- targets.push("node");
32
- }
33
- const useWorkerTarget = (0, import_utils.isServiceWorker)(normalizedConfig);
34
- if (useWorkerTarget) {
35
- targets.push("service-worker");
36
- }
37
- return targets;
38
- }
39
- // Annotate the CommonJS export names for ESM import in node:
40
- 0 && (module.exports = {
41
- getBuilderTargets
42
- });
@@ -1,185 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var generateCode_exports = {};
30
- __export(generateCode_exports, {
31
- createImportStatements: () => createImportStatements,
32
- generateCode: () => generateCode,
33
- generateIndexCode: () => generateIndexCode
34
- });
35
- module.exports = __toCommonJS(generateCode_exports);
36
- var import_path = __toESM(require("path"));
37
- var import_utils = require("@modern-js/utils");
38
- var templates = __toESM(require("./templates"));
39
- var import_constants = require("./constants");
40
- var import_utils2 = require("./utils");
41
- const createImportSpecifier = (specifiers) => {
42
- let defaults = "";
43
- const named = [];
44
- for (const { local, imported } of specifiers) {
45
- if (local && imported) {
46
- named.push(`${imported} as ${local}`);
47
- } else if (local) {
48
- defaults = local;
49
- } else {
50
- named.push(imported);
51
- }
52
- }
53
- if (defaults && named.length) {
54
- return `${defaults}, { ${named.join(", ")} }`;
55
- } else if (defaults) {
56
- return defaults;
57
- } else {
58
- return `{ ${named.join(", ")} }`;
59
- }
60
- };
61
- const createImportStatements = (statements) => {
62
- const deDuplicated = [];
63
- const seen = /* @__PURE__ */ new Map();
64
- for (const { value, specifiers, initialize } of statements) {
65
- if (!seen.has(value)) {
66
- deDuplicated.push({
67
- value,
68
- specifiers,
69
- initialize
70
- });
71
- seen.set(value, specifiers);
72
- } else {
73
- var _deDuplicated_modifyIndex;
74
- seen.get(value).push(...specifiers);
75
- const modifyIndex = deDuplicated.findIndex((v) => v.value === value);
76
- var _deDuplicated_modifyIndex_initialize;
77
- const originInitialize = (_deDuplicated_modifyIndex_initialize = (_deDuplicated_modifyIndex = deDuplicated[modifyIndex]) === null || _deDuplicated_modifyIndex === void 0 ? void 0 : _deDuplicated_modifyIndex.initialize) !== null && _deDuplicated_modifyIndex_initialize !== void 0 ? _deDuplicated_modifyIndex_initialize : "";
78
- deDuplicated[modifyIndex].initialize = originInitialize.concat(`
79
- ${initialize || ""}`);
80
- }
81
- }
82
- return deDuplicated.map(({ value, specifiers, initialize }) => `import ${createImportSpecifier(specifiers)} from '${value}';
83
- ${initialize || ""}`).join("\n");
84
- };
85
- const generateCode = async (appContext, config, entrypoints, api) => {
86
- const { internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias, runtimeConfigFile } = appContext;
87
- const hookRunners = api.useHookRunners();
88
- const customRuntimeConfig = (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(srcDirectory, `${runtimeConfigFile}${ext}`)));
89
- const importsStatemets = /* @__PURE__ */ new Map();
90
- await Promise.all(entrypoints.map((entrypoint) => generateEntryCode(entrypoint, customRuntimeConfig)));
91
- return {
92
- importsStatemets
93
- };
94
- async function generateEntryCode(entrypoint, customRuntimeConfig2) {
95
- const { entryName, isAutoMount } = entrypoint;
96
- if (isAutoMount) {
97
- const { imports } = await hookRunners.modifyEntryImports({
98
- entrypoint,
99
- imports: (0, import_utils2.getDefaultImports)({
100
- entrypoint,
101
- srcDirectory,
102
- appDirectory,
103
- internalSrcAlias,
104
- internalDirAlias,
105
- runtimeConfigFile,
106
- customRuntimeConfig: customRuntimeConfig2
107
- })
108
- });
109
- importsStatemets.set(entryName, imports);
110
- const entryFile = import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_POINT_FILE_NAME}`);
111
- entrypoint.internalEntry = entryFile;
112
- }
113
- }
114
- };
115
- const generateIndexCode = async ({ appContext, api, entrypoints, config, importsStatemets, bundlerConfigs }) => {
116
- const hookRunners = api.useHookRunners();
117
- const { mountId } = config.html;
118
- const { internalDirectory, packageName, srcDirectory, runtimeConfigFile } = appContext;
119
- const customRuntimeConfig = (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(srcDirectory, `${runtimeConfigFile}${ext}`)));
120
- await Promise.all(entrypoints.map(async (entrypoint) => {
121
- const { entryName, isMainEntry, isAutoMount, customBootstrap, fileSystemRoutes } = entrypoint;
122
- if (isAutoMount) {
123
- const { plugins } = await hookRunners.modifyEntryRuntimePlugins({
124
- entrypoint,
125
- plugins: [],
126
- bundlerConfigs
127
- });
128
- const { code: renderFunction } = await hookRunners.modifyEntryRenderFunction({
129
- entrypoint,
130
- code: templates.renderFunction({
131
- plugins,
132
- customBootstrap,
133
- customRuntimeConfig,
134
- fileSystemRoutes
135
- })
136
- });
137
- const { exportStatement } = await hookRunners.modifyEntryExport({
138
- entrypoint,
139
- exportStatement: "export default AppWrapper;"
140
- });
141
- const imports = importsStatemets.get(entryName);
142
- const code = templates.index({
143
- mountId,
144
- imports: createImportStatements(imports),
145
- renderFunction,
146
- exportStatement
147
- });
148
- const entryFile = import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_POINT_FILE_NAME}`);
149
- if (config.source.enableAsyncEntry) {
150
- let rawAsyncEntryCode = `import('./${import_constants.ENTRY_BOOTSTRAP_FILE_NAME}');`;
151
- const ssr = (0, import_utils.getEntryOptions)(entryName, isMainEntry, config.server.ssr, config.server.ssrByEntries, packageName);
152
- if (ssr) {
153
- rawAsyncEntryCode = `
154
- export const ${import_utils.SERVER_RENDER_FUNCTION_NAME} = async (...args) => {
155
- let entry = await ${rawAsyncEntryCode};
156
- if (entry.default instanceof Promise){
157
- entry = await entry.default;
158
- return entry.default.${import_utils.SERVER_RENDER_FUNCTION_NAME}.apply(null, args);
159
- }
160
- return entry.${import_utils.SERVER_RENDER_FUNCTION_NAME}.apply(null, args);
161
- };
162
- if(typeof window!=='undefined'){
163
- ${rawAsyncEntryCode}
164
- }
165
- `;
166
- }
167
- const { code: asyncEntryCode } = await hookRunners.modifyAsyncEntry({
168
- entrypoint,
169
- code: rawAsyncEntryCode
170
- });
171
- import_utils.fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
172
- const bootstrapFile = import_path.default.resolve(internalDirectory, `./${entryName}/${import_constants.ENTRY_BOOTSTRAP_FILE_NAME}`);
173
- import_utils.fs.outputFileSync(bootstrapFile, code, "utf8");
174
- } else {
175
- import_utils.fs.outputFileSync(entryFile, code, "utf8");
176
- }
177
- }
178
- }));
179
- };
180
- // Annotate the CommonJS export names for ESM import in node:
181
- 0 && (module.exports = {
182
- createImportStatements,
183
- generateCode,
184
- generateIndexCode
185
- });
@@ -1,18 +0,0 @@
1
- import { isProd, isServiceWorker, isSSR, isUseSSRBundle } from "@modern-js/utils";
2
- function getBuilderTargets(normalizedConfig) {
3
- var targets = [
4
- "web"
5
- ];
6
- var useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
7
- if (useNodeTarget) {
8
- targets.push("node");
9
- }
10
- var useWorkerTarget = isServiceWorker(normalizedConfig);
11
- if (useWorkerTarget) {
12
- targets.push("service-worker");
13
- }
14
- return targets;
15
- }
16
- export {
17
- getBuilderTargets
18
- };