How to use the pkg-dir.sync function in pkg-dir

To help you get started, we’ve selected a few pkg-dir 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 openbmc / phosphor-webui / webpack.config.js View on Github external
// Modules
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
var HtmlWebpackInlineSourcePlugin =
    require('html-webpack-inline-source-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var CompressionPlugin = require('compression-webpack-plugin');
var path = require('path');
var FilterChunkWebpackPlugin = require('filter-chunk-webpack-plugin');
var MiniCssExtractPlugin = require('mini-css-extract-plugin');

const isPathInside = require('is-path-inside')
const pkgDir = require('pkg-dir')
const coreJsDir = pkgDir.sync(require.resolve('core-js'))

module.exports = (env, options) => {
  var isProd = options.mode === 'production';

  /**
   * Config
   * Reference: http://webpack.github.io/docs/configuration.html
   * This is the object where all configuration gets set
   */
  var config = {};

  /**
   * Entry
   * Reference: http://webpack.github.io/docs/configuration.html#entry
   * Should be an empty object if it's generating a test build
   * Karma will set this when it's a test build
github dojo / cli / src / commands / version.ts View on Github external
function createVersionsString(groupMap: GroupMap, checkOutdated: boolean): Promise {
	const packagePath = pkgDir.sync(__dirname);
	const myPackageDetails = readPackageDetails(packagePath); // fetch the cli's package details
	const versions: ModuleVersion[] = buildVersions(groupMap);
	if (checkOutdated) {
		return areCommandsOutdated(versions).then(
			(commandVersions: ModuleVersion[]) => createOutput(myPackageDetails, commandVersions),
			(err) => {
				return `Something went wrong trying to fetch command versions: ${err.message}`;
			}
		);
	} else {
		return Promise.resolve(createOutput(myPackageDetails, versions));
	}
}
github foray1010 / didyoumean2 / test / lib / normalizeString.js View on Github external
'use strict'

const rootPath = require('pkg-dir').sync(__dirname)

const normalizeString = require(`${rootPath}/src/lib/normalizeString`)

test('caseSensitive', () => {
  expect(
    normalizeString('AbC', {
      caseSensitive: false
    })
  ).toBe('abc')

  expect(
    normalizeString('AbC', {
      caseSensitive: true
    })
  ).toBe('AbC')
})
github foray1010 / didyoumean2 / test / index.js View on Github external
'use strict'

const assocPath = require('ramda/src/assocPath')
const Immutable = require('seamless-immutable').static
const rootPath = require('pkg-dir').sync(__dirname)

const didYouMean = require(rootPath)
const returnTypeEnums = require(`${rootPath}/src/enums/returnTypeEnums`)
const thresholdTypeEnums = require(`${rootPath}/src/enums/thresholdTypeEnums`)

const ALL_CLOSEST_MATCHES = returnTypeEnums.ALL_CLOSEST_MATCHES
const ALL_MATCHES = returnTypeEnums.ALL_MATCHES
const ALL_SORTED_MATCHES = returnTypeEnums.ALL_SORTED_MATCHES
const FIRST_CLOSEST_MATCH = returnTypeEnums.FIRST_CLOSEST_MATCH
const FIRST_MATCH = returnTypeEnums.FIRST_MATCH

const EDIT_DISTANCE = thresholdTypeEnums.EDIT_DISTANCE
const SIMILARITY = thresholdTypeEnums.SIMILARITY

const input = 'abcdefghij'
const matchList = Immutable([
github sindresorhus / np / source / npm / util.js View on Github external
exports.checkIgnoreStrategy = ({files}) => {
	const rootDir = pkgDir.sync();
	const npmignoreExists = fs.existsSync(path.resolve(rootDir, '.npmignore'));

	if (!files && !npmignoreExists) {
		console.log(`
		\n${chalk.bold.yellow('Warning:')} No ${chalk.bold.cyan('files')} field specified in ${chalk.bold.magenta('package.json')} nor is a ${chalk.bold.magenta('.npmignore')} file present. Having one of those will prevent you from accidentally publishing development-specific files along with your package's source code to npm. 
		`);
	}
};
github dojo / cli / src / commands / init.ts View on Github external
async function run(helper: Helper, args: { dojorc?: string } = {}) {
	const cwd = process.cwd();
	let rootDir = pkgDir.sync(cwd);
	if (!rootDir) {
		console.warn(noPackageWarning);
		rootDir = cwd;
	}

	const dojoRcPath = join(rootDir, args.dojorc || '.dojorc');
	const file = existsSync(dojoRcPath) && readFileSync(dojoRcPath, 'utf8');
	let json: { [name: string]: {} } = {};
	let indent = '\t';

	if (file) {
		indent = detectIndent(file).indent || indent;
		json = JSON.parse(file);
	}

	const groupMap = await loadExternalCommands();
github xing / hops / packages / build-config / lib / check-esnext.js View on Github external
function checkEsnextConfig(filepath) {
  var pkgDir = getPkgDir(path.dirname(filepath));
  var packageJsonPath = path.join(pkgDir, 'package.json');
  if (fs.existsSync(packageJsonPath)) {
    var json = fs.readFileSync(packageJsonPath, 'utf8');
    return /"((e|j)snext(:(browser|server|main))?)":/m.test(json);
  }
}
github wix / import-cost / src / packageInfo.ts View on Github external
import * as fs from 'fs';
import * as path from 'path';
import * as workerFarm from 'worker-farm';
import * as pkgDir from 'pkg-dir';
import {debouncePromise, DebounceError} from './debouncePromise';
import {workspace} from 'vscode';

const workers = workerFarm(require.resolve('./webpack'), ['calcSize']);
const extensionVersion = getVersion(pkgDir.sync(__dirname));
const cacheFile = path.join(__dirname, `ic-cache-${extensionVersion}`);
let sizeCache = {};
const versionsCache = {};
readSizeCache();

export async function getSize(pkg) {
  try {
    versionsCache[pkg.string] = versionsCache[pkg.string] || getPackageVersion(pkg);
  } catch (e) {
    return {...pkg, size: 0};
  }
  const key = `${pkg.string}#${versionsCache[pkg.string]}`;
  if (sizeCache[key] === undefined || sizeCache[key] instanceof Promise) {
    try {
      sizeCache[key] = sizeCache[key] || calcPackageSize(pkg);
      sizeCache[key] = await sizeCache[key];
github codejamninja / reactant / packages / web / src / storybook / webpack.config.js View on Github external
modules.forEach(module => {
    try {
      const modulePath = pkgDir.sync(
        require.resolve(path.resolve(rootPath, 'node_modules', module))
      );
      includes.push(modulePath);
    } catch (err) {}
  });
  return includes;
github dojo / widgets / support / grunt / config.ts View on Github external
const pkgDir = require('pkg-dir');
const {join} = require('path');
const createProcessors = require('grunt-dojo2/tasks/util/postcss').createProcessors;

const packagePath = pkgDir.sync(process.cwd());

const fontFiles = 'theme/fonts/*.{svg,ttf,woff}';
const staticExampleFiles = [ '*/example/**', '!*/example/**/*.js' ];
const staticTestFiles = '*/tests/**/*.{html,css,json,xml,js,txt}';

export const copy = {
	'staticDefinitionFiles-dev': {
		cwd: 'src',
		src: [ '<%= staticDefinitionFiles %>' ],
		dest: '<%= devDirectory %>'
	},
	staticTestFiles: {
		expand: true,
		cwd: 'src',
		src: [ staticTestFiles ],
		dest: '<%= devDirectory %>'

pkg-dir

Find the root directory of a Node.js project or npm package

MIT
Latest version published 7 months ago

Package Health Score

76 / 100
Full package analysis