@modern-js/server-utils 1.2.0 → 1.2.3

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,41 @@
1
1
  # @modern-js/server-utils
2
2
 
3
+ ## 1.2.3
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 [6cffe99d]
14
+ - Updated dependencies [04ae5262]
15
+ - Updated dependencies [60f7d8bf]
16
+ - Updated dependencies [3bf4f8b0]
17
+ - @modern-js/utils@1.5.0
18
+ - @modern-js/babel-preset-lib@1.2.3
19
+ - @modern-js/plugin@1.3.3
20
+
21
+ ## 1.2.2
22
+
23
+ ### Patch Changes
24
+
25
+ - bebb39b6: chore: improve devDependencies and peerDependencies
26
+ - Updated dependencies [132f7b53]
27
+ - @modern-js/utils@1.3.7
28
+
29
+ ## 1.2.1
30
+
31
+ ### Patch Changes
32
+
33
+ - 83166714: change .npmignore
34
+ - Updated dependencies [83166714]
35
+ - @modern-js/babel-preset-lib@1.2.1
36
+ - @modern-js/plugin@1.2.1
37
+ - @modern-js/utils@1.2.2
38
+
3
39
  ## 1.2.0
4
40
 
5
41
  ### Minor Changes
package/jest.config.js CHANGED
@@ -2,7 +2,6 @@ const sharedConfig = require('@scripts/jest-config');
2
2
 
3
3
  /** @type {import('@jest/types').Config.InitialOptions} */
