@modern-js/plugin-server 0.0.0-nightly-20231226170639 → 0.0.0-nightly-20231228170609

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/cli.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
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
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var cli_exports = {};
20
30
  __export(cli_exports, {
@@ -22,9 +32,19 @@ __export(cli_exports, {
22
32
  serverPlugin: () => serverPlugin
23
33
  });
24
34
  module.exports = __toCommonJS(cli_exports);
35
+ var import_path = __toESM(require("path"));
36
+ var import_fs_extra = __toESM(require("@modern-js/utils/fs-extra"));
37
+ var import_utils = require("@modern-js/utils");
38
+ var import_server_utils = require("@modern-js/server-utils");
39
+ function checkHasCache(appDir) {
40
+ const tsFilepath = import_path.default.resolve(appDir, "server", "cache.ts");
41
+ const jsfilepath = import_path.default.resolve(appDir, "server", "cache.js");
42
+ return import_fs_extra.default.existsSync(tsFilepath) || import_fs_extra.default.existsSync(jsfilepath);
43
+ }
44
+ const TS_CONFIG_FILENAME = "tsconfig.json";
25
45
  const serverPlugin = () => ({
26
46
  name: "@modern-js/plugin-server",
27
- setup: (_) => ({
47
+ setup: (api) => ({
28
48
  collectServerPlugins({ plugins }) {
29
49
  plugins.push({
30
50
  "@modern-js/plugin-server": "@modern-js/plugin-server/server"
@@ -32,6 +52,38 @@ const serverPlugin = () => ({
32
52
  return {
33
53
  plugins
34
54
  };
55
+ },
56
+ async afterBuild() {
57
+ const { appDirectory, distDirectory } = api.useAppContext();
58
+ if (checkHasCache(appDirectory)) {
59
+ return;
60
+ }
61
+ const modernConfig = api.useResolvedConfigContext();
62
+ const distDir = import_path.default.resolve(distDirectory);
63
+ const serverDir = import_path.default.resolve(appDirectory, import_utils.SERVER_DIR);
64
+ const sharedDir = import_path.default.resolve(appDirectory, import_utils.SHARED_DIR);
65
+ const tsconfigPath = import_path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
66
+ const sourceDirs = [];
67
+ if (import_fs_extra.default.existsSync(serverDir)) {
68
+ sourceDirs.push(serverDir);
69
+ if (import_fs_extra.default.existsSync(sharedDir)) {
70
+ sourceDirs.push(sharedDir);
71
+ }
72
+ }
73
+ const { server } = modernConfig;
74
+ const { alias } = modernConfig.source;
75
+ const { babel } = modernConfig.tools;
76
+ if (sourceDirs.length > 0) {
77
+ await (0, import_server_utils.compile)(appDirectory, {
78
+ server,
79
+ alias,
80
+ babelConfig: babel
81
+ }, {
82
+ sourceDirs,
83
+ distDir,
84
+ tsconfigPath
85
+ });
86
+ }
35
87
  }
36
88
  })
37
89
  });
package/dist/esm/cli.js CHANGED
@@ -1,7 +1,19 @@
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 from "@modern-js/utils/fs-extra";
5
+ import { SERVER_DIR, SHARED_DIR } from "@modern-js/utils";
6
+ import { compile } from "@modern-js/server-utils";
7
+ function checkHasCache(appDir) {
8
+ var tsFilepath = path.resolve(appDir, "server", "cache.ts");
9
+ var jsfilepath = path.resolve(appDir, "server", "cache.js");
10
+ return fs.existsSync(tsFilepath) || fs.existsSync(jsfilepath);
11
+ }
12
+ var TS_CONFIG_FILENAME = "tsconfig.json";
1
13
  var serverPlugin = function() {
2
14
  return {
3
15
  name: "@modern-js/plugin-server",
4
- setup: function(_) {
16
+ setup: function(api) {
5
17
  return {
6
18
  collectServerPlugins: function collectServerPlugins(param) {
7
19
  var plugins = param.plugins;
@@ -11,6 +23,61 @@ var serverPlugin = function() {
11
23
  return {
12
24
  plugins
13
25
  };
26
+ },
27
+ afterBuild: function afterBuild() {
28
+ return _async_to_generator(function() {
29
+ var _api_useAppContext, appDirectory, distDirectory, modernConfig, distDir, serverDir, sharedDir, tsconfigPath, sourceDirs, server, alias, babel;
30
+ return _ts_generator(this, function(_state) {
31
+ switch (_state.label) {
32
+ case 0:
33
+ _api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory;
34
+ if (checkHasCache(appDirectory)) {
35
+ return [
36
+ 2
37
+ ];
38
+ }
39
+ modernConfig = api.useResolvedConfigContext();
40
+ distDir = path.resolve(distDirectory);
41
+ serverDir = path.resolve(appDirectory, SERVER_DIR);
42
+ sharedDir = path.resolve(appDirectory, SHARED_DIR);
43
+ tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
44
+ sourceDirs = [];
45
+ if (fs.existsSync(serverDir)) {
46
+ sourceDirs.push(serverDir);
47
+ if (fs.existsSync(sharedDir)) {
48
+ sourceDirs.push(sharedDir);
49
+ }
50
+ }
51
+ server = modernConfig.server;
52
+ alias = modernConfig.source.alias;
53
+ babel = modernConfig.tools.babel;
54
+ if (!(sourceDirs.length > 0))
55
+ return [
56
+ 3,
57
+ 2
58
+ ];
59
+ return [
60
+ 4,
61
+ compile(appDirectory, {
62
+ server,
63
+ alias,
64
+ babelConfig: babel
65
+ }, {
66
+ sourceDirs,
67
+ distDir,
68
+ tsconfigPath
69
+ })
70
+ ];
71
+ case 1:
72
+ _state.sent();
73
+ _state.label = 2;
74
+ case 2:
75
+ return [
76
+ 2
77
+ ];
78
+ }
79
+ });
80
+ })();
14
81
  }
15
82
  };
16
83
  }
@@ -1,6 +1,16 @@
1
+ import path from "path";
2
+ import fs from "@modern-js/utils/fs-extra";
3
+ import { SERVER_DIR, SHARED_DIR } from "@modern-js/utils";
4
+ import { compile } from "@modern-js/server-utils";
5
+ function checkHasCache(appDir) {
6
+ const tsFilepath = path.resolve(appDir, "server", "cache.ts");
7
+ const jsfilepath = path.resolve(appDir, "server", "cache.js");
8
+ return fs.existsSync(tsFilepath) || fs.existsSync(jsfilepath);
9
+ }
10
+ const TS_CONFIG_FILENAME = "tsconfig.json";
1
11
  const serverPlugin = () => ({
2
12
  name: "@modern-js/plugin-server",
3
- setup: (_) => ({
13
+ setup: (api) => ({
4
14
  collectServerPlugins({ plugins }) {
5
15
  plugins.push({
6
16
  "@modern-js/plugin-server": "@modern-js/plugin-server/server"
@@ -8,6 +18,38 @@ const serverPlugin = () => ({
8
18
  return {
9
19
  plugins
10
20
  };
21
+ },
22
+ async afterBuild() {
23
+ const { appDirectory, distDirectory } = api.useAppContext();
24
+ if (checkHasCache(appDirectory)) {
25
+ return;
26
+ }
27
+ const modernConfig = api.useResolvedConfigContext();
28
+ const distDir = path.resolve(distDirectory);
29
+ const serverDir = path.resolve(appDirectory, SERVER_DIR);
30
+ const sharedDir = path.resolve(appDirectory, SHARED_DIR);
31
+ const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
32
+ const sourceDirs = [];
33
+ if (fs.existsSync(serverDir)) {
34
+ sourceDirs.push(serverDir);
35
+ if (fs.existsSync(sharedDir)) {
36
+ sourceDirs.push(sharedDir);
37
+ }
38
+ }
39
+ const { server } = modernConfig;
40
+ const { alias } = modernConfig.source;
41
+ const { babel } = modernConfig.tools;
42
+ if (sourceDirs.length > 0) {
43
+ await compile(appDirectory, {
44
+ server,
45
+ alias,
46
+ babelConfig: babel
47
+ }, {
48
+ sourceDirs,
49
+ distDir,
50
+ tsconfigPath
51
+ });
52
+ }
11
53
  }
12
54
  })
13
55
  });
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "0.0.0-nightly-20231226170639",
18
+ "version": "0.0.0-nightly-20231228170609",
19
19
  "types": "./dist/types/cli.d.ts",
20
20
  "jsnext:source": "./src/cli",
21
21
  "main": "./dist/cjs/cli.js",
@@ -51,19 +51,20 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@swc/helpers": "0.5.3",
54
- "@modern-js/utils": "0.0.0-nightly-20231226170639"
54
+ "@modern-js/utils": "0.0.0-nightly-20231228170609",
55
+ "@modern-js/server-utils": "0.0.0-nightly-20231228170609"
55
56
  },
56
57
  "devDependencies": {
57
58
  "typescript": "^5",
58
59
  "@types/jest": "^29",
59
60
  "@types/node": "^14",
60
61
  "jest": "^29",
61
- "@modern-js/server-core": "0.0.0-nightly-20231226170639",
62
- "@modern-js/app-tools": "0.0.0-nightly-20231226170639",
63
- "@modern-js/core": "0.0.0-nightly-20231226170639",
64
- "@scripts/build": "0.0.0-nightly-20231226170639",
65
- "@modern-js/types": "0.0.0-nightly-20231226170639",
66
- "@scripts/jest-config": "0.0.0-nightly-20231226170639"
62
+ "@modern-js/server-core": "0.0.0-nightly-20231228170609",
63
+ "@modern-js/app-tools": "0.0.0-nightly-20231228170609",
64
+ "@modern-js/core": "0.0.0-nightly-20231228170609",
65
+ "@scripts/build": "0.0.0-nightly-20231228170609",
66
+ "@modern-js/types": "0.0.0-nightly-20231228170609",
67
+ "@scripts/jest-config": "0.0.0-nightly-20231228170609"
67
68
  },
68
69
  "sideEffects": [
69
70
  "*.css",