Skip to content

Commit

Permalink
➡️ Migrate core package 'update-package-dependencies' into ./packages
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrudolph committed Aug 12, 2019
1 parent 9ebdee1 commit 3cd91ff
Show file tree
Hide file tree
Showing 12 changed files with 449 additions and 6 deletions.
3 changes: 1 addition & 2 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
"tree-sitter-css": "^0.13.7",
"tree-view": "https://www.atom.io/api/packages/tree-view/versions/0.228.0/tarball",
"typescript-simple": "1.0.0",
"update-package-dependencies": "https://www.atom.io/api/packages/update-package-dependencies/versions/0.13.1/tarball",
"update-package-dependencies": "file:./packages/update-package-dependencies",
"vscode-ripgrep": "^1.2.5",
"welcome": "file:packages/welcome",
"whitespace": "https://www.atom.io/api/packages/whitespace/versions/0.37.7/tarball",
Expand Down Expand Up @@ -225,7 +225,7 @@
"tabs": "0.110.0",
"timecop": "0.36.2",
"tree-view": "0.228.0",
"update-package-dependencies": "0.13.1",
"update-package-dependencies": "file:./packages/update-package-dependencies",
"welcome": "file:./packages/welcome",
"whitespace": "0.37.7",
"wrap-guide": "0.41.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ See [RFC 003](https://github.com/atom/atom/blob/master/docs/rfcs/003-consolidate
| **tabs** | [`atom/tabs`][tabs] | |
| **timecop** | [`atom/timecop`][timecop] | [#18272](https://github.com/atom/atom/issues/18272) |
| **tree-view** | [`atom/tree-view`][tree-view] | |
| **update-package-dependencies** | [`atom/update-package-dependencies`][update-package-dependencies] | [#18284](https://github.com/atom/atom/issues/18284) |
| **update-package-dependencies** | [`./update-package-dependencies`](./update-package-dependencies) | [#18284](https://github.com/atom/atom/issues/18284) |
| **welcome** | [`./welcome`](./welcome) | [#18285](https://github.com/atom/atom/issues/18285) |
| **whitespace** | [`atom/whitespace`][whitespace] | |
| **wrap-guide** | [`atom/wrap-guide`][wrap-guide] | [#18286](https://github.com/atom/atom/issues/18286) |
Expand Down Expand Up @@ -165,6 +165,5 @@ See [RFC 003](https://github.com/atom/atom/blob/master/docs/rfcs/003-consolidate
[tabs]: https://github.com/atom/tabs
[timecop]: https://github.com/atom/timecop
[tree-view]: https://github.com/atom/tree-view
[update-package-dependencies]: https://github.com/atom/update-package-dependencies
[whitespace]: https://github.com/atom/whitespace
[wrap-guide]: https://github.com/atom/wrap-guide
3 changes: 3 additions & 0 deletions packages/update-package-dependencies/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
npm-debug.log
node_modules
20 changes: 20 additions & 0 deletions packages/update-package-dependencies/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2014 GitHub Inc.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5 changes: 5 additions & 0 deletions packages/update-package-dependencies/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Update Package Dependencies package

Runs `apm install` from the current project's directory. This will install all dependencies referenced in the `package.json` file to the `node_modules` folder.

This should only be used in projects that are Atom packages.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = class UpdatePackageDependenciesStatusView {
constructor(statusBar) {
this.statusBar = statusBar;
this.element = document.createElement('update-package-dependencies-status');
this.element.classList.add(
'update-package-dependencies-status',
'inline-block',
'is-read-only'
);
this.spinner = document.createElement('span');
this.spinner.classList.add(
'loading',
'loading-spinner-tiny',
'inline-block'
);
this.element.appendChild(this.spinner);
}

attach() {
this.tile = this.statusBar.addRightTile({ item: this.element });
this.tooltip = atom.tooltips.add(this.element, {
title: 'Updating package dependencies\u2026'
});
}

detach() {
if (this.tile) this.tile.destroy();
if (this.tooltip) this.tooltip.dispose();
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const { BufferedProcess } = require('atom');
const UpdatePackageDependenciesStatusView = require('./update-package-dependencies-status-view');

module.exports = {
activate() {
this.subscription = atom.commands.add(
'atom-workspace',
'update-package-dependencies:update',
() => this.update()
);
},

deactivate() {
this.subscription.dispose();
if (this.updatePackageDependenciesStatusView) {
this.updatePackageDependenciesStatusView.detach();
this.updatePackageDependenciesStatusView = null;
}
},

consumeStatusBar(statusBar) {
this.updatePackageDependenciesStatusView = new UpdatePackageDependenciesStatusView(
statusBar
);
},

update() {
if (this.process) return; // Do not allow multiple apm processes to run
if (this.updatePackageDependenciesStatusView)
this.updatePackageDependenciesStatusView.attach();

let errorOutput = '';

const command = atom.packages.getApmPath();
const args = ['install', '--no-color'];
const stderr = output => {
errorOutput += output;
};
const options = {
cwd: this.getActiveProjectPath(),
env: Object.assign({}, process.env, { NODE_ENV: 'development' })
};

const exit = code => {
this.process = null;
if (this.updatePackageDependenciesStatusView)
this.updatePackageDependenciesStatusView.detach();

if (code === 0) {
atom.notifications.addSuccess('Package dependencies updated');
} else {
atom.notifications.addError('Failed to update package dependencies', {
detail: errorOutput,
dismissable: true
});
}
};

this.process = this.runBufferedProcess({
command,
args,
stderr,
exit,
options
});
},

// This function exists so that it can be spied on by tests
runBufferedProcess(params) {
return new BufferedProcess(params);
},

getActiveProjectPath() {
const activeItem = atom.workspace.getActivePaneItem();
if (activeItem && typeof activeItem.getPath === 'function') {
return atom.project.relativizePath(activeItem.getPath())[0];
} else {
return atom.project.getPaths()[0];
}
}
};
39 changes: 39 additions & 0 deletions packages/update-package-dependencies/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "update-package-dependencies",
"main": "./lib/update-package-dependencies",
"version": "0.13.1",
"private": true,
"description": "Runs `apm install` for the current project",
"repository": "https://github.com/atom/atom",
"license": "MIT",
"engines": {
"atom": ">0.39.0"
},
"activationCommands": {
"atom-workspace": [
"update-package-dependencies:update"
]
},
"consumedServices": {
"status-bar": {
"versions": {
"^1.1.0": "consumeStatusBar"
}
}
},
"dependencies": {},
"devDependencies": {
"standard": "^10.0.3"
},
"standard": {
"env": {
"atomtest": true,
"browser": true,
"jasmine": true,
"node": true
},
"globals": [
"atom"
]
}
}
106 changes: 106 additions & 0 deletions packages/update-package-dependencies/spec/async-spec-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/** @babel */

export function beforeEach(fn) {
global.beforeEach(function() {
const result = fn();
if (result instanceof Promise) {
waitsForPromise(() => result);
}
});
}

export function afterEach(fn) {
global.afterEach(function() {
const result = fn();
if (result instanceof Promise) {
waitsForPromise(() => result);
}
});
}

['it', 'fit', 'ffit', 'fffit'].forEach(function(name) {
module.exports[name] = function(description, fn) {
if (fn === undefined) {
global[name](description);
return;
}

global[name](description, function() {
const result = fn();
if (result instanceof Promise) {
waitsForPromise(() => result);
}
});
};
});

export async function conditionPromise(
condition,
description = 'anonymous condition'
) {
const startTime = Date.now();

while (true) {
await timeoutPromise(100);

if (await condition()) {
return;
}

if (Date.now() - startTime > 5000) {
throw new Error('Timed out waiting on ' + description);
}
}
}

export function timeoutPromise(timeout) {
return new Promise(function(resolve) {
global.setTimeout(resolve, timeout);
});
}

function waitsForPromise(fn) {
const promise = fn();
global.waitsFor('spec promise to resolve', function(done) {
promise.then(done, function(error) {
jasmine.getEnv().currentSpec.fail(error);
done();
});
});
}

export function emitterEventPromise(emitter, event, timeout = 15000) {
return new Promise((resolve, reject) => {
const timeoutHandle = setTimeout(() => {
reject(new Error(`Timed out waiting for '${event}' event`));
}, timeout);
emitter.once(event, () => {
clearTimeout(timeoutHandle);
resolve();
});
});
}

export function promisify(original) {
return function(...args) {
return new Promise((resolve, reject) => {
args.push((err, ...results) => {
if (err) {
reject(err);
} else {
resolve(...results);
}
});

return original(...args);
});
};
}

export function promisifySome(obj, fnNames) {
const result = {};
for (const fnName of fnNames) {
result[fnName] = promisify(obj[fnName]);
}
return result;
}
Loading

0 comments on commit 3cd91ff

Please sign in to comment.