Repository: prettier/prettier-atom (js)

Issue:
Only format if Prettier in dependencies does not work
The option “Only format if Prettier is found in your project's depedencies” does not detect Prettier correctly and the formatter does not run.

![image](https://user-images.githubusercontent.com/113721/61868919-1be03b00-aee3-11e9-8e12-938c7784fa19.png)

It works when downgrading to 0.56.6, but does not work anymore on 0.57.0.

The regression is caused by an incorrect dependency bump in f5a0b18 #51 

read-pkg-up [in the new version](https://github.com/sindresorhus/read-pkg-up/releases) renames a key from `pkg` to `package`:

![image](https://user-images.githubusercontent.com/113721/61871115-a1b2b500-aee8-11e9-89d5-61f50596aa10.png)

Prettier is very definitely in project’s dependencies, it was there for many months, and the option worked before. It does not work with all my projects now. (`"prettier": "^1.18.2"`)

This has began since a month or two ago, until then the addon worked great. Both functionality-wise and timeline-wise this seems quite similar to #502.

Atom’s console has no relevant messages neither on start-up, nor at the time when I save. Manually triggering Prettier: Format does format the file. Unchecking the option leads to the plugin formatting on save.

This is not related to symlinks or directory permissions, a clean project clone on the desktop produces the same results.

<details>

Atom version: 1.39.0
prettier-atom version: 0.57.1
prettier: bundled
prettier version: 1.18.2
prettier-eslint version: 9.0.0
prettier-atom configuration:
```json
{
  "formatOnSaveOptions": {
    "enabled": true,
    "jsonScopes": [
      "-"
    ],
    "showInStatusBar": true,
    "whitelistedGlobs": [],
    "isDisabledIfNotInPackageJson": true,
    "respectEslintignore": true,
    "excludedGlobs": [],
    "isDisabledIfNoConfigFile": false,
    "ignoreNodeModules": true
  },
  "useEslint": false,
  "useStylelint": false,
  "prettierEslintOptions": {
    "prettierLast": false
  }
}
```

Search terms: isDisabledIfNotInPackageJson #43

</details>

Pull request description:
fix(deps): correctly use new pkg-up, fixup f5a0b18, #507
Closes #510.

Patch:
diff --git a/dist/formatOnSave/isPrettierInPackageJson.js b/dist/formatOnSave/isPrettierInPackageJson.js
index fca854d..e0ea42d 100644
--- a/dist/formatOnSave/isPrettierInPackageJson.js
+++ b/dist/formatOnSave/isPrettierInPackageJson.js
@@ -12,9 +12,9 @@ const {
   shouldUseEslint
 } = require('../atomInterface');
 
-const hasPackageDependency = packageName => _.flow(_.get('pkg.dependencies'), _.has(packageName));
+const hasPackageDependency = packageName => _.flow(_.get('package.dependencies'), _.has(packageName));
 
-const hasPackageDevDependency = packageName => _.flow(_.get('pkg.devDependencies'), _.has(packageName));
+const hasPackageDevDependency = packageName => _.flow(_.get('package.devDependencies'), _.has(packageName));
 
 const hasPackage = packageName => _.overSome([hasPackageDependency(packageName), hasPackageDevDependency(packageName)]);
 
diff --git a/src/formatOnSave/isPrettierInPackageJson.js b/src/formatOnSave/isPrettierInPackageJson.js
index ad49120..83f0dbb 100644
--- a/src/formatOnSave/isPrettierInPackageJson.js
+++ b/src/formatOnSave/isPrettierInPackageJson.js
@@ -7,13 +7,13 @@ const { shouldUseEslint } = require('../atomInterface');
 
 const hasPackageDependency = (packageName: string): ((packageJson: {}) => boolean) =>
   _.flow(
-    _.get('pkg.dependencies'),
+    _.get('package.dependencies'),
     _.has(packageName),
   );
 
 const hasPackageDevDependency = (packageName: string) =>
   _.flow(
-    _.get('pkg.devDependencies'),
+    _.get('package.devDependencies'),
     _.has(packageName),
   );
 


Test patch:
diff --git a/dist/formatOnSave/isPrettierInPackageJson.test.js b/dist/formatOnSave/isPrettierInPackageJson.test.js
index 481da2a..c2d1a69 100644
--- a/dist/formatOnSave/isPrettierInPackageJson.test.js
+++ b/dist/formatOnSave/isPrettierInPackageJson.test.js
@@ -29,7 +29,7 @@ describe('when shouldUseEslint is false', () => {
   });
   it('is true if prettier is a dependency', () => {
     readPkgUp.sync.mockImplementation(() => ({
-      pkg: {
+      "package": {
         dependencies: {
           prettier: '^0.0.1'
         }
@@ -40,7 +40,7 @@ describe('when shouldUseEslint is false', () => {
   });
   it('is true if prettier is a dev dependency', () => {
     readPkgUp.sync.mockImplementation(() => ({
-      pkg: {
+      "package": {
         devDependencies: {
           prettier: '^0.0.1'
         }
@@ -67,7 +67,7 @@ describe('when shouldUseEslint is true', () => {
   });
   it('is true if prettier-eslint is a dependency', () => {
     readPkgUp.sync.mockImplementation(() => ({
-      pkg: {
+      "package": {
         dependencies: {
           'prettier-eslint': '^0.0.1'
         }
@@ -78,7 +78,7 @@ describe('when shouldUseEslint is true', () => {
   });
   it('is true if prettier-eslint is a dev dependency', () => {
     readPkgUp.sync.mockImplementation(() => ({
-      pkg: {
+      "package": {
         devDependencies: {
           'prettier-eslint': '^0.0.1'
         }
@@ -89,7 +89,7 @@ describe('when shouldUseEslint is true', () => {
   });
   it('is true if prettier-eslint-cli is a dependency', () => {
     readPkgUp.sync.mockImplementation(() => ({
-      pkg: {
+      "package": {
         dependencies: {
           'prettier-eslint-cli': '^0.0.1'
         }
@@ -100,7 +100,7 @@ describe('when shouldUseEslint is true', () => {
   });
   it('is true if prettier-eslint-cli is a dev dependency', () => {
     readPkgUp.sync.mockImplementation(() => ({
-      pkg: {
+      "package": {
         devDependencies: {
           'prettier-eslint-cli': '^0.0.1'
         }
@@ -111,7 +111,7 @@ describe('when shouldUseEslint is true', () => {
   });
   it('is true if eslint-plugin-prettier is a dependency', () => {
     readPkgUp.sync.mockImplementation(() => ({
-      pkg: {
+      "package": {
         dependencies: {
           'eslint-plugin-prettier': '^0.0.1'
         }
@@ -122,7 +122,7 @@ describe('when shouldUseEslint is true', () => {
   });
   it('is true if eslint-plugin-prettier is a dev dependency', () => {
     readPkgUp.sync.mockImplementation(() => ({
-      pkg: {
+      "package": {
         devDependencies: {
           'eslint-plugin-prettier': '^0.0.1'
         }
diff --git a/src/formatOnSave/isPrettierInPackageJson.test.js b/src/formatOnSave/isPrettierInPackageJson.test.js
index 6d12070..0ee3c17 100644
--- a/src/formatOnSave/isPrettierInPackageJson.test.js
+++ b/src/formatOnSave/isPrettierInPackageJson.test.js
@@ -21,7 +21,7 @@ describe('when shouldUseEslint is false', () => {
   });
 
   it('is true if prettier is a dependency', () => {
-    readPkgUp.sync.mockImplementation(() => ({ pkg: { dependencies: { prettier: '^0.0.1' } } }));
+    readPkgUp.sync.mockImplementation(() => ({ package: { dependencies: { prettier: '^0.0.1' } } }));
 
     const actual = isPrettierInPackageJson();
 
@@ -29,7 +29,7 @@ describe('when shouldUseEslint is false', () => {
   });
 
   it('is true if prettier is a dev dependency', () => {
-    readPkgUp.sync.mockImplementation(() => ({ pkg: { devDependencies: { prettier: '^0.0.1' } } }));
+    readPkgUp.sync.mockImplementation(() => ({ package: { devDependencies: { prettier: '^0.0.1' } } }));
 
     const actual = isPrettierInPackageJson();
 
@@ -57,7 +57,7 @@ describe('when shouldUseEslint is true', () => {
   });
 
   it('is true if prettier-eslint is a dependency', () => {
-    readPkgUp.sync.mockImplementation(() => ({ pkg: { dependencies: { 'prettier-eslint': '^0.0.1' } } }));
+    readPkgUp.sync.mockImplementation(() => ({ package: { dependencies: { 'prettier-eslint': '^0.0.1' } } }));
 
     const actual = isPrettierInPackageJson();
 
@@ -65,7 +65,9 @@ describe('when shouldUseEslint is true', () => {
   });
 
   it('is true if prettier-eslint is a dev dependency', () => {
-    readPkgUp.sync.mockImplementation(() => ({ pkg: { devDependencies: { 'prettier-eslint': '^0.0.1' } } }));
+    readPkgUp.sync.mockImplementation(() => ({
+      package: { devDependencies: { 'prettier-eslint': '^0.0.1' } },
+    }));
 
     const actual = isPrettierInPackageJson();
 
@@ -73,7 +75,9 @@ describe('when shouldUseEslint is true', () => {
   });
 
   it('is true if prettier-eslint-cli is a dependency', () => {
-    readPkgUp.sync.mockImplementation(() => ({ pkg: { dependencies: { 'prettier-eslint-cli': '^0.0.1' } } }));
+    readPkgUp.sync.mockImplementation(() => ({
+      package: { dependencies: { 'prettier-eslint-cli': '^0.0.1' } },
+    }));
 
     const actual = isPrettierInPackageJson();
 
@@ -82,7 +86,7 @@ describe('when shouldUseEslint is true', () => {
 
   it('is true if prettier-eslint-cli is a dev dependency', () => {
     readPkgUp.sync.mockImplementation(() => ({
-      pkg: { devDependencies: { 'prettier-eslint-cli': '^0.0.1' } },
+      package: { devDependencies: { 'prettier-eslint-cli': '^0.0.1' } },
     }));
 
     const actual = isPrettierInPackageJson();
@@ -92,7 +96,7 @@ describe('when shouldUseEslint is true', () => {
 
   it('is true if eslint-plugin-prettier is a dependency', () => {
     readPkgUp.sync.mockImplementation(() => ({
-      pkg: { dependencies: { 'eslint-plugin-prettier': '^0.0.1' } },
+      package: { dependencies: { 'eslint-plugin-prettier': '^0.0.1' } },
     }));
 
     const actual = isPrettierInPackageJson();
@@ -102,7 +106,7 @@ describe('when shouldUseEslint is true', () => {
 
   it('is true if eslint-plugin-prettier is a dev dependency', () => {
     readPkgUp.sync.mockImplementation(() => ({
-      pkg: { devDependencies: { 'eslint-plugin-prettier': '^0.0.1' } },
+      package: { devDependencies: { 'eslint-plugin-prettier': '^0.0.1' } },
     }));
 
     const actual = isPrettierInPackageJson();