Skip to content

Commit 022002a

Browse files
committed
🎨 update data
1 parent dca0d93 commit 022002a

File tree

8 files changed

+83
-8
lines changed

8 files changed

+83
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"dotenv": "^8.2.0"
5858
},
5959
"peerDependencies": {
60-
"@micro-app/shared-utils": ">=0.0.5"
60+
"@micro-app/shared-utils": ">=0.1.0"
6161
},
6262
"engines": {
6363
"node": ">=8"

src/core/Config/libs/BaseConfig.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class BaseConfig {
7474
return this[KEY_ORIGNAL_CONFIG] || {};
7575
}
7676

77+
get originalConfig() {
78+
return this.config;
79+
}
80+
7781
get root() {
7882
const config = this.config;
7983
return config[Symbols.ROOT] || '';

src/core/Package/libs/BasePackage.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
22

3-
const npa = require('npm-package-arg');
43
const path = require('path');
5-
const { fs, _ } = require('@micro-app/shared-utils');
4+
const { fs, _, npa } = require('@micro-app/shared-utils');
65

76
const CONSTANTS = require('../../Constants');
87

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
'use strict';
2+

src/core/PackageGraph/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
'use strict';
2+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
'use strict';
2+
3+
const semver = require('semver');
4+
const prereleaseIdFromVersion = require('@lerna/prerelease-id-from-version');
5+
6+
/**
7+
* Represents a node in a PackageGraph.
8+
* @constructor
9+
* @param {!<Package>} pkg - A Package object to build the node from.
10+
*/
11+
class PackageGraphNode {
12+
constructor(pkg) {
13+
Object.defineProperties(this, {
14+
// immutable properties
15+
name: {
16+
enumerable: true,
17+
value: pkg.name,
18+
},
19+
location: {
20+
value: pkg.location,
21+
},
22+
prereleaseId: {
23+
// an existing prerelease ID only matters at the beginning
24+
value: prereleaseIdFromVersion(pkg.version),
25+
},
26+
// properties that might change over time
27+
version: {
28+
get() {
29+
return pkg.version;
30+
},
31+
},
32+
pkg: {
33+
get() {
34+
return pkg;
35+
},
36+
},
37+
});
38+
39+
this.externalDependencies = new Map();
40+
this.localDependencies = new Map();
41+
this.localDependents = new Map();
42+
}
43+
44+
/**
45+
* Determine if the Node satisfies a resolved semver range.
46+
* @see https://github.com/npm/npm-package-arg#result-object
47+
*
48+
* @param {!Result} resolved npm-package-arg Result object
49+
* @return {Boolean}
50+
*/
51+
satisfies({ gitCommittish, gitRange, fetchSpec }) {
52+
return semver.satisfies(this.version, gitCommittish || gitRange || fetchSpec);
53+
}
54+
55+
/**
56+
* Returns a string representation of this node (its name)
57+
*
58+
* @return {String}
59+
*/
60+
toString() {
61+
return this.name;
62+
}
63+
}
64+
65+
module.exports = PackageGraphNode;

src/core/Service/libs/MethodService.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class MethodService extends BaseService {
183183
value: config,
184184
});
185185

186+
// redirect
186187
Object.defineProperty(this, 'selfConfig', {
187188
get() {
188189
return this.microsConfig[selfKey] || {};

src/utils/requireMicro.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,29 @@ function loadMicroAppConfig(id, [ rootPath, originalMicPath ]) {
3535
microConfig[symbols.KEY] = id;
3636
microConfig[symbols.ORIGINAL_ROOT] = originalMicPath;
3737
const _microAppConfig = new MicroAppConfig(microConfig);
38-
configCache[name] = _microAppConfig;
3938
return _microAppConfig;
4039
}
4140
return null;
4241
}
4342

4443
function requireMicro(id, changeRootPath, scope = '') {
4544
const { ROOT, SCOPE_NAME, NODE_MODULES_NAME } = CONSTANTS;
46-
const name = `${SCOPE_NAME}/${id}`;
47-
if (configCache[name]) {
48-
return configCache[name];
45+
if (configCache[id]) {
46+
return configCache[id];
4947
}
5048
let result = null;
5149
// 兼容 id
5250
let originalMicPath = path.resolve(ROOT, NODE_MODULES_NAME, scope, id);
5351
const ps = _.isFunction(changeRootPath) && changeRootPath(id, originalMicPath) || [ originalMicPath, originalMicPath ];
5452
result = loadMicroAppConfig(id, ps);
5553
if (!result) {
54+
const name = `${SCOPE_NAME}/${id}`;
5655
originalMicPath = path.resolve(ROOT, NODE_MODULES_NAME, scope, name);
5756
const ps = _.isFunction(changeRootPath) && changeRootPath(id, originalMicPath) || [ originalMicPath, originalMicPath ];
58-
result = loadMicroAppConfig(id, ps);
57+
result = loadMicroAppConfig(name, ps);
58+
}
59+
if (result) { // cache
60+
configCache[id] = result;
5961
}
6062
return result;
6163
}

0 commit comments

Comments
 (0)