Skip to content

Commit

Permalink
Require Node.js 8, add TypeScript definition (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed May 12, 2019
1 parent b898cd4 commit 9bb3d61
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 54 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: node_js
node_js:
- '6'
- '4'
- '12'
- '10'
- '8'
Empty file modified fixture/cli.js
100644 → 100755
Empty file.
19 changes: 19 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
Check if your package was installed globally.
@example
```
import isInstalledGlobally = require('is-installed-globally');
// With `npm install your-package`
console.log(isInstalledGlobally);
//=> false
// With `npm install --global your-package`
console.log(isInstalledGlobally);
//=> true
```
*/
declare const isInstalledGlobally: boolean;

export = isInstalledGlobally;
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ const fs = require('fs');
const globalDirs = require('global-dirs');
const isPathInside = require('is-path-inside');

module.exports = isPathInside(__dirname, globalDirs.yarn.packages) || isPathInside(__dirname, fs.realpathSync(globalDirs.npm.packages));
module.exports =
isPathInside(__dirname, globalDirs.yarn.packages) ||
isPathInside(__dirname, fs.realpathSync(globalDirs.npm.packages));
4 changes: 4 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {expectType} from 'tsd';
import isInstalledGlobally = require('.');

expectType<boolean>(isInstalledGlobally);
97 changes: 51 additions & 46 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,53 @@
{
"name": "is-installed-globally",
"version": "0.1.0",
"description": "Check if your package was installed globally",
"license": "MIT",
"repository": "sindresorhus/is-installed-globally",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"global",
"package",
"globally",
"module",
"install",
"installed",
"npm",
"yarn",
"is",
"check",
"detect",
"local",
"locally",
"cli",
"bin",
"binary"
],
"dependencies": {
"global-dirs": "^0.1.0",
"is-path-inside": "^1.0.0"
},
"devDependencies": {
"ava": "*",
"execa": "^0.7.0",
"xo": "*"
}
"name": "is-installed-globally",
"version": "0.1.0",
"description": "Check if your package was installed globally",
"license": "MIT",
"repository": "sindresorhus/is-installed-globally",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"global",
"package",
"globally",
"module",
"install",
"installed",
"npm",
"yarn",
"is",
"check",
"detect",
"local",
"locally",
"cli",
"bin",
"binary"
],
"dependencies": {
"global-dirs": "^0.1.1",
"is-path-inside": "^2.1.0"
},
"devDependencies": {
"ava": "^1.4.1",
"cpy": "^7.2.0",
"del": "^4.1.0",
"execa": "^1.0.0",
"make-dir": "^3.0.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
36 changes: 33 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
import path from 'path';
import test from 'ava';
import execa from 'execa';
import m from '.';
import globalDirs from 'global-dirs';
import del from 'del';
import makeDir from 'make-dir';
import cpy from 'cpy';
/* eslint-disable import/extensions */
import packageJson from './package.json';
import fixturePackageJson from './fixture/package.json';
/* eslint-enable import/extensions */
import isInstalledGlobally from '.';

test('local', t => {
t.false(m);
t.false(isInstalledGlobally);
});

test('global', async t => {
const npm = args => execa('npm', args, {cwd: 'fixture'});
await npm(['install', '--global', '.']);

const fixtureGlobalPath = path.join(
globalDirs.npm.packages,
fixturePackageJson.name
);
const isInstalledGloballyGlobalPathInFixture = path.join(
fixtureGlobalPath,
'node_modules',
packageJson.name
);
await del(fixtureGlobalPath, {force: true});
await makeDir(isInstalledGloballyGlobalPathInFixture);
await cpy(['./**/*'], fixtureGlobalPath, {
cwd: 'fixture',
followSymlinkedDirectories: false,
parents: true
});
await cpy(['./**/*'], isInstalledGloballyGlobalPathInFixture, {
followSymlinkedDirectories: false,
parents: true
});

t.is(await execa.stdout('is-installed-globally-fixture'), 'true');

await npm(['uninstall', '--global', '.']);
await del(fixtureGlobalPath, {force: true});
});

0 comments on commit 9bb3d61

Please sign in to comment.