@modern-js/app-tools 2.54.5 → 2.55.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. package/dist/cjs/builder/generator/createBuilderOptions.js +18 -1
  2. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -2
  3. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -2
  4. package/dist/cjs/commands/index.js +2 -2
  5. package/dist/cjs/commands/serve.js +1 -0
  6. package/dist/cjs/config/default.js +2 -0
  7. package/dist/cjs/config/legacy/createSourceConfig.js +2 -1
  8. package/dist/cjs/hooks.js +2 -5
  9. package/dist/cjs/plugins/analyze/constants.js +3 -18
  10. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +36 -11
  11. package/dist/cjs/plugins/analyze/index.js +7 -64
  12. package/dist/cjs/plugins/analyze/templates.js +2 -55
  13. package/dist/cjs/plugins/analyze/utils.js +0 -86
  14. package/dist/esm/builder/generator/createBuilderOptions.js +21 -1
  15. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +1 -1
  16. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +1 -1
  17. package/dist/esm/commands/index.js +1 -1
  18. package/dist/esm/commands/serve.js +1 -0
  19. package/dist/esm/config/default.js +2 -0
  20. package/dist/esm/config/legacy/createSourceConfig.js +2 -1
  21. package/dist/esm/hooks.js +2 -5
  22. package/dist/esm/plugins/analyze/constants.js +2 -12
  23. package/dist/esm/plugins/analyze/getFileSystemEntry.js +57 -14
  24. package/dist/esm/plugins/analyze/index.js +25 -128
  25. package/dist/esm/plugins/analyze/templates.js +1 -17
  26. package/dist/esm/plugins/analyze/utils.js +1 -87
  27. package/dist/esm-node/builder/generator/createBuilderOptions.js +18 -1
  28. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +1 -1
  29. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +1 -1
  30. package/dist/esm-node/commands/index.js +1 -1
  31. package/dist/esm-node/commands/serve.js +1 -0
  32. package/dist/esm-node/config/default.js +2 -0
  33. package/dist/esm-node/config/legacy/createSourceConfig.js +2 -1
  34. package/dist/esm-node/hooks.js +2 -5
  35. package/dist/esm-node/plugins/analyze/constants.js +2 -12
  36. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +37 -12
  37. package/dist/esm-node/plugins/analyze/index.js +10 -67
  38. package/dist/esm-node/plugins/analyze/templates.js +1 -52
  39. package/dist/esm-node/plugins/analyze/utils.js +1 -86
  40. package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
  41. package/dist/types/builder/generator/createBuilderOptions.d.ts +1 -2
  42. package/dist/types/builder/generator/getBuilderTargets.d.ts +1 -1
  43. package/dist/types/builder/generator/index.d.ts +1 -2
  44. package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +1 -1
  45. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +1 -1
  46. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +1 -1
  47. package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +1 -1
  48. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -1
  49. package/dist/types/commands/inspect.d.ts +1 -1
  50. package/dist/types/plugins/analyze/constants.d.ts +1 -6
  51. package/dist/types/plugins/analyze/templates.d.ts +0 -14
  52. package/dist/types/plugins/analyze/utils.d.ts +0 -11
  53. package/dist/types/types/config/source.d.ts +5 -0
  54. package/dist/types/types/hooks.d.ts +7 -27
  55. package/dist/types/types/index.d.ts +1 -1
  56. package/dist/types/types/legacyConfig/output.d.ts +1 -1
  57. package/dist/types/types/legacyConfig/source.d.ts +4 -0
  58. package/dist/types/utils/register.d.ts +1 -1
  59. package/package.json +17 -18
  60. package/dist/cjs/plugins/analyze/generateCode.js +0 -185
  61. package/dist/esm/plugins/analyze/generateCode.js +0 -296
  62. package/dist/esm-node/plugins/analyze/generateCode.js +0 -149
  63. package/dist/types/plugins/analyze/generateCode.d.ts +0 -16
@@ -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.5",
18
+ "version": "2.55.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -78,7 +78,6 @@
78
78
  "@babel/traverse": "^7.23.2",
79
79
  "@babel/types": "^7.23.0",
80
80
  "@rsbuild/plugin-node-polyfill": "0.7.10",
81
- "@rsbuild/shared": "0.7.10",
82
81
  "@rsbuild/core": "0.7.10",
83
82
  "@swc/helpers": "0.5.3",
84
83
  "@vercel/nft": "^0.26.4",
@@ -88,20 +87,20 @@
88
87
  "mlly": "^1.6.1",
