@modern-js/app-tools 2.49.3-alpha.0 → 2.49.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/index.js +2 -4
- package/dist/cjs/locale/en.js +1 -2
- package/dist/cjs/locale/zh.js +1 -2
- package/dist/esm/index.js +2 -4
- package/dist/esm/locale/en.js +1 -2
- package/dist/esm/locale/zh.js +1 -2
- package/dist/esm-node/index.js +2 -4
- package/dist/esm-node/locale/en.js +1 -2
- package/dist/esm-node/locale/zh.js +1 -2
- package/dist/types/locale/en.d.ts +0 -1
- package/dist/types/locale/index.d.ts +0 -2
- package/dist/types/locale/zh.d.ts +0 -1
- package/dist/types/utils/types.d.ts +0 -1
- package/package.json +22 -26
- package/dist/cjs/plugins/deploy/dependencies.js +0 -256
- package/dist/cjs/plugins/deploy/entrys/netlify.js +0 -95
- package/dist/cjs/plugins/deploy/entrys/node.js +0 -88
- package/dist/cjs/plugins/deploy/entrys/vercel.js +0 -94
- package/dist/cjs/plugins/deploy/index.js +0 -186
- package/dist/cjs/plugins/deploy/utils.js +0 -150
- package/dist/esm/plugins/deploy/dependencies.js +0 -725
- package/dist/esm/plugins/deploy/entrys/netlify.js +0 -41
- package/dist/esm/plugins/deploy/entrys/node.js +0 -39
- package/dist/esm/plugins/deploy/entrys/vercel.js +0 -40
- package/dist/esm/plugins/deploy/index.js +0 -297
- package/dist/esm/plugins/deploy/utils.js +0 -244
- package/dist/esm-node/plugins/deploy/dependencies.js +0 -222
- package/dist/esm-node/plugins/deploy/entrys/netlify.js +0 -71
- package/dist/esm-node/plugins/deploy/entrys/node.js +0 -64
- package/dist/esm-node/plugins/deploy/entrys/vercel.js +0 -70
- package/dist/esm-node/plugins/deploy/index.js +0 -156
- package/dist/esm-node/plugins/deploy/utils.js +0 -109
- package/dist/types/plugins/deploy/dependencies.d.ts +0 -1
- package/dist/types/plugins/deploy/entrys/netlify.d.ts +0 -5
- package/dist/types/plugins/deploy/entrys/node.d.ts +0 -5
- package/dist/types/plugins/deploy/entrys/vercel.d.ts +0 -5
- package/dist/types/plugins/deploy/index.d.ts +0 -4
- package/dist/types/plugins/deploy/utils.d.ts +0 -27
@@ -1,41 +0,0 @@
|
|
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
|
-
};
|
@@ -1,39 +0,0 @@
|
|
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
|
-
};
|
@@ -1,40 +0,0 @@
|
|
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 { 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
|
-
let requestHandler = null;
|
20
|
-
async function createHandler() {
|
21
|
-
try {
|
22
|
-
let routes = [];
|
23
|
-
const routeFilepath = path.join(__dirname, "`).concat(ROUTE_SPEC_FILE, `");
|
24
|
-
try {
|
25
|
-
await fs.access(routeFilepath);
|
26
|
-
const content = await fs.readFile(routeFilepath, "utf-8");
|
27
|
-
const routeSpec = JSON.parse(content);
|
28
|
-
routes = routeSpec.routes;
|
29
|
-
} catch (error) {
|
30
|
-
console.warn('route.json not found, continuing with empty routes.');
|
31
|
-
}
|
32
|
-
|
33
|
-
const prodServerOptions = {
|
34
|
-
pwd: __dirname,
|
35
|
-
routes,
|
36
|
-
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 requestHandler = app.getRequestListener();\n\n return requestHandler;\n } catch(error) {\n console.error(error);\n process.exit(1);\n }\n }\n\n createHandler();\n\n module.exports = async(req, res) => {\n if(typeof requestHandler !== 'function'){\n await createHandler();\n }\n return requestHandler(req, res);\n }\n ");
|
37
|
-
}
|
38
|
-
export {
|
39
|
-
genVercelEntry
|
40
|
-
};
|
@@ -1,297 +0,0 @@
|
|
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 { provider } from "std-env";
|
6
|
-
import { getProjectUsage } from "./utils";
|
7
|
-
import { handleDependencies } from "./dependencies";
|
8
|
-
function deploy_default() {
|
9
|
-
return {
|
10
|
-
name: "@modern-js/plugin-deploy",
|
11
|
-
pre: [
|
12
|
-
"@modern-js/plugin-bff",
|
13
|
-
"@modern-js/plugin-server"
|
14
|
-
],
|
15
|
-
setup: function(api) {
|
16
|
-
var deployTarget = process.env.MODERNJS_DEPLOY || provider || "node";
|
17
|
-
return {
|
18
|
-
beforeDeploy: function beforeDeploy(options) {
|
19
|
-
return _async_to_generator(function() {
|
20
|
-
var outputPath, appContext, appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, configContext, outputDirectory, funcsDirectory, staticDirectory, vercelOutput, config, destHtmlDirectory, outputHtmlDirectory, bff, config1, plugins, serverAppContext, code, genNodeEntry, genVercelEntry, genNetlifyEntry, entryFilePath;
|
21
|
-
return _ts_generator(this, function(_state) {
|
22
|
-
switch (_state.label) {
|
23
|
-
case 0:
|
24
|
-
outputPath = options.output;
|
25
|
-
appContext = api.useAppContext();
|
26
|
-
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, sharedDirectory = appContext.sharedDirectory, apiDirectory = appContext.apiDirectory, lambdaDirectory = appContext.lambdaDirectory, metaName = appContext.metaName, entrypoints = appContext.entrypoints;
|
27
|
-
_getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
|
28
|
-
needModernServer = useSSR || useAPI || useWebServer;
|
29
|
-
configContext = api.useResolvedConfigContext();
|
30
|
-
outputDirectory = path.resolve(appDirectory, ".output");
|
31
|
-
if (outputPath) {
|
32
|
-
outputDirectory = path.isAbsolute(outputPath) ? outputPath : path.resolve(outputPath);
|
33
|
-
}
|
34
|
-
funcsDirectory = outputDirectory;
|
35
|
-
staticDirectory = path.join(outputDirectory, "static");
|
36
|
-
if (!(deployTarget === "node"))
|
37
|
-
return [
|
38
|
-
3,
|
39
|
-
3
|
40
|
-
];
|
41
|
-
return [
|
42
|
-
4,
|
43
|
-
fse.remove(outputDirectory)
|
44
|
-
];
|
45
|
-
case 1:
|
46
|
-
_state.sent();
|
47
|
-
return [
|
48
|
-
4,
|
49
|
-
fse.copy(distDirectory, outputDirectory)
|
50
|
-
];
|
51
|
-
case 2:
|
52
|
-
_state.sent();
|
53
|
-
_state.label = 3;
|
54
|
-
case 3:
|
55
|
-
if (!(deployTarget === "vercel"))
|
56
|
-
return [
|
57
|
-
3,
|
58
|
-
13
|
59
|
-
];
|
60
|
-
vercelOutput = path.join(appDirectory, ".vercel");
|
61
|
-
return [
|
62
|
-
4,
|
63
|
-
fse.remove(vercelOutput)
|
64
|
-
];
|
65
|
-
case 4:
|
66
|
-
_state.sent();
|
67
|
-
outputDirectory = path.join(vercelOutput, "output");
|
68
|
-
config = {
|
69
|
-
version: 3,
|
70
|
-
routes: [
|
71
|
-
{
|
72
|
-
src: "/static/(.*)",
|
73
|
-
headers: {
|
74
|
-
"cache-control": "s-maxage=31536000, immutable"
|
75
|
-
},
|
76
|
-
continue: true
|
77
|
-
},
|
78
|
-
{
|
79
|
-
handle: "filesystem"
|
80
|
-
}
|
81
|
-
]
|
82
|
-
};
|
83
|
-
if (!needModernServer) {
|
84
|
-
entrypoints.forEach(function(entry) {
|
85
|
-
config.routes.push({
|
86
|
-
src: "/".concat(entry.entryName, "(?:/.*)?"),
|
87
|
-
headers: {
|
88
|
-
"cache-control": "s-maxage=0"
|
89
|
-
},
|
90
|
-
dest: "/html/".concat(entry.entryName, "/index.html")
|
91
|
-
});
|
92
|
-
});
|
93
|
-
} else {
|
94
|
-
config.routes.push({
|
95
|
-
src: "/(.*)",
|
96
|
-
dest: "/index"
|
97
|
-
});
|
98
|
-
}
|
99
|
-
return [
|
100
|
-
4,
|
101
|
-
fse.ensureDir(outputDirectory)
|
102
|
-
];
|
103
|
-
case 5:
|
104
|
-
_state.sent();
|
105
|
-
return [
|
106
|
-
4,
|
107
|
-
fse.writeJSON(path.join(outputDirectory, "config.json"), config, {
|
108
|
-
spaces: 2
|
109
|
-
})
|
110
|
-
];
|
111
|
-
case 6:
|
112
|
-
_state.sent();
|
113
|
-
staticDirectory = path.join(outputDirectory, "static/static");
|
114
|
-
return [
|
115
|
-
4,
|
116
|
-
fse.copy(path.join(distDirectory, "static"), staticDirectory)
|
117
|
-
];
|
118
|
-
case 7:
|
119
|
-
_state.sent();
|
120
|
-
if (!!needModernServer)
|
121
|
-
return [
|
122
|
-
3,
|
123
|
-
9
|
124
|
-
];
|
125
|
-
destHtmlDirectory = path.join(distDirectory, "html");
|
126
|
-
outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
|
127
|
-
return [
|
128
|
-
4,
|
129
|
-
fse.copy(destHtmlDirectory, outputHtmlDirectory)
|
130
|
-
];
|
131
|
-
case 8:
|
132
|
-
_state.sent();
|
133
|
-
return [
|
134
|
-
3,
|
135
|
-
13
|
136
|
-
];
|
137
|
-
case 9:
|
138
|
-
funcsDirectory = path.join(outputDirectory, "functions", "index.func");
|
139
|
-
return [
|
140
|
-
4,
|
141
|
-
fse.ensureDir(funcsDirectory)
|
142
|
-
];
|
143
|
-
case 10:
|
144
|
-
_state.sent();
|
145
|
-
return [
|
146
|
-
4,
|
147
|
-
fse.copy(distDirectory, funcsDirectory, {
|
148
|
-
filter: function(src) {
|
149
|
-
var distStaticDirectory = path.join(distDirectory, "static");
|
150
|
-
return !src.includes(distStaticDirectory);
|
151
|
-
}
|
152
|
-
})
|
153
|
-
];
|
154
|
-
case 11:
|
155
|
-
_state.sent();
|
156
|
-
return [
|
157
|
-
4,
|
158
|
-
fse.writeJSON(path.join(funcsDirectory, ".vc-config.json"), {
|
159
|
-
runtime: "nodejs16.x",
|
160
|
-
handler: "index.js",
|
161
|
-
launcherType: "Nodejs",
|
162
|
-
shouldAddHelpers: false,
|
163
|
-
supportsResponseStreaming: true
|
164
|
-
})
|
165
|
-
];
|
166
|
-
case 12:
|
167
|
-
_state.sent();
|
168
|
-
_state.label = 13;
|
169
|
-
case 13:
|
170
|
-
bff = configContext.bff;
|
171
|
-
config1 = {
|
172
|
-
output: {
|
173
|
-
path: "."
|
174
|
-
},
|
175
|
-
bff
|
176
|
-
};
|
177
|
-
plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
|
178
|
-
serverAppContext = {
|
179
|
-
sharedDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, sharedDirectory), '")'),
|
180
|
-
apiDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, apiDirectory), '")'),
|
181
|
-
lambdaDirectory: 'path.join(__dirname, "'.concat(path.relative(appDirectory, lambdaDirectory), '")'),
|
182
|
-
metaName
|
183
|
-
};
|
184
|
-
code = "";
|
185
|
-
console.log("deployTarget111111111", deployTarget);
|
186
|
-
switch (deployTarget) {
|
187
|
-
case "node":
|
188
|
-
return [
|
189
|
-
3,
|
190
|
-
14
|
191
|
-
];
|
192
|
-
case "vercel":
|
193
|
-
return [
|
194
|
-
3,
|
195
|
-
16
|
196
|
-
];
|
197
|
-
case "netlify":
|
198
|
-
return [
|
199
|
-
3,
|
200
|
-
18
|
201
|
-
];
|
202
|
-
}
|
203
|
-
return [
|
204
|
-
3,
|
205
|
-
20
|
206
|
-
];
|
207
|
-
case 14:
|
208
|
-
return [
|
209
|
-
4,
|
210
|
-
import("./entrys/node")
|
211
|
-
];
|
212
|
-
case 15:
|
213
|
-
genNodeEntry = _state.sent().genNodeEntry;
|
214
|
-
code = genNodeEntry({
|
215
|
-
plugins,
|
216
|
-
config: config1,
|
217
|
-
appContext: serverAppContext
|
218
|
-
});
|
219
|
-
return [
|
220
|
-
3,
|
221
|
-
21
|
222
|
-
];
|
223
|
-
case 16:
|
224
|
-
return [
|
225
|
-
4,
|
226
|
-
import("./entrys/vercel")
|
227
|
-
];
|
228
|
-
case 17:
|
229
|
-
genVercelEntry = _state.sent().genVercelEntry;
|
230
|
-
code = genVercelEntry({
|
231
|
-
plugins,
|
232
|
-
config: config1,
|
233
|
-
appContext: serverAppContext
|
234
|
-
});
|
235
|
-
return [
|
236
|
-
3,
|
237
|
-
21
|
238
|
-
];
|
239
|
-
case 18:
|
240
|
-
return [
|
241
|
-
4,
|
242
|
-
import("./entrys/netlify")
|
243
|
-
];
|
244
|
-
case 19:
|
245
|
-
genNetlifyEntry = _state.sent().genNetlifyEntry;
|
246
|
-
code = genNetlifyEntry({
|
247
|
-
plugins,
|
248
|
-
config: config1,
|
249
|
-
appContext: serverAppContext
|
250
|
-
});
|
251
|
-
return [
|
252
|
-
3,
|
253
|
-
21
|
254
|
-
];
|
255
|
-
case 20:
|
256
|
-
{
|
257
|
-
code = 'throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");';
|
258
|
-
}
|
259
|
-
_state.label = 21;
|
260
|
-
case 21:
|
261
|
-
entryFilePath = path.join(funcsDirectory, "index.js");
|
262
|
-
if (!needModernServer)
|
263
|
-
return [
|
264
|
-
3,
|
265
|
-
24
|
266
|
-
];
|
267
|
-
return [
|
268
|
-
4,
|
269
|
-
fse.writeFile(entryFilePath, code)
|
270
|
-
];
|
271
|
-
case 22:
|
272
|
-
_state.sent();
|
273
|
-
return [
|
274
|
-
4,
|
275
|
-
handleDependencies(appDirectory, funcsDirectory, [
|
276
|
-
"@modern-js/prod-server"
|
277
|
-
])
|
278
|
-
];
|
279
|
-
case 23:
|
280
|
-
_state.sent();
|
281
|
-
_state.label = 24;
|
282
|
-
case 24:
|
283
|
-
return [
|
284
|
-
2
|
285
|
-
];
|
286
|
-
}
|
287
|
-
});
|
288
|
-
})();
|
289
|
-
}
|
290
|
-
};
|
291
|
-
}
|
292
|
-
};
|
293
|
-
}
|
294
|
-
;
|
295
|
-
export {
|
296
|
-
deploy_default as default
|
297
|
-
};
|
@@ -1,244 +0,0 @@
|
|
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
|
-
};
|