How to use pkg-dir - 10 common examples

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 RadarTech / lnrpc / src / rpc / ln-rpc.ts View on Github external
export async function createLnRpc(userConfig: LnRpcClientConfig): Promise {
  const rootPath = await pkgDir(__dirname);
  const protoFilePath = join(
    rootPath,
    `lnd/${packageJson.config['lnd-release-tag']}/rpc.proto`,
  );

  // Configuration options
  const config = {
    ...defaults,
    ...userConfig,
  };
  const { lightning, walletUnlocker, server, grpcLoader, grpc, includeDefaults } = config;

  // Generate grpc SSL credentials
  const credentials = await createCredentials(config);

  // Create RPC from proto and return GRPC
github RadarTech / lnrpc / src / rpc / chain-rpc.ts View on Github external
export async function createChainRpc(userConfig: ChainRpcClientConfig): Promise {
  const rootPath = await pkgDir(__dirname);
  const protoFilePath = join(
    rootPath,
    `lnd/${packageJson.config['lnd-release-tag']}/chainrpc/chainnotifier.proto`,
  );

  // Configuration options
  const config = {
    ...defaults,
    ...userConfig,
  };
  const { chainNotifier, server, grpcLoader, grpc, includeDefaults } = config;

  // Generate grpc SSL credentials
  const credentials = await createCredentials(config);

  // Create RPC from proto and return GRPC
github tommy351 / kosko / integration / run.ts View on Github external
export async function runCLI(
  args: string[],
  options: execa.Options = {}
): Promise {
  const root = await pkgDir();

  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  return execa(join(root!, "packages", "cli", "bin", "kosko.js"), args, {
    ...options,
    env: {
      LC_ALL: "en_US",
      ...options.env
    }
  });
}
github RadarTech / lnrpc / src / rpc / wallet-rpc.ts View on Github external
export async function createWalletRpc(userConfig: WalletRpcClientConfig): Promise {
  const rootPath = await pkgDir(__dirname);
  const lndProtosRootPath = join(
    rootPath,
    `lnd/${packageJson.config['lnd-release-tag']}`,
  );
  const protoFilePath = join(
    lndProtosRootPath,
    '/walletrpc/walletkit.proto',
  );

  // Configuration options
  const config = {
    ...defaults,
    ...userConfig,
  };
  const { walletKit, server, grpcLoader, grpc, includeDefaults } = config;
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 Jordaneisenburger / fallback-studio / src / pwa-studio / packages / pwa-buildpack / lib / WebpackTools / __tests__ / configureWebpack.spec.js View on Github external
jest.mock('fs');
jest.mock('pkg-dir');
jest.mock('webpack-assets-manifest');
jest.mock('../../Utilities/loadEnvironment');
jest.mock('../plugins/RootComponentsPlugin');
jest.mock('../PWADevServer');

const fs = require('fs');
const pkgDir = require('pkg-dir');
const WebpackAssetsManifest = require('webpack-assets-manifest');
const RootComponentsPlugin = require('../plugins/RootComponentsPlugin');
const loadEnvironment = require('../../Utilities/loadEnvironment');
const configureWebpack = require('../configureWebpack');

pkgDir.mockImplementation(x => x);

const mockStat = (dir, file, err = null) => {
    fs.stat.mockImplementationOnce((_, callback) =>
        callback(err, { isDirectory: () => dir, isFile: () => file })
    );
};

const mockEnv = prod =>
    loadEnvironment.mockReturnValueOnce({
        env: process.env,
        sections: jest.fn(),
        section: jest.fn(),
        isProd: prod
    });

const simulate = {
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. 
		`);
	}
};

pkg-dir

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

MIT
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis