@awesomeness-js/utils 1.0.17 → 1.0.18

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
@@ -9,6 +9,8 @@ import _convertBytes from './src/convertBytes.js';
9
9
  import _each from './src/each.js';
10
10
  import _eachAsync from './src/eachAsync.js';
11
11
  import _getAllFiles from './src/getAllFiles.js';
12
+ import _ignoreFolder_ignoreMe from './src/ignoreFolder/ignoreMe.js';
13
+ import _ignoreMe from './src/ignoreMe.js';
12
14
  import _isUUID from './src/isUUID.js';
13
15
  import _md5 from './src/md5.js';
14
16
  import _setLocalEnvs from './src/setLocalEnvs.js';
@@ -31,6 +33,7 @@ export { _convertBytes as convertBytes };
31
33
  export { _each as each };
32
34
  export { _eachAsync as eachAsync };
33
35
  export { _getAllFiles as getAllFiles };
36
+ export { _ignoreMe as ignoreMe };
34
37
  export { _isUUID as isUUID };
35
38
  export { _md5 as md5 };
36
39
  export { _setLocalEnvs as setLocalEnvs };
@@ -63,11 +66,15 @@ export default {
63
66
  each: _each,
64
67
  eachAsync: _eachAsync,
65
68
  getAllFiles: _getAllFiles,
69
+ ignoreMe: _ignoreMe,
66
70
  isUUID: _isUUID,
67
71
  md5: _md5,
68
72
  setLocalEnvs: _setLocalEnvs,
69
73
  toPennies: _toPennies,
70
74
  uuid: _uuid,
75
+ ignoreFolder: {
76
+ ignoreMe: _ignoreFolder_ignoreMe,
77
+ },
71
78
  utils: {
72
79
  buildExportsTree: _utils_buildExportsTree,
73
80
  buildFileDataList: _utils_buildFileDataList,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awesomeness-js/utils",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "Awesomeness - Utils",
5
5
  "repository": {
6
6
  "type": "git",
@@ -3,50 +3,46 @@ import { join } from 'path';
3
3
  import shouldIgnore from './utils/shouldIgnore.js';
4
4
 
5
5
  export default function getAllFiles(base, {
6
- dir = '.',
7
- files = [],
8
- ignore = [],
9
- fileTypes = []
6
+ dir = '.',
7
+ files = [],
8
+ ignore = [],
9
+ fileTypes = []
10
10
  } = {}) {
11
11
 
12
- const directory = join(base, dir);
13
- const normalizedDir = dir.replace(/\\/g, '/');
14
-
15
- if (ignore.some(pattern => normalizedDir.startsWith(pattern.replace(/\/\*$/, '')))) {
16
- return files;
17
- }
18
-
19
- const sortedFiles = readdirSync(directory).sort();
20
-
21
- sortedFiles.forEach(file => {
22
-
23
- const fullPath = join(directory, file);
24
- const relativePath = join(dir, file).replace(/\\/g, '/');
25
-
26
- if (shouldIgnore(relativePath, ignore)) {
27
- return;
28
- }
29
-
30
- if (statSync(fullPath).isDirectory()) {
31
-
32
- getAllFiles(base, {
33
- dir: join(dir, file),
34
- files,
35
- ignore
36
- });
37
-
38
- } else {
39
-
40
- if(fileTypes.length > 0) {
41
- if (!fileTypes.some(ext => file.endsWith(ext))) return;
42
- }
43
-
44
- files.push(relativePath);
45
-
46
- }
47
-
48
- });
49
-
50
- return files;
51
-
52
- }
12
+ const directory = join(base, dir);
13
+
14
+ const sortedFiles = readdirSync(directory).sort();
15
+
16
+ sortedFiles.forEach(file => {
17
+ const fullPath = join(directory, file);
18
+ // 1) Generate the original "relative path"
19
+ const relativePath = join(dir, file).replace(/\\/g, '/');
20
+
21
+ // 2) Prepend a slash so patterns like "/css/*.js" will match "/css/some.js"
22
+ const pathForIgnore = '/' + relativePath.replace(/^\/*/, '');
23
+
24
+ // 3) Check with the leading slash path
25
+ if (shouldIgnore(pathForIgnore, ignore)) {
26
+ return;
27
+ }
28
+
29
+ // Recurse if it's a directory
30
+ if (statSync(fullPath).isDirectory()) {
31
+ getAllFiles(base, {
32
+ dir: join(dir, file),
33
+ files,
34
+ ignore,
35
+ fileTypes
36
+ });
37
+ } else {
38
+ // Filter by file types if specified
39
+ if (fileTypes.length > 0 && !fileTypes.some(ext => file.endsWith(ext))) {
40
+ return;
41
+ }
42
+ // 4) Store the original relative path (without leading slash) in `files` if you prefer
43
+ files.push(relativePath);
44
+ }
45
+ });
46
+
47
+ return files;
48
+ }
@@ -1,17 +1,43 @@
1
1
  export default function shouldIgnore(filePath, ignorePatterns) {
2
- const ignore = ignorePatterns.some(pattern => {
3
- const normalizedPath = filePath.replace(/\\/g, '/');
4
- const normalizedPattern = pattern.replace(/\\/g, '/');
5
- if (normalizedPath === normalizedPattern) return true;
2
+ // filePath is already something like "/css/some.js"
3
+ return ignorePatterns.some(pattern => {
4
+ // pattern might be "/css/*.js" or "/ignoreFolder", etc.
5
+ let normalizedPattern = pattern.replace(/\\/g, '/');
6
+
7
+ // 1) Full directory ignore: "/ignoreFolder" => ignore "/ignoreFolder" + subdirectories
8
+ // If the pattern ends with "/", treat it as a directory path.
9
+ if (!normalizedPattern.includes('*')) {
10
+ // e.g. "/ignoreFolder/"
11
+ if (normalizedPattern.endsWith('/')) {
12
+ normalizedPattern = normalizedPattern.slice(0, -1); // remove trailing slash
13
+ }
14
+ return filePath === normalizedPattern || filePath.startsWith(normalizedPattern + '/');
15
+ }
16
+
17
+ // 2) folder/* => Ignore all immediate children in that folder (no subfolders)
6
18
  if (normalizedPattern.endsWith('/*')) {
7
- const baseDir = normalizedPattern.slice(0, -2);
8
- return normalizedPath.startsWith(baseDir + '/');
19
+ const baseFolder = normalizedPattern.slice(0, -2); // e.g. "/css"
20
+ // e.g. filePath === "/css/some.js" => startsWith("/css/")
21
+ // But also ensure there's no further subfolder.
22
+ return filePath.startsWith(baseFolder + '/') &&
23
+ !filePath.slice(baseFolder.length + 1).includes('/');
24
+ }
25
+
26
+ // 3) *.ext => extension-based ignore (any folder)
27
+ if (normalizedPattern.startsWith('*.')) {
28
+ const ext = normalizedPattern.slice(1); // remove '*'
29
+ return filePath.endsWith(ext);
9
30
  }
10
- if (normalizedPattern.endsWith('/')) {
11
- return normalizedPath === normalizedPattern.slice(0, -1) ||
12
- normalizedPath.startsWith(normalizedPattern);
31
+
32
+ // 4) folder/*.ext => only files with that extension in that folder (no subfolders)
33
+ if (normalizedPattern.includes('/*')) {
34
+ const [baseFolder, ext] = normalizedPattern.split('/*');
35
+ return filePath.startsWith(baseFolder + '/') &&
36
+ filePath.endsWith(ext) &&
37
+ !filePath.slice(baseFolder.length + 1).includes('/');
13
38
  }
14
- return false;
39
+
40
+ // 5) Exact match
41
+ return filePath === normalizedPattern;
15
42
  });
16
- return ignore;
17
- }
43
+ }
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ export default function ignoreMeTest() {
2
+ console.log('I should not be in the build!');
3
+ };
@@ -0,0 +1,3 @@
1
+ export default function ignoreMeTest() {
2
+ console.log('I should not be in the build!');
3
+ };
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ // just a test file to ignore
package/test.js CHANGED
@@ -1,10 +1,17 @@
1
1
  import utils from './index.js';
2
2
 
3
-
4
- let fileList2 = utils.getAllFiles('./secrets', {
5
- fileTypes: ['.env'],
6
- ignore: ['dev.env']
7
- });
3
+ let fileList2 = utils.getAllFiles('./test', {
4
+ // fileTypes: ['.css'],
5
+ // fileTypes: ['.js'],
6
+ ignore: [
7
+ "/ignoreFolder",
8
+ "/ignoreFolder2/",
9
+ "*.env",
10
+ "*.test.js",
11
+ "/css/*.js",
12
+ "/js/*.css"
13
+ ]
14
+ })
8
15
 
9
16
  console.log({fileList2});
10
17
 
package/types/index.d.ts CHANGED
@@ -9,6 +9,8 @@ import type _convertBytes from './convertBytes';
9
9
  import type _each from './each';
10
10
  import type _eachAsync from './eachAsync';
11
11
  import type _getAllFiles from './getAllFiles';
12
+ import type _ignoreFolder_ignoreMe from './ignoreFolder/ignoreMe';
13
+ import type _ignoreMe from './ignoreMe';
12
14
  import type _isUUID from './isUUID';
13
15
  import type _md5 from './md5';
14
16
  import type _setLocalEnvs from './setLocalEnvs';
@@ -31,6 +33,7 @@ export declare const convertBytes: typeof _convertBytes;
31
33
  export declare const each: typeof _each;
32
34
  export declare const eachAsync: typeof _eachAsync;
33
35
  export declare const getAllFiles: typeof _getAllFiles;
36
+ export declare const ignoreMe: typeof _ignoreMe;
34
37
  export declare const isUUID: typeof _isUUID;
35
38
  export declare const md5: typeof _md5;
36
39
  export declare const setLocalEnvs: typeof _setLocalEnvs;
@@ -63,11 +66,15 @@ declare const _default: {
63
66
  each: typeof _each;
64
67
  eachAsync: typeof _eachAsync;
65
68
  getAllFiles: typeof _getAllFiles;
69
+ ignoreMe: typeof _ignoreMe;
66
70
  isUUID: typeof _isUUID;
67
71
  md5: typeof _md5;
68
72
  setLocalEnvs: typeof _setLocalEnvs;
69
73
  toPennies: typeof _toPennies;
70
74
  uuid: typeof _uuid;
75
+ ignoreFolder: {
76
+ ignoreMe: typeof _ignoreFolder_ignoreMe,
77
+ },
71
78
  utils: {
72
79
  buildExportsTree: typeof _utils_buildExportsTree,
73
80
  buildFileDataList: typeof _utils_buildFileDataList,