@modern-js/app-tools 2.49.3-alpha.0 → 2.49.3
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/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,88 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var node_exports = {};
|
20
|
-
__export(node_exports, {
|
21
|
-
genNodeEntry: () => genNodeEntry
|
22
|
-
});
|
23
|
-
module.exports = __toCommonJS(node_exports);
|
24
|
-
var import_utils = require("@modern-js/utils");
|
25
|
-
var import_utils2 = require("../utils");
|
26
|
-
function genNodeEntry({ config, plugins, appContext } = {}) {
|
27
|
-
const defaultConfig = {
|
28
|
-
server: {
|
29
|
-
port: 8080
|
30
|
-
},
|
31
|
-
output: {
|
32
|
-
path: "."
|
33
|
-
}
|
34
|
-
};
|
35
|
-
return `
|
36
|
-
|
37
|
-
const fs = require('node:fs/promises');
|
38
|
-
const path = require('node:path');
|
39
|
-
const { createProdServer } = require('@modern-js/prod-server');
|
40
|
-
${(0, import_utils2.genPluginImportsCode)(plugins || [])}
|
41
|
-
|
42
|
-
if(!process.env.NODE_ENV){
|
43
|
-
process.env.NODE_ENV = 'production';
|
44
|
-
}
|
45
|
-
|
46
|
-
async function main() {
|
47
|
-
try {
|
48
|
-
let routes = [];
|
49
|
-
const routeFilepath = path.join(__dirname, "${import_utils.ROUTE_SPEC_FILE}");
|
50
|
-
try {
|
51
|
-
await fs.access(routeFilepath);
|
52
|
-
const content = await fs.readFile(routeFilepath, "utf-8");
|
53
|
-
const routeSpec = JSON.parse(content);
|
54
|
-
routes = routeSpec.routes;
|
55
|
-
} catch (error) {
|
56
|
-
console.warn('route.json not found, continuing with empty routes.');
|
57
|
-
}
|
58
|
-
|
59
|
-
const prodServerOptions = {
|
60
|
-
pwd: __dirname,
|
61
|
-
routes,
|
62
|
-
config: ${JSON.stringify(config || defaultConfig)},
|
63
|
-
serverConfigFile: '${import_utils.DEFAULT_SERVER_CONFIG}',
|
64
|
-
plugins: ${(0, import_utils2.getPluginsCode)(plugins || [])},
|
65
|
-
appContext: ${appContext ? (0, import_utils2.severAppContextTemplate)(appContext) : "undefined"},
|
66
|
-
disableCustomHook: true
|
67
|
-
}
|
68
|
-
|
69
|
-
const app = await createProdServer(prodServerOptions)
|
70
|
-
|
71
|
-
const port = process.env.PORT || 3000;
|
72
|
-
|
73
|
-
app.listen(port, () => {
|
74
|
-
console.log('\\x1b[32mServer is listening on port', port, '\\x1b[0m');
|
75
|
-
});
|
76
|
-
} catch(error) {
|
77
|
-
console.error(error);
|
78
|
-
process.exit(1);
|
79
|
-
}
|
80
|
-
}
|
81
|
-
|
82
|
-
main();
|
83
|
-
`;
|
84
|
-
}
|
85
|
-
// Annotate the CommonJS export names for ESM import in node:
|
86
|
-
0 && (module.exports = {
|
87
|
-
genNodeEntry
|
88
|
-
});
|
@@ -1,94 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var vercel_exports = {};
|
20
|
-
__export(vercel_exports, {
|
21
|
-
genVercelEntry: () => genVercelEntry
|
22
|
-
});
|
23
|
-
module.exports = __toCommonJS(vercel_exports);
|
24
|
-
var import_utils = require("@modern-js/utils");
|
25
|
-
var import_utils2 = require("../utils");
|
26
|
-
function genVercelEntry({ config, plugins, appContext } = {}) {
|
27
|
-
const defaultConfig = {
|
28
|
-
server: {
|
29
|
-
port: 8080
|
30
|
-
},
|
31
|
-
output: {
|
32
|
-
path: "."
|
33
|
-
}
|
34
|
-
};
|
35
|
-
return `
|
36
|
-
|
37
|
-
const fs = require('node:fs/promises');
|
38
|
-
const path = require('node:path');
|
39
|
-
const { createProdServer } = require('@modern-js/prod-server');
|
40
|
-
${(0, import_utils2.genPluginImportsCode)(plugins || [])}
|
41
|
-
|
42
|
-
if(!process.env.NODE_ENV){
|
43
|
-
process.env.NODE_ENV = 'production';
|
44
|
-
}
|
45
|
-
|
46
|
-
let requestHandler = null;
|
47
|
-
async function createHandler() {
|
48
|
-
try {
|
49
|
-
let routes = [];
|
50
|
-
const routeFilepath = path.join(__dirname, "${import_utils.ROUTE_SPEC_FILE}");
|
51
|
-
try {
|
52
|
-
await fs.access(routeFilepath);
|
53
|
-
const content = await fs.readFile(routeFilepath, "utf-8");
|
54
|
-
const routeSpec = JSON.parse(content);
|
55
|
-
routes = routeSpec.routes;
|
56
|
-
} catch (error) {
|
57
|
-
console.warn('route.json not found, continuing with empty routes.');
|
58
|
-
}
|
59
|
-
|
60
|
-
const prodServerOptions = {
|
61
|
-
pwd: __dirname,
|
62
|
-
routes,
|
63
|
-
config: ${JSON.stringify(config || defaultConfig)},
|
64
|
-
serverConfigFile: '${import_utils.DEFAULT_SERVER_CONFIG}',
|
65
|
-
plugins: ${(0, import_utils2.getPluginsCode)(plugins || [])},
|
66
|
-
appContext: ${appContext ? (0, import_utils2.severAppContextTemplate)(appContext) : "undefined"},
|
67
|
-
disableCustomHook: true
|
68
|
-
}
|
69
|
-
|
70
|
-
const app = await createProdServer(prodServerOptions)
|
71
|
-
|
72
|
-
requestHandler = app.getRequestListener();
|
73
|
-
|
74
|
-
return requestHandler;
|
75
|
-
} catch(error) {
|
76
|
-
console.error(error);
|
77
|
-
process.exit(1);
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
createHandler();
|
82
|
-
|
83
|
-
module.exports = async(req, res) => {
|
84
|
-
if(typeof requestHandler !== 'function'){
|
85
|
-
await createHandler();
|
86
|
-
}
|
87
|
-
return requestHandler(req, res);
|
88
|
-
}
|
89
|
-
`;
|
90
|
-
}
|
91
|
-
// Annotate the CommonJS export names for ESM import in node:
|
92
|
-
0 && (module.exports = {
|
93
|
-
genVercelEntry
|
94
|
-
});
|
@@ -1,186 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
-
var deploy_exports = {};
|
30
|
-
__export(deploy_exports, {
|
31
|
-
default: () => deploy_default
|
32
|
-
});
|
33
|
-
module.exports = __toCommonJS(deploy_exports);
|
34
|
-
var import_path = __toESM(require("path"));
|
35
|
-
var import_utils = require("@modern-js/utils");
|
36
|
-
var import_std_env = require("std-env");
|
37
|
-
var import_utils2 = require("./utils");
|
38
|
-
var import_dependencies = require("./dependencies");
|
39
|
-
var deploy_default = () => ({
|
40
|
-
name: "@modern-js/plugin-deploy",
|
41
|
-
pre: [
|
42
|
-
"@modern-js/plugin-bff",
|
43
|
-
"@modern-js/plugin-server"
|
44
|
-
],
|
45
|
-
setup: (api) => {
|
46
|
-
const deployTarget = process.env.MODERNJS_DEPLOY || import_std_env.provider || "node";
|
47
|
-
return {
|
48
|
-
async beforeDeploy(options) {
|
49
|
-
const { output: outputPath } = options;
|
50
|
-
const appContext = api.useAppContext();
|
51
|
-
const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName, entrypoints } = appContext;
|
52
|
-
const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
|
53
|
-
const needModernServer = useSSR || useAPI || useWebServer;
|
54
|
-
const configContext = api.useResolvedConfigContext();
|
55
|
-
let outputDirectory = import_path.default.resolve(appDirectory, ".output");
|
56
|
-
if (outputPath) {
|
57
|
-
outputDirectory = import_path.default.isAbsolute(outputPath) ? outputPath : import_path.default.resolve(outputPath);
|
58
|
-
}
|
59
|
-
let funcsDirectory = outputDirectory;
|
60
|
-
let staticDirectory = import_path.default.join(outputDirectory, "static");
|
61
|
-
if (deployTarget === "node") {
|
62
|
-
await import_utils.fs.remove(outputDirectory);
|
63
|
-
await import_utils.fs.copy(distDirectory, outputDirectory);
|
64
|
-
}
|
65
|
-
if (deployTarget === "vercel") {
|
66
|
-
const vercelOutput = import_path.default.join(appDirectory, ".vercel");
|
67
|
-
await import_utils.fs.remove(vercelOutput);
|
68
|
-
outputDirectory = import_path.default.join(vercelOutput, "output");
|
69
|
-
const config2 = {
|
70
|
-
version: 3,
|
71
|
-
routes: [
|
72
|
-
{
|
73
|
-
src: "/static/(.*)",
|
74
|
-
headers: {
|
75
|
-
"cache-control": "s-maxage=31536000, immutable"
|
76
|
-
},
|
77
|
-
continue: true
|
78
|
-
},
|
79
|
-
{
|
80
|
-
handle: "filesystem"
|
81
|
-
}
|
82
|
-
]
|
83
|
-
};
|
84
|
-
if (!needModernServer) {
|
85
|
-
entrypoints.forEach((entry) => {
|
86
|
-
config2.routes.push({
|
87
|
-
src: `/${entry.entryName}(?:/.*)?`,
|
88
|
-
headers: {
|
89
|
-
"cache-control": "s-maxage=0"
|
90
|
-
},
|
91
|
-
dest: `/html/${entry.entryName}/index.html`
|
92
|
-
});
|
93
|
-
});
|
94
|
-
} else {
|
95
|
-
config2.routes.push({
|
96
|
-
src: "/(.*)",
|
97
|
-
dest: `/index`
|
98
|
-
});
|
99
|
-
}
|
100
|
-
await import_utils.fs.ensureDir(outputDirectory);
|
101
|
-
await import_utils.fs.writeJSON(import_path.default.join(outputDirectory, "config.json"), config2, {
|
102
|
-
spaces: 2
|
103
|
-
});
|
104
|
-
staticDirectory = import_path.default.join(outputDirectory, "static/static");
|
105
|
-
await import_utils.fs.copy(import_path.default.join(distDirectory, "static"), staticDirectory);
|
106
|
-
if (!needModernServer) {
|
107
|
-
const destHtmlDirectory = import_path.default.join(distDirectory, "html");
|
108
|
-
const outputHtmlDirectory = import_path.default.join(import_path.default.join(outputDirectory, "static"), "html");
|
109
|
-
await import_utils.fs.copy(destHtmlDirectory, outputHtmlDirectory);
|
110
|
-
} else {
|
111
|
-
funcsDirectory = import_path.default.join(outputDirectory, "functions", "index.func");
|
112
|
-
await import_utils.fs.ensureDir(funcsDirectory);
|
113
|
-
await import_utils.fs.copy(distDirectory, funcsDirectory, {
|
114
|
-
filter: (src) => {
|
115
|
-
const distStaticDirectory = import_path.default.join(distDirectory, "static");
|
116
|
-
return !src.includes(distStaticDirectory);
|
117
|
-
}
|
118
|
-
});
|
119
|
-
await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
|
120
|
-
runtime: "nodejs16.x",
|
121
|
-
handler: "index.js",
|
122
|
-
launcherType: "Nodejs",
|
123
|
-
shouldAddHelpers: false,
|
124
|
-
supportsResponseStreaming: true
|
125
|
-
});
|
126
|
-
}
|
127
|
-
}
|
128
|
-
const { bff } = configContext;
|
129
|
-
const config = {
|
130
|
-
output: {
|
131
|
-
path: "."
|
132
|
-
},
|
133
|
-
bff
|
134
|
-
};
|
135
|
-
const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
|
136
|
-
const serverAppContext = {
|
137
|
-
sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
|
138
|
-
apiDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, apiDirectory)}")`,
|
139
|
-
lambdaDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, lambdaDirectory)}")`,
|
140
|
-
metaName
|
141
|
-
};
|
142
|
-
let code = ``;
|
143
|
-
console.log("deployTarget111111111", deployTarget);
|
144
|
-
switch (deployTarget) {
|
145
|
-
case "node": {
|
146
|
-
const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/node")));
|
147
|
-
code = genNodeEntry({
|
148
|
-
plugins,
|
149
|
-
config,
|
150
|
-
appContext: serverAppContext
|
151
|
-
});
|
152
|
-
break;
|
153
|
-
}
|
154
|
-
case "vercel": {
|
155
|
-
const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/vercel")));
|
156
|
-
code = genVercelEntry({
|
157
|
-
plugins,
|
158
|
-
config,
|
159
|
-
appContext: serverAppContext
|
160
|
-
});
|
161
|
-
break;
|
162
|
-
}
|
163
|
-
case "netlify": {
|
164
|
-
const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/netlify")));
|
165
|
-
code = genNetlifyEntry({
|
166
|
-
plugins,
|
167
|
-
config,
|
168
|
-
appContext: serverAppContext
|
169
|
-
});
|
170
|
-
break;
|
171
|
-
}
|
172
|
-
default: {
|
173
|
-
code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
|
174
|
-
}
|
175
|
-
}
|
176
|
-
const entryFilePath = import_path.default.join(funcsDirectory, "index.js");
|
177
|
-
if (needModernServer) {
|
178
|
-
await import_utils.fs.writeFile(entryFilePath, code);
|
179
|
-
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
180
|
-
"@modern-js/prod-server"
|
181
|
-
]);
|
182
|
-
}
|
183
|
-
}
|
184
|
-
};
|
185
|
-
}
|
186
|
-
});
|
@@ -1,150 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
-
var utils_exports = {};
|
30
|
-
__export(utils_exports, {
|
31
|
-
applyProductionCondition: () => applyProductionCondition,
|
32
|
-
applyPublicCondition: () => applyPublicCondition,
|
33
|
-
genPluginImportsCode: () => genPluginImportsCode,
|
34
|
-
getPluginsCode: () => getPluginsCode,
|
35
|
-
getProjectUsage: () => getProjectUsage,
|
36
|
-
linkPackage: () => linkPackage,
|
37
|
-
severAppContextTemplate: () => severAppContextTemplate,
|
38
|
-
writePackage: () => writePackage
|
39
|
-
});
|
40
|
-
module.exports = __toCommonJS(utils_exports);
|
41
|
-
var import_path = __toESM(require("path"));
|
42
|
-
var import_node_os = __toESM(require("node:os"));
|
43
|
-
var import_utils = require("@modern-js/utils");
|
44
|
-
var import_mlly = require("mlly");
|
45
|
-
const severAppContextTemplate = (serverAppContext) => {
|
46
|
-
return `{
|
47
|
-
sharedDirectory: ${serverAppContext.sharedDirectory},
|
48
|
-
apiDirectory: ${serverAppContext.apiDirectory},
|
49
|
-
lambdaDirectory: ${serverAppContext.lambdaDirectory},
|
50
|
-
}`;
|
51
|
-
};
|
52
|
-
const getPluginsCode = (plugins) => `[${plugins.map((_, index) => `plugin_${index}()`).join(",")}]`;
|
53
|
-
const genPluginImportsCode = (plugins) => {
|
54
|
-
return plugins.map((plugin, index) => `
|
55
|
-
let plugin_${index} = require('${plugin}')
|
56
|
-
plugin_${index} = plugin_${index}.default || plugin_${index}
|
57
|
-
`).join(";\n");
|
58
|
-
};
|
59
|
-
const getProjectUsage = (appDirectory, distDirectory) => {
|
60
|
-
const routeJSON = import_path.default.join(distDirectory, import_utils.ROUTE_SPEC_FILE);
|
61
|
-
const { routes } = import_utils.fs.readJSONSync(routeJSON);
|
62
|
-
let useSSR = false;
|
63
|
-
let useAPI = false;
|
64
|
-
routes.forEach((route) => {
|
65
|
-
if (route.isSSR) {
|
66
|
-
useSSR = true;
|
67
|
-
}
|
68
|
-
if (route.isApi) {
|
69
|
-
useAPI = true;
|
70
|
-
}
|
71
|
-
});
|
72
|
-
const useWebServer = (0, import_utils.isDepExists)(appDirectory, "@modern-js/plugin-server");
|
73
|
-
return {
|
74
|
-
useSSR,
|
75
|
-
useAPI,
|
76
|
-
useWebServer
|
77
|
-
};
|
78
|
-
};
|
79
|
-
function applyProductionCondition(exports) {
|
80
|
-
if (!exports || typeof exports === "string") {
|
81
|
-
return;
|
82
|
-
}
|
83
|
-
if (exports.production) {
|
84
|
-
if (typeof exports.production === "string") {
|
85
|
-
exports.default = exports.production;
|
86
|
-
} else {
|
87
|
-
Object.assign(exports, exports.production);
|
88
|
-
}
|
89
|
-
}
|
90
|
-
for (const key in exports) {
|
91
|
-
applyProductionCondition(exports[key]);
|
92
|
-
}
|
93
|
-
}
|
94
|
-
function applyPublicCondition(pkg) {
|
95
|
-
var _pkg_publishConfig;
|
96
|
-
if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
|
97
|
-
var _pkg_publishConfig1;
|
98
|
-
pkg.exports = pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig1 = pkg.publishConfig) === null || _pkg_publishConfig1 === void 0 ? void 0 : _pkg_publishConfig1.exports;
|
99
|
-
}
|
100
|
-
}
|
101
|
-
const writePackage = async (pkg, version, projectDir, _pkgPath) => {
|
102
|
-
const pkgPath = _pkgPath || pkg.name;
|
103
|
-
for (const src of pkg.versions[version].files) {
|
104
|
-
if (src.includes("node_modules")) {
|
105
|
-
const { subpath } = (0, import_mlly.parseNodeModulePath)(src);
|
106
|
-
const dest = import_path.default.join(projectDir, "node_modules", pkgPath, subpath);
|
107
|
-
const dirname = import_path.default.dirname(dest);
|
108
|
-
await import_utils.fs.ensureDir(dirname);
|
109
|
-
await import_utils.fs.copyFile(src, dest);
|
110
|
-
} else {
|
111
|
-
const subpath = import_path.default.relative(pkg.versions[version].path, src);
|
112
|
-
const dest = import_path.default.join(projectDir, "node_modules", pkgPath, subpath);
|
113
|
-
const dirname = import_path.default.dirname(dest);
|
114
|
-
await import_utils.fs.ensureDir(dirname);
|
115
|
-
await import_utils.fs.copyFile(src, dest);
|
116
|
-
}
|
117
|
-
}
|
118
|
-
const { pkgJSON } = pkg.versions[version];
|
119
|
-
applyPublicCondition(pkgJSON);
|
120
|
-
const packageJsonPath = import_path.default.join(projectDir, "node_modules", pkgPath, "package.json");
|
121
|
-
await import_utils.fs.ensureDir(import_path.default.dirname(packageJsonPath));
|
122
|
-
await import_utils.fs.writeFile(packageJsonPath, JSON.stringify(pkgJSON, null, 2));
|
123
|
-
};
|
124
|
-
const isWindows = import_node_os.default.platform() === "win32";
|
125
|
-
const linkPackage = async (from, to, projectRootDir) => {
|
126
|
-
const src = import_path.default.join(projectRootDir, "node_modules", from);
|
127
|
-
const dest = import_path.default.join(projectRootDir, "node_modules", to);
|
128
|
-
const dstStat = await import_utils.fs.lstat(dest).catch(() => null);
|
129
|
-
const exists = dstStat === null || dstStat === void 0 ? void 0 : dstStat.isSymbolicLink();
|
130
|
-
if (exists) {
|
131
|
-
return;
|
132
|
-
}
|
133
|
-
await import_utils.fs.mkdir(import_path.default.dirname(dest), {
|
134
|
-
recursive: true
|
135
|
-
});
|
136
|
-
await import_utils.fs.symlink(import_path.default.relative(import_path.default.dirname(dest), src), dest, isWindows ? "junction" : "dir").catch((error) => {
|
137
|
-
console.error("Cannot link", from, "to", to, error);
|
138
|
-
});
|
139
|
-
};
|
140
|
-
// Annotate the CommonJS export names for ESM import in node:
|
141
|
-
0 && (module.exports = {
|
142
|
-
applyProductionCondition,
|
143
|
-
applyPublicCondition,
|
144
|
-
genPluginImportsCode,
|
145
|
-
getPluginsCode,
|
146
|
-
getProjectUsage,
|
147
|
-
linkPackage,
|
148
|
-
severAppContextTemplate,
|
149
|
-
writePackage
|
150
|
-
});
|