@modern-js/app-tools 2.62.2-alpha.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 +20 -8
- package/dist/cjs/{new/compat → compat}/index.js +10 -2
- package/dist/cjs/{new/compat → compat}/utils.js +10 -1
- package/dist/cjs/index.js +156 -7
- 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 +44 -50
- package/dist/cjs/plugins/serverBuild.js +30 -32
- package/dist/cjs/{new/run.js → run/index.js} +6 -6
- package/dist/cjs/{new/types/index.js → types/new.js} +2 -2
- package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
- package/dist/cjs/{new/context.js → utils/initAppContext.js} +5 -5
- 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 +65 -41
- package/dist/esm/{new/compat → compat}/index.js +13 -2
- package/dist/{esm-node/new → esm}/compat/utils.js +10 -1
- package/dist/esm/index.js +248 -5
- 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 +61 -64
- 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} +3 -3
- 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 +20 -8
- package/dist/esm-node/{new/compat → compat}/index.js +10 -2
- package/dist/{esm/new → esm-node}/compat/utils.js +10 -1
- package/dist/esm-node/index.js +143 -5
- 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 +44 -50
- 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} +3 -3
- 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/compat/hooks.d.ts +7 -0
- package/dist/types/compat/index.d.ts +2 -0
- package/dist/types/config/default.d.ts +4 -3
- 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 +8 -5
- 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/initialize/index.d.ts +2 -2
- package/dist/types/plugins/serverBuild.d.ts +2 -2
- package/dist/types/types/index.d.ts +7 -3
- package/dist/types/types/new.d.ts +157 -0
- package/dist/types/utils/env.d.ts +2 -2
- 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/lib/types.d.ts +82 -61
- package/package.json +24 -24
- 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/hooks.d.ts +0 -8
- package/dist/types/new/compat/index.d.ts +0 -4
- package/dist/types/new/index.d.ts +0 -9
- package/dist/types/new/loadPlugins.d.ts +0 -9
- package/dist/types/new/types/index.d.ts +0 -90
- 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/{new/types/index.js → types/new.js} +0 -0
- /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
- /package/dist/esm-node/{new/types/index.js → types/new.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
@@ -28,7 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
29
|
var getHtmlTemplate_exports = {};
|
30
30
|
__export(getHtmlTemplate_exports, {
|
31
|
-
getHtmlTemplate: () => getHtmlTemplate
|
31
|
+
getHtmlTemplate: () => getHtmlTemplate,
|
32
|
+
getModifyHtmlPartials: () => getModifyHtmlPartials
|
32
33
|
});
|
33
34
|
module.exports = __toCommonJS(getHtmlTemplate_exports);
|
34
35
|
var import_path = __toESM(require("path"));
|
@@ -54,7 +55,36 @@ const findPartials = (dir, entryName, position) => {
|
|
54
55
|
}
|
55
56
|
return null;
|
56
57
|
};
|
57
|
-
const
|
58
|
+
const getModifyHtmlPartials = (partials) => {
|
59
|
+
const append = (type, ...script) => {
|
60
|
+
script.forEach((item) => {
|
61
|
+
partials[type].push(item);
|
62
|
+
});
|
63
|
+
};
|
64
|
+
const prepend = (type, ...script) => {
|
65
|
+
script.forEach((item) => {
|
66
|
+
partials[type].unshift(item);
|
67
|
+
});
|
68
|
+
};
|
69
|
+
return {
|
70
|
+
top: {
|
71
|
+
append: (...script) => append("top", ...script),
|
72
|
+
prepend: (...script) => prepend("top", ...script),
|
73
|
+
current: partials.top
|
74
|
+
},
|
75
|
+
head: {
|
76
|
+
append: (...script) => append("head", ...script),
|
77
|
+
prepend: (...script) => prepend("head", ...script),
|
78
|
+
current: partials.head
|
79
|
+
},
|
80
|
+
body: {
|
81
|
+
append: (...script) => append("body", ...script),
|
82
|
+
prepend: (...script) => prepend("body", ...script),
|
83
|
+
current: partials.body
|
84
|
+
}
|
85
|
+
};
|
86
|
+
};
|
87
|
+
const getHtmlTemplate = async (entrypoints, hooks, { appContext, config }) => {
|
58
88
|
const { appDirectory, internalDirectory } = appContext;
|
59
89
|
const { source: { configDir } } = config;
|
60
90
|
const htmlDir = import_path.default.resolve(appDirectory, configDir || "", import_constants.HTML_PARTIALS_FOLDER);
|
@@ -67,24 +97,20 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
|
|
67
97
|
if (customIndexTemplate) {
|
68
98
|
htmlTemplates[entryName] = customIndexTemplate.file;
|
69
99
|
} else {
|
70
|
-
const
|
71
|
-
|
100
|
+
const getPartialInitValue = (position) => {
|
101
|
+
const partial = findPartials(htmlDir, name, position);
|
102
|
+
return partial ? [
|
103
|
+
partial.content
|
104
|
+
] : [];
|
105
|
+
};
|
106
|
+
const partials = {
|
107
|
+
top: getPartialInitValue("top"),
|
108
|
+
head: getPartialInitValue("head"),
|
109
|
+
body: getPartialInitValue("body")
|
110
|
+
};
|
111
|
+
await hooks.modifyHtmlPartials.call({
|
72
112
|
entrypoint,
|
73
|
-
partials:
|
74
|
-
"top",
|
75
|
-
"head",
|
76
|
-
"body"
|
77
|
-
].reduce((previous, position) => {
|
78
|
-
const found = findPartials(htmlDir, name, position);
|
79
|
-
previous[position] = found ? [
|
80
|
-
found.content
|
81
|
-
] : [];
|
82
|
-
return previous;
|
83
|
-
}, {
|
84
|
-
top: [],
|
85
|
-
head: [],
|
86
|
-
body: []
|
87
|
-
})
|
113
|
+
partials: getModifyHtmlPartials(partials)
|
88
114
|
});
|
89
115
|
const templatePath = import_path.default.resolve(internalDirectory, entryName, "index.html");
|
90
116
|
import_utils.fs.outputFileSync(templatePath, templates.html(partials), "utf8");
|
@@ -96,13 +122,13 @@ const getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
|
|
96
122
|
}
|
97
123
|
}
|
98
124
|
}
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
}
|
103
|
-
return htmlTemplates;
|
125
|
+
return {
|
126
|
+
partialsByEntrypoint,
|
127
|
+
htmlTemplates
|
128
|
+
};
|
104
129
|
};
|
105
130
|
// Annotate the CommonJS export names for ESM import in node:
|
106
131
|
0 && (module.exports = {
|
107
|
-
getHtmlTemplate
|
132
|
+
getHtmlTemplate,
|
133
|
+
getModifyHtmlPartials
|
108
134
|
});
|
@@ -49,146 +49,144 @@ var analyze_default = ({ bundler }) => ({
|
|
49
49
|
setup: (api) => {
|
50
50
|
let pagesDir = [];
|
51
51
|
let nestedRouteEntries = [];
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
import_utils.fs.emptydirSync(appContext.internalDirectory);
|
61
|
-
}
|
62
|
-
} catch {
|
63
|
-
}
|
64
|
-
const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
|
65
|
-
await hookRunners.addRuntimeExports();
|
66
|
-
if (apiOnly) {
|
67
|
-
const { routes: routes2 } = await hookRunners.modifyServerRoutes({
|
68
|
-
routes: []
|
69
|
-
});
|
70
|
-
debug(`server routes: %o`, routes2);
|
71
|
-
appContext = {
|
72
|
-
...api.useAppContext(),
|
73
|
-
apiOnly,
|
74
|
-
serverRoutes: routes2
|
75
|
-
};
|
76
|
-
api.setAppContext(appContext);
|
77
|
-
return;
|
52
|
+
api.onPrepare(async () => {
|
53
|
+
var _resolvedConfig_source;
|
54
|
+
let appContext = api.getAppContext();
|
55
|
+
const resolvedConfig = api.getNormalizedConfig();
|
56
|
+
const hooks = api.getHooks();
|
57
|
+
try {
|
58
|
+
if ((0, import_utils2.checkIsBuildCommands)()) {
|
59
|
+
import_utils.fs.emptydirSync(appContext.internalDirectory);
|
78
60
|
}
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
const {
|
85
|
-
|
61
|
+
} catch {
|
62
|
+
}
|
63
|
+
const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
|
64
|
+
await hooks.addRuntimeExports.call();
|
65
|
+
if (apiOnly) {
|
66
|
+
const { routes: routes2 } = await hooks.modifyServerRoutes.call({
|
67
|
+
routes: []
|
86
68
|
});
|
87
|
-
debug(`
|
88
|
-
|
89
|
-
|
90
|
-
|
69
|
+
debug(`server routes: %o`, routes2);
|
70
|
+
api.updateAppContext({
|
71
|
+
apiOnly,
|
72
|
+
serverRoutes: routes2
|
91
73
|
});
|
92
|
-
|
93
|
-
|
74
|
+
return;
|
75
|
+
}
|
76
|
+
const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
|
77
|
+
import("./getBundleEntry.js"),
|
78
|
+
import("./getServerRoutes.js"),
|
79
|
+
import("./getHtmlTemplate.js")
|
80
|
+
]);
|
81
|
+
const { entrypoints } = await hooks.modifyEntrypoints.call({
|
82
|
+
entrypoints: await getBundleEntry(hooks, appContext, resolvedConfig)
|
83
|
+
});
|
84
|
+
debug(`entrypoints: %o`, entrypoints);
|
85
|
+
const initialRoutes = getServerRoutes(entrypoints, {
|
86
|
+
appContext,
|
87
|
+
config: resolvedConfig
|
88
|
+
});
|
89
|
+
const { routes } = await hooks.modifyServerRoutes.call({
|
90
|
+
routes: initialRoutes
|
91
|
+
});
|
92
|
+
debug(`server routes: %o`, routes);
|
93
|
+
appContext = {
|
94
|
+
...api.getAppContext(),
|
95
|
+
entrypoints,
|
96
|
+
serverRoutes: routes
|
97
|
+
};
|
98
|
+
api.updateAppContext(appContext);
|
99
|
+
nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
100
|
+
pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
|
101
|
+
const { partialsByEntrypoint, htmlTemplates } = await getHtmlTemplate(entrypoints, hooks, {
|
102
|
+
appContext,
|
103
|
+
config: resolvedConfig
|
104
|
+
});
|
105
|
+
debug(`html templates: %o`, htmlTemplates);
|
106
|
+
api.updateAppContext({
|
107
|
+
partialsByEntrypoint
|
108
|
+
});
|
109
|
+
let checkedEntries = entrypoints.map((point) => point.entryName);
|
110
|
+
if ((0, import_utils.isDevCommand)()) {
|
111
|
+
const { entry } = (0, import_utils.minimist)((0, import_utils.getArgv)());
|
112
|
+
checkedEntries = await (0, import_getSelectedEntries.getSelectedEntries)(typeof entry === "string" ? entry.split(",") : entry, entrypoints);
|
113
|
+
}
|
114
|
+
appContext = {
|
115
|
+
...api.getAppContext(),
|
116
|
+
entrypoints,
|
117
|
+
checkedEntries,
|
118
|
+
apiOnly,
|
119
|
+
serverRoutes: routes,
|
120
|
+
htmlTemplates
|
121
|
+
};
|
122
|
+
api.updateAppContext(appContext);
|
123
|
+
if ((0, import_utils2.checkIsBuildCommands)()) {
|
124
|
+
await hooks.generateEntryCode.call({
|
125
|
+
entrypoints
|
94
126
|
});
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
};
|
101
|
-
api.setAppContext(appContext);
|
102
|
-
nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
103
|
-
pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
|
104
|
-
const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
|
105
|
-
appContext,
|
106
|
-
config: resolvedConfig
|
127
|
+
const normalizedConfig = api.getNormalizedConfig();
|
128
|
+
const createBuilderForModern = await (0, import_builder.createBuilderGenerator)(bundler);
|
129
|
+
const builder = await createBuilderForModern({
|
130
|
+
normalizedConfig,
|
131
|
+
appContext
|
107
132
|
});
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
apiOnly,
|
119
|
-
serverRoutes: routes,
|
120
|
-
htmlTemplates
|
121
|
-
};
|
122
|
-
api.setAppContext(appContext);
|
123
|
-
if ((0, import_utils2.checkIsBuildCommands)()) {
|
124
|
-
await hookRunners.generateEntryCode({
|
125
|
-
entrypoints
|
126
|
-
});
|
127
|
-
const normalizedConfig = api.useResolvedConfigContext();
|
128
|
-
const createBuilderForModern = await (0, import_builder.createBuilderGenerator)(bundler);
|
129
|
-
const builder = await createBuilderForModern({
|
130
|
-
normalizedConfig,
|
131
|
-
appContext
|
132
|
-
});
|
133
|
-
builder.onBeforeBuild(async ({ bundlerConfigs, isFirstCompile }) => {
|
134
|
-
if (!isFirstCompile) {
|
135
|
-
return;
|
136
|
-
}
|
137
|
-
const hookRunners2 = api.useHookRunners();
|
138
|
-
await (0, import_routes.generateRoutes)(appContext);
|
139
|
-
await hookRunners2.beforeBuild({
|
140
|
-
bundlerConfigs
|
141
|
-
});
|
133
|
+
builder.onBeforeBuild(async ({ bundlerConfigs, isFirstCompile, environments, isWatch }) => {
|
134
|
+
if (!isFirstCompile) {
|
135
|
+
return;
|
136
|
+
}
|
137
|
+
await (0, import_routes.generateRoutes)(appContext);
|
138
|
+
await hooks.onBeforeBuild.call({
|
139
|
+
isFirstCompile,
|
140
|
+
isWatch,
|
141
|
+
environments,
|
142
|
+
bundlerConfigs
|
142
143
|
});
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
144
|
+
});
|
145
|
+
builder.onAfterBuild(async ({ stats, environments, isFirstCompile, isWatch }) => {
|
146
|
+
await hooks.onAfterBuild.call({
|
147
|
+
stats,
|
148
|
+
environments,
|
149
|
+
isFirstCompile,
|
150
|
+
isWatch
|
149
151
|
});
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
if (isFirstCompile) {
|
156
|
-
(0, import_printInstructions.printInstructions)(hookRunners2, appContext, normalizedConfig);
|
157
|
-
}
|
152
|
+
await (0, import_config2.emitResolvedConfig)(appContext.appDirectory, normalizedConfig);
|
153
|
+
});
|
154
|
+
builder.onDevCompileDone(async ({ isFirstCompile }) => {
|
155
|
+
hooks.onAfterDev.call({
|
156
|
+
isFirstCompile
|
158
157
|
});
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
158
|
+
if (isFirstCompile) {
|
159
|
+
(0, import_printInstructions.printInstructions)(hooks, appContext, normalizedConfig);
|
160
|
+
}
|
161
|
+
});
|
162
|
+
builder.onBeforeCreateCompiler(async ({ bundlerConfigs, environments }) => {
|
163
|
+
await hooks.onBeforeCreateCompiler.call({
|
164
|
+
environments,
|
165
|
+
bundlerConfigs
|
164
166
|
});
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
167
|
+
});
|
168
|
+
builder.onAfterCreateCompiler(async ({ compiler, environments }) => {
|
169
|
+
await hooks.onAfterCreateCompiler.call({
|
170
|
+
environments,
|
171
|
+
compiler
|
170
172
|
});
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
api.setAppContext(appContext);
|
177
|
-
}
|
178
|
-
},
|
179
|
-
watchFiles() {
|
180
|
-
return {
|
181
|
-
files: pagesDir,
|
182
|
-
isPrivate: true
|
183
|
-
};
|
184
|
-
},
|
185
|
-
resolvedConfig({ resolved }) {
|
186
|
-
const appContext = api.useAppContext();
|
187
|
-
const config = (0, import_config.initialNormalizedConfig)(resolved, appContext, bundler);
|
188
|
-
return {
|
189
|
-
resolved: config
|
190
|
-
};
|
173
|
+
});
|
174
|
+
builder.addPlugins(resolvedConfig.builderPlugins);
|
175
|
+
api.updateAppContext({
|
176
|
+
builder
|
177
|
+
});
|
191
178
|
}
|
192
|
-
};
|
179
|
+
});
|
180
|
+
api.addWatchFiles(() => {
|
181
|
+
return {
|
182
|
+
files: pagesDir,
|
183
|
+
isPrivate: true
|
184
|
+
};
|
185
|
+
});
|
186
|
+
api.modifyResolvedConfig((resolved) => {
|
187
|
+
const appContext = api.getAppContext();
|
188
|
+
const config = (0, import_config.initialNormalizedConfig)(resolved, appContext, bundler);
|
189
|
+
return config;
|
190
|
+
});
|
193
191
|
}
|
194
192
|
});
|
@@ -45,20 +45,18 @@ var deploy_default = () => ({
|
|
45
45
|
name: "@modern-js/plugin-deploy",
|
46
46
|
setup: (api) => {
|
47
47
|
const deployTarget = process.env.MODERNJS_DEPLOY || import_std_env.provider || "node";
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
return;
|
54
|
-
}
|
55
|
-
const modernConfig = api.useResolvedConfigContext();
|
56
|
-
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
|
57
|
-
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
|
58
|
-
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
|
59
|
-
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
|
60
|
-
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end());
|
48
|
+
api.deploy(async () => {
|
49
|
+
const appContext = api.getAppContext();
|
50
|
+
const { metaName } = appContext;
|
51
|
+
if (metaName !== "modern-js" && !process.env.MODERNJS_DEPLOY) {
|
52
|
+
return;
|
61
53
|
}
|
62
|
-
|
54
|
+
const modernConfig = api.getNormalizedConfig();
|
55
|
+
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
|
56
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare());
|
57
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput());
|
58
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry());
|
59
|
+
(deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end) && await (deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end());
|
60
|
+
});
|
63
61
|
}
|
64
62
|
});
|
@@ -34,60 +34,54 @@ var initialize_default = ({ bundler }) => ({
|
|
34
34
|
"@modern-js/plugin-polyfill"
|
35
35
|
],
|
36
36
|
setup(api) {
|
37
|
-
|
38
|
-
const appContext = api.
|
39
|
-
const userConfig = api.
|
40
|
-
api.
|
41
|
-
...appContext,
|
37
|
+
api.config(() => {
|
38
|
+
const appContext = api.getAppContext();
|
39
|
+
const userConfig = api.getConfig();
|
40
|
+
api.updateAppContext({
|
42
41
|
bundlerType: bundler
|
43
42
|
});
|
44
43
|
return (0, import_config.checkIsLegacyConfig)(userConfig) ? (0, import_config.createLegacyDefaultConfig)(appContext) : (0, import_config.createDefaultConfig)(appContext);
|
45
|
-
};
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
resolved.security = normalizedConfig.security || {};
|
84
|
-
resolved.experiments = normalizedConfig.experiments;
|
85
|
-
}
|
86
|
-
return {
|
87
|
-
resolved
|
88
|
-
};
|
44
|
+
});
|
45
|
+
api.modifyResolvedConfig(async (resolved) => {
|
46
|
+
var _resolved_output_distPath;
|
47
|
+
let appContext = api.getAppContext();
|
48
|
+
const userConfig = api.getConfig();
|
49
|
+
const port = await getServerPort(resolved);
|
50
|
+
appContext = {
|
51
|
+
...appContext,
|
52
|
+
port,
|
53
|
+
distDirectory: (0, import_utils.ensureAbsolutePath)(appContext.appDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
|
54
|
+
};
|
55
|
+
api.updateAppContext(appContext);
|
56
|
+
const normalizedConfig = (0, import_config.checkIsLegacyConfig)(resolved) ? (0, import_config.transformNormalizedConfig)(resolved) : resolved;
|
57
|
+
resolved._raw = userConfig;
|
58
|
+
resolved.server = {
|
59
|
+
...normalizedConfig.server || {},
|
60
|
+
port
|
61
|
+
};
|
62
|
+
var _normalizedConfig_autoLoadPlugins;
|
63
|
+
resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
|
64
|
+
stabilizeConfig(resolved, normalizedConfig, [
|
65
|
+
"source",
|
66
|
+
"bff",
|
67
|
+
"dev",
|
68
|
+
"html",
|
69
|
+
"output",
|
70
|
+
"tools",
|
71
|
+
"testing",
|
72
|
+
"plugins",
|
73
|
+
"builderPlugins",
|
74
|
+
"runtime",
|
75
|
+
"runtimeByEntries",
|
76
|
+
"deploy",
|
77
|
+
"performance"
|
78
|
+
]);
|
79
|
+
if (bundler === "webpack") {
|
80
|
+
resolved.security = normalizedConfig.security || {};
|
81
|
+
resolved.experiments = normalizedConfig.experiments;
|
89
82
|
}
|
90
|
-
|
83
|
+
return resolved;
|
84
|
+
});
|
91
85
|
}
|
92
86
|
});
|
93
87
|
function stabilizeConfig(resolve, config, keys) {
|
@@ -50,39 +50,37 @@ function checkHasConfig(appDir, metaName = "modern-js") {
|
|
50
50
|
var serverBuild_default = () => ({
|
51
51
|
name: "@modern-js/server-build",
|
52
52
|
setup(api) {
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
sourceDirs.push(sharedDir);
|
69
|
-
}
|
70
|
-
}
|
71
|
-
const { server } = modernConfig;
|
72
|
-
const { alias } = modernConfig.source;
|
73
|
-
const { babel } = modernConfig.tools;
|
74
|
-
if (sourceDirs.length > 0) {
|
75
|
-
await (0, import_server_utils.compile)(appDirectory, {
|
76
|
-
server,
|
77
|
-
alias,
|
78
|
-
babelConfig: babel
|
79
|
-
}, {
|
80
|
-
sourceDirs,
|
81
|
-
distDir,
|
82
|
-
tsconfigPath
|
83
|
-
});
|
53
|
+
api.onAfterBuild(async () => {
|
54
|
+
const { appDirectory, distDirectory, metaName } = api.getAppContext();
|
55
|
+
if (!checkHasCache(appDirectory) && !checkHasConfig(appDirectory, metaName)) {
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
const modernConfig = api.getNormalizedConfig();
|
59
|
+
const distDir = import_path.default.resolve(distDirectory);
|
60
|
+
const serverDir = import_path.default.resolve(appDirectory, import_utils.SERVER_DIR);
|
61
|
+
const sharedDir = import_path.default.resolve(appDirectory, import_utils.SHARED_DIR);
|
62
|
+
const tsconfigPath = import_path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
|
63
|
+
const sourceDirs = [];
|
64
|
+
if (import_fs.default.existsSync(serverDir)) {
|
65
|
+
sourceDirs.push(serverDir);
|
66
|
+
if (import_fs.default.existsSync(sharedDir)) {
|
67
|
+
sourceDirs.push(sharedDir);
|
84
68
|
}
|
85
69
|
}
|
86
|
-
|
70
|
+
const { server } = modernConfig;
|
71
|
+
const { alias } = modernConfig.source;
|
72
|
+
const { babel } = modernConfig.tools;
|
73
|
+
if (sourceDirs.length > 0) {
|
74
|
+
await (0, import_server_utils.compile)(appDirectory, {
|
75
|
+
server,
|
76
|
+
alias,
|
77
|
+
babelConfig: babel
|
78
|
+
}, {
|
79
|
+
sourceDirs,
|
80
|
+
distDir,
|
81
|
+
tsconfigPath
|
82
|
+
});
|
83
|
+
}
|
84
|
+
});
|
87
85
|
}
|
88
86
|
});
|
@@ -24,11 +24,11 @@ module.exports = __toCommonJS(run_exports);
|
|
24
24
|
var import_cli = require("@modern-js/plugin-v2/cli");
|
25
25
|
var import_run = require("@modern-js/plugin-v2/run");
|
26
26
|
var import_utils = require("@modern-js/utils");
|
27
|
-
var import_hooks = require("
|
28
|
-
var import_constants = require("
|
29
|
-
var import_getConfigFile = require("
|
30
|
-
var
|
31
|
-
var
|
27
|
+
var import_hooks = require("../compat/hooks");
|
28
|
+
var import_constants = require("../constants");
|
29
|
+
var import_getConfigFile = require("../utils/getConfigFile");
|
30
|
+
var import_isAutoLoadPlugins = require("../utils/isAutoLoadPlugins");
|
31
|
+
var import_loadPlugins = require("../utils/loadPlugins");
|
32
32
|
async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfig, configFile }) {
|
33
33
|
const command = process.argv[2];
|
34
34
|
const cliParams = (0, import_utils.minimist)(process.argv.slice(2));
|
@@ -50,7 +50,7 @@ async function run({ cwd, initialLog, version, internalPlugins, packageJsonConfi
|
|
50
50
|
}
|
51
51
|
const appDirectory = await (0, import_cli.initAppDir)(cwd);
|
52
52
|
const finalConfigFile = customConfigFile || (0, import_getConfigFile.getConfigFile)(configFile);
|
53
|
-
const autoLoadPlugins = await (0,
|
53
|
+
const autoLoadPlugins = await (0, import_isAutoLoadPlugins.isAutoLoadPlugins)(appDirectory, finalConfigFile);
|
54
54
|
const plugins = await (0, import_loadPlugins.loadInternalPlugins)(appDirectory, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.cli, internalPlugins === null || internalPlugins === void 0 ? void 0 : internalPlugins.autoLoad, autoLoadPlugins);
|
55
55
|
await (0, import_run.run)({
|
56
56
|
cwd,
|
@@ -12,5 +12,5 @@ var __copyProps = (to, from, except, desc) => {
|
|
12
12
|
return to;
|
13
13
|
};
|
14
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
15
|
-
var
|
16
|
-
module.exports = __toCommonJS(
|
15
|
+
var new_exports = {};
|
16
|
+
module.exports = __toCommonJS(new_exports);
|
@@ -33,7 +33,7 @@ __export(getConfigFile_exports, {
|
|
33
33
|
module.exports = __toCommonJS(getConfigFile_exports);
|
34
34
|
var import_path = __toESM(require("path"));
|
35
35
|
var import_utils = require("@modern-js/utils");
|
36
|
-
var import_constants = require("
|
36
|
+
var import_constants = require("../constants");
|
37
37
|
const getConfigFile = (configFile) => (0, import_utils.findExists)(import_utils.CONFIG_FILE_EXTENSIONS.map((extension) => import_path.default.resolve(process.cwd(), `${configFile || import_constants.DEFAULT_CONFIG_FILE}${extension}`)));
|
38
38
|
// Annotate the CommonJS export names for ESM import in node:
|
39
39
|
0 && (module.exports = {
|