File tree 2 files changed +29
-5
lines changed
2 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -147,24 +147,38 @@ describe('File Service', () => {
147
147
} ) ;
148
148
149
149
describe ( '#isDangerous' , ( ) => {
150
- it ( 'should get false if is considered dangerous' , ( ) => {
150
+ it ( 'should return false for paths that are not considered dangerous' , ( ) => {
151
151
expect (
152
152
fileService . isDangerous ( '/home/apps/myapp/node_modules' ) ,
153
153
) . toBeFalsy ( ) ;
154
154
expect ( fileService . isDangerous ( 'node_modules' ) ) . toBeFalsy ( ) ;
155
155
expect (
156
156
fileService . isDangerous ( '/home/user/projects/a/node_modules' ) ,
157
157
) . toBeFalsy ( ) ;
158
+ expect (
159
+ fileService . isDangerous ( '/Applications/NotAnApp/node_modules' ) ,
160
+ ) . toBeFalsy ( ) ;
161
+ expect (
162
+ fileService . isDangerous ( 'C:\\Users\\User\\Documents\\node_modules' ) ,
163
+ ) . toBeFalsy ( ) ;
158
164
} ) ;
159
165
160
- it ( 'should get true if is not considered dangerous ' , ( ) => {
166
+ it ( 'should return true for paths that are considered dangerous' , ( ) => {
161
167
expect (
162
168
fileService . isDangerous ( '/home/.config/myapp/node_modules' ) ,
163
169
) . toBeTruthy ( ) ;
164
170
expect ( fileService . isDangerous ( '.apps/node_modules' ) ) . toBeTruthy ( ) ;
165
171
expect (
166
172
fileService . isDangerous ( '.apps/.sample/node_modules' ) ,
167
173
) . toBeTruthy ( ) ;
174
+ expect (
175
+ fileService . isDangerous ( '/Applications/MyApp.app/node_modules' ) ,
176
+ ) . toBeTruthy ( ) ;
177
+ expect (
178
+ fileService . isDangerous (
179
+ 'C:\\Users\\User\\AppData\\Local\\node_modules' ,
180
+ ) ,
181
+ ) . toBeTruthy ( ) ;
168
182
} ) ;
169
183
} ) ;
170
184
Original file line number Diff line number Diff line change @@ -64,16 +64,26 @@ export abstract class FileService implements IFileService {
64
64
return path . includes ( targetFolder ) ;
65
65
}
66
66
67
- /** We consider a directory to be dangerous if it is hidden.
68
- *
67
+ /**
69
68
* > Why dangerous?
70
69
* It is probable that if the node_module is included in some hidden directory, it is
71
70
* required by some application like "spotify", "vscode" or "Discord" and deleting it
72
71
* would imply breaking the application (until the dependencies are reinstalled).
72
+ *
73
+ * In the case of macOS applications and Windows AppData directory, these locations often contain
74
+ * application-specific data or configurations that should not be tampered with. Deleting node_modules
75
+ * from these locations could potentially disrupt the normal operation of these applications.
73
76
*/
74
77
isDangerous ( path : string ) : boolean {
75
78
const hiddenFilePattern = / ( ^ | \/ ) \. [ ^ / . ] / g;
76
- return hiddenFilePattern . test ( path ) ;
79
+ const macAppsPattern = / ( ^ | \/ ) A p p l i c a t i o n s \/ [ ^ / ] + \. a p p \/ / g;
80
+ const windowsAppDataPattern = / ( ^ | \\ ) A p p D a t a \\ / g;
81
+
82
+ return (
83
+ hiddenFilePattern . test ( path ) ||
84
+ macAppsPattern . test ( path ) ||
85
+ windowsAppDataPattern . test ( path )
86
+ ) ;
77
87
}
78
88
79
89
async getRecentModificationInDir ( path : string ) : Promise < number > {
You can’t perform that action at this time.
0 commit comments