UNPKG

20.2 kBMarkdownView Raw
1# fyn
2
3**A fast node package manager for better productivity and efficiency**
4
5[![NPM version][npm-image]][npm-url]
6[![Apache 2.0 License][apache-2.0-blue-image]][apache-2.0-url]
7[![Build Status][travis-image]][travis-url]
8[![Coverage Status][coveralls-image]][coveralls-url]
9[![Dependency Status][daviddm-image]][daviddm-url] [![devDependency Status][daviddm-dev-image]][daviddm-dev-url]
10
11`fyn` is a super fast node package manager with some unique features:
12
13- enhanced [npm link] with [fynlocal mode](#fynlocal-mode)
14- efficient disk space usage with [central storage](#central-storage)
15- smaller `node_modules` with [guaranteed single copy of a package](#smaller-node_modules)
16- flexible dependencies lock by using a [lock time stamp](#locking-dependencies-by-time)
17- and [more](#features)
18
19![fyn demo][fyn-demo-gif]
20
21## Quick Start
22
23Interested in giving it a quick test? Just install and run it on your project:
24
25```sh
26npm i -g fyn
27cd <your-project>
28fyn
29```
30
31- It can read and use some settings from your `.npmrc`.
32- It can use `npm-shrinkwrap.json` or `package-lock.json` files.
33
34## Table Of Contents
35
36- [Features](#features)
37 - [Unique](#unique)
38 - [General](#general)
39- [Overview](#overview)
40 - [Rationale](#rationale)
41 - [Enhanced `npm link`](#enhanced-npm-link)
42 - [`fynlocal` mode](#fynlocal-mode)
43 - [Smaller `node_modules`](#smaller-node_modules)
44 - [Easier Debugging `node_modules`](#easier-debugging-node_modules)
45- [Using fyn](#using-fyn)
46 - [Installing `fyn`](#installing-fyn)
47 - [Installing Your Dependencies](#installing-your-dependencies)
48 - [Running npm scripts](#running-npm-scripts)
49 - [The `stat` command](#the-stat-command)
50 - [Locking Dependencies by Time](#locking-dependencies-by-time)
51 - [Refreshing Optional Dependencies](#refreshing-optional-dependencies)
52 - [Using with Lerna](#using-with-lerna)
53- [Configuring fyn](#configuring-fyn)
54 - [Command Line Option to RC Mapping](#command-line-option-to-rc-mapping)
55 - [Other RC Options](#other-rc-options)
56 - [Scope registry](#scope-registry)
57 - [Central Storage](#central-storage)
58- [Other Info](#other-info)
59 - [Compatibility](#compatibility)
60 - [Package Resolution and Layout](#package-resolution-and-layout)
61 - [Thank you `npm`](#thank-you-npm)
62- [License](#license)
63
64## Features
65
66### Unique
67
68- Focus on improving workflow and productivity.
69- Very comprehensive and proper handling of `optionalDependencies`.
70- A new `devOptDependencies` allows optional `devDependencies`.
71- [Guaranteed single copy of a package](#flatten-nodemodules) => smaller `node_modules`.
72- The best at installing and linking local packages - better [npm link].
73- Install local packages like they are published (`fynlocal` mode)
74- Works particularly well with [lerna] monorepos.
75- Shows detailed stats of your dependencies.
76- Efficient disk space usage with optional [central storage](#central-storage).
77- Central storage mode is fast (and very fast on Linux) once cache is hot.
78- Install dependencies with a time stamp lock.
79
80### General
81
82- A super fast node package manager for installing modules.
83- Production quality with a lot of unit tests and verified on real applications.
84- 100% compatible with Node.js and its ecosystem.
85- A flat and simple dependency lock file that can be diffed and edited.
86- Always deterministic `node_modules` installation.
87- Compatible with [npm] by internally using the same modules as [npm].
88- Maintains as much of [npm]'s behaviors as possible.
89- Able to use [npm]'s `npm-shrinkwrap.json` or `package-lock.json`.
90
91## Overview
92
93`fyn` is the result of a long pursuit to make developing and managing large and complex software in Node.js easier.
94To realize that, it ultimately ends up being a node package manager.
95
96It started out as small experiments for a single goal of better local package installing and linking, ie: better [npm link], but has gradually grown to a fully functional node package manager for the [flat node_modules design]. It is fast, production quality, and maintains [100% compatibility](#compatibility).
97
98While it has all the bells and whistles to make it an extremely fast and efficient package manager, it's not just another [npm].
99
100It comes with two unique features that are very useful when you are working on a large Node.js application that consists of many packages.
101
102## Rationale
103
104So why would you want to use this? If you just want to try a different approach to installing your `node_modules`, then it's worth a look.
105
106`fyn`'s flatten `node_modules` is the smallest in size because there are no multiple copies of the exact same package installed.
107
108It also has a special `fynlocal` mode that's a better [npm link] for handling local packages.
109
110If your development in Node.js are typically simple and involves only a single module or small applications, then `fyn`'s advantage may not be apparent to you, but if your Node.js project is large and complex, then fyn may be helpful to you. Please read further to learn more.
111
112## Enhanced `npm link`
113
114`fyn` has a `fynlocal` mode that's designed specifically to be a much better [npm link]. It treats packages on your local disk like they've been published. You can install and use them directly, and quickly test changes iteratively. It would be very useful if you've ever done any of these:
115
116- Debug your application by inspecting code inside `node_modules`.
117- Live edit your package that's installed to `node_modules`, and then have to copy the changes out to commit.
118- Use [lerna] to maintain and develop multiple packages. `fyn` works particularly well with a [lerna] repo.
119- Or just have to juggle a lot of packages as part of your development.
120
121### `fynlocal` mode
122
123What is this? Think [npm link], but better. `fyn` subjects local packages to the same dependency resolution logic as those from the npm registry. Then you can test changes to any module locally as if they were published.
124
125To enable, use the path to your local modules as semver in your package.json, or you can use the `fyn add` command.
126
127For example:
128
129```sh
130fyn add ../my-awesome-module
131```
132
133That will install `my-awesome-module` into your node_modules. You can continue to develop and test `my-awesome-module` in its own directory and have the changes within existing files reflected in your app directly. Unlike `npm link`, your app resolves dependencies for `my-awesome-module` instead of relying on having them installed under `my-awesome-module/node_modules`.
134
135If you add/remove files/directories in your local package, then running `fyn` install would take only seconds to update.
136
137`fyn` will also save a file `package-fyn.json` with local dependencies in a section called `fyn`. You should not commit this file and `.gitignore` it. `fyn` will automatically check this file when installing, but you can turn off `fynlocal` mode with with the flag `--no-fynlocal` easily.
138
139## Smaller `node_modules`
140
141As a package manager, `fyn` employs a different approach that installs only one copy of every required versions of a package in a flat node_modules structure. Hence the name `fyn`, which stands for Flatten Your Node_modules.
142
143At the top level, it installs a chosen version of each package. All other versions are installed under the directory `node_modules/__fv_/<version>/<package_name>`.
144
145When necessary, packages have their own `node_modules` with symlinks/junctions inside pointing to dependencies under `__fv_`.
146
147This approach has the benefit of guaranteeing a single copy of a package installed and therefore slightly smaller size `node_modules`.
148
149## Easier Debugging `node_modules`
150
151With a guaranteed single copy of a package, it makes debugging easier when you have to reach into code under `node_modules`.
152
153`node_modules` installed by [npm] could potentially have multiple copies of an identical package. So even if you've identified the module under `node_modules` to investigate your issue, you may still need to figure which copy.
154
155With `fyn`'s flat `node_modules` design, there is only one copy of any version so it's easier for you to set your breakpoint.
156
157## Using fyn
158
159### Installing `fyn`
160
161Please install `fyn` to your Node.js setup globally.
162
163```sh
164npm install -g fyn
165```
166
167### Installing Your Dependencies
168
169Change into the directory for your project with the `package.json` file, and run:
170
171```sh
172fyn
173```
174
175- Which is a shorthand for `fyn install` since `install` is the default command.
176
177Depending on the size of your dependencies and your network speed, this could take anywhere from a few seconds to a few minutes.
178
179### Running npm scripts
180
181As a convenience, `fyn` implements `npm run` by utilizing the same modules from [npm]. You can run your [npm scripts] in `package.json`. An alias command `fun` is available also:
182
183- `test` - `fyn test` or `fun test`
184- any script - `fyn run <script-name>` or `fun <script-name>`
185- list scripts - `fyn run -l` or `fun -l`
186
187### The `stat` command
188
189If you have a lockfile, then `fyn` takes sub seconds to regenerate the entire dependency tree even on very large applications. This makes it very fast to probe what's installed.
190
191It has a `stat` command that's very fast and can let you know all copies of a package installed and all others that depend on it.
192
193For example:
194
195```sh
196$ fyn stat chalk
197> loaded lockfile ~/fyn
198> done resolving dependencies 0.113secs
199> chalk matched these installed versions chalk@2.4.1, chalk@1.1.3(fv)
200> chalk@2.4.1 has these dependents eslint@4.19.1, inquirer@3.3.0, table@4.0.2, visual-exec@0.1.0, visual-logger@0.1.8, webpack-bundle-analyzer@2.13.1, xclap@0.2.24, ~package.json
201> chalk@1.1.3 has these dependents babel-code-frame@6.26.0, electrode-server@1.5.1
202```
203
204#### Locking Dependencies by Time
205
206Ever want to install your dependencies only consider packages published up to a certain date in the past? `fyn`'s got you covered with the `--lock-time` option.
207
208- First rename or remove `fyn-lock.yaml` file.
209- Then run install like this:
210
211```sh
212rm fyn-lock.yaml
213fyn install --lock-time "12/01/2018"
214```
215
216Or
217
218```sh
219fyn install --lock-time "dec 01, 2018"
220```
221
222And `fyn` will only consider packages published up to Dec 01, 2018 when installing.
223
224### Refreshing Optional Dependencies
225
226If you have any optional dependencies, then they will not be re-evaluated if you have a lock file.
227
228You can re-evaluate optional dependencies with `--refresh-optionals` option:
229
230```sh
231fyn install --refresh-optionals
232```
233
234#### Using with Lerna
235
236[lerna] actually implements its own internal `npm link` like feature to support a monorepo with packages that depend on each other.
237
238`fyn` works particularly well with a [lerna] monorepo, but since it offers an enhanced `npm link`, it replaces [lerna]'s bootstrap feature.
239
240To bootstrap a [lerna] repo with `fyn`'s enhanced `npm link`, please use the module [fynpo].
241
242`fyn` also has a [central storage](#central-storage) option that would saves you a lot of disk space when working with [lerna] repos.
243
244You can use [fynpo]'s `local` command to update and commit your monorepo's packages' `package.json`, and you can run `fyn` to install and update their dependencies without having to do it through bootstrap.
245
246For example:
247
248```sh
249fynpo local
250cd packages/my-awesome-package
251fyn
252```
253
254## Configuring fyn
255
256fyn options can be listed in help:
257
258```sh
259fyn --help
260```
261
262fyn loads config from `CWD/.fynrc`, `CWD/.npmrc`, `~/.fynrc`, and `~/.npmrc` in this specified order, from highest to lowest priority.
263
264From `.npmrc`, only fields `registry`, `@<scope>:registry`,`email`, and `_auth` are read.
265
266`.fynrc` file can be an [ini] or `YAML` format. For the `YAML` format, the first line must be `---`.
267
268Below is an `YAML` example, with all the options set to their default values:
269
270```yml
271---
272registry: https://registry.npmjs.org
273"@scope:registry": https://registry.custom.com
274offline: false
275forceCache: false
276lockOnly: false
277progress: normal
278logLevel: info
279production: false
280centralStore: false
281```
282
283Or as an ini:
284
285```ini
286registry=https://registry.npmjs.org
287@scope:registry=https://registry.custom.com
288offline=false
289forceCache=false
290lockOnly=false
291progress=normal
292logLevel=info
293production=false
294centralStore=false
295```
296
297### Command Line Option to RC Mapping
298
299> Any command line option can be converted to an option in the RC file by changing the name to camelCase form.
300
301If there's no RC file or command line override, then these defaults are used:
302
303- `registry` - `https://registry.npmjs.org`
304- `progress` - `normal`
305- `logLevel` - `info`
306
307### Other RC Options
308
309#### Scope registry
310
311Scope registry can be specified in the RC files, the same as `.npmrc`.
312
313For example, in Yaml format:
314
315```yml
316---
317"@scope:registry": https://registry.custom.com
318```
319
320In ini format:
321
322```ini
323@scope:registry=https://registry.custom.com
324```
325
326### Central Storage
327
328Inspired by [pnpm], `fyn` supports storing a single copy of all packages at a central location, and use hardlinks to install them into your `node_modules`.
329
330The main advantage of this is to save disk space and slightly faster install if the storage is primed.
331
332However, this feature is not enabled by default due to the following drawbacks:
333
3341. Creating hardlinks actually could take a lot more than trivial time.
335
336 - What this means is the first time you install with `fyn`, when nothing is cached in the storage, central store mode will actually take noticeably more time, but subsequent installs could be faster.
337
338 - In particular, very bad on MacOS (High Sierra). For example, using hardlinks to replicate the module `nyc` actually takes longer than untaring the tgz file. It improves somewhat with concurrency, but still significant.
339
340 - On Linux with ext4 hardlinking appears to be more than 10 times more efficient than MacOS.
341
3422. You can't do your debugging and development by modifying code that's installed into `node_modules` directly.
343
344 - Reason being that any change you make will affect the central copy, and therefore any other `node_modules` that's linked to it.
345
346 - If you do this, then even after you blow away your `node_modules` and reinstall it, your "debugging" changes will be there again.
347
348 - I imagine that this is actually a fairly big drawback for a lot of people.
349
350 - However, the primary design goal of `fyn` is to make your module development easier with its local linking install feature. You should use that to develop and debug multiple modules locally.
351
3523. Similar to 2, but if any package has `postinstall` script that modifies its own files, then those modifications would affect all installations.
353
354 - There should not be a lot of packages like this, but if you happen to use one, it's unlikely a central storage would work.
355
356In general if disk space is not an issue for you, then it's better to avoid this and the issues that will likely creep up on you when you least expect it.
357
358If you do have a use of this feature despite the drawbacks, then you can enable it with the `--central-store` CLI option.
359
360The recommendation is to add the following to `.fynrc` because then you don't have to remember to specify the option in the CLI every time.
361
362```ini
363centralStore=true
364```
365
366And to work around the issues, `fyn` does the following:
367
368- issue 2: `fyn` has a `--copy` option that allows you to force any package to install with copying instead of hardlinking.
369- issue 3: `fyn` will not hard link packages from central store if they have `preinstall`, `install`, or `postinstall` npm scripts.
370
371## Other Info
372
373### Compatibility
374
375- `fyn`'s top level `node_modules` is 100% compatible with Node.js and 3rd party tools and modules. No special updates or changes needed.
376
377- `fyn` uses npm's [pacote] to do data retrieval. That means its package data handling is the same as npm and it can use npm's cache directly.
378
379- The way `fyn` uses symlinks to resolve nested dependencies is also fully compatible with Node.js. The only caveat is Node.js module loader always resolve a package's path to its real path.
380
381 For example, if `A` depends on `B@1.0.0` that's not at the top level, then `node_modules/A/node_modules/B` is a symlink to `node_modules/B/__fv_/1.0.0/B`.
382
383 Without preserve symlinks, `B`'s path would be resolved to the real path `node_modules/B/__fv_/1.0.0/B`, instead of the symlink path `node_modules/A/node_modules/B`.
384
385 If you want to keep the symlink path, then set the environment variable [NODE_PRESERVE_SYMLINKS] to `1`. It doesn't affect normal operations either way unless you have code that explicitly depend on the path, which should be avoided. The subtle difference is that with preserve symlink, each symlink path of the same module will be loaded as its own instance by Node's module system.
386
387- `fyn` will take [npm]'s `npm-shrinkwrap.json` or `package-lock.json` if its own `fyn-lock.yaml` file doesn't exist, but will save `fyn-lock.yaml` after.
388
389### Package Resolution and Layout
390
391As a package manager, the top level `node_modules` installed by `fyn` is a flat list of all the modules your application needs. It's easier to view and smaller in size. Extra versions of a module will be installed under a directory `__fv_`, and linked through symlinks or [flat-module].
392
393`fyn` has an asynchronous and concurrent dependency resolution engine that is 100% compatible with node's nesting design, and properly handles `optionalDependencies`.
394
395### Thank you `npm`
396
397Node Package Manager is a very large and complex piece of software. Developing `fyn` was 10 times easier because of the generous open source software from the community, especially the individual packages that are part of `npm`.
398
399Other than benefiting from the massive package ecosystem and all the documents from `npm`, these are the concrete packages from `npm` that `fyn` is using directly.
400
401- [node-tar] - for untaring `tgz` files.
402- [semver] - for handling Semver versions.
403- [pacote] - for retrieving `npm` package data.
404- [ini] - for handling `ini` config files.
405- [npm-packlist] - for filtering files according to npm ignore rules.
406- [npm-lifecycle] - for npm_config env and offering `run` as a convenience.
407- [npmlog] - for offering the `run` command as a convenience.
408- And all the other packages they depend on.
409
410## License
411
412Copyright (c) 2015-present, WalmartLabs
413
414Licensed under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).
415
416[flat-module]: https://github.com/jchip/node-flat-module
417[flat node_modules design]: https://github.com/jchip/node-flat-module
418[node_options]: https://nodejs.org/dist/latest-v8.x/docs/api/cli.html#cli_node_options_options
419[`-r` option]: https://nodejs.org/docs/latest-v6.x/api/cli.html#cli_r_require_module
420[fyn-demo-gif]: ./images/fyn-demo.gif
421[ini]: https://www.npmjs.com/package/ini
422[node_preserve_symlinks]: https://nodejs.org/docs/latest-v8.x/api/cli.html#cli_node_preserve_symlinks_1
423[require-at]: https://www.npmjs.com/package/require-at
424[travis-image]: https://travis-ci.org/electrode-io/fyn.svg?branch=master
425[travis-url]: https://travis-ci.org/electrode-io/fyn
426[npm-image]: https://badge.fury.io/js/fyn.svg
427[npm-url]: https://npmjs.org/package/fyn
428[coveralls-image]: https://coveralls.io/repos/github/electrode-io/fyn/badge.svg?branch=master
429[coveralls-url]: https://coveralls.io/github/electrode-io/fyn?branch=master
430[daviddm-image]: https://david-dm.org/electrode-io/fyn/status.svg
431[daviddm-url]: https://david-dm.org/electrode-io/fyn
432[daviddm-dev-image]: https://david-dm.org/electrode-io/fyn/dev-status.svg
433[daviddm-dev-url]: https://david-dm.org/electrode-io/fyn?type=dev
434[apache-2.0-blue-image]: https://img.shields.io/badge/License-Apache%202.0-blue.svg
435[apache-2.0-url]: https://www.apache.org/licenses/LICENSE-2.0
436[npm scripts]: https://docs.npmjs.com/misc/scripts
437[node-tar]: https://www.npmjs.com/package/tar
438[semver]: https://www.npmjs.com/package/semver
439[pacote]: https://www.npmjs.com/package/pacote
440[ini]: https://www.npmjs.com/package/ini
441[npm-packlist]: https://www.npmjs.com/package/npm-packlist
442[pnpm]: https://www.npmjs.com/package/pnpm
443[npm]: https://www.npmjs.com/package/npm
444[lerna]: https://www.npmjs.com/package/lerna
445[fynpo]: https://www.npmjs.com/package/fynpo
446[npm link]: https://docs.npmjs.com/cli/link.html
447[npm-lifecycle]: https://www.npmjs.com/package/npm-lifecycle
448[npmlog]: https://www.npmjs.com/package/npmlog