forked from atom/atom
-
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 'dalek' into ./packages
- Loading branch information
Showing
11 changed files
with
217 additions
and
8 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) 2016 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,19 @@ | ||
# dalek | ||
|
||
**EXTERMINATEs** core packages installed in `~/.atom/packages`. | ||
|
||
## Why worry? | ||
|
||
When people install core Atom packages as if they are community packages, it can cause many problems that are very hard to diagnose. This package is intended to notify people when they are in this precarious position so they can take corrective action. | ||
|
||
## I got a warning, what do I do? | ||
|
||
1. Note down the packages named in the notification | ||
1. Exit Atom | ||
1. Open a command prompt | ||
1. For each package named in the notification, execute `apm uninstall [package-name]` | ||
1. Start Atom again normally to verify that the warning notification no longer appears | ||
|
||
## I have more questions. Where can I ask them? | ||
|
||
Please feel free to ask on [the official Atom message board](https://discuss.atom.io/c/support). |
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,54 @@ | ||
/** @babel */ | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
module.exports = { | ||
async enumerate () { | ||
if (atom.inDevMode()) { | ||
return [] | ||
} | ||
|
||
const duplicatePackages = [] | ||
const names = atom.packages.getAvailablePackageNames() | ||
for (let name of names) { | ||
if (atom.packages.isBundledPackage(name)) { | ||
const isDuplicatedPackage = await this.isInstalledAsCommunityPackage(name) | ||
if (isDuplicatedPackage) { | ||
duplicatePackages.push(name) | ||
} | ||
} | ||
} | ||
|
||
return duplicatePackages | ||
}, | ||
|
||
async isInstalledAsCommunityPackage (name) { | ||
const availablePackagePaths = atom.packages.getPackageDirPaths() | ||
|
||
for (let packagePath of availablePackagePaths) { | ||
const candidate = path.join(packagePath, name) | ||
|
||
if (fs.existsSync(candidate)) { | ||
const realPath = await this.realpath(candidate) | ||
if (realPath === candidate) { | ||
return true | ||
} | ||
} | ||
} | ||
|
||
return false | ||
}, | ||
|
||
realpath (path) { | ||
return new Promise((resolve, reject) => { | ||
fs.realpath(path, function (error, realpath) { | ||
if (error) { | ||
reject(error) | ||
} else { | ||
resolve(realpath) | ||
} | ||
}) | ||
}) | ||
} | ||
} |
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,19 @@ | ||
/** @babel */ | ||
|
||
const dalek = require('./dalek') | ||
const Grim = require('grim') | ||
|
||
module.exports = { | ||
activate () { | ||
atom.packages.onDidActivateInitialPackages(async () => { | ||
const duplicates = await dalek.enumerate() | ||
for (let i = 0; i < duplicates.length; i++) { | ||
const duplicate = duplicates[i] | ||
Grim.deprecate( | ||
`You have the core package "${duplicate}" installed as a community package. See https://github.com/atom/dalek for how this causes problems and instructions on how to correct the situation.`, | ||
{ packageName: duplicate } | ||
) | ||
} | ||
}) | ||
} | ||
} |
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,29 @@ | ||
{ | ||
"name": "dalek", | ||
"main": "./lib/main", | ||
"version": "0.2.2", | ||
"description": "EXTERMINATEs built-in packages installed in ~/.atom/packages", | ||
"keywords": [], | ||
"repository": "https://github.com/atom/atom", | ||
"license": "MIT", | ||
"atomTestRunner": "./test/runner", | ||
"engines": { | ||
"atom": ">=1.12.7 <2.0.0" | ||
}, | ||
"dependencies": { | ||
"grim": "^2.0.1" | ||
}, | ||
"devDependencies": { | ||
"atom-mocha-test-runner": "^1.0.0", | ||
"sinon": "^2.0.0", | ||
"standard": "^8.6.0" | ||
}, | ||
"standard": { | ||
"env": { | ||
"jasmine": true | ||
}, | ||
"globals": [ | ||
"atom" | ||
] | ||
} | ||
} |
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,66 @@ | ||
/** @babel */ | ||
|
||
const assert = require('assert') | ||
const fs = require('fs') | ||
const sinon = require('sinon') | ||
const path = require('path') | ||
|
||
const dalek = require('../lib/dalek') | ||
|
||
describe('dalek', function () { | ||
describe('enumerate', function () { | ||
let availablePackages = {} | ||
let realPaths = {} | ||
let bundledPackages = [] | ||
let packageDirPaths = [] | ||
let sandbox = null | ||
|
||
beforeEach(function () { | ||
availablePackages = { | ||
'an-unduplicated-installed-package': path.join('Users', 'username', '.atom', 'packages', 'an-unduplicated-installed-package'), | ||
'duplicated-package': path.join('Users', 'username', '.atom', 'packages', 'duplicated-package'), | ||
'unduplicated-package': path.join(`${atom.getLoadSettings().resourcePath}`, 'node_modules', 'unduplicated-package') | ||
} | ||
|
||
atom.devMode = false | ||
bundledPackages = ['duplicated-package', 'unduplicated-package'] | ||
packageDirPaths = [path.join('Users', 'username', '.atom', 'packages')] | ||
sandbox = sinon.sandbox.create() | ||
sandbox.stub(dalek, 'realpath').callsFake((filePath) => Promise.resolve(realPaths[filePath] || filePath)) | ||
sandbox.stub(atom.packages, 'isBundledPackage').callsFake((packageName) => { return bundledPackages.includes(packageName) }) | ||
sandbox.stub(atom.packages, 'getAvailablePackageNames').callsFake(() => Object.keys(availablePackages)) | ||
sandbox.stub(atom.packages, 'getPackageDirPaths').callsFake(() => { return packageDirPaths }) | ||
sandbox.stub(fs, 'existsSync').callsFake((candidate) => { return Object.values(availablePackages).includes(candidate) && !candidate.includes(atom.getLoadSettings().resourcePath) }) | ||
}) | ||
|
||
afterEach(function () { | ||
sandbox.restore() | ||
}) | ||
|
||
it('returns a list of duplicate names', async function () { | ||
assert.deepEqual(await dalek.enumerate(), ['duplicated-package']) | ||
}) | ||
|
||
describe('when in dev mode', function () { | ||
beforeEach(function () { | ||
atom.devMode = true | ||
}) | ||
|
||
it('always returns an empty list', async function () { | ||
assert.deepEqual(await dalek.enumerate(), []) | ||
}) | ||
}) | ||
|
||
describe('when a package is symlinked into the package directory', async function () { | ||
beforeEach(function () { | ||
const realPath = path.join('Users', 'username', 'duplicated-package') | ||
const packagePath = path.join('Users', 'username', '.atom', 'packages', 'duplicated-package') | ||
realPaths[packagePath] = realPath | ||
}) | ||
|
||
it('is not included in the list of duplicate names', async function () { | ||
assert.deepEqual(await dalek.enumerate(), []) | ||
}) | ||
}) | ||
}) | ||
}) |
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,2 @@ | ||
const createRunner = require('atom-mocha-test-runner').createRunner | ||
module.exports = createRunner({testSuffixes: ['test.js']}) |