binhend 2.2.10 → 2.2.12
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/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const path = require('path');
|
|
|
10
10
|
|
|
11
11
|
//___ Run scripts ___//
|
|
12
12
|
const moduleAlias = require('./packages/module-alias'); // path alias '@' for requiring modules: require('@/any/path') - use jsconfig.json
|
|
13
|
-
moduleAlias.
|
|
13
|
+
moduleAlias.path('@binhend/*', [ path.join(__dirname, './packages') ]); // set path alias '@binhend' for all packages to call each others when 'npm install' in another project
|
|
14
14
|
|
|
15
15
|
const server = require('./packages/core/src/server');
|
|
16
16
|
const Router = require('./packages/core/src/Router');
|
package/package.json
CHANGED
package/packages/core/index.js
CHANGED
|
@@ -1,33 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
const utils = require('@binhend/utils');
|
|
3
|
-
const middlewares = require('@binhend/middlewares');
|
|
4
|
-
const { config, ConfigLoader } = require('@binhend/config');
|
|
5
|
-
const { WebBuild, binh } = require('@binhend/web');
|
|
6
|
-
|
|
7
|
-
// Run scripts
|
|
8
|
-
require('@binhend/module-alias'); // for format: require('@/any/path')
|
|
9
|
-
|
|
10
2
|
module.exports = {
|
|
11
3
|
server: require('./src/server'),
|
|
12
4
|
Router: require('./src/Router'),
|
|
13
|
-
routes: require('./src/routes').routes
|
|
14
|
-
|
|
15
|
-
cors: middlewares.cors,
|
|
16
|
-
trycatch: middlewares.trycatch,
|
|
17
|
-
|
|
18
|
-
config, ConfigLoader,
|
|
19
|
-
|
|
20
|
-
HTTPS: require('@binhend/https').HTTPS,
|
|
21
|
-
HttpError: utils.HttpError,
|
|
22
|
-
HttpCodes: utils.HttpCodes,
|
|
23
|
-
Bromise: utils.Bromise,
|
|
24
|
-
|
|
25
|
-
CSD: require('@binhend/csd'),
|
|
26
|
-
|
|
27
|
-
crypto: require('@binhend/crypto'),
|
|
28
|
-
|
|
29
|
-
types: require('@binhend/types'),
|
|
30
|
-
validation: require('@binhend/validation'),
|
|
31
|
-
|
|
32
|
-
WebBuild, binh
|
|
5
|
+
routes: require('./src/routes').routes
|
|
33
6
|
};
|
|
@@ -24,19 +24,24 @@ const paths = jsconfig?.compilerOptions?.paths || {};
|
|
|
24
24
|
const settings = { // for external modification in run-time
|
|
25
25
|
paths,
|
|
26
26
|
webSourcePath: null,
|
|
27
|
-
webModulePath: null
|
|
27
|
+
webModulePath: null,
|
|
28
|
+
path: mapAliasWithFilePaths
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
/** Step 2: Create an alias map with all possible paths */
|
|
31
|
-
const aliasMap = {}
|
|
32
|
+
const aliasMap = {}, ENDING_WILDCARD = /\/\*$/;
|
|
32
33
|
|
|
33
34
|
for (const alias in paths) {
|
|
34
|
-
const
|
|
35
|
-
|
|
35
|
+
const filePaths = paths[alias]; // Get the array of file paths
|
|
36
|
+
mapAliasWithFilePaths(alias, filePaths);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function mapAliasWithFilePaths(alias, filePaths) {
|
|
40
|
+
const aliasPath = alias.replace(ENDING_WILDCARD, ''); // Strip the '/*' for matching
|
|
36
41
|
|
|
37
|
-
aliasMap[aliasPath] =
|
|
42
|
+
aliasMap[aliasPath] = filePaths.map((filePath) => {
|
|
38
43
|
// Resolve each path to an absolute path
|
|
39
|
-
return path.resolve(baseUrl,
|
|
44
|
+
return path.resolve(baseUrl, filePath.replace(ENDING_WILDCARD, ''));
|
|
40
45
|
});
|
|
41
46
|
}
|
|
42
47
|
|
|
@@ -48,18 +53,21 @@ Module._resolveFilename = function (request, parent, isMain, options) {
|
|
|
48
53
|
if (!request.startsWith(alias)) continue;
|
|
49
54
|
// Loop through the array of resolved paths for this alias
|
|
50
55
|
for (const resolvedPath of aliasMap[alias]) {
|
|
51
|
-
// Construct
|
|
56
|
+
// Construct a new request path (convert @ path to resolved path)
|
|
52
57
|
var newRequest = request.replace(alias, resolvedPath);
|
|
53
58
|
|
|
54
|
-
//
|
|
59
|
+
// Check if the above resolved path matching web component path, then change from source directory to module directory
|
|
55
60
|
if (parent.filename.startsWith(settings.webModulePath)) {
|
|
61
|
+
// BINHEND web components (formatted code) load each others in build-time still requiring src paths (src file paths), not module paths (formatted file paths)
|
|
62
|
+
// parent.filename is the file location of module which makes this request by calling require()
|
|
56
63
|
newRequest = newRequest.replace(settings.webSourcePath, settings.webModulePath);
|
|
57
64
|
}
|
|
58
65
|
|
|
59
66
|
// Attempt to resolve the new request
|
|
60
67
|
try {
|
|
61
68
|
return originalResolveFilename.call(this, newRequest, parent, isMain, options);
|
|
62
|
-
}
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
63
71
|
// If it fails, continue to the next path
|
|
64
72
|
continue;
|
|
65
73
|
}
|