@modern-js/app-tools 2.49.3-alpha.2 → 2.49.3-alpha.20
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/analyze/getServerRoutes.js +4 -3
- package/dist/cjs/plugins/deploy/dependencies.js +1 -12
- package/dist/cjs/plugins/deploy/index.js +25 -147
- package/dist/cjs/plugins/deploy/platforms/netlify.js +120 -0
- package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +60 -0
- package/dist/cjs/plugins/deploy/platforms/node.js +90 -0
- package/dist/cjs/plugins/deploy/platforms/nodeEntry.js +41 -0
- package/dist/cjs/plugins/deploy/platforms/platform.js +16 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +145 -0
- package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +60 -0
- package/dist/cjs/plugins/deploy/utils.js +22 -8
- package/dist/cjs/utils/routes.js +7 -2
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/plugins/deploy/dependencies.js +1 -47
- package/dist/esm/plugins/deploy/index.js +66 -245
- package/dist/esm/plugins/deploy/platforms/netlify.js +182 -0
- package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +202 -0
- package/dist/esm/plugins/deploy/platforms/node.js +122 -0
- package/dist/esm/plugins/deploy/platforms/nodeEntry.js +104 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +220 -0
- package/dist/esm/plugins/deploy/platforms/vercelEntry.js +202 -0
- package/dist/esm/plugins/deploy/utils.js +55 -3
- package/dist/esm/utils/routes.js +6 -2
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/plugins/deploy/dependencies.js +1 -12
- package/dist/esm-node/plugins/deploy/index.js +24 -136
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +86 -0
- package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +56 -0
- package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +40 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +111 -0
- package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +68 -0
- package/dist/esm-node/plugins/deploy/utils.js +20 -7
- package/dist/esm-node/utils/routes.js +6 -2
- package/dist/types/plugins/deploy/platforms/netlify.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/node.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/nodeEntry.d.ts +1 -0
- package/dist/types/plugins/deploy/platforms/platform.d.ts +10 -0
- package/dist/types/plugins/deploy/platforms/vercel.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/utils.d.ts +8 -1
- package/dist/types/utils/routes.d.ts +3 -3
- package/package.json +21 -21
- 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 -97
- 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 -43
- 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 -73
- 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 -6
| @@ -1,10 +1,37 @@ | |
| 1 1 | 
             
            import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
         | 
| 2 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 3 | 
             
            import { provider } from "std-env";
         | 
| 6 4 | 
             
            import { getProjectUsage } from "./utils";
         | 
