@modern-js/app-tools 2.27.0 → 2.28.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/cjs/analyze/generateCode.js +2 -2
  3. package/dist/cjs/analyze/getFileSystemEntry.js +2 -1
  4. package/dist/cjs/analyze/getServerRoutes.js +5 -4
  5. package/dist/cjs/analyze/index.js +209 -211
  6. package/dist/cjs/analyze/nestedRoutes.js +2 -2
  7. package/dist/cjs/analyze/templates.js +4 -4
  8. package/dist/cjs/analyze/utils.js +2 -1
  9. package/dist/cjs/builder/builder-rspack/adapterCopy.js +41 -43
  10. package/dist/cjs/builder/builder-webpack/adapterModern.js +23 -25
  11. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +2 -1
  12. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +11 -9
  13. package/dist/cjs/commands/build.js +2 -1
  14. package/dist/cjs/commands/dev.js +3 -2
  15. package/dist/cjs/commands/inspect.js +2 -1
  16. package/dist/cjs/commands/serve.js +2 -2
  17. package/dist/cjs/index.js +7 -2
  18. package/dist/cjs/initialize/index.js +70 -72
  19. package/dist/esm/analyze/generateCode.js +2 -2
  20. package/dist/esm/analyze/getFileSystemEntry.js +2 -1
  21. package/dist/esm/analyze/getServerRoutes.js +5 -4
  22. package/dist/esm/analyze/nestedRoutes.js +2 -2
  23. package/dist/esm/analyze/templates.js +4 -4
  24. package/dist/esm/analyze/utils.js +2 -1
  25. package/dist/esm/builder/builder-rspack/adapterCopy.js +1 -1
  26. package/dist/esm/builder/generator/createBuilderProviderConfig.js +2 -1
  27. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +12 -10
  28. package/dist/esm/commands/build.js +2 -2
  29. package/dist/esm/commands/dev.js +5 -3
  30. package/dist/esm/commands/inspect.js +2 -2
  31. package/dist/esm/commands/serve.js +2 -2
  32. package/dist/esm/index.js +7 -5
  33. package/dist/esm-node/analyze/generateCode.js +2 -2
  34. package/dist/esm-node/analyze/getFileSystemEntry.js +2 -1
  35. package/dist/esm-node/analyze/getServerRoutes.js +5 -4
  36. package/dist/esm-node/analyze/index.js +209 -211
  37. package/dist/esm-node/analyze/nestedRoutes.js +2 -2
  38. package/dist/esm-node/analyze/templates.js +4 -4
  39. package/dist/esm-node/analyze/utils.js +2 -1
  40. package/dist/esm-node/builder/builder-rspack/adapterCopy.js +41 -43
  41. package/dist/esm-node/builder/builder-webpack/adapterModern.js +23 -25
  42. package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +2 -1
  43. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +11 -9
  44. package/dist/esm-node/commands/build.js +2 -1
  45. package/dist/esm-node/commands/dev.js +3 -2
  46. package/dist/esm-node/commands/inspect.js +2 -1
  47. package/dist/esm-node/commands/serve.js +2 -2
  48. package/dist/esm-node/index.js +6 -4
  49. package/dist/esm-node/initialize/index.js +70 -72
  50. package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +2 -2
  51. package/dist/types/analyze/nestedRoutes.d.ts +2 -2
  52. package/dist/types/analyze/templates.d.ts +3 -3
  53. package/dist/types/commands/dev.d.ts +4 -1
  54. package/dist/types/index.d.ts +1 -0
  55. package/dist/types/types/hooks.d.ts +2 -2
  56. package/package.json +24 -24
package/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # @modern-js/app-tools
2
2
 
