@modern-js/app-tools 2.63.0 → 2.63.1-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/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
|
@@ -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
|
});
|
|
@@ -50,7 +50,7 @@ var initialize_default = ({ bundler }) => ({
|
|
|
50
50
|
appContext = {
|
|
51
51
|
...appContext,
|
|
52
52
|
port,
|
|
53
|
-
distDirectory: (0, import_utils.ensureAbsolutePath)(appContext.
|
|
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
54
|
};
|
|
55
55
|
api.updateAppContext(appContext);
|
|
56
56
|
const normalizedConfig = (0, import_config.checkIsLegacyConfig)(resolved) ? (0, import_config.transformNormalizedConfig)(resolved) : resolved;
|
|
@@ -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,
|
|
@@ -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 = {
|
|
@@ -26,11 +26,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var initAppContext_exports = {};
|
|
30
|
+
__export(initAppContext_exports, {
|
|
31
31
|
initAppContext: () => initAppContext
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
33
|
+
module.exports = __toCommonJS(initAppContext_exports);
|
|
34
34
|
var import_path = __toESM(require("path"));
|
|
35
35
|
var import_utils = require("@modern-js/utils");
|
|
36
36
|
const initAppContext = ({ appDirectory, runtimeConfigFile, options, serverConfigFile, tempDir }) => {
|
|
@@ -46,7 +46,6 @@ const initAppContext = ({ appDirectory, runtimeConfigFile, options, serverConfig
|
|
|
46
46
|
apiDirectory: import_path.default.resolve(appDirectory, apiDir),
|
|
47
47
|
lambdaDirectory: import_path.default.resolve(appDirectory, apiDir, "lambda"),
|
|
48
48
|
sharedDirectory: import_path.default.resolve(appDirectory, sharedDir),
|
|
49
|
-
distDirectory: distDir,
|
|
50
49
|
serverPlugins: [],
|
|
51
50
|
internalDirectory: import_path.default.resolve(appDirectory, tempDir || `./node_modules/.${metaName}`),
|
|
52
51
|
htmlTemplates: {},
|
|
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var isAutoLoadPlugins_exports = {};
|
|
20
|
+
__export(isAutoLoadPlugins_exports, {
|
|
21
|
+
isAutoLoadPlugins: () => isAutoLoadPlugins
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
23
|
+
module.exports = __toCommonJS(isAutoLoadPlugins_exports);
|
|
24
24
|
var import_cli = require("@modern-js/plugin-v2/cli");
|
|
25
|
-
async function
|
|
25
|
+
async function isAutoLoadPlugins(appDirectory, configFile = "modern.config.ts", packageJsonConfig = "ModernConfig") {
|
|
26
26
|
var _loaded_config;
|
|
27
27
|
const loaded = await (0, import_cli.createLoadedConfig)(appDirectory, configFile, packageJsonConfig);
|
|
28
28
|
const autoLoadPlugins = (_loaded_config = loaded.config) === null || _loaded_config === void 0 ? void 0 : _loaded_config.autoLoadPlugins;
|
|
@@ -30,5 +30,5 @@ async function getIsAutoLoadPlugins(appDirectory, configFile = "modern.config.ts
|
|
|
30
30
|
}
|
|
31
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
32
|
0 && (module.exports = {
|
|
33
|
-
|
|
33
|
+
isAutoLoadPlugins
|
|
34
34
|
});
|
|
@@ -19,18 +19,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var loadPlugins_exports = {};
|
|
20
20
|
__export(loadPlugins_exports, {
|
|
21
21
|
getServerPlugins: () => getServerPlugins,
|
|
22
|
+
loadInternalPlugins: () => loadInternalPlugins,
|
|
22
23
|
loadServerPlugins: () => loadServerPlugins
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(loadPlugins_exports);
|
|
25
26
|
var import_prod_server = require("@modern-js/prod-server");
|
|
27
|
+
var import_utils = require("@modern-js/utils");
|
|
28
|
+
const debug = (0, import_utils.createDebugger)("load-plugins");
|
|
26
29
|
async function getServerPlugins(api, metaName = "modern-js") {
|
|
27
|
-
const
|
|
28
|
-
const { plugins } = await
|
|
30
|
+
const hooks = api.getHooks();
|
|
31
|
+
const { plugins } = await hooks._internalServerPlugins.call({
|
|
29
32
|
plugins: []
|
|
30
33
|
});
|
|
31
34
|
const filtedPlugins = plugins.filter((plugin) => plugin.name.includes(metaName));
|
|
32
|
-
api.
|
|
33
|
-
...api.useAppContext(),
|
|
35
|
+
api.updateAppContext({
|
|
34
36
|
serverPlugins: filtedPlugins
|
|
35
37
|
});
|
|
36
38
|
return filtedPlugins;
|
|
@@ -40,8 +42,37 @@ async function loadServerPlugins(api, appDirectory, metaName) {
|
|
|
40
42
|
const instances = await (0, import_prod_server.loadServerPlugins)(plugins, appDirectory);
|
|
41
43
|
return instances;
|
|
42
44
|
}
|
|
45
|
+
const resolveCliPlugin = async (p, appDirectory) => {
|
|
46
|
+
const pkg = typeof p === "string" ? p : p[0];
|
|
47
|
+
const pluginOptions = typeof p === "string" ? void 0 : p[1];
|
|
48
|
+
const path = (0, import_utils.tryResolve)(pkg, appDirectory);
|
|
49
|
+
let module2;
|
|
50
|
+
try {
|
|
51
|
+
module2 = await (0, import_utils.compatibleRequire)(path);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
({ default: module2 } = await (0, import_utils.dynamicImport)(path));
|
|
54
|
+
}
|
|
55
|
+
if (typeof module2 === "function") {
|
|
56
|
+
const result = module2(pluginOptions);
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
return module2;
|
|
60
|
+
};
|
|
61
|
+
const loadInternalPlugins = async (appDirectory, internalPlugins, autoLoad, autoLoadPlugins) => {
|
|
62
|
+
const plugins = [
|
|
63
|
+
...autoLoadPlugins ? (0, import_utils.getInternalPlugins)(appDirectory, internalPlugins) : [],
|
|
64
|
+
...autoLoad ? (0, import_utils.getInternalPlugins)(appDirectory, autoLoad) : []
|
|
65
|
+
];
|
|
66
|
+
const loadedPlugins = await Promise.all(plugins.map((plugin) => {
|
|
67
|
+
const loadedPlugin = resolveCliPlugin(plugin, appDirectory);
|
|
68
|
+
debug(`resolve plugin %s: %s`, plugin, loadedPlugin);
|
|
69
|
+
return loadedPlugin;
|
|
70
|
+
}));
|
|
71
|
+
return loadedPlugins;
|
|
72
|
+
};
|
|
43
73
|
// Annotate the CommonJS export names for ESM import in node:
|
|
44
74
|
0 && (module.exports = {
|
|
45
75
|
getServerPlugins,
|
|
76
|
+
loadInternalPlugins,
|
|
46
77
|
loadServerPlugins
|
|
47
78
|
});
|
|
@@ -22,9 +22,9 @@ __export(printInstructions_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(printInstructions_exports);
|
|
24
24
|
var import_utils = require("@modern-js/utils");
|
|
25
|
-
const printInstructions = async (
|
|
25
|
+
const printInstructions = async (hooks, appContext, config) => {
|
|
26
26
|
const message = (0, import_utils.prettyInstructions)(appContext, config);
|
|
27
|
-
const { instructions } = await
|
|
27
|
+
const { instructions } = await hooks.onBeforePrintInstructions.call({
|
|
28
28
|
instructions: message
|
|
29
29
|
});
|
|
30
30
|
import_utils.logger.log(instructions);
|