@modern-js/server-core 1.3.4 → 1.4.0-alpha.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # @modern-js/server-plugin
2
2
 
3
+ ## 1.4.0-alpha.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 77a8e9e1b: feat: support bff operators
8
+
9
+ ### Patch Changes
10
+
11
+ - f29e9bacf: feat: simplify context usage, no longer depend on containers
12
+ - a90bc96bd: perf(babel): skip babel-plugin-import if package not installed
13
+ - Updated dependencies [9cd364e06]
14
+ - Updated dependencies [f29e9bacf]
15
+ - Updated dependencies [a90bc96bd]
16
+ - @modern-js/utils@1.7.9-alpha.0
17
+ - @modern-js/plugin@1.4.0-alpha.0
18
+
19
+ ## 1.3.5
20
+
21
+ ### Patch Changes
22
+
23
+ - d32f35134: chore: add modern/jest/eslint/ts config files to .npmignore
24
+ - Updated dependencies [d5913bd96]
25
+ - Updated dependencies [d32f35134]
26
+ - Updated dependencies [6ae4a34ae]
27
+ - Updated dependencies [b80229c79]
28
+ - Updated dependencies [948cc4436]
29
+ - @modern-js/plugin@1.3.4
30
+ - @modern-js/utils@1.7.3
31
+
3
32
  ## 1.3.4
4
33
 
5
34
  ### Patch Changes
@@ -4,28 +4,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { compatRequire } from '@modern-js/utils';
7
+ import { compatRequire, tryResolve } from '@modern-js/utils';
8
8
  import { createPlugin } from "./plugin";
