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