How to use global-dirs - 10 common examples

To help you get started, we’ve selected a few global-dirs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jesusprubio / pwr / test / main.spec.js View on Github external
/**
 * @license
 *
 * Copyright (c) 2019, Jesús Rubio 
 *
 * This source code is licensed under the MIT License found in
 * the LICENSE.txt file in the root directory of this source tree.
 */

'use strict';

const globalDirs = require('global-dirs');
const path = require('path');

const npm = require.resolve(path.join(globalDirs.npm.binaries, 'npm'));
const mockNpx = jest.fn();
mockNpx.parseArgs = jest.fn();

jest.mock('inquirer');
jest.mock('await-spawn', () => jest.fn());
jest.mock('import-from', () => (fromDirectory, moduleId) => {
  if (moduleId === 'libnpx') return mockNpx;
  return jest.requireActual('import-from')(fromDirectory, moduleId);
});

/* eslint-disable import/order */
const inquirer = require('inquirer');
const spawn = require('await-spawn');
/* eslint-enable */

const { runCommands, generateChoices, selectTool } = require('../bin/main');
github boneskull / create-yo / src / create-yo.js View on Github external
async function create(
  argv = process.argv.slice(),
  npmPath = path.join(globalDirs.npm.binaries, 'npm')
) {
  if (argv.length < 3) {
    throw new Error(
      `specify a generator to run via ${bold(
        'npm init yo '
      )}. See list: http://yeoman.io/generators/`
    );
  }

  let generator = argv.pop();
  let generatorPackage;
  let generatorName;
  if (generator.startsWith('@')) {
    // handle scoped packages
    generatorName = generatorPackage = generator;
  } else {
github boneskull / create-yo / test / create-yo.spec.js View on Github external
'use strict';

const path = require('path');
const expect = require('unexpected').clone();
expect.use(require('unexpected-sinon'));
const sinon = require('sinon');
const rewiremock = require('rewiremock/node');
const globalDirs = require('global-dirs');
const importFrom = require('import-from');
const {parseArgs} = importFrom(
  path.join(globalDirs.npm.packages, 'npm'),
  'libnpx'
);

describe('create-yo', function() {
  let sandbox;

  let libnpx;
  let create;

  beforeEach(function() {
    sandbox = sinon.createSandbox();
    libnpx = sandbox.spy();
    libnpx.parseArgs = parseArgs;
    create = rewiremock.proxy('..', r => ({
      'global-dirs': r.by(() => ({
        npm: {
github thiagodp / concordialang / __tests__ / plugin / PackageBasedPluginFinder.spec.ts View on Github external
describe( 'PackageBasedPluginFinder', () => {

    const currentDir: string = normalize( process.cwd() );
    const localModulesDir: string = join( currentDir, 'node_modules' );
    const globalModulesDir: string = globalDirs.npm.packages;

    const PLUGIN_NAME: string = 'concordialang-fake';
    const PKG_FILENAME: string = 'package.json';

    const localPluginDir: string = join( localModulesDir, PLUGIN_NAME );
    const localPluginPackageFile: string = join( localPluginDir, PKG_FILENAME );
    const globalPluginDir: string = join( globalModulesDir, PLUGIN_NAME );
    const globalPluginPackageFile: string = join( globalPluginDir, PKG_FILENAME );

    let pkg = {
        name: PLUGIN_NAME,
        description: 'Fake plugin',
        version: '0.1.0',
        author: {
            name: 'Bob',
            email: 'bob@fake.com'
github thiagodp / concordialang / dist / __tests__ / plugin / PackageBasedPluginFinder.spec.js View on Github external
describe('PackageBasedPluginFinder', () => {
    const currentDir = path_1.normalize(process.cwd());
    const localModulesDir = path_1.join(currentDir, 'node_modules');
    const globalModulesDir = globalDirs.npm.packages;
    const PLUGIN_NAME = 'concordialang-fake';
    const PKG_FILENAME = 'package.json';
    const localPluginDir = path_1.join(localModulesDir, PLUGIN_NAME);
    const localPluginPackageFile = path_1.join(localPluginDir, PKG_FILENAME);
    const globalPluginDir = path_1.join(globalModulesDir, PLUGIN_NAME);
    const globalPluginPackageFile = path_1.join(globalPluginDir, PKG_FILENAME);
    let pkg = {
        name: PLUGIN_NAME,
        description: 'Fake plugin',
        version: '0.1.0',
        author: {
            name: 'Bob',
            email: 'bob@fake.com'
        }
    };
    pkg[PluginData_1.PLUGIN_PROPERTY] = {
github alefesouza / thanosjs / src / cli.js View on Github external
path,
  noAsk,
} = cli.flags;

if (!cli.input.includes('snap-fingers')) {
  console.log('You need to snap your fingers.');
  process.exit();
}

if (force) {
  thanos(path, noAsk);
  return;
}

const gems = ['reality', 'mind', 'space', 'time', 'soul'];
const globalPackages = fs.readdirSync(globalDirs.npm.packages);

const notInstalledGems = gems.filter(gem => !globalPackages.includes(gem));

if (notInstalledGems.length > 0) {
  console.log('You have not installed all the Infinity Gems packages, to install it just run: \n');

  notInstalledGems.forEach(gem => {
    console.log(`$ npm install -g ${gem}`);
  });

  process.exit();
}

if (!withGlove) {
  console.log('You need the Infinity Gauntlet, to add it just rerun the command with `--with-glove` argument.');
github sindresorhus / is-installed-globally / index.js View on Github external
'use strict';
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));
github sindresorhus / resolve-global / index.js View on Github external
const resolveGlobal = moduleId => {
	try {
		return require.resolve(path.join(globalDirs.yarn.packages, moduleId));
	} catch (_) {
		return require.resolve(path.join(globalDirs.npm.packages, moduleId));
	}
};
github stone-payments / pos-mamba-sdk / packages / cli / lib / loadPlugins.js View on Github external
}
  return plugin;
}

const getPackagesFrom = (path, includedStr) => {
  if (existsSync(path)) {
    return readdirSync(path).filter(f => {
      const fullPath = resolve(path, f);
      return statSync(fullPath).isDirectory() && fullPath.includes(includedStr);
    });
  }
  return [];
};

const pkgListPaths = [
  globalDirs.npm.packages,
  globalDirs.npm.packages !== globalDirs.yarn.packages &&
    globalDirs.yarn.packages,
  resolve(process.cwd(), 'node_modules'),
].filter(Boolean);

const externalPlugins = pkgListPaths.reduce((acc, pkgListPath) => {
  const orgPluginPath = resolve(pkgListPath, '@mamba');
  return [
    ...acc,
    ...getPackagesFrom(pkgListPath, 'mamba-cli-plugin-'),
    ...getPackagesFrom(orgPluginPath, 'cli-plugin-').map(
      pkg => `@mamba/${pkg}`,
    ),
  ];
}, []);

global-dirs

Get the directory of globally installed packages and binaries

MIT
Latest version published 6 months ago

Package Health Score

58 / 100
Full package analysis

Popular global-dirs functions