@modern-js/app-tools 2.48.6 → 2.49.1-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/builder/builder-webpack/index.js +1 -1
- package/dist/cjs/commands/build.js +3 -0
- package/dist/cjs/commands/dev.js +16 -16
- package/dist/cjs/commands/serve.js +14 -22
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/plugins/deploy/dependencies.js +257 -0
- package/dist/cjs/plugins/deploy/entrys/netlify.js +95 -0
- package/dist/cjs/plugins/deploy/entrys/node.js +88 -0
- package/dist/cjs/plugins/deploy/entrys/vercel.js +95 -0
- package/dist/cjs/plugins/deploy/index.js +140 -0
- package/dist/cjs/plugins/deploy/utils.js +150 -0
- package/dist/cjs/utils/createServer.js +5 -27
- package/dist/cjs/utils/env.js +2 -2
- package/dist/cjs/utils/register.js +103 -0
- package/dist/esm/builder/builder-webpack/index.js +1 -1
- package/dist/esm/commands/build.js +16 -9
- package/dist/esm/commands/dev.js +34 -38
- package/dist/esm/commands/serve.js +28 -32
- package/dist/esm/index.js +3 -1
- package/dist/esm/plugins/deploy/dependencies.js +726 -0
- package/dist/esm/plugins/deploy/entrys/netlify.js +41 -0
- package/dist/esm/plugins/deploy/entrys/node.js +39 -0
- package/dist/esm/plugins/deploy/entrys/vercel.js +41 -0
- package/dist/esm/plugins/deploy/index.js +219 -0
- package/dist/esm/plugins/deploy/utils.js +244 -0
- package/dist/esm/utils/createServer.js +14 -50
- package/dist/esm/utils/env.js +1 -1
- package/dist/esm/utils/register.js +129 -0
- package/dist/esm-node/builder/builder-webpack/index.js +1 -1
- package/dist/esm-node/commands/build.js +3 -0
- package/dist/esm-node/commands/dev.js +17 -17
- package/dist/esm-node/commands/serve.js +14 -12
- package/dist/esm-node/index.js +3 -1
- package/dist/esm-node/plugins/deploy/dependencies.js +223 -0
- package/dist/esm-node/plugins/deploy/entrys/netlify.js +71 -0
- package/dist/esm-node/plugins/deploy/entrys/node.js +64 -0
- package/dist/esm-node/plugins/deploy/entrys/vercel.js +71 -0
- package/dist/esm-node/plugins/deploy/index.js +110 -0
- package/dist/esm-node/plugins/deploy/utils.js +109 -0
- package/dist/esm-node/utils/createServer.js +6 -17
- package/dist/esm-node/utils/env.js +1 -1
- package/dist/esm-node/utils/register.js +69 -0
- package/dist/types/plugins/deploy/dependencies.d.ts +1 -0
- package/dist/types/plugins/deploy/entrys/netlify.d.ts +5 -0
- package/dist/types/plugins/deploy/entrys/node.d.ts +5 -0
- package/dist/types/plugins/deploy/entrys/vercel.d.ts +5 -0
- package/dist/types/plugins/deploy/index.d.ts +4 -0
- package/dist/types/plugins/deploy/utils.d.ts +27 -0
- package/dist/types/types/config/tools.d.ts +1 -1
- package/dist/types/utils/createServer.d.ts +4 -9
- package/dist/types/utils/register.d.ts +3 -0
- package/package.json +28 -22
@@ -0,0 +1,41 @@
|
|
1
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
|
2
|
+
import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
|
3
|
+
function genNetlifyEntry() {
|
4
|
+
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, config = _ref.config, plugins = _ref.plugins, appContext = _ref.appContext;
|
5
|
+
var defaultConfig = {
|
6
|
+
server: {
|
7
|
+
port: 8080
|
8
|
+
},
|
9
|
+
output: {
|
10
|
+
path: "."
|
11
|
+
}
|
12
|
+
};
|
13
|
+
return "\n\n const fs = require('node:fs/promises');\n const path = require('node:path');\n const { createNetlifyFunction } = require('@modern-js/prod-server/netlify');\n ".concat(genPluginImportsCode(plugins || []), `
|
14
|
+
|
15
|
+
let requestHandler = null;
|
16
|
+
|
17
|
+
if(!process.env.NODE_ENV){
|
18
|
+
process.env.NODE_ENV = 'production';
|
19
|
+
}
|
20
|
+
|
21
|
+
async function createHandler() {
|
22
|
+
try {
|
23
|
+
let routes = [];
|
24
|
+
const routeFilepath = path.join(__dirname, "`).concat(ROUTE_SPEC_FILE, `");
|
25
|
+
try {
|
26
|
+
await fs.access(routeFilepath);
|
27
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
28
|
+
const routeSpec = JSON.parse(content);
|
29
|
+
routes = routeSpec.routes;
|
30
|
+
} catch (error) {
|
31
|
+
console.warn('route.json not found, continuing with empty routes.');
|
32
|
+
}
|
33
|
+
|
34
|
+
const prodServerOptions = {
|
35
|
+
pwd: __dirname,
|
36
|
+
routes,
|
37
|
+
config: `).concat(JSON.stringify(config || defaultConfig), ",\n serverConfigFile: '").concat(DEFAULT_SERVER_CONFIG, "',\n plugins: ").concat(getPluginsCode(plugins || []), ",\n appContext: ").concat(appContext ? severAppContextTemplate(appContext) : "undefined", ",\n disableCustomHook: true\n }\n\n requestHandler = await createNetlifyFunction(prodServerOptions)\n\n return requestHandler\n } catch(error) {\n console.error(error);\n process.exit(1);\n }\n }\n\n createHandler();\n\n const handleRequest = async(request, context) => {\n if(typeof requestHandler !== 'function'){\n await createHandler();\n }\n return requestHandler(request, context);\n }\n\n export default handleRequest;\n ");
|
38
|
+
}
|
39
|
+
export {
|
40
|
+
genNetlifyEntry
|
41
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
|
2
|
+
import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
|
3
|
+
function genNodeEntry() {
|
4
|
+
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, config = _ref.config, plugins = _ref.plugins, appContext = _ref.appContext;
|
5
|
+
var defaultConfig = {
|
6
|
+
server: {
|
7
|
+
port: 8080
|
8
|
+
},
|
9
|
+
output: {
|
10
|
+
path: "."
|
11
|
+
}
|
12
|
+
};
|
13
|
+
return "\n\n const fs = require('node:fs/promises');\n const path = require('node:path');\n const { createProdServer } = require('@modern-js/prod-server');\n ".concat(genPluginImportsCode(plugins || []), `
|
14
|
+
|
15
|
+
if(!process.env.NODE_ENV){
|
16
|
+
process.env.NODE_ENV = 'production';
|
17
|
+
}
|
18
|
+
|
19
|
+
async function main() {
|
20
|
+
try {
|
21
|
+
let routes = [];
|
22
|
+
const routeFilepath = path.join(__dirname, "`).concat(ROUTE_SPEC_FILE, `");
|
23
|
+
try {
|
24
|
+
await fs.access(routeFilepath);
|
25
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
26
|
+
const routeSpec = JSON.parse(content);
|
27
|
+
routes = routeSpec.routes;
|
28
|
+
} catch (error) {
|
29
|
+
console.warn('route.json not found, continuing with empty routes.');
|
30
|
+
}
|
31
|
+
|
32
|
+
const prodServerOptions = {
|
33
|
+
pwd: __dirname,
|
34
|
+
routes,
|
35
|
+
config: `).concat(JSON.stringify(config || defaultConfig), ",\n serverConfigFile: '").concat(DEFAULT_SERVER_CONFIG, "',\n plugins: ").concat(getPluginsCode(plugins || []), ",\n appContext: ").concat(appContext ? severAppContextTemplate(appContext) : "undefined", ",\n disableCustomHook: true\n }\n\n const app = await createProdServer(prodServerOptions)\n\n const port = process.env.PORT || 3000;\n\n app.listen(port, () => {\n console.log('\\x1b[32mServer is listening on port', port, '\\x1b[0m');\n });\n } catch(error) {\n console.error(error);\n process.exit(1);\n }\n }\n\n main();\n ");
|
36
|
+
}
|
37
|
+
export {
|
38
|
+
genNodeEntry
|
39
|
+
};
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG } from "@modern-js/utils";
|
2
|
+
import { genPluginImportsCode, getPluginsCode, severAppContextTemplate } from "../utils";
|
3
|
+
function genVercelEntry() {
|
4
|
+
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, config = _ref.config, plugins = _ref.plugins, appContext = _ref.appContext;
|
5
|
+
var defaultConfig = {
|
6
|
+
server: {
|
7
|
+
port: 8080
|
8
|
+
},
|
9
|
+
output: {
|
10
|
+
path: "."
|
11
|
+
}
|
12
|
+
};
|
13
|
+
return "\n\n const fs = require('node:fs/promises');\n const path = require('node:path');\n const { createNetlifyFunction } = require('@modern-js/prod-server/netlify');\n ".concat(genPluginImportsCode(plugins || []), `
|
14
|
+
|
15
|
+
let requestHandler = null;
|
16
|
+
|
17
|
+
if(!process.env.NODE_ENV){
|
18
|
+
process.env.NODE_ENV = 'production';
|
19
|
+
}
|
20
|
+
|
21
|
+
async function createHandler() {
|
22
|
+
try {
|
23
|
+
let routes = [];
|
24
|
+
const routeFilepath = path.join(__dirname, "`).concat(ROUTE_SPEC_FILE, `");
|
25
|
+
try {
|
26
|
+
await fs.access(routeFilepath);
|
27
|
+
const content = await fs.readFile(routeFilepath, "utf-8");
|
28
|
+
const routeSpec = JSON.parse(content);
|
29
|
+
routes = routeSpec.routes;
|
30
|
+
} catch (error) {
|
31
|
+
console.warn('route.json not found, continuing with empty routes.');
|
32
|
+
}
|
33
|
+
|
34
|
+
const prodServerOptions = {
|
35
|
+
pwd: __dirname,
|
36
|
+
routes,
|
37
|
+
config: `).concat(JSON.stringify(config || defaultConfig), ",\n serverConfigFile: '").concat(DEFAULT_SERVER_CONFIG, "',\n plugins: ").concat(getPluginsCode(plugins || []), ",\n appContext: ").concat(appContext ? severAppContextTemplate(appContext) : "undefined", ",\n disableCustomHook: true\n }\n\n requestHandler = await createNetlifyFunction(prodServerOptions)\n\n return requestHandler\n } catch(error) {\n console.error(error);\n process.exit(1);\n }\n }\n\n createHandler();\n\n const handleRequest = async(request, context) => {\n if(typeof requestHandler !== 'function'){\n await createHandler();\n }\n return requestHandler(request, context);\n }\n\n export default handleRequest;\n ");
|
38
|
+
}
|
39
|
+
export {
|
40
|
+
genVercelEntry
|
41
|
+
};
|
@@ -0,0 +1,219 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
|
+
import path from "path";
|
4
|
+
import { fs as fse, getInternalPlugins } from "@modern-js/utils";
|
5
|
+
import { getProjectUsage } from "./utils";
|
6
|
+
import { handleDependencies } from "./dependencies";
|
7
|
+
function deploy_default() {
|
8
|
+
return {
|
9
|
+
name: "@modern-js/plugin-deploy",
|
10
|
+
pre: [
|
11
|
+
"@modern-js/plugin-bff",
|
12
|
+
"@modern-js/plugin-server"
|
13
|
+
],
|
14
|
+
setup: function(api) {
|
15
|
+
return {
|
16
|
+
beforeDeploy: function beforeDeploy() {
|
17
|
+
return _async_to_generator(function() {
|
18
|
+
var deployTarget, appContext, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, configContext, outputDirectory, funcsDirectory, staticDirectory, bff, config, plugins, serverAppContext, code, genNodeEntry, genVercelEntry, genNetlifyEntry, _getProjectUsage, useSSR, useAPI, useWebServer, entryFilePath;
|
19
|
+
return _ts_generator(this, function(_state) {
|
20
|
+
switch (_state.label) {
|
21
|
+
case 0:
|
22
|
+
deployTarget = process.env.MODERNJS_DEPLOY || "node";
|
23
|
+
appContext = api.useAppContext();
|
24
|
+
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName;
|
25
|
+
configContext = api.useResolvedConfigContext();
|
26
|
+
outputDirectory = path.join(appDirectory, ".output");
|
27
|
+
funcsDirectory = outputDirectory;
|
28
|
+
staticDirectory = path.join(outputDirectory, "static");
|
29
|
+
return [
|
30
|
+
4,
|
31
|
+
fse.remove(outputDirectory)
|
32
|
+
];
|
33
|
+
case 1:
|
34
|
+
_state.sent();
|
35
|
+
if (!(deployTarget === "node"))
|
36
|
+
return [
|
37
|
+
3,
|
38
|
+
3
|
39
|
+
];
|
40
|
+
return [
|
41
|
+
4,
|
42
|
+
fse.copy(distDirectory, outputDirectory, {
|
43
|
+
filter: function(src) {
|
44
|
+
var distStaticDirectory = path.join(distDirectory, "static");
|
45
|
+
return !src.includes(distStaticDirectory);
|
46
|
+
}
|
47
|
+
})
|
48
|
+
];
|
49
|
+
case 2:
|
50
|
+
_state.sent();
|
51
|
+
_state.label = 3;
|
52
|
+
case 3:
|
53
|
+
if (!(deployTarget === "vercel"))
|
54
|
+
return [
|
55
|
+
3,
|
56
|
+
7
|
57
|
+
];
|
58
|
+
funcsDirectory = path.join(outputDirectory, "functions");
|
59
|
+
staticDirectory = path.join(outputDirectory, "static");
|
60
|
+
return [
|
61
|
+
4,
|
62
|
+
fse.copy(distDirectory, funcsDirectory, {
|
63
|
+
filter: function(src) {
|
64
|
+
var distStaticDirectory = path.join(distDirectory, "static");
|
65
|
+
return !src.includes(distStaticDirectory);
|
66
|
+
}
|
67
|
+
})
|
68
|
+
];
|
69
|
+
case 4:
|
70
|
+
_state.sent();
|
71
|
+
return [
|
72
|
+
4,
|
73
|
+
fse.copy(path.join(distDirectory, "static"), staticDirectory)
|
74
|
+
];
|
75
|
+
case 5:
|
76
|
+
_state.sent();
|
77
|
+
return [
|
78
|
+
4,
|
79
|
+
fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
80
|
+
runtime: "nodejs16.x",
|
81
|
+
handler: "index.js",
|
82
|
+
launcherType: "Nodejs",
|
83
|
+
shouldAddHelpers: false,
|
84
|
+
supportsResponseStreaming: true
|
85
|
+
})
|
86
|
+
];
|
87
|
+
case 6:
|
88
|
+
_state.sent();
|
89
|
+
_state.label = 7;
|
90
|
+
case 7:
|
91
|
+
bff = configContext.bff;
|
92
|
+
config = {
|
93
|
+
output: {
|
94
|
+
path: "."
|
95
|
+
},
|
96
|
+
bff
|
97
|
+
};
|
98
|
+
plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
99
|
+
serverAppContext = {
|
100
|
+
sharedDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, sharedDirectory), '")'),
|
101
|
+
apiDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, apiDirectory), '")'),
|
102
|
+
lambdaDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, lambdaDirectory), '")'),
|
103
|
+
metaName
|
104
|
+
};
|
105
|
+
code = "";
|
106
|
+
console.log("deployTarget111111111", deployTarget);
|
107
|
+
switch (deployTarget) {
|
108
|
+
case "node":
|
109
|
+
return [
|
110
|
+
3,
|
111
|
+
8
|
112
|
+
];
|
113
|
+
case "vercel":
|
114
|
+
return [
|
115
|
+
3,
|
116
|
+
10
|
117
|
+
];
|
118
|
+
case "netlify":
|
119
|
+
return [
|
120
|
+
3,
|
121
|
+
12
|
122
|
+
];
|
123
|
+
}
|
124
|
+
return [
|
125
|
+
3,
|
126
|
+
14
|
127
|
+
];
|
128
|
+
case 8:
|
129
|
+
return [
|
130
|
+
4,
|
131
|
+
import("./entrys/node")
|
132
|
+
];
|
133
|
+
case 9:
|
134
|
+
genNodeEntry = _state.sent().genNodeEntry;
|
135
|
+
code = genNodeEntry({
|
136
|
+
plugins,
|
137
|
+
config,
|
138
|
+
appContext: serverAppContext
|
139
|
+
});
|
140
|
+
return [
|
141
|
+
3,
|
142
|
+
15
|
143
|
+
];
|
144
|
+
case 10:
|
145
|
+
return [
|
146
|
+
4,
|
147
|
+
import("./entrys/vercel")
|
148
|
+
];
|
149
|
+
case 11:
|
150
|
+
genVercelEntry = _state.sent().genVercelEntry;
|
151
|
+
code = genVercelEntry({
|
152
|
+
plugins,
|
153
|
+
config,
|
154
|
+
appContext: serverAppContext
|
155
|
+
});
|
156
|
+
return [
|
157
|
+
3,
|
158
|
+
15
|
159
|
+
];
|
160
|
+
case 12:
|
161
|
+
return [
|
162
|
+
4,
|
163
|
+
import("./entrys/netlify")
|
164
|
+
];
|
165
|
+
case 13:
|
166
|
+
genNetlifyEntry = _state.sent().genNetlifyEntry;
|
167
|
+
code = genNetlifyEntry({
|
168
|
+
plugins,
|
169
|
+
config,
|
170
|
+
appContext: serverAppContext
|
171
|
+
});
|
172
|
+
return [
|
173
|
+
3,
|
174
|
+
15
|
175
|
+
];
|
176
|
+
case 14:
|
177
|
+
{
|
178
|
+
code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
|
179
|
+
}
|
180
|
+
_state.label = 15;
|
181
|
+
case 15:
|
182
|
+
_getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
|
183
|
+
entryFilePath = path.join(funcsDirectory, "index.js");
|
184
|
+
if (!(useSSR || useAPI || useWebServer))
|
185
|
+
return [
|
186
|
+
3,
|
187
|
+
17
|
188
|
+
];
|
189
|
+
return [
|
190
|
+
4,
|
191
|
+
fse.writeFile(entryFilePath, code)
|
192
|
+
];
|
193
|
+
case 16:
|
194
|
+
_state.sent();
|
195
|
+
_state.label = 17;
|
196
|
+
case 17:
|
197
|
+
return [
|
198
|
+
4,
|
199
|
+
handleDependencies(appDirectory, funcsDirectory, [
|
200
|
+
"@modern-js/prod-server"
|
201
|
+
])
|
202
|
+
];
|
203
|
+
case 18:
|
204
|
+
_state.sent();
|
205
|
+
return [
|
206
|
+
2
|
207
|
+
];
|
208
|
+
}
|
209
|
+
});
|
210
|
+
})();
|
211
|
+
}
|
212
|
+
};
|
213
|
+
}
|
214
|
+
};
|
215
|
+
}
|
216
|
+
;
|
217
|
+
export {
|
218
|
+
deploy_default as default
|
219
|
+
};
|
@@ -0,0 +1,244 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
|
+
import path from "path";
|
4
|
+
import os from "node:os";
|
5
|
+
import { ROUTE_SPEC_FILE, fs as fse, isDepExists } from "@modern-js/utils";
|
6
|
+
import { parseNodeModulePath } from "mlly";
|
7
|
+
var severAppContextTemplate = function(serverAppContext) {
|
8
|
+
return "{\n sharedDirectory: ".concat(serverAppContext.sharedDirectory, ",\n apiDirectory: ").concat(serverAppContext.apiDirectory, ",\n lambdaDirectory: ").concat(serverAppContext.lambdaDirectory, ",\n }");
|
9
|
+
};
|
10
|
+
var getPluginsCode = function(plugins) {
|
11
|
+
return "[".concat(plugins.map(function(_, index) {
|
12
|
+
return "plugin_".concat(index, "()");
|
13
|
+
}).join(","), "]");
|
14
|
+
};
|
15
|
+
var genPluginImportsCode = function(plugins) {
|
16
|
+
return plugins.map(function(plugin, index) {
|
17
|
+
return "\n let plugin_".concat(index, " = require('").concat(plugin, "')\n plugin_").concat(index, " = plugin_").concat(index, ".default || plugin_").concat(index, "\n ");
|
18
|
+
}).join(";\n");
|
19
|
+
};
|
20
|
+
var getProjectUsage = function(appDirectory, distDirectory) {
|
21
|
+
var routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
|
22
|
+
var routes = fse.readJSONSync(routeJSON).routes;
|
23
|
+
var useSSR = false;
|
24
|
+
var useAPI = false;
|
25
|
+
routes.forEach(function(route) {
|
26
|
+
if (route.isSSR) {
|
27
|
+
useSSR = true;
|
28
|
+
}
|
29
|
+
if (route.isApi) {
|
30
|
+
useAPI = true;
|
31
|
+
}
|
32
|
+
});
|
33
|
+
var useWebServer = isDepExists(appDirectory, "@modern-js/plugin-server");
|
34
|
+
return {
|
35
|
+
useSSR,
|
36
|
+
useAPI,
|
37
|
+
useWebServer
|
38
|
+
};
|
39
|
+
};
|
40
|
+
function applyProductionCondition(exports) {
|
41
|
+
if (!exports || typeof exports === "string") {
|
42
|
+
return;
|
43
|
+
}
|
44
|
+
if (exports.production) {
|
45
|
+
if (typeof exports.production === "string") {
|
46
|
+
exports.default = exports.production;
|
47
|
+
} else {
|
48
|
+
Object.assign(exports, exports.production);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
for (var key in exports) {
|
52
|
+
applyProductionCondition(exports[key]);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
function applyPublicCondition(pkg) {
|
56
|
+
var _pkg_publishConfig;
|
57
|
+
if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
|
58
|
+
var _pkg_publishConfig1;
|
59
|
+
pkg.exports = pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig1 = pkg.publishConfig) === null || _pkg_publishConfig1 === void 0 ? void 0 : _pkg_publishConfig1.exports;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
var writePackage = function() {
|
63
|
+
var _ref = _async_to_generator(function(pkg, version, projectDir, _pkgPath) {
|
64
|
+
var pkgPath, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, src, subpath, dest, dirname, subpath1, dest1, dirname1, err, pkgJSON, packageJsonPath;
|
65
|
+
return _ts_generator(this, function(_state) {
|
66
|
+
switch (_state.label) {
|
67
|
+
case 0:
|
68
|
+
pkgPath = _pkgPath || pkg.name;
|
69
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
70
|
+
_state.label = 1;
|
71
|
+
case 1:
|
72
|
+
_state.trys.push([
|
73
|
+
1,
|
74
|
+
10,
|
75
|
+
11,
|
76
|
+
12
|
77
|
+
]);
|
78
|
+
_iterator = pkg.versions[version].files[Symbol.iterator]();
|
79
|
+
_state.label = 2;
|
80
|
+
case 2:
|
81
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
|
82
|
+
return [
|
83
|
+
3,
|
84
|
+
9
|
85
|
+
];
|
86
|
+
src = _step.value;
|
87
|
+
if (!src.includes("node_modules"))
|
88
|
+
return [
|
89
|
+
3,
|
90
|
+
5
|
91
|
+
];
|
92
|
+
subpath = parseNodeModulePath(src).subpath;
|
93
|
+
dest = path.join(projectDir, "node_modules", pkgPath, subpath);
|
94
|
+
dirname = path.dirname(dest);
|
95
|
+
return [
|
96
|
+
4,
|
97
|
+
fse.ensureDir(dirname)
|
98
|
+
];
|
99
|
+
case 3:
|
100
|
+
_state.sent();
|
101
|
+
return [
|
102
|
+
4,
|
103
|
+
fse.copyFile(src, dest)
|
104
|
+
];
|
105
|
+
case 4:
|
106
|
+
_state.sent();
|
107
|
+
return [
|
108
|
+
3,
|
109
|
+
8
|
110
|
+
];
|
111
|
+
case 5:
|
112
|
+
subpath1 = path.relative(pkg.versions[version].path, src);
|
113
|
+
dest1 = path.join(projectDir, "node_modules", pkgPath, subpath1);
|
114
|
+
dirname1 = path.dirname(dest1);
|
115
|
+
return [
|
116
|
+
4,
|
117
|
+
fse.ensureDir(dirname1)
|
118
|
+
];
|
119
|
+
case 6:
|
120
|
+
_state.sent();
|
121
|
+
return [
|
122
|
+
4,
|
123
|
+
fse.copyFile(src, dest1)
|
124
|
+
];
|
125
|
+
case 7:
|
126
|
+
_state.sent();
|
127
|
+
_state.label = 8;
|
128
|
+
case 8:
|
129
|
+
_iteratorNormalCompletion = true;
|
130
|
+
return [
|
131
|
+
3,
|
132
|
+
2
|
133
|
+
];
|
134
|
+
case 9:
|
135
|
+
return [
|
136
|
+
3,
|
137
|
+
12
|
138
|
+
];
|
139
|
+
case 10:
|
140
|
+
err = _state.sent();
|
141
|
+
_didIteratorError = true;
|
142
|
+
_iteratorError = err;
|
143
|
+
return [
|
144
|
+
3,
|
145
|
+
12
|
146
|
+
];
|
147
|
+
case 11:
|
148
|
+
try {
|
149
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
150
|
+
_iterator.return();
|
151
|
+
}
|
152
|
+
} finally {
|
153
|
+
if (_didIteratorError) {
|
154
|
+
throw _iteratorError;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
return [
|
158
|
+
7
|
159
|
+
];
|
160
|
+
case 12:
|
161
|
+
pkgJSON = pkg.versions[version].pkgJSON;
|
162
|
+
applyPublicCondition(pkgJSON);
|
163
|
+
packageJsonPath = path.join(projectDir, "node_modules", pkgPath, "package.json");
|
164
|
+
return [
|
165
|
+
4,
|
166
|
+
fse.ensureDir(path.dirname(packageJsonPath))
|
167
|
+
];
|
168
|
+
case 13:
|
169
|
+
_state.sent();
|
170
|
+
return [
|
171
|
+
4,
|
172
|
+
fse.writeFile(packageJsonPath, JSON.stringify(pkgJSON, null, 2))
|
173
|
+
];
|
174
|
+
case 14:
|
175
|
+
_state.sent();
|
176
|
+
return [
|
177
|
+
2
|
178
|
+
];
|
179
|
+
}
|
180
|
+
});
|
181
|
+
});
|
182
|
+
return function writePackage2(pkg, version, projectDir, _pkgPath) {
|
183
|
+
return _ref.apply(this, arguments);
|
184
|
+
};
|
185
|
+
}();
|
186
|
+
var isWindows = os.platform() === "win32";
|
187
|
+
var linkPackage = function() {
|
188
|
+
var _ref = _async_to_generator(function(from, to, projectRootDir) {
|
189
|
+
var src, dest, dstStat, exists;
|
190
|
+
return _ts_generator(this, function(_state) {
|
191
|
+
switch (_state.label) {
|
192
|
+
case 0:
|
193
|
+
src = path.join(projectRootDir, "node_modules", from);
|
194
|
+
dest = path.join(projectRootDir, "node_modules", to);
|
195
|
+
return [
|
196
|
+
4,
|
197
|
+
fse.lstat(dest).catch(function() {
|
198
|
+
return null;
|
199
|
+
})
|
200
|
+
];
|
201
|
+
case 1:
|
202
|
+
dstStat = _state.sent();
|
203
|
+
exists = dstStat === null || dstStat === void 0 ? void 0 : dstStat.isSymbolicLink();
|
204
|
+
if (exists) {
|
205
|
+
return [
|
206
|
+
2
|
207
|
+
];
|
208
|
+
}
|
209
|
+
return [
|
210
|
+
4,
|
211
|
+
fse.mkdir(path.dirname(dest), {
|
212
|
+
recursive: true
|
213
|
+
})
|
214
|
+
];
|
215
|
+
case 2:
|
216
|
+
_state.sent();
|
217
|
+
return [
|
218
|
+
4,
|
219
|
+
fse.symlink(path.relative(path.dirname(dest), src), dest, isWindows ? "junction" : "dir").catch(function(error) {
|
220
|
+
console.error("Cannot link", from, "to", to, error);
|
221
|
+
})
|
222
|
+
];
|
223
|
+
case 3:
|
224
|
+
_state.sent();
|
225
|
+
return [
|
226
|
+
2
|
227
|
+
];
|
228
|
+
}
|
229
|
+
});
|
230
|
+
});
|
231
|
+
return function linkPackage2(from, to, projectRootDir) {
|
232
|
+
return _ref.apply(this, arguments);
|
233
|
+
};
|
234
|
+
}();
|
235
|
+
export {
|
236
|
+
applyProductionCondition,
|
237
|
+
applyPublicCondition,
|
238
|
+
genPluginImportsCode,
|
239
|
+
getPluginsCode,
|
240
|
+
getProjectUsage,
|
241
|
+
linkPackage,
|
242
|
+
severAppContextTemplate,
|
243
|
+
writePackage
|
244
|
+
};
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
3
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
|
-
import {
|
3
|
+
import { createDevServer } from "@modern-js/server";
|
4
|
+
import { initProdMiddlewares } from "@modern-js/prod-server";
|
6
5
|
var server = null;
|
7
6
|
var getServer = function() {
|
8
7
|
return server;
|
@@ -13,26 +12,13 @@ var setServer = function(newServer) {
|
|
13
12
|
var closeServer = function() {
|
14
13
|
var _ref = _async_to_generator(function() {
|
15
14
|
return _ts_generator(this, function(_state) {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
return [
|
20
|
-
3,
|
21
|
-
2
|
22
|
-
];
|
23
|
-
return [
|
24
|
-
4,
|
25
|
-
server.close()
|
26
|
-
];
|
27
|
-
case 1:
|
28
|
-
_state.sent();
|
29
|
-
server = null;
|
30
|
-
_state.label = 2;
|
31
|
-
case 2:
|
32
|
-
return [
|
33
|
-
2
|
34
|
-
];
|
15
|
+
if (server) {
|
16
|
+
server.close();
|
17
|
+
server = null;
|
35
18
|
}
|
19
|
+
return [
|
20
|
+
2
|
21
|
+
];
|
36
22
|
});
|
37
23
|
});
|
38
24
|
return function closeServer2() {
|
@@ -41,33 +27,21 @@ var closeServer = function() {
|
|
41
27
|
}();
|
42
28
|
var createServer = function() {
|
43
29
|
var _ref = _async_to_generator(function(options) {
|
44
|
-
var app;
|
45
30
|
return _ts_generator(this, function(_state) {
|
46
31
|
switch (_state.label) {
|
47
32
|
case 0:
|
48
|
-
if (
|
49
|
-
|
50
|
-
|
51
|
-
2
|
52
|
-
];
|
33
|
+
if (server) {
|
34
|
+
server.close();
|
35
|
+
}
|
53
36
|
return [
|
54
37
|
4,
|
55
|
-
|
38
|
+
createDevServer(options, initProdMiddlewares)
|
56
39
|
];
|
57
40
|
case 1:
|
58
|
-
_state.sent();
|
59
|
-
_state.label = 2;
|
60
|
-
case 2:
|
61
|
-
server = new Server(options);
|
62
|
-
return [
|
63
|
-
4,
|
64
|
-
server.init()
|
65
|
-
];
|
66
|
-
case 3:
|
67
|
-
app = _state.sent();
|
41
|
+
server = _state.sent();
|
68
42
|
return [
|
69
43
|
2,
|
70
|
-
|
44
|
+
server
|
71
45
|
];
|
72
46
|
}
|
73
47
|
});
|
@@ -76,19 +50,9 @@ var createServer = function() {
|
|
76
50
|
return _ref.apply(this, arguments);
|
77
51
|
};
|
78
52
|
}();
|
79
|
-
var injectDataLoaderPlugin = function(internalPlugins) {
|
80
|
-
var DataLoaderPlugin = require.resolve("@modern-js/plugin-data-loader/server");
|
81
|
-
return _object_spread_props(_object_spread({}, internalPlugins), {
|
82
|
-
"@modern-js/plugin-data-loader": {
|
83
|
-
path: DataLoaderPlugin,
|
84
|
-
forced: true
|
85
|
-
}
|
86
|
-
});
|
87
|
-
};
|
88
53
|
export {
|
89
54
|
closeServer,
|
90
55
|
createServer,
|
91
56
|
getServer,
|
92
|
-
injectDataLoaderPlugin,
|
93
57
|
setServer
|
94
58
|
};
|
package/dist/esm/utils/env.js
CHANGED