@modern-js/app-tools 2.53.1-alpha.4 → 2.54.1-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/modern.js +0 -2
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/cjs/commands/build.js +2 -0
- package/dist/cjs/commands/deploy.js +2 -2
- package/dist/cjs/commands/dev.js +19 -5
- package/dist/cjs/commands/index.js +113 -7
- package/dist/cjs/commands/serve.js +19 -5
- package/dist/cjs/hooks.js +5 -0
- package/dist/cjs/index.js +14 -83
- package/dist/cjs/plugins/analyze/constants.js +56 -0
- package/dist/cjs/{analyze → plugins/analyze}/generateCode.js +11 -84
- package/dist/cjs/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
- package/dist/cjs/{analyze → plugins/analyze}/getFileSystemEntry.js +33 -47
- package/dist/cjs/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/cjs/{analyze → plugins/analyze}/index.js +9 -24
- package/dist/cjs/plugins/analyze/templates.js +101 -0
- package/dist/cjs/{analyze → plugins/analyze}/utils.js +12 -55
- package/dist/cjs/plugins/deploy/platforms/netlify.js +2 -2
- package/dist/cjs/plugins/deploy/platforms/node.js +2 -2
- package/dist/cjs/plugins/deploy/platforms/vercel.js +2 -2
- package/dist/cjs/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/cjs/plugins/serverBuild.js +10 -4
- package/dist/cjs/utils/createServer.js +1 -1
- package/dist/cjs/utils/{getServerInternalPlugins.js → loadPlugins.js} +18 -11
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +4 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/esm/commands/build.js +16 -9
- package/dist/esm/commands/deploy.js +2 -2
- package/dist/esm/commands/dev.js +13 -9
- package/dist/esm/commands/index.js +411 -3
- package/dist/esm/commands/serve.js +12 -8
- package/dist/esm/hooks.js +5 -0
- package/dist/esm/index.js +12 -394
- package/dist/esm/plugins/analyze/constants.js +24 -0
- package/dist/esm/{analyze → plugins/analyze}/generateCode.js +27 -169
- package/dist/esm/plugins/analyze/getBundleEntry.js +101 -0
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +195 -0
- package/dist/esm/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/esm/{analyze → plugins/analyze}/index.js +42 -70
- package/dist/esm/plugins/analyze/templates.js +22 -0
- package/dist/esm/{analyze → plugins/analyze}/utils.js +13 -135
- package/dist/esm/plugins/deploy/platforms/netlify.js +5 -3
- package/dist/esm/plugins/deploy/platforms/node.js +5 -3
- package/dist/esm/plugins/deploy/platforms/vercel.js +5 -3
- package/dist/esm/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/esm/plugins/serverBuild.js +13 -6
- package/dist/esm/utils/createServer.js +2 -2
- package/dist/esm/utils/loadPlugins.js +64 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/esm-node/commands/build.js +2 -0
- package/dist/esm-node/commands/deploy.js +2 -2
- package/dist/esm-node/commands/dev.js +11 -7
- package/dist/esm-node/commands/index.js +92 -3
- package/dist/esm-node/commands/serve.js +10 -6
- package/dist/esm-node/hooks.js +5 -0
- package/dist/esm-node/index.js +12 -79
- package/dist/esm-node/plugins/analyze/constants.js +24 -0
- package/dist/esm-node/{analyze → plugins/analyze}/generateCode.js +14 -87
- package/dist/esm-node/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +75 -0
- package/dist/esm-node/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/esm-node/{analyze → plugins/analyze}/index.js +10 -25
- package/dist/esm-node/plugins/analyze/templates.js +75 -0
- package/dist/esm-node/{analyze → plugins/analyze}/utils.js +13 -52
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +3 -3
- package/dist/esm-node/plugins/deploy/platforms/node.js +3 -3
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +3 -3
- package/dist/esm-node/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/esm-node/plugins/serverBuild.js +11 -5
- package/dist/esm-node/utils/createServer.js +2 -2
- package/dist/esm-node/utils/loadPlugins.js +21 -0
- package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
- package/dist/types/commands/index.d.ts +10 -3
- package/dist/types/config/initialize/inits.d.ts +1 -1
- package/dist/types/exports/server.d.ts +4 -0
- package/dist/types/index.d.ts +2 -5
- package/dist/types/plugins/analyze/constants.d.ts +9 -0
- package/dist/types/{analyze → plugins/analyze}/generateCode.d.ts +1 -1
- package/dist/types/plugins/analyze/getBundleEntry.d.ts +4 -0
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +5 -0
- package/dist/types/{analyze → plugins/analyze}/getHtmlTemplate.d.ts +1 -1
- package/dist/types/{analyze → plugins/analyze}/getServerRoutes.d.ts +1 -1
- package/dist/types/{analyze → plugins/analyze}/index.d.ts +1 -1
- package/dist/types/plugins/analyze/templates.d.ts +19 -0
- package/dist/types/{analyze → plugins/analyze}/utils.d.ts +4 -6
- package/dist/types/{initialize → plugins/initialize}/index.d.ts +1 -1
- package/dist/types/types/hooks.d.ts +11 -1
- package/dist/types/utils/loadPlugins.d.ts +5 -0
- package/package.json +22 -22
- package/dist/cjs/analyze/constants.js +0 -122
- package/dist/cjs/analyze/getClientRoutes/getRoutes.js +0 -197
- package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +0 -195
- package/dist/cjs/analyze/getClientRoutes/index.js +0 -31
- package/dist/cjs/analyze/getClientRoutes/utils.js +0 -59
- package/dist/cjs/analyze/makeLegalIdentifier.js +0 -37
- package/dist/cjs/analyze/nestedRoutes.js +0 -295
- package/dist/cjs/analyze/templates.js +0 -444
- package/dist/esm/analyze/constants.js +0 -76
- package/dist/esm/analyze/getBundleEntry.js +0 -75
- package/dist/esm/analyze/getClientRoutes/getRoutes.js +0 -185
- package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +0 -183
- package/dist/esm/analyze/getClientRoutes/index.js +0 -6
- package/dist/esm/analyze/getClientRoutes/utils.js +0 -28
- package/dist/esm/analyze/getFileSystemEntry.js +0 -113
- package/dist/esm/analyze/makeLegalIdentifier.js +0 -15
- package/dist/esm/analyze/nestedRoutes.js +0 -398
- package/dist/esm/analyze/templates.js +0 -435
- package/dist/esm/utils/getServerInternalPlugins.js +0 -40
- package/dist/esm-node/analyze/constants.js +0 -76
- package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +0 -163
- package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +0 -161
- package/dist/esm-node/analyze/getClientRoutes/index.js +0 -6
- package/dist/esm-node/analyze/getClientRoutes/utils.js +0 -22
- package/dist/esm-node/analyze/getFileSystemEntry.js +0 -89
- package/dist/esm-node/analyze/makeLegalIdentifier.js +0 -13
- package/dist/esm-node/analyze/nestedRoutes.js +0 -259
- package/dist/esm-node/analyze/templates.js +0 -405
- package/dist/esm-node/utils/getServerInternalPlugins.js +0 -15
- package/dist/types/analyze/constants.d.ts +0 -42
- package/dist/types/analyze/getBundleEntry.d.ts +0 -3
- package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +0 -8
- package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +0 -9
- package/dist/types/analyze/getClientRoutes/index.d.ts +0 -2
- package/dist/types/analyze/getClientRoutes/utils.d.ts +0 -5
- package/dist/types/analyze/getFileSystemEntry.d.ts +0 -4
- package/dist/types/analyze/makeLegalIdentifier.d.ts +0 -1
- package/dist/types/analyze/nestedRoutes.d.ts +0 -7
- package/dist/types/analyze/templates.d.ts +0 -30
- package/dist/types/utils/getServerInternalPlugins.d.ts +0 -2
- /package/dist/cjs/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/cjs/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/esm/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/esm/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/esm-node/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/esm-node/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/types/{analyze → plugins/analyze}/isDefaultExportFunction.d.ts +0 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
import fs from "fs";
|
2
|
+
import path from "path";
|
3
|
+
import { findExists, ensureAbsolutePath, JS_EXTENSIONS } from "@modern-js/utils";
|
4
|
+
import { 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 isBundleEntry = async (hookRunners, dir) => {
|
8
|
+
return (await hookRunners.checkEntryPoint({
|
9
|
+
path: dir,
|
10
|
+
entry: false
|
11
|
+
})).entry || hasIndex(dir);
|
12
|
+
};
|
13
|
+
const scanDir = (hookRunners, dirs) => Promise.all(dirs.map(async (dir) => {
|
14
|
+
const indexFile = hasIndex(dir);
|
15
|
+
const customBootstrap = isDefaultExportFunction(indexFile) ? indexFile : false;
|
16
|
+
const entryName = path.basename(dir);
|
17
|
+
if (indexFile && !customBootstrap) {
|
18
|
+
return {
|
19
|
+
entryName,
|
20
|
+
isMainEntry: false,
|
21
|
+
entry: indexFile,
|
22
|
+
absoluteEntryDir: path.resolve(dir),
|
23
|
+
isAutoMount: false,
|
24
|
+
customBootstrap
|
25
|
+
};
|
26
|
+
}
|
27
|
+
const entryFile = (await hookRunners.checkEntryPoint({
|
28
|
+
path: dir,
|
29
|
+
entry: false
|
30
|
+
})).entry;
|
31
|
+
if (entryFile) {
|
32
|
+
return {
|
33
|
+
entryName,
|
34
|
+
isMainEntry: false,
|
35
|
+
entry: entryFile,
|
36
|
+
absoluteEntryDir: path.resolve(dir),
|
37
|
+
isAutoMount: true,
|
38
|
+
customBootstrap
|
39
|
+
};
|
40
|
+
}
|
41
|
+
throw Error("There is no valid entry point in the current project!");
|
42
|
+
}));
|
43
|
+
const getFileSystemEntry = async (hookRunners, appContext, config) => {
|
44
|
+
const { appDirectory } = appContext;
|
45
|
+
const { source: { entriesDir, disableEntryDirs } } = config;
|
46
|
+
let disabledDirs = [];
|
47
|
+
if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
|
48
|
+
disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map((dir) => ensureAbsolutePath(appDirectory, dir));
|
49
|
+
}
|
50
|
+
const src = ensureAbsolutePath(appDirectory, entriesDir || "");
|
51
|
+
if (fs.existsSync(src)) {
|
52
|
+
if (fs.statSync(src).isDirectory()) {
|
53
|
+
if (await isBundleEntry(hookRunners, src)) {
|
54
|
+
return scanDir(hookRunners, [
|
55
|
+
src
|
56
|
+
]);
|
57
|
+
}
|
58
|
+
const dirs = [];
|
59
|
+
await Promise.all(fs.readdirSync(src).map(async (filename) => {
|
60
|
+
const file = path.join(src, filename);
|
61
|
+
if (fs.statSync(file).isDirectory() && await isBundleEntry(hookRunners, file) && !disabledDirs.includes(file)) {
|
62
|
+
dirs.push(file);
|
63
|
+
}
|
64
|
+
}));
|
65
|
+
return scanDir(hookRunners, dirs);
|
66
|
+
} else {
|
67
|
+
throw Error(`source.entriesDir accept a directory.`);
|
68
|
+
}
|
69
|
+
} else {
|
70
|
+
throw Error(`src dir ${entriesDir} not found.`);
|
71
|
+
}
|
72
|
+
};
|
73
|
+
export {
|
74
|
+
getFileSystemEntry
|
75
|
+
};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import path from "path";
|
2
2
|
import fs from "fs";
|
3
3
|
import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
|
4
|
-
import { isMainEntry } from "
|
4
|
+
import { isMainEntry } from "../../utils/routes";
|
5
5
|
import { walkDirectory } from "./utils";
|
6
6
|
const applyBaseUrl = (baseUrl, routes) => {
|
7
7
|
if (baseUrl) {
|
@@ -1,13 +1,12 @@
|
|
1
1
|
import * as path from "path";
|
2
2
|
import { createDebugger, findExists, fs, isApiOnly, minimist, isDevCommand, getArgv } from "@modern-js/utils";
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
import {
|
9
|
-
import {
|
10
|
-
import { checkIsBuildCommands, isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
|
3
|
+
import { printInstructions } from "../../utils/printInstructions";
|
4
|
+
import { generateRoutes, getPathWithoutExt } from "../../utils/routes";
|
5
|
+
import { emitResolvedConfig } from "../../utils/config";
|
6
|
+
import { getSelectedEntries } from "../../utils/getSelectedEntries";
|
7
|
+
import { initialNormalizedConfig } from "../../config";
|
8
|
+
import { createBuilderGenerator } from "../../builder";
|
9
|
+
import { checkIsBuildCommands, parseModule, replaceWithAlias } from "./utils";
|
11
10
|
import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
|
12
11
|
import { generateIndexCode } from "./generateCode";
|
13
12
|
const debug = createDebugger("plugin-analyze");
|
@@ -16,7 +15,6 @@ var analyze_default = ({ bundler }) => ({
|
|
16
15
|
setup: (api) => {
|
17
16
|
let pagesDir = [];
|
18
17
|
let nestedRouteEntries = [];
|
19
|
-
let originEntrypoints = [];
|
20
18
|
return {
|
21
19
|
async prepare() {
|
22
20
|
var _resolvedConfig_source;
|
@@ -50,7 +48,9 @@ var analyze_default = ({ bundler }) => ({
|
|
50
48
|
import("./generateCode"),
|
51
49
|
import("./getHtmlTemplate")
|
52
50
|
]);
|
53
|
-
const entrypoints =
|
51
|
+
const { entrypoints } = await hookRunners.modifyEntrypoints({
|
52
|
+
entrypoints: await getBundleEntry(hookRunners, appContext, resolvedConfig)
|
53
|
+
});
|
54
54
|
debug(`entrypoints: %o`, entrypoints);
|
55
55
|
const initialRoutes = getServerRoutes(entrypoints, {
|
56
56
|
appContext,
|
@@ -68,7 +68,6 @@ var analyze_default = ({ bundler }) => ({
|
|
68
68
|
api.setAppContext(appContext);
|
69
69
|
nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
70
70
|
pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
|
71
|
-
originEntrypoints = cloneDeep(entrypoints);
|
72
71
|
const { importsStatemets } = await generateCode(appContext, resolvedConfig, entrypoints, api);
|
73
72
|
const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
|
74
73
|
appContext,
|
@@ -212,20 +211,6 @@ var analyze_default = ({ bundler }) => ({
|
|
212
211
|
entrypoint,
|
213
212
|
imports
|
214
213
|
};
|
215
|
-
},
|
216
|
-
async fileChange(e) {
|
217
|
-
const appContext = api.useAppContext();
|
218
|
-
const { appDirectory } = appContext;
|
219
|
-
const { filename, eventType } = e;
|
220
|
-
const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
|
221
|
-
const absoluteFilePath = path.resolve(appDirectory, filename);
|
222
|
-
const isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
|
223
|
-
if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
|
224
|
-
const resolvedConfig = api.useResolvedConfigContext();
|
225
|
-
const { generateCode } = await import("./generateCode");
|
226
|
-
const entrypoints = cloneDeep(originEntrypoints);
|
227
|
-
generateCode(appContext, resolvedConfig, entrypoints, api);
|
228
|
-
}
|
229
214
|
}
|
230
215
|
};
|
231
216
|
}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { APP_CONFIG_NAME } from "./constants";
|
2
|
+
const index = ({ mountId, imports, renderFunction: renderFunction2, exportStatement }) => `
|
3
|
+
const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
|
4
|
+
const IS_REACT18 = process.env.IS_REACT18 === 'true';
|
5
|
+
const MOUNT_ID = '${mountId}';
|
6
|
+
|
7
|
+
${imports}
|
8
|
+
|
9
|
+
let AppWrapper = null;
|
10
|
+
|
11
|
+
let root = null;
|
12
|
+
|
13
|
+
function render() {
|
14
|
+
${renderFunction2}
|
15
|
+
}
|
16
|
+
|
17
|
+
AppWrapper = render();
|
18
|
+
|
19
|
+
${exportStatement};
|
20
|
+
`;
|
21
|
+
const renderFunction = ({ plugins, customBootstrap, fileSystemRoutes, customRuntimeConfig }) => {
|
22
|
+
const bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
|
23
|
+
const runtimePlugins = `...(runtimeConfig?.plugins || []),`;
|
24
|
+
return `
|
25
|
+
const finalAppConfig = {
|
26
|
+
...App.config,
|
27
|
+
...typeof ${APP_CONFIG_NAME} === 'function' ? ${APP_CONFIG_NAME}() : {},
|
28
|
+
}
|
29
|
+
|
30
|
+
AppWrapper = createApp({
|
31
|
+
plugins: [
|
32
|
+
${plugins.map(({ name, options, args }) => `${name}({...${options}, ...finalAppConfig?.${args || name}}),`).join("\n")}
|
33
|
+
${customRuntimeConfig ? runtimePlugins : ""}
|
34
|
+
]
|
35
|
+
})(${fileSystemRoutes ? "" : `App`})
|
36
|
+
|
37
|
+
|
38
|
+
if(!AppWrapper.init && typeof appInit !== 'undefined') {
|
39
|
+
AppWrapper.init = appInit;
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
if (IS_BROWSER) {
|
44
|
+
${customBootstrap ? `customBootstrap(AppWrapper, () => ${bootstrap});` : `${bootstrap};`}
|
45
|
+
}
|
46
|
+
|
47
|
+
return AppWrapper
|
48
|
+
`;
|
49
|
+
};
|
50
|
+
const html = (partials) => `
|
51
|
+
<!DOCTYPE html>
|
52
|
+
<html>
|
53
|
+
<head>
|
54
|
+
|
55
|
+
${partials.top.join("\n")}
|
56
|
+
|
57
|
+
${partials.head.join("\n")}
|
58
|
+
|
59
|
+
</head>
|
60
|
+
|
61
|
+
<body>
|
62
|
+
<div id="<%= mountId %>"><!--<?- html ?>--></div>
|
63
|
+
${partials.body.join("\n")}
|
64
|
+
<!--<?- chunksMap.js ?>-->
|
65
|
+
<!--<?- SSRDataScript ?>-->
|
66
|
+
<!--<?- bottomTemplate ?>-->
|
67
|
+
</body>
|
68
|
+
|
69
|
+
</html>
|
70
|
+
`;
|
71
|
+
export {
|
72
|
+
html,
|
73
|
+
index,
|
74
|
+
renderFunction
|
75
|
+
};
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import fs from "fs";
|
2
2
|
import path from "path";
|
3
|
-
import { isReact18, normalizeToPosixPath,
|
3
|
+
import { isReact18, normalizeToPosixPath, getCommand, JS_EXTENSIONS } from "@modern-js/utils";
|
4
4
|
import { transform } from "esbuild";
|
5
5
|
import { parse } from "es-module-lexer";
|
6
|
-
import {
|
6
|
+
import { FILE_SYSTEM_ROUTES_FILE_NAME } from "./constants";
|
7
7
|
const walkDirectory = (dir) => fs.readdirSync(dir).reduce((previous, filename) => {
|
8
8
|
const filePath = path.join(dir, filename);
|
9
9
|
if (fs.statSync(filePath).isDirectory()) {
|
@@ -18,7 +18,7 @@ const walkDirectory = (dir) => fs.readdirSync(dir).reduce((previous, filename) =
|
|
18
18
|
];
|
19
19
|
}
|
20
20
|
}, []);
|
21
|
-
const getDefaultImports = ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias }) => {
|
21
|
+
const getDefaultImports = ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias, runtimeConfigFile, customRuntimeConfig }) => {
|
22
22
|
const { entryName, fileSystemRoutes, customBootstrap, entry } = entrypoint;
|
23
23
|
const imports = [
|
24
24
|
{
|
@@ -89,21 +89,17 @@ const getDefaultImports = ({ entrypoint, srcDirectory, appDirectory, internalSrc
|
|
89
89
|
value: normalizeToPosixPath(entry.replace(srcDirectory, internalSrcAlias))
|
90
90
|
});
|
91
91
|
}
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
".ts",
|
102
|
-
".tsx"
|
103
|
-
].includes(path.extname(filePath))) {
|
104
|
-
return true;
|
92
|
+
if (customRuntimeConfig) {
|
93
|
+
imports.push({
|
94
|
+
specifiers: [
|
95
|
+
{
|
96
|
+
local: "runtimeConfig"
|
97
|
+
}
|
98
|
+
],
|
99
|
+
value: path.join(internalSrcAlias, runtimeConfigFile || "")
|
100
|
+
});
|
105
101
|
}
|
106
|
-
return
|
102
|
+
return imports;
|
107
103
|
};
|
108
104
|
const replaceWithAlias = (base, filePath, alias) => {
|
109
105
|
if (filePath.includes(base)) {
|
@@ -123,37 +119,6 @@ const parseModule = async ({ source, filename }) => {
|
|
123
119
|
}
|
124
120
|
return await parse(content);
|
125
121
|
};
|
126
|
-
const hasLoader = async (filename, source) => {
|
127
|
-
let content = source;
|
128
|
-
if (!source) {
|
129
|
-
content = (await fse.readFile(filename, "utf-8")).toString();
|
130
|
-
}
|
131
|
-
if (content) {
|
132
|
-
const [, moduleExports] = await parseModule({
|
133
|
-
source: content.toString(),
|
134
|
-
filename
|
135
|
-
});
|
136
|
-
return moduleExports.some((e) => e.n === LOADER_EXPORT_NAME);
|
137
|
-
}
|
138
|
-
return false;
|
139
|
-
};
|
140
|
-
const hasAction = async (filename, source) => {
|
141
|
-
let content = source;
|
142
|
-
if (!source) {
|
143
|
-
content = (await fse.readFile(filename, "utf-8")).toString();
|
144
|
-
}
|
145
|
-
if (content) {
|
146
|
-
const [, moduleExports] = await parseModule({
|
147
|
-
source: content.toString(),
|
148
|
-
filename
|
149
|
-
});
|
150
|
-
return moduleExports.some((e) => e.n === ACTION_EXPORT_NAME);
|
151
|
-
}
|
152
|
-
return false;
|
153
|
-
};
|
154
|
-
const getServerLoadersFile = (internalDirectory, entryName) => {
|
155
|
-
return path.join(internalDirectory, entryName, "route-server-loaders.js");
|
156
|
-
};
|
157
122
|
const getServerCombinedModueFile = (internalDirectory, entryName) => {
|
158
123
|
return path.join(internalDirectory, entryName, "server-loader-combined.js");
|
159
124
|
};
|
@@ -181,10 +146,6 @@ export {
|
|
181
146
|
checkIsBuildCommands,
|
182
147
|
getDefaultImports,
|
183
148
|
getServerCombinedModueFile,
|
184
|
-
getServerLoadersFile,
|
185
|
-
hasAction,
|
186
|
-
hasLoader,
|
187
|
-
isPageComponentFile,
|
188
149
|
isSubDirOrEqual,
|
189
150
|
parseModule,
|
190
151
|
replaceWithAlias,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import path from "node:path";
|
2
|
-
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse
|
2
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
|
3
3
|
import { isMainEntry } from "../../../utils/routes";
|
4
4
|
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
5
5
|
import { handleDependencies } from "../dependencies";
|
@@ -17,8 +17,8 @@ async function cleanDistDirectory(dir) {
|
|
17
17
|
}
|
18
18
|
}
|
19
19
|
const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
20
|
-
const { appDirectory, distDirectory,
|
21
|
-
const plugins =
|
20
|
+
const { appDirectory, distDirectory, entrypoints, serverPlugins } = appContext;
|
21
|
+
const plugins = serverPlugins.map((plugin) => plugin.name);
|
22
22
|
const netlifyOutput = path.join(appDirectory, ".netlify");
|
23
23
|
const funcsDirectory = path.join(netlifyOutput, "functions");
|
24
24
|
const entryFilePath = path.join(funcsDirectory, "index.js");
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import path from "node:path";
|
2
|
-
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse,
|
2
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, chalk } from "@modern-js/utils";
|
3
3
|
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
4
4
|
import { handleDependencies } from "../dependencies";
|
5
5
|
const createNodePreset = (appContext, config) => {
|
6
|
-
const { appDirectory, distDirectory,
|
7
|
-
const plugins =
|
6
|
+
const { appDirectory, distDirectory, serverPlugins } = appContext;
|
7
|
+
const plugins = serverPlugins.map((plugin) => plugin.name);
|
8
8
|
const outputDirectory = path.join(appDirectory, ".output");
|
9
9
|
const staticDirectory = path.join(outputDirectory, "static");
|
10
10
|
const entryFilePath = path.join(outputDirectory, "index.js");
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import path from "node:path";
|
2
|
-
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse
|
2
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse } from "@modern-js/utils";
|
3
3
|
import { isMainEntry } from "../../../utils/routes";
|
4
4
|
import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
|
5
5
|
import { handleDependencies } from "../dependencies";
|
6
6
|
const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
7
|
-
const { appDirectory, distDirectory,
|
8
|
-
const plugins =
|
7
|
+
const { appDirectory, distDirectory, entrypoints, serverPlugins } = appContext;
|
8
|
+
const plugins = serverPlugins.map((plugin) => plugin.name);
|
9
9
|
const vercelOutput = path.join(appDirectory, ".vercel");
|
10
10
|
const outputDirectory = path.join(vercelOutput, "output");
|
11
11
|
const funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ensureAbsolutePath, getPort, isDev, isDevCommand } from "@modern-js/utils";
|
2
|
-
import { checkIsLegacyConfig, createDefaultConfig, createLegacyDefaultConfig, transformNormalizedConfig } from "
|
2
|
+
import { checkIsLegacyConfig, createDefaultConfig, createLegacyDefaultConfig, transformNormalizedConfig } from "../../config";
|
3
3
|
var initialize_default = ({ bundler }) => ({
|
4
4
|
name: "@modern-js/plugin-initialize",
|
5
5
|
post: [
|
@@ -1,11 +1,17 @@
|
|
1
1
|
import path from "path";
|
2
2
|
import fs from "fs";
|
3
|
-
import { SERVER_DIR, SHARED_DIR } from "@modern-js/utils";
|
3
|
+
import { SERVER_DIR, SHARED_DIR, getMeta } from "@modern-js/utils";
|
4
4
|
import { compile } from "@modern-js/server-utils";
|
5
5
|
const TS_CONFIG_FILENAME = "tsconfig.json";
|
6
6
|
function checkHasCache(appDir) {
|
7
|
-
const tsFilepath = path.resolve(appDir,
|
8
|
-
const jsfilepath = path.resolve(appDir,
|
7
|
+
const tsFilepath = path.resolve(appDir, SERVER_DIR, "cache.ts");
|
8
|
+
const jsfilepath = path.resolve(appDir, SERVER_DIR, "cache.js");
|
9
|
+
return fs.existsSync(tsFilepath) || fs.existsSync(jsfilepath);
|
10
|
+
}
|
11
|
+
function checkHasConfig(appDir, metaName = "modern-js") {
|
12
|
+
const meta = getMeta(metaName);
|
13
|
+
const tsFilepath = path.resolve(appDir, SERVER_DIR, `${meta}.server.ts`);
|
14
|
+
const jsfilepath = path.resolve(appDir, SERVER_DIR, `${meta}.server.js`);
|
9
15
|
return fs.existsSync(tsFilepath) || fs.existsSync(jsfilepath);
|
10
16
|
}
|
11
17
|
var serverBuild_default = () => ({
|
@@ -13,8 +19,8 @@ var serverBuild_default = () => ({
|
|
13
19
|
setup(api) {
|
14
20
|
return {
|
15
21
|
async afterBuild() {
|
16
|
-
const { appDirectory, distDirectory } = api.useAppContext();
|
17
|
-
if (!checkHasCache(appDirectory)) {
|
22
|
+
const { appDirectory, distDirectory, metaName } = api.useAppContext();
|
23
|
+
if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
|
18
24
|
return;
|
19
25
|
}
|
20
26
|
const modernConfig = api.useResolvedConfigContext();
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { createDevServer } from "@modern-js/server";
|
2
|
-
import {
|
2
|
+
import { applyPlugins } from "@modern-js/prod-server";
|
3
3
|
let server = null;
|
4
4
|
const getServer = () => server;
|
5
5
|
const setServer = (newServer) => {
|
@@ -15,7 +15,7 @@ const createServer = async (options) => {
|
|
15
15
|
if (server) {
|
16
16
|
server.close();
|
17
17
|
}
|
18
|
-
server = await createDevServer(options,
|
18
|
+
server = await createDevServer(options, applyPlugins);
|
19
19
|
return server;
|
20
20
|
};
|
21
21
|
export {
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { loadServerPlugins as loadServerPluginInstances } from "@modern-js/prod-server";
|
2
|
+
async function getServerPlugins(api) {
|
3
|
+
const runner = api.useHookRunners();
|
4
|
+
const { plugins } = await runner._internalServerPlugins({
|
5
|
+
plugins: []
|
6
|
+
});
|
7
|
+
api.setAppContext({
|
8
|
+
...api.useAppContext(),
|
9
|
+
serverPlugins: plugins
|
10
|
+
});
|
11
|
+
return plugins;
|
12
|
+
}
|
13
|
+
async function loadServerPlugins(api, appDirectory) {
|
14
|
+
const plugins = await getServerPlugins(api);
|
15
|
+
const instances = loadServerPluginInstances(plugins, appDirectory);
|
16
|
+
return instances;
|
17
|
+
}
|
18
|
+
export {
|
19
|
+
getServerPlugins,
|
20
|
+
loadServerPlugins
|
21
|
+
};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/// <reference types="node" />
|
2
|
-
import { CopyPluginOptions,
|
2
|
+
import { CopyPluginOptions, RspackChain } from '@modern-js/uni-builder';
|
3
3
|
import type { AppNormalizedConfig, Bundler, IAppContext } from '../../types';
|
4
|
-
export declare function createPublicPattern(appContext: IAppContext, config: AppNormalizedConfig, chain:
|
4
|
+
export declare function createPublicPattern(appContext: IAppContext, config: AppNormalizedConfig, chain: RspackChain): {
|
5
5
|
info: (file: {
|
6
6
|
sourceFilename: string;
|
7
7
|
}) => {
|
@@ -1,3 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
import { PluginAPI } from '@modern-js/core';
|
2
|
+
import { Command } from '@modern-js/utils';
|
3
|
+
import { AppTools } from '../types';
|
4
|
+
export declare const devCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => Promise<void>;
|
5
|
+
export declare const buildCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => Promise<void>;
|
6
|
+
export declare const serverCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => void;
|
7
|
+
export declare const deployCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => void;
|
8
|
+
export declare const newCommand: (program: Command, locale: string) => void;
|
9
|
+
export declare const inspectCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => void;
|
10
|
+
export declare const upgradeCommand: (program: Command) => void;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { AppNormalizedConfig, IAppContext } from '../../types';
|
2
2
|
export declare function initHtmlConfig(config: AppNormalizedConfig<'shared'>, appContext: IAppContext): AppNormalizedConfig<'shared'>['html'];
|
3
3
|
export declare function initSourceConfig(config: AppNormalizedConfig<'shared'>, appContext: IAppContext, bundler: 'webpack' | 'rspack'): void;
|
4
|
-
export declare function createBuilderModuleScope(config: AppNormalizedConfig<'webpack'>):
|
4
|
+
export declare function createBuilderModuleScope(config: AppNormalizedConfig<'webpack'>): (string | RegExp)[] | undefined;
|
@@ -1 +1,5 @@
|
|
1
|
+
import { UnstableMiddleware, UnstableMiddlewareContext, UnstableNext } from '@modern-js/types';
|
2
|
+
export type RenderMiddleware = UnstableMiddleware;
|
3
|
+
export type RenderMiddlewareContext = UnstableMiddlewareContext;
|
4
|
+
export type RenderNext = UnstableNext;
|
1
5
|
export { defineServerConfig as defineConfig } from '../utils/config';
|
package/dist/types/index.d.ts
CHANGED
@@ -1,13 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
import { CliPlugin, PluginAPI } from '@modern-js/core';
|
1
|
+
import { CliPlugin } from '@modern-js/core';
|
3
2
|
import { AppTools } from './types';
|
3
|
+
export { dev } from './commands/dev';
|
4
4
|
export { mergeConfig } from '@modern-js/core';
|
5
|
-
export { dev } from './commands';
|
6
5
|
export * from './defineConfig';
|
7
6
|
export * from './types';
|
8
7
|
export type { RuntimeUserConfig } from './types/config';
|
9
|
-
export declare const devCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => Promise<void>;
|
10
|
-
export declare const buildCommand: (program: Command, api: PluginAPI<AppTools<'shared'>>) => Promise<void>;
|
11
8
|
export type AppToolsOptions = {
|
12
9
|
/**
|
13
10
|
* Specify which bundler to use for the build.
|
@@ -0,0 +1,9 @@
|
|
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";
|
5
|
+
export declare const HTML_PARTIALS_FOLDER = "html";
|
6
|
+
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,7 +1,7 @@
|
|
1
1
|
import { IAppContext, PluginAPI } from '@modern-js/core';
|
2
2
|
import type { Entrypoint } from '@modern-js/types';
|
3
3
|
import { RspackConfig, WebpackConfig } from '@rsbuild/shared';
|
4
|
-
import { AppNormalizedConfig, AppTools, ImportStatement } from '
|
4
|
+
import { AppNormalizedConfig, AppTools, ImportStatement } from '../../types';
|
5
5
|
export declare const createImportStatements: (statements: ImportStatement[]) => string;
|
6
6
|
export declare const generateCode: (appContext: IAppContext, config: AppNormalizedConfig<'shared'>, entrypoints: Entrypoint[], api: PluginAPI<AppTools<'shared'>>) => Promise<{
|
7
7
|
importsStatemets: Map<string, ImportStatement[]>;
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import type { Entrypoint } from '@modern-js/types';
|
2
|
+
import { CliHooksRunner } from '@modern-js/core';
|
3
|
+
import type { AppNormalizedConfig, AppTools, IAppContext } from '../../types';
|
4
|
+
export declare const getBundleEntry: (hookRunners: CliHooksRunner<AppTools<'shared'>>, appContext: IAppContext, config: AppNormalizedConfig<'shared'>) => Promise<Entrypoint[]>;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import type { Entrypoint } from '@modern-js/types';
|
2
|
+
import { CliHooksRunner } from '@modern-js/core';
|
3
|
+
import type { AppNormalizedConfig, AppTools, IAppContext } from '../../types';
|
4
|
+
export type { Entrypoint };
|
5
|
+
export declare const getFileSystemEntry: (hookRunners: CliHooksRunner<AppTools<'shared'>>, appContext: IAppContext, config: AppNormalizedConfig<'shared'>) => Promise<Entrypoint[]>;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { Entrypoint, HtmlTemplates } from '@modern-js/types';
|
2
|
-
import type { AppNormalizedConfig, AppTools, IAppContext, PluginAPI } from '
|
2
|
+
import type { AppNormalizedConfig, AppTools, IAppContext, PluginAPI } from '../../types';
|
3
3
|
export declare const getHtmlTemplate: (entrypoints: Entrypoint[], api: PluginAPI<AppTools<'shared'>>, { appContext, config, }: {
|
4
4
|
appContext: IAppContext;
|
5
5
|
config: AppNormalizedConfig<'shared'>;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { IAppContext } from '@modern-js/core';
|
2
2
|
import type { Entrypoint, ServerRoute } from '@modern-js/types';
|
3
|
-
import type { AppNormalizedConfig } from '
|
3
|
+
import type { AppNormalizedConfig } from '../../types';
|
4
4
|
export declare const getServerRoutes: (entrypoints: Entrypoint[], { appContext, config, }: {
|
5
5
|
appContext: IAppContext;
|
6
6
|
config: AppNormalizedConfig<'shared'>;
|
@@ -0,0 +1,19 @@
|
|
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
|
+
export declare const html: (partials: {
|
16
|
+
top: string[];
|
17
|
+
head: string[];
|
18
|
+
body: string[];
|
19
|
+
}) => string;
|
@@ -1,22 +1,20 @@
|
|
1
1
|
import type { Entrypoint } from '@modern-js/types';
|
2
|
-
import type { ImportStatement } from '
|
2
|
+
import type { ImportStatement } from '../../types';
|
3
3
|
export declare const walkDirectory: (dir: string) => string[];
|
4
|
-
export declare const getDefaultImports: ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias, }: {
|
4
|
+
export declare const getDefaultImports: ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias, runtimeConfigFile, customRuntimeConfig, }: {
|
5
5
|
entrypoint: Entrypoint;
|
6
6
|
srcDirectory: string;
|
7
7
|
appDirectory: string;
|
8
8
|
internalSrcAlias: string;
|
9
9
|
internalDirAlias: string;
|
10
|
+
runtimeConfigFile: string | false;
|
11
|
+
customRuntimeConfig: string | false;
|
10
12
|
}) => ImportStatement[];
|
11
|
-
export declare const isPageComponentFile: (filePath: string) => boolean;
|
12
13
|
export declare const replaceWithAlias: (base: string, filePath: string, alias: string) => string;
|
13
14
|
export declare const parseModule: ({ source, filename, }: {
|
14
15
|
source: string;
|
15
16
|
filename: string;
|
16
17
|
}) => Promise<readonly [imports: readonly import("es-module-lexer").ImportSpecifier[], exports: readonly import("es-module-lexer").ExportSpecifier[], facade: boolean]>;
|
17
|
-
export declare const hasLoader: (filename: string, source?: string) => Promise<boolean>;
|
18
|
-
export declare const hasAction: (filename: string, source?: string) => Promise<boolean>;
|
19
|
-
export declare const getServerLoadersFile: (internalDirectory: string, entryName: string) => string;
|
20
18
|
export declare const getServerCombinedModueFile: (internalDirectory: string, entryName: string) => string;
|
21
19
|
export declare const checkIsBuildCommands: () => boolean;
|
22
20
|
export declare const isSubDirOrEqual: (parent: string, child: string) => boolean;
|