9
-
10
- const tryResolve = (name, appDirectory) => {
11
- let filePath = '';
12
-
13
- try {
14
- filePath = require.resolve(name, {
15
- paths: [appDirectory]
16
- });
17
- delete require.cache[filePath];
18
- } catch (err) {
19
- if (err.code === 'MODULE_NOT_FOUND') {
20
- throw new Error(`Can not find plugin ${name}.`);
21
- }
22
-
23
- throw err;
24
- }
25
-
26
- return filePath;
27
- };
28
-
29
9
  export const loadPlugins = (plugins, appDirectory) => {
30
10
  const resolvePlugin = p => {
31
11
  const isPluginInstance = typeof p !== 'string' && !Array.isArray(p);
@@ -1,7 +1,5 @@
1
1
  import { createContext, createAsyncManager, createAsyncPipeline, createAsyncWaterfall, createParallelWorkflow, createWaterfall } from '@modern-js/plugin';
2
- import { enable } from '@modern-js/plugin/node';
3
- enable(); // collect all middleware register in server plugins
4
-
2
+ // collect all middleware register in server plugins
5
3
  const gather = createParallelWorkflow();
6
4
  // config
7
5
  const config = createWaterfall();
@@ -35,6 +33,7 @@ const beforeSend = createAsyncPipeline();
35
33
  const afterSend = createParallelWorkflow();
36
34
  const reset = createParallelWorkflow();
37
35
  export const AppContext = createContext({});
36
+ export const setAppContext = value => AppContext.set(value);
38
37
  export const ConfigContext = createContext({});
39
38
  /**
40
39
  * Get original content of user config.
@@ -48,7 +47,8 @@ export const useConfigContext = () => ConfigContext.use().value;
48
47
  export const useAppContext = () => AppContext.use().value;
49
48
  const pluginAPI = {
50
49
  useAppContext,
51
- useConfigContext
50
+ useConfigContext,
51
+ setAppContext
52
52
  };
53
53
  const serverHooks = {
54
54
  // server hook
@@ -15,25 +15,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
15
15
 
16
16
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
17
 
18
- const tryResolve = (name, appDirectory) => {
19
- let filePath = '';
20
-
21
- try {
22
- filePath = require.resolve(name, {
23
- paths: [appDirectory]
24
- });
25
- delete require.cache[filePath];
26
- } catch (err) {
27
- if (err.code === 'MODULE_NOT_FOUND') {
28
- throw new Error(`Can not find plugin ${name}.`);
29
- }
30
-
31
- throw err;
32
- }
33
-
34
- return filePath;
35
- };
36
-
37
18
  const loadPlugins = (plugins, appDirectory) => {
38
19
  const resolvePlugin = p => {
39
20
  const isPluginInstance = typeof p !== 'string' && !Array.isArray(p);
@@ -45,7 +26,7 @@ const loadPlugins = (plugins, appDirectory) => {
45
26
  }
46
27
 
47
28
  const [pkg, options] = typeof p === 'string' ? [p, undefined] : p;
48
- const pluginPath = tryResolve(pkg, appDirectory);
29
+ const pluginPath = (0, _utils.tryResolve)(pkg, appDirectory);
49
30
  let module = (0, _utils.compatRequire)(pluginPath);
50
31
  const useNewSyntax = typeof module === 'function';
51
32
 
@@ -3,14 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useConfigContext = exports.useAppContext = exports.serverManager = exports.createServerManager = exports.createPlugin = exports.ConfigContext = exports.AppContext = void 0;
6
+ exports.useConfigContext = exports.useAppContext = exports.setAppContext = exports.serverManager = exports.createServerManager = exports.createPlugin = exports.ConfigContext = exports.AppContext = void 0;
7
7
 
8
8
  var _plugin = require("@modern-js/plugin");
9
9
 
10
- var _node = require("@modern-js/plugin/node");
11
-
12
- (0, _node.enable)(); // collect all middleware register in server plugins
13
-
10
+ // collect all middleware register in server plugins
14
11
  const gather = (0, _plugin.createParallelWorkflow)();
15
12
  // config
16
13
  const config = (0, _plugin.createWaterfall)();
@@ -45,6 +42,10 @@ const afterSend = (0, _plugin.createParallelWorkflow)();
45
42
  const reset = (0, _plugin.createParallelWorkflow)();
46
43
  const AppContext = (0, _plugin.createContext)({});
47
44
  exports.AppContext = AppContext;
45
+
46
+ const setAppContext = value => AppContext.set(value);
47
+
48
+ exports.setAppContext = setAppContext;
48
49
  const ConfigContext = (0, _plugin.createContext)({});
49
50
  /**
50
51
  * Get original content of user config.
@@ -65,7 +66,8 @@ const useAppContext = () => AppContext.use().value;
65
66
  exports.useAppContext = useAppContext;
66
67
  const pluginAPI = {
67
68
  useAppContext,
68
- useConfigContext
69
+ useConfigContext,
70
+ setAppContext
69
71
  };
70
72
  const serverHooks = {
71
73
  // server hook
@@ -34,6 +34,7 @@ export declare type RequestResult = {
34
34
  export declare type SSRServerContext = Record<string, unknown>;
35
35
  export declare type RenderContext = Record<string, unknown>;
36
36
  export declare const AppContext: import("@modern-js/plugin").Context<ISAppContext>;
37
+ export declare const setAppContext: (value: ISAppContext) => void;
37
38
  export declare const ConfigContext: import("@modern-js/plugin").Context<UserConfig>;
38
39
  /**
39
40
  * Get original content of user config.
@@ -48,6 +49,7 @@ export declare const useAppContext: () => ISAppContext;
48
49
  declare const pluginAPI: {
49
50
  useAppContext: () => ISAppContext;
50
51
  useConfigContext: () => UserConfig;
52
+ setAppContext: (value: ISAppContext) => void;
51
53
  };
52
54
  declare const serverHooks: {
53
55
  gather: import("@modern-js/plugin").ParallelWorkflow<{
@@ -170,6 +172,7 @@ export declare const createServerManager: () => import("@modern-js/plugin").Asyn
170
172
  }, {
171
173
  useAppContext: () => ISAppContext;
172
174
  useConfigContext: () => UserConfig;
175
+ setAppContext: (value: ISAppContext) => void;
173
176
  }>;
174
177
  export declare const serverManager: import("@modern-js/plugin").AsyncManager<{
175
178
  gather: import("@modern-js/plugin").ParallelWorkflow<{
@@ -228,6 +231,7 @@ export declare const serverManager: import("@modern-js/plugin").AsyncManager<{
228
231
  }, {
229
232
  useAppContext: () => ISAppContext;
230
233
  useConfigContext: () => UserConfig;
234
+ setAppContext: (value: ISAppContext) => void;
231
235
  }>;
232
236
  /** Plugin options of a server plugin. */
233
237
 
@@ -295,6 +299,7 @@ export declare const createPlugin: (setup?: AsyncSetup<{
295
299
  }, {
296
300
  useAppContext: () => ISAppContext;
297
301
  useConfigContext: () => UserConfig;
302
+ setAppContext: (value: ISAppContext) => void;
298
303
  }> | undefined, options?: PluginOptions<{
299
304
  gather: import("@modern-js/plugin").ParallelWorkflow<{
300
305
  addWebMiddleware: (_input: any) => void;
@@ -406,6 +411,7 @@ export declare const createPlugin: (setup?: AsyncSetup<{
406
411
  }, {
407
412
  useAppContext: () => ISAppContext;
408
413
  useConfigContext: () => UserConfig;
414
+ setAppContext: (value: ISAppContext) => void;
409
415
  }>> | undefined) => import("@modern-js/plugin").AsyncPlugin<{
410
416
  gather: import("@modern-js/plugin").ParallelWorkflow<{
411
417
  addWebMiddleware: (_input: any) => void;
@@ -463,5 +469,6 @@ export declare const createPlugin: (setup?: AsyncSetup<{
463
469
  }, {
464
470
  useAppContext: () => ISAppContext;
465
471
  useConfigContext: () => UserConfig;
472
+ setAppContext: (value: ISAppContext) => void;
466
473
  }>;
467
474
  export {};
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.3.4",
14
+ "version": "1.4.0-alpha.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -28,15 +28,15 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@modern-js/plugin": "^1.3.3",
32
- "@modern-js/utils": "^1.7.2"
31
+ "@modern-js/plugin": "^1.4.0-alpha.0",
32
+ "@modern-js/utils": "^1.7.9-alpha.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@modern-js/core": "1.10.1",
36
- "@modern-js/types": "1.5.2",
35
+ "@modern-js/core": "1.12.2-alpha.0",
36
+ "@modern-js/types": "1.5.5-alpha.0",
37
37
  "@scripts/build": "0.0.0",
38
38
  "@scripts/jest-config": "0.0.0",
39
- "@types/jest": "^26",
39
+ "@types/jest": "^27",
40
40
  "@types/node": "^14",
41
41
  "@types/react": "^17",
42
42
  "@types/react-dom": "^17",
@@ -55,10 +55,33 @@
55
55
  "registry": "https://registry.npmjs.org/",
56
56
  "access": "public"
57
57
  },
58
+ "wireit": {
59
+ "build": {
60
+ "command": "modern build",
61
+ "files": [
62
+ "src/**/*",
63
+ "tsconfig.json",
64
+ "package.json"
65
+ ],
66
+ "output": [
67
+ "dist/**/*"
68
+ ]
69
+ },
70
+ "test": {
71
+ "command": "jest --passWithNoTests",
72
+ "files": [
73
+ "src/**/*",
74
+ "tsconfig.json",
75
+ "package.json",
76
+ "tests/**/*"
77
+ ],
78
+ "output": []
79
+ }
80
+ },
58
81
  "scripts": {
59
82
  "new": "modern new",
60
- "build": "modern build",
61
- "test": "jest --passWithNoTests"
83
+ "build": "wireit",
84
+ "test": "wireit"
62
85
  },
63
86
  "readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
64
87
  }
package/.eslintrc.js DELETED
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- extends: ['@modern-js'],
3
- parserOptions: {
4
- project: require.resolve('./tsconfig.json'),
5
- },
6
- };
package/jest.config.js DELETED
@@ -1,7 +0,0 @@
1
- const sharedConfig = require('@scripts/jest-config');
2
-
3
- /** @type {import('@jest/types').Config.InitialOptions} */
4
- module.exports = {
5
- ...sharedConfig,
6
- rootDir: __dirname,
7
- };
package/modern.config.js DELETED
@@ -1,2 +0,0 @@
1
- /** @type {import('@modern-js/module-tools').UserConfig} */
2
- module.exports = {};
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "@modern-js/tsconfig/base",
3
- "compilerOptions": {
4
- "declaration": false,
5
- "jsx": "preserve",
6
- "baseUrl": "./",
7
- "isolatedModules": true,
8
- "paths": {},
9
- "types": ["node", "jest"]
10
- },
11
- "include": ["src"]
12
- }