@awesomeness-js/server 1.1.5 → 1.1.7
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/example-.awesomeness/config.js +2 -1
- package/index.js +101 -101
- package/package.json +1 -1
- package/src/componentDependencies.js +71 -40
package/index.js
CHANGED
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is auto-generated by the build script.
|
|
3
|
-
* It consolidates API functions for use in the application.
|
|
4
|
-
* Do not edit manually.
|
|
5
|
-
*/
|
|
6
|
-
import _applicationMap from './src/applicationMap.js';
|
|
7
|
-
import _awesomenessNormalizeRequest from './src/awesomenessNormalizeRequest.js';
|
|
8
|
-
import _brotliJsonResponse from './src/brotliJsonResponse.js';
|
|
9
|
-
import _checkAccess from './src/checkAccess.js';
|
|
10
|
-
import _componentDependencies from './src/componentDependencies.js';
|
|
11
|
-
import _config from './src/config.js';
|
|
12
|
-
import _fetchPage from './src/fetchPage.js';
|
|
13
|
-
import _getConfig from './src/getConfig.js';
|
|
14
|
-
import _getMD from './src/getMD.js';
|
|
15
|
-
import _init from './src/init.js';
|
|
16
|
-
import _koa_attachAwesomenessRequest from './src/koa/attachAwesomenessRequest.js';
|
|
17
|
-
import _koa_cors from './src/koa/cors.js';
|
|
18
|
-
import _koa_errorHandler from './src/koa/errorHandler.js';
|
|
19
|
-
import _koa_finalFormat from './src/koa/finalFormat.js';
|
|
20
|
-
import _koa_jsonBodyParser from './src/koa/jsonBodyParser.js';
|
|
21
|
-
import _koa_routeRequest from './src/koa/routeRequest.js';
|
|
22
|
-
import _koa_serverUp from './src/koa/serverUp.js';
|
|
23
|
-
import _koa_staticFiles from './src/koa/staticFiles.js';
|
|
24
|
-
import _koa_timeout from './src/koa/timeout.js';
|
|
25
|
-
import _pageInfo from './src/pageInfo.js';
|
|
26
|
-
import _reRoute from './src/reRoute.js';
|
|
27
|
-
import _resolveRealCasePath from './src/resolveRealCasePath.js';
|
|
28
|
-
import _specialPaths from './src/specialPaths.js';
|
|
29
|
-
import _start from './src/start.js';
|
|
30
|
-
import _validateRequest from './src/validateRequest.js';
|
|
31
|
-
import _ws_handlers from './src/ws/handlers.js';
|
|
32
|
-
import _ws_index from './src/ws/index.js';
|
|
33
|
-
|
|
34
|
-
export { _applicationMap as applicationMap };
|
|
35
|
-
export { _awesomenessNormalizeRequest as awesomenessNormalizeRequest };
|
|
36
|
-
export { _brotliJsonResponse as brotliJsonResponse };
|
|
37
|
-
export { _checkAccess as checkAccess };
|
|
38
|
-
export { _componentDependencies as componentDependencies };
|
|
39
|
-
export { _config as config };
|
|
40
|
-
export { _fetchPage as fetchPage };
|
|
41
|
-
export { _getConfig as getConfig };
|
|
42
|
-
export { _getMD as getMD };
|
|
43
|
-
export { _init as init };
|
|
44
|
-
export { _pageInfo as pageInfo };
|
|
45
|
-
export { _reRoute as reRoute };
|
|
46
|
-
export { _resolveRealCasePath as resolveRealCasePath };
|
|
47
|
-
export { _specialPaths as specialPaths };
|
|
48
|
-
export { _start as start };
|
|
49
|
-
export { _validateRequest as validateRequest };
|
|
50
|
-
|
|
51
|
-
export const koa = {
|
|
52
|
-
attachAwesomenessRequest: _koa_attachAwesomenessRequest,
|
|
53
|
-
cors: _koa_cors,
|
|
54
|
-
errorHandler: _koa_errorHandler,
|
|
55
|
-
finalFormat: _koa_finalFormat,
|
|
56
|
-
jsonBodyParser: _koa_jsonBodyParser,
|
|
57
|
-
routeRequest: _koa_routeRequest,
|
|
58
|
-
serverUp: _koa_serverUp,
|
|
59
|
-
staticFiles: _koa_staticFiles,
|
|
60
|
-
timeout: _koa_timeout
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const ws = {
|
|
64
|
-
handlers: _ws_handlers,
|
|
65
|
-
index: _ws_index
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export default {
|
|
70
|
-
applicationMap: _applicationMap,
|
|
71
|
-
awesomenessNormalizeRequest: _awesomenessNormalizeRequest,
|
|
72
|
-
brotliJsonResponse: _brotliJsonResponse,
|
|
73
|
-
checkAccess: _checkAccess,
|
|
74
|
-
componentDependencies: _componentDependencies,
|
|
75
|
-
config: _config,
|
|
76
|
-
fetchPage: _fetchPage,
|
|
77
|
-
getConfig: _getConfig,
|
|
78
|
-
getMD: _getMD,
|
|
79
|
-
init: _init,
|
|
80
|
-
pageInfo: _pageInfo,
|
|
81
|
-
reRoute: _reRoute,
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto-generated by the build script.
|
|
3
|
+
* It consolidates API functions for use in the application.
|
|
4
|
+
* Do not edit manually.
|
|
5
|
+
*/
|
|
6
|
+
import _applicationMap from './src/applicationMap.js';
|
|
7
|
+
import _awesomenessNormalizeRequest from './src/awesomenessNormalizeRequest.js';
|
|
8
|
+
import _brotliJsonResponse from './src/brotliJsonResponse.js';
|
|
9
|
+
import _checkAccess from './src/checkAccess.js';
|
|
10
|
+
import _componentDependencies from './src/componentDependencies.js';
|
|
11
|
+
import _config from './src/config.js';
|
|
12
|
+
import _fetchPage from './src/fetchPage.js';
|
|
13
|
+
import _getConfig from './src/getConfig.js';
|
|
14
|
+
import _getMD from './src/getMD.js';
|
|
15
|
+
import _init from './src/init.js';
|
|
16
|
+
import _koa_attachAwesomenessRequest from './src/koa/attachAwesomenessRequest.js';
|
|
17
|
+
import _koa_cors from './src/koa/cors.js';
|
|
18
|
+
import _koa_errorHandler from './src/koa/errorHandler.js';
|
|
19
|
+
import _koa_finalFormat from './src/koa/finalFormat.js';
|
|
20
|
+
import _koa_jsonBodyParser from './src/koa/jsonBodyParser.js';
|
|
21
|
+
import _koa_routeRequest from './src/koa/routeRequest.js';
|
|
22
|
+
import _koa_serverUp from './src/koa/serverUp.js';
|
|
23
|
+
import _koa_staticFiles from './src/koa/staticFiles.js';
|
|
24
|
+
import _koa_timeout from './src/koa/timeout.js';
|
|
25
|
+
import _pageInfo from './src/pageInfo.js';
|
|
26
|
+
import _reRoute from './src/reRoute.js';
|
|
27
|
+
import _resolveRealCasePath from './src/resolveRealCasePath.js';
|
|
28
|
+
import _specialPaths from './src/specialPaths.js';
|
|
29
|
+
import _start from './src/start.js';
|
|
30
|
+
import _validateRequest from './src/validateRequest.js';
|
|
31
|
+
import _ws_handlers from './src/ws/handlers.js';
|
|
32
|
+
import _ws_index from './src/ws/index.js';
|
|
33
|
+
|
|
34
|
+
export { _applicationMap as applicationMap };
|
|
35
|
+
export { _awesomenessNormalizeRequest as awesomenessNormalizeRequest };
|
|
36
|
+
export { _brotliJsonResponse as brotliJsonResponse };
|
|
37
|
+
export { _checkAccess as checkAccess };
|
|
38
|
+
export { _componentDependencies as componentDependencies };
|
|
39
|
+
export { _config as config };
|
|
40
|
+
export { _fetchPage as fetchPage };
|
|
41
|
+
export { _getConfig as getConfig };
|
|
42
|
+
export { _getMD as getMD };
|
|
43
|
+
export { _init as init };
|
|
44
|
+
export { _pageInfo as pageInfo };
|
|
45
|
+
export { _reRoute as reRoute };
|
|
46
|
+
export { _resolveRealCasePath as resolveRealCasePath };
|
|
47
|
+
export { _specialPaths as specialPaths };
|
|
48
|
+
export { _start as start };
|
|
49
|
+
export { _validateRequest as validateRequest };
|
|
50
|
+
|
|
51
|
+
export const koa = {
|
|
52
|
+
attachAwesomenessRequest: _koa_attachAwesomenessRequest,
|
|
53
|
+
cors: _koa_cors,
|
|
54
|
+
errorHandler: _koa_errorHandler,
|
|
55
|
+
finalFormat: _koa_finalFormat,
|
|
56
|
+
jsonBodyParser: _koa_jsonBodyParser,
|
|
57
|
+
routeRequest: _koa_routeRequest,
|
|
58
|
+
serverUp: _koa_serverUp,
|
|
59
|
+
staticFiles: _koa_staticFiles,
|
|
60
|
+
timeout: _koa_timeout
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const ws = {
|
|
64
|
+
handlers: _ws_handlers,
|
|
65
|
+
index: _ws_index
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
export default {
|
|
70
|
+
applicationMap: _applicationMap,
|
|
71
|
+
awesomenessNormalizeRequest: _awesomenessNormalizeRequest,
|
|
72
|
+
brotliJsonResponse: _brotliJsonResponse,
|
|
73
|
+
checkAccess: _checkAccess,
|
|
74
|
+
componentDependencies: _componentDependencies,
|
|
75
|
+
config: _config,
|
|
76
|
+
fetchPage: _fetchPage,
|
|
77
|
+
getConfig: _getConfig,
|
|
78
|
+
getMD: _getMD,
|
|
79
|
+
init: _init,
|
|
80
|
+
pageInfo: _pageInfo,
|
|
81
|
+
reRoute: _reRoute,
|
|
82
82
|
/**
|
|
83
83
|
* Case-insensitive real path resolver.
|
|
84
84
|
* Works correctly on Windows, macOS, and Linux/Docker.
|
|
85
|
-
*/
|
|
86
|
-
resolveRealCasePath: _resolveRealCasePath,
|
|
87
|
-
specialPaths: _specialPaths,
|
|
88
|
-
start: _start,
|
|
89
|
-
validateRequest: _validateRequest,
|
|
90
|
-
koa: {
|
|
91
|
-
attachAwesomenessRequest: _koa_attachAwesomenessRequest,
|
|
92
|
-
cors: _koa_cors,
|
|
93
|
-
errorHandler: _koa_errorHandler,
|
|
94
|
-
finalFormat: _koa_finalFormat,
|
|
95
|
-
jsonBodyParser: _koa_jsonBodyParser,
|
|
96
|
-
routeRequest: _koa_routeRequest,
|
|
97
|
-
serverUp: _koa_serverUp,
|
|
98
|
-
staticFiles: _koa_staticFiles,
|
|
99
|
-
timeout: _koa_timeout,
|
|
100
|
-
},
|
|
101
|
-
ws: {
|
|
102
|
-
handlers: _ws_handlers,
|
|
103
|
-
index: _ws_index,
|
|
104
|
-
},
|
|
85
|
+
*/
|
|
86
|
+
resolveRealCasePath: _resolveRealCasePath,
|
|
87
|
+
specialPaths: _specialPaths,
|
|
88
|
+
start: _start,
|
|
89
|
+
validateRequest: _validateRequest,
|
|
90
|
+
koa: {
|
|
91
|
+
attachAwesomenessRequest: _koa_attachAwesomenessRequest,
|
|
92
|
+
cors: _koa_cors,
|
|
93
|
+
errorHandler: _koa_errorHandler,
|
|
94
|
+
finalFormat: _koa_finalFormat,
|
|
95
|
+
jsonBodyParser: _koa_jsonBodyParser,
|
|
96
|
+
routeRequest: _koa_routeRequest,
|
|
97
|
+
serverUp: _koa_serverUp,
|
|
98
|
+
staticFiles: _koa_staticFiles,
|
|
99
|
+
timeout: _koa_timeout,
|
|
100
|
+
},
|
|
101
|
+
ws: {
|
|
102
|
+
handlers: _ws_handlers,
|
|
103
|
+
index: _ws_index,
|
|
104
|
+
},
|
|
105
105
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import path from "path";
|
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
import { each, getAllFiles } from "@awesomeness-js/utils";
|
|
4
4
|
import { readFileSync } from "fs";
|
|
5
|
-
|
|
5
|
+
import getConfig from "./getConfig.js";
|
|
6
6
|
|
|
7
7
|
function urlToFsPath(u) {
|
|
8
8
|
|
|
@@ -50,12 +50,17 @@ function extractUiFirstParts(str) {
|
|
|
50
50
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export default function componentDependencies(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
export default function componentDependencies(
|
|
54
|
+
allComponents,
|
|
55
|
+
{
|
|
56
|
+
componentLocations = [],
|
|
57
|
+
namespace = "ui",
|
|
58
|
+
showDetails = false,
|
|
59
|
+
ignore = [ "*.css.js" ],
|
|
60
|
+
} = {}
|
|
61
|
+
) {
|
|
62
|
+
|
|
63
|
+
const awesomenessConfig = getConfig();
|
|
59
64
|
|
|
60
65
|
if (!Array.isArray(componentLocations) || componentLocations.length === 0) {
|
|
61
66
|
|
|
@@ -77,17 +82,12 @@ export default function componentDependencies(allComponents, {
|
|
|
77
82
|
|
|
78
83
|
// baseUrl should point at a directory; we resolve component under it
|
|
79
84
|
const componentUrl = new URL(`./${component}/`, baseUrl);
|
|
80
|
-
|
|
85
|
+
|
|
86
|
+
|
|
81
87
|
return path.resolve(urlToFsPath(componentUrl));
|
|
82
88
|
|
|
83
89
|
});
|
|
84
90
|
|
|
85
|
-
// console.log({
|
|
86
|
-
// "import.meta.url =": import.meta.url,
|
|
87
|
-
// component,
|
|
88
|
-
// candidateRoots
|
|
89
|
-
// });
|
|
90
|
-
|
|
91
91
|
let allFiles;
|
|
92
92
|
let chosenRoot;
|
|
93
93
|
let lastErr;
|
|
@@ -96,26 +96,24 @@ export default function componentDependencies(allComponents, {
|
|
|
96
96
|
|
|
97
97
|
try {
|
|
98
98
|
|
|
99
|
+
// IMPORTANT: pass root so getAllFiles returns paths relative to the scan root
|
|
99
100
|
allFiles = getAllFiles(".", {
|
|
100
101
|
dir: root,
|
|
101
|
-
|
|
102
|
+
root,
|
|
103
|
+
ignore,
|
|
102
104
|
});
|
|
103
105
|
|
|
104
106
|
chosenRoot = root;
|
|
105
|
-
|
|
106
107
|
break; // first match wins
|
|
107
108
|
|
|
108
|
-
} catch(e) {
|
|
109
|
+
} catch (e) {
|
|
109
110
|
|
|
110
|
-
// try next
|
|
111
111
|
lastErr = e;
|
|
112
112
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
|
|
119
117
|
if (!allFiles) {
|
|
120
118
|
|
|
121
119
|
throw {
|
|
@@ -127,35 +125,52 @@ export default function componentDependencies(allComponents, {
|
|
|
127
125
|
|
|
128
126
|
}
|
|
129
127
|
|
|
128
|
+
if (
|
|
129
|
+
awesomenessConfig.debug_componentDependencies &&
|
|
130
|
+
Array.isArray(awesomenessConfig.debug_componentDependencies) &&
|
|
131
|
+
awesomenessConfig.debug_componentDependencies.includes(component)
|
|
132
|
+
) {
|
|
133
|
+
|
|
134
|
+
console.log("[awesomenessConfig.debug componentDependencies] chosenRoot:", chosenRoot);
|
|
135
|
+
console.log("[awesomenessConfig.debug componentDependencies] allFiles count:", allFiles.length);
|
|
136
|
+
console.log("[awesomenessConfig.debug componentDependencies] first 50 files:", allFiles.slice(0, 50));
|
|
137
|
+
console.log(
|
|
138
|
+
"[awesomenessConfig.debug componentDependencies] any non-string:",
|
|
139
|
+
allFiles.some((f) => typeof f !== "string")
|
|
140
|
+
);
|
|
141
|
+
console.log(
|
|
142
|
+
"[awesomenessConfig.debug componentDependencies] any absolute:",
|
|
143
|
+
allFiles.some((f) => path.isAbsolute(f))
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
130
148
|
allFiles.forEach((file) => {
|
|
131
149
|
|
|
132
150
|
const normalizedPath = path.normalize(file);
|
|
133
|
-
const pathSegments = normalizedPath.split(path.sep);
|
|
134
|
-
|
|
135
|
-
const variableIndex = pathSegments.indexOf(component);
|
|
136
151
|
|
|
137
|
-
|
|
152
|
+
const fileNameFull = path.basename(normalizedPath);
|
|
138
153
|
const fileTypeArr = fileNameFull.split(".");
|
|
139
|
-
const fileType = fileTypeArr[fileTypeArr.length - 1];
|
|
154
|
+
const fileType = fileTypeArr[fileTypeArr.length - 1].toLowerCase();
|
|
140
155
|
const fileName = fileTypeArr.slice(0, -1).join(".");
|
|
141
156
|
|
|
142
157
|
out[component] = out[component] || {};
|
|
143
158
|
out[component][fileType] = out[component][fileType] || {};
|
|
144
159
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
160
|
+
// Build tail from the file's relative directory (NOT by searching for `component` in the path)
|
|
161
|
+
const dir = path.dirname(normalizedPath);
|
|
162
|
+
const dirParts = dir === "." ? [] : dir.split(path.sep);
|
|
148
163
|
|
|
149
164
|
let tail = "";
|
|
150
165
|
|
|
151
166
|
if (fileType === "js" || fileType === "css") {
|
|
152
167
|
|
|
153
|
-
if (
|
|
168
|
+
if (dirParts.length > 0) {
|
|
154
169
|
|
|
155
170
|
tail =
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
171
|
+
fileName === "index"
|
|
172
|
+
? "." + dirParts.join(".")
|
|
173
|
+
: `.${dirParts.join(".")}.${fileName}`;
|
|
159
174
|
|
|
160
175
|
} else {
|
|
161
176
|
|
|
@@ -169,7 +184,10 @@ export default function componentDependencies(allComponents, {
|
|
|
169
184
|
|
|
170
185
|
try {
|
|
171
186
|
|
|
172
|
-
|
|
187
|
+
// readFileSync must use chosenRoot + relative file path
|
|
188
|
+
const filePath = path.isAbsolute(file) ? file : path.join(chosenRoot, file);
|
|
189
|
+
const fileContent = readFileSync(filePath, "utf-8");
|
|
190
|
+
|
|
173
191
|
const lines = fileContent.split("\n");
|
|
174
192
|
let fileWithImportsStripped = "";
|
|
175
193
|
|
|
@@ -208,7 +226,9 @@ export default function componentDependencies(allComponents, {
|
|
|
208
226
|
|
|
209
227
|
if (imports.length > 1) {
|
|
210
228
|
|
|
211
|
-
const importComponents = imports[1]
|
|
229
|
+
const importComponents = imports[1]
|
|
230
|
+
.split(",")
|
|
231
|
+
.map((c) => c.trim());
|
|
212
232
|
|
|
213
233
|
importComponents.forEach((importComponent) => {
|
|
214
234
|
|
|
@@ -226,15 +246,17 @@ export default function componentDependencies(allComponents, {
|
|
|
226
246
|
}
|
|
227
247
|
|
|
228
248
|
} else if (
|
|
229
|
-
line.startsWith("// awesomeness import")
|
|
230
|
-
|
|
249
|
+
line.startsWith("// awesomeness import") ||
|
|
250
|
+
line.startsWith("/* awesomeness @import")
|
|
231
251
|
) {
|
|
232
252
|
|
|
233
253
|
const importPathMatch = line.match(/['"]([^'"]+)['"]/);
|
|
234
254
|
|
|
235
255
|
if (importPathMatch) {
|
|
236
256
|
|
|
237
|
-
const importedComponentName = importPathMatch[1]
|
|
257
|
+
const importedComponentName = importPathMatch[1]
|
|
258
|
+
.replace(/;$/, "")
|
|
259
|
+
.trim();
|
|
238
260
|
|
|
239
261
|
if (!allComponents.includes(importedComponentName)) {
|
|
240
262
|
|
|
@@ -256,8 +278,8 @@ export default function componentDependencies(allComponents, {
|
|
|
256
278
|
if (fileType === "js") {
|
|
257
279
|
|
|
258
280
|
if (
|
|
259
|
-
fileWithImportsStripped.startsWith("(function")
|
|
260
|
-
|
|
281
|
+
fileWithImportsStripped.startsWith("(function") ||
|
|
282
|
+
fileWithImportsStripped.startsWith("((")
|
|
261
283
|
) {
|
|
262
284
|
|
|
263
285
|
fileWithImportsStripped = `;${fileWithImportsStripped}`;
|
|
@@ -277,7 +299,16 @@ export default function componentDependencies(allComponents, {
|
|
|
277
299
|
|
|
278
300
|
} catch (err) {
|
|
279
301
|
|
|
280
|
-
|
|
302
|
+
const full = path.isAbsolute(file) ? file : path.join(chosenRoot, file);
|
|
303
|
+
|
|
304
|
+
console.error("Failed to get dependencies", {
|
|
305
|
+
component,
|
|
306
|
+
file,
|
|
307
|
+
full,
|
|
308
|
+
code: err?.code,
|
|
309
|
+
message: err?.message,
|
|
310
|
+
stack: err?.stack,
|
|
311
|
+
});
|
|
281
312
|
|
|
282
313
|
}
|
|
283
314
|
|