@modern-js/app-tools 2.63.0 → 2.63.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. package/dist/cjs/commands/dev.js +1 -1
  2. package/dist/cjs/commands/serve.js +1 -1
  3. package/dist/cjs/new/compat/hooks.js +11 -4
  4. package/dist/cjs/new/compat/utils.js +10 -1
  5. package/dist/cjs/new/context.js +0 -1
  6. package/dist/cjs/plugins/analyze/getBundleEntry.js +2 -2
  7. package/dist/cjs/plugins/analyze/getFileSystemEntry.js +9 -9
  8. package/dist/cjs/plugins/analyze/getHtmlTemplate.js +51 -25
  9. package/dist/cjs/plugins/analyze/index.js +128 -130
  10. package/dist/cjs/plugins/deploy/index.js +12 -14
  11. package/dist/cjs/plugins/initialize/index.js +1 -1
  12. package/dist/cjs/utils/printInstructions.js +12 -3
  13. package/dist/cjs/utils/restart.js +2 -1
  14. package/dist/esm/commands/dev.js +2 -2
  15. package/dist/esm/commands/serve.js +2 -2
  16. package/dist/esm/new/compat/hooks.js +27 -17
  17. package/dist/esm/new/compat/utils.js +10 -1
  18. package/dist/esm/new/context.js +0 -1
  19. package/dist/esm/plugins/analyze/getBundleEntry.js +3 -3
  20. package/dist/esm/plugins/analyze/getFileSystemEntry.js +12 -12
  21. package/dist/esm/plugins/analyze/getHtmlTemplate.js +101 -28
  22. package/dist/esm/plugins/analyze/index.js +328 -331
  23. package/dist/esm/plugins/deploy/index.js +84 -88
  24. package/dist/esm/plugins/initialize/index.js +1 -1
  25. package/dist/esm/utils/printInstructions.js +29 -2
  26. package/dist/esm/utils/restart.js +2 -1
  27. package/dist/esm-node/commands/dev.js +2 -2
  28. package/dist/esm-node/commands/serve.js +2 -2
  29. package/dist/esm-node/new/compat/hooks.js +11 -4
  30. package/dist/esm-node/new/compat/utils.js +10 -1
  31. package/dist/esm-node/new/context.js +0 -1
  32. package/dist/esm-node/plugins/analyze/getBundleEntry.js +2 -2
  33. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +9 -9
  34. package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +49 -24
  35. package/dist/esm-node/plugins/analyze/index.js +128 -130
  36. package/dist/esm-node/plugins/deploy/index.js +12 -14
  37. package/dist/esm-node/plugins/initialize/index.js +1 -1
  38. package/dist/esm-node/utils/printInstructions.js +10 -2
  39. package/dist/esm-node/utils/restart.js +2 -1
  40. package/dist/types/builder/generator/adapterCopy.d.ts +2 -1
  41. package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +3 -2
  42. package/dist/types/builder/generator/createCopyPattern.d.ts +4 -3
  43. package/dist/types/builder/generator/getBuilderEnvironments.d.ts +2 -2
  44. package/dist/types/builder/index.d.ts +1 -1
  45. package/dist/types/builder/shared/createCopyInfo.d.ts +3 -2
  46. package/dist/types/builder/shared/types.d.ts +3 -2
  47. package/dist/types/config/initialize/index.d.ts +3 -2
  48. package/dist/types/config/initialize/inits.d.ts +4 -3
  49. package/dist/types/new/context.d.ts +0 -1
  50. package/dist/types/plugins/analyze/getBundleEntry.d.ts +3 -3
  51. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +3 -3
  52. package/dist/types/plugins/analyze/getHtmlTemplate.d.ts +26 -5
  53. package/dist/types/plugins/analyze/getServerRoutes.d.ts +2 -2
  54. package/dist/types/plugins/analyze/index.d.ts +2 -3
  55. package/dist/types/plugins/deploy/index.d.ts +2 -3
  56. package/dist/types/plugins/deploy/platforms/platform.d.ts +3 -3
  57. package/dist/types/plugins/deploy/utils.d.ts +2 -2
  58. package/dist/types/types/new.d.ts +38 -21
  59. package/dist/types/utils/printInstructions.d.ts +3 -1
  60. package/dist/types/utils/routes.d.ts +2 -1
  61. package/package.json +20 -20
@@ -113,7 +113,7 @@ const dev = async (api, options, devServerOptions) => {
113
113
  port,
114
114
  host
115
115
  }, () => {
116
- (0, import_printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
116
+ (0, import_printInstructions.printInstructionsCompat)(hookRunners, appContext, normalizedConfig);
117
117
  });