89
88
  "pkg-types": "^1.1.0",
90
89
  "std-env": "^3.7.0",
91
- "@modern-js/core": "2.54.5",
92
- "@modern-js/node-bundle-require": "2.54.5",
93
- "@modern-js/plugin-data-loader": "2.54.5",
94
- "@modern-js/plugin-i18n": "2.54.5",
95
- "@modern-js/plugin": "2.54.5",
96
- "@modern-js/prod-server": "2.54.5",
97
- "@modern-js/rsbuild-plugin-esbuild": "2.54.5",
98
- "@modern-js/plugin-lint": "2.54.5",
99
- "@modern-js/server": "2.54.5",
100
- "@modern-js/server-core": "2.54.5",
101
- "@modern-js/server-utils": "2.54.5",
102
- "@modern-js/types": "2.54.5",
103
- "@modern-js/uni-builder": "2.54.5",
104
- "@modern-js/utils": "2.54.5"
90
+ "@modern-js/node-bundle-require": "2.55.0",
91
+ "@modern-js/core": "2.55.0",
92
+ "@modern-js/plugin": "2.55.0",
93
+ "@modern-js/plugin-data-loader": "2.55.0",
94
+ "@modern-js/plugin-i18n": "2.55.0",
95
+ "@modern-js/plugin-lint": "2.55.0",
96
+ "@modern-js/prod-server": "2.55.0",
97
+ "@modern-js/server-core": "2.55.0",
98
+ "@modern-js/server": "2.55.0",
99
+ "@modern-js/server-utils": "2.55.0",
100
+ "@modern-js/rsbuild-plugin-esbuild": "2.55.0",
101
+ "@modern-js/types": "2.55.0",
102
+ "@modern-js/utils": "2.55.0",
103
+ "@modern-js/uni-builder": "2.55.0"
105
104
  },
106
105
  "devDependencies": {
107
106
  "@rsbuild/plugin-swc": "0.7.10",
@@ -113,8 +112,8 @@
113
112
  "tsconfig-paths": "^4.2.0",
114
113
  "typescript": "^5",
115
114
  "webpack": "^5.92.0",
116
- "@scripts/build": "2.54.5",
117
- "@scripts/jest-config": "2.54.5"
115
+ "@scripts/build": "2.55.0",
116
+ "@scripts/jest-config": "2.55.0"
118
117
  },
119
118
  "sideEffects": false,
