@modern-js/prod-server 1.1.0 → 1.1.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.
package/.eslintrc.js ADDED
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ['@modern-js'],
4
+ parserOptions: {
5
+ tsconfigRootDir: __dirname,
6
+ project: ['./tsconfig.json'],
7
+ },
8
+ };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @modern-js/prod-server
2
2
 
3
+ ## 1.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 6cffe99d: chore:
8
+ remove react eslint rules for `modern-js` rule set.
9
+ add .eslintrc for each package to speed up linting
10
+ - 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
11
+ - 60f7d8bf: feat: add tests dir to npmignore
12
+ - Updated dependencies [b8599d09]
13
+ - Updated dependencies [04ae5262]
14
+ - Updated dependencies [60f7d8bf]
15
+ - Updated dependencies [3bf4f8b0]
16
+ - @modern-js/utils@1.5.0
17
+ - @modern-js/server-core@1.3.1
18
+
3
19
  ## 1.1.0
4
20
 
5
21
  ### Minor Changes
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.0",
14
+ "version": "1.1.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -28,9 +28,9 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@modern-js/utils": "^1.4.0",
31
+ "@modern-js/utils": "^1.5.0",
32
32
  "@babel/compat-data": "^7.17.0",
33
- "@modern-js/server-core": "^1.3.0",
33
+ "@modern-js/server-core": "^1.3.1",
34
34
  "axios": "^0.24.0",
35
35
  "compare-versions": "^3.6.0",
36
36
  "cookie": "^0.4.2",
@@ -45,8 +45,8 @@
45
45
  "ua-parser-js": "^0.7.28"
46
46
  },