118
118
  } else {
119
119
  const { server, afterListen } = await (0, import_server.createDevServer)({
@@ -77,7 +77,7 @@ const start = async (api) => {
77
77
  runMode
78
78
  });
79
79
  app.listen(port, async () => {
80
- await (0, import_printInstructions.printInstructions)(hookRunners, appContext, userConfig);
80
+ await (0, import_printInstructions.printInstructionsCompat)(hookRunners, appContext, userConfig);
81
81
  });
82
82
  };
83
83
  // Annotate the CommonJS export names for ESM import in node:
@@ -22,6 +22,7 @@ __export(hooks_exports, {
22
22
  handleSetupResult: () => handleSetupResult
23
23
  });
24
24
  module.exports = __toCommonJS(hooks_exports);
25
+ var import_getHtmlTemplate = require("../../plugins/analyze/getHtmlTemplate");
25
26
  var import_utils = require("./utils");
26
27
  function getHookRunners(context) {
27
28
  const { hooks } = context;
@@ -80,7 +81,13 @@ function getHookRunners(context) {
80
81
  return hooks.modifyResolvedConfig.call(params);
81
82
  },
82
83
  htmlPartials: async (params) => {
83
- return hooks.modifyHtmlPartials.call(params);
84
+ await hooks.modifyHtmlPartials.call({
85
+ entrypoint: params.entrypoint,
86
+ partials: (0, import_getHtmlTemplate.getModifyHtmlPartials)(params.partials)
87
+ });
88
+ return {
89
+ partials: params.partials
90
+ };
84
91
  },
85
92
  commands: async (params) => {
86
93
  return hooks.addCommand.call(params);
@@ -91,7 +98,7 @@ function getHookRunners(context) {
91
98
  prepare: async () => {
92
99
  return hooks.onPrepare.call();
93
100
  },
94
- filedChange: async (params) => {
101
+ fileChange: async (params) => {
95
102
  return hooks.onFileChanged.call(params);
96
103
  },
97
104
  beforeCreateCompiler: async (params) => {
@@ -139,8 +146,8 @@ function getHookRunners(context) {
139
146
  /**
140
147
  * @deprecated
141
148
  */
142
- addRuntimeExports: async (params) => {
143
- return hooks.addRuntimeExports.call(params);
149
+ addRuntimeExports: async () => {
150
+ return hooks.addRuntimeExports.call();
144
151
  }
145
152
  };
146
153
  }
@@ -41,7 +41,7 @@ function transformHookRunner(hookRunnerName) {
41
41
  return "addCommand";
42
42
  case "watchFiles":
43
43
  return "addWatchFiles";
44
- case "filedChange":
44
+ case "fileChange":
45
45
  return "onFileChanged";
46
46
  case "beforeCreateCompiler":
47
47
  return "onBeforeCreateCompiler";
@@ -75,6 +75,15 @@ function transformHookParams(hookRunnerName, params) {
75
75
  return {
76
76
  resolved: params
77
77
  };
78
+ case "htmlPartials":
79
+ return {
80
+ partials: {
81
+ top: params.partials.top.current,
82
+ head: params.partials.head.current,
83
+ body: params.partials.body.current
84
+ },
85
+ entrypoint: params.entrypoint
86
+ };
78
87
  default:
79
88
  return params;
80
89
  }
@@ -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: {},
@@ -55,10 +55,10 @@ const ifAlreadyExists = (entrypoints, checked) => entrypoints.some((entrypoint)
55
55
  }
56
56
  return false;
57
57
  });
58
- const getBundleEntry = async (hookRunners, appContext, config) => {
58
+ const getBundleEntry = async (hooks, appContext, config) => {
59
59
  const { appDirectory, packageName } = appContext;
60
60
  const { disableDefaultEntries, entries, entriesDir, mainEntryName } = config.source;
61
- const defaults = disableDefaultEntries ? [] : await (0, import_getFileSystemEntry.getFileSystemEntry)(hookRunners, appContext, config);
61
+ const defaults = disableDefaultEntries ? [] : await (0, import_getFileSystemEntry.getFileSystemEntry)(hooks, appContext, config);
62
62
  if (entries) {
63
63
  Object.keys(entries).forEach((name) => {
64
64
  const value = entries[name];
@@ -39,8 +39,8 @@ var import_isDefaultExportFunction = require("./isDefaultExportFunction");
39
39
  const hasIndex = (dir) => (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.INDEX_FILE_NAME}${ext}`)));
40
40
  const hasEntry = (dir) => (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.ENTRY_FILE_NAME}${ext}`)));
41
41
  const hasServerEntry = (dir) => (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.ENTRY_FILE_NAME}.server${ext}`)));
42
- const isBundleEntry = async (hookRunners, dir, enableCustomEntry) => {
43
- const { entry } = await hookRunners.checkEntryPoint({
42
+ const isBundleEntry = async (hooks, dir, enableCustomEntry) => {
43
+ const { entry } = await hooks.checkEntryPoint.call({
44
44
  path: dir,
45
45
  entry: false
46
46
  });
@@ -53,7 +53,7 @@ const isBundleEntry = async (hookRunners, dir, enableCustomEntry) => {
53
53
  }
54
54
  return hasIndex(dir);
55
55
  };
56
- const scanDir = async (hookRunners, dirs, enableCustomEntry) => {
56
+ const scanDir = async (hooks, dirs, enableCustomEntry) => {
57
57
  const entries = await Promise.all(dirs.map(async (dir) => {
58
58
  const indexFile = hasIndex(dir);
59
59
  const customBootstrap = (0, import_isDefaultExportFunction.isDefaultExportFunction)(indexFile) ? indexFile : false;
@@ -70,7 +70,7 @@ const scanDir = async (hookRunners, dirs, enableCustomEntry) => {
70
70
  customBootstrap
71
71
  };
72
72
  }
73
- const entryFile = (await hookRunners.checkEntryPoint({
73
+ const entryFile = (await hooks.checkEntryPoint.call({
74
74
  path: dir,
75
75
  entry: false
76
76
  })).entry;
@@ -104,7 +104,7 @@ const scanDir = async (hookRunners, dirs, enableCustomEntry) => {
104
104
  }
105
105
  return entries;
106
106
  };
107
- const getFileSystemEntry = async (hookRunners, appContext, config) => {
107
+ const getFileSystemEntry = async (hooks, appContext, config) => {
108
108
  const { appDirectory } = appContext;
109
109
  const { source: { entriesDir, disableEntryDirs, enableCustomEntry } } = config;
110
110
  let disabledDirs = [];
@@ -114,19 +114,19 @@ const getFileSystemEntry = async (hookRunners, appContext, config) => {
114
114
  const src = (0, import_utils.ensureAbsolutePath)(appDirectory, entriesDir || "");
115
115
  if (import_fs.default.existsSync(src)) {
116
116
  if (import_fs.default.statSync(src).isDirectory()) {
117
- if (await isBundleEntry(hookRunners, src, enableCustomEntry)) {
118
- return scanDir(hookRunners, [
117
+ if (await isBundleEntry(hooks, src, enableCustomEntry)) {
118
+ return scanDir(hooks, [
119
119
  src
120
120
  ], enableCustomEntry);
121
121
  }
122
122
  const dirs = [];
123
123
  await Promise.all(import_fs.default.readdirSync(src).map(async (filename) => {
124
124
  const file = import_path.default.join(src, filename);
125
- if (import_fs.default.statSync(file).isDirectory() && await isBundleEntry(hookRunners, file, enableCustomEntry) && !disabledDirs.includes(file)) {
125
+ if (import_fs.default.statSync(file).isDirectory() && await isBundleEntry(hooks, file, enableCustomEntry) && !disabledDirs.includes(file)) {
126
126
  dirs.push(file);
127
127
  }
128
128
  }));
129
- return scanDir(hookRunners, dirs, enableCustomEntry);
129
+ return scanDir(hooks, dirs, enableCustomEntry);
130
130
  } else {
131
131
  throw Error(`source.entriesDir accept a directory.`);
132
132
  }
@@ -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 getHtmlTemplate = async (entrypoints, api, { appContext, config }) => {
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 hookRunners = api.useHookRunners();
71
- const { partials } = await hookRunners.htmlPartials({
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
- api.setAppContext({
100
- ...api.useAppContext(),
101
- partialsByEntrypoint
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
- return {
53
- async prepare() {
54
- var _resolvedConfig_source;
55
- let appContext = api.useAppContext();
56
- const resolvedConfig = api.useResolvedConfigContext();
57
- const hookRunners = api.useHookRunners();
58
- try {
59
- if ((0, import_utils2.checkIsBuildCommands)()) {
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
- const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
80
- import("./getBundleEntry.js"),
81
- import("./getServerRoutes.js"),
82
- import("./getHtmlTemplate.js")
83
- ]);
84
- const { entrypoints } = await hookRunners.modifyEntrypoints({
85
- entrypoints: await getBundleEntry(hookRunners, appContext, resolvedConfig)
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(`entrypoints: %o`, entrypoints);
88
- const initialRoutes = getServerRoutes(entrypoints, {
89
- appContext,
90
- config: resolvedConfig
69
+ debug(`server routes: %o`, routes2);
70
+ api.updateAppContext({
71
+ apiOnly,
72
+ serverRoutes: routes2
91
73
  });
92
- const { routes } = await hookRunners.modifyServerRoutes({
93
- routes: initialRoutes
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
- debug(`server routes: %o`, routes);
96
- appContext = {
97
- ...api.useAppContext(),
98
- entrypoints,
99
- serverRoutes: routes
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
- debug(`html templates: %o`, htmlTemplates);
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.useAppContext(),
116
- entrypoints,
117
- checkedEntries,
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
- builder.onAfterBuild(async ({ stats }) => {
144
- const hookRunners2 = api.useHookRunners();
145
- await hookRunners2.afterBuild({
146
- stats
147
- });
148
- await (0, import_config2.emitResolvedConfig)(appContext.appDirectory, normalizedConfig);
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
- builder.onDevCompileDone(async ({ isFirstCompile }) => {
151
- const hookRunners2 = api.useHookRunners();
152
- hookRunners2.afterDev({
153
- isFirstCompile
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
- builder.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
160
- const hookRunners2 = api.useHookRunners();
161
- await hookRunners2.beforeCreateCompiler({
162
- bundlerConfigs
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
- builder.onAfterCreateCompiler(async ({ compiler }) => {
166
- const hookRunners2 = api.useHookRunners();
167
- await hookRunners2.afterCreateCompiler({
168
- compiler
169
- });
167
+ });
168
+ builder.onAfterCreateCompiler(async ({ compiler, environments }) => {
169
+ await hooks.onAfterCreateCompiler.call({
170
+ environments,
171
+ compiler
170
172
  });
171
- builder.addPlugins(resolvedConfig.builderPlugins);
172
- appContext = {
173
- ...api.useAppContext(),
174
- builder
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
- return {
49
- async deploy() {
50
- const appContext = api.useAppContext();
51
- const { metaName } = appContext;
52
- if (metaName !== "modern-js" && !process.env.MODERNJS_DEPLOY) {
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.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
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;
@@ -18,11 +18,19 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var printInstructions_exports = {};
20
20
  __export(printInstructions_exports, {
21
- printInstructions: () => printInstructions
21
+ printInstructions: () => printInstructions,
22
+ printInstructionsCompat: () => printInstructionsCompat
22
23
  });
23
24
  module.exports = __toCommonJS(printInstructions_exports);
24
25
  var import_utils = require("@modern-js/utils");
25
- const printInstructions = async (hookRunners, appContext, config) => {
26
+ const printInstructions = async (hooks, appContext, config) => {
27
+ const message = (0, import_utils.prettyInstructions)(appContext, config);
28
+ const { instructions } = await hooks.onBeforePrintInstructions.call({
29
+ instructions: message
30
+ });
31
+ import_utils.logger.log(instructions);
32
+ };
33
+ const printInstructionsCompat = async (hookRunners, appContext, config) => {
26
34
  const message = (0, import_utils.prettyInstructions)(appContext, config);
27
35
  const { instructions } = await hookRunners.beforePrintInstructions({
28
36
  instructions: message
@@ -31,5 +39,6 @@ const printInstructions = async (hookRunners, appContext, config) => {
31
39
  };
32
40
  // Annotate the CommonJS export names for ESM import in node:
33
41
  0 && (module.exports = {
34
- printInstructions
42
+ printInstructions,
43
+ printInstructionsCompat
35
44
  });
@@ -23,6 +23,7 @@ __export(restart_exports, {
23
23
  module.exports = __toCommonJS(restart_exports);
24
24
  var import_cli = require("@modern-js/plugin-v2/cli");
25
25
  var import_utils = require("@modern-js/utils");
26
+ var import_commander = require("@modern-js/utils/commander");
26
27
  async function restart(hooksRunner, filename) {
27
28
  (0, import_utils.clearConsole)();
28
29
  import_utils.logger.info(`Restart because ${import_utils.chalk.yellow(filename)} is changed...
@@ -36,7 +37,7 @@ async function restart(hooksRunner, filename) {
36
37
  hasGetError = true;
37
38
  } finally {
38
39
  if (!hasGetError) {
39
- import_utils.program.parse((0, import_utils.getFullArgv)());
40
+ import_commander.program.parse((0, import_utils.getFullArgv)());
40
41
  }
41
42
  }
42
43
  }