@modern-js/app-tools 2.4.0 → 2.5.0-alpha.0
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/CHANGELOG.md +59 -0
- package/dist/cjs/analyze/constants.js +100 -0
- package/dist/cjs/analyze/generateCode.js +251 -0
- package/dist/cjs/analyze/getBundleEntry.js +101 -0
- package/dist/cjs/analyze/getClientRoutes/getRoutes.js +225 -0
- package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +221 -0
- package/dist/cjs/analyze/getClientRoutes/index.js +30 -0
- package/dist/cjs/analyze/getClientRoutes/utils.js +58 -0
- package/dist/cjs/analyze/getFileSystemEntry.js +131 -0
- package/dist/cjs/analyze/getHtmlTemplate.js +124 -0
- package/dist/cjs/analyze/getServerRoutes.js +174 -0
- package/dist/cjs/analyze/index.js +294 -0
- package/dist/cjs/analyze/isDefaultExportFunction.js +71 -0
- package/dist/cjs/analyze/makeLegalIdentifier.js +36 -0
- package/dist/cjs/analyze/nestedRoutes.js +179 -0
- package/dist/cjs/analyze/templates.js +330 -0
- package/dist/cjs/analyze/utils.js +152 -0
- package/dist/cjs/builder/builder-rspack/index.js +31 -0
- package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/cjs/builder/builder-webpack/index.js +78 -0
- package/dist/cjs/builder/builder-webpack/webpackPlugins/RouterPlugin.js +120 -0
- package/dist/cjs/builder/builder-webpack/webpackPlugins/index.js +17 -0
- package/dist/cjs/builder/generator/createBuilderOptions.js +47 -0
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +49 -0
- package/dist/cjs/builder/generator/getBuilderTargets.js +39 -0
- package/dist/cjs/builder/generator/index.js +58 -0
- package/dist/cjs/builder/index.js +46 -0
- package/dist/cjs/builder/shared/builderPlugins/adapterModern.js +230 -0
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +50 -0
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +57 -0
- package/dist/cjs/builder/shared/createCopyPattern.js +75 -0
- package/dist/cjs/builder/shared/index.js +19 -0
- package/dist/cjs/builder/shared/loaders/serverModuleLoader.js +28 -0
- package/dist/cjs/builder/shared/types.js +15 -0
- package/dist/cjs/commands/build.js +75 -0
- package/dist/cjs/commands/deploy.js +31 -0
- package/dist/cjs/commands/dev.js +91 -0
- package/dist/cjs/commands/index.js +19 -0
- package/dist/cjs/commands/inspect.js +41 -0
- package/dist/cjs/commands/serve.js +63 -0
- package/dist/cjs/config/default.js +186 -0
- package/dist/cjs/config/index.js +19 -0
- package/dist/cjs/config/initialize/index.js +35 -0
- package/dist/cjs/config/initialize/inits.js +161 -0
- package/dist/cjs/config/legacy/createHtmlConfig.js +58 -0
- package/dist/cjs/config/legacy/createOutputConfig.js +91 -0
- package/dist/cjs/config/legacy/createSourceConfig.js +62 -0
- package/dist/cjs/config/legacy/createToolsConfig.js +65 -0
- package/dist/cjs/config/legacy/index.js +75 -0
- package/dist/cjs/defineConfig.js +33 -0
- package/dist/cjs/exports/server.js +27 -0
- package/dist/cjs/hooks.js +54 -0
- package/dist/cjs/index.js +198 -0
- package/dist/cjs/initialize/index.js +102 -0
- package/dist/cjs/locale/en.js +59 -0
- package/dist/cjs/locale/index.js +33 -0
- package/dist/cjs/locale/zh.js +59 -0
- package/dist/cjs/schema/Schema.js +63 -0
- package/dist/cjs/schema/index.js +118 -0
- package/dist/cjs/schema/legacy.js +169 -0
- package/dist/cjs/types/config/deploy.js +15 -0
- package/dist/cjs/types/config/dev.js +15 -0
- package/dist/cjs/types/config/experiments.js +15 -0
- package/dist/cjs/types/config/html.js +15 -0
- package/dist/cjs/types/config/index.js +17 -0
- package/dist/cjs/types/config/output.js +15 -0
- package/dist/cjs/types/config/performance.js +15 -0
- package/dist/cjs/types/config/security.js +15 -0
- package/dist/cjs/types/config/source.js +15 -0
- package/dist/cjs/types/config/tools.js +15 -0
- package/dist/cjs/types/hooks.js +15 -0
- package/dist/cjs/types/index.js +19 -0
- package/dist/cjs/types/legacyConfig/deploy.js +15 -0
- package/dist/cjs/types/legacyConfig/dev.js +15 -0
- package/dist/cjs/types/legacyConfig/index.js +15 -0
- package/dist/cjs/types/legacyConfig/output.js +15 -0
- package/dist/cjs/types/legacyConfig/source.js +15 -0
- package/dist/cjs/types/legacyConfig/tools.js +15 -0
- package/dist/cjs/types/utils.js +15 -0
- package/dist/cjs/utils/config.js +115 -0
- package/dist/cjs/utils/createServer.js +70 -0
- package/dist/cjs/utils/env.js +38 -0
- package/dist/cjs/utils/generateWatchFiles.js +63 -0
- package/dist/cjs/utils/getSelectedEntries.js +61 -0
- package/dist/cjs/utils/getServerInternalPlugins.js +41 -0
- package/dist/cjs/utils/language.js +31 -0
- package/dist/cjs/utils/printInstructions.js +34 -0
- package/dist/cjs/utils/restart.js +45 -0
- package/dist/cjs/utils/routes.js +39 -0
- package/dist/cjs/utils/types.js +15 -0
- package/dist/esm/analyze/constants.js +42 -0
- package/dist/esm/analyze/generateCode.js +486 -0
- package/dist/esm/analyze/getBundleEntry.js +64 -0
- package/dist/esm/analyze/getClientRoutes/getRoutes.js +233 -0
- package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +231 -0
- package/dist/esm/analyze/getClientRoutes/index.js +3 -0
- package/dist/esm/analyze/getClientRoutes/utils.js +23 -0
- package/dist/esm/analyze/getFileSystemEntry.js +107 -0
- package/dist/esm/analyze/getHtmlTemplate.js +302 -0
- package/dist/esm/analyze/getServerRoutes.js +224 -0
- package/dist/esm/analyze/index.js +703 -0
- package/dist/esm/analyze/isDefaultExportFunction.js +47 -0
- package/dist/esm/analyze/makeLegalIdentifier.js +13 -0
- package/dist/esm/analyze/nestedRoutes.js +409 -0
- package/dist/esm/analyze/templates.js +466 -0
- package/dist/esm/analyze/utils.js +374 -0
- package/dist/esm/builder/builder-rspack/index.js +6 -0
- package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/esm/builder/builder-webpack/index.js +301 -0
- package/dist/esm/builder/builder-webpack/webpackPlugins/RouterPlugin.js +346 -0
- package/dist/esm/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/esm/builder/generator/createBuilderOptions.js +41 -0
- package/dist/esm/builder/generator/createBuilderProviderConfig.js +70 -0
- package/dist/esm/builder/generator/getBuilderTargets.js +16 -0
- package/dist/esm/builder/generator/index.js +199 -0
- package/dist/esm/builder/index.js +175 -0
- package/dist/esm/builder/shared/builderPlugins/adapterModern.js +300 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +110 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +72 -0
- package/dist/esm/builder/shared/createCopyPattern.js +40 -0
- package/dist/esm/builder/shared/index.js +3 -0
- package/dist/esm/builder/shared/loaders/serverModuleLoader.js +5 -0
- package/dist/esm/builder/shared/types.js +1 -0
- package/dist/esm/commands/build.js +291 -0
- package/dist/esm/commands/deploy.js +154 -0
- package/dist/esm/commands/dev.js +301 -0
- package/dist/esm/commands/index.js +3 -0
- package/dist/esm/commands/inspect.js +149 -0
- package/dist/esm/commands/serve.js +199 -0
- package/dist/esm/config/default.js +210 -0
- package/dist/esm/config/index.js +3 -0
- package/dist/esm/config/initialize/index.js +10 -0
- package/dist/esm/config/initialize/inits.js +211 -0
- package/dist/esm/config/legacy/createHtmlConfig.js +19 -0
- package/dist/esm/config/legacy/createOutputConfig.js +41 -0
- package/dist/esm/config/legacy/createSourceConfig.js +42 -0
- package/dist/esm/config/legacy/createToolsConfig.js +23 -0
- package/dist/esm/config/legacy/index.js +38 -0
- package/dist/esm/defineConfig.js +61 -0
- package/dist/esm/exports/server.js +2 -0
- package/dist/esm/hooks.js +29 -0
- package/dist/esm/index.js +713 -0
- package/dist/esm/initialize/index.js +284 -0
- package/dist/esm/locale/en.js +38 -0
- package/dist/esm/locale/index.js +9 -0
- package/dist/esm/locale/zh.js +38 -0
- package/dist/esm/schema/Schema.js +273 -0
- package/dist/esm/schema/index.js +181 -0
- package/dist/esm/schema/legacy.js +337 -0
- package/dist/esm/types/config/deploy.js +1 -0
- package/dist/esm/types/config/dev.js +1 -0
- package/dist/esm/types/config/experiments.js +1 -0
- package/dist/esm/types/config/html.js +1 -0
- package/dist/esm/types/config/index.js +1 -0
- package/dist/esm/types/config/output.js +1 -0
- package/dist/esm/types/config/performance.js +1 -0
- package/dist/esm/types/config/security.js +1 -0
- package/dist/esm/types/config/source.js +1 -0
- package/dist/esm/types/config/tools.js +1 -0
- package/dist/esm/types/hooks.js +1 -0
- package/dist/esm/types/index.js +3 -0
- package/dist/esm/types/legacyConfig/deploy.js +1 -0
- package/dist/esm/types/legacyConfig/dev.js +1 -0
- package/dist/esm/types/legacyConfig/index.js +1 -0
- package/dist/esm/types/legacyConfig/output.js +1 -0
- package/dist/esm/types/legacyConfig/source.js +1 -0
- package/dist/esm/types/legacyConfig/tools.js +1 -0
- package/dist/esm/types/utils.js +1 -0
- package/dist/esm/utils/config.js +302 -0
- package/dist/esm/utils/createServer.js +258 -0
- package/dist/esm/utils/env.js +13 -0
- package/dist/esm/utils/generateWatchFiles.js +214 -0
- package/dist/esm/utils/getSelectedEntries.js +186 -0
- package/dist/esm/utils/getServerInternalPlugins.js +210 -0
- package/dist/esm/utils/language.js +6 -0
- package/dist/esm/utils/printInstructions.js +152 -0
- package/dist/esm/utils/restart.js +187 -0
- package/dist/esm/utils/routes.js +153 -0
- package/dist/esm/utils/types.js +1 -0
- package/dist/esm-node/analyze/constants.js +56 -0
- package/dist/esm-node/analyze/generateCode.js +227 -0
- package/dist/esm-node/analyze/getBundleEntry.js +77 -0
- package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +201 -0
- package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +197 -0
- package/dist/esm-node/analyze/getClientRoutes/index.js +6 -0
- package/dist/esm-node/analyze/getClientRoutes/utils.js +31 -0
- package/dist/esm-node/analyze/getFileSystemEntry.js +109 -0
- package/dist/esm-node/analyze/getHtmlTemplate.js +95 -0
- package/dist/esm-node/analyze/getServerRoutes.js +154 -0
- package/dist/esm-node/analyze/index.js +285 -0
- package/dist/esm-node/analyze/isDefaultExportFunction.js +42 -0
- package/dist/esm-node/analyze/makeLegalIdentifier.js +13 -0
- package/dist/esm-node/analyze/nestedRoutes.js +150 -0
- package/dist/esm-node/analyze/templates.js +297 -0
- package/dist/esm-node/analyze/utils.js +121 -0
- package/dist/esm-node/builder/builder-rspack/index.js +8 -0
- package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
- package/dist/esm-node/builder/builder-webpack/index.js +51 -0
- package/dist/esm-node/builder/builder-webpack/webpackPlugins/RouterPlugin.js +96 -0
- package/dist/esm-node/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/esm-node/builder/generator/createBuilderOptions.js +24 -0
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +26 -0
- package/dist/esm-node/builder/generator/getBuilderTargets.js +21 -0
- package/dist/esm-node/builder/generator/index.js +29 -0
- package/dist/esm-node/builder/index.js +17 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterModern.js +202 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
- package/dist/esm-node/builder/shared/createCopyPattern.js +46 -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 +52 -0
- package/dist/esm-node/commands/deploy.js +8 -0
- package/dist/esm-node/commands/dev.js +72 -0
- package/dist/esm-node/commands/index.js +3 -0
- package/dist/esm-node/commands/inspect.js +18 -0
- package/dist/esm-node/commands/serve.js +34 -0
- package/dist/esm-node/config/default.js +162 -0
- package/dist/esm-node/config/index.js +3 -0
- package/dist/esm-node/config/initialize/index.js +12 -0
- package/dist/esm-node/config/initialize/inits.js +136 -0
- package/dist/esm-node/config/legacy/createHtmlConfig.js +35 -0
- package/dist/esm-node/config/legacy/createOutputConfig.js +68 -0
- package/dist/esm-node/config/legacy/createSourceConfig.js +39 -0
- package/dist/esm-node/config/legacy/createToolsConfig.js +42 -0
- package/dist/esm-node/config/legacy/index.js +51 -0
- package/dist/esm-node/defineConfig.js +9 -0
- package/dist/esm-node/exports/server.js +4 -0
- package/dist/esm-node/hooks.js +35 -0
- package/dist/esm-node/index.js +172 -0
- package/dist/esm-node/initialize/index.js +91 -0
- package/dist/esm-node/locale/en.js +36 -0
- package/dist/esm-node/locale/index.js +9 -0
- package/dist/esm-node/locale/zh.js +36 -0
- package/dist/esm-node/schema/Schema.js +40 -0
- package/dist/esm-node/schema/index.js +88 -0
- package/dist/esm-node/schema/legacy.js +148 -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/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/tools.js +0 -0
- package/dist/esm-node/types/utils.js +0 -0
- package/dist/esm-node/utils/config.js +88 -0
- package/dist/esm-node/utils/createServer.js +37 -0
- package/dist/esm-node/utils/env.js +15 -0
- package/dist/esm-node/utils/generateWatchFiles.js +33 -0
- package/dist/esm-node/utils/getSelectedEntries.js +38 -0
- package/dist/esm-node/utils/getServerInternalPlugins.js +18 -0
- package/dist/esm-node/utils/language.js +8 -0
- package/dist/esm-node/utils/printInstructions.js +11 -0
- package/dist/esm-node/utils/restart.js +22 -0
- package/dist/esm-node/utils/routes.js +10 -0
- package/dist/esm-node/utils/types.js +0 -0
- package/dist/js/modern/analyze/nestedRoutes.js +1 -10
- package/dist/js/node/analyze/nestedRoutes.js +1 -10
- package/dist/js/treeshaking/analyze/nestedRoutes.js +1 -10
- package/dist/types/analyze/templates.d.ts +3 -1
- package/dist/types/types/config/tools.d.ts +1 -1
- package/dist/types/types/hooks.d.ts +5 -4
- package/dist/types/types/index.d.ts +3 -1
- package/package.json +30 -31
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import { bundle } from "@modern-js/node-bundle-require";
|
|
3
|
+
import {
|
|
4
|
+
CONFIG_FILE_EXTENSIONS,
|
|
5
|
+
fs,
|
|
6
|
+
getServerConfig,
|
|
7
|
+
OUTPUT_CONFIG_FILE
|
|
8
|
+
} from "@modern-js/utils";
|
|
9
|
+
const defineServerConfig = (config) => config;
|
|
10
|
+
const buildServerConfig = async ({
|
|
11
|
+
appDirectory,
|
|
12
|
+
distDirectory,
|
|
13
|
+
configFile,
|
|
14
|
+
options
|
|
15
|
+
}) => {
|
|
16
|
+
const configFilePath = await getServerConfig(appDirectory, configFile);
|
|
17
|
+
const getOutputFile = async (filepath) => path.resolve(
|
|
18
|
+
distDirectory,
|
|
19
|
+
`${filepath.replace(
|
|
20
|
+
new RegExp(CONFIG_FILE_EXTENSIONS.join("|")),
|
|
21
|
+
""
|
|
22
|
+
)}.js`
|
|
23
|
+
);
|
|
24
|
+
if (configFilePath) {
|
|
25
|
+
const configHelperFilePath = path.normalize(
|
|
26
|
+
path.join(distDirectory, "./config-helper.js")
|
|
27
|
+
);
|
|
28
|
+
const helperCode = `
|
|
29
|
+
export const defineConfig = (config) => config;
|
|
30
|
+
`;
|
|
31
|
+
await fs.ensureDir(distDirectory);
|
|
32
|
+
await fs.writeFile(configHelperFilePath, helperCode);
|
|
33
|
+
await bundle(configFilePath, {
|
|
34
|
+
...options,
|
|
35
|
+
getOutputFile,
|
|
36
|
+
esbuildPlugins: [
|
|
37
|
+
{
|
|
38
|
+
name: "native-build-config",
|
|
39
|
+
setup(ctx) {
|
|
40
|
+
ctx.onResolve(
|
|
41
|
+
{
|
|
42
|
+
filter: /app-tools\/server/
|
|
43
|
+
},
|
|
44
|
+
() => {
|
|
45
|
+
return {
|
|
46
|
+
path: configHelperFilePath
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const safeReplacer = () => {
|
|
57
|
+
const cache = [];
|
|
58
|
+
const keyCache = [];
|
|
59
|
+
return function(key, value) {
|
|
60
|
+
if (typeof value === "object" && value !== null) {
|
|
61
|
+
const index = cache.indexOf(value);
|
|
62
|
+
if (index !== -1) {
|
|
63
|
+
return `[Circular ${keyCache[index]}]`;
|
|
64
|
+
}
|
|
65
|
+
cache.push(value);
|
|
66
|
+
keyCache.push(key || "root");
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
|
|
72
|
+
var _a;
|
|
73
|
+
const outputPath = path.join(
|
|
74
|
+
appDirectory,
|
|
75
|
+
((_a = resolvedConfig.output.distPath) == null ? void 0 : _a.root) || "./dist",
|
|
76
|
+
OUTPUT_CONFIG_FILE
|
|
77
|
+
);
|
|
78
|
+
await fs.writeJSON(outputPath, resolvedConfig, {
|
|
79
|
+
spaces: 2,
|
|
80
|
+
replacer: safeReplacer()
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
export {
|
|
84
|
+
buildServerConfig,
|
|
85
|
+
defineServerConfig,
|
|
86
|
+
emitResolvedConfig,
|
|
87
|
+
safeReplacer
|
|
88
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Server } from "@modern-js/server";
|
|
2
|
+
let server = null;
|
|
3
|
+
const getServer = () => server;
|
|
4
|
+
const setServer = (newServer) => {
|
|
5
|
+
server = newServer;
|
|
6
|
+
};
|
|
7
|
+
const closeServer = async () => {
|
|
8
|
+
if (server) {
|
|
9
|
+
await server.close();
|
|
10
|
+
server = null;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const createServer = async (options) => {
|
|
14
|
+
if (server) {
|
|
15
|
+
await server.close();
|
|
16
|
+
}
|
|
17
|
+
server = new Server(options);
|
|
18
|
+
const app = await server.init();
|
|
19
|
+
return app;
|
|
20
|
+
};
|
|
21
|
+
const injectDataLoaderPlugin = (internalPlugins) => {
|
|
22
|
+
const DataLoaderPlugin = require.resolve("@modern-js/plugin-data-loader/server");
|
|
23
|
+
return {
|
|
24
|
+
...internalPlugins,
|
|
25
|
+
"@modern-js/plugin-data-loader": {
|
|
26
|
+
path: DataLoaderPlugin,
|
|
27
|
+
forced: true
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export {
|
|
32
|
+
closeServer,
|
|
33
|
+
createServer,
|
|
34
|
+
getServer,
|
|
35
|
+
injectDataLoaderPlugin,
|
|
36
|
+
setServer
|
|
37
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function getAutoInjectEnv(appContext) {
|
|
2
|
+
const { metaName } = appContext;
|
|
3
|
+
const prefix = `${metaName.split(/[-_]/)[0]}_`.toUpperCase();
|
|
4
|
+
const envReg = new RegExp(`^${prefix}`);
|
|
5
|
+
return Object.keys(process.env).reduce((prev, key) => {
|
|
6
|
+
const value = process.env[key];
|
|
7
|
+
if (envReg.test(key) && typeof value !== "undefined") {
|
|
8
|
+
prev[`process.env.${key}`] = value;
|
|
9
|
+
}
|
|
10
|
+
return prev;
|
|
11
|
+
}, {});
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
getAutoInjectEnv
|
|
15
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { fs, getServerConfig } from "@modern-js/utils";
|
|
3
|
+
const getPackageConfig = (appDirectory, packageJsonConfig) => {
|
|
4
|
+
const PACKAGE_JSON_CONFIG_NAME = "modernConfig";
|
|
5
|
+
const json = JSON.parse(
|
|
6
|
+
fs.readFileSync(path.resolve(appDirectory, "./package.json"), "utf8")
|
|
7
|
+
);
|
|
8
|
+
return json[packageJsonConfig != null ? packageJsonConfig : PACKAGE_JSON_CONFIG_NAME];
|
|
9
|
+
};
|
|
10
|
+
const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFile) => {
|
|
11
|
+
const serverConfig = await getServerConfig(appDirectory, serverConfigFile);
|
|
12
|
+
if (serverConfig) {
|
|
13
|
+
dependencies.push(serverConfig);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
async function generateWatchFiles(appContext, configDir) {
|
|
17
|
+
const { appDirectory, configFile } = appContext;
|
|
18
|
+
const configPath = path.join(appDirectory, configDir || "");
|
|
19
|
+
const dependencies = getPackageConfig(
|
|
20
|
+
appContext.appDirectory,
|
|
21
|
+
appContext.packageName
|
|
22
|
+
) ? [path.resolve(appDirectory, "./package.json")] : [];
|
|
23
|
+
await addServerConfigToDeps(
|
|
24
|
+
dependencies,
|
|
25
|
+
appContext.appDirectory,
|
|
26
|
+
appContext.serverConfigFile
|
|
27
|
+
);
|
|
28
|
+
return [`${configPath}/html`, configFile || "./config", ...dependencies];
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
addServerConfigToDeps,
|
|
32
|
+
generateWatchFiles
|
|
33
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { chalk, inquirer } from "@modern-js/utils";
|
|
2
|
+
import { i18n, localeKeys } from "../locale";
|
|
3
|
+
const getSelectedEntries = async (entry, entrypoints) => {
|
|
4
|
+
const entryNames = entrypoints.map((e) => e.entryName);
|
|
5
|
+
if (!entry) {
|
|
6
|
+
return entryNames;
|
|
7
|
+
}
|
|
8
|
+
if (typeof entry === "boolean") {
|
|
9
|
+
const { selected } = await inquirer.prompt([
|
|
10
|
+
{
|
|
11
|
+
type: "checkbox",
|
|
12
|
+
name: "selected",
|
|
13
|
+
choices: entryNames,
|
|
14
|
+
message: i18n.t(localeKeys.command.dev.selectEntry),
|
|
15
|
+
validate(answer) {
|
|
16
|
+
if (answer.length < 1) {
|
|
17
|
+
return i18n.t(localeKeys.command.dev.requireEntry);
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
]);
|
|
23
|
+
return selected;
|
|
24
|
+
}
|
|
25
|
+
entry.forEach((name) => {
|
|
26
|
+
if (!entryNames.includes(name)) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Can not found entry ${chalk.yellow(
|
|
29
|
+
name
|
|
30
|
+
)}, the entry should be one of ${chalk.yellow(entryNames.join(", "))}`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return entry;
|
|
35
|
+
};
|
|
36
|
+
export {
|
|
37
|
+
getSelectedEntries
|
|
38
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
async function getServerInternalPlugins(api) {
|
|
2
|
+
const hookRunners = api.useHookRunners();
|
|
3
|
+
const { plugins: serverPlugins } = await hookRunners.collectServerPlugins({
|
|
4
|
+
plugins: []
|
|
5
|
+
});
|
|
6
|
+
const serverInternalPlugins = serverPlugins.reduce(
|
|
7
|
+
(result, plugin) => Object.assign(result, plugin),
|
|
8
|
+
{}
|
|
9
|
+
);
|
|
10
|
+
api.setAppContext({
|
|
11
|
+
...api.useAppContext(),
|
|
12
|
+
serverInternalPlugins
|
|
13
|
+
});
|
|
14
|
+
return serverInternalPlugins;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
getServerInternalPlugins
|
|
18
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { prettyInstructions, logger } from "@modern-js/utils";
|
|
2
|
+
const printInstructions = async (hookRunners, appContext, config) => {
|
|
3
|
+
const message = prettyInstructions(appContext, config);
|
|
4
|
+
const { instructions } = await hookRunners.beforePrintInstructions({
|
|
5
|
+
instructions: message
|
|
6
|
+
});
|
|
7
|
+
logger.info(instructions);
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
printInstructions
|
|
11
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { cli } from "@modern-js/core";
|
|
2
|
+
import { chalk, clearConsole, logger, program } from "@modern-js/utils";
|
|
3
|
+
async function restart(hooksRunner, filename) {
|
|
4
|
+
clearConsole();
|
|
5
|
+
logger.info(`Restart because ${chalk.yellow(filename)} is changed...
|
|
6
|
+
`);
|
|
7
|
+
let hasGetError = false;
|
|
8
|
+
await hooksRunner.beforeRestart();
|
|
9
|
+
try {
|
|
10
|
+
await cli.init(cli.getPrevInitOptions());
|
|
11
|
+
} catch (err) {
|
|
12
|
+
console.error(err);
|
|
13
|
+
hasGetError = true;
|
|
14
|
+
} finally {
|
|
15
|
+
if (!hasGetError) {
|
|
16
|
+
program.parse(process.argv);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
restart
|
|
22
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { fs, ROUTE_SPEC_FILE } from "@modern-js/utils";
|
|
3
|
+
const generateRoutes = async (appContext) => {
|
|
4
|
+
const { serverRoutes, distDirectory } = appContext;
|
|
5
|
+
const output = JSON.stringify({ routes: serverRoutes }, null, 2);
|
|
6
|
+
await fs.outputFile(path.join(distDirectory, ROUTE_SPEC_FILE), output);
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
generateRoutes
|
|
10
|
+
};
|
|
File without changes
|
|
@@ -157,7 +157,7 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
157
157
|
route.error = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
|
|
160
|
+
const finalRoute = createRoute(
|
|
161
161
|
route,
|
|
162
162
|
rootDir,
|
|
163
163
|
path.join(dirname, `${NESTED_ROUTE.LAYOUT_FILE}.ts`),
|
|
@@ -170,15 +170,6 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
170
170
|
if (route.children && route.children.length === 0 && !route.index) {
|
|
171
171
|
return null;
|
|
172
172
|
}
|
|
173
|
-
if (finalRoute.children && finalRoute.children.length === 1 && !finalRoute._component) {
|
|
174
|
-
const childRoute = finalRoute.children[0];
|
|
175
|
-
if (childRoute.path === "*") {
|
|
176
|
-
const path2 = `${finalRoute.path || ""}/${childRoute.path || ""}`;
|
|
177
|
-
finalRoute = __spreadProps(__spreadValues({}, childRoute), {
|
|
178
|
-
path: path2
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
173
|
return finalRoute;
|
|
183
174
|
});
|
|
184
175
|
export {
|
|
@@ -183,7 +183,7 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
183
183
|
route.error = (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
|
|
186
|
+
const finalRoute = createRoute(
|
|
187
187
|
route,
|
|
188
188
|
rootDir,
|
|
189
189
|
path.join(dirname, `${import_constants.NESTED_ROUTE.LAYOUT_FILE}.ts`),
|
|
@@ -196,15 +196,6 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
|
|
|
196
196
|
if (route.children && route.children.length === 0 && !route.index) {
|
|
197
197
|
return null;
|
|
198
198
|
}
|
|
199
|
-
if (finalRoute.children && finalRoute.children.length === 1 && !finalRoute._component) {
|
|
200
|
-
const childRoute = finalRoute.children[0];
|
|
201
|
-
if (childRoute.path === "*") {
|
|
202
|
-
const path2 = `${finalRoute.path || ""}/${childRoute.path || ""}`;
|
|
203
|
-
finalRoute = __spreadProps(__spreadValues({}, childRoute), {
|
|
204
|
-
path: path2
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
199
|
return finalRoute;
|
|
209
200
|
});
|
|
210
201
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -197,7 +197,7 @@ var createRoute = function(routeInfo, rootDir, filename, entryName) {
|
|
|
197
197
|
};
|
|
198
198
|
var walk = function() {
|
|
199
199
|
var _ref = _asyncToGenerator(function(dirname, rootDir, alias, entryName) {
|
|
200
|
-
var ref, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, ref1, ref2, ref3, err, finalRoute
|
|
200
|
+
var ref, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, ref1, ref2, ref3, err, finalRoute;
|
|
201
201
|
return __generator(this, function(_state) {
|
|
202
202
|
switch(_state.label){
|
|
203
203
|
case 0:
|
|
@@ -386,15 +386,6 @@ var walk = function() {
|
|
|
386
386
|
null
|
|
387
387
|
];
|
|
388
388
|
}
|
|
389
|
-
if (finalRoute.children && finalRoute.children.length === 1 && !finalRoute._component) {
|
|
390
|
-
childRoute1 = finalRoute.children[0];
|
|
391
|
-
if (childRoute1.path === "*") {
|
|
392
|
-
path2 = "".concat(finalRoute.path || "", "/").concat(childRoute1.path || "");
|
|
393
|
-
finalRoute = _objectSpreadProps(_objectSpread({}, childRoute1), {
|
|
394
|
-
path: path2
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
389
|
return [
|
|
399
390
|
2,
|
|
400
391
|
finalRoute
|
|
@@ -26,9 +26,11 @@ export declare const html: (partials: {
|
|
|
26
26
|
body: string[];
|
|
27
27
|
}) => string;
|
|
28
28
|
export declare const routesForServer: ({
|
|
29
|
-
routes
|
|
29
|
+
routes,
|
|
30
|
+
metaName
|
|
30
31
|
}: {
|
|
31
32
|
routes: (NestedRoute | PageRoute)[];
|
|
33
|
+
metaName: string;
|
|
32
34
|
}) => string;
|
|
33
35
|
export declare const fileSystemRoutes: ({
|
|
34
36
|
routes,
|
|
@@ -8,7 +8,7 @@ import type { UnwrapBuilderConfig } from '../utils';
|
|
|
8
8
|
export type BuilderToolsConfig = UnwrapBuilderConfig<BuilderConfig, 'tools'> & {
|
|
9
9
|
esbuild?: PluginEsbuildOptions;
|
|
10
10
|
};
|
|
11
|
-
export type RsBuilderToolsConfig = UnwrapBuilderConfig<RsBuilderConfig, '
|
|
11
|
+
export type RsBuilderToolsConfig = UnwrapBuilderConfig<RsBuilderConfig, 'tools'>;
|
|
12
12
|
/**
|
|
13
13
|
* The configuration of `tools.tailwindcss` is provided by `tailwindcss` plugin.
|
|
14
14
|
* Please use `yarn new` or `pnpm new` to enable the corresponding capability.
|
|
@@ -4,6 +4,7 @@ import type { Entrypoint, HtmlPartials, NestedRoute, PageRoute, RouteLegacy, Ser
|
|
|
4
4
|
import type { RegisterBuildPlatformResult, DevToolData } from '@modern-js/core';
|
|
5
5
|
import type { Stats, MultiStats } from '@modern-js/builder-shared';
|
|
6
6
|
import type { Rspack } from '@modern-js/builder-rspack-provider';
|
|
7
|
+
import { Bundler } from './utils';
|
|
7
8
|
export interface ImportSpecifier {
|
|
8
9
|
local?: string;
|
|
9
10
|
imported?: string;
|
|
@@ -18,7 +19,7 @@ export interface RuntimePlugin {
|
|
|
18
19
|
options: string;
|
|
19
20
|
args?: string;
|
|
20
21
|
}
|
|
21
|
-
export type AppToolsHooks = {
|
|
22
|
+
export type AppToolsHooks<B extends Bundler = 'webpack'> = {
|
|
22
23
|
modifyEntryExport: AsyncWaterfall<{
|
|
23
24
|
entrypoint: Entrypoint;
|
|
24
25
|
exportStatement: string;
|
|
@@ -61,16 +62,16 @@ export type AppToolsHooks = {
|
|
|
61
62
|
beforeDev: AsyncWorkflow<void, unknown>;
|
|
62
63
|
afterDev: AsyncWorkflow<void, unknown>;
|
|
63
64
|
beforeCreateCompiler: AsyncWorkflow<{
|
|
64
|
-
bundlerConfigs
|
|
65
|
+
bundlerConfigs?: B extends 'rspack' ? Rspack.Configuration[] : webpack.Configuration[];
|
|
65
66
|
}, unknown>;
|
|
66
67
|
afterCreateCompiler: AsyncWorkflow<{
|
|
67
|
-
compiler?:
|
|
68
|
+
compiler?: B extends 'rspack' ? Rspack.Compiler : webpack.Compiler | webpack.MultiCompiler;
|
|
68
69
|
}, unknown>;
|
|
69
70
|
beforePrintInstructions: AsyncWaterfall<{
|
|
70
71
|
instructions: string;
|
|
71
72
|
}>;
|
|
72
73
|
beforeBuild: AsyncWorkflow<{
|
|
73
|
-
bundlerConfigs?:
|
|
74
|
+
bundlerConfigs?: B extends 'rspack' ? Rspack.Configuration[] : webpack.Configuration[];
|
|
74
75
|
}, unknown>;
|
|
75
76
|
afterBuild: AsyncWorkflow<{
|
|
76
77
|
stats?: Stats | MultiStats;
|
|
@@ -6,11 +6,13 @@ import { Bundler, FromConfig } from './utils';
|
|
|
6
6
|
export * from './hooks';
|
|
7
7
|
export * from './config';
|
|
8
8
|
export * from './legacyConfig';
|
|
9
|
+
export type { webpack } from '@modern-js/builder-webpack-provider';
|
|
10
|
+
export type { Rspack } from '@modern-js/builder-rspack-provider';
|
|
9
11
|
export type { Bundler } from './utils';
|
|
10
12
|
export type { ServerUserConfig, ServerNormalizedConfig, BffUserConfig, BffNormalizedConfig, SSR, SSRByEntries } from '@modern-js/server-core';
|
|
11
13
|
export type { IAppContext, PluginAPI, CliPlugin, NormalizedConfig, UserConfig } from '@modern-js/core';
|
|
12
14
|
export type AppTools<B extends Bundler = 'webpack'> = {
|
|
13
|
-
hooks: AppToolsHooks
|
|
15
|
+
hooks: AppToolsHooks<B>;
|
|
14
16
|
userConfig: FromConfig<B, {
|
|
15
17
|
rspack: RsAppToolsUserConfig;
|
|
16
18
|
webpack: AppToolsUserConfig;
|
package/package.json
CHANGED
|
@@ -11,23 +11,22 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.5.0-alpha.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
|
-
"main": "./dist/
|
|
18
|
-
"jsnext:modern": "./dist/js/modern/index.js",
|
|
17
|
+
"main": "./dist/cjs/index.js",
|
|
19
18
|
"exports": {
|
|
20
19
|
".": {
|
|
21
20
|
"node": {
|
|
22
21
|
"jsnext:source": "./src/index.ts",
|
|
23
|
-
"import": "./dist/
|
|
24
|
-
"require": "./dist/
|
|
22
|
+
"import": "./dist/esm/index.js",
|
|
23
|
+
"require": "./dist/cjs/index.js"
|
|
25
24
|
},
|
|
26
|
-
"default": "./dist/
|
|
25
|
+
"default": "./dist/cjs/index.js"
|
|
27
26
|
},
|
|
28
27
|
"./cli": {
|
|
29
28
|
"jsnext:source": "./src/index.ts",
|
|
30
|
-
"default": "./dist/
|
|
29
|
+
"default": "./dist/cjs/index.js"
|
|
31
30
|
},
|
|
32
31
|
"./types": {
|
|
33
32
|
"jsnext:source": "./lib/types.d.ts",
|
|
@@ -35,7 +34,7 @@
|
|
|
35
34
|
},
|
|
36
35
|
"./server": {
|
|
37
36
|
"jsnext:source": "./src/exports/server.ts",
|
|
38
|
-
"default": "./dist/
|
|
37
|
+
"default": "./dist/cjs/exports/server.js"
|
|
39
38
|
}
|
|
40
39
|
},
|
|
41
40
|
"engines": {
|
|
@@ -65,23 +64,23 @@
|
|
|
65
64
|
"@babel/types": "^7.18.0",
|
|
66
65
|
"es-module-lexer": "^1.1.0",
|
|
67
66
|
"esbuild": "0.15.7",
|
|
68
|
-
"@modern-js/builder": "2.
|
|
69
|
-
"@modern-js/builder-plugin-
|
|
70
|
-
"@modern-js/builder-
|
|
71
|
-
"@modern-js/builder-
|
|
72
|
-
"@modern-js/builder-
|
|
73
|
-
"@modern-js/
|
|
74
|
-
"@modern-js/
|
|
75
|
-
"@modern-js/
|
|
76
|
-
"@modern-js/
|
|
77
|
-
"@modern-js/plugin-
|
|
78
|
-
"@modern-js/plugin-
|
|
79
|
-
"@modern-js/
|
|
80
|
-
"@modern-js/
|
|
81
|
-
"@modern-js/
|
|
82
|
-
"@modern-js/
|
|
83
|
-
"@modern-js/upgrade": "2.
|
|
84
|
-
"@modern-js/utils": "2.
|
|
67
|
+
"@modern-js/builder": "2.5.0",
|
|
68
|
+
"@modern-js/builder-plugin-esbuild": "2.5.0",
|
|
69
|
+
"@modern-js/builder-plugin-node-polyfill": "2.5.0",
|
|
70
|
+
"@modern-js/builder-shared": "2.5.0",
|
|
71
|
+
"@modern-js/builder-webpack-provider": "2.5.0",
|
|
72
|
+
"@modern-js/new-action": "2.5.0",
|
|
73
|
+
"@modern-js/core": "2.5.0",
|
|
74
|
+
"@modern-js/plugin": "2.5.0",
|
|
75
|
+
"@modern-js/node-bundle-require": "2.5.0",
|
|
76
|
+
"@modern-js/plugin-i18n": "2.5.0",
|
|
77
|
+
"@modern-js/plugin-lint": "2.5.0",
|
|
78
|
+
"@modern-js/prod-server": "2.5.0",
|
|
79
|
+
"@modern-js/plugin-data-loader": "2.5.0-alpha.0",
|
|
80
|
+
"@modern-js/types": "2.5.0",
|
|
81
|
+
"@modern-js/server": "2.5.0",
|
|
82
|
+
"@modern-js/upgrade": "2.5.0",
|
|
83
|
+
"@modern-js/utils": "2.5.0-alpha.0"
|
|
85
84
|
},
|
|
86
85
|
"devDependencies": {
|
|
87
86
|
"@types/babel__traverse": "^7.14.2",
|
|
@@ -90,14 +89,14 @@
|
|
|
90
89
|
"jest": "^27",
|
|
91
90
|
"typescript": "^4",
|
|
92
91
|
"webpack": "^5.75.0",
|
|
93
|
-
"@modern-js/builder-plugin-swc": "2.
|
|
94
|
-
"@modern-js/builder-rspack-provider": "2.
|
|
95
|
-
"@modern-js/server-core": "2.
|
|
96
|
-
"@scripts/jest-config": "2.
|
|
97
|
-
"@scripts/build": "2.
|
|
92
|
+
"@modern-js/builder-plugin-swc": "2.5.0",
|
|
93
|
+
"@modern-js/builder-rspack-provider": "2.5.0",
|
|
94
|
+
"@modern-js/server-core": "2.5.0",
|
|
95
|
+
"@scripts/jest-config": "2.5.0",
|
|
96
|
+
"@scripts/build": "2.5.0"
|
|
98
97
|
},
|
|
99
98
|
"peerDependencies": {
|
|
100
|
-
"@modern-js/builder-rspack-provider": "^2.
|
|
99
|
+
"@modern-js/builder-rspack-provider": "^2.5.0"
|
|
101
100
|
},
|
|
102
101
|
"peerDependenciesMeta": {
|
|
103
102
|
"@modern-js/builder-rspack-provider": {
|