@vercel/fs-detectors 2.1.0 → 3.1.0

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.
@@ -45,8 +45,12 @@ export declare abstract class DetectorFilesystem {
45
45
  readFile: (name: string) => Promise<Buffer>;
46
46
  /**
47
47
  * Returns a list of Stat objects from the current working directory.
48
+ * @param dirPath The path of the directory to read.
49
+ * @param options.potentialFiles optional. Array of potential file names (relative to the path). If provided, these will be used to mark the filesystem caches as existing or not existing.
48
50
  */
49
- readdir: (name: string) => Promise<Stat[]>;
51
+ readdir: (dirPath: string, options?: {
52
+ potentialFiles?: string[] | undefined;
53
+ } | undefined) => Promise<Stat[]>;
50
54
  /**
51
55
  * Changes the current directory to the specified path and returns a new instance of DetectorFilesystem.
52
56
  */
@@ -56,5 +60,5 @@ export declare abstract class DetectorFilesystem {
56
60
  * @param name the name of the file to write
57
61
  * @param content The content of the file
58
62
  */
59
- writeFile(name: string, content?: string): void;
63
+ writeFile: (name: string, content: string) => Promise<void>;
60
64
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DetectorFilesystem = void 0;
4
+ const path_1 = require("path");
4
5
  /**
5
6
  * `DetectorFilesystem` is an abstract class that represents a virtual filesystem
6
7
  * to perform read-only operations on in order to detect which framework is being
@@ -54,12 +55,34 @@ class DetectorFilesystem {
54
55
  };
55
56
  /**
56
57
  * Returns a list of Stat objects from the current working directory.
58
+ * @param dirPath The path of the directory to read.
59
+ * @param options.potentialFiles optional. Array of potential file names (relative to the path). If provided, these will be used to mark the filesystem caches as existing or not existing.
57
60
  */
58
- this.readdir = async (name) => {
59
- let p = this.readdirCache.get(name);
61
+ this.readdir = async (dirPath, options) => {
62
+ let p = this.readdirCache.get(dirPath);
60
63
  if (!p) {
61
- p = this._readdir(name);
62
- this.readdirCache.set(name, p);
64
+ p = this._readdir(dirPath);
65
+ this.readdirCache.set(dirPath, p);
66
+ const directoryContent = await p;
67
+ const directoryFiles = new Set();
68
+ for (const file of directoryContent) {
69
+ if (file.type === 'file') {
70
+ // we know this file exists, mark it as so on the filesystem
71
+ this.fileCache.set(file.path, Promise.resolve(true));
72
+ this.pathCache.set(file.path, Promise.resolve(true));
73
+ directoryFiles.add(file.name);
74
+ }
75
+ }
76
+ if (options?.potentialFiles) {
77
+ // calculate the set of paths that truly do not exist
78
+ const filesThatDoNotExist = options.potentialFiles.filter(path => !directoryFiles.has(path));
79
+ for (const filePath of filesThatDoNotExist) {
80
+ const fullFilePath = dirPath === '/' ? filePath : path_1.posix.join(dirPath, filePath);
81
+ // we know this file does not exist, mark it as so on the filesystem
82
+ this.fileCache.set(fullFilePath, Promise.resolve(false));
83
+ this.pathCache.set(fullFilePath, Promise.resolve(false));
84
+ }
85
+ }
63
86
  }
64
87
  return p;
65
88
  };
@@ -69,22 +92,21 @@ class DetectorFilesystem {
69
92
  this.chdir = (name) => {
70
93
  return this._chdir(name);
71
94
  };
95
+ /**
96
+ * Writes a file to the filesystem cache.
97
+ * @param name the name of the file to write
98
+ * @param content The content of the file
99
+ */
100
+ this.writeFile = async (name, content) => {
101
+ this.readFileCache.set(name, Promise.resolve(Buffer.from(content)));
102
+ this.fileCache.set(name, Promise.resolve(true));
103
+ this.pathCache.set(name, Promise.resolve(true));
104
+ };
72
105
  this.pathCache = new Map();
73
106
  this.fileCache = new Map();
74
107
  this.readFileCache = new Map();
75
108
  this.readdirCache = new Map();
76
109
  }
77
- /**
78
- * Writes a file to the filesystem cache.
79
- * @param name the name of the file to write
80
- * @param content The content of the file
81
- */
82
- writeFile(name, content) {
83
- if (content)
84
- this.readFileCache.set(name, Promise.resolve(Buffer.from(content)));
85
- this.fileCache.set(name, Promise.resolve(true));
86
- this.pathCache.set(name, Promise.resolve(true));
87
- }
88
110
  }
89
111
  exports.DetectorFilesystem = DetectorFilesystem;
90
112
  //# sourceMappingURL=filesystem.js.map
@@ -1 +1 @@
1
- {"version":3,"file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BACF;aACF;YACD,OAAO,CAAC,CAAC;QACX,CAAC,CAAC;QAEF;;WAEG;QACI,UAAK,GAAG,CAAC,IAAY,EAAsB,EAAE;YAClD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC,CAAC;QAEF;;;;WAIG;QACI,cAAS,GAAG,KAAK,EAAE,IAAY,EAAE,OAAe,EAAiB,EAAE;YACxE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACpE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YAChD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QAClD,CAAC,CAAC;QA5FA,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAE,CAAC;IAChC,CAAC;CAyFF;AA1GD,gDA0GC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/fs-detectors",
3
- "version": "2.1.0",
3
+ "version": "3.1.0",
4
4
  "description": "Vercel filesystem detectors",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "test-unit": "yarn test"
20
20
  },
21
21
  "dependencies": {
22
- "@vercel/frameworks": "1.1.3",
22
+ "@vercel/frameworks": "1.1.5",
23
23
  "@vercel/routing-utils": "2.0.2",
24
24
  "glob": "8.0.3",
25
25
  "js-yaml": "4.1.0",
@@ -36,5 +36,5 @@
36
36
  "@vercel/build-utils": "4.2.0",
37
37
  "typescript": "4.3.4"
38
38
  },
39
- "gitHead": "2906d83eaeddc72f9d874981dbe6698e812f3ca3"
39
+ "gitHead": "8b3c52b9e8cbf7de7fc51f76975374c4bb2fad56"
40
40
  }