4
4
  module.exports = {
5
- // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
5
  ...sharedConfig,
7
6
  rootDir: __dirname,
8
7
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.2.0",
14
+ "version": "1.2.3",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -35,15 +35,15 @@
35
35
  "@babel/preset-env": "^7.15.0",
36
36
  "@babel/preset-typescript": "^7.15.0",
37
37
  "@babel/runtime": "^7",
38
- "@modern-js/babel-preset-lib": "^1.2.0",
39
- "@modern-js/plugin": "^1.2.0",
40
- "@modern-js/utils": "^1.2.0",
38
+ "@modern-js/babel-preset-lib": "^1.2.3",
39
+ "@modern-js/plugin": "^1.3.3",
40
+ "@modern-js/utils": "^1.5.0",
41
41
  "babel-plugin-module-resolver": "^4.1.0",
42
42
  "babel-plugin-transform-typescript-metadata": "^0.3.2",
43
43
  "json5": "^2.2.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@modern-js/core": "^1.3.0",
46
+ "@modern-js/core": "1.8.0",
47
47
  "@types/babel__core": "^7.1.15",
48
48
  "@types/jest": "^26",
49
49
  "@types/node": "^14",
@@ -58,8 +58,7 @@
58
58
  "sideEffects": false,
59
59
  "publishConfig": {
60
60
  "registry": "https://registry.npmjs.org/",
61
- "access": "public",
62
- "types": "./dist/types/index.d.ts"
61
+ "access": "public"
63
62
  },
64
63
  "scripts": {
65
64
  "new": "modern new",
package/src/babel.ts DELETED
@@ -1,151 +0,0 @@
1
- import {
2
- getBabelChain,
3
- ILibPresetOption,
4
- ISyntaxOption,
5
- } from '@modern-js/babel-preset-lib';
6
- import { TransformOptions } from '@babel/core';
7
- import { applyOptionsChain, fs, getAlias } from '@modern-js/utils';
8
- import type { NormalizedConfig } from '@modern-js/core';
9
- import json5 from 'json5';
10
-
11
- export * from '@babel/core';
12
-
13
- export interface ITsconfig {
14
- compilerOptions?:
15
- | {
16
- rootDir?: string;
17
- baseUrl?: string;
18
- declaration?: boolean;
19
- emitDeclarationOnly?: boolean;
20
- isolatedModules?: boolean;
21
- allowJs?: boolean;
22
- outDir?: string;
23
- paths?: Record<string, string[]>;
24
- }
25
- | undefined;
26
- include?: string[];
27
- exclude?: string[];
28
- }
29
-
30
- export const readTsConfig = <T extends null | ITsconfig>(
31
- tsconfigPath: string,
32
- noExistReturn: T = null as T,
33
- ): ITsconfig | T => {
34
- // 如果不存在,则返回 noExistReturn
35
- if (!fs.existsSync(tsconfigPath)) {
36
- return noExistReturn;
37
- }
38
- const content = fs.readFileSync(tsconfigPath, 'utf-8');
39
- return json5.parse(content);
40
- };
41
-
42
- export const existTsConfigFile = (tsconfigAbsolutePath: string) => {
43
- const tsconfig = readTsConfig(tsconfigAbsolutePath);
44
- return Boolean(tsconfig);
45
- };
46
-
47
- export const getBabelConfig = (
48
- libPresetOption: ILibPresetOption,
49
- syntaxOption: ISyntaxOption,
50
- ): TransformOptions => {
51
- const chain = getBabelChain(libPresetOption, syntaxOption);
52
-
53
- return {
54
- sourceType: 'unambiguous',
55
- ...chain.toJSON(),
56
- };
57
- };
58
-
59
- export interface IPackageModeValue {
60
- type: 'module' | 'commonjs';
61
- syntax: 'es5' | 'es6+';
62
- tsconfigPath: string;
63
- }
64
-
65
- export const resolveBabelConfig = (
66
- appDirectory: string,
67
- modernConfig: NormalizedConfig,
68
- option: IPackageModeValue,
69
- // FIXME: babel type can't pass type checking
70
- ): any => {
71
- const {
72
- source: {
73
- envVars,
74
- globalVars,
75
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
76
- // @ts-expect-error
77
- jsxTransformRuntime = 'automatic',
78
- },
79
- tools: { lodash: userLodashOption },
80
- } = modernConfig;
81
-
82
- // alias config
83
- const aliasConfig = getAlias(modernConfig.source.alias, {
84
- appDirectory,
85
- ...option,
86
- });
87
-
88
- // lodash config
89
- const lodashOptions = applyOptionsChain(
90
- { id: ['lodash', 'ramda'] },
91
- // TODO: 需要处理类型问题
92
- userLodashOption as any,
93
- );
94
- // babel config
95
- const babelChain = getBabelChain(
96
- {
97
- appDirectory,
98
- enableReactPreset: true,
99
- enableTypescriptPreset: true,
100
- alias: aliasConfig,
101
- envVars,
102
- globalVars,
103
- lodashOptions,
104
- jsxTransformRuntime,
105
- },
106
- {
107
- type: option.type,
108
- syntax: option.syntax,
109
- },
110
- );
111
-
112
- const envOptions = babelChain.preset('@babel/preset-env').options();
113
- babelChain
114
- .preset('@babel/preset-env')
115
- .use(require.resolve('@babel/preset-env'), [
116
- {
117
- ...envOptions[0],
118
- loose: true,
119
- },
120
- ]);
121
-
122
- babelChain.plugin('babel-plugin-transform-typescript-metadata').use(
123
- require.resolve('babel-plugin-transform-typescript-metadata'),
124
-
125
- [],
126
- );
127
-
128
- babelChain
129
- .plugin('@babel/plugin-proposal-decorators')
130
- .use(require.resolve('@babel/plugin-proposal-decorators'), [
131
- { legacy: true },
132
- ]);
133
-
134
- babelChain.plugin('@babel/plugin-proposal-class-properties').use(
135
- require.resolve('@babel/plugin-proposal-class-properties'),
136
-
137
- [{ loose: true }],
138
- );
139
-
140
- const internalBabelConfig = { ...babelChain.toJSON() };
141
-
142
- const userBabelConfig = modernConfig.tools.babel;
143
- applyOptionsChain(
144
- internalBabelConfig,
145
- // TODO: 感觉 userBabelConfig 的类型应该是TransformOptions
146
- userBabelConfig as any,
147
- { chain: babelChain },
148
- );
149
-
150
- return internalBabelConfig;
151
- };
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './babel';
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- extends: ['@modern-js'],
3
- parserOptions: {
4
- project: require.resolve('./tsconfig.json'),
5
- },
6
- };
@@ -1,174 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`babel resolveBabelConfig 1`] = `
4
- Object {
5
- "plugins": Array [
6
- Array [
7
- "/babel-plugin-macros/dist/index.js",
8
- Object {
9
- "twin": Object {
10
- "preset": "styled-components",
11
- },
12
- },
13
- ],
14
- Array [
15
- "/babel-plugin-import/lib/index.js",
16
- Object {
17
- "libraryDirectory": "es",
18
- "libraryName": "antd",
19
- "style": true,
20
- },
21
- "import-antd",
22
- ],
23
- Array [
24
- "/babel-plugin-lodash/lib/index.js",
25
- Object {
26
- "id": Array [
27
- "lodash",
28
- "ramda",
29
- ],
30
- },
31
- ],
32
- Array [
33
- "/@babel/plugin-proposal-decorators/lib/index.js",
34
- Object {
35
- "legacy": true,
36
- },
37
- ],
38
- Array [
39
- "/@babel/plugin-proposal-class-properties/lib/index.js",
40
- Object {
41
- "loose": true,
42
- },
43
- ],
44
- Array [
45
- "/@babel/plugin-proposal-private-methods/lib/index.js",
46
- Object {
47
- "loose": true,
48
- },
49
- ],
50
- Array [
51
- "/@babel/plugin-proposal-private-property-in-object/lib/index.js",
52
- Object {
53
- "loose": true,
54
- },
55
- ],
56
- Array [
57
- "/@babel/plugin-proposal-object-rest-spread/lib/index.js",
58
- Object {
59
- "useBuiltIns": true,
60
- },
61
- ],
62
- Array [
63
- "/@babel/plugin-transform-runtime/lib/index.js",
64
- Object {
65
- "corejs": false,
66
- "helpers": false,
67
- "regenerator": true,
68
- "useESModules": false,
69
- "version": "7.16.7",
70
- },
71
- ],
72
- Array [
73
- "/babel-plugin-transform-react-remove-prop-types/lib/index.js",
74
- Object {
75
- "removeImport": true,
76
- },
77
- ],
78
- Array [
79
- "/@babel/plugin-proposal-function-bind/lib/index.js",
80
- ],
81
- Array [
82
- "/@babel/plugin-proposal-export-default-from/lib/index.js",
83
- ],
84
- Array [
85
- "/@babel/plugin-proposal-export-namespace-from/lib/index.js",
86
- ],
87
- Array [
88
- "/@babel/plugin-proposal-optional-chaining/lib/index.js",
89
- ],
90
- Array [
91
- "/@babel/plugin-proposal-numeric-separator/lib/index.js",
92
- ],
93
- Array [
94
- "/@babel/plugin-proposal-pipeline-operator/lib/index.js",
95
- Object {
96
- "proposal": "minimal",
97
- },
98
- ],
99
- Array [
100
- "/@babel/plugin-proposal-partial-application/lib/index.js",
101
- ],
102
- Array [
103
- "/@babel/plugin-proposal-nullish-coalescing-operator/lib/index.js",
104
- ],
105
- Array [
106
- "/babel-plugin-styled-components/lib/index.js",
107
- Object {},
108
- "styled-components",
109
- ],
110
- Array [
111
- "/babel-plugin-transform-inline-environment-variables/lib/index.js",
112
- Object {
113
- "include": Array [],
114
- },
115
- ],
116
- Array [
117
- "/babel-plugin-module-resolver/lib/index.js",
118
- Object {
119
- "alias": Object {
120
- "@/*": Array [
121
- "./src/*",
122
- ],
123
- },
124
- "extensions": Array [
125
- ".ts",
126
- ".tsx",
127
- ".js",
128
- ".jsx",
129
- ".es",
130
- ".es6",
131
- ".mjs",
132
- ],
133
- "resolvePath": [Function],
134
- "root": "/packages/server/utils/tests/fixtures/",
135
- },
136
- ],
137
- Array [
138
- "/babel-plugin-transform-typescript-metadata/lib/plugin.js",
139
- ],
140
- ],
141
- "presets": Array [
142
- Array [
143
- "/@babel/preset-env/lib/index.js",
144
- Object {
145
- "bugfixes": true,
146
- "modules": "commonjs",
147
- "shippedProposals": false,
148
- "targets": Array [
149
- "chrome > 61",
150
- "edge > 16",
151
- "firefox > 60",
152
- "safari > 11",
153
- "ios_saf > 11",
154
- ],
155
- },
156
- ],
157
- Array [
158
- "/@babel/preset-react/lib/index.js",
159
- Object {
160
- "runtime": "automatic",
161
- },
162
- ],
163
- Array [
164
- "/@babel/preset-typescript/lib/index.js",
165
- Object {
166
- "allExtensions": true,
167
- "allowDeclareFields": true,
168
- "allowNamespaces": true,
169
- "isTSX": true,
170
- },
171
- ],
172
- ],
173
- }
174
- `;
@@ -1,40 +0,0 @@
1
- import path from 'path';
2
- import { resolveBabelConfig } from '../src';
3
- import { defaults } from './helpers';
4
-
5
- describe('babel', () => {
6
- it('resolveBabelConfig', () => {
7
- const pwd = path.resolve(__dirname, './fixtures');
8
- const tsconfigPath = path.resolve(
9
- __dirname,
10
- './fixtures/api/tsconfig.json',
11
- );
12
- const config = resolveBabelConfig(pwd, defaults as any, {
13
- type: 'commonjs',
14
- syntax: 'es6+',
15
- tsconfigPath,
16
- });
17
-
18
- const root = path.resolve(__dirname, '../../../../');
19
-
20
- expect.addSnapshotSerializer({
21
- test: val =>
22
- typeof val === 'string' &&
23
- (val.includes('modern.js') ||
24
- val.includes('node_modules') ||
25
- val.includes(root)),
26
- print: val =>
27
- // eslint-disable-next-line no-nested-ternary
28
- typeof val === 'string'
29
- ? // eslint-disable-next-line no-nested-ternary
30
- val.includes('node_modules')
31
- ? `"${val.replace(/.+node_modules/, '').replace(/\\/g, '/')}"`
32
- : val.includes('modern.js')
33
- ? `"${val.replace(/.+modern\.js/, '').replace(/\\/g, '/')}"`
34
- : `"${val.replace(root, '').replace(/\\/g, '/')}"`
35
- : (val as string),
36
- });
37
-
38
- expect(config).toMatchSnapshot();
39
- });
40
- });
@@ -1,5 +0,0 @@
1
- import { hook } from '../../../src';
2
-
3
- export default hook(({ addMiddleware }) => {
4
- addMiddleware('@koa/api');
5
- });
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "declaration": false,
4
- "jsx": "preserve",
5
- "baseUrl": "./",
6
- "isolatedModules": true,
7
- "experimentalDecorators": true,
8
- "esModuleInterop": true,
9
- "paths": {
10
- "@/*": ["./src/*"]
11
- }
12
- },
13
- "include": ["src", "api", "server", "electron"]
14
- }
@@ -1,5 +0,0 @@
1
- import { hook } from '../../../src';
2
-
3
- export default hook(({ addMiddleware }) => {
4
- addMiddleware('@koa/web');
5
- });
package/tests/helpers.ts DELETED
@@ -1,100 +0,0 @@
1
- const sourceDefaults = {
2
- entries: undefined,
3
- disableDefaultEntries: false,
4
- entriesDir: './src',
5
- configDir: './config',
6
- apiDir: './api',
7
- envVars: [],
8
- globalVars: undefined,
9
- alias: undefined,
10
- moduleScopes: undefined,
11
- include: [],
12
- };
13
-
14
- const outputDefaults = {
15
- assetPrefix: '/',
16
- htmlPath: 'html',
17
- jsPath: 'static/js',
18
- cssPath: 'static/css',
19
- mediaPath: 'static/media',
20
- path: 'dist',
21
- title: '',
22
- titleByEntries: undefined,
23
- meta: {
24
- charset: { charset: 'utf-8' },
25
- viewport:
26
- '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',
27
- 'http-equiv': { 'http-equiv': 'x-ua-compatible', content: 'ie=edge' },
28
- renderer: 'webkit',
29
- layoutmode: 'standard',
30
- imagemode: 'force',
31
- 'wap-font-scale': 'no',
32
- 'format-detection': 'telephone=no',
33
- },
34
- metaByEntries: undefined,
35
- inject: 'head',
36
- injectByEntries: undefined,
37
- mountId: 'root',
38
- favicon: '',
39
- faviconByEntries: undefined,
40
- copy: undefined,
41
- scriptExt: undefined,
42
- disableHtmlFolder: false,
43
- disableCssModuleExtension: false,
44
- disableCssExtract: false,
45
- enableCssModuleTSDeclaration: false,
46
- disableMinimize: false,
47
- enableInlineStyles: false,
48
- enableInlineScripts: false,
49
- disableSourceMap: false,
50
- disableInlineRuntimeChunk: false,
51
- disableAssetsCache: false,
52
- enableLatestDecorators: false,
53
- polyfill: 'entry',
54
- dataUriLimit: 10000,
55
- templateParameters: {},
56
- templateParametersByEntries: undefined,
57
- cssModuleLocalIdentName: '[name]__[local]--[hash:base64:5]',
58
- enableModernMode: false,
59
- federation: undefined,
60
- disableNodePolyfill: false,
61
- enableTsLoader: false,
62
- };
63
-
64
- const serverDefaults = {
65
- routes: undefined,
66
- publicRoutes: undefined,
67
- ssr: undefined,
68
- ssrByEntries: undefined,
69
- baseUrl: '/',
70
- port: 8080,
71
- };
72
-
73
- const devDefaults = { assetPrefix: false };
74
-
75
- const deployDefaults = {
76
- microFrontend: false,
77
- domain: '',
78
- domainByEntries: undefined,
79
- };
80
-
81
- const toolsDefaults = {
82
- webpack: undefined,
83
- babel: undefined,
84
- postcss: undefined,
85
- autoprefixer: undefined,
86
- lodash: undefined,
87
- devServer: undefined,
88
- tsLoader: undefined,
89
- terser: undefined,
90
- minifyCss: undefined,
91
- };
92
-
93
- export const defaults = {
94
- source: sourceDefaults,
95
- output: outputDefaults,
96
- server: serverDefaults,
97
- dev: devDefaults,
98
- deploy: deployDefaults,
99
- tools: toolsDefaults,
100
- };
@@ -1,11 +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
- }