@modern-js/plugin-bff 1.4.5 → 1.5.2-canary.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 +30 -0
- package/dist/js/modern/cli.js +66 -25
- package/dist/js/node/cli.js +67 -25
- package/package.json +13 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @modern-js/plugin-bff
|
|
2
2
|
|
|
3
|
+
## 1.5.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6451a098: fix: cyclic dependencies of @modern-js/core and @moden-js/webpack
|
|
8
|
+
- Updated dependencies [d57e7622]
|
|
9
|
+
- Updated dependencies [6451a098]
|
|
10
|
+
- Updated dependencies [bfccb4c8]
|
|
11
|
+
- Updated dependencies [d5a2cfd8]
|
|
12
|
+
- Updated dependencies [437367c6]
|
|
13
|
+
- @modern-js/bff-utils@1.2.8
|
|
14
|
+
- @modern-js/utils@1.7.6
|
|
15
|
+
- @modern-js/create-request@1.2.10
|
|
16
|
+
- @modern-js/server-utils@1.2.9
|
|
17
|
+
|
|
18
|
+
## 1.5.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- f66fa0e98: feat: support tools.webpackChain config
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- 1dfe08fcd: feat(webpack): add CHAIN_ID constants for webpack chain
|
|
27
|
+
- 41dc62010: fix: remove typings from ignore directories
|
|
28
|
+
- Updated dependencies [77917e355]
|
|
29
|
+
- Updated dependencies [33de0f7ec]
|
|
30
|
+
- @modern-js/server-utils@1.2.9
|
|
31
|
+
- @modern-js/utils@1.7.5
|
|
32
|
+
|
|
3
33
|
## 1.4.5
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/dist/js/modern/cli.js
CHANGED
|
@@ -1,10 +1,49 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { compiler } from '@modern-js/babel-compiler';
|
|
3
|
-
import { fs, API_DIR, PLUGIN_SCHEMAS, normalizeOutputPath } from '@modern-js/utils';
|
|
3
|
+
import { fs, API_DIR, PLUGIN_SCHEMAS, normalizeOutputPath, SHARED_DIR } from '@modern-js/utils';
|
|
4
4
|
import { resolveBabelConfig } from '@modern-js/server-utils';
|
|
5
5
|
const DEFAULT_API_PREFIX = '/api';
|
|
6
6
|
const TS_CONFIG_FILENAME = 'tsconfig.json';
|
|
7
7
|
const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
|
|
8
|
+
|
|
9
|
+
const compile = async (appDirectory, modernConfig, compileOptions) => {
|
|
10
|
+
const {
|
|
11
|
+
patterns
|
|
12
|
+
} = compileOptions;
|
|
13
|
+
const results = await Promise.all(patterns.map(async pattern => {
|
|
14
|
+
const {
|
|
15
|
+
from,
|
|
16
|
+
to,
|
|
17
|
+
tsconfigPath
|
|
18
|
+
} = pattern;
|
|
19
|
+
const babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
|
|
20
|
+
tsconfigPath: tsconfigPath ? tsconfigPath : '',
|
|
21
|
+
syntax: 'es6+',
|
|
22
|
+
type: 'commonjs'
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (await fs.pathExists(from)) {
|
|
26
|
+
const basename = path.basename(from);
|
|
27
|
+
const targetDir = path.join(to, basename);
|
|
28
|
+
await fs.copy(from, targetDir, {
|
|
29
|
+
filter: src => !['.ts', '.js'].includes(path.extname(src)) && src !== tsconfigPath
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return compiler({
|
|
34
|
+
rootDir: appDirectory,
|
|
35
|
+
distDir: to,
|
|
36
|
+
sourceDir: from,
|
|
37
|
+
extensions: FILE_EXTENSIONS
|
|
38
|
+
}, babelConfig);
|
|
39
|
+
}));
|
|
40
|
+
results.forEach(result => {
|
|
41
|
+
if (result.code === 1) {
|
|
42
|
+
throw new Error(result.message);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
8
47
|
export default (() => ({
|
|
9
48
|
name: '@modern-js/plugin-bff',
|
|
10
49
|
setup: api => ({
|
|
@@ -15,8 +54,9 @@ export default (() => ({
|
|
|
15
54
|
config() {
|
|
16
55
|
return {
|
|
17
56
|
tools: {
|
|
18
|
-
|
|
19
|
-
|
|
57
|
+
webpackChain: (chain, {
|
|
58
|
+
name,
|
|
59
|
+
CHAIN_ID
|
|
20
60
|
}) => {
|
|
21
61
|
const {
|
|
22
62
|
appDirectory,
|
|
@@ -33,12 +73,12 @@ export default (() => ({
|
|
|
33
73
|
const rootDir = path.resolve(appDirectory, API_DIR);
|
|
34
74
|
chain.resolve.alias.set('@api', rootDir);
|
|
35
75
|
const apiRegexp = new RegExp(normalizeOutputPath(`${appDirectory}${path.sep}api${path.sep}.*(.[tj]s)$`));
|
|
36
|
-
chain.module.rule(
|
|
76
|
+
chain.module.rule(CHAIN_ID.RULE.LOADERS).oneOf(CHAIN_ID.ONE_OF.BFF_CLIENT).before(CHAIN_ID.ONE_OF.FALLBACK).test(apiRegexp).use('custom-loader').loader(require.resolve("./loader").replace(/\\/g, '/')).options({
|
|
37
77
|
prefix,
|
|
38
78
|
apiDir: rootDir,
|
|
39
79
|
port,
|
|
40
80
|
fetcher,
|
|
41
|
-
target:
|
|
81
|
+
target: name,
|
|
42
82
|
requestCreator: bff === null || bff === void 0 ? void 0 : bff.requestCreator
|
|
43
83
|
});
|
|
44
84
|
}
|
|
@@ -84,31 +124,32 @@ export default (() => ({
|
|
|
84
124
|
distDirectory
|
|
85
125
|
} = api.useAppContext();
|
|
86
126
|
const modernConfig = api.useResolvedConfigContext();
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const
|
|
127
|
+
const distDir = path.resolve(distDirectory);
|
|
128
|
+
const apiDir = path.resolve(appDirectory, API_DIR);
|
|
129
|
+
const sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
|
90
130
|
const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
extensions: FILE_EXTENSIONS,
|
|
101
|
-
ignore: [`**/__tests__/**`, '**/typings/**', '*.d.ts', '*.test.ts']
|
|
102
|
-
}, babelConfig);
|
|
131
|
+
const patterns = [];
|
|
132
|
+
|
|
133
|
+
if (fs.existsSync(apiDir)) {
|
|
134
|
+
patterns.push({
|
|
135
|
+
from: apiDir,
|
|
136
|
+
to: distDir,
|
|
137
|
+
tsconfigPath
|
|
138
|
+
});
|
|
139
|
+
}
|
|
103
140
|
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
141
|
+
if (fs.existsSync(sharedDir)) {
|
|
142
|
+
patterns.push({
|
|
143
|
+
from: sharedDir,
|
|
144
|
+
to: distDir,
|
|
145
|
+
tsconfigPath
|
|
107
146
|
});
|
|
108
147
|
}
|
|
109
148
|
|
|
110
|
-
if (
|
|
111
|
-
|
|
149
|
+
if (patterns.length > 0) {
|
|
150
|
+
await compile(appDirectory, modernConfig, {
|
|
151
|
+
patterns
|
|
152
|
+
});
|
|
112
153
|
}
|
|
113
154
|
}
|
|
114
155
|
|
package/dist/js/node/cli.js
CHANGED
|
@@ -19,6 +19,46 @@ const DEFAULT_API_PREFIX = '/api';
|
|
|
19
19
|
const TS_CONFIG_FILENAME = 'tsconfig.json';
|
|
20
20
|
const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
|
|
21
21
|
|
|
22
|
+
const compile = async (appDirectory, modernConfig, compileOptions) => {
|
|
23
|
+
const {
|
|
24
|
+
patterns
|
|
25
|
+
} = compileOptions;
|
|
26
|
+
const results = await Promise.all(patterns.map(async pattern => {
|
|
27
|
+
const {
|
|
28
|
+
from,
|
|
29
|
+
to,
|
|
30
|
+
tsconfigPath
|
|
31
|
+
} = pattern;
|
|
32
|
+
const babelConfig = (0, _serverUtils.resolveBabelConfig)(appDirectory, modernConfig, {
|
|
33
|
+
tsconfigPath: tsconfigPath ? tsconfigPath : '',
|
|
34
|
+
syntax: 'es6+',
|
|
35
|
+
type: 'commonjs'
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (await _utils.fs.pathExists(from)) {
|
|
39
|
+
const basename = _path.default.basename(from);
|
|
40
|
+
|
|
41
|
+
const targetDir = _path.default.join(to, basename);
|
|
42
|
+
|
|
43
|
+
await _utils.fs.copy(from, targetDir, {
|
|
44
|
+
filter: src => !['.ts', '.js'].includes(_path.default.extname(src)) && src !== tsconfigPath
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (0, _babelCompiler.compiler)({
|
|
49
|
+
rootDir: appDirectory,
|
|
50
|
+
distDir: to,
|
|
51
|
+
sourceDir: from,
|
|
52
|
+
extensions: FILE_EXTENSIONS
|
|
53
|
+
}, babelConfig);
|
|
54
|
+
}));
|
|
55
|
+
results.forEach(result => {
|
|
56
|
+
if (result.code === 1) {
|
|
57
|
+
throw new Error(result.message);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
22
62
|
var _default = () => ({
|
|
23
63
|
name: '@modern-js/plugin-bff',
|
|
24
64
|
setup: api => ({
|
|
@@ -29,8 +69,9 @@ var _default = () => ({
|
|
|
29
69
|
config() {
|
|
30
70
|
return {
|
|
31
71
|
tools: {
|
|
32
|
-
|
|
33
|
-
|
|
72
|
+
webpackChain: (chain, {
|
|
73
|
+
name,
|
|
74
|
+
CHAIN_ID
|
|
34
75
|
}) => {
|
|
35
76
|
const {
|
|
36
77
|
appDirectory,
|
|
@@ -49,12 +90,12 @@ var _default = () => ({
|
|
|
49
90
|
|
|
50
91
|
chain.resolve.alias.set('@api', rootDir);
|
|
51
92
|
const apiRegexp = new RegExp((0, _utils.normalizeOutputPath)(`${appDirectory}${_path.default.sep}api${_path.default.sep}.*(.[tj]s)$`));
|
|
52
|
-
chain.module.rule(
|
|
93
|
+
chain.module.rule(CHAIN_ID.RULE.LOADERS).oneOf(CHAIN_ID.ONE_OF.BFF_CLIENT).before(CHAIN_ID.ONE_OF.FALLBACK).test(apiRegexp).use('custom-loader').loader(require.resolve("./loader").replace(/\\/g, '/')).options({
|
|
53
94
|
prefix,
|
|
54
95
|
apiDir: rootDir,
|
|
55
96
|
port,
|
|
56
97
|
fetcher,
|
|
57
|
-
target:
|
|
98
|
+
target: name,
|
|
58
99
|
requestCreator: bff === null || bff === void 0 ? void 0 : bff.requestCreator
|
|
59
100
|
});
|
|
60
101
|
}
|
|
@@ -101,35 +142,36 @@ var _default = () => ({
|
|
|
101
142
|
} = api.useAppContext();
|
|
102
143
|
const modernConfig = api.useResolvedConfigContext();
|
|
103
144
|
|
|
104
|
-
const
|
|
145
|
+
const distDir = _path.default.resolve(distDirectory);
|
|
105
146
|
|
|
106
|
-
const
|
|
147
|
+
const apiDir = _path.default.resolve(appDirectory, _utils.API_DIR);
|
|
107
148
|
|
|
108
|
-
const
|
|
149
|
+
const sharedDir = _path.default.resolve(appDirectory, _utils.SHARED_DIR);
|
|
109
150
|
|
|
110
151
|
const tsconfigPath = _path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
111
152
|
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
distDir,
|
|
120
|
-
sourceDir: sourceAbsDir,
|
|
121
|
-
extensions: FILE_EXTENSIONS,
|
|
122
|
-
ignore: [`**/__tests__/**`, '**/typings/**', '*.d.ts', '*.test.ts']
|
|
123
|
-
}, babelConfig);
|
|
124
|
-
|
|
125
|
-
if (await _utils.fs.pathExists(rootDir)) {
|
|
126
|
-
await _utils.fs.copy(rootDir, distDir, {
|
|
127
|
-
filter: src => !['.ts', '.js'].includes(_path.default.extname(src)) && src !== tsconfigPath
|
|
153
|
+
const patterns = [];
|
|
154
|
+
|
|
155
|
+
if (_utils.fs.existsSync(apiDir)) {
|
|
156
|
+
patterns.push({
|
|
157
|
+
from: apiDir,
|
|
158
|
+
to: distDir,
|
|
159
|
+
tsconfigPath
|
|
128
160
|
});
|
|
129
161
|
}
|
|
130
162
|
|
|
131
|
-
if (
|
|
132
|
-
|
|
163
|
+
if (_utils.fs.existsSync(sharedDir)) {
|
|
164
|
+
patterns.push({
|
|
165
|
+
from: sharedDir,
|
|
166
|
+
to: distDir,
|
|
167
|
+
tsconfigPath
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (patterns.length > 0) {
|
|
172
|
+
await compile(appDirectory, modernConfig, {
|
|
173
|
+
patterns
|
|
174
|
+
});
|
|
133
175
|
}
|
|
134
176
|
}
|
|
135
177
|
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.5.2-canary.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -56,17 +56,17 @@
|
|
|
56
56
|
"@babel/core": "^7.17.0",
|
|
57
57
|
"@babel/runtime": "^7",
|
|
58
58
|
"@modern-js/babel-compiler": "^1.2.5",
|
|
59
|
-
"@modern-js/bff-utils": "^1.2.
|
|
60
|
-
"@modern-js/create-request": "^1.2.
|
|
61
|
-
"@modern-js/server-utils": "^1.2.
|
|
62
|
-
"@modern-js/utils": "^1.7.
|
|
59
|
+
"@modern-js/bff-utils": "^1.2.8",
|
|
60
|
+
"@modern-js/create-request": "^1.2.10",
|
|
61
|
+
"@modern-js/server-utils": "^1.2.9",
|
|
62
|
+
"@modern-js/utils": "^1.7.6"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@modern-js/core": "1.
|
|
66
|
-
"@modern-js/plugin-analyze": "1.4.
|
|
67
|
-
"@modern-js/runtime": "1.3.
|
|
65
|
+
"@modern-js/core": "1.11.1",
|
|
66
|
+
"@modern-js/plugin-analyze": "1.4.5",
|
|
67
|
+
"@modern-js/runtime": "1.3.1",
|
|
68
68
|
"@modern-js/server-core": "1.3.5",
|
|
69
|
-
"@modern-js/types": "1.5.
|
|
69
|
+
"@modern-js/types": "1.5.4",
|
|
70
70
|
"@scripts/build": "0.0.0",
|
|
71
71
|
"@scripts/jest-config": "0.0.0",
|
|
72
72
|
"@types/babel__core": "^7.1.15",
|
|
@@ -82,7 +82,8 @@
|
|
|
82
82
|
"sideEffects": false,
|
|
83
83
|
"publishConfig": {
|
|
84
84
|
"registry": "https://registry.npmjs.org/",
|
|
85
|
-
"access": "public"
|
|
85
|
+
"access": "public",
|
|
86
|
+
"types": "./dist/types/index.d.ts"
|
|
86
87
|
},
|
|
87
88
|
"wireit": {
|
|
88
89
|
"build": {
|
|
@@ -101,7 +102,8 @@
|
|
|
101
102
|
"files": [
|
|
102
103
|
"src/**/*",
|
|
103
104
|
"tsconfig.json",
|
|
104
|
-
"package.json"
|
|
105
|
+
"package.json",
|
|
106
|
+
"tests/**/*"
|
|
105
107
|
],
|
|
106
108
|
"output": []
|
|
107
109
|
}
|