@modern-js/app-tools 2.39.2-alpha.0 → 2.39.2
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.
- package/dist/cjs/analyze/nestedRoutes.js +1 -2
- package/dist/esm/analyze/nestedRoutes.js +1 -2
- package/dist/esm-node/analyze/nestedRoutes.js +1 -2
- package/package.json +24 -24
- package/dist/js/modern/analyze/constants.js +0 -15
- package/dist/js/modern/analyze/generateCode.js +0 -179
- package/dist/js/modern/analyze/getBundleEntry.js +0 -75
- package/dist/js/modern/analyze/getClientRoutes.js +0 -219
- package/dist/js/modern/analyze/getFileSystemEntry.js +0 -74
- package/dist/js/modern/analyze/getHtmlTemplate.js +0 -82
- package/dist/js/modern/analyze/getServerRoutes.js +0 -192
- package/dist/js/modern/analyze/index.js +0 -148
- package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -32
- package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -16
- package/dist/js/modern/analyze/templates.js +0 -88
- package/dist/js/modern/analyze/utils.js +0 -92
- package/dist/js/modern/commands/build.js +0 -154
- package/dist/js/modern/commands/deploy.js +0 -5
- package/dist/js/modern/commands/dev.js +0 -95
- package/dist/js/modern/commands/index.js +0 -3
- package/dist/js/modern/commands/inspect.js +0 -69
- package/dist/js/modern/commands/start.js +0 -31
- package/dist/js/modern/exports/server.js +0 -1
- package/dist/js/modern/hooks.js +0 -21
- package/dist/js/modern/index.js +0 -109
- package/dist/js/modern/locale/en.js +0 -35
- package/dist/js/modern/locale/index.js +0 -9
- package/dist/js/modern/locale/zh.js +0 -35
- package/dist/js/modern/utils/config.js +0 -78
- package/dist/js/modern/utils/createCompiler.js +0 -61
- package/dist/js/modern/utils/createServer.js +0 -18
- package/dist/js/modern/utils/getSpecifiedEntries.js +0 -36
- package/dist/js/modern/utils/language.js +0 -5
- package/dist/js/modern/utils/printInstructions.js +0 -11
- package/dist/js/modern/utils/routes.js +0 -15
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/analyze/constants.js +0 -36
- package/dist/js/node/analyze/generateCode.js +0 -208
- package/dist/js/node/analyze/getBundleEntry.js +0 -89
- package/dist/js/node/analyze/getClientRoutes.js +0 -241
- package/dist/js/node/analyze/getFileSystemEntry.js +0 -90
- package/dist/js/node/analyze/getHtmlTemplate.js +0 -106
- package/dist/js/node/analyze/getServerRoutes.js +0 -208
- package/dist/js/node/analyze/index.js +0 -178
- package/dist/js/node/analyze/isDefaultExportFunction.js +0 -50
- package/dist/js/node/analyze/makeLegalIdentifier.js +0 -24
- package/dist/js/node/analyze/templates.js +0 -106
- package/dist/js/node/analyze/utils.js +0 -113
- package/dist/js/node/commands/build.js +0 -174
- package/dist/js/node/commands/deploy.js +0 -14
- package/dist/js/node/commands/dev.js +0 -120
- package/dist/js/node/commands/index.js +0 -44
- package/dist/js/node/commands/inspect.js +0 -98
- package/dist/js/node/commands/start.js +0 -47
- package/dist/js/node/exports/server.js +0 -13
- package/dist/js/node/hooks.js +0 -39
- package/dist/js/node/index.js +0 -141
- package/dist/js/node/locale/en.js +0 -42
- package/dist/js/node/locale/index.js +0 -20
- package/dist/js/node/locale/zh.js +0 -42
- package/dist/js/node/utils/config.js +0 -103
- package/dist/js/node/utils/createCompiler.js +0 -81
- package/dist/js/node/utils/createServer.js +0 -35
- package/dist/js/node/utils/getSpecifiedEntries.js +0 -46
- package/dist/js/node/utils/language.js +0 -13
- package/dist/js/node/utils/printInstructions.js +0 -22
- package/dist/js/node/utils/routes.js +0 -25
- package/dist/js/node/utils/types.js +0 -0
@@ -1,61 +0,0 @@
|
|
1
|
-
import { webpack } from '@modern-js/webpack';
|
2
|
-
import { chalk, logger, formatWebpackMessages, clearConsole } from '@modern-js/utils';
|
3
|
-
import { printInstructions } from "./printInstructions";
|
4
|
-
export const createCompiler = async ({
|
5
|
-
api,
|
6
|
-
webpackConfigs,
|
7
|
-
// TODO: params
|
8
|
-
userConfig,
|
9
|
-
appContext
|
10
|
-
}) => {
|
11
|
-
try {
|
12
|
-
const hookRunners = api.useHookRunners();
|
13
|
-
await hookRunners.beforeCreateCompiler({
|
14
|
-
webpackConfigs
|
15
|
-
});
|
16
|
-
const compiler = webpack(webpackConfigs);
|
17
|
-
await hookRunners.afterCreateCompiler({
|
18
|
-
compiler
|
19
|
-
});
|
20
|
-
let isFirstCompile = true;
|
21
|
-
compiler.hooks.invalid.tap('invalid', () => {
|
22
|
-
clearConsole();
|
23
|
-
logger.log('Compiling...');
|
24
|
-
});
|
25
|
-
compiler.hooks.done.tap('done', async stats => {
|
26
|
-
const statsData = stats.toJson({
|
27
|
-
preset: 'errors-warnings'
|
28
|
-
});
|
29
|
-
const {
|
30
|
-
errors,
|
31
|
-
warnings
|
32
|
-
} = formatWebpackMessages(statsData);
|
33
|
-
|
34
|
-
if (errors.length) {
|
35
|
-
logger.log(chalk.red(`Failed to compile.\n`));
|
36
|
-
logger.log(errors.join('\n\n'));
|
37
|
-
logger.log();
|
38
|
-
} else if (process.stdout.isTTY || isFirstCompile) {
|
39
|
-
await hookRunners.afterDev();
|
40
|
-
|
41
|
-
if (warnings.length) {
|
42
|
-
logger.log(chalk.yellow(`Compiled with warnings.\n`));
|
43
|
-
logger.log(warnings.join('\n\n'));
|
44
|
-
logger.log();
|
45
|
-
}
|
46
|
-
|
47
|
-
await printInstructions(hookRunners, appContext, userConfig);
|
48
|
-
}
|
49
|
-
|
50
|
-
isFirstCompile = false;
|
51
|
-
});
|
52
|
-
return compiler;
|
53
|
-
} catch (err) {
|
54
|
-
logger.log(chalk.red(`Failed to compile.`));
|
55
|
-
logger.log();
|
56
|
-
logger.log(err); // FIXME: 这里最好抛出异常,执行 process.exit 的地方尽可能少或者控制在几个统一的地方比较合适
|
57
|
-
// eslint-disable-next-line no-process-exit
|
58
|
-
|
59
|
-
process.exit(1);
|
60
|
-
}
|
61
|
-
};
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import { Server } from '@modern-js/server';
|
2
|
-
let server = null;
|
3
|
-
export const getServer = () => server;
|
4
|
-
export const closeServer = async () => {
|
5
|
-
if (server) {
|
6
|
-
await server.close();
|
7
|
-
server = null;
|
8
|
-
}
|
9
|
-
};
|
10
|
-
export const createServer = async options => {
|
11
|
-
if (server) {
|
12
|
-
await server.close();
|
13
|
-
}
|
14
|
-
|
15
|
-
server = new Server(options);
|
16
|
-
const app = await server.init();
|
17
|
-
return app;
|
18
|
-
};
|
@@ -1,36 +0,0 @@
|
|
1
|
-
import { inquirer } from '@modern-js/utils';
|
2
|
-
export const getSpecifiedEntries = async (entry, entrypoints) => {
|
3
|
-
const entryNames = entrypoints.map(e => e.entryName);
|
4
|
-
|
5
|
-
if (!entry) {
|
6
|
-
return entryNames;
|
7
|
-
}
|
8
|
-
|
9
|
-
if (typeof entry === 'boolean') {
|
10
|
-
const {
|
11
|
-
selected
|
12
|
-
} = await inquirer.prompt([{
|
13
|
-
type: 'checkbox',
|
14
|
-
name: 'selected',
|
15
|
-
choices: entryNames,
|
16
|
-
message: '请选择需要构建的入口',
|
17
|
-
|
18
|
-
validate(answer) {
|
19
|
-
if (answer.length < 1) {
|
20
|
-
return 'You must choose at least one topping.';
|
21
|
-
}
|
22
|
-
|
23
|
-
return true;
|
24
|
-
}
|
25
|
-
|
26
|
-
}]);
|
27
|
-
return selected;
|
28
|
-
}
|
29
|
-
|
30
|
-
entry.forEach(name => {
|
31
|
-
if (!entryNames.includes(name)) {
|
32
|
-
throw new Error(`can not found entry ${name}, compiler entry should in ${entryNames.join(', ')}`);
|
33
|
-
}
|
34
|
-
});
|
35
|
-
return entry;
|
36
|
-
};
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import { prettyInstructions, logger } from '@modern-js/utils';
|
2
|
-
export const printInstructions = async (hookRunners, appContext, config) => {
|
3
|
-
const message = prettyInstructions(appContext, config); // call beforePrintInstructions hook.
|
4
|
-
|
5
|
-
const {
|
6
|
-
instructions
|
7
|
-
} = await hookRunners.beforePrintInstructions({
|
8
|
-
instructions: message
|
9
|
-
});
|
10
|
-
logger.log(instructions);
|
11
|
-
};
|
@@ -1,15 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
import { fs, ROUTE_SPEC_FILE } from '@modern-js/utils';
|
3
|
-
|
4
|
-
const generateRoutes = async appContext => {
|
5
|
-
const {
|
6
|
-
serverRoutes,
|
7
|
-
distDirectory
|
8
|
-
} = appContext;
|
9
|
-
const output = JSON.stringify({
|
10
|
-
routes: serverRoutes
|
11
|
-
}, null, 2);
|
12
|
-
await fs.outputFile(path.join(distDirectory, ROUTE_SPEC_FILE), output);
|
13
|
-
};
|
14
|
-
|
15
|
-
export { generateRoutes };
|
File without changes
|
@@ -1,36 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.PAGES_DIR_NAME = exports.JS_EXTENSIONS = exports.INDEX_FILE_NAME = exports.HTML_PARTIALS_FOLDER = exports.HTML_PARTIALS_EXTENSIONS = exports.FILE_SYSTEM_ROUTES_LAYOUT = exports.FILE_SYSTEM_ROUTES_INDEX = exports.FILE_SYSTEM_ROUTES_IGNORED_REGEX = exports.FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = exports.FILE_SYSTEM_ROUTES_FILE_NAME = exports.FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = exports.FILE_SYSTEM_ROUTES_COMPONENTS_DIR = exports.ENTRY_POINT_FILE_NAME = exports.ENTRY_BOOTSTRAP_FILE_NAME = exports.APP_FILE_NAME = void 0;
|
7
|
-
const JS_EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx'];
|
8
|
-
exports.JS_EXTENSIONS = JS_EXTENSIONS;
|
9
|
-
const INDEX_FILE_NAME = 'index';
|
10
|
-
exports.INDEX_FILE_NAME = INDEX_FILE_NAME;
|
11
|
-
const APP_FILE_NAME = 'App';
|
12
|
-
exports.APP_FILE_NAME = APP_FILE_NAME;
|
13
|
-
const PAGES_DIR_NAME = 'pages';
|
14
|
-
exports.PAGES_DIR_NAME = PAGES_DIR_NAME;
|
15
|
-
const FILE_SYSTEM_ROUTES_FILE_NAME = 'routes.js';
|
16
|
-
exports.FILE_SYSTEM_ROUTES_FILE_NAME = FILE_SYSTEM_ROUTES_FILE_NAME;
|
17
|
-
const ENTRY_POINT_FILE_NAME = 'index.js';
|
18
|
-
exports.ENTRY_POINT_FILE_NAME = ENTRY_POINT_FILE_NAME;
|
19
|
-
const ENTRY_BOOTSTRAP_FILE_NAME = 'bootstrap.js';
|
20
|
-
exports.ENTRY_BOOTSTRAP_FILE_NAME = ENTRY_BOOTSTRAP_FILE_NAME;
|
21
|
-
const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
|
22
|
-
exports.FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP;
|
23
|
-
const FILE_SYSTEM_ROUTES_LAYOUT = '_layout';
|
24
|
-
exports.FILE_SYSTEM_ROUTES_LAYOUT = FILE_SYSTEM_ROUTES_LAYOUT;
|
25
|
-
const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = '_app';
|
26
|
-
exports.FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT;
|
27
|
-
const FILE_SYSTEM_ROUTES_INDEX = 'index';
|
28
|
-
exports.FILE_SYSTEM_ROUTES_INDEX = FILE_SYSTEM_ROUTES_INDEX;
|
29
|
-
const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
|
30
|
-
exports.FILE_SYSTEM_ROUTES_IGNORED_REGEX = FILE_SYSTEM_ROUTES_IGNORED_REGEX;
|
31
|
-
const HTML_PARTIALS_FOLDER = 'html';
|
32
|
-
exports.HTML_PARTIALS_FOLDER = HTML_PARTIALS_FOLDER;
|
33
|
-
const HTML_PARTIALS_EXTENSIONS = ['.htm', '.html', '.ejs'];
|
34
|
-
exports.HTML_PARTIALS_EXTENSIONS = HTML_PARTIALS_EXTENSIONS;
|
35
|
-
const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = 'internal_components';
|
36
|
-
exports.FILE_SYSTEM_ROUTES_COMPONENTS_DIR = FILE_SYSTEM_ROUTES_COMPONENTS_DIR;
|
@@ -1,208 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.generateCode = exports.createImportStatements = void 0;
|
7
|
-
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
9
|
-
|
10
|
-
var _utils = require("@modern-js/utils");
|
11
|
-
|
12
|
-
var templates = _interopRequireWildcard(require("./templates"));
|
13
|
-
|
14
|
-
var _getClientRoutes = require("./getClientRoutes");
|
15
|
-
|
16
|
-
var _constants = require("./constants");
|
17
|
-
|
18
|
-
var _utils2 = require("./utils");
|
19
|
-
|
20
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
21
|
-
|
22
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
23
|
-
|
24
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
25
|
-
|
26
|
-
const createImportSpecifier = specifiers => {
|
27
|
-
let defaults = '';
|
28
|
-
const named = [];
|
29
|
-
|
30
|
-
for (const {
|
31
|
-
local,
|
32
|
-
imported
|
33
|
-
} of specifiers) {
|
34
|
-
if (local && imported) {
|
35
|
-
named.push(`${imported} as ${local}`);
|
36
|
-
} else if (local) {
|
37
|
-
defaults = local;
|
38
|
-
} else {
|
39
|
-
named.push(imported);
|
40
|
-
}
|
41
|
-
}
|
42
|
-
|
43
|
-
if (defaults && named.length) {
|
44
|
-
return `${defaults}, { ${named.join(', ')} }`;
|
45
|
-
} else if (defaults) {
|
46
|
-
return defaults;
|
47
|
-
} else {
|
48
|
-
return `{ ${named.join(', ')} }`;
|
49
|
-
}
|
50
|
-
};
|
51
|
-
|
52
|
-
const createImportStatements = statements => {
|
53
|
-
// merge import statements with the same value.
|
54
|
-
const deDuplicated = [];
|
55
|
-
const seen = new Map();
|
56
|
-
|
57
|
-
for (const {
|
58
|
-
value,
|
59
|
-
specifiers,
|
60
|
-
initialize
|
61
|
-
} of statements) {
|
62
|
-
if (!seen.has(value)) {
|
63
|
-
deDuplicated.push({
|
64
|
-
value,
|
65
|
-
specifiers,
|
66
|
-
initialize
|
67
|
-
});
|
68
|
-
seen.set(value, specifiers);
|
69
|
-
} else {
|
70
|
-
var _deDuplicated$modifyI, _deDuplicated$modifyI2;
|
71
|
-
|
72
|
-
seen.get(value).push(...specifiers); // make "initialize" param can be connected when multiple plugins were imported from same package
|
73
|
-
|
74
|
-
const modifyIndex = deDuplicated.findIndex(v => v.value === value);
|
75
|
-
const originInitialize = (_deDuplicated$modifyI = (_deDuplicated$modifyI2 = deDuplicated[modifyIndex]) === null || _deDuplicated$modifyI2 === void 0 ? void 0 : _deDuplicated$modifyI2.initialize) !== null && _deDuplicated$modifyI !== void 0 ? _deDuplicated$modifyI : '';
|
76
|
-
deDuplicated[modifyIndex].initialize = originInitialize.concat(`\n${initialize || ''}`);
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
return deDuplicated.map(({
|
81
|
-
value,
|
82
|
-
specifiers,
|
83
|
-
initialize
|
84
|
-
}) => `import ${createImportSpecifier(specifiers)} from '${value}';\n${initialize || ''}`).join('\n');
|
85
|
-
};
|
86
|
-
|
87
|
-
exports.createImportStatements = createImportStatements;
|
88
|
-
|
89
|
-
const generateCode = async (appContext, config, entrypoints, api) => {
|
90
|
-
const {
|
91
|
-
internalDirectory,
|
92
|
-
srcDirectory,
|
93
|
-
internalDirAlias,
|
94
|
-
internalSrcAlias
|
95
|
-
} = appContext;
|
96
|
-
const hookRunners = api.useHookRunners();
|
97
|
-
const {
|
98
|
-
output: {
|
99
|
-
mountId
|
100
|
-
}
|
101
|
-
} = config;
|
102
|
-
|
103
|
-
for (const entrypoint of entrypoints) {
|
104
|
-
const {
|
105
|
-
entryName,
|
106
|
-
isAutoMount,
|
107
|
-
customBootstrap,
|
108
|
-
fileSystemRoutes
|
109
|
-
} = entrypoint;
|
110
|
-
|
111
|
-
if (isAutoMount) {
|
112
|
-
// generate routes file for file system routes entrypoint.
|
113
|
-
if (fileSystemRoutes) {
|
114
|
-
const initialRoutes = (0, _getClientRoutes.getClientRoutes)({
|
115
|
-
entrypoint,
|
116
|
-
srcDirectory,
|
117
|
-
srcAlias: internalSrcAlias,
|
118
|
-
internalDirectory,
|
119
|
-
internalDirAlias
|
120
|
-
});
|
121
|
-
const {
|
122
|
-
routes
|
123
|
-
} = await hookRunners.modifyFileSystemRoutes({
|
124
|
-
entrypoint,
|
125
|
-
routes: initialRoutes
|
126
|
-
});
|
127
|
-
const {
|
128
|
-
code
|
129
|
-
} = await hookRunners.beforeGenerateRoutes({
|
130
|
-
entrypoint,
|
131
|
-
code: templates.fileSystemRoutes({
|
132
|
-
routes
|
133
|
-
})
|
134
|
-
});
|
135
|
-
|
136
|
-
_utils.fs.outputFileSync(_path.default.resolve(internalDirectory, `./${entryName}/${_constants.FILE_SYSTEM_ROUTES_FILE_NAME}`), code, 'utf8');
|
137
|
-
} // call modifyEntryImports hook
|
138
|
-
|
139
|
-
|
140
|
-
const {
|
141
|
-
imports: importStatements
|
142
|
-
} = await hookRunners.modifyEntryImports({
|
143
|
-
entrypoint,
|
144
|
-
imports: (0, _utils2.getDefaultImports)({
|
145
|
-
entrypoint,
|
146
|
-
srcDirectory,
|
147
|
-
internalSrcAlias,
|
148
|
-
internalDirAlias,
|
149
|
-
internalDirectory
|
150
|
-
})
|
151
|
-
}); // call modifyEntryRuntimePlugins hook
|
152
|
-
|
153
|
-
const {
|
154
|
-
plugins
|
155
|
-
} = await hookRunners.modifyEntryRuntimePlugins({
|
156
|
-
entrypoint,
|
157
|
-
plugins: []
|
158
|
-
}); // call modifyEntryRenderFunction hook
|
159
|
-
|
160
|
-
const {
|
161
|
-
code: renderFunction
|
162
|
-
} = await hookRunners.modifyEntryRenderFunction({
|
163
|
-
entrypoint,
|
164
|
-
code: templates.renderFunction({
|
165
|
-
plugins,
|
166
|
-
customBootstrap,
|
167
|
-
fileSystemRoutes
|
168
|
-
})
|
169
|
-
}); // call modifyEntryExport hook
|
170
|
-
|
171
|
-
const {
|
172
|
-
exportStatement
|
173
|
-
} = await hookRunners.modifyEntryExport({
|
174
|
-
entrypoint,
|
175
|
-
exportStatement: 'export default AppWrapper;'
|
176
|
-
});
|
177
|
-
const code = templates.index({
|
178
|
-
mountId: mountId,
|
179
|
-
imports: createImportStatements(importStatements),
|
180
|
-
renderFunction,
|
181
|
-
exportStatement
|
182
|
-
});
|
183
|
-
|
184
|
-
const entryFile = _path.default.resolve(internalDirectory, `./${entryName}/${_constants.ENTRY_POINT_FILE_NAME}`);
|
185
|
-
|
186
|
-
entrypoint.entry = entryFile; // generate entry file.
|
187
|
-
|
188
|
-
if (config.source.enableAsyncEntry) {
|
189
|
-
const {
|
190
|
-
code: asyncEntryCode
|
191
|
-
} = await hookRunners.modifyAsyncEntry({
|
192
|
-
entrypoint,
|
193
|
-
code: `import('./${_constants.ENTRY_BOOTSTRAP_FILE_NAME}');`
|
194
|
-
});
|
195
|
-
|
196
|
-
_utils.fs.outputFileSync(entryFile, asyncEntryCode, 'utf8');
|
197
|
-
|
198
|
-
const bootstrapFile = _path.default.resolve(internalDirectory, `./${entryName}/${_constants.ENTRY_BOOTSTRAP_FILE_NAME}`);
|
199
|
-
|
200
|
-
_utils.fs.outputFileSync(bootstrapFile, code, 'utf8');
|
201
|
-
} else {
|
202
|
-
_utils.fs.outputFileSync(entryFile, code, 'utf8');
|
203
|
-
}
|
204
|
-
}
|
205
|
-
}
|
206
|
-
};
|
207
|
-
|
208
|
-
exports.generateCode = generateCode;
|
@@ -1,89 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.getBundleEntry = void 0;
|
7
|
-
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
9
|
-
|
10
|
-
var _utils = require("@modern-js/utils");
|
11
|
-
|
12
|
-
var _getFileSystemEntry = require("./getFileSystemEntry");
|
13
|
-
|
14
|
-
var _constants = require("./constants");
|
15
|
-
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
-
|
18
|
-
const ensureExtensions = file => {
|
19
|
-
if (!_path.default.extname(file)) {
|
20
|
-
return (0, _utils.findExists)(_constants.JS_EXTENSIONS.map(ext => `${file}${ext}`)) || file;
|
21
|
-
}
|
22
|
-
|
23
|
-
return file;
|
24
|
-
};
|
25
|
-
|
26
|
-
const ifAlreadyExists = (entrypoints, checked) => entrypoints.some(entrypoint => {
|
27
|
-
if (ensureExtensions(entrypoint.entry) === ensureExtensions(checked.entry)) {
|
28
|
-
// reset entryName
|
29
|
-
checked.entryName = entrypoint.entryName;
|
30
|
-
return true;
|
31
|
-
} // filesystem routes entrypoint conflict with normal entrypoint.
|
32
|
-
|
33
|
-
|
34
|
-
if (entrypoint.entry.startsWith(checked.entry) || checked.entry.startsWith(entrypoint.entry)) {
|
35
|
-
throw new Error(`Entry configuration conflicts\n Your configuration: ${checked.entry}.\n Default entrypoint: ${entrypoint.entry}\n Please reset source.entries or set source.disableDefaultEntries to disable the default entry rules.`);
|
36
|
-
}
|
37
|
-
|
38
|
-
return false;
|
39
|
-
});
|
40
|
-
|
41
|
-
const getBundleEntry = (appContext, config) => {
|
42
|
-
const {
|
43
|
-
appDirectory,
|
44
|
-
packageName
|
45
|
-
} = appContext;
|
46
|
-
const {
|
47
|
-
source: {
|
48
|
-
disableDefaultEntries,
|
49
|
-
entries,
|
50
|
-
entriesDir
|
51
|
-
}
|
52
|
-
} = config;
|
53
|
-
const defaults = disableDefaultEntries ? [] : (0, _getFileSystemEntry.getFileSystemEntry)(appContext, config); // merge entrypoints from user config with directory convention.
|
54
|
-
|
55
|
-
if (entries) {
|
56
|
-
Object.keys(entries).forEach(name => {
|
57
|
-
const value = entries[name];
|
58
|
-
const entrypoint = typeof value === 'string' ? {
|
59
|
-
entryName: name,
|
60
|
-
entry: (0, _utils.ensureAbsolutePath)(appDirectory, value),
|
61
|
-
isAutoMount: true,
|
62
|
-
fileSystemRoutes: _utils.fs.statSync((0, _utils.ensureAbsolutePath)(appDirectory, value)).isDirectory() ? {} : undefined
|
63
|
-
} : {
|
64
|
-
entryName: name,
|
65
|
-
entry: (0, _utils.ensureAbsolutePath)(appDirectory, value.entry),
|
66
|
-
isAutoMount: !value.disableMount,
|
67
|
-
fileSystemRoutes: value.enableFileSystemRoutes ? {} : undefined
|
68
|
-
};
|
69
|
-
|
70
|
-
if (!ifAlreadyExists(defaults, entrypoint)) {
|
71
|
-
defaults.push(entrypoint);
|
72
|
-
}
|
73
|
-
});
|
74
|
-
}
|
75
|
-
|
76
|
-
if (!disableDefaultEntries) {
|
77
|
-
// find main entry point which server route is '/'.
|
78
|
-
const entriesDirAbs = (0, _utils.ensureAbsolutePath)(appDirectory, entriesDir);
|
79
|
-
const found = defaults.find(({
|
80
|
-
entryName,
|
81
|
-
entry
|
82
|
-
}) => entryName === packageName || _path.default.dirname(entry) === entriesDirAbs);
|
83
|
-
found && (found.entryName = _utils.MAIN_ENTRY_NAME);
|
84
|
-
}
|
85
|
-
|
86
|
-
return defaults;
|
87
|
-
};
|
88
|
-
|
89
|
-
exports.getBundleEntry = getBundleEntry;
|