47
47
  "devDependencies": {
48
- "@modern-js/types": "^1.4.0",
49
- "@modern-js/core": "1.7.0",
48
+ "@modern-js/types": "^1.5.0",
49
+ "@modern-js/core": "1.8.0",
50
50
  "@scripts/jest-config": "0.0.0",
51
51
  "@scripts/build": "0.0.0",
52
52
  "@types/cookie": "^0.4.1",
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- extends: ['@modern-js'],
3
- parserOptions: {
4
- project: require.resolve('./tsconfig.json'),
5
- },
6
- };
@@ -1,52 +0,0 @@
1
- import EventEmitter from 'events';
2
- import { Readable } from 'stream';
3
- import httpMocks from 'node-mocks-http';
4
- import { createContext } from '../src/libs/context';
5
-
6
- describe('test server context', () => {
7
- test('should route api work correctly', () => {
8
- const req = httpMocks.createRequest({
9
- url: '/pathname?foo=baz',
10
- headers: {
11
- host: 'modernjs.com',
12
- },
13
- eventEmitter: Readable,
14
- method: 'GET',
15
- });
16
- const res = httpMocks.createResponse({ eventEmitter: EventEmitter });
17
- const context = createContext(req, res);
18
- const {
19
- method,
20
- url,
21
- origin,
22
- host,
23
- path,
24
- href,
25
- query,
26
- querystring,
27
- protocol,
28
- params,
29
- } = context;
30
-
31
- expect(method).toBe('GET');
32
- expect(url).toBe('/pathname?foo=baz');
33
- expect(origin).toBe('http://modernjs.com');
34
- expect(host).toBe('modernjs.com');
35
- expect(path).toBe('/pathname');
36
- expect(href).toBe('http://modernjs.com/pathname?foo=baz');
37
- expect(query).toEqual({ foo: 'baz' });
38
- expect(querystring).toBe('foo=baz');
39
- expect(protocol).toBe('http');
40
- expect(params).toEqual({});
41
-
42
- expect(context.serverData).toEqual({});
43
- context.setServerData('foo', {
44
- name: 'foo',
45
- });
46
- expect(context.serverData).toEqual({
47
- foo: {
48
- name: 'foo',
49
- },
50
- });
51
- });
52
- });
@@ -1 +0,0 @@
1
- console.info('index.js');
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- server: {
3
- ssr: true,
4
- },
5
- };
@@ -1,21 +0,0 @@
1
- {
2
- "name": "prod-server-pure",
3
- "version": "0.1.0",
4
- "scripts": {
5
- "reset": "del-cli node_modules",
6
- "dev": "modern dev",
7
- "build": "modern build",
8
- "start": "modern start",
9
- "new": "modern new",
10
- "lint": "modern lint",
11
- "deploy": "modern deploy"
12
- },
13
- "dependencies": {},
14
- "devDependencies": {},
15
- "modernConfig": {
16
- "runtime": {
17
- "router": true,
18
- "state": true
19
- }
20
- }
21
- }
@@ -1,119 +0,0 @@
1
- html,
2
- body {
3
- padding: 0;
4
- margin: 0;
5
- font-family: nunito_for_arco, Helvetica Neue, Helvetica, PingFang SC,
6
- Hiragino Sans GB, Microsoft YaHei, 微软雅黑, Arial, sans-serif;
7
- }
8
-
9
- * {
10
- -webkit-font-smoothing: antialiased;
11
- -moz-osx-font-smoothing: grayscale;
12
- box-sizing: border-box;
13
- }
14
-
15
- .container {
16
- min-height: 100vh;
17
- max-width: 100%;
18
- display: flex;
19
- flex-direction: column;
20
- justify-content: center;
21
- align-items: center;
22
- }
23
-
24
- main {
25
- padding: 5rem 0;
26
- flex: 1;
27
- display: flex;
28
- flex-direction: column;
29
- justify-content: center;
30
- align-items: center;
31
- }
32
-
33
- .footer {
34
- width: 100%;
35
- height: 80px;
36
- border-top: 1px solid #eaeaea;
37
- display: flex;
38
- justify-content: center;
39
- align-items: center;
40
- background-color: #470000;
41
- }
42
-
43
- .footer a {
44
- display: flex;
45
- justify-content: center;
46
- align-items: center;
47
- flex-grow: 1;
48
- color: #f4f4f4;
49
- text-decoration: none;
50
- font-size: 1.1rem;
51
- }
52
-
53
- .logo {
54
- margin-bottom: 2rem;
55
- }
56
-
57
- .logo svg {
58
- width: 450px;
59
- height: 132px;
60
- }
61
-
62
- .description {
63
- text-align: center;
64
- line-height: 1.5;
65
- font-size: 1.5rem;
66
- }
67
-
68
- .code {
69
- background: #fafafa;
70
- border-radius: 5px;
71
- padding: 0.75rem;
72
- font-size: 1.1rem;
73
- font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
74
- Bitstream Vera Sans Mono, Courier New, monospace;
75
- }
76
-
77
- @media (max-width: 600px) {
78
- .grid {
79
- width: 100%;
80
- flex-direction: column;
81
- }
82
- }
83
-
84
- .grid {
85
- display: flex;
86
- align-items: center;
87
- justify-content: center;
88
- flex-wrap: wrap;
89
- width: 800px;
90
- margin-top: 3rem;
91
- }
92
-
93
- .card {
94
- margin: 1rem;
95
- padding: 1.5rem;
96
- display: flex;
97
- align-items: center;
98
- justify-content: center;
99
- height: 100px;
100
- color: inherit;
101
- text-decoration: none;
102
- border: 1px solid #470000;
103
- color: #470000;
104
- transition: color 0.15s ease, border-color 0.15s ease;
105
- width: 45%;
106
- }
107
-
108
- .card:hover,
109
- .card:focus,
110
- .card:active {
111
- transform: scale(1.05);
112
- transition: 0.1s ease-in-out;
113
- }
114
-
115
- .card h2 {
116
- font-size: 1.5rem;
117
- margin: 0;
118
- padding: 0;
119
- }
@@ -1,43 +0,0 @@
1
- import './App.css';
2
-
3
- const App = () => (
4
- <div className="container">
5
- <main>
6
- <div className="logo">
7
- <img
8
- src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png"
9
- width="300"
10
- alt="Modern.js Logo"
11
- />
12
- </div>
13
- <p className="description">
14
- Get started by editing <code className="code">src/home/App.tsx</code>
15
- </p>
16
- <div className="grid">
17
- <a href="https://modernjs.dev/docs/start" className="card">
18
- <h2>Quick Start Tencent</h2>
19
- </a>
20
- <a href="https://modernjs.dev/docs/guides" className="card">
21
- <h2>Handbook</h2>
22
- </a>
23
- <a href="https://modernjs.dev/docs/apis" className="card">
24
- <h2>API Reference </h2>
25
- </a>
26
- <a
27
- href="https://modernjs.dev/coming-soon"
28
- target="_blank"
29
- rel="noopener noreferrer"
30
- className="card">
31
- <h2>Community </h2>
32
- </a>
33
- </div>
34
- </main>
35
- <footer className="footer">
36
- <a href="https://modernjs.dev" target="_blank" rel="noopener noreferrer">
37
- Powered by Modern.js
38
- </a>
39
- </footer>
40
- </div>
41
- );
42
-
43
- export default App;
@@ -1,5 +0,0 @@
1
- const { SERVER_RENDER_FUNCTION_NAME } = require('@modern-js/utils');
2
-
3
- module.exports = {
4
- [SERVER_RENDER_FUNCTION_NAME]: () => '<div>Modern.js</div>',
5
- };
@@ -1,36 +0,0 @@
1
-
2
- <!DOCTYPE html>
3
- <html>
4
- <head>
5
-
6
- <meta charset="utf-8">
7
- <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no, viewport-fit=cover, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
8
- <meta http-equiv="x-ua-compatible" content="ie=edge">
9
- <meta name="renderer" content="webkit">
10
- <meta name="layoutmode" content="standard">
11
- <meta name="imagemode" content="force">
12
- <meta name="wap-font-scale" content="no">
13
- <meta name="format-detection" content="telephone=no">
14
- <title></title>
15
-
16
-
17
-
18
- <script>
19
- window.__assetPrefix__ = '';
20
- </script>
21
-
22
- <script defer src="/static/js/runtime-main.js"></script><script defer src="/static/js/vendors-node_modules_pnpm_babel_runtime_7_16_7_node_modules_babel_runtime_regenerator_index_j-7f9278.js"></script><script defer src="/static/js/main.js"></script></head>
23
-
24
- <body>
25
- <!--<?- chunksMap.css ?>-->
26
- <noscript>
27
- We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.
28
- </noscript>
29
- <div id="root"><!--<?- html ?>--></div>
30
-
31
- <!--<?- chunksMap.js ?>-->
32
- <!--<?- SSRDataScript ?>-->
33
-
34
- </body>
35
-
36
- </html>
@@ -1,31 +0,0 @@
1
- {
2
- "routes": [
3
- {
4
- "urlPath": "/",
5
- "entryName": "main",
6
- "entryPath": "html/main/index.html",
7
- "isSPA": true,
8
- "isSSR": true,
9
- "enableModernMode": false,
10
- "bundle": "bundles/main.js"
11
- },
12
- {
13
- "urlPath": "/500",
14
- "entryName": "500",
15
- "entryPath": "html/main/index.html",
16
- "isSPA": true,
17
- "isSSR": true,
18
- "enableModernMode": false,
19
- "bundle": "bundles/main.js"
20
- },
21
- {
22
- "urlPath": "/404",
23
- "entryName": "500",
24
- "entryPath": "html/main/index.html",
25
- "isSPA": true,
26
- "isSSR": true,
27
- "enableModernMode": false,
28
- "bundle": "bundles/main.js"
29
- }
30
- ]
31
- }
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "@modern-js/tsconfig/base",
3
- "compilerOptions": {
4
- "declaration": false,
5
- "jsx": "preserve",
6
- "baseUrl": "./",
7
- "paths": {
8
- "@shared/*": ["./shared/*"]
9
- }
10
- },
11
- "include": ["src", "shared", "config"]
12
- }
@@ -1,3 +0,0 @@
1
- export default {
2
- name: 'modern',
3
- };
@@ -1,13 +0,0 @@
1
- {
2
- "routes": [
3
- {
4
- "urlPath": "/entry/:id",
5
- "entryName": "entry",
6
- "entryPath": "html/entry/index.html",
7
- "isSPA": true,
8
- "isSSR": true,
9
- "enableModernMode": false,
10
- "bundle": "bundles/entry.js"
11
- }
12
- ]
13
- }
@@ -1,29 +0,0 @@
1
- {
2
- "routes": [
3
- {
4
- "urlPath": "/entry",
5
- "entryName": "entry",
6
- "entryPath": "html/entry/index.html",
7
- "isSPA": true,
8
- "isSSR": true,
9
- "enableModernMode": false,
10
- "bundle": "bundles/entry.js"
11
- },
12
- {
13
- "urlPath": "/home",
14
- "entryName": "home",
15
- "entryPath": "html/home/index.html",
16
- "isSPA": true,
17
- "isSSR": true,
18
- "enableModernMode": false,
19
- "bundle": "bundles/home.js"
20
- },
21
- {
22
- "urlPath": "/api",
23
- "isApi": true,
24
- "entryPath": "",
25
- "isSPA": false,
26
- "isSSR": false
27
- }
28
- ]
29
- }
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- error: () => '<div>Modern.js</div>',
3
- };
@@ -1,5 +0,0 @@
1
- const { SERVER_RENDER_FUNCTION_NAME } = require('@modern-js/utils');
2
-
3
- module.exports = {
4
- [SERVER_RENDER_FUNCTION_NAME]: () => '<div>Modern.js</div>',
5
- };
@@ -1,11 +0,0 @@
1
- <html lang="en">
2
- <head>
3
- <meta charset="UTF-8">
4
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Document</title>
7
- </head>
8
- <body>
9
- <div>csr</div>
10
- </body>
11
- </html>
@@ -1,11 +0,0 @@
1
- <html lang="en">
2
- <head>
3
- <meta charset="UTF-8">
4
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>bar</title>
7
- </head>
8
- <body>
9
-
10
- </body>
11
- </html>
@@ -1,11 +0,0 @@
1
- <html lang="en">
2
- <head>
3
- <meta charset="UTF-8">
4
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>baz</title>
7
- </head>
8
- <body>
9
-
10
- </body>
11
- </html>
@@ -1,11 +0,0 @@
1
- <html lang="en">
2
- <head>
3
- <meta charset="UTF-8">
4
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>foo</title>
7
- </head>
8
- <body>
9
-
10
- </body>
11
- </html>
package/tests/helper.ts DELETED
@@ -1,8 +0,0 @@
1
- export const createDoc = () => `<html>
2
- <head>
3
- <title>mock</title>
4
- </head>
5
- <body>
6
- <div>hello</div>
7
- </body>
8
- </html>`;
@@ -1,44 +0,0 @@
1
- import { createRouteAPI } from '../src/libs/hook-api/route';
2
- import { createTemplateAPI } from '../src/libs/hook-api/template';
3
- import { RouteMatchManager } from '../src/libs/route';
4
- import { createDoc } from './helper';
5
- import spec from './fixtures/route-spec/index.json';
6
-
7
- describe('test hook api', () => {
8
- test('should route api work correctly', () => {
9
- const manager = new RouteMatchManager();
10
- manager.reset(spec.routes);
11
- const matcher = manager.match('/home');
12
-
13
- const routeAPI = createRouteAPI(matcher!, manager, '');
14
- expect(routeAPI.cur().entryName).toBe('home');
15
- expect(routeAPI.get('entry')?.entryPath).toBe('html/entry/index.html');
16
-
17
- expect(routeAPI.use('home')).toBeTruthy();
18
- expect(routeAPI.cur().entryName).toBe('home');
19
- });
20
-
21
- test('should template api work correctly', () => {
22
- const content = createDoc();
23
- const templateAPI = createTemplateAPI(content);
24
-
25
- expect(templateAPI.get()).toMatch(content);
26
-
27
- templateAPI.replace('mock', 'replace');
28
- expect(templateAPI.get()).toMatch('replace');
29
-
30
- templateAPI.appendBody('after body');
31
- templateAPI.prependBody('before body');
32
- templateAPI.appendHead('after head');
33
- templateAPI.prependHead('before head');
34
-
35
- const newContent = templateAPI.get();
36
- expect(newContent).toMatch('<head>before head');
37
- expect(newContent).toMatch('<body>before body');
38
- expect(newContent).toMatch('after head</head>');
39
- expect(newContent).toMatch('after body</body>');
40
-
41
- templateAPI.set('<div>empty</div>');
42
- expect(templateAPI.get()).toBe('<div>empty</div>');
43
- });
44
- });
@@ -1,65 +0,0 @@
1
- import * as path from 'path';
2
- import type { NormalizedConfig } from '@modern-js/core';
3
- import { DEFAULT_SERVER_CONFIG } from '@modern-js/utils';
4
- import mergeDeep from 'merge-deep';
5
- import { getServerConfigPath } from '../src/libs/loadConfig';
6
-
7
- describe('test loadConfig', () => {
8
- test('should merge CliConfig and ServerConfig correctly', () => {
9
- const cliConfig = {
10
- bff: {
11
- prefix: '/bff',
12
- },
13
- source: {
14
- envVars: ['VERSION'],
15
- },
16
- };
17
-
18
- const serverConfig = {
19
- bff: {
20
- proxy: {
21
- '/api': {
22
- target: 'https://cnodejs.org',
23
- pathRewrite: { '/api/topics': '/api/v1/topics' },
24
- changeOrigin: true,
25
- },
26
- },
27
- },
28
- };
29
-
30
- const config = mergeDeep(
31
- cliConfig as unknown as NormalizedConfig,
32
- serverConfig,
33
- );
34
-
35
- expect(config).toEqual({
36
- bff: {
37
- prefix: '/bff',
38
- proxy: {
39
- '/api': {
40
- target: 'https://cnodejs.org',
41
- pathRewrite: { '/api/topics': '/api/v1/topics' },
42
- changeOrigin: true,
43
- },
44
- },
45
- },
46
- source: {
47
- envVars: ['VERSION'],
48
- },
49
- });
50
- });
51
-
52
- test('should get server config path correctly', () => {
53
- const distDirectory = path.normalize(
54
- '/Users/user/project/local-test-project/dist',
55
- );
56
- const serverConfigFile = DEFAULT_SERVER_CONFIG;
57
- const serverConfigPath = path.normalize(
58
- `/Users/user/project/local-test-project/dist/${DEFAULT_SERVER_CONFIG}.js`,
59
- );
60
-
61
- expect(getServerConfigPath(distDirectory, serverConfigFile)).toEqual(
62
- serverConfigPath,
63
- );
64
- });
65
- });