Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking Change] Split off Shell into separate bundle #643

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ section below.
Filer also supports node's Path module. See the [Filer.Path](#FilerPath) section below.

In addition, common shell operations (e.g., rm, touch, cat, etc.) are supported via the
`FileSystemShell` object, which can be obtained from, and used with a `FileSystem`.
`FileSystemShell` object, which can be used with a `FileSystem`.
See the[FileSystemShell](#FileSystemShell) section below.

### API Reference
Expand All @@ -113,6 +113,7 @@ you omit the callback, errors will be thrown as exceptions). The first callback
reserved for passing errors. It will be `null` if no errors occurred and should always be checked.

#### Support for Promises

The Promise based API mimics the way Node [implements](https://nodejs.org/api/fs.html#fs_fs_promises_api) them. Both `Shell` and `FileSystem` now have a `promises` object attached alongside the regular callback style methods. Method names are identical to their callback counterparts with the difference that instead of receiving a final argument as a callback, they return a Promise that is resolved or rejected based on the success of method execution.
> Please note that `exists` method will always throw, since it was [deprecated](https://nodejs.org/api/fs.html#fs_fs_exists_path_callback) by Node.

Expand Down Expand Up @@ -1295,34 +1296,27 @@ and provides augmented features. Many separate `FileSystemShell` objects can exi
`FileSystem`, but each `FileSystemShell` is bound to a single instance of a `FileSystem`
for its lifetime.

A `FileSystemShell` is created by instantiating `Filer.FileSystem().Shell`:
> NOTE: previous versions of Filer (`v0.44` and before) bundled the `Shell` with `Filer`. This is no longer done, because it added too much size to the bundle.

```javascript
var fs = new Filer.FileSystem();
var sh = new fs.Shell(options);
var sh2 = new fs.Shell(options);
// sh and sh2 are two separate shells, each bound to fs
```

In addition, the constructor function can be accessed through `Filer`:
To use the `FileSystemShell`, first include the separate `shell.js` dependency.
This allows you to create new instances with `new Shell(fs, options)`:

```javascript
var fs = new Filer.FileSystem();
var sh = new fs.Shell();

Filer.Shell.prototype.newFunction = ...;

sh.newFunction();
var sh = new Shell(fs, options);
var sh2 = new Shell(fs, options);
// sh and sh2 are two separate shells, each bound to fs
```

The `FileSystemShell` can take an optional `options` object. The `options` object
can include `env`, which is a set of environment variables. Currently supported variables
In addition to the `fs` instance, The `Shell` constructor can take an optional
`options` object. The `options` object can include `env` (an `Object`), which is
a set of environment variables. Currently supported variables
include `TMP` (the path to the temporary directory), and `PATH` (the list of known paths) and
others may be added in the future. You can also add your own, or update existing variables.

```javascript
var fs = new Filer.FileSystem();
var sh = new fs.Shell({
var sh = new Shell(fs, {
env: {
TMP: '/tempdir',
PATH: '/one:/two'
Expand All @@ -1348,7 +1342,7 @@ Example:

```javascript
var fs = new Filer.FileSystem();
var sh = new fs.Shell();
var sh = new Shell(fs);
var p = sh.env.get('PATH');

// Store the current location
Expand All @@ -1368,7 +1362,7 @@ examples below assume a `FileSystemShell` instance named `sh` has been created l

```javascript
var fs = new Filer.FileSystem();
var sh = new fs.Shell();
var sh = new Shell(fs);
```

* [sh.cd(path, callback)](#cd)
Expand Down
87 changes: 87 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
"pretest": "npm run lint",
"test": "npm run karma-mocha",
"posttest": "npm run test:migrations",
"prebuild": "parcel build --global Filer src/index.js --no-minify --out-file filer.js",
"build": "parcel build --global Filer src/index.js --out-file filer.min.js --detailed-report",
"build": "npm-run-all -n build-filer build-shell",
"prebuild-filer": "parcel build --global Filer src/index.js --no-minify --out-file filer.js",
"build-filer": "parcel build --global Filer src/index.js --out-file filer.min.js --detailed-report",
"prebuild-shell": "parcel build --global Shell src/shell/index.js --no-minify --out-file shell.js",
"build-shell": "parcel build --global Shell src/shell/index.js --out-file shell.min.js --detailed-report",
"build-tests": "parcel build tests/index.js --no-source-maps --out-dir tests/dist",
"prekarma-mocha-firefox": "npm run build-tests",
"karma-mocha-firefox": "karma start karma.conf.js --browsers FirefoxHeadless",
Expand Down Expand Up @@ -59,6 +62,7 @@
"karma-summary-reporter": "^1.5.1",
"meow": "^5.0.0",
"mocha": "^5.2.0",
"npm-run-all": "^4.1.5",
"nyc": "^13.1.0",
"parcel-bundler": "^1.10.3",
"pretty-bytes": "^5.1.0",
Expand Down
4 changes: 0 additions & 4 deletions src/filesystem/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var FS_NODUPEIDCHECK = Constants.FS_NODUPEIDCHECK;

var providers = require('../providers/index.js');

var Shell = require('../shell/shell.js');
var Intercom = require('../../lib/intercom.js');
var FSWatcher = require('../fs-watcher.js');
var Errors = require('../errors.js');
Expand Down Expand Up @@ -98,9 +97,6 @@ function FileSystem(options, callback) {
// Expose Node's fs.constants to users
fs.constants = Constants.fsConstants;

// Expose Shell constructor
this.Shell = Shell.bind(undefined, this);

// Safely expose the list of open files and file
// descriptor management functions
var openFiles = {};
Expand Down
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ module.exports = {
FileSystem: require('./filesystem/interface.js'),
Buffer: Buffer,
Path: require('./path.js'),
Errors: require('./errors.js'),
Shell: require('./shell/shell.js')
Errors: require('./errors.js')
};
File renamed without changes.
3 changes: 1 addition & 2 deletions tests/bugs/issue247.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ describe('sh.cd doesn\'t seem to be working from a relative path if I am one or
afterEach(util.cleanup);

it('should properly deal with relative paths missing ./ and ../', function(done) {
var fs = util.fs();
var sh = new fs.Shell();
var sh = util.shell();

sh.mkdirp('/home/scott', function(err) {
if(err) throw err;
Expand Down
5 changes: 2 additions & 3 deletions tests/bugs/ls-depth-bug.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ describe('sh.ls and deep directory trees', function() {
afterEach(util.cleanup);

it('should not crash when calling sh.ls() on deep directory layouts', function(done) {
var fs = util.fs();
var sh = new fs.Shell();
var sh = util.shell();

var path = '';
for(var i=0; i<50; i++) {
Expand All @@ -29,7 +28,7 @@ describe('sh.ls and deep directory trees', function() {

it('should not crash when calling sh.ls() on wide directory layouts', function(done) {
var fs = util.fs();
var sh = new fs.Shell();
var sh = util.shell();

var dirName = '/dir';

Expand Down
1 change: 0 additions & 1 deletion tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ require('./spec/time-flags.spec');
require('./spec/fs.watch.spec');
require('./spec/fs.unwatchFile.spec');
require('./spec/errors.spec');
require('./spec/fs.shell.spec');
require('./spec/fs.chmod.spec');
require('./spec/fs.chown.spec');
require('./spec/fs.copyFile.spec');
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var IndexedDBTestProvider = require('./indexeddb.js');
var WebSQLTestProvider = require('./websql.js');
var MemoryTestProvider = require('./memory.js');
var Url = require('url');
var Shell = require('../../src/shell');

var _provider;
var _fs;
Expand Down Expand Up @@ -108,8 +109,7 @@ function provider() {
}

function shell(options) {
var _fs = fs();
return new _fs.Shell(options);
return new Shell(fs(), options);
}

function cleanup(callback) {
Expand Down
4 changes: 0 additions & 4 deletions tests/spec/filer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ describe('Filer', function() {
expect(typeof Filer.FileSystem).to.equal('function');
});

it('has Shell constructor', function() {
expect(typeof Filer.Shell).to.equal('function');
});

it('must honor the \'FORMAT\' flag', function(done) {
var name = 'local-test';
// Because we need to use a bunch of Filer filesystems
Expand Down
29 changes: 0 additions & 29 deletions tests/spec/fs.shell.spec.js

This file was deleted.

Loading