| 7 | 
            -
            import {  | 
| 5 | 
            +
            import { createNodePreset } from "./platforms/node";
         | 
| 6 | 
            +
            import { createVercelPreset } from "./platforms/vercel";
         | 
| 7 | 
            +
            import { createNetlifyPreset } from "./platforms/netlify";
         | 
| 8 | 
            +
            var deployPresets = {
         | 
| 9 | 
            +
              node: createNodePreset,
         | 
| 10 | 
            +
              vercel: createVercelPreset,
         | 
| 11 | 
            +
              netlify: createNetlifyPreset
         | 
| 12 | 
            +
            };
         | 
| 13 | 
            +
            function getDeployPreset(appContext, modernConfig, deployTarget) {
         | 
| 14 | 
            +
              return _getDeployPreset.apply(this, arguments);
         | 
| 15 | 
            +
            }
         | 
| 16 | 
            +
            function _getDeployPreset() {
         | 
| 17 | 
            +
              _getDeployPreset = _async_to_generator(function(appContext, modernConfig, deployTarget) {
         | 
| 18 | 
            +
                var appDirectory, distDirectory, _getProjectUsage, useSSR, useAPI, useWebServer, needModernServer, createPreset;
         | 
| 19 | 
            +
                return _ts_generator(this, function(_state) {
         | 
| 20 | 
            +
                  appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory;
         | 
| 21 | 
            +
                  _getProjectUsage = getProjectUsage(appDirectory, distDirectory), useSSR = _getProjectUsage.useSSR, useAPI = _getProjectUsage.useAPI, useWebServer = _getProjectUsage.useWebServer;
         | 
| 22 | 
            +
                  needModernServer = useSSR || useAPI || useWebServer;
         | 
| 23 | 
            +
                  createPreset = deployPresets[deployTarget];
         | 
| 24 | 
            +
                  if (!createPreset) {
         | 
| 25 | 
            +
                    throw new Error("Unknown deploy target: '".concat(deployTarget, "'. MODERNJS_DEPLOY should be 'node', 'vercel', or 'netlify'."));
         | 
| 26 | 
            +
                  }
         | 
| 27 | 
            +
                  return [
         | 
| 28 | 
            +
                    2,
         | 
| 29 | 
            +
                    createPreset(appContext, modernConfig, needModernServer)
         | 
| 30 | 
            +
                  ];
         | 
| 31 | 
            +
                });
         | 
| 32 | 
            +
              });
         | 
| 33 | 
            +
              return _getDeployPreset.apply(this, arguments);
         | 
| 34 | 
            +
            }
         | 
| 8 35 | 
             
            function deploy_default() {
         | 
| 9 36 | 
             
              return {
         | 
| 10 37 | 
             
                name: "@modern-js/plugin-deploy",
         | 
| @@ -17,284 +44,78 @@ function deploy_default() { | |
| 17 44 | 
             
                  return {
         | 
| 18 45 | 
             
                    beforeDeploy: function beforeDeploy() {
         | 
| 19 46 | 
             
                      return _async_to_generator(function() {
         | 
| 20 | 
            -
                        var appContext,  | 
| 47 | 
            +
                        var appContext, modernConfig, deployPreset, _tmp, _tmp1, _tmp2, _tmp3;
         | 
| 21 48 | 
             
                        return _ts_generator(this, function(_state) {
         | 
| 22 49 | 
             
                          switch (_state.label) {
         | 
| 23 50 | 
             
                            case 0:
         | 
| 24 51 | 
             
                              appContext = api.useAppContext();
         | 
| 25 | 
            -
                               | 
| 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 | 
            -
                                ];
         | 
| 52 | 
            +
                              modernConfig = api.useResolvedConfigContext();
         | 
| 37 53 | 
             
                              return [
         | 
| 38 54 | 
             
                                4,
         | 
| 39 | 
            -
                                 | 
| 55 | 
            +
                                getDeployPreset(appContext, modernConfig, deployTarget)
         | 
| 40 56 | 
             
                              ];
         | 
| 41 57 | 
             
                            case 1:
         | 
| 42 | 
            -
                              _state.sent();
         | 
| 58 | 
            +
                              deployPreset = _state.sent();
         | 
| 59 | 
            +
                              _tmp = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare;
         | 
| 60 | 
            +
                              if (!_tmp)
         | 
| 61 | 
            +
                                return [
         | 
| 62 | 
            +
                                  3,
         | 
| 63 | 
            +
                                  3
         | 
| 64 | 
            +
                                ];
         | 
| 43 65 | 
             
                              return [
         | 
| 44 66 | 
             
                                4,
         | 
| 45 | 
            -
                                 | 
| 67 | 
            +
                                deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.prepare()
         | 
| 46 68 | 
             
                              ];
         | 
| 47 69 | 
             
                            case 2:
         | 
| 48 | 
            -
                              _state.sent();
         | 
| 70 | 
            +
                              _tmp = _state.sent();
         | 
| 49 71 | 
             
                              _state.label = 3;
         | 
| 50 72 | 
             
                            case 3:
         | 
| 51 | 
            -
                               | 
| 73 | 
            +
                              _tmp;
         | 
| 74 | 
            +
                              _tmp1 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput;
         | 
| 75 | 
            +
                              if (!_tmp1)
         | 
| 52 76 | 
             
                                return [
         | 
| 53 77 | 
             
                                  3,
         | 
| 54 | 
            -
                                   | 
| 78 | 
            +
                                  5
         | 
| 55 79 | 
             
                                ];
         | 
| 56 | 
            -
                              vercelOutput = path.join(appDirectory, ".vercel");
         | 
| 57 80 | 
             
                              return [
         | 
| 58 81 | 
             
                                4,
         | 
| 59 | 
            -
                                 | 
| 82 | 
            +
                                deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.writeOutput()
         | 
| 60 83 | 
             
                              ];
         | 
| 61 84 | 
             
                            case 4:
         | 
| 62 | 
            -
                              _state.sent();
         | 
| 63 | 
            -
                               | 
| 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 | 
            -
                              ];
         | 
| 85 | 
            +
                              _tmp1 = _state.sent();
         | 
| 86 | 
            +
                              _state.label = 5;
         | 
| 99 87 | 
             
                            case 5:
         | 
| 100 | 
            -
                               | 
| 88 | 
            +
                              _tmp1;
         | 
| 89 | 
            +
                              _tmp2 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry;
         | 
| 90 | 
            +
                              if (!_tmp2)
         | 
| 91 | 
            +
                                return [
         | 
| 92 | 
            +
                                  3,
         | 
| 93 | 
            +
                                  7
         | 
| 94 | 
            +
                                ];
         | 
| 101 95 | 
             
                              return [
         | 
| 102 96 | 
             
                                4,
         | 
| 103 | 
            -
                                 | 
| 104 | 
            -
                                  spaces: 2
         | 
| 105 | 
            -
                                })
         | 
| 97 | 
            +
                                deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.genEntry()
         | 
| 106 98 | 
             
                              ];
         | 
| 107 99 | 
             
                            case 6:
         | 
| 108 | 
            -
                              _state.sent();
         | 
| 109 | 
            -
                               | 
| 110 | 
            -
                              return [
         | 
| 111 | 
            -
                                4,
         | 
| 112 | 
            -
                                fse.copy(path.join(distDirectory, "static"), staticDirectory)
         | 
| 113 | 
            -
                              ];
         | 
| 100 | 
            +
                              _tmp2 = _state.sent();
         | 
| 101 | 
            +
                              _state.label = 7;
         | 
| 114 102 | 
             
                            case 7:
         | 
| 115 | 
            -
                               | 
| 116 | 
            -
                               | 
| 103 | 
            +
                              _tmp2;
         | 
| 104 | 
            +
                              _tmp3 = deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end;
         | 
| 105 | 
            +
                              if (!_tmp3)
         | 
| 117 106 | 
             
                                return [
         | 
| 118 107 | 
             
                                  3,
         | 
| 119 108 | 
             
                                  9
         | 
| 120 109 | 
             
                                ];
         | 
| 121 | 
            -
                              destHtmlDirectory = path.join(distDirectory, "html");
         | 
| 122 | 
            -
                              outputHtmlDirectory = path.join(path.join(outputDirectory, "static"), "html");
         | 
| 123 110 | 
             
                              return [
         | 
| 124 111 | 
             
                                4,
         | 
| 125 | 
            -
                                 | 
| 112 | 
            +
                                deployPreset === null || deployPreset === void 0 ? void 0 : deployPreset.end()
         | 
| 126 113 | 
             
                              ];
         | 
| 127 114 | 
             
                            case 8:
         | 
| 128 | 
            -
                              _state.sent();
         | 
| 129 | 
            -
                               | 
| 130 | 
            -
                                3,
         | 
| 131 | 
            -
                                16
         | 
| 132 | 
            -
                              ];
         | 
| 115 | 
            +
                              _tmp3 = _state.sent();
         | 
| 116 | 
            +
                              _state.label = 9;
         | 
| 133 117 | 
             
                            case 9:
         | 
| 134 | 
            -
                               | 
| 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:
         | 
| 118 | 
            +
                              _tmp3;
         | 
| 298 119 | 
             
                              return [
         | 
| 299 120 | 
             
                                2
         | 
| 300 121 | 
             
                              ];
         | 
| @@ -0,0 +1,182 @@ | |
| 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 "node:path";
         | 
| 4 | 
            +
            import { ROUTE_SPEC_FILE, DEFAULT_SERVER_CONFIG, fs as fse, getInternalPlugins } from "@modern-js/utils";
         | 
| 5 | 
            +
            import { isMainEntry } from "../../../utils/routes";
         | 
| 6 | 
            +
            import { genPluginImportsCode, serverAppContenxtTemplate } from "../utils";
         | 
| 7 | 
            +
            import { handleDependencies } from "../dependencies";
         | 
| 8 | 
            +
            var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
         | 
| 9 | 
            +
              var appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverInternalPlugins = appContext.serverInternalPlugins, entrypoints = appContext.entrypoints;
         | 
| 10 | 
            +
              var plugins = getInternalPlugins(appDirectory, serverInternalPlugins);
         | 
| 11 | 
            +
              var netlifyOutput = path.join(appDirectory, ".netlify");
         | 
| 12 | 
            +
              var funcsDirectory = path.join(netlifyOutput, "functions");
         | 
| 13 | 
            +
              var entryFilePath = path.join(funcsDirectory, "index.js");
         | 
| 14 | 
            +
              return {
         | 
| 15 | 
            +
                prepare: function prepare() {
         | 
| 16 | 
            +
                  return _async_to_generator(function() {
         | 
| 17 | 
            +
                    return _ts_generator(this, function(_state) {
         | 
| 18 | 
            +
                      switch (_state.label) {
         | 
| 19 | 
            +
                        case 0:
         | 
| 20 | 
            +
                          return [
         | 
| 21 | 
            +
                            4,
         | 
| 22 | 
            +
                            fse.remove(netlifyOutput)
         | 
| 23 | 
            +
                          ];
         | 
| 24 | 
            +
                        case 1:
         | 
| 25 | 
            +
                          _state.sent();
         | 
| 26 | 
            +
                          return [
         | 
| 27 | 
            +
                            2
         | 
| 28 | 
            +
                          ];
         | 
| 29 | 
            +
                      }
         | 
| 30 | 
            +
                    });
         | 
| 31 | 
            +
                  })();
         | 
| 32 | 
            +
                },
         | 
| 33 | 
            +
                writeOutput: function writeOutput() {
         | 
| 34 | 
            +
                  return _async_to_generator(function() {
         | 
| 35 | 
            +
                    var routes, mainEntryName, redirectContent, redirectFilePath;
         | 
| 36 | 
            +
                    return _ts_generator(this, function(_state) {
         | 
| 37 | 
            +
                      switch (_state.label) {
         | 
| 38 | 
            +
                        case 0:
         | 
| 39 | 
            +
                          routes = [];
         | 
| 40 | 
            +
                          mainEntryName = modernConfig.source.mainEntryName;
         | 
| 41 | 
            +
                          if (!needModernServer) {
         | 
| 42 | 
            +
                            entrypoints.forEach(function(entry) {
         | 
| 43 | 
            +
                              var isMain = isMainEntry(entry.entryName, mainEntryName);
         | 
| 44 | 
            +
                              routes.push({
         | 
| 45 | 
            +
                                src: "/".concat(isMain ? "" : "".concat(entry.entryName, "/"), "*"),
         | 
| 46 | 
            +
                                dest: "/html/".concat(entry.entryName, "/index.html"),
         | 
| 47 | 
            +
                                status: 200
         | 
| 48 | 
            +
                              });
         | 
| 49 | 
            +
                            });
         | 
| 50 | 
            +
                          } else {
         | 
| 51 | 
            +
                            routes.push({
         | 
| 52 | 
            +
                              src: "/*",
         | 
| 53 | 
            +
                              dest: "/.netlify/functions/index",
         | 
| 54 | 
            +
                              status: 200
         | 
| 55 | 
            +
                            });
         | 
| 56 | 
            +
                          }
         | 
| 57 | 
            +
                          redirectContent = routes.map(function(route) {
         | 
| 58 | 
            +
                            return "".concat(route.src, " ").concat(route.dest, " ").concat(route.status);
         | 
| 59 | 
            +
                          }).join("\n");
         | 
| 60 | 
            +
                          if (!needModernServer)
         | 
| 61 | 
            +
                            return [
         | 
| 62 | 
            +
                              3,
         | 
| 63 | 
            +
                              4
         | 
| 64 | 
            +
                            ];
         | 
| 65 | 
            +
                          return [
         | 
| 66 | 
            +
                            4,
         | 
| 67 | 
            +
                            fse.ensureDir(funcsDirectory)
         | 
| 68 | 
            +
                          ];
         | 
| 69 | 
            +
                        case 1:
         | 
| 70 | 
            +
                          _state.sent();
         | 
| 71 | 
            +
                          return [
         | 
| 72 | 
            +
                            4,
         | 
| 73 | 
            +
                            fse.copy(distDirectory, funcsDirectory)
         | 
| 74 | 
            +
                          ];
         | 
| 75 | 
            +
                        case 2:
         | 
| 76 | 
            +
                          _state.sent();
         | 
| 77 | 
            +
                          return [
         | 
| 78 | 
            +
                            4,
         | 
| 79 | 
            +
                            fse.copy(distDirectory, funcsDirectory, {
         | 
| 80 | 
            +
                              filter: function(src) {
         | 
| 81 | 
            +
                                var distStaticDirectory = path.join(distDirectory, "static");
         | 
| 82 | 
            +
                                return !src.includes(distStaticDirectory);
         | 
| 83 | 
            +
                              }
         | 
| 84 | 
            +
                            })
         | 
| 85 | 
            +
                          ];
         | 
| 86 | 
            +
                        case 3:
         | 
| 87 | 
            +
                          _state.sent();
         | 
| 88 | 
            +
                          _state.label = 4;
         | 
| 89 | 
            +
                        case 4:
         | 
| 90 | 
            +
                          redirectFilePath = path.join(distDirectory, "_redirects");
         | 
| 91 | 
            +
                          return [
         | 
| 92 | 
            +
                            4,
         | 
| 93 | 
            +
                            fse.writeFile(redirectFilePath, redirectContent)
         | 
| 94 | 
            +
                          ];
         | 
| 95 | 
            +
                        case 5:
         | 
| 96 | 
            +
                          _state.sent();
         | 
| 97 | 
            +
                          return [
         | 
| 98 | 
            +
                            2
         | 
| 99 | 
            +
                          ];
         | 
| 100 | 
            +
                      }
         | 
| 101 | 
            +
                    });
         | 
| 102 | 
            +
                  })();
         | 
| 103 | 
            +
                },
         | 
| 104 | 
            +
                genEntry: function genEntry() {
         | 
| 105 | 
            +
                  return _async_to_generator(function() {
         | 
| 106 | 
            +
                    var _modernConfig_bff, serverConfig, pluginImportCode, dynamicProdOptions, entryCode, serverAppContext;
         | 
| 107 | 
            +
                    return _ts_generator(this, function(_state) {
         | 
| 108 | 
            +
                      switch (_state.label) {
         | 
| 109 | 
            +
                        case 0:
         | 
| 110 | 
            +
                          if (!needModernServer) {
         | 
| 111 | 
            +
                            return [
         | 
| 112 | 
            +
                              2
         | 
| 113 | 
            +
                            ];
         | 
| 114 | 
            +
                          }
         | 
| 115 | 
            +
                          serverConfig = {
         | 
| 116 | 
            +
                            bff: {
         | 
| 117 | 
            +
                              prefix: modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_bff = modernConfig.bff) === null || _modernConfig_bff === void 0 ? void 0 : _modernConfig_bff.prefix
         | 
| 118 | 
            +
                            },
         | 
| 119 | 
            +
                            output: {
         | 
| 120 | 
            +
                              path: "."
         | 
| 121 | 
            +
                            }
         | 
| 122 | 
            +
                          };
         | 
| 123 | 
            +
                          pluginImportCode = genPluginImportsCode(plugins || []);
         | 
| 124 | 
            +
                          dynamicProdOptions = {
         | 
| 125 | 
            +
                            config: serverConfig,
         | 
| 126 | 
            +
                            serverConfigFile: DEFAULT_SERVER_CONFIG,
         | 
| 127 | 
            +
                            plugins
         | 
| 128 | 
            +
                          };
         | 
| 129 | 
            +
                          return [
         | 
| 130 | 
            +
                            4,
         | 
| 131 | 
            +
                            fse.readFile(path.join(__dirname, "./netlifyEntry.js"))
         | 
| 132 | 
            +
                          ];
         | 
| 133 | 
            +
                        case 1:
         | 
| 134 | 
            +
                          entryCode = _state.sent().toString();
         | 
| 135 | 
            +
                          serverAppContext = serverAppContenxtTemplate(appContext);
         | 
| 136 | 
            +
                          entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
         | 
| 137 | 
            +
                          return [
         | 
| 138 | 
            +
                            4,
         | 
| 139 | 
            +
                            fse.writeFile(entryFilePath, entryCode)
         | 
| 140 | 
            +
                          ];
         | 
| 141 | 
            +
                        case 2:
         | 
| 142 | 
            +
                          _state.sent();
         | 
| 143 | 
            +
                          return [
         | 
| 144 | 
            +
                            2
         | 
| 145 | 
            +
                          ];
         | 
| 146 | 
            +
                      }
         | 
| 147 | 
            +
                    });
         | 
| 148 | 
            +
                  })();
         | 
| 149 | 
            +
                },
         | 
| 150 | 
            +
                end: function end() {
         | 
| 151 | 
            +
                  return _async_to_generator(function() {
         | 
| 152 | 
            +
                    var netlifyNodeModules;
         | 
| 153 | 
            +
                    return _ts_generator(this, function(_state) {
         | 
| 154 | 
            +
                      switch (_state.label) {
         | 
| 155 | 
            +
                        case 0:
         | 
| 156 | 
            +
                          return [
         | 
| 157 | 
            +
                            4,
         | 
| 158 | 
            +
                            handleDependencies(appDirectory, funcsDirectory, [
         | 
| 159 | 
            +
                              "@modern-js/prod-server"
         | 
| 160 | 
            +
                            ])
         | 
| 161 | 
            +
                          ];
         | 
| 162 | 
            +
                        case 1:
         | 
| 163 | 
            +
                          _state.sent();
         | 
| 164 | 
            +
                          netlifyNodeModules = path.join(netlifyOutput, "node_modules");
         | 
| 165 | 
            +
                          return [
         | 
| 166 | 
            +
                            4,
         | 
| 167 | 
            +
                            fse.move(path.join(funcsDirectory, "node_modules"), netlifyNodeModules)
         | 
| 168 | 
            +
                          ];
         | 
| 169 | 
            +
                        case 2:
         | 
| 170 | 
            +
                          _state.sent();
         | 
| 171 | 
            +
                          return [
         | 
| 172 | 
            +
                            2
         | 
| 173 | 
            +
                          ];
         | 
| 174 | 
            +
                      }
         | 
| 175 | 
            +
                    });
         | 
| 176 | 
            +
                  })();
         | 
| 177 | 
            +
                }
         | 
| 178 | 
            +
              };
         | 
| 179 | 
            +
            };
         | 
| 180 | 
            +
            export {
         | 
| 181 | 
            +
              createNetlifyPreset
         | 
| 182 | 
            +
            };
         |