(watchSet: WatchSet, absPath: string)
| 843 | // *rely* on the hash being returned; merely that if the hash is |
| 844 | // present, it is the correct hash of the contents. |
| 845 | export function readAndWatchFileWithHash(watchSet: WatchSet, absPath: string) { |
| 846 | const result: { |
| 847 | contents: string | Buffer | null; |
| 848 | hash: string | null; |
| 849 | } = { |
| 850 | contents: null, |
| 851 | hash: null, |
| 852 | }; |
| 853 | |
| 854 | try { |
| 855 | result.contents = files.readFile(absPath); |
| 856 | } catch (e) { |
| 857 | if (e && e.code === "EISDIR") { |
| 858 | // Avoid adding directories to the watchSet as files. |
| 859 | return result; |
| 860 | } |
| 861 | |
| 862 | if (e && e.code === "ENOENT") { |
| 863 | // Continue, leaving result.{contents,hash} both null. |
| 864 | } else { |
| 865 | // Throw all other errors. |
| 866 | throw e; |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | if (result.contents !== null) { |
| 871 | result.hash = sha1(result.contents); |
| 872 | } |
| 873 | |
| 874 | // Allow null watchSet, if we want to use readFile-style error handling in a |
| 875 | // context where we might not always have a WatchSet (eg, reading |
| 876 | // settings.json where we watch for "meteor run" but not for "meteor deploy"). |
| 877 | if (watchSet) { |
| 878 | watchSet.addFile(absPath, result.hash); |
| 879 | } |
| 880 | |
| 881 | return result; |
| 882 | } |
| 883 | |
| 884 | export function readAndWatchFile(watchSet: WatchSet, absPath: string) { |
| 885 | return readAndWatchFileWithHash(watchSet, absPath).contents; |
no test coverage detected
searching dependent graphs…