120
119
  "publishConfig": {
@@ -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,296 +0,0 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
- import path from "path";
5
- import { findExists, fs, getEntryOptions, JS_EXTENSIONS, SERVER_RENDER_FUNCTION_NAME } from "@modern-js/utils";
6
- import * as templates from "./templates";
7
- import { ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
8
- import { getDefaultImports } from "./utils";
9
- var createImportSpecifier = function(specifiers) {
10
- var defaults = "";
11
- var named = [];
12
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
13
- try {
14
- for (var _iterator = specifiers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
15
- var _step_value = _step.value, local = _step_value.local, imported = _step_value.imported;
16
- if (local && imported) {
17
- named.push("".concat(imported, " as ").concat(local));
18
- } else if (local) {
19
- defaults = local;
20
- } else {
21
- named.push(imported);
22
- }
23
- }
24
- } catch (err) {
25
- _didIteratorError = true;
26
- _iteratorError = err;
27
- } finally {
28
- try {
29
- if (!_iteratorNormalCompletion && _iterator.return != null) {
30
- _iterator.return();
31
- }
32
- } finally {
33
- if (_didIteratorError) {
34
- throw _iteratorError;
35
- }
36
- }
37
- }
38
- if (defaults && named.length) {
39
- return "".concat(defaults, ", { ").concat(named.join(", "), " }");
40
- } else if (defaults) {
41
- return defaults;
42
- } else {
43
- return "{ ".concat(named.join(", "), " }");
44
- }
45
- };
46
- var createImportStatements = function(statements) {
47
- var deDuplicated = [];
48
- var seen = /* @__PURE__ */ new Map();
49
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
50
- try {
51
- var _loop = function() {
52
- var _step_value = _step.value, value = _step_value.value, specifiers = _step_value.specifiers, initialize = _step_value.initialize;
53
- if (!seen.has(value)) {
54
- deDuplicated.push({
55
- value,
56
- specifiers,
57
- initialize
58
- });
59
- seen.set(value, specifiers);
60
- } else {
61
- var _seen_get;
62
- var _deDuplicated_modifyIndex;
63
- (_seen_get = seen.get(value)).push.apply(_seen_get, _to_consumable_array(specifiers));
64
- var modifyIndex = deDuplicated.findIndex(function(v) {
65
- return v.value === value;
66
- });
67
- var _deDuplicated_modifyIndex_initialize;
68
- var 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 : "";
69
- deDuplicated[modifyIndex].initialize = originInitialize.concat("\n".concat(initialize || ""));
70
- }
71
- };
72
- for (var _iterator = statements[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)
73
- _loop();
74
- } catch (err) {
75
- _didIteratorError = true;
76
- _iteratorError = err;
77
- } finally {
78
- try {
79
- if (!_iteratorNormalCompletion && _iterator.return != null) {
80
- _iterator.return();
81
- }
82
- } finally {
83
- if (_didIteratorError) {
84
- throw _iteratorError;
85
- }
86
- }
87
- }
88
- return deDuplicated.map(function(param) {
89
- var value = param.value, specifiers = param.specifiers, initialize = param.initialize;
90
- return "import ".concat(createImportSpecifier(specifiers), " from '").concat(value, "';\n").concat(initialize || "");
91
- }).join("\n");
92
- };
93
- var generateCode = function() {
94
- var _ref = _async_to_generator(function(appContext, config, entrypoints, api) {
95
- var internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias, runtimeConfigFile, hookRunners, customRuntimeConfig, importsStatemets;
96
- function generateEntryCode(entrypoint, customRuntimeConfig2) {
97
- return _generateEntryCode.apply(this, arguments);
98
- }
99
- function _generateEntryCode() {
100
- _generateEntryCode = _async_to_generator(function(entrypoint, customRuntimeConfig2) {
101
- var entryName, isAutoMount, imports, entryFile;
102
- return _ts_generator(this, function(_state) {
103
- switch (_state.label) {
104
- case 0:
105
- entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount;
106
- if (!isAutoMount)
107
- return [
108
- 3,
109
- 2
110
- ];
111
- return [
112
- 4,
113
- hookRunners.modifyEntryImports({
114
- entrypoint,
115
- imports: getDefaultImports({
116
- entrypoint,
117
- srcDirectory,
118
- appDirectory,
119
- internalSrcAlias,
120
- internalDirAlias,
121
- runtimeConfigFile,
122
- customRuntimeConfig: customRuntimeConfig2
123
- })
124
- })
125
- ];
126
- case 1:
127
- imports = _state.sent().imports;
128
- importsStatemets.set(entryName, imports);
129
- entryFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
130
- entrypoint.internalEntry = entryFile;
131
- _state.label = 2;
132
- case 2:
133
- return [
134
- 2
135
- ];
136
- }
137
- });
138
- });
139
- return _generateEntryCode.apply(this, arguments);
140
- }
141
- return _ts_generator(this, function(_state) {
142
- switch (_state.label) {
143
- case 0:
144
- internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, appDirectory = appContext.appDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, runtimeConfigFile = appContext.runtimeConfigFile;
145
- hookRunners = api.useHookRunners();
146
- customRuntimeConfig = findExists(JS_EXTENSIONS.map(function(ext) {
147
- return path.resolve(srcDirectory, "".concat(runtimeConfigFile).concat(ext));
148
- }));
149
- importsStatemets = /* @__PURE__ */ new Map();
150
- return [
151
- 4,
152
- Promise.all(entrypoints.map(function(entrypoint) {
153
- return generateEntryCode(entrypoint, customRuntimeConfig);
154
- }))
155
- ];
156
- case 1:
157
- _state.sent();
158
- return [
159
- 2,
160
- {
161
- importsStatemets
162
- }
163
- ];
164
- }
165
- });
166
- });
167
- return function generateCode2(appContext, config, entrypoints, api) {
168
- return _ref.apply(this, arguments);
169
- };
170
- }();
171
- var generateIndexCode = function() {
172
- var _ref = _async_to_generator(function(param) {
173
- var appContext, api, entrypoints, config, importsStatemets, bundlerConfigs, hookRunners, mountId, internalDirectory, packageName, srcDirectory, runtimeConfigFile, customRuntimeConfig;
174
- return _ts_generator(this, function(_state) {
175
- switch (_state.label) {
176
- case 0:
177
- appContext = param.appContext, api = param.api, entrypoints = param.entrypoints, config = param.config, importsStatemets = param.importsStatemets, bundlerConfigs = param.bundlerConfigs;
178
- hookRunners = api.useHookRunners();
179
- mountId = config.html.mountId;
180
- internalDirectory = appContext.internalDirectory, packageName = appContext.packageName, srcDirectory = appContext.srcDirectory, runtimeConfigFile = appContext.runtimeConfigFile;
181
- customRuntimeConfig = findExists(JS_EXTENSIONS.map(function(ext) {
182
- return path.resolve(srcDirectory, "".concat(runtimeConfigFile).concat(ext));
183
- }));
184
- return [
185
- 4,
186
- Promise.all(entrypoints.map(function() {
187
- var _ref2 = _async_to_generator(function(entrypoint) {
188
- var entryName, isMainEntry, isAutoMount, customBootstrap, fileSystemRoutes, plugins, _ref3, renderFunction, exportStatement, imports, code, entryFile, rawAsyncEntryCode, ssr, _ref1, asyncEntryCode, bootstrapFile;
189
- return _ts_generator(this, function(_state2) {
190
- switch (_state2.label) {
191
- case 0:
192
- entryName = entrypoint.entryName, isMainEntry = entrypoint.isMainEntry, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
193
- if (!isAutoMount)
194
- return [
195
- 3,
196
- 6
197
- ];
198
- return [
199
- 4,
200
- hookRunners.modifyEntryRuntimePlugins({
201
- entrypoint,
202
- plugins: [],
203
- bundlerConfigs
204
- })
205
- ];
206
- case 1:
207
- plugins = _state2.sent().plugins;
208
- return [
209
- 4,
210
- hookRunners.modifyEntryRenderFunction({
211
- entrypoint,
212
- code: templates.renderFunction({
213
- plugins,
214
- customBootstrap,
215
- customRuntimeConfig,
216
- fileSystemRoutes
217
- })
218
- })
219
- ];
220
- case 2:
221
- _ref3 = _state2.sent(), renderFunction = _ref3.code;
222
- return [
223
- 4,
224
- hookRunners.modifyEntryExport({
225
- entrypoint,
226
- exportStatement: "export default AppWrapper;"
227
- })
228
- ];
229
- case 3:
230
- exportStatement = _state2.sent().exportStatement;
231
- imports = importsStatemets.get(entryName);
232
- code = templates.index({
233
- mountId,
234
- imports: createImportStatements(imports),
235
- renderFunction,
236
- exportStatement
237
- });
238
- entryFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_POINT_FILE_NAME));
239
- if (!config.source.enableAsyncEntry)
240
- return [
241
- 3,
242
- 5
243
- ];
244
- rawAsyncEntryCode = "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');");
245
- ssr = getEntryOptions(entryName, isMainEntry, config.server.ssr, config.server.ssrByEntries, packageName);
246
- if (ssr) {
247
- rawAsyncEntryCode = "\n export const ".concat(SERVER_RENDER_FUNCTION_NAME, " = async (...args) => {\n let entry = await ").concat(rawAsyncEntryCode, ";\n if (entry.default instanceof Promise){\n entry = await entry.default;\n return entry.default.").concat(SERVER_RENDER_FUNCTION_NAME, ".apply(null, args);\n }\n return entry.").concat(SERVER_RENDER_FUNCTION_NAME, ".apply(null, args);\n };\n if(typeof window!=='undefined'){\n ").concat(rawAsyncEntryCode, "\n }\n ");
248
- }
249
- return [
250
- 4,
251
- hookRunners.modifyAsyncEntry({
252
- entrypoint,
253
- code: rawAsyncEntryCode
254
- })
255
- ];
256
- case 4:
257
- _ref1 = _state2.sent(), asyncEntryCode = _ref1.code;
258
- fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
259
- bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
260
- fs.outputFileSync(bootstrapFile, code, "utf8");
261
- return [
262
- 3,
263
- 6
264
- ];
265
- case 5:
266
- fs.outputFileSync(entryFile, code, "utf8");
267
- _state2.label = 6;
268
- case 6:
269
- return [
270
- 2
271
- ];
272
- }
273
- });
274
- });
275
- return function(entrypoint) {
276
- return _ref2.apply(this, arguments);
277
- };
278
- }()))
279
- ];
280
- case 1:
281
- _state.sent();
282
- return [
283
- 2
284
- ];
285
- }
286
- });
287
- });
288
- return function generateIndexCode2(_) {
289
- return _ref.apply(this, arguments);
290
- };
291
- }();
292
- export {
293
- createImportStatements,
294
- generateCode,
295
- generateIndexCode
296
- };