Files
meteor/tools/fs
Ben Newman 646fa4e3ee Consider only named packages in optimisticLookupPackageJson.
Sometimes (very rarely) an npm package may contain package.json files
other than the one found in the root package directory. For example, the
date-fns@2.0.0-alpha.27 package includes a small package.json file for
each of its functions (date-fns/someDateFn/package.json) that contains
only { sideEffects, typings }, for whatever reason. These package.json
files clearly do not serve the same purpose as date-fns/package.json, and
it would be convenient to ignore them in optimisticLookupPackageJson. The
easiest way I can see to accomplish that is to ignore package.json files
that do not have a "name" property, since any package.json file that
governs an actual package must have a name.

Should fix #10547.
2019-05-06 17:23:06 -04:00
..
2015-08-03 22:09:28 -07:00
2019-01-16 22:16:51 -06:00

This folder contains modules that help communicating with the file-system.

files vs fs and files.path* vs path

Since the Meteor tool was originally written to work on Mac OS X and Linux but now is also required to work on Windows, there has been a decision to abstract the file-system calls to fs and path modules and make them go through the files.js lib.

All path and files manipulations in the tools code assumes it is running in a unixy environment, where the path separator is / and the default line-break symbol is \n; calls like rename and unlink are atomic and the file-system always works as you expect.

The files.js file tries its best to simulate this behavior on Windows, converting slashes, file contents and running FS operations in a "try/sleep/repeat" loop when an EBUSY error is returned. Operations on Windows happen to be slower, especially moving folders and symlinking (which is done by copying the directory instead).

It is advised to use files.readFile and others instead of fs.readFileSync. The methods are Fiberized and are converted on Windows.

Also files.pathJoin instead of path.join and others to properly preserve the unixy feel of paths: /C/Users/IEUser/AppData/Local instead of C:\Users\IEUser\AppData\Local.

mini-files

Some code is shared between the tool libs (this folder) and the code that gets copied to a built bundle (boot.js). The shared code is stored in mini-files.js.

File watching

Since node.js doesn't ship a stable library to watch a folder on all file-systems, a wrapper is used. The wrapper checks if the native functionality works, if not (while on Windows, or a virtualized shared file-system like in VirtualBox), polling is used.

Watchset

A specific data-structure that is a set of files and directories paths observed by the file-watcher.