-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
➡️ Migrate core package 'update-package-dependencies' into ./packages
- Loading branch information
1 parent
9ebdee1
commit 3cd91ff
Showing
12 changed files
with
449 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
npm-debug.log | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
30 changes: 30 additions & 0 deletions
30
packages/update-package-dependencies/lib/update-package-dependencies-status-view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}; |
81 changes: 81 additions & 0 deletions
81
packages/update-package-dependencies/lib/update-package-dependencies.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
106
packages/update-package-dependencies/spec/async-spec-helpers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.