3
+ ## 2.28.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6eae1e7: feat: support worker hmr using dev-server
8
+ feat: 借用 dev-server 支持 wokrer hmr
9
+
10
+ ### Patch Changes
11
+
12
+ - 4e3ce96: fix: fix type for NestedRoute
13
+ fix: 修复 NestedRoute 的类型
14
+ - Updated dependencies [213089e]
15
+ - Updated dependencies [fb93353]
16
+ - Updated dependencies [4e3ce96]
17
+ - Updated dependencies [d870acd]
18
+ - Updated dependencies [6400d98]
19
+ - Updated dependencies [6eae1e7]
20
+ - Updated dependencies [362416f]
21
+ - Updated dependencies [aa0c0c3]
22
+ - Updated dependencies [9301e46]
23
+ - Updated dependencies [00b58a7]
24
+ - Updated dependencies [820bfe9]
25
+ - Updated dependencies [d3e52e4]
26
+ - Updated dependencies [7d966a1]
27
+ - @modern-js/builder-rspack-provider@2.28.0
28
+ - @modern-js/builder@2.28.0
29
+ - @modern-js/types@2.28.0
30
+ - @modern-js/builder-webpack-provider@2.28.0
31
+ - @modern-js/builder-shared@2.28.0
32
+ - @modern-js/prod-server@2.28.0
33
+ - @modern-js/server@2.28.0
34
+ - @modern-js/utils@2.28.0
35
+ - @modern-js/upgrade@2.28.0
36
+ - @modern-js/builder-plugin-node-polyfill@2.28.0
37
+ - @modern-js/builder-plugin-esbuild@2.28.0
38
+ - @modern-js/core@2.28.0
39
+ - @modern-js/plugin-data-loader@2.28.0
40
+ - @modern-js/server-core@2.28.0
41
+ - @modern-js/plugin-i18n@2.28.0
42
+ - @modern-js/plugin-lint@2.28.0
43
+ - @modern-js/new-action@2.28.0
44
+ - @modern-js/node-bundle-require@2.28.0
45
+ - @modern-js/plugin@2.28.0
46
+
3
47
  ## 2.27.0
4
48
 
5
49
  ### Patch Changes
@@ -87,7 +87,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
87
87
  const { entryName, isMainEntry, isAutoMount, fileSystemRoutes } = entrypoint;
