@modern-js/app-tools 2.58.2 → 2.59.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/builder/builder-rspack/adapterCopy.js +1 -1
- package/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -1
- package/dist/cjs/builder/generator/index.js +2 -3
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +8 -13
- package/dist/cjs/builder/shared/builderPlugins/index.js +1 -3
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
- package/dist/cjs/commands/build.js +2 -2
- package/dist/cjs/commands/dev.js +6 -5
- package/dist/cjs/commands/index.js +1 -1
- package/dist/cjs/commands/serve.js +4 -3
- package/dist/cjs/config/legacy/index.js +3 -3
- package/dist/cjs/esm/register-esm.mjs +2 -3
- package/dist/cjs/esm/utils.mjs +2 -2
- package/dist/cjs/index.js +17 -10
- package/dist/cjs/locale/index.js +1 -1
- package/dist/cjs/plugins/analyze/getFileSystemEntry.js +50 -44
- package/dist/cjs/plugins/analyze/getServerRoutes.js +2 -2
- package/dist/cjs/plugins/analyze/index.js +6 -6
- package/dist/cjs/plugins/analyze/utils.js +1 -1
- package/dist/cjs/plugins/deploy/dependencies/index.js +1 -1
- package/dist/cjs/plugins/deploy/dependencies/utils.js +2 -2
- package/dist/cjs/plugins/deploy/index.js +2 -2
- package/dist/cjs/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/node.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/cjs/plugins/serverBuild.js +2 -2
- package/dist/cjs/utils/createServer.js +1 -1
- package/dist/esm/builder/builder-rspack/adapterCopy.js +166 -0
- package/dist/esm/builder/builder-rspack/index.js +34 -0
- package/dist/esm/builder/builder-webpack/adapterModern.js +29 -0
- package/dist/esm/builder/builder-webpack/createCopyPattern.js +43 -0
- package/dist/esm/builder/builder-webpack/index.js +52 -0
- package/dist/esm/builder/generator/createBuilderProviderConfig.js +37 -0
- package/dist/esm/builder/generator/getBuilderEnvironments.js +81 -0
- package/dist/esm/builder/generator/index.js +93 -0
- package/dist/esm/builder/index.js +45 -0
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +85 -0
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +126 -0
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +261 -0
- package/dist/esm/builder/shared/builderPlugins/index.js +3 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +51 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +37 -0
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +314 -0
- package/dist/esm/builder/shared/bundlerPlugins/index.js +3 -0
- package/dist/esm/builder/shared/createCopyInfo.js +14 -0
- package/dist/esm/builder/shared/index.js +3 -0
- package/dist/esm/builder/shared/loaders/serverModuleLoader.js +7 -0
- package/dist/esm/builder/shared/types.js +0 -0
- package/dist/esm/commands/build.js +140 -0
- package/dist/esm/commands/deploy.js +48 -0
- package/dist/esm/commands/dev.js +193 -0
- package/dist/esm/commands/index.js +411 -0
- package/dist/esm/commands/inspect.js +28 -0
- package/dist/esm/commands/serve.js +94 -0
- package/dist/esm/config/default.js +190 -0
- package/dist/esm/config/index.js +3 -0
- package/dist/esm/config/initialize/index.js +9 -0
- package/dist/esm/config/initialize/inits.js +89 -0
- package/dist/esm/config/legacy/createHtmlConfig.js +21 -0
- package/dist/esm/config/legacy/createOutputConfig.js +45 -0
- package/dist/esm/config/legacy/createSourceConfig.js +46 -0
- package/dist/esm/config/legacy/createToolsConfig.js +28 -0
- package/dist/esm/config/legacy/index.js +43 -0
- package/dist/esm/defineConfig.js +16 -0
- package/dist/esm/esm/esbuild-loader.mjs +20 -0
- package/dist/esm/esm/register-esm.mjs +66 -0
- package/dist/esm/esm/ts-node-loader.mjs +21 -0
- package/dist/esm/esm/utils.mjs +43 -0
- package/dist/esm/exports/server.js +4 -0
- package/dist/esm/hooks.js +34 -0
- package/dist/esm/index.js +246 -0
- package/dist/esm/locale/en.js +43 -0
- package/dist/esm/locale/index.js +12 -0
- package/dist/esm/locale/zh.js +43 -0
- package/dist/esm/plugins/analyze/constants.js +14 -0
- package/dist/esm/plugins/analyze/getBundleEntry.js +102 -0
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +266 -0
- package/dist/esm/plugins/analyze/getHtmlTemplate.js +178 -0
- package/dist/esm/plugins/analyze/getServerRoutes.js +132 -0
- package/dist/esm/plugins/analyze/index.js +380 -0
- package/dist/esm/plugins/analyze/isDefaultExportFunction.js +49 -0
- package/dist/esm/plugins/analyze/templates.js +6 -0
- package/dist/esm/plugins/analyze/utils.js +101 -0
- package/dist/esm/plugins/deploy/dependencies/index.js +615 -0
- package/dist/esm/plugins/deploy/dependencies/utils.js +421 -0
- package/dist/esm/plugins/deploy/exports.js +4 -0
- package/dist/esm/plugins/deploy/index.js +135 -0
- package/dist/esm/plugins/deploy/platforms/netlify-entry.js +11 -0
- package/dist/esm/plugins/deploy/platforms/netlify-entry.mjs +1 -0
- package/dist/esm/plugins/deploy/platforms/netlify-handler.js +205 -0
- package/dist/esm/plugins/deploy/platforms/netlify.js +327 -0
- package/dist/esm/plugins/deploy/platforms/node-entry.js +108 -0
- package/dist/esm/plugins/deploy/platforms/node.js +161 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel-entry.js +11 -0
- package/dist/esm/plugins/deploy/platforms/vercel-entry.mjs +3 -0
- package/dist/esm/plugins/deploy/platforms/vercel-handler.js +206 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +261 -0
- package/dist/esm/plugins/deploy/utils.js +47 -0
- package/dist/esm/plugins/initialize/index.js +119 -0
- package/dist/esm/plugins/serverBuild.js +87 -0
- package/dist/esm/types/config/deploy.js +0 -0
- package/dist/esm/types/config/dev.js +0 -0
- package/dist/esm/types/config/experiments.js +0 -0
- package/dist/esm/types/config/html.js +0 -0
- package/dist/esm/types/config/index.js +1 -0
- package/dist/esm/types/config/output.js +0 -0
- package/dist/esm/types/config/performance.js +0 -0
- package/dist/esm/types/config/security.js +0 -0
- package/dist/esm/types/config/source.js +0 -0
- package/dist/esm/types/config/testing.js +0 -0
- package/dist/esm/types/config/tools.js +0 -0
- package/dist/esm/types/hooks.js +0 -0
- package/dist/esm/types/index.js +3 -0
- package/dist/esm/types/legacyConfig/deploy.js +0 -0
- package/dist/esm/types/legacyConfig/dev.js +0 -0
- package/dist/esm/types/legacyConfig/index.js +0 -0
- package/dist/esm/types/legacyConfig/output.js +0 -0
- package/dist/esm/types/legacyConfig/source.js +0 -0
- package/dist/esm/types/legacyConfig/testing.js +0 -0
- package/dist/esm/types/legacyConfig/tools.js +0 -0
- package/dist/esm/types/utils.js +0 -0
- package/dist/esm/utils/config.js +122 -0
- package/dist/esm/utils/createServer.js +58 -0
- package/dist/esm/utils/env.js +16 -0
- package/dist/esm/utils/generateWatchFiles.js +71 -0
- package/dist/esm/utils/getSelectedEntries.js +67 -0
- package/dist/esm/utils/loadPlugins.js +74 -0
- package/dist/esm/utils/printInstructions.js +32 -0
- package/dist/esm/utils/register.js +188 -0
- package/dist/esm/utils/restart.js +67 -0
- package/dist/esm/utils/routes.js +42 -0
- package/dist/esm/utils/types.js +0 -0
- package/dist/esm-node/builder/builder-rspack/adapterCopy.js +67 -0
- package/dist/esm-node/builder/builder-rspack/index.js +12 -0
- package/dist/esm-node/builder/builder-webpack/adapterModern.js +26 -0
- package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +41 -0
- package/dist/esm-node/builder/builder-webpack/index.js +20 -0
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +44 -0
- package/dist/esm-node/builder/generator/getBuilderEnvironments.js +60 -0
- package/dist/esm-node/builder/generator/index.js +36 -0
- package/dist/esm-node/builder/index.js +11 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +48 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +60 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +151 -0
- package/dist/esm-node/builder/shared/builderPlugins/index.js +3 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +30 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +31 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +228 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/index.js +3 -0
- package/dist/esm-node/builder/shared/createCopyInfo.js +14 -0
- package/dist/esm-node/builder/shared/index.js +3 -0
- package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +7 -0
- package/dist/esm-node/builder/shared/types.js +0 -0
- package/dist/esm-node/commands/build.js +64 -0
- package/dist/esm-node/commands/deploy.js +12 -0
- package/dist/esm-node/commands/dev.js +105 -0
- package/dist/esm-node/commands/index.js +92 -0
- package/dist/esm-node/commands/inspect.js +15 -0
- package/dist/esm-node/commands/serve.js +52 -0
- package/dist/esm-node/config/default.js +197 -0
- package/dist/esm-node/config/index.js +3 -0
- package/dist/esm-node/config/initialize/index.js +9 -0
- package/dist/esm-node/config/initialize/inits.js +79 -0
- package/dist/esm-node/config/legacy/createHtmlConfig.js +21 -0
- package/dist/esm-node/config/legacy/createOutputConfig.js +45 -0
- package/dist/esm-node/config/legacy/createSourceConfig.js +29 -0
- package/dist/esm-node/config/legacy/createToolsConfig.js +28 -0
- package/dist/esm-node/config/legacy/index.js +43 -0
- package/dist/esm-node/defineConfig.js +13 -0
- package/dist/esm-node/esm/esbuild-loader.mjs +20 -0
- package/dist/esm-node/esm/register-esm.mjs +66 -0
- package/dist/esm-node/esm/ts-node-loader.mjs +21 -0
- package/dist/esm-node/esm/utils.mjs +43 -0
- package/dist/esm-node/exports/server.js +4 -0
- package/dist/esm-node/hooks.js +34 -0
- package/dist/esm-node/index.js +131 -0
- package/dist/esm-node/locale/en.js +43 -0
- package/dist/esm-node/locale/index.js +12 -0
- package/dist/esm-node/locale/zh.js +43 -0
- package/dist/esm-node/plugins/analyze/constants.js +14 -0
- package/dist/esm-node/plugins/analyze/getBundleEntry.js +61 -0
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +106 -0
- package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +74 -0
- package/dist/esm-node/plugins/analyze/getServerRoutes.js +132 -0
- package/dist/esm-node/plugins/analyze/index.js +166 -0
- package/dist/esm-node/plugins/analyze/isDefaultExportFunction.js +47 -0
- package/dist/esm-node/plugins/analyze/templates.js +24 -0
- package/dist/esm-node/plugins/analyze/utils.js +68 -0
- package/dist/esm-node/plugins/deploy/dependencies/index.js +202 -0
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +137 -0
- package/dist/esm-node/plugins/deploy/exports.js +4 -0
- package/dist/esm-node/plugins/deploy/index.js +44 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify-entry.js +11 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify-entry.mjs +1 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify-handler.js +71 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +117 -0
- package/dist/esm-node/plugins/deploy/platforms/node-entry.js +44 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +72 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel-entry.js +11 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel-entry.mjs +3 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel-handler.js +72 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +129 -0
- package/dist/esm-node/plugins/deploy/utils.js +44 -0
- package/dist/esm-node/plugins/initialize/index.js +84 -0
- package/dist/esm-node/plugins/serverBuild.js +58 -0
- package/dist/esm-node/types/config/deploy.js +0 -0
- package/dist/esm-node/types/config/dev.js +0 -0
- package/dist/esm-node/types/config/experiments.js +0 -0
- package/dist/esm-node/types/config/html.js +0 -0
- package/dist/esm-node/types/config/index.js +1 -0
- package/dist/esm-node/types/config/output.js +0 -0
- package/dist/esm-node/types/config/performance.js +0 -0
- package/dist/esm-node/types/config/security.js +0 -0
- package/dist/esm-node/types/config/source.js +0 -0
- package/dist/esm-node/types/config/testing.js +0 -0
- package/dist/esm-node/types/config/tools.js +0 -0
- package/dist/esm-node/types/hooks.js +0 -0
- package/dist/esm-node/types/index.js +3 -0
- package/dist/esm-node/types/legacyConfig/deploy.js +0 -0
- package/dist/esm-node/types/legacyConfig/dev.js +0 -0
- package/dist/esm-node/types/legacyConfig/index.js +0 -0
- package/dist/esm-node/types/legacyConfig/output.js +0 -0
- package/dist/esm-node/types/legacyConfig/source.js +0 -0
- package/dist/esm-node/types/legacyConfig/testing.js +0 -0
- package/dist/esm-node/types/legacyConfig/tools.js +0 -0
- package/dist/esm-node/types/utils.js +0 -0
- package/dist/esm-node/utils/config.js +49 -0
- package/dist/esm-node/utils/createServer.js +26 -0
- package/dist/esm-node/utils/env.js +16 -0
- package/dist/esm-node/utils/generateWatchFiles.js +30 -0
- package/dist/esm-node/utils/getSelectedEntries.js +34 -0
- package/dist/esm-node/utils/loadPlugins.js +22 -0
- package/dist/esm-node/utils/printInstructions.js +11 -0
- package/dist/esm-node/utils/register.js +96 -0
- package/dist/esm-node/utils/restart.js +22 -0
- package/dist/esm-node/utils/routes.js +21 -0
- package/dist/esm-node/utils/types.js +0 -0
- package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +1 -1
- package/dist/types/builder/generator/index.d.ts +2 -2
- package/dist/types/builder/shared/builderPlugins/index.d.ts +0 -1
- package/dist/types/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts +1 -1
- package/dist/types/builder/shared/bundlerPlugins/HtmlBottomTemplate.d.ts +1 -1
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -1
- package/dist/types/builder/shared/loaders/serverModuleLoader.d.ts +1 -1
- package/dist/types/builder/shared/types.d.ts +1 -1
- package/dist/types/commands/build.d.ts +1 -1
- package/dist/types/commands/dev.d.ts +1 -1
- package/dist/types/commands/inspect.d.ts +1 -1
- package/dist/types/config/default.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugins/analyze/getBundleEntry.d.ts +1 -1
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -1
- package/dist/types/plugins/initialize/index.d.ts +1 -1
- package/dist/types/plugins/serverBuild.d.ts +1 -1
- package/dist/types/types/config/index.d.ts +8 -8
- package/dist/types/types/config/output.d.ts +1 -1
- package/dist/types/types/config/tools.d.ts +3 -3
- package/dist/types/types/hooks.d.ts +2 -2
- package/dist/types/types/index.d.ts +2 -2
- package/dist/types/types/legacyConfig/index.d.ts +3 -3
- package/dist/types/types/legacyConfig/tools.d.ts +1 -1
- package/dist/types/utils/printInstructions.d.ts +1 -1
- package/package.json +20 -20
- package/dist/cjs/builder/shared/builderPlugins/adapterWorker.js +0 -51
- package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +0 -2
@@ -0,0 +1,43 @@
|
|
1
|
+
import { createHtmlConfig } from "./createHtmlConfig";
|
2
|
+
import { createOutputConfig } from "./createOutputConfig";
|
3
|
+
import { createSourceConfig } from "./createSourceConfig";
|
4
|
+
import { createToolsConfig } from "./createToolsConfig";
|
5
|
+
function transformNormalizedConfig(config) {
|
6
|
+
const html = createHtmlConfig(config);
|
7
|
+
const output = createOutputConfig(config);
|
8
|
+
const source = createSourceConfig(config);
|
9
|
+
const tools = createToolsConfig(config);
|
10
|
+
const { bff, dev, deploy, runtime, runtimeByEntries, server, cliOptions, plugins, testing, autoLoadPlugins } = config;
|
11
|
+
return {
|
12
|
+
source,
|
13
|
+
html,
|
14
|
+
output,
|
15
|
+
tools,
|
16
|
+
bff,
|
17
|
+
dev,
|
18
|
+
deploy,
|
19
|
+
runtime,
|
20
|
+
runtimeByEntries,
|
21
|
+
server,
|
22
|
+
cliOptions,
|
23
|
+
testing,
|
24
|
+
devtools: {},
|
25
|
+
builderPlugins: [],
|
26
|
+
plugins,
|
27
|
+
security: {},
|
28
|
+
_raw: {},
|
29
|
+
experiments: {},
|
30
|
+
environments: {},
|
31
|
+
autoLoadPlugins,
|
32
|
+
performance: {
|
33
|
+
removeMomentLocale: true
|
34
|
+
}
|
35
|
+
};
|
36
|
+
}
|
37
|
+
function checkIsLegacyConfig(config) {
|
38
|
+
return Boolean(config.legacy);
|
39
|
+
}
|
40
|
+
export {
|
41
|
+
checkIsLegacyConfig,
|
42
|
+
transformNormalizedConfig
|
43
|
+
};
|
@@ -0,0 +1,13 @@
|
|
1
|
+
const defineConfig = (config) => config;
|
2
|
+
const defineLegacyConfig = (config) => {
|
3
|
+
var _config_autoLoadPlugins;
|
4
|
+
return {
|
5
|
+
...config,
|
6
|
+
legacy: true,
|
7
|
+
autoLoadPlugins: (_config_autoLoadPlugins = config.autoLoadPlugins) !== null && _config_autoLoadPlugins !== void 0 ? _config_autoLoadPlugins : true
|
8
|
+
};
|
9
|
+
};
|
10
|
+
export {
|
11
|
+
defineConfig,
|
12
|
+
defineLegacyConfig
|
13
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { pathToFileURL } from 'url';
|
2
|
+
import { createMatchPath } from './utils.mjs';
|
3
|
+
|
4
|
+
let matchPath;
|
5
|
+
export async function initialize({ appDir, alias, tsconfigPath }) {
|
6
|
+
matchPath = createMatchPath({
|
7
|
+
alias,
|
8
|
+
appDir,
|
9
|
+
tsconfigPath,
|
10
|
+
});
|
11
|
+
}
|
12
|
+
|
13
|
+
export function resolve(specifier, context, defaultResolve) {
|
14
|
+
const match = matchPath(specifier);
|
15
|
+
return match
|
16
|
+
? defaultResolve(pathToFileURL(match).href, context)
|
17
|
+
: defaultResolve(specifier, context);
|
18
|
+
}
|
19
|
+
|
20
|
+
export { load } from 'esbuild-register/loader';
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import assert from 'node:assert';
|
2
|
+
import path from 'node:path';
|
3
|
+
import { fs, isVersionAtLeast1819, readTsConfigByFile } from '@modern-js/utils';
|
4
|
+
|
5
|
+
const checkDep = async dep => {
|
6
|
+
try {
|
7
|
+
await import(dep);
|
8
|
+
return true;
|
9
|
+
} catch (error) {
|
10
|
+
return false;
|
11
|
+
}
|
12
|
+
};
|
13
|
+
|
14
|
+
export const registerEsm = async ({ appDir, distDir, alias }) => {
|
15
|
+
const nodeVersion = process.versions.node;
|
16
|
+
const versionArr = nodeVersion.split('.').map(Number);
|
17
|
+
|
18
|
+
assert(
|
19
|
+
isVersionAtLeast1819(nodeVersion),
|
20
|
+
`The node version of the esm project must be greater than 18.19.0, current version is ${nodeVersion}`,
|
21
|
+
);
|
22
|
+
const hasTsNode = await checkDep('ts-node');
|
23
|
+
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
24
|
+
const tsconfigPath = path.resolve(appDir, TS_CONFIG_FILENAME);
|
25
|
+
const hasTsconfig = await fs.pathExists(tsconfigPath);
|
26
|
+
const { register } = await import('node:module');
|
27
|
+
if (hasTsNode && hasTsconfig) {
|
28
|
+
// These can be overridden by ts-node options in tsconfig.json
|
29
|
+
process.env.TS_NODE_TRANSPILE_ONLY = true;
|
30
|
+
process.env.TS_NODE_PROJECT = tsconfigPath;
|
31
|
+
process.env.TS_NODE_SCOPE = true;
|
32
|
+
process.env.TS_NODE_FILES = true;
|
33
|
+
process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${path.relative(
|
34
|
+
appDir,
|
35
|
+
distDir,
|
36
|
+
)}/`;
|
37
|
+
register('./ts-node-loader.mjs', import.meta.url, {
|
38
|
+
data: {
|
39
|
+
appDir,
|
40
|
+
distDir,
|
41
|
+
alias,
|
42
|
+
tsconfigPath,
|
43
|
+
},
|
44
|
+
});
|
45
|
+
} else {
|
46
|
+
process.env.MODERN_NODE_LOADER = 'esbuild';
|
47
|
+
let tsConfig = {};
|
48
|
+
if (hasTsconfig) {
|
49
|
+
tsConfig = readTsConfigByFile(tsconfigPath);
|
50
|
+
}
|
51
|
+
const esbuildRegister = await import('esbuild-register/dist/node');
|
52
|
+
esbuildRegister.register({
|
53
|
+
tsconfigRaw: hasTsconfig ? tsConfig : undefined,
|
54
|
+
hookIgnoreNodeModules: true,
|
55
|
+
hookMatcher: fileName => !fileName.startsWith(distDir),
|
56
|
+
});
|
57
|
+
register('./esbuild-loader.mjs', import.meta.url, {
|
58
|
+
data: {
|
59
|
+
appDir,
|
60
|
+
distDir,
|
61
|
+
alias,
|
62
|
+
tsconfigPath,
|
63
|
+
},
|
64
|
+
});
|
65
|
+
}
|
66
|
+
};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { pathToFileURL } from 'url';
|
2
|
+
import { resolve as tsNodeResolve } from 'ts-node/esm';
|
3
|
+
import { createMatchPath } from './utils.mjs';
|
4
|
+
|
5
|
+
let matchPath;
|
6
|
+
export async function initialize({ appDir, alias, tsconfigPath }) {
|
7
|
+
matchPath = createMatchPath({
|
8
|
+
alias,
|
9
|
+
appDir,
|
10
|
+
tsconfigPath,
|
11
|
+
});
|
12
|
+
}
|
13
|
+
|
14
|
+
export function resolve(specifier, context, defaultResolve) {
|
15
|
+
const match = matchPath(specifier);
|
16
|
+
return match
|
17
|
+
? tsNodeResolve(pathToFileURL(match).href, context, defaultResolve)
|
18
|
+
: tsNodeResolve(specifier, context, defaultResolve);
|
19
|
+
}
|
20
|
+
|
21
|
+
export { transformSource, load } from 'ts-node/esm';
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { createRequire } from 'module';
|
2
|
+
import path from 'path';
|
3
|
+
import { getAliasConfig } from '@modern-js/utils';
|
4
|
+
import tsConfigPaths from '@modern-js/utils/tsconfig-paths';
|
5
|
+
|
6
|
+
const require = createRequire(import.meta.url);
|
7
|
+
export function createMatchPath({ alias, appDir, tsconfigPath }) {
|
8
|
+
const aliasConfig = getAliasConfig(alias, {
|
9
|
+
appDirectory: appDir,
|
10
|
+
tsconfigPath,
|
11
|
+
});
|
12
|
+
|
13
|
+
const { paths = {}, absoluteBaseUrl = './' } = aliasConfig;
|
14
|
+
|
15
|
+
const tsPaths = Object.keys(paths).reduce((o, key) => {
|
16
|
+
let tsPath = paths[key];
|
17
|
+
// Do some special handling for Modern.js's internal alias, we can drop it in the next version
|
18
|
+
if (
|
19
|
+
typeof tsPath === 'string' &&
|
20
|
+
key.startsWith('@') &&
|
21
|
+
tsPath.startsWith('@')
|
22
|
+
) {
|
23
|
+
try {
|
24
|
+
tsPath = require.resolve(tsPath, {
|
25
|
+
paths: [appDir],
|
26
|
+
});
|
27
|
+
} catch {}
|
28
|
+
}
|
29
|
+
|
30
|
+
if (typeof tsPath === 'string' && path.isAbsolute(tsPath)) {
|
31
|
+
tsPath = path.relative(absoluteBaseUrl, tsPath);
|
32
|
+
}
|
33
|
+
if (typeof tsPath === 'string') {
|
34
|
+
tsPath = [tsPath];
|
35
|
+
}
|
36
|
+
return {
|
37
|
+
...o,
|
38
|
+
[`${key}`]: tsPath,
|
39
|
+
};
|
40
|
+
}, {});
|
41
|
+
|
42
|
+
return tsConfigPaths.createMatchPath(absoluteBaseUrl, tsPaths);
|
43
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { createAsyncWaterfall, createAsyncWorkflow, createParallelWorkflow } from "@modern-js/plugin";
|
2
|
+
const hooks = {
|
3
|
+
_internalRuntimePlugins: createAsyncWaterfall(),
|
4
|
+
modifyFileSystemRoutes: createAsyncWaterfall(),
|
5
|
+
modifyServerRoutes: createAsyncWaterfall(),
|
6
|
+
/** add entry point info to entrypoints array */
|
7
|
+
modifyEntrypoints: createAsyncWaterfall(),
|
8
|
+
/** add entry type */
|
9
|
+
checkEntryPoint: createAsyncWaterfall(),
|
10
|
+
generateEntryCode: createAsyncWorkflow(),
|
11
|
+
htmlPartials: createAsyncWaterfall(),
|
12
|
+
beforeGenerateRoutes: createAsyncWaterfall(),
|
13
|
+
addDefineTypes: createAsyncWaterfall(),
|
14
|
+
collectServerPlugins: createAsyncWaterfall(),
|
15
|
+
_internalServerPlugins: createAsyncWaterfall(),
|
16
|
+
beforeDev: createAsyncWorkflow(),
|
17
|
+
afterDev: createAsyncWorkflow(),
|
18
|
+
beforeCreateCompiler: createAsyncWorkflow(),
|
19
|
+
afterCreateCompiler: createAsyncWorkflow(),
|
20
|
+
beforePrintInstructions: createAsyncWaterfall(),
|
21
|
+
beforeBuild: createAsyncWorkflow(),
|
22
|
+
afterBuild: createAsyncWorkflow(),
|
23
|
+
beforeDeploy: createAsyncWorkflow(),
|
24
|
+
deploy: createAsyncWorkflow(),
|
25
|
+
afterDeploy: createAsyncWorkflow(),
|
26
|
+
beforeRestart: createAsyncWorkflow(),
|
27
|
+
registerDev: createParallelWorkflow(),
|
28
|
+
beforeDevTask: createParallelWorkflow(),
|
29
|
+
registerBuildPlatform: createParallelWorkflow(),
|
30
|
+
beforeBuildPlatform: createParallelWorkflow()
|
31
|
+
};
|
32
|
+
export {
|
33
|
+
hooks
|
34
|
+
};
|
@@ -0,0 +1,131 @@
|
|
1
|
+
import path from "path";
|
2
|
+
import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
|
3
|
+
import { lintPlugin } from "@modern-js/plugin-lint";
|
4
|
+
import { cleanRequireCache, emptyDir, getArgv, getCommand } from "@modern-js/utils";
|
5
|
+
import { hooks } from "./hooks";
|
6
|
+
import { i18n } from "./locale";
|
7
|
+
import analyzePlugin from "./plugins/analyze";
|
8
|
+
import deployPlugin from "./plugins/deploy";
|
9
|
+
import initializePlugin from "./plugins/initialize";
|
10
|
+
import serverBuildPlugin from "./plugins/serverBuild";
|
11
|
+
import { buildCommand, deployCommand, devCommand, inspectCommand, newCommand, serverCommand, upgradeCommand } from "./commands";
|
12
|
+
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
13
|
+
import { restart } from "./utils/restart";
|
14
|
+
import { dev } from "./commands/dev";
|
15
|
+
import { mergeConfig } from "@modern-js/core";
|
16
|
+
export * from "./defineConfig";
|
17
|
+
export * from "./types";
|
18
|
+
const appTools = (options = {
|
19
|
+
// default webpack to be compatible with original projects
|
20
|
+
bundler: "webpack"
|
21
|
+
}) => ({
|
22
|
+
name: "@modern-js/app-tools",
|
23
|
+
post: [
|
24
|
+
"@modern-js/plugin-initialize",
|
25
|
+
"@modern-js/plugin-analyze",
|
26
|
+
"@modern-js/plugin-ssr",
|
27
|
+
"@modern-js/plugin-document",
|
28
|
+
"@modern-js/plugin-state",
|
29
|
+
"@modern-js/plugin-router",
|
30
|
+
"@modern-js/plugin-router-v5",
|
31
|
+
"@modern-js/plugin-polyfill"
|
32
|
+
],
|
33
|
+
registerHook: hooks,
|
34
|
+
usePlugins: [
|
35
|
+
initializePlugin({
|
36
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
|
37
|
+
"rspack",
|
38
|
+
"experimental-rspack"
|
39
|
+
].includes(options.bundler) ? "rspack" : "webpack"
|
40
|
+
}),
|
41
|
+
analyzePlugin({
|
42
|
+
bundler: (options === null || options === void 0 ? void 0 : options.bundler) && [
|
43
|
+
"rspack",
|
44
|
+
"experimental-rspack"
|
45
|
+
].includes(options.bundler) ? "rspack" : "webpack"
|
46
|
+
}),
|
47
|
+
serverBuildPlugin(),
|
48
|
+
lintPlugin(),
|
49
|
+
deployPlugin()
|
50
|
+
],
|
51
|
+
setup: (api) => {
|
52
|
+
const appContext = api.useAppContext();
|
53
|
+
api.setAppContext({
|
54
|
+
...appContext,
|
55
|
+
toolsType: "app-tools"
|
56
|
+
});
|
57
|
+
const locale = getLocaleLanguage();
|
58
|
+
i18n.changeLanguage({
|
59
|
+
locale
|
60
|
+
});
|
61
|
+
return {
|
62
|
+
async beforeConfig() {
|
63
|
+
var _userConfig_output;
|
64
|
+
const userConfig = api.useConfigContext();
|
65
|
+
const appContext2 = api.useAppContext();
|
66
|
+
if ((_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir) {
|
67
|
+
api.setAppContext({
|
68
|
+
...appContext2,
|
69
|
+
internalDirectory: path.resolve(appContext2.appDirectory, userConfig.output.tempDir)
|
70
|
+
});
|
71
|
+
}
|
72
|
+
},
|
73
|
+
async commands({ program }) {
|
74
|
+
await devCommand(program, api);
|
75
|
+
await buildCommand(program, api);
|
76
|
+
serverCommand(program, api);
|
77
|
+
deployCommand(program, api);
|
78
|
+
newCommand(program, locale);
|
79
|
+
inspectCommand(program, api);
|
80
|
+
upgradeCommand(program);
|
81
|
+
},
|
82
|
+
async prepare() {
|
83
|
+
const command = getCommand();
|
84
|
+
if (command === "deploy") {
|
85
|
+
const isSkipBuild = [
|
86
|
+
"-s",
|
87
|
+
"--skip-build"
|
88
|
+
].some((tag) => {
|
89
|
+
return getArgv().includes(tag);
|
90
|
+
});
|
91
|
+
if (isSkipBuild) {
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
if (command === "dev" || command === "start" || command === "build" || command === "deploy") {
|
96
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
97
|
+
if (resolvedConfig.output.cleanDistPath) {
|
98
|
+
const appContext2 = api.useAppContext();
|
99
|
+
await emptyDir(appContext2.distDirectory);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
},
|
103
|
+
async watchFiles() {
|
104
|
+
const appContext2 = api.useAppContext();
|
105
|
+
const config = api.useResolvedConfigContext();
|
106
|
+
return await generateWatchFiles(appContext2, config.source.configDir);
|
107
|
+
},
|
108
|
+
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
109
|
+
async fileChange(e) {
|
110
|
+
const { filename, eventType, isPrivate } = e;
|
111
|
+
if (!isPrivate && (eventType === "change" || eventType === "unlink")) {
|
112
|
+
const { closeServer } = await import("./utils/createServer.js");
|
113
|
+
await closeServer();
|
114
|
+
await restart(api.useHookRunners(), filename);
|
115
|
+
}
|
116
|
+
},
|
117
|
+
async beforeRestart() {
|
118
|
+
cleanRequireCache([
|
119
|
+
require.resolve("./plugins/analyze")
|
120
|
+
]);
|
121
|
+
}
|
122
|
+
};
|
123
|
+
}
|
124
|
+
});
|
125
|
+
var src_default = appTools;
|
126
|
+
export {
|
127
|
+
appTools,
|
128
|
+
src_default as default,
|
129
|
+
dev,
|
130
|
+
mergeConfig
|
131
|
+
};
|
@@ -0,0 +1,43 @@
|
|
1
|
+
const EN_LOCALE = {
|
2
|
+
command: {
|
3
|
+
shared: {
|
4
|
+
analyze: "analyze bundle size",
|
5
|
+
config: "specify the configuration file, which can be a relative or absolute path",
|
6
|
+
skipBuild: "skip the build phase",
|
7
|
+
noNeedInstall: "not run install command"
|
8
|
+
},
|
9
|
+
dev: {
|
10
|
+
describe: "starting the dev server",
|
11
|
+
entry: "compiler by entry",
|
12
|
+
apiOnly: "start api server only",
|
13
|
+
webOnly: "start web server only",
|
14
|
+
selectEntry: "Please select the entry that needs to be built",
|
15
|
+
requireEntry: "You must choose at least one entry"
|
16
|
+
},
|
17
|
+
build: {
|
18
|
+
describe: "build the app for production"
|
19
|
+
},
|
20
|
+
serve: {
|
21
|
+
describe: "preview the production build locally"
|
22
|
+
},
|
23
|
+
deploy: {
|
24
|
+
describe: "deploy the application"
|
25
|
+
},
|
26
|
+
new: {
|
27
|
+
describe: "enable optional features or add a new entry",
|
28
|
+
debug: "using debug mode to log something",
|
29
|
+
config: "set default generator config(json string)",
|
30
|
+
distTag: `use specified tag version for it's generator`,
|
31
|
+
registry: "set npm registry url to run npm command",
|
32
|
+
lang: "set new command language(en or zh)"
|
33
|
+
},
|
34
|
+
inspect: {
|
35
|
+
env: "specify env mode",
|
36
|
+
output: "specify inspect content output path",
|
37
|
+
verbose: "show full function definitions in output"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
};
|
41
|
+
export {
|
42
|
+
EN_LOCALE
|
43
|
+
};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { I18n } from "@modern-js/plugin-i18n";
|
2
|
+
import { EN_LOCALE } from "./en";
|
3
|
+
import { ZH_LOCALE } from "./zh";
|
4
|
+
const i18n = new I18n();
|
5
|
+
const localeKeys = i18n.init("en", {
|
6
|
+
zh: ZH_LOCALE,
|
7
|
+
en: EN_LOCALE
|
8
|
+
});
|
9
|
+
export {
|
10
|
+
i18n,
|
11
|
+
localeKeys
|
12
|
+
};
|
@@ -0,0 +1,43 @@
|
|
1
|
+
const ZH_LOCALE = {
|
2
|
+
command: {
|
3
|
+
shared: {
|
4
|
+
analyze: "分析构建产物体积,查看各个模块打包后的大小",
|
5
|
+
config: "指定配置文件路径,可以为相对路径或绝对路径",
|
6
|
+
skipBuild: "跳过构建阶段",
|
7
|
+
noNeedInstall: "无需安装依赖"
|
8
|
+
},
|
9
|
+
dev: {
|
10
|
+
describe: "启动开发服务器",
|
11
|
+
entry: "指定入口,编译特定的页面",
|
12
|
+
apiOnly: "仅启动 API 接口服务",
|
13
|
+
webOnly: "仅启动 Web 服务",
|
14
|
+
selectEntry: "请选择需要构建的入口",
|
15
|
+
requireEntry: "请至少选择一个入口"
|
16
|
+
},
|
17
|
+
build: {
|
18
|
+
describe: "构建生产环境产物"
|
19
|
+
},
|
20
|
+
serve: {
|
21
|
+
describe: "启动生产环境服务"
|
22
|
+
},
|
23
|
+
deploy: {
|
24
|
+
describe: "部署应用"
|
25
|
+
},
|
26
|
+
new: {
|
27
|
+
describe: "Web App 项目中执行生成器",
|
28
|
+
debug: "开启 Debug 模式,打印调试日志信息",
|
29
|
+
config: "生成器运行默认配置(JSON 字符串)",
|
30
|
+
distTag: "生成器使用特殊的 npm Tag 版本",
|
31
|
+
registry: "生成器运行过程中定制 npm Registry",
|
32
|
+
lang: "设置 new 命令执行语言(zh 或者 en)"
|
33
|
+
},
|
34
|
+
inspect: {
|
35
|
+
env: "查看指定环境下的配置",
|
36
|
+
output: "指定在 dist 目录下输出的路径",
|
37
|
+
verbose: "在结果中展示函数的完整内容"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
};
|
41
|
+
export {
|
42
|
+
ZH_LOCALE
|
43
|
+
};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
const INDEX_FILE_NAME = "index";
|
2
|
+
const ENTRY_FILE_NAME = "entry";
|
3
|
+
const HTML_PARTIALS_FOLDER = "html";
|
4
|
+
const HTML_PARTIALS_EXTENSIONS = [
|
5
|
+
".htm",
|
6
|
+
".html",
|
7
|
+
".ejs"
|
8
|
+
];
|
9
|
+
export {
|
10
|
+
ENTRY_FILE_NAME,
|
11
|
+
HTML_PARTIALS_EXTENSIONS,
|
12
|
+
HTML_PARTIALS_FOLDER,
|
13
|
+
INDEX_FILE_NAME
|
14
|
+
};
|
@@ -0,0 +1,61 @@
|
|
1
|
+
import path from "path";
|
2
|
+
import { fs, JS_EXTENSIONS, MAIN_ENTRY_NAME, ensureAbsolutePath, findExists } from "@modern-js/utils";
|
3
|
+
import { getFileSystemEntry } from "./getFileSystemEntry";
|
4
|
+
import { isSubDirOrEqual } from "./utils";
|
5
|
+
const ensureExtensions = (file) => {
|
6
|
+
if (!path.extname(file)) {
|
7
|
+
return findExists(JS_EXTENSIONS.map((ext) => `${file}${ext}`)) || file;
|
8
|
+
}
|
9
|
+
return file;
|
10
|
+
};
|
11
|
+
const isDirectory = (file) => !path.extname(file);
|
12
|
+
const ifAlreadyExists = (entrypoints, checked) => entrypoints.some((entrypoint) => {
|
13
|
+
if (ensureExtensions(entrypoint.entry) === ensureExtensions(checked.entry)) {
|
14
|
+
checked.entryName = entrypoint.entryName;
|
15
|
+
return true;
|
16
|
+
}
|
17
|
+
if (isSubDirOrEqual(entrypoint.entry, checked.entry) || isSubDirOrEqual(checked.entry, entrypoint.entry)) {
|
18
|
+
throw new Error(`Entry configuration conflicts
|
19
|
+
Your configuration: ${checked.entry}.
|
20
|
+
Default entrypoint: ${entrypoint.entry}
|
21
|
+
Please reset source.entries or set source.disableDefaultEntries to disable the default entry rules.`);
|
22
|
+
}
|
23
|
+
return false;
|
24
|
+
});
|
25
|
+
const getBundleEntry = async (hookRunners, appContext, config) => {
|
26
|
+
const { appDirectory, packageName } = appContext;
|
27
|
+
const { disableDefaultEntries, entries, entriesDir, mainEntryName } = config.source;
|
28
|
+
const defaults = disableDefaultEntries ? [] : await getFileSystemEntry(hookRunners, appContext, config);
|
29
|
+
if (entries) {
|
30
|
+
Object.keys(entries).forEach((name) => {
|
31
|
+
const value = entries[name];
|
32
|
+
const entryName = typeof value === "string" ? value : value.entry;
|
33
|
+
const isAutoMount = typeof value === "string" ? true : !value.disableMount;
|
34
|
+
const entrypoint = {
|
35
|
+
entryName: name,
|
36
|
+
isMainEntry: false,
|
37
|
+
entry: ensureAbsolutePath(appDirectory, entryName),
|
38
|
+
absoluteEntryDir: isDirectory(ensureAbsolutePath(appDirectory, entryName)) ? ensureAbsolutePath(appDirectory, entryName) : path.dirname(ensureAbsolutePath(appDirectory, entryName)),
|
39
|
+
isAutoMount,
|
40
|
+
customBootstrap: typeof value === "string" ? false : value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
|
41
|
+
fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, entryName)).isDirectory() ? {} : void 0,
|
42
|
+
isCustomSourceEntry: true
|
43
|
+
};
|
44
|
+
if (!ifAlreadyExists(defaults, entrypoint)) {
|
45
|
+
defaults.push(entrypoint);
|
46
|
+
}
|
47
|
+
});
|
48
|
+
}
|
49
|
+
if (!disableDefaultEntries) {
|
50
|
+
const entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir || "");
|
51
|
+
const found = defaults.find(({ entryName, entry, nestedRoutesEntry = "" }) => entryName === packageName || path.dirname(entry) === entriesDirAbs || path.dirname(nestedRoutesEntry) === entriesDirAbs);
|
52
|
+
if (found) {
|
53
|
+
found.entryName = mainEntryName || MAIN_ENTRY_NAME;
|
54
|
+
found.isMainEntry = true;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
return defaults;
|
58
|
+
};
|
59
|
+
export {
|
60
|
+
getBundleEntry
|
61
|
+
};
|
@@ -0,0 +1,106 @@
|
|
1
|
+
import fs from "fs";
|
2
|
+
import path from "path";
|
3
|
+
import { JS_EXTENSIONS, ensureAbsolutePath, findExists } from "@modern-js/utils";
|
4
|
+
import { ENTRY_FILE_NAME, INDEX_FILE_NAME } from "./constants";
|
5
|
+
import { isDefaultExportFunction } from "./isDefaultExportFunction";
|
6
|
+
const hasIndex = (dir) => findExists(JS_EXTENSIONS.map((ext) => path.resolve(dir, `${INDEX_FILE_NAME}${ext}`)));
|
7
|
+
const hasEntry = (dir) => findExists(JS_EXTENSIONS.map((ext) => path.resolve(dir, `${ENTRY_FILE_NAME}${ext}`)));
|
8
|
+
const hasServerEntry = (dir) => findExists(JS_EXTENSIONS.map((ext) => path.resolve(dir, `${ENTRY_FILE_NAME}.server${ext}`)));
|
9
|
+
const isBundleEntry = async (hookRunners, dir, enableCustomEntry) => {
|
10
|
+
const { entry } = await hookRunners.checkEntryPoint({
|
11
|
+
path: dir,
|
12
|
+
entry: false
|
13
|
+
});
|
14
|
+
if (entry) {
|
15
|
+
return entry;
|
16
|
+
}
|
17
|
+
const customEntry = hasEntry(dir);
|
18
|
+
if (enableCustomEntry && customEntry) {
|
19
|
+
return customEntry;
|
20
|
+
}
|
21
|
+
return hasIndex(dir);
|
22
|
+
};
|
23
|
+
const scanDir = async (hookRunners, dirs, enableCustomEntry) => {
|
24
|
+
const entries = await Promise.all(dirs.map(async (dir) => {
|
25
|
+
const indexFile = hasIndex(dir);
|
26
|
+
const customBootstrap = isDefaultExportFunction(indexFile) ? indexFile : false;
|
27
|
+
const entryName = path.basename(dir);
|
28
|
+
const customEntryFile = hasEntry(dir);
|
29
|
+
const customServerEntry = hasServerEntry(dir);
|
30
|
+
if (indexFile && !customBootstrap) {
|
31
|
+
return {
|
32
|
+
entryName,
|
33
|
+
isMainEntry: false,
|
34
|
+
entry: indexFile,
|
35
|
+
absoluteEntryDir: path.resolve(dir),
|
36
|
+
isAutoMount: false,
|
37
|
+
customBootstrap
|
38
|
+
};
|
39
|
+
}
|
40
|
+
const entryFile = (await hookRunners.checkEntryPoint({
|
41
|
+
path: dir,
|
42
|
+
entry: false
|
43
|
+
})).entry;
|
44
|
+
if (entryFile) {
|
45
|
+
return {
|
46
|
+
entryName,
|
47
|
+
isMainEntry: false,
|
48
|
+
entry: enableCustomEntry ? customEntryFile || entryFile : entryFile,
|
49
|
+
customServerEntry,
|
50
|
+
absoluteEntryDir: path.resolve(dir),
|
51
|
+
isAutoMount: true,
|
52
|
+
customBootstrap,
|
53
|
+
customEntry: enableCustomEntry ? Boolean(customEntryFile) : false
|
54
|
+
};
|
55
|
+
}
|
56
|
+
if (enableCustomEntry && customEntryFile) {
|
57
|
+
return {
|
58
|
+
entryName,
|
59
|
+
isMainEntry: false,
|
60
|
+
entry: customEntryFile,
|
61
|
+
customServerEntry,
|
62
|
+
absoluteEntryDir: path.resolve(dir),
|
63
|
+
isAutoMount: false,
|
64
|
+
customEntry: Boolean(customEntryFile)
|
65
|
+
};
|
66
|
+
}
|
67
|
+
return false;
|
68
|
+
})).then((entries2) => entries2.filter(Boolean));
|
69
|
+
if (entries.length === 0) {
|
70
|
+
throw Error("There is no valid entry point in the current project!");
|
71
|
+
}
|
72
|
+
return entries;
|
73
|
+
};
|
74
|
+
const getFileSystemEntry = async (hookRunners, appContext, config) => {
|
75
|
+
const { appDirectory } = appContext;
|
76
|
+
const { source: { entriesDir, disableEntryDirs, enableCustomEntry } } = config;
|
77
|
+
let disabledDirs = [];
|
78
|
+
if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
|
79
|
+
disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map((dir) => ensureAbsolutePath(appDirectory, dir));
|
80
|
+
}
|
81
|
+
const src = ensureAbsolutePath(appDirectory, entriesDir || "");
|
82
|
+
if (fs.existsSync(src)) {
|
83
|
+
if (fs.statSync(src).isDirectory()) {
|
84
|
+
if (await isBundleEntry(hookRunners, src, enableCustomEntry)) {
|
85
|
+
return scanDir(hookRunners, [
|
86
|
+
src
|
87
|
+
], enableCustomEntry);
|
88
|
+
}
|
89
|
+
const dirs = [];
|
90
|
+
await Promise.all(fs.readdirSync(src).map(async (filename) => {
|
91
|
+
const file = path.join(src, filename);
|
92
|
+
if (fs.statSync(file).isDirectory() && await isBundleEntry(hookRunners, file, enableCustomEntry) && !disabledDirs.includes(file)) {
|
93
|
+
dirs.push(file);
|
94
|
+
}
|
95
|
+
}));
|
96
|
+
return scanDir(hookRunners, dirs, enableCustomEntry);
|
97
|
+
} else {
|
98
|
+
throw Error(`source.entriesDir accept a directory.`);
|
99
|
+
}
|
100
|
+
} else {
|
101
|
+
throw Error(`src dir ${entriesDir} not found.`);
|
102
|
+
}
|
103
|
+
};
|
104
|
+
export {
|
105
|
+
getFileSystemEntry
|
106
|
+
};
|