@modern-js/app-tools 2.63.0 → 2.63.1-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/modern.js +1 -1
- package/dist/cjs/commands/build.js +19 -13
- package/dist/cjs/commands/deploy.js +5 -5
- package/dist/cjs/commands/dev.js +11 -11
- package/dist/cjs/commands/index.js +6 -6
- package/dist/cjs/commands/inspect.js +1 -1
- package/dist/cjs/commands/serve.js +4 -4
- package/dist/cjs/{new/compat → compat}/hooks.js +15 -8
- package/dist/cjs/{new/compat → compat}/index.js +4 -1
- package/dist/cjs/{new/compat → compat}/utils.js +10 -1
- package/dist/cjs/index.js +154 -5
- package/dist/cjs/plugins/analyze/getBundleEntry.js +2 -2
- package/dist/cjs/plugins/analyze/getFileSystemEntry.js +9 -9
- package/dist/cjs/plugins/analyze/getHtmlTemplate.js +51 -25
- package/dist/cjs/plugins/analyze/index.js +128 -130
- package/dist/cjs/plugins/deploy/index.js +12 -14
- package/dist/cjs/plugins/initialize/index.js +1 -1
- package/dist/cjs/plugins/serverBuild.js +30 -32
- package/dist/cjs/{new/run.js → run/index.js} +6 -6
- package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
- package/dist/cjs/{new/context.js → utils/initAppContext.js} +3 -4
- package/dist/cjs/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
- package/dist/cjs/utils/loadPlugins.js +35 -4
- package/dist/cjs/utils/printInstructions.js +2 -2
- package/dist/cjs/utils/restart.js +4 -3
- package/dist/esm/commands/build.js +18 -12
- package/dist/esm/commands/deploy.js +6 -6
- package/dist/esm/commands/dev.js +10 -10
- package/dist/esm/commands/index.js +8 -8
- package/dist/esm/commands/inspect.js +1 -1
- package/dist/esm/commands/serve.js +5 -5
- package/dist/esm/{new/compat → compat}/hooks.js +41 -41
- package/dist/esm/{new/compat → compat}/index.js +4 -1
- package/dist/esm/{new/compat → compat}/utils.js +10 -1
- package/dist/esm/index.js +245 -2
- package/dist/esm/plugins/analyze/getBundleEntry.js +3 -3
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +12 -12
- package/dist/esm/plugins/analyze/getHtmlTemplate.js +101 -28
- package/dist/esm/plugins/analyze/index.js +328 -331
- package/dist/esm/plugins/deploy/index.js +84 -88
- package/dist/esm/plugins/initialize/index.js +1 -1
- package/dist/esm/plugins/serverBuild.js +52 -56
- package/dist/esm/{new/run.js → run/index.js} +6 -6
- package/dist/esm/{new → utils}/getConfigFile.js +1 -1
- package/dist/esm/{new/context.js → utils/initAppContext.js} +0 -1
- package/dist/esm/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
- package/dist/esm/utils/loadPlugins.js +95 -7
- package/dist/esm/utils/printInstructions.js +3 -3
- package/dist/esm/utils/restart.js +5 -4
- package/dist/esm-node/commands/build.js +19 -13
- package/dist/esm-node/commands/deploy.js +5 -5
- package/dist/esm-node/commands/dev.js +11 -11
- package/dist/esm-node/commands/index.js +6 -6
- package/dist/esm-node/commands/inspect.js +1 -1
- package/dist/esm-node/commands/serve.js +4 -4
- package/dist/esm-node/{new/compat → compat}/hooks.js +15 -8
- package/dist/esm-node/{new/compat → compat}/index.js +4 -1
- package/dist/esm-node/{new/compat → compat}/utils.js +10 -1
- package/dist/esm-node/index.js +140 -2
- package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -2
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +9 -9
- package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +49 -24
- package/dist/esm-node/plugins/analyze/index.js +128 -130
- package/dist/esm-node/plugins/deploy/index.js +12 -14
- package/dist/esm-node/plugins/initialize/index.js +1 -1
- package/dist/esm-node/plugins/serverBuild.js +30 -32
- package/dist/esm-node/{new/run.js → run/index.js} +6 -6
- package/dist/esm-node/{new → utils}/getConfigFile.js +1 -1
- package/dist/esm-node/{new/context.js → utils/initAppContext.js} +0 -1
- package/dist/esm-node/{new/utils/index.js → utils/isAutoLoadPlugins.js} +2 -2
- package/dist/esm-node/utils/loadPlugins.js +34 -4
- package/dist/esm-node/utils/printInstructions.js +2 -2
- package/dist/esm-node/utils/restart.js +4 -3
- package/dist/types/builder/generator/adapterCopy.d.ts +2 -1
- package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +3 -2
- package/dist/types/builder/generator/createCopyPattern.d.ts +4 -3
- package/dist/types/builder/generator/getBuilderEnvironments.d.ts +2 -2
- package/dist/types/builder/index.d.ts +1 -1
- package/dist/types/builder/shared/createCopyInfo.d.ts +3 -2
- package/dist/types/builder/shared/types.d.ts +3 -2
- package/dist/types/commands/build.d.ts +2 -2
- package/dist/types/commands/deploy.d.ts +2 -2
- package/dist/types/commands/dev.d.ts +2 -2
- package/dist/types/commands/index.d.ts +6 -6
- package/dist/types/commands/inspect.d.ts +2 -2
- package/dist/types/commands/serve.d.ts +2 -2
- package/dist/types/{new/compat → compat}/hooks.d.ts +2 -2
- package/dist/types/compat/index.d.ts +2 -0
- package/dist/types/config/initialize/index.d.ts +3 -2
- package/dist/types/config/initialize/inits.d.ts +4 -3
- package/dist/types/index.d.ts +5 -3
- package/dist/types/plugins/analyze/getBundleEntry.d.ts +3 -3
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +3 -3
- package/dist/types/plugins/analyze/getHtmlTemplate.d.ts +26 -5
- package/dist/types/plugins/analyze/getServerRoutes.d.ts +2 -2
- package/dist/types/plugins/analyze/index.d.ts +2 -3
- package/dist/types/plugins/deploy/index.d.ts +2 -3
- package/dist/types/plugins/deploy/platforms/platform.d.ts +3 -3
- package/dist/types/plugins/deploy/utils.d.ts +2 -2
- package/dist/types/plugins/serverBuild.d.ts +2 -2
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/types/new.d.ts +46 -34
- package/dist/types/utils/generateWatchFiles.d.ts +2 -2
- package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -1
- package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -0
- package/dist/types/utils/loadPlugins.d.ts +13 -3
- package/dist/types/utils/printInstructions.d.ts +3 -3
- package/dist/types/utils/restart.d.ts +2 -3
- package/dist/types/utils/routes.d.ts +2 -1
- package/package.json +14 -15
- package/dist/cjs/hooks.js +0 -60
- package/dist/cjs/new/index.js +0 -79
- package/dist/cjs/new/loadPlugins.js +0 -57
- package/dist/cjs/old.js +0 -179
- package/dist/esm/hooks.js +0 -36
- package/dist/esm/new/index.js +0 -55
- package/dist/esm/new/loadPlugins.js +0 -94
- package/dist/esm/old.js +0 -258
- package/dist/esm-node/hooks.js +0 -36
- package/dist/esm-node/new/index.js +0 -52
- package/dist/esm-node/new/loadPlugins.js +0 -33
- package/dist/esm-node/old.js +0 -140
- package/dist/types/hooks.d.ts +0 -2
- package/dist/types/new/compat/index.d.ts +0 -2
- package/dist/types/new/index.d.ts +0 -6
- package/dist/types/new/loadPlugins.d.ts +0 -9
- package/dist/types/new/utils/index.d.ts +0 -1
- package/dist/types/old.d.ts +0 -13
- /package/dist/cjs/{new/constants.js → constants.js} +0 -0
- /package/dist/esm/{new/constants.js → constants.js} +0 -0
- /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
- /package/dist/types/{new/compat → compat}/utils.d.ts +0 -0
- /package/dist/types/{new/constants.d.ts → constants.d.ts} +0 -0
- /package/dist/types/{new/run.d.ts → run/index.d.ts} +0 -0
- /package/dist/types/{new → utils}/getConfigFile.d.ts +0 -0
@@ -16,147 +16,145 @@ var analyze_default = ({ bundler }) => ({
|
|
16
16
|
setup: (api) => {
|
17
17
|
let pagesDir = [];
|
18
18
|
let nestedRouteEntries = [];
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
fs.emptydirSync(appContext.internalDirectory);
|
28
|
-
}
|
29
|
-
} catch {
|
30
|
-
}
|
31
|
-
const apiOnly = await isApiOnly(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
|
32
|
-
await hookRunners.addRuntimeExports();
|
33
|
-
if (apiOnly) {
|
34
|
-
const { routes: routes2 } = await hookRunners.modifyServerRoutes({
|
35
|
-
routes: []
|
36
|
-
});
|
37
|
-
debug(`server routes: %o`, routes2);
|
38
|
-
appContext = {
|
39
|
-
...api.useAppContext(),
|
40
|
-
apiOnly,
|
41
|
-
serverRoutes: routes2
|
42
|
-
};
|
43
|
-
api.setAppContext(appContext);
|
44
|
-
return;
|
19
|
+
api.onPrepare(async () => {
|
20
|
+
var _resolvedConfig_source;
|
21
|
+
let appContext = api.getAppContext();
|
22
|
+
const resolvedConfig = api.getNormalizedConfig();
|
23
|
+
const hooks = api.getHooks();
|
24
|
+
try {
|
25
|
+
if (checkIsBuildCommands()) {
|
26
|
+
fs.emptydirSync(appContext.internalDirectory);
|
45
27
|
}
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
const {
|
52
|
-
|
28
|
+
} catch {
|
29
|
+
}
|
30
|
+
const apiOnly = await isApiOnly(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
|
31
|
+
await hooks.addRuntimeExports.call();
|
32
|
+
if (apiOnly) {
|
33
|
+
const { routes: routes2 } = await hooks.modifyServerRoutes.call({
|
34
|
+
routes: []
|
53
35
|
});
|
54
|
-
debug(`
|
55
|
-
|
56
|
-
|
57
|
-
|
36
|
+
debug(`server routes: %o`, routes2);
|
37
|
+
api.updateAppContext({
|
38
|
+
apiOnly,
|
39
|
+
serverRoutes: routes2
|
58
40
|
});
|
59
|
-
|
60
|
-
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
|
44
|
+
import("./getBundleEntry.js"),
|
45
|
+
import("./getServerRoutes.js"),
|
46
|
+
import("./getHtmlTemplate.js")
|
47
|
+
]);
|
48
|
+
const { entrypoints } = await hooks.modifyEntrypoints.call({
|
49
|
+
entrypoints: await getBundleEntry(hooks, appContext, resolvedConfig)
|
50
|
+
});
|
51
|
+
debug(`entrypoints: %o`, entrypoints);
|
52
|
+
const initialRoutes = getServerRoutes(entrypoints, {
|
53
|
+
appContext,
|
54
|
+
config: resolvedConfig
|
55
|
+
});
|
56
|
+
const { routes } = await hooks.modifyServerRoutes.call({
|
57
|
+
routes: initialRoutes
|
58
|
+
});
|
59
|
+
debug(`server routes: %o`, routes);
|
60
|
+
appContext = {
|
61
|
+
...api.getAppContext(),
|
62
|
+
entrypoints,
|
63
|
+
serverRoutes: routes
|
64
|
+
};
|
65
|
+
api.updateAppContext(appContext);
|
66
|
+
nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
67
|
+
pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
|
68
|
+
const { partialsByEntrypoint, htmlTemplates } = await getHtmlTemplate(entrypoints, hooks, {
|
69
|
+
appContext,
|
70
|
+
config: resolvedConfig
|
71
|
+
});
|
72
|
+
debug(`html templates: %o`, htmlTemplates);
|
73
|
+
api.updateAppContext({
|
74
|
+
partialsByEntrypoint
|
75
|
+
});
|
76
|
+
let checkedEntries = entrypoints.map((point) => point.entryName);
|
77
|
+
if (isDevCommand()) {
|
78
|
+
const { entry } = minimist(getArgv());
|
79
|
+
checkedEntries = await getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints);
|
80
|
+
}
|
81
|
+
appContext = {
|
82
|
+
...api.getAppContext(),
|
83
|
+
entrypoints,
|
84
|
+
checkedEntries,
|
85
|
+
apiOnly,
|
86
|
+
serverRoutes: routes,
|
87
|
+
htmlTemplates
|
88
|
+
};
|
89
|
+
api.updateAppContext(appContext);
|
90
|
+
if (checkIsBuildCommands()) {
|
91
|
+
await hooks.generateEntryCode.call({
|
92
|
+
entrypoints
|
61
93
|
});
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
};
|
68
|
-
api.setAppContext(appContext);
|
69
|
-
nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
70
|
-
pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
|
71
|
-
const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
|
72
|
-
appContext,
|
73
|
-
config: resolvedConfig
|
94
|
+
const normalizedConfig = api.getNormalizedConfig();
|
95
|
+
const createBuilderForModern = await createBuilderGenerator(bundler);
|
96
|
+
const builder = await createBuilderForModern({
|
97
|
+
normalizedConfig,
|
98
|
+
appContext
|
74
99
|
});
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
apiOnly,
|
86
|
-
serverRoutes: routes,
|
87
|
-
htmlTemplates
|
88
|
-
};
|
89
|
-
api.setAppContext(appContext);
|
90
|
-
if (checkIsBuildCommands()) {
|
91
|
-
await hookRunners.generateEntryCode({
|
92
|
-
entrypoints
|
93
|
-
});
|
94
|
-
const normalizedConfig = api.useResolvedConfigContext();
|
95
|
-
const createBuilderForModern = await createBuilderGenerator(bundler);
|
96
|
-
const builder = await createBuilderForModern({
|
97
|
-
normalizedConfig,
|
98
|
-
appContext
|
99
|
-
});
|
100
|
-
builder.onBeforeBuild(async ({ bundlerConfigs, isFirstCompile }) => {
|
101
|
-
if (!isFirstCompile) {
|
102
|
-
return;
|
103
|
-
}
|
104
|
-
const hookRunners2 = api.useHookRunners();
|
105
|
-
await generateRoutes(appContext);
|
106
|
-
await hookRunners2.beforeBuild({
|
107
|
-
bundlerConfigs
|
108
|
-
});
|
100
|
+
builder.onBeforeBuild(async ({ bundlerConfigs, isFirstCompile, environments, isWatch }) => {
|
101
|
+
if (!isFirstCompile) {
|
102
|
+
return;
|
103
|
+
}
|
104
|
+
await generateRoutes(appContext);
|
105
|
+
await hooks.onBeforeBuild.call({
|
106
|
+
isFirstCompile,
|
107
|
+
isWatch,
|
108
|
+
environments,
|
109
|
+
bundlerConfigs
|
109
110
|
});
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
111
|
+
});
|
112
|
+
builder.onAfterBuild(async ({ stats, environments, isFirstCompile, isWatch }) => {
|
113
|
+
await hooks.onAfterBuild.call({
|
114
|
+
stats,
|
115
|
+
environments,
|
116
|
+
isFirstCompile,
|
117
|
+
isWatch
|
116
118
|
});
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
if (isFirstCompile) {
|
123
|
-
printInstructions(hookRunners2, appContext, normalizedConfig);
|
124
|
-
}
|
119
|
+
await emitResolvedConfig(appContext.appDirectory, normalizedConfig);
|
120
|
+
});
|
121
|
+
builder.onDevCompileDone(async ({ isFirstCompile }) => {
|
122
|
+
hooks.onAfterDev.call({
|
123
|
+
isFirstCompile
|
125
124
|
});
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
125
|
+
if (isFirstCompile) {
|
126
|
+
printInstructions(hooks, appContext, normalizedConfig);
|
127
|
+
}
|
128
|
+
});
|
129
|
+
builder.onBeforeCreateCompiler(async ({ bundlerConfigs, environments }) => {
|
130
|
+
await hooks.onBeforeCreateCompiler.call({
|
131
|
+
environments,
|
132
|
+
bundlerConfigs
|
131
133
|
});
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
134
|
+
});
|
135
|
+
builder.onAfterCreateCompiler(async ({ compiler, environments }) => {
|
136
|
+
await hooks.onAfterCreateCompiler.call({
|
137
|
+
environments,
|
138
|
+
compiler
|
137
139
|
});
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
api.setAppContext(appContext);
|
144
|
-
}
|
145
|
-
},
|
146
|
-
watchFiles() {
|
147
|
-
return {
|
148
|
-
files: pagesDir,
|
149
|
-
isPrivate: true
|
150
|
-
};
|
151
|
-
},
|
152
|
-
resolvedConfig({ resolved }) {
|
153
|
-
const appContext = api.useAppContext();
|
154
|
-
const config = initialNormalizedConfig(resolved, appContext, bundler);
|
155
|
-
return {
|
156
|
-
resolved: config
|
157
|
-
};
|
140
|
+
});
|
141
|
+
builder.addPlugins(resolvedConfig.builderPlugins);
|
142
|
+
api.updateAppContext({
|
143
|
+
builder
|
144
|
+
});
|
158
145
|
}
|
159
|
-
};
|
146
|
+
});
|
147
|
+
api.addWatchFiles(() => {
|
148
|
+
return {
|
149
|
+
files: pagesDir,
|
150
|
+
isPrivate: true
|
151
|
+
};
|
152
|
+
});
|
153
|
+
api.modifyResolvedConfig((resolved) => {
|
154
|
+
const appContext = api.getAppContext();
|
155
|
+
const config = initialNormalizedConfig(resolved, appContext, bundler);
|
156
|
+
return config;
|
157
|
+
});
|
160
158
|
}
|
161
159
|
});
|
162
160
|
export {
|
@@ -22,21 +22,19 @@ var deploy_default = () => ({
|
|
22
22
|
name: "@modern-js/plugin-deploy",
|
23
23
|
setup: (api) => {
|
24
24
|
const deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
return;
|
31
|
-
}
|
32
|
-
const modernConfig = api.useResolvedConfigContext();
|
33
|
-
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
|
34
|
-
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
|
35
|
-
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
|
36
|
-
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
|
37
|
-
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end());
|
25
|
+
api.deploy(async () => {
|
26
|
+
const appContext = api.getAppContext();
|
27
|
+
const { metaName } = appContext;
|
28
|
+
if (metaName !== "modern-js" && !process.env.MODERNJS_DEPLOY) {
|
29
|
+
return;
|
38
30
|
}
|
39
|
-
|
31
|
+
const modernConfig = api.getNormalizedConfig();
|
32
|
+
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
|
33
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
|
34
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
|
35
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
|
36
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end());
|
37
|
+
});
|
40
38
|
}
|
41
39
|
});
|
42
40
|
export {
|
@@ -27,7 +27,7 @@ var initialize_default = ({ bundler }) => ({
|
|
27
27
|
appContext = {
|
28
28
|
...appContext,
|
29
29
|
port,
|
30
|
-
distDirectory: ensureAbsolutePath(appContext.
|
30
|
+
distDirectory: ensureAbsolutePath(appContext.appDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
|
31
31
|
};
|
32
32
|
api.updateAppContext(appContext);
|
33
33
|
const normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
|
@@ -17,40 +17,38 @@ function checkHasConfig(appDir, metaName = "modern-js") {
|
|
17
17
|
var serverBuild_default = () => ({
|
18
18
|
name: "@modern-js/server-build",
|
19
19
|
setup(api) {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
sourceDirs.push(sharedDir);
|
36
|
-
}
|
37
|
-
}
|
38
|
-
const { server } = modernConfig;
|
39
|
-
const { alias } = modernConfig.source;
|
40
|
-
const { babel } = modernConfig.tools;
|
41
|
-
if (sourceDirs.length > 0) {
|
42
|
-
await compile(appDirectory, {
|
43
|
-
server,
|
44
|
-
alias,
|
45
|
-
babelConfig: babel
|
46
|
-
}, {
|
47
|
-
sourceDirs,
|
48
|
-
distDir,
|
49
|
-
tsconfigPath
|
50
|
-
});
|
20
|
+
api.onAfterBuild(async () => {
|
21
|
+
const { appDirectory, distDirectory, metaName } = api.getAppContext();
|
22
|
+
if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
const modernConfig = api.getNormalizedConfig();
|
26
|
+
const distDir = path.resolve(distDirectory);
|
27
|
+
const serverDir = path.resolve(appDirectory, SERVER_DIR);
|
28
|
+
const sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
29
|
+
const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
30
|
+
const sourceDirs = [];
|
31
|
+
if (fs.existsSync(serverDir)) {
|
32
|
+
sourceDirs.push(serverDir);
|
33
|
+
if (fs.existsSync(sharedDir)) {
|
34
|
+
sourceDirs.push(sharedDir);
|
51
35
|
}
|
52
36
|
}
|
53
|
-
|
37
|
+
const { server } = modernConfig;
|
38
|
+
const { alias } = modernConfig.source;
|
39
|
+
const { babel } = modernConfig.tools;
|
40
|
+
if (sourceDirs.length > 0) {
|
41
|
+
await compile(appDirectory, {
|
42
|
+
server,
|
43
|
+
alias,
|
44
|
+
babelConfig: babel
|
45
|
+
}, {
|
46
|
+
sourceDirs,
|
47
|
+
distDir,
|
48
|
+
tsconfigPath
|
49
|
+
});
|
50
|
+
}
|
51
|
+
});
|
54
52
|
}
|
55
53
|
});
|
56
54
|
export {
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { initAppDir } from "@modern-js/plugin-v2/cli";
|
2
2
|
import { run as CLIPluginRun } from "@modern-js/plugin-v2/run";
|
3
3
|
import { minimist } from "@modern-js/utils";
|
4
|
-
import { handleSetupResult } from "
|
5
|
-
import { PACKAGE_JSON_CONFIG_NAME } from "
|
6
|
-
import { getConfigFile } from "
|
7
|
-
import {
|
8
|
-
import {
|
4
|
+
import { handleSetupResult } from "../compat/hooks";
|
5
|
+
import { PACKAGE_JSON_CONFIG_NAME } from "../constants";
|
6
|
+
import { getConfigFile } from "../utils/getConfigFile";
|
7
|
+
import { isAutoLoadPlugins } from "../utils/isAutoLoadPlugins";
|
8
|
+
import { loadInternalPlugins } from "../utils/loadPlugins";
|
9
9
|
async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfig, configFile }) {
|
10
10
|
const command = process.argv[2];
|
11
11
|
const cliParams = minimist(process.argv.slice(2));
|
@@ -27,7 +27,7 @@ async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfi
|
|
27
27
|
}
|
28
28
|
const appDirectory = await initAppDir(cwd);
|
29
29
|
const finalConfigFile = customConfigFile || getConfigFile(configFile);
|
30
|
-
const autoLoadPlugins = await
|
30
|
+
const autoLoadPlugins = await isAutoLoadPlugins(appDirectory, finalConfigFile);
|
31
31
|
const plugins = await loadInternalPlugins(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, autoLoadPlugins);
|
32
32
|
await CLIPluginRun({
|
33
33
|
cwd,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import path from "path";
|
2
2
|
import { CONFIG_FILE_EXTENSIONS, findExists } from "@modern-js/utils";
|
3
|
-
import { DEFAULT_CONFIG_FILE } from "
|
3
|
+
import { DEFAULT_CONFIG_FILE } from "../constants";
|
4
4
|
const getConfigFile = (configFile) => findExists(CONFIG_FILE_EXTENSIONS.map((extension) => path.resolve(process.cwd(), `${configFile || DEFAULT_CONFIG_FILE}${extension}`)));
|
5
5
|
export {
|
6
6
|
getConfigFile
|
@@ -13,7 +13,6 @@ const initAppContext = ({ appDirectory, runtimeConfigFile, options, serverConfig
|
|
13
13
|
apiDirectory: path.resolve(appDirectory, apiDir),
|
14
14
|
lambdaDirectory: path.resolve(appDirectory, apiDir, "lambda"),
|
15
15
|
sharedDirectory: path.resolve(appDirectory, sharedDir),
|
16
|
-
distDirectory: distDir,
|
17
16
|
serverPlugins: [],
|
18
17
|
internalDirectory: path.resolve(appDirectory, tempDir || `./node_modules/.${metaName}`),
|
19
18
|
htmlTemplates: {},
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { createLoadedConfig } from "@modern-js/plugin-v2/cli";
|
2
|
-
async function
|
2
|
+
async function isAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
|
3
3
|
var _loaded_config;
|
4
4
|
const loaded = await createLoadedConfig(appDirectory, configFile, packageJsonConfig);
|
5
5
|
const autoLoadPlugins = (_loaded_config = loaded.config) === null || _loaded_config === void 0 ? void 0 : _loaded_config.autoLoadPlugins;
|
6
6
|
return autoLoadPlugins || false;
|
7
7
|
}
|
8
8
|
export {
|
9
|
-
|
9
|
+
isAutoLoadPlugins
|
10
10
|
};
|
@@ -1,12 +1,13 @@
|
|
1
1
|
import { loadServerPlugins as loadServerPluginInstances } from "@modern-js/prod-server";
|
2
|
+
import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
|
3
|
+
const debug = createDebugger("load-plugins");
|
2
4
|
async function getServerPlugins(api, metaName = "modern-js") {
|
3
|
-
const
|
4
|
-
const { plugins } = await
|
5
|
+
const hooks = api.getHooks();
|
6
|
+
const { plugins } = await hooks._internalServerPlugins.call({
|
5
7
|
plugins: []
|
6
8
|
});
|
7
9
|
const filtedPlugins = plugins.filter((plugin) => plugin.name.includes(metaName));
|
8
|
-
api.
|
9
|
-
...api.useAppContext(),
|
10
|
+
api.updateAppContext({
|
10
11
|
serverPlugins: filtedPlugins
|
11
12
|
});
|
12
13
|
return filtedPlugins;
|
@@ -16,7 +17,36 @@ async function loadServerPlugins(api, appDirectory, metaName) {
|
|
16
17
|
const instances = await loadServerPluginInstances(plugins, appDirectory);
|
17
18
|
return instances;
|
18
19
|
}
|
20
|
+
const resolveCliPlugin = async (p, appDirectory) => {
|
21
|
+
const pkg = typeof p === "string" ? p : p[0];
|
22
|
+
const pluginOptions = typeof p === "string" ? void 0 : p[1];
|
23
|
+
const path = tryResolve(pkg, appDirectory);
|
24
|
+
let module;
|
25
|
+
try {
|
26
|
+
module = await compatibleRequire(path);
|
27
|
+
} catch (e) {
|
28
|
+
({ default: module } = await dynamicImport(path));
|
29
|
+
}
|
30
|
+
if (typeof module === "function") {
|
31
|
+
const result = module(pluginOptions);
|
32
|
+
return result;
|
33
|
+
}
|
34
|
+
return module;
|
35
|
+
};
|
36
|
+
const loadInternalPlugins = async (appDirectory, internalPlugins, autoLoad, autoLoadPlugins) => {
|
37
|
+
const plugins = [
|
38
|
+
...autoLoadPlugins ? getInternalPlugins(appDirectory, internalPlugins) : [],
|
39
|
+
...autoLoad ? getInternalPlugins(appDirectory, autoLoad) : []
|
40
|
+
];
|
41
|
+
const loadedPlugins = await Promise.all(plugins.map((plugin) => {
|
42
|
+
const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
|
43
|
+
debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
|
44
|
+
return loadedPlugin;
|
45
|
+
}));
|
46
|
+
return loadedPlugins;
|
47
|
+
};
|
19
48
|
export {
|
20
49
|
getServerPlugins,
|
50
|
+
loadInternalPlugins,
|
21
51
|
loadServerPlugins
|
22
52
|
};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { logger, prettyInstructions } from "@modern-js/utils";
|
2
|
-
const printInstructions = async (
|
2
|
+
const printInstructions = async (hooks, appContext, config) => {
|
3
3
|
const message = prettyInstructions(appContext, config);
|
4
|
-
const { instructions } = await
|
4
|
+
const { instructions } = await hooks.onBeforePrintInstructions.call({
|
5
5
|
instructions: message
|
6
6
|
});
|
7
7
|
logger.log(instructions);
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { cli } from "@modern-js/plugin-v2/cli";
|
2
|
-
import { chalk, clearConsole, getFullArgv, logger
|
3
|
-
|
2
|
+
import { chalk, clearConsole, getFullArgv, logger } from "@modern-js/utils";
|
3
|
+
import { program } from "@modern-js/utils/commander";
|
4
|
+
async function restart(hooks, filename) {
|
4
5
|
clearConsole();
|
5
6
|
logger.info(`Restart because ${chalk.yellow(filename)} is changed...
|
6
7
|
`);
|
7
8
|
let hasGetError = false;
|
8
|
-
await
|
9
|
+
await hooks.onBeforeRestart.call();
|
9
10
|
try {
|
10
11
|
await cli.init(cli.getPrevInitOptions());
|
11
12
|
} catch (err) {
|
@@ -1,3 +1,4 @@
|
|
1
1
|
import type { RsbuildPlugin } from '@modern-js/uni-builder';
|
2
|
+
import type { Bundler } from '../../types';
|
2
3
|
import type { BuilderOptions } from '../shared';
|
3
|
-
export declare const builderPluginAdapterCopy: (options: BuilderOptions<
|
4
|
+
export declare const builderPluginAdapterCopy: <B extends Bundler>(options: BuilderOptions<B>) => RsbuildPlugin;
|
@@ -1,2 +1,3 @@
|
|
1
|
-
import type { AppNormalizedConfig, Bundler
|
2
|
-
|
1
|
+
import type { AppNormalizedConfig, Bundler } from '../../types';
|
2
|
+
import type { AppToolsContext } from '../../types/new';
|
3
|
+
export declare function createBuilderProviderConfig<B extends Bundler>(resolveConfig: AppNormalizedConfig<B>, appContext: AppToolsContext<B>): Omit<AppNormalizedConfig<B>, 'plugins'>;
|
@@ -1,7 +1,8 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
import type { Rspack, RspackChain } from '@rsbuild/core';
|
3
|
-
import type { AppNormalizedConfig, Bundler
|
4
|
-
|
3
|
+
import type { AppNormalizedConfig, Bundler } from '../../types';
|
4
|
+
import type { AppToolsContext } from '../../types/new';
|
5
|
+
export declare function createPublicPattern<B extends Bundler>(appContext: AppToolsContext<B>, config: AppNormalizedConfig, chain: RspackChain): {
|
5
6
|
info: (file: {
|
6
7
|
sourceFilename: string;
|
7
8
|
}) => {
|
@@ -13,4 +14,4 @@ export declare function createPublicPattern(appContext: IAppContext, config: App
|
|
13
14
|
noErrorOnMissing: boolean;
|
14
15
|
transform: (content: Buffer, absoluteFrom: string) => string | Buffer;
|
15
16
|
};
|
16
|
-
export declare function createUploadPattern<B extends Bundler>(appContext:
|
17
|
+
export declare function createUploadPattern<B extends Bundler>(appContext: AppToolsContext<B>, config: AppNormalizedConfig<B>): Rspack.CopyRspackPluginOptions['patterns']['0'];
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import type { IAppContext } from '@modern-js/core';
|
2
1
|
import type { AppNormalizedConfig, Bundler } from '../../types';
|
3
|
-
|
2
|
+
import type { AppToolsContext } from '../../types/new';
|
3
|
+
export declare function getBuilderEnvironments<B extends Bundler>(normalizedConfig: AppNormalizedConfig<B>, appContext: AppToolsContext<B>, tempBuilderConfig: Omit<AppNormalizedConfig<B>, 'plugins'>): {
|
4
4
|
environments: {
|
5
5
|
[name: string]: import("@rsbuild/core").EnvironmentConfig;
|
6
6
|
};
|
@@ -1 +1 @@
|
|
1
|
-
export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack/index.js").createRspackBuilderForModern>;
|
1
|
+
export declare function createBuilderGenerator(bundler: 'webpack' | 'rspack'): Promise<typeof import("./builder-rspack/index.js").createRspackBuilderForModern | typeof import("./builder-webpack/index.js").createWebpackBuilderForModern>;
|
@@ -1,5 +1,6 @@
|
|
1
|
-
import type { AppNormalizedConfig,
|
2
|
-
|
1
|
+
import type { AppNormalizedConfig, Bundler } from '../../types';
|
2
|
+
import type { AppToolsContext } from '../../types/new';
|
3
|
+
export declare function createCopyInfo<B extends Bundler>(appContext: AppToolsContext<B>, config: AppNormalizedConfig<B>): {
|
3
4
|
configDir: string;
|
4
5
|
uploadDir: string;
|
5
6
|
publicDir: string;
|
@@ -1,5 +1,6 @@
|
|
1
|
-
import type { AppNormalizedConfig, Bundler
|
1
|
+
import type { AppNormalizedConfig, Bundler } from '../../types';
|
2
|
+
import type { AppToolsContext } from '../../types/new';
|
2
3
|
export type BuilderOptions<B extends Bundler> = {
|
3
4
|
normalizedConfig: AppNormalizedConfig<B>;
|
4
|
-
appContext:
|
5
|
+
appContext: AppToolsContext<B>;
|
5
6
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import type { CLIPluginAPI } from '@modern-js/plugin-v2';
|
2
2
|
import type { AppTools } from '../types';
|
3
3
|
import type { BuildOptions } from '../utils/types';
|
4
|
-
export declare const build: (api:
|
4
|
+
export declare const build: (api: CLIPluginAPI<AppTools<'shared'>>, options?: BuildOptions) => Promise<void>;
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import type {
|
1
|
+
import type { CLIPluginAPI } from '@modern-js/plugin-v2';
|
2
2
|
import type { AppTools } from '../types';
|
3
|
-
export declare const deploy: (api:
|
3
|
+
export declare const deploy: (api: CLIPluginAPI<AppTools<'shared'>>, options: any) => Promise<void>;
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import type { CLIPluginAPI } from '@modern-js/plugin-v2';
|
2
2
|
import { type ApplyPlugins } from '@modern-js/server';
|
3
3
|
import type { AppTools } from '../types';
|
4
4
|
import type { DevOptions } from '../utils/types';
|
5
5
|
export interface ExtraServerOptions {
|
6
6
|
applyPlugins?: ApplyPlugins;
|
7
7
|
}
|
8
|
-
export declare const dev: (api:
|
8
|
+
export declare const dev: (api: CLIPluginAPI<AppTools<'shared'>>, options: DevOptions, devServerOptions?: ExtraServerOptions) => Promise<void>;
|