@modern-js/app-tools 2.57.0 → 2.57.1-alpha.1
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/dist/cjs/builder/builder-webpack/index.js +1 -1
- package/dist/cjs/builder/generator/index.js +2 -2
- package/dist/cjs/builder/index.js +2 -2
- package/dist/cjs/commands/build.js +19 -0
- package/dist/cjs/commands/dev.js +9 -0
- package/dist/cjs/commands/index.js +8 -8
- package/dist/cjs/esm/esbuild-loader.mjs +20 -0
- package/dist/cjs/esm/register-esm.mjs +65 -0
- package/dist/cjs/esm/ts-node-loader.mjs +21 -0
- package/dist/cjs/esm/utils.mjs +28 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/plugins/analyze/index.js +3 -3
- package/dist/cjs/plugins/deploy/dependencies/index.js +1 -0
- package/dist/cjs/plugins/deploy/dependencies/utils.js +12 -1
- package/dist/cjs/plugins/deploy/platforms/netlify-entry-cjs.js +1 -0
- package/dist/cjs/plugins/deploy/platforms/netlify-entry-mjs.js +10 -0
- package/dist/cjs/plugins/deploy/platforms/netlify.js +9 -2
- package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +26 -0
- package/dist/cjs/plugins/deploy/platforms/node.js +9 -2
- package/dist/cjs/utils/loadPlugins.js +1 -1
- package/dist/cjs/utils/register.js +38 -22
- package/dist/esm/builder/generator/getBuilderEnvironments.js +0 -2
- package/dist/esm/builder/generator/index.js +1 -1
- package/dist/esm/builder/index.js +2 -2
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +1 -1
- package/dist/esm/commands/build.js +9 -16
- package/dist/esm/commands/dev.js +37 -55
- package/dist/esm/commands/index.js +6 -6
- package/dist/esm/custom-loader.mjs +41 -0
- package/dist/esm/index.js +42 -1
- package/dist/esm/plugins/analyze/index.js +4 -3
- package/dist/esm/plugins/deploy/dependencies/index.js +2 -3
- package/dist/esm/register-esm.mjs +22 -0
- package/dist/esm/utils/createServer.js +1 -1
- package/dist/esm-node/builder/generator/getBuilderEnvironments.js +1 -1
- package/dist/esm-node/builder/generator/index.js +1 -1
- package/dist/esm-node/builder/index.js +2 -2
- package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +1 -1
- package/dist/esm-node/commands/build.js +0 -3
- package/dist/esm-node/commands/dev.js +16 -24
- package/dist/esm-node/commands/index.js +6 -6
- package/dist/esm-node/esm/esbuild-loader.js +39 -0
- package/dist/esm-node/esm/register-esm.js +39 -0
- package/dist/esm-node/esm/ts-node-loader.js +42 -0
- package/dist/esm-node/index.js +17 -1
- package/dist/esm-node/plugins/analyze/index.js +4 -3
- package/dist/esm-node/plugins/deploy/dependencies/index.js +1 -2
- package/dist/esm-node/utils/createServer.js +1 -1
- package/dist/types/builder/index.d.ts +1 -1
- package/dist/types/esm/esbuild-loader.d.mts +6 -0
- package/dist/types/esm/register-esm.d.mts +5 -0
- package/dist/types/esm/ts-node-loader.d.mts +6 -0
- package/dist/types/esm/utils.d.mts +6 -0
- package/dist/types/plugins/deploy/platforms/netlify-entry-cjs.d.ts +0 -0
- package/dist/types/plugins/deploy/platforms/netlify-entry-mjs.d.ts +1 -0
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +1 -2
- package/package.json +8 -8
|
@@ -7,10 +7,9 @@ import { logger } from "@modern-js/utils";
|
|
|
7
7
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
|
8
8
|
import { generateRoutes } from "../utils/routes";
|
|
9
9
|
import { buildServerConfig } from "../utils/config";
|
|
10
|
-
import { registerCompiler } from "../utils/register";
|
|
11
10
|
var build = function() {
|
|
12
11
|
var _ref = _async_to_generator(function(api, options) {
|
|
13
|
-
var
|
|
12
|
+
var resolvedConfig, appContext, hookRunners, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
|
|
14
13
|
return _ts_generator(this, function(_state) {
|
|
15
14
|
switch (_state.label) {
|
|
16
15
|
case 0:
|
|
@@ -25,18 +24,12 @@ var build = function() {
|
|
|
25
24
|
loadServerPlugins(api, appContext.appDirectory, appContext.metaName)
|
|
26
25
|
];
|
|
27
26
|
case 1:
|
|
28
|
-
_state.sent();
|
|
29
|
-
return [
|
|
30
|
-
4,
|
|
31
|
-
registerCompiler(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias)
|
|
32
|
-
];
|
|
33
|
-
case 2:
|
|
34
27
|
_state.sent();
|
|
35
28
|
apiOnly = appContext.apiOnly;
|
|
36
29
|
if (!apiOnly)
|
|
37
30
|
return [
|
|
38
31
|
3,
|
|
39
|
-
|
|
32
|
+
6
|
|
40
33
|
];
|
|
41
34
|
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverConfigFile = appContext.serverConfigFile;
|
|
42
35
|
return [
|
|
@@ -46,7 +39,7 @@ var build = function() {
|
|
|
46
39
|
bundlerConfigs: void 0
|
|
47
40
|
})
|
|
48
41
|
];
|
|
49
|
-
case
|
|
42
|
+
case 2:
|
|
50
43
|
_state.sent();
|
|
51
44
|
return [
|
|
52
45
|
4,
|
|
@@ -56,13 +49,13 @@ var build = function() {
|
|
|
56
49
|
configFile: serverConfigFile
|
|
57
50
|
})
|
|
58
51
|
];
|
|
59
|
-
case
|
|
52
|
+
case 3:
|
|
60
53
|
_state.sent();
|
|
61
54
|
return [
|
|
62
55
|
4,
|
|
63
56
|
generateRoutes(appContext)
|
|
64
57
|
];
|
|
65
|
-
case
|
|
58
|
+
case 4:
|
|
66
59
|
_state.sent();
|
|
67
60
|
return [
|
|
68
61
|
4,
|
|
@@ -71,12 +64,12 @@ var build = function() {
|
|
|
71
64
|
stats: void 0
|
|
72
65
|
})
|
|
73
66
|
];
|
|
74
|
-
case
|
|
67
|
+
case 5:
|
|
75
68
|
_state.sent();
|
|
76
69
|
return [
|
|
77
70
|
2
|
|
78
71
|
];
|
|
79
|
-
case
|
|
72
|
+
case 6:
|
|
80
73
|
resolvedConfig = _object_spread_props(_object_spread({}, resolvedConfig), {
|
|
81
74
|
cliOptions: options
|
|
82
75
|
});
|
|
@@ -90,7 +83,7 @@ var build = function() {
|
|
|
90
83
|
configFile: serverConfigFile1
|
|
91
84
|
})
|
|
92
85
|
];
|
|
93
|
-
case
|
|
86
|
+
case 7:
|
|
94
87
|
_state.sent();
|
|
95
88
|
logger.info("Starting production build...");
|
|
96
89
|
if (!appContext.builder) {
|
|
@@ -100,7 +93,7 @@ var build = function() {
|
|
|
100
93
|
4,
|
|
101
94
|
appContext.builder.build()
|
|
102
95
|
];
|
|
103
|
-
case
|
|
96
|
+
case 8:
|
|
104
97
|
_state.sent();
|
|
105
98
|
return [
|
|
106
99
|
2
|
package/dist/esm/commands/dev.js
CHANGED
|
@@ -4,21 +4,22 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { ResolvedConfigContext } from "@modern-js/core";
|
|
7
|
-
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta
|
|
7
|
+
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta } from "@modern-js/utils";
|
|
8
8
|
import { createDevServer } from "@modern-js/server";
|
|
9
9
|
import { applyPlugins } from "@modern-js/prod-server";
|
|
10
10
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
|
11
|
-
import { registerCompiler } from "../utils/register";
|
|
12
11
|
import { printInstructions } from "../utils/printInstructions";
|
|
13
12
|
import { setServer } from "../utils/createServer";
|
|
14
13
|
import { generateRoutes } from "../utils/routes";
|
|
15
14
|
import { buildServerConfig } from "../utils/config";
|
|
16
15
|
var dev = function() {
|
|
17
|
-
var _ref = _async_to_generator(function(api, options
|
|
18
|
-
var _normalizedConfig_source, _normalizedConfig_tools,
|
|
16
|
+
var _ref = _async_to_generator(function(api, options) {
|
|
17
|
+
var devServerOptions, _normalizedConfig_source, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, registerEsm, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, meta, serverConfigPath, pluginInstances, serverOptions, _normalizedConfig_dev, app, host, server;
|
|
18
|
+
var _arguments = arguments;
|
|
19
19
|
return _ts_generator(this, function(_state) {
|
|
20
20
|
switch (_state.label) {
|
|
21
21
|
case 0:
|
|
22
|
+
devServerOptions = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
|
|
22
23
|
if (options.analyze) {
|
|
23
24
|
process.env.BUNDLE_ANALYZE = "true";
|
|
24
25
|
}
|
|
@@ -27,9 +28,19 @@ var dev = function() {
|
|
|
27
28
|
hookRunners = api.useHookRunners();
|
|
28
29
|
return [
|
|
29
30
|
4,
|
|
30
|
-
|
|
31
|
+
import("../esm/register-esm.mjs")
|
|
31
32
|
];
|
|
32
33
|
case 1:
|
|
34
|
+
registerEsm = _state.sent().registerEsm;
|
|
35
|
+
return [
|
|
36
|
+
4,
|
|
37
|
+
registerEsm({
|
|
38
|
+
appDir: appContext.appDirectory,
|
|
39
|
+
distDir: appContext.distDirectory,
|
|
40
|
+
alias: (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias
|
|
41
|
+
})
|
|
42
|
+
];
|
|
43
|
+
case 2:
|
|
33
44
|
_state.sent();
|
|
34
45
|
normalizedConfig = _object_spread_props(_object_spread({}, normalizedConfig), {
|
|
35
46
|
cliOptions: options
|
|
@@ -45,7 +56,7 @@ var dev = function() {
|
|
|
45
56
|
watch: true
|
|
46
57
|
})
|
|
47
58
|
];
|
|
48
|
-
case
|
|
59
|
+
case 3:
|
|
49
60
|
_state.sent();
|
|
50
61
|
meta = getMeta(metaName);
|
|
51
62
|
serverConfigPath = path.resolve(appDirectory, SERVER_DIR, "".concat(meta, ".server"));
|
|
@@ -53,7 +64,7 @@ var dev = function() {
|
|
|
53
64
|
4,
|
|
54
65
|
hookRunners.beforeDev()
|
|
55
66
|
];
|
|
56
|
-
case
|
|
67
|
+
case 4:
|
|
57
68
|
_state.sent();
|
|
58
69
|
if (!appContext.builder && !apiOnly) {
|
|
59
70
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
@@ -62,13 +73,13 @@ var dev = function() {
|
|
|
62
73
|
4,
|
|
63
74
|
generateRoutes(appContext)
|
|
64
75
|
];
|
|
65
|
-
case
|
|
76
|
+
case 5:
|
|
66
77
|
_state.sent();
|
|
67
78
|
return [
|
|
68
79
|
4,
|
|
69
80
|
loadServerPlugins(api, appDirectory, metaName)
|
|
70
81
|
];
|
|
71
|
-
case
|
|
82
|
+
case 6:
|
|
72
83
|
pluginInstances = _state.sent();
|
|
73
84
|
serverOptions = _object_spread({
|
|
74
85
|
metaName,
|
|
@@ -90,21 +101,19 @@ var dev = function() {
|
|
|
90
101
|
serverConfigFile,
|
|
91
102
|
plugins: pluginInstances
|
|
92
103
|
}, devServerOptions);
|
|
93
|
-
host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
|
|
94
104
|
if (!apiOnly)
|
|
95
105
|
return [
|
|
96
106
|
3,
|
|
97
|
-
|
|
107
|
+
8
|
|
98
108
|
];
|
|
99
109
|
return [
|
|
100
110
|
4,
|
|
101
|
-
createDevServer(
|
|
102
|
-
runCompile: false
|
|
103
|
-
}), (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins)
|
|
111
|
+
createDevServer(serverOptions, applyPlugins)
|
|
104
112
|
];
|
|
105
|
-
case
|
|
106
|
-
|
|
107
|
-
|
|
113
|
+
case 7:
|
|
114
|
+
app = _state.sent();
|
|
115
|
+
host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
|
|
116
|
+
app.listen({
|
|
108
117
|
port,
|
|
109
118
|
host
|
|
110
119
|
}, function() {
|
|
@@ -112,55 +121,28 @@ var dev = function() {
|
|
|
112
121
|
});
|
|
113
122
|
return [
|
|
114
123
|
3,
|
|
115
|
-
|
|
124
|
+
10
|
|
116
125
|
];
|
|
117
|
-
case
|
|
126
|
+
case 8:
|
|
118
127
|
return [
|
|
119
128
|
4,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
129
|
+
appContext.builder.startDevServer({
|
|
130
|
+
serverOptions,
|
|
131
|
+
applyPlugins
|
|
132
|
+
})
|
|
123
133
|
];
|
|
124
|
-
case 8:
|
|
125
|
-
_ref2 = _state.sent(), server1 = _ref2.server, afterListen = _ref2.afterListen;
|
|
126
|
-
server1.listen({
|
|
127
|
-
port,
|
|
128
|
-
host
|
|
129
|
-
}, function() {
|
|
130
|
-
var _ref3 = _async_to_generator(function(err) {
|
|
131
|
-
return _ts_generator(this, function(_state2) {
|
|
132
|
-
switch (_state2.label) {
|
|
133
|
-
case 0:
|
|
134
|
-
if (err) {
|
|
135
|
-
logger.error("Occur error %s, when start dev server", err);
|
|
136
|
-
}
|
|
137
|
-
logger.debug("listen dev server done");
|
|
138
|
-
return [
|
|
139
|
-
4,
|
|
140
|
-
afterListen()
|
|
141
|
-
];
|
|
142
|
-
case 1:
|
|
143
|
-
_state2.sent();
|
|
144
|
-
return [
|
|
145
|
-
2
|
|
146
|
-
];
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
return function(err) {
|
|
151
|
-
return _ref3.apply(this, arguments);
|
|
152
|
-
};
|
|
153
|
-
}());
|
|
154
|
-
setServer(server1);
|
|
155
|
-
_state.label = 9;
|
|
156
134
|
case 9:
|
|
135
|
+
server = _state.sent().server;
|
|
136
|
+
setServer(server);
|
|
137
|
+
_state.label = 10;
|
|
138
|
+
case 10:
|
|
157
139
|
return [
|
|
158
140
|
2
|
|
159
141
|
];
|
|
160
142
|
}
|
|
161
143
|
});
|
|
162
144
|
});
|
|
163
|
-
return function dev2(api, options
|
|
145
|
+
return function dev2(api, options) {
|
|
164
146
|
return _ref.apply(this, arguments);
|
|
165
147
|
};
|
|
166
148
|
}();
|
|
@@ -26,7 +26,7 @@ var devCommand = function() {
|
|
|
26
26
|
case 0:
|
|
27
27
|
return [
|
|
28
28
|
4,
|
|
29
|
-
import("./dev")
|
|
29
|
+
import("./dev.js")
|
|
30
30
|
];
|
|
31
31
|
case 1:
|
|
32
32
|
dev = _state2.sent().dev;
|
|
@@ -152,7 +152,7 @@ var buildCommand = function() {
|
|
|
152
152
|
case 0:
|
|
153
153
|
return [
|
|
154
154
|
4,
|
|
155
|
-
import("./build")
|
|
155
|
+
import("./build.js")
|
|
156
156
|
];
|
|
157
157
|
case 1:
|
|
158
158
|
build = _state2.sent().build;
|
|
@@ -265,7 +265,7 @@ var serverCommand = function(program, api) {
|
|
|
265
265
|
case 0:
|
|
266
266
|
return [
|
|
267
267
|
4,
|
|
268
|
-
import("./serve")
|
|
268
|
+
import("./serve.js")
|
|
269
269
|
];
|
|
270
270
|
case 1:
|
|
271
271
|
start = _state.sent().start;
|
|
@@ -296,7 +296,7 @@ var deployCommand = function(program, api) {
|
|
|
296
296
|
];
|
|
297
297
|
return [
|
|
298
298
|
4,
|
|
299
|
-
import("./build")
|
|
299
|
+
import("./build.js")
|
|
300
300
|
];
|
|
301
301
|
case 1:
|
|
302
302
|
build = _state.sent().build;
|
|
@@ -310,7 +310,7 @@ var deployCommand = function(program, api) {
|
|
|
310
310
|
case 3:
|
|
311
311
|
return [
|
|
312
312
|
4,
|
|
313
|
-
import("./deploy")
|
|
313
|
+
import("./deploy.js")
|
|
314
314
|
];
|
|
315
315
|
case 4:
|
|
316
316
|
deploy = _state.sent().deploy;
|
|
@@ -366,7 +366,7 @@ var inspectCommand = function(program, api) {
|
|
|
366
366
|
case 0:
|
|
367
367
|
return [
|
|
368
368
|
4,
|
|
369
|
-
import("./inspect")
|
|
369
|
+
import("./inspect.js")
|
|
370
370
|
];
|
|
371
371
|
case 1:
|
|
372
372
|
inspect = _state.sent().inspect;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { pathToFileURL } from 'url';
|
|
2
|
+
import { resolve as tsNodeResolve } from 'ts-node/esm';
|
|
3
|
+
import * as tsConfigPaths from 'tsconfig-paths';
|
|
4
|
+
import fs from 'fs/promises'
|
|
5
|
+
import { getAliasConfig } from '@modern-js/utils';
|
|
6
|
+
import path from 'path'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
let matchPath;
|
|
10
|
+
export function initialize({ appDir, alias }){
|
|
11
|
+
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
12
|
+
const aliasConfig = getAliasConfig(alias, {
|
|
13
|
+
appDirectory: appDir,
|
|
14
|
+
tsconfigPath: path.resolve(appDir, TS_CONFIG_FILENAME),
|
|
15
|
+
});
|
|
16
|
+
const { paths = {}, absoluteBaseUrl = './' } = aliasConfig;
|
|
17
|
+
const tsPaths = Object.keys(paths).reduce((o, key) => {
|
|
18
|
+
let tsPath = paths[key];
|
|
19
|
+
if (typeof tsPath === 'string' && path.isAbsolute(tsPath)) {
|
|
20
|
+
tsPath = path.relative(absoluteBaseUrl, tsPath);
|
|
21
|
+
}
|
|
22
|
+
if (typeof tsPath === 'string') {
|
|
23
|
+
tsPath = [tsPath];
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
...o,
|
|
27
|
+
[`${key}`]: tsPath,
|
|
28
|
+
};
|
|
29
|
+
}, {});
|
|
30
|
+
|
|
31
|
+
matchPath = tsConfigPaths.createMatchPath(absoluteBaseUrl, tsPaths);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function resolve(specifier, context, defaultResolve) {
|
|
35
|
+
const match = matchPath(specifier);
|
|
36
|
+
return match
|
|
37
|
+
? tsNodeResolve(pathToFileURL(match).href, context, defaultResolve)
|
|
38
|
+
: tsNodeResolve(specifier, context, defaultResolve);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { transformSource, load } from 'ts-node/esm';
|
package/dist/esm/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import { lintPlugin } from "@modern-js/plugin-lint";
|
|
7
|
-
import { cleanRequireCache, emptyDir, getCommand, getArgv } from "@modern-js/utils";
|
|
7
|
+
import { cleanRequireCache, emptyDir, getCommand, getArgv, fs, NESTED_ROUTE_SPEC_FILE } from "@modern-js/utils";
|
|
8
8
|
import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
|
|
9
9
|
import initializePlugin from "./plugins/initialize";
|
|
10
10
|
import analyzePlugin from "./plugins/analyze";
|
|
@@ -52,6 +52,7 @@ var appTools = function() {
|
|
|
52
52
|
api.setAppContext(_object_spread_props(_object_spread({}, appContext), {
|
|
53
53
|
toolsType: "app-tools"
|
|
54
54
|
}));
|
|
55
|
+
var nestedRoutes = {};
|
|
55
56
|
var locale = getLocaleLanguage();
|
|
56
57
|
i18n.changeLanguage({
|
|
57
58
|
locale
|
|
@@ -225,6 +226,46 @@ var appTools = function() {
|
|
|
225
226
|
];
|
|
226
227
|
});
|
|
227
228
|
})();
|
|
229
|
+
},
|
|
230
|
+
modifyFileSystemRoutes: function modifyFileSystemRoutes(param) {
|
|
231
|
+
var entrypoint = param.entrypoint, routes = param.routes;
|
|
232
|
+
return _async_to_generator(function() {
|
|
233
|
+
return _ts_generator(this, function(_state) {
|
|
234
|
+
nestedRoutes[entrypoint.entryName] = routes;
|
|
235
|
+
return [
|
|
236
|
+
2,
|
|
237
|
+
{
|
|
238
|
+
entrypoint,
|
|
239
|
+
routes
|
|
240
|
+
}
|
|
241
|
+
];
|
|
242
|
+
});
|
|
243
|
+
})();
|
|
244
|
+
},
|
|
245
|
+
beforeGenerateRoutes: function beforeGenerateRoutes(param) {
|
|
246
|
+
var entrypoint = param.entrypoint, code = param.code;
|
|
247
|
+
return _async_to_generator(function() {
|
|
248
|
+
var distDirectory;
|
|
249
|
+
return _ts_generator(this, function(_state) {
|
|
250
|
+
switch (_state.label) {
|
|
251
|
+
case 0:
|
|
252
|
+
distDirectory = api.useAppContext().distDirectory;
|
|
253
|
+
return [
|
|
254
|
+
4,
|
|
255
|
+
fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutes)
|
|
256
|
+
];
|
|
257
|
+
case 1:
|
|
258
|
+
_state.sent();
|
|
259
|
+
return [
|
|
260
|
+
2,
|
|
261
|
+
{
|
|
262
|
+
entrypoint,
|
|
263
|
+
code
|
|
264
|
+
}
|
|
265
|
+
];
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
})();
|
|
228
269
|
}
|
|
229
270
|
};
|
|
230
271
|
}
|
|
@@ -12,6 +12,7 @@ import { getSelectedEntries } from "../../utils/getSelectedEntries";
|
|
|
12
12
|
import { initialNormalizedConfig } from "../../config";
|
|
13
13
|
import { createBuilderGenerator } from "../../builder";
|
|
14
14
|
import { checkIsBuildCommands } from "./utils";
|
|
15
|
+
import { compatibleRequire } from "@modern-js/utils";
|
|
15
16
|
var debug = createDebugger("plugin-analyze");
|
|
16
17
|
function analyze_default(param) {
|
|
17
18
|
var bundler = param.bundler;
|
|
@@ -77,9 +78,9 @@ function analyze_default(param) {
|
|
|
77
78
|
return [
|
|
78
79
|
4,
|
|
79
80
|
Promise.all([
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
compatibleRequire(path.join(__dirname, "./getBundleEntry.js")),
|
|
82
|
+
compatibleRequire(path.join(__dirname, "./getServerRoutes.js")),
|
|
83
|
+
compatibleRequire(path.join(__dirname, "./getHtmlTemplate.js"))
|
|
83
84
|
])
|
|
84
85
|
];
|
|
85
86
|
case 5:
|
|
@@ -10,7 +10,7 @@ import { parseNodeModulePath } from "mlly";
|
|
|
10
10
|
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
|
|
11
11
|
var handleDependencies = function() {
|
|
12
12
|
var _ref = _async_to_generator(function(param) {
|
|
13
|
-
var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, base, entryFiles, fileTrace, currentProjectModules,
|
|
13
|
+
var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, base, entryFiles, fileTrace, currentProjectModules, tracedFiles, _, tracedPackages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, tracedFile, pkgName, tracedPackage, pkgJSON, tracedPackageVersion, shouldCopyWholePackage, _tracedPackageVersion_files, allFiles, err, multiVersionPkgs, singleVersionPackages, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tracedPackage1, versions, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, version, projectPkgJson, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _loop, _iterator3, _step3, err, outputPkgPath, newPkgJson, finalPkgJson;
|
|
14
14
|
return _ts_generator(this, function(_state) {
|
|
15
15
|
switch (_state.label) {
|
|
16
16
|
case 0:
|
|
@@ -29,7 +29,6 @@ var handleDependencies = function() {
|
|
|
29
29
|
case 2:
|
|
30
30
|
fileTrace = _state.sent();
|
|
31
31
|
currentProjectModules = path.join(appDir, "node_modules");
|
|
32
|
-
dependencySearchRoot = path.resolve(appDir, "../../../../../../");
|
|
33
32
|
_ = Object.fromEntries;
|
|
34
33
|
return [
|
|
35
34
|
4,
|
|
@@ -106,7 +105,7 @@ var handleDependencies = function() {
|
|
|
106
105
|
_state2.label = 6;
|
|
107
106
|
case 6:
|
|
108
107
|
packageJsonPath = _tmp;
|
|
109
|
-
if (!
|
|
108
|
+
if (!packageJsonPath)
|
|
110
109
|
return [
|
|
111
110
|
3,
|
|
112
111
|
8
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { register } from 'node:module';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
export const registerEsm = async ({
|
|
5
|
+
appDir,
|
|
6
|
+
distDir,
|
|
7
|
+
alias
|
|
8
|
+
}) => {
|
|
9
|
+
// These can be overridden by ts-node options in tsconfig.json
|
|
10
|
+
process.env.TS_NODE_TRANSPILE_ONLY = true;
|
|
11
|
+
process.env.TS_NODE_PROJECT = path.join(appDir, 'tsconfig.json');
|
|
12
|
+
process.env.TS_NODE_SCOPE = true;
|
|
13
|
+
process.env.TS_NODE_FILES = true;
|
|
14
|
+
process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${path.relative(appDir, distDir)}/`
|
|
15
|
+
register('./custom-loader.mjs', import.meta.url, {
|
|
16
|
+
data: {
|
|
17
|
+
appDir,
|
|
18
|
+
distDir,
|
|
19
|
+
alias
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
};
|
|
@@ -19,7 +19,7 @@ function getBuilderEnvironments(normalizedConfig, appContext) {
|
|
|
19
19
|
const serverEntries = {};
|
|
20
20
|
for (const entry in entries) {
|
|
21
21
|
const v = entries[entry];
|
|
22
|
-
serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx"))
|
|
22
|
+
serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx"));
|
|
23
23
|
}
|
|
24
24
|
const environments = {
|
|
25
25
|
web: {
|
|
@@ -17,7 +17,7 @@ async function generateBuilder(options, bundlerType) {
|
|
|
17
17
|
return builder;
|
|
18
18
|
}
|
|
19
19
|
async function applyBuilderPlugins(builder, options) {
|
|
20
|
-
const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await import("../shared/builderPlugins");
|
|
20
|
+
const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await import("../shared/builderPlugins/index.js");
|
|
21
21
|
builder.addPlugins([
|
|
22
22
|
builderPluginAdapterBasic(),
|
|
23
23
|
builderPluginAdapterSSR(options),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
async function createBuilderGenerator(bundler) {
|
|
2
2
|
if (bundler === "rspack") {
|
|
3
|
-
const { createRspackBuilderForModern } = await import("./builder-rspack");
|
|
3
|
+
const { createRspackBuilderForModern } = await import("./builder-rspack/index.js");
|
|
4
4
|
return createRspackBuilderForModern;
|
|
5
5
|
}
|
|
6
|
-
const { createWebpackBuilderForModern } = await import("./builder-webpack");
|
|
6
|
+
const { createWebpackBuilderForModern } = await import("./builder-webpack/index.js");
|
|
7
7
|
return createWebpackBuilderForModern;
|
|
8
8
|
}
|
|
9
9
|
export {
|
|
@@ -3,9 +3,7 @@ import { logger } from "@modern-js/utils";
|
|
|
3
3
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
|
4
4
|
import { generateRoutes } from "../utils/routes";
|
|
5
5
|
import { buildServerConfig } from "../utils/config";
|
|
6
|
-
import { registerCompiler } from "../utils/register";
|
|
7
6
|
const build = async (api, options) => {
|
|
8
|
-
var _resolvedConfig_source;
|
|
9
7
|
if (options === null || options === void 0 ? void 0 : options.analyze) {
|
|
10
8
|
process.env.BUNDLE_ANALYZE = "true";
|
|
11
9
|
}
|
|
@@ -13,7 +11,6 @@ const build = async (api, options) => {
|
|
|
13
11
|
const appContext = api.useAppContext();
|
|
14
12
|
const hookRunners = api.useHookRunners();
|
|
15
13
|
await loadServerPlugins(api, appContext.appDirectory, appContext.metaName);
|
|
16
|
-
await registerCompiler(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias);
|
|
17
14
|
const { apiOnly } = appContext;
|
|
18
15
|
if (apiOnly) {
|
|
19
16
|
const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { ResolvedConfigContext } from "@modern-js/core";
|
|
3
|
-
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta
|
|
3
|
+
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta } from "@modern-js/utils";
|
|
4
4
|
import { createDevServer } from "@modern-js/server";
|
|
5
5
|
import { applyPlugins } from "@modern-js/prod-server";
|
|
6
6
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
|
7
|
-
import { registerCompiler } from "../utils/register";
|
|
8
7
|
import { printInstructions } from "../utils/printInstructions";
|
|
9
8
|
import { setServer } from "../utils/createServer";
|
|
10
9
|
import { generateRoutes } from "../utils/routes";
|
|
11
10
|
import { buildServerConfig } from "../utils/config";
|
|
12
|
-
const dev = async (api, options, devServerOptions) => {
|
|
13
|
-
var _normalizedConfig_source, _normalizedConfig_tools
|
|
11
|
+
const dev = async (api, options, devServerOptions = {}) => {
|
|
12
|
+
var _normalizedConfig_source, _normalizedConfig_tools;
|
|
14
13
|
if (options.analyze) {
|
|
15
14
|
process.env.BUNDLE_ANALYZE = "true";
|
|
16
15
|
}
|
|
17
16
|
let normalizedConfig = api.useResolvedConfigContext();
|
|
18
17
|
const appContext = api.useAppContext();
|
|
19
18
|
const hookRunners = api.useHookRunners();
|
|
20
|
-
|
|
19
|
+
const { registerEsm } = await import("../esm/register-esm.mjs");
|
|
20
|
+
await registerEsm({
|
|
21
|
+
appDir: appContext.appDirectory,
|
|
22
|
+
distDir: appContext.distDirectory,
|
|
23
|
+
alias: (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias
|
|
24
|
+
});
|
|
21
25
|
normalizedConfig = {
|
|
22
26
|
...normalizedConfig,
|
|
23
27
|
cliOptions: options
|
|
@@ -60,32 +64,20 @@ const dev = async (api, options, devServerOptions) => {
|
|
|
60
64
|
plugins: pluginInstances,
|
|
61
65
|
...devServerOptions
|
|
62
66
|
};
|
|
63
|
-
const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
|
|
64
67
|
if (apiOnly) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
server.listen({
|
|
68
|
+
var _normalizedConfig_dev;
|
|
69
|
+
const app = await createDevServer(serverOptions, applyPlugins);
|
|
70
|
+
const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
|
|
71
|
+
app.listen({
|
|
70
72
|
port,
|
|
71
73
|
host
|
|
72
74
|
}, () => {
|
|
73
75
|
printInstructions(hookRunners, appContext, normalizedConfig);
|
|
74
76
|
});
|
|
75
77
|
} else {
|
|
76
|
-
const { server
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}, (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins);
|
|
80
|
-
server.listen({
|
|
81
|
-
port,
|
|
82
|
-
host
|
|
83
|
-
}, async (err) => {
|
|
84
|
-
if (err) {
|
|
85
|
-
logger.error("Occur error %s, when start dev server", err);
|
|
86
|
-
}
|
|
87
|
-
logger.debug("listen dev server done");
|
|
88
|
-
await afterListen();
|
|
78
|
+
const { server } = await appContext.builder.startDevServer({
|
|
79
|
+
serverOptions,
|
|
80
|
+
applyPlugins
|
|
89
81
|
});
|
|
90
82
|
setServer(server);
|
|
91
83
|
}
|