@sap-ux/project-access 1.29.13 → 1.29.14
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/dist/file/file-search.d.ts +2 -0
- package/dist/file/file-search.js +45 -10
- package/dist/project/cap.js +5 -23
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Editor } from 'mem-fs-editor';
|
|
2
2
|
/**
|
|
3
3
|
* Find function to search for files by names or file extensions.
|
|
4
|
+
* Empty name and extension option returns all files in the given folder.
|
|
4
5
|
*
|
|
5
6
|
* @param options - find options
|
|
6
7
|
* @param [options.fileNames] - optional array of file names to search for
|
|
@@ -10,6 +11,7 @@ import type { Editor } from 'mem-fs-editor';
|
|
|
10
11
|
* @param [options.memFs] - optional memfs editor instance
|
|
11
12
|
* @param [options.noTraversal] - optional flag to disable root path traversal
|
|
12
13
|
* @returns - array of paths that contain the file
|
|
14
|
+
* @throws Error[] - list of errors that occurred during the search
|
|
13
15
|
*/
|
|
14
16
|
export declare function findBy(options: {
|
|
15
17
|
fileNames?: string[];
|
package/dist/file/file-search.js
CHANGED
|
@@ -18,12 +18,16 @@ const fs_1 = require("fs");
|
|
|
18
18
|
* @param changes - memfs editor changes, usually retrieved by fs.dump()
|
|
19
19
|
* @param fileNames - array of file names to search for
|
|
20
20
|
* @param extensionNames - array of extensions names to search for
|
|
21
|
+
* @param root - path to root folder
|
|
21
22
|
* @returns - array of deleted and modified files filtered by query
|
|
22
23
|
*/
|
|
23
|
-
function getMemFsChanges(changes, fileNames, extensionNames) {
|
|
24
|
+
function getMemFsChanges(changes, fileNames, extensionNames, root) {
|
|
24
25
|
const deleted = [];
|
|
25
26
|
const modified = [];
|
|
26
|
-
const filteredChanges = Object.keys(changes).filter((f) =>
|
|
27
|
+
const filteredChanges = Object.keys(changes).filter((f) => f.startsWith(root.replaceAll(path_1.sep, path_1.posix.sep)) &&
|
|
28
|
+
(fileNames.includes((0, path_1.basename)(f)) ||
|
|
29
|
+
extensionNames.includes((0, path_1.extname)(f)) ||
|
|
30
|
+
(fileNames.length === 0 && extensionNames.length === 0)));
|
|
27
31
|
for (const file of filteredChanges) {
|
|
28
32
|
if (changes[file].state === 'deleted') {
|
|
29
33
|
deleted.push((0, path_1.join)(file));
|
|
@@ -34,8 +38,34 @@ function getMemFsChanges(changes, fileNames, extensionNames) {
|
|
|
34
38
|
}
|
|
35
39
|
return { deleted, modified };
|
|
36
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns the search results and fatal errors.
|
|
43
|
+
* This is required to include potential memfs changes in the search results.
|
|
44
|
+
*
|
|
45
|
+
* @param results - array of file paths that were found during the search.
|
|
46
|
+
* @param fileNames - array of file names that were searched for
|
|
47
|
+
* @param extensionNames - array of file extensions that were searched for
|
|
48
|
+
* @param root - root directory where the search was performed
|
|
49
|
+
* @param errors - array of errors that occurred during the search
|
|
50
|
+
* @param [memFs] - optional memfs editor instance
|
|
51
|
+
* @returns - object containing the search results and any fatal errors
|
|
52
|
+
*/
|
|
53
|
+
function getFindResultOnEnd(results, fileNames, extensionNames, root, errors, memFs) {
|
|
54
|
+
let searchResult = results;
|
|
55
|
+
let fatalErrors = errors;
|
|
56
|
+
if (memFs) {
|
|
57
|
+
const { modified, deleted } = getMemFsChanges(memFs.dump(''), fileNames, extensionNames, root);
|
|
58
|
+
const merged = Array.from(new Set([...results, ...modified]));
|
|
59
|
+
searchResult = merged.filter((f) => !deleted.includes(f));
|
|
60
|
+
// Filter out errors that are of type ENOENT and path is part of memfs changes, which can happen for folders that contain memfs files only.
|
|
61
|
+
fatalErrors = errors.filter((e) => e.code !== 'ENOENT' ||
|
|
62
|
+
(typeof e.path === 'string' && !modified.some((f) => f.startsWith(e.path))));
|
|
63
|
+
}
|
|
64
|
+
return { searchResult, fatalErrors };
|
|
65
|
+
}
|
|
37
66
|
/**
|
|
38
67
|
* Find function to search for files by names or file extensions.
|
|
68
|
+
* Empty name and extension option returns all files in the given folder.
|
|
39
69
|
*
|
|
40
70
|
* @param options - find options
|
|
41
71
|
* @param [options.fileNames] - optional array of file names to search for
|
|
@@ -45,6 +75,7 @@ function getMemFsChanges(changes, fileNames, extensionNames) {
|
|
|
45
75
|
* @param [options.memFs] - optional memfs editor instance
|
|
46
76
|
* @param [options.noTraversal] - optional flag to disable root path traversal
|
|
47
77
|
* @returns - array of paths that contain the file
|
|
78
|
+
* @throws Error[] - list of errors that occurred during the search
|
|
48
79
|
*/
|
|
49
80
|
function findBy(options) {
|
|
50
81
|
return new Promise((resolve, reject) => {
|
|
@@ -53,6 +84,7 @@ function findBy(options) {
|
|
|
53
84
|
const extensionNames = Array.isArray(options.extensionNames) ? options.extensionNames : [];
|
|
54
85
|
const excludeFolders = Array.isArray(options.excludeFolders) ? options.excludeFolders : [];
|
|
55
86
|
const noTraversal = options.noTraversal ?? false;
|
|
87
|
+
const errors = [];
|
|
56
88
|
const finder = (0, findit2_1.default)(options.root);
|
|
57
89
|
finder.on('directory', (dir, _stat, stop) => {
|
|
58
90
|
const base = (0, path_1.basename)(dir);
|
|
@@ -61,21 +93,24 @@ function findBy(options) {
|
|
|
61
93
|
}
|
|
62
94
|
});
|
|
63
95
|
finder.on('file', (file) => {
|
|
64
|
-
if (extensionNames.includes((0, path_1.extname)(file)) ||
|
|
96
|
+
if (extensionNames.includes((0, path_1.extname)(file)) ||
|
|
97
|
+
fileNames.includes((0, path_1.basename)(file)) ||
|
|
98
|
+
(fileNames.length === 0 && extensionNames.length === 0)) {
|
|
65
99
|
results.push(file);
|
|
66
100
|
}
|
|
67
101
|
});
|
|
68
102
|
finder.on('end', () => {
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
103
|
+
const { searchResult, fatalErrors } = getFindResultOnEnd(results, fileNames, extensionNames, options.root, errors, options.memFs);
|
|
104
|
+
if (fatalErrors.length === 0) {
|
|
105
|
+
resolve(searchResult);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// eslint-disable-next-line prefer-promise-reject-errors
|
|
109
|
+
reject(fatalErrors);
|
|
74
110
|
}
|
|
75
|
-
resolve(searchResult);
|
|
76
111
|
});
|
|
77
112
|
finder.on('error', (error) => {
|
|
78
|
-
|
|
113
|
+
errors.push(error);
|
|
79
114
|
});
|
|
80
115
|
});
|
|
81
116
|
}
|
package/dist/project/cap.js
CHANGED
|
@@ -51,30 +51,12 @@ async function isCapJavaProject(projectRoot, capCustomPaths, memFs) {
|
|
|
51
51
|
* @returns {Promise<boolean>} - Resolves to `true` if files are found in the `srv` folder; otherwise, `false`.
|
|
52
52
|
*/
|
|
53
53
|
async function checkFilesInSrvFolder(srvFolderPath, memFs) {
|
|
54
|
-
|
|
55
|
-
return await (0, file_1.
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// By loading the files, we ensure they are available within mem-fs.
|
|
60
|
-
if (await (0, file_1.fileExists)(srvFolderPath)) {
|
|
61
|
-
const fileSystemFiles = await (0, file_1.readDirectory)(srvFolderPath);
|
|
62
|
-
for (const file of fileSystemFiles) {
|
|
63
|
-
const filePath = (0, path_1.join)(srvFolderPath, file);
|
|
64
|
-
if (await (0, file_1.fileExists)(filePath)) {
|
|
65
|
-
const fileContent = await (0, file_1.readFile)(filePath);
|
|
66
|
-
memFs.write(filePath, fileContent);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
54
|
+
try {
|
|
55
|
+
return (await (0, file_1.findBy)({ root: srvFolderPath, memFs })).length > 0;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
return false;
|
|
69
59
|
}
|
|
70
|
-
// Dump the mem-fs state
|
|
71
|
-
const memFsDump = memFs.dump();
|
|
72
|
-
const memFsFiles = Object.keys(memFsDump).filter((filePath) => {
|
|
73
|
-
const normalisedFilePath = (0, path_1.resolve)(filePath);
|
|
74
|
-
const normalisedSrvPath = (0, path_1.resolve)(srvFolderPath);
|
|
75
|
-
return normalisedFilePath.startsWith(normalisedSrvPath);
|
|
76
|
-
});
|
|
77
|
-
return memFsFiles.length > 0;
|
|
78
60
|
}
|
|
79
61
|
/**
|
|
80
62
|
* Returns the CAP project type, undefined if it is not a CAP project.
|