88
88
  if (isAutoMount) {
89
89
  if (fileSystemRoutes) {
90
- var _config_output;
90
+ var _config_output, _config;
91
91
  let initialRoutes = [];
92
92
  let nestedRoute = null;
93
93
  if (entrypoint.entry) {
@@ -134,7 +134,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
134
134
  nestedRoutesEntry: entrypoint.nestedRoutesEntry,
135
135
  entryName: entrypoint.entryName,
136
136
  internalDirectory,
137
- splitRouteChunks: config2 === null || config2 === void 0 ? void 0 : (_config_output = config2.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
137
+ splitRouteChunks: (_config = config2) === null || _config === void 0 ? void 0 : (_config_output = _config.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
138
138
  })
139
139
  });
140
140
  if (entrypoint.nestedRoutesEntry && (0, _utils.isUseSSRBundle)(config2)) {
@@ -80,7 +80,8 @@ const getFileSystemEntry = (appContext, config) => {
80
80
  const { source: { entriesDir, disableEntryDirs } } = config;
81
81
  let disabledDirs = [];
82
82
  if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
83
- disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map((dir) => (0, _utils.ensureAbsolutePath)(appDirectory, dir));
83
+ var _disableEntryDirs;
84
+ disabledDirs = (_disableEntryDirs = disableEntryDirs) === null || _disableEntryDirs === void 0 ? void 0 : _disableEntryDirs.map((dir) => (0, _utils.ensureAbsolutePath)(appDirectory, dir));
84
85
  }
85
86
  const src = (0, _utils.ensureAbsolutePath)(appDirectory, entriesDir || "");
86
87
  if (_fs.default.existsSync(src)) {
@@ -79,17 +79,18 @@ const applyRouteOptions = (original, routeOptions) => {
79
79
  return routes;
80
80
  };
81
81
  const collectHtmlRoutes = (entrypoints, appContext, config) => {
82
- var _deploy_worker;
82
+ var _deploy_worker, _deploy;
83
83
  const { source: { mainEntryName }, html: { disableHtmlFolder }, output: { distPath: { html: htmlPath } = {} }, server: { baseUrl, routes, ssr, ssrByEntries }, deploy } = config;
84
84
  const { packageName } = appContext;
85
- const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
85
+ const workerSSR = (_deploy = deploy) === null || _deploy === void 0 ? void 0 : (_deploy_worker = _deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
86
86
  let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
87
+ var _routes, _routes1;
87
88
  const isMainEntry = entryName === (mainEntryName || _utils.MAIN_ENTRY_NAME);
88
89
  const entryOptions = (0, _utils.getEntryOptions)(entryName, isMainEntry, ssr, ssrByEntries, packageName);
89
90
  const isSSR = Boolean(entryOptions);
90
91
  const isWorker = Boolean(workerSSR);
91
92
  const isStream = typeof entryOptions === "object" && entryOptions.mode === "stream";
92
- const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
93
+ const { resHeaders } = ((_routes = routes) === null || _routes === void 0 ? void 0 : _routes[entryName]) || {};
93
94
  let route = {
94
95
  urlPath: `/${isMainEntry ? "" : entryName}`,
95
96
  entryName,
@@ -101,7 +102,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
101
102
  worker: isWorker ? `${_utils.SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
102
103
  bundle: isSSR ? `${_utils.SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
103
104
  };
104
- if (routes === null || routes === void 0 ? void 0 : routes.hasOwnProperty(entryName)) {
105
+ if ((_routes1 = routes) === null || _routes1 === void 0 ? void 0 : _routes1.hasOwnProperty(entryName)) {
105
106
  const routeOptions = (0, _utils.isPlainObject)(routes[entryName]) ? routes[entryName] : {
106
107
  route: routes[entryName]
107
108
  };
@@ -22,234 +22,232 @@ const _utils1 = require("./utils");
22
22
  const _constants = require("./constants");
23
23
  const _generateCode = require("./generateCode");
24
24
  const debug = (0, _utils.createDebugger)("plugin-analyze");
25
- const _default = ({ bundler }) => {
26
- return {
27
- name: "@modern-js/plugin-analyze",
28
- setup: (api) => {
29
- let pagesDir = [];
30
- let nestedRouteEntries = [];
31
- let originEntrypoints = [];
32
- return {
33
- async prepare() {
34
- var _resolvedConfig_source;
35
- let appContext = api.useAppContext();
36
- const resolvedConfig = api.useResolvedConfigContext();
37
- const hookRunners = api.useHookRunners();
38
- try {
39
- if ((0, _utils1.checkIsBuildCommands)()) {
40
- _utils.fs.emptydirSync(appContext.internalDirectory);
41
- }
42
- } catch {
43
- }
44
- const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
45
- await hookRunners.addRuntimeExports();
46
- if (apiOnly) {
47
- const { routes: routes2 } = await hookRunners.modifyServerRoutes({
48
- routes: []
49
- });
50
- debug(`server routes: %o`, routes2);
51
- appContext = {
52
- ...api.useAppContext(),
53
- apiOnly,
54
- serverRoutes: routes2
55
- };
56
- api.setAppContext(appContext);
57
- return;
25
+ const _default = ({ bundler }) => ({
26
+ name: "@modern-js/plugin-analyze",
27
+ setup: (api) => {
28
+ let pagesDir = [];
29
+ let nestedRouteEntries = [];
30
+ let originEntrypoints = [];
31
+ return {
32
+ async prepare() {
33
+ var _resolvedConfig_source;
34
+ let appContext = api.useAppContext();
35
+ const resolvedConfig = api.useResolvedConfigContext();
36
+ const hookRunners = api.useHookRunners();
37
+ try {
38
+ if ((0, _utils1.checkIsBuildCommands)()) {
39
+ _utils.fs.emptydirSync(appContext.internalDirectory);
58
40
  }
59
- const [{ getBundleEntry }, { getServerRoutes }, { generateCode }, { getHtmlTemplate }] = await Promise.all([
60
- Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./getBundleEntry"))),
61
- Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./getServerRoutes"))),
62
- Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./generateCode"))),
63
- Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./getHtmlTemplate")))
64
- ]);
65
- const entrypoints = getBundleEntry(appContext, resolvedConfig);
66
- debug(`entrypoints: %o`, entrypoints);
67
- const initialRoutes = getServerRoutes(entrypoints, {
68
- appContext,
69
- config: resolvedConfig
70
- });
71
- const { routes } = await hookRunners.modifyServerRoutes({
72
- routes: initialRoutes
41
+ } catch {
42
+ }
43
+ const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
44
+ await hookRunners.addRuntimeExports();
45
+ if (apiOnly) {
46
+ const { routes: routes2 } = await hookRunners.modifyServerRoutes({
47
+ routes: []
73
48
  });
74
- debug(`server routes: %o`, routes);
49
+ debug(`server routes: %o`, routes2);
75
50
  appContext = {
76
51
  ...api.useAppContext(),
77
- entrypoints,
78
- serverRoutes: routes
79
- };
80
- api.setAppContext(appContext);
81
- nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
82
- pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !_path.extname(entry)).concat(nestedRouteEntries);
83
- originEntrypoints = (0, _lodash.cloneDeep)(entrypoints);
84
- const { importsStatemets } = await generateCode(appContext, resolvedConfig, entrypoints, api);
85
- const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
86
- appContext,
87
- config: resolvedConfig
88
- });
89
- debug(`html templates: %o`, htmlTemplates);
90
- await hookRunners.addDefineTypes();
91
- debug(`add Define Types`);
92
- let checkedEntries = entrypoints.map((point) => point.entryName);
93
- if ((0, _utils.isDevCommand)()) {
94
- const { entry } = (0, _utils.minimist)((0, _utils.getArgv)());
95
- checkedEntries = await (0, _getSelectedEntries.getSelectedEntries)(typeof entry === "string" ? entry.split(",") : entry, entrypoints);
96
- }
97
- appContext = {
98
- ...api.useAppContext(),
99
- entrypoints,
100
- checkedEntries,
101
52
  apiOnly,
102
- serverRoutes: routes,
103
- htmlTemplates
53
+ serverRoutes: routes2
104
54
  };
105
55
  api.setAppContext(appContext);
106
- if ((0, _utils1.checkIsBuildCommands)()) {
107
- const normalizedConfig = api.useResolvedConfigContext();
108
- const createBuilderForModern = await (0, _builder.createBuilderGenerator)(bundler);
109
- const builder = await createBuilderForModern({
110
- normalizedConfig,
111
- appContext
56
+ return;
57
+ }
58
+ const [{ getBundleEntry }, { getServerRoutes }, { generateCode }, { getHtmlTemplate }] = await Promise.all([
59
+ Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./getBundleEntry"))),
60
+ Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./getServerRoutes"))),
61
+ Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./generateCode"))),
62
+ Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./getHtmlTemplate")))
63
+ ]);
64
+ const entrypoints = getBundleEntry(appContext, resolvedConfig);
65
+ debug(`entrypoints: %o`, entrypoints);
66
+ const initialRoutes = getServerRoutes(entrypoints, {
67
+ appContext,
68
+ config: resolvedConfig
69
+ });
70
+ const { routes } = await hookRunners.modifyServerRoutes({
71
+ routes: initialRoutes
72
+ });
73
+ debug(`server routes: %o`, routes);
74
+ appContext = {
75
+ ...api.useAppContext(),
76
+ entrypoints,
77
+ serverRoutes: routes
78
+ };
79
+ api.setAppContext(appContext);
80
+ nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
81
+ pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !_path.extname(entry)).concat(nestedRouteEntries);
82
+ originEntrypoints = (0, _lodash.cloneDeep)(entrypoints);
83
+ const { importsStatemets } = await generateCode(appContext, resolvedConfig, entrypoints, api);
84
+ const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
85
+ appContext,
86
+ config: resolvedConfig
87
+ });
88
+ debug(`html templates: %o`, htmlTemplates);
89
+ await hookRunners.addDefineTypes();
90
+ debug(`add Define Types`);
91
+ let checkedEntries = entrypoints.map((point) => point.entryName);
92
+ if ((0, _utils.isDevCommand)()) {
93
+ const { entry } = (0, _utils.minimist)((0, _utils.getArgv)());
94
+ checkedEntries = await (0, _getSelectedEntries.getSelectedEntries)(typeof entry === "string" ? entry.split(",") : entry, entrypoints);
95
+ }
96
+ appContext = {
97
+ ...api.useAppContext(),
98
+ entrypoints,
99
+ checkedEntries,
100
+ apiOnly,
101
+ serverRoutes: routes,
102
+ htmlTemplates
103
+ };
104
+ api.setAppContext(appContext);
105
+ if ((0, _utils1.checkIsBuildCommands)()) {
106
+ const normalizedConfig = api.useResolvedConfigContext();
107
+ const createBuilderForModern = await (0, _builder.createBuilderGenerator)(bundler);
108
+ const builder = await createBuilderForModern({
109
+ normalizedConfig,
110
+ appContext
111
+ });
112
+ builder.onBeforeBuild(async ({ bundlerConfigs }) => {
113
+ const hookRunners2 = api.useHookRunners();
114
+ await (0, _routes.generateRoutes)(appContext);
115
+ await hookRunners2.beforeBuild({
116
+ bundlerConfigs
112
117
  });
113
- builder.onBeforeBuild(async ({ bundlerConfigs }) => {
114
- const hookRunners2 = api.useHookRunners();
115
- await (0, _routes.generateRoutes)(appContext);
116
- await hookRunners2.beforeBuild({
117
- bundlerConfigs
118
- });
118
+ });
119
+ builder.onAfterBuild(async ({ stats }) => {
120
+ const hookRunners2 = api.useHookRunners();
121
+ await hookRunners2.afterBuild({
122
+ stats
119
123
  });
120
- builder.onAfterBuild(async ({ stats }) => {
121
- const hookRunners2 = api.useHookRunners();
122
- await hookRunners2.afterBuild({
123
- stats
124
+ await (0, _config.emitResolvedConfig)(appContext.appDirectory, normalizedConfig);
125
+ });
126
+ builder.onDevCompileDone(async ({ isFirstCompile }) => {
127
+ const hookRunners2 = api.useHookRunners();
128
+ if (process.stdout.isTTY || isFirstCompile) {
129
+ hookRunners2.afterDev({
130
+ isFirstCompile
124
131
  });
125
- await (0, _config.emitResolvedConfig)(appContext.appDirectory, normalizedConfig);
126
- });
127
- builder.onDevCompileDone(async ({ isFirstCompile }) => {
128
- const hookRunners2 = api.useHookRunners();
129
- if (process.stdout.isTTY || isFirstCompile) {
130
- hookRunners2.afterDev({
131
- isFirstCompile
132
- });
133
- if (isFirstCompile) {
134
- (0, _printInstructions.printInstructions)(hookRunners2, appContext, normalizedConfig);
135
- }
132
+ if (isFirstCompile) {
133
+ (0, _printInstructions.printInstructions)(hookRunners2, appContext, normalizedConfig);
136
134
  }
135
+ }
136
+ });
137
+ builder.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
138
+ const hookRunners2 = api.useHookRunners();
139
+ await (0, _generateCode.generateIndexCode)({
140
+ appContext,
141
+ config: resolvedConfig,
142
+ entrypoints,
143
+ api,
144
+ importsStatemets,
145
+ bundlerConfigs
137
146
  });
138
- builder.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
139
- const hookRunners2 = api.useHookRunners();
140
- await (0, _generateCode.generateIndexCode)({
141
- appContext,
142
- config: resolvedConfig,
143
- entrypoints,
144
- api,
145
- importsStatemets,
146
- bundlerConfigs
147
- });
148
- await hookRunners2.beforeCreateCompiler({
149
- bundlerConfigs
150
- });
147
+ await hookRunners2.beforeCreateCompiler({
148
+ bundlerConfigs
151
149
  });
152
- builder.onAfterCreateCompiler(async ({ compiler }) => {
153
- const hookRunners2 = api.useHookRunners();
154
- await hookRunners2.afterCreateCompiler({
155
- compiler
156
- });
150
+ });
151
+ builder.onAfterCreateCompiler(async ({ compiler }) => {
152
+ const hookRunners2 = api.useHookRunners();
153
+ await hookRunners2.afterCreateCompiler({
154
+ compiler
157
155
  });
158
- builder.addPlugins(resolvedConfig.builderPlugins);
159
- appContext = {
160
- ...api.useAppContext(),
161
- builder
162
- };
163
- api.setAppContext(appContext);
164
- }
165
- },
166
- watchFiles() {
167
- return {
168
- files: pagesDir,
169
- isPrivate: true
170
- };
171
- },
172
- resolvedConfig({ resolved }) {
173
- const appContext = api.useAppContext();
174
- const config = (0, _config1.initialNormalizedConfig)(resolved, appContext, bundler);
175
- return {
176
- resolved: config
156
+ });
157
+ builder.addPlugins(resolvedConfig.builderPlugins);
158
+ appContext = {
159
+ ...api.useAppContext(),
160
+ builder
177
161
  };
178
- },
179
- // This logic is not in the router plugin to avoid having to include some dependencies in the utils package
180
- async modifyEntryImports({ entrypoint, imports }) {
181
- const appContext = api.useAppContext();
182
- const { srcDirectory, internalSrcAlias } = appContext;
183
- const { fileSystemRoutes, nestedRoutesEntry } = entrypoint;
184
- if (fileSystemRoutes && nestedRoutesEntry) {
185
- const rootLayoutPath = _path.join(nestedRoutesEntry, "layout");
186
- const rootLayoutFile = (0, _utils.findExists)([
187
- ".js",
188
- ".ts",
189
- ".jsx",
190
- ".tsx"
191
- ].map((ext) => `${rootLayoutPath}${ext}`));
192
- if (rootLayoutFile) {
193
- const rootLayoutBuffer = await _utils.fs.readFile(rootLayoutFile);
194
- const rootLayout = rootLayoutBuffer.toString();
195
- const [, moduleExports] = await (0, _utils1.parseModule)({
196
- source: rootLayout.toString(),
197
- filename: rootLayoutFile
162
+ api.setAppContext(appContext);
163
+ }
164
+ },
165
+ watchFiles() {
166
+ return {
167
+ files: pagesDir,
168
+ isPrivate: true
169
+ };
170
+ },
171
+ resolvedConfig({ resolved }) {
172
+ const appContext = api.useAppContext();
173
+ const config = (0, _config1.initialNormalizedConfig)(resolved, appContext, bundler);
174
+ return {
175
+ resolved: config
176
+ };
177
+ },
178
+ // This logic is not in the router plugin to avoid having to include some dependencies in the utils package
179
+ async modifyEntryImports({ entrypoint, imports }) {
180
+ const appContext = api.useAppContext();
181
+ const { srcDirectory, internalSrcAlias } = appContext;
182
+ const { fileSystemRoutes, nestedRoutesEntry } = entrypoint;
183
+ if (fileSystemRoutes && nestedRoutesEntry) {
184
+ const rootLayoutPath = _path.join(nestedRoutesEntry, "layout");
185
+ const rootLayoutFile = (0, _utils.findExists)([
186
+ ".js",
187
+ ".ts",
188
+ ".jsx",
189
+ ".tsx"
190
+ ].map((ext) => `${rootLayoutPath}${ext}`));
191
+ if (rootLayoutFile) {
192
+ const rootLayoutBuffer = await _utils.fs.readFile(rootLayoutFile);
193
+ const rootLayout = rootLayoutBuffer.toString();
194
+ const [, moduleExports] = await (0, _utils1.parseModule)({
195
+ source: rootLayout.toString(),
196
+ filename: rootLayoutFile
197
+ });
198
+ const hasAppConfig = moduleExports.some((e) => e.n === _constants.APP_CONFIG_NAME);
199
+ const generateLayoutPath = (0, _utils1.replaceWithAlias)(srcDirectory, rootLayoutFile, internalSrcAlias);
200
+ if (hasAppConfig) {
201
+ imports.push({
202
+ value: generateLayoutPath,
203
+ specifiers: [
204
+ {
205
+ imported: _constants.APP_CONFIG_NAME
206
+ }
207
+ ]
198
208
  });
199
- const hasAppConfig = moduleExports.some((e) => e.n === _constants.APP_CONFIG_NAME);
200
- const generateLayoutPath = (0, _utils1.replaceWithAlias)(srcDirectory, rootLayoutFile, internalSrcAlias);
201
- if (hasAppConfig) {
202
- imports.push({
203
- value: generateLayoutPath,
204
- specifiers: [
205
- {
206
- imported: _constants.APP_CONFIG_NAME
207
- }
208
- ]
209
- });
210
- }
211
- const hasAppInit = moduleExports.some((e) => e.n === _constants.APP_INIT_EXPORTED);
212
- if (hasAppInit) {
213
- imports.push({
214
- value: generateLayoutPath,
215
- specifiers: [
216
- {
217
- imported: _constants.APP_INIT_EXPORTED,
218
- local: _constants.APP_INIT_IMPORTED
219
- }
220
- ]
221
- });
222
- }
223
209
  }
224
- }
225
- return {
226
- entrypoint,
227
- imports
228
- };
229
- },
230
- validateSchema() {
231
- return {
232
- target: "output.splitRouteChunks",
233
- schema: {
234
- type: "boolean"
210
+ const hasAppInit = moduleExports.some((e) => e.n === _constants.APP_INIT_EXPORTED);
211
+ if (hasAppInit) {
212
+ imports.push({
213
+ value: generateLayoutPath,
214
+ specifiers: [
215
+ {
216
+ imported: _constants.APP_INIT_EXPORTED,
217
+ local: _constants.APP_INIT_IMPORTED
218
+ }
219
+ ]
220
+ });
235
221
  }
236
- };
237
- },
238
- async fileChange(e) {
239
- const appContext = api.useAppContext();
240
- const { appDirectory } = appContext;
241
- const { filename, eventType } = e;
242
- const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
243
- const absoluteFilePath = _path.resolve(appDirectory, filename);
244
- const isRouteComponent = isPageFile(absoluteFilePath) && (0, _utils1.isPageComponentFile)(absoluteFilePath);
245
- if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
246
- const resolvedConfig = api.useResolvedConfigContext();
247
- const { generateCode } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./generateCode")));
248
- const entrypoints = (0, _lodash.cloneDeep)(originEntrypoints);
249
- generateCode(appContext, resolvedConfig, entrypoints, api);
250
222
  }
251
223
  }
252
- };
253
- }
254
- };
255
- };
224
+ return {
225
+ entrypoint,
226
+ imports
227
+ };
228
+ },
229
+ validateSchema() {
230
+ return {
231
+ target: "output.splitRouteChunks",
232
+ schema: {
233
+ type: "boolean"
234
+ }
235
+ };
236
+ },
237
+ async fileChange(e) {
238
+ const appContext = api.useAppContext();
239
+ const { appDirectory } = appContext;
240
+ const { filename, eventType } = e;
241
+ const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
242
+ const absoluteFilePath = _path.resolve(appDirectory, filename);
243
+ const isRouteComponent = isPageFile(absoluteFilePath) && (0, _utils1.isPageComponentFile)(absoluteFilePath);
244
+ if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
245
+ const resolvedConfig = api.useResolvedConfigContext();
246
+ const { generateCode } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./generateCode")));
247
+ const entrypoints = (0, _lodash.cloneDeep)(originEntrypoints);
248
+ generateCode(appContext, resolvedConfig, entrypoints, api);
249
+ }
250
+ }
251
+ };
252
+ }
253
+ });
@@ -57,7 +57,7 @@ const createRoute = (routeInfo, rootDir, filename, entryName, isMainEntry) => {
57
57
  };
58
58
  };
59
59
  const walk = async (dirname, rootDir, alias, entryName, isMainEntry) => {
60
- var _route_children;
60
+ var _routePath, _route_children;
61
61
  if (!await _utils.fs.pathExists(dirname)) {
62
62
  return null;
63
63
  }
@@ -77,7 +77,7 @@ const walk = async (dirname, rootDir, alias, entryName, isMainEntry) => {
77
77
  }
78
78
  routePath = replaceDynamicPath(routePath);
79
79
  const route = {
80
- path: routePath === null || routePath === void 0 ? void 0 : routePath.replace(/\$$/, "?"),
80
+ path: (_routePath = routePath) === null || _routePath === void 0 ? void 0 : _routePath.replace(/\$$/, "?"),
81
81
  children: [],
82
82
  isRoot
83
83
  };
@@ -111,8 +111,8 @@ const routesForServer = ({ routes }) => {
111
111
  const traverseRouteTree = (route) => {
112
112
  let children;
113
113
  if ("children" in route && route.children) {
114
- var _route_children;
115
- children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
114
+ var _route_children, _route;
115
+ children = (_route = route) === null || _route === void 0 ? void 0 : (_route_children = _route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
116
116
  }
117
117
  let loader;
118
118
  if (route.type === "nested") {
@@ -179,8 +179,8 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
179
179
  const traverseRouteTree = (route) => {
180
180
  let children;
181
181
  if ("children" in route && route.children) {
182
- var _route_children;
183
- children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
182
+ var _route_children, _route;
183
+ children = (_route = route) === null || _route === void 0 ? void 0 : (_route_children = _route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
184
184
  }
185
185
  let loading;
186
186
  let error;
@@ -184,7 +184,8 @@ const checkIsBuildCommands = () => {
184
184
  "start",
185
185
  "build",
186
186
  "inspect",
187
- "deploy"
187
+ "deploy",
188
+ "dev-worker"
188
189
  ];
189
190
  const command = (0, _utils.getCommand)();
190
191
  return buildCommands.includes(command);