Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
name: string,
target: string,
packageDir?: string,
): Promise {
if (!target) {
throw new Error(`Error in getPackage: Please provide a target`)
}
packageDir =
packageDir ||
resolvePkg(name, { cwd: __dirname }) ||
resolvePkg(name, { cwd: target })
debug({ packageDir })
if (!packageDir) {
const pkg = await readPkgUp({
cwd: target,
})
if (pkg && pkg.packageJson.name === name) {
packageDir = path.dirname(pkg.path)
}
}
if (!packageDir) {
throw new Error(
`Error in getPackage: Could not resolve package ${name} from ${__dirname}`,
)
}
const tmpDir = tempy.directory() // thanks Sindre
const archivePath = path.join(tmpDir, `package.tgz`)
// pack into a .tgz in a tmp dir
export function checkUpdate (): void {
readPkgUp({ cwd: __dirname })
.then(pack => {
if (!pack) {
throw new Error('package.json not found')
}
const pkg = pack.package
// 1 week
const updateCheckInterval = 1000 * 60 * 60 * 24 * 7
const notifier = new UpdateNotifier({
pkg,
updateCheckInterval,
})
notifier.notify()
return null
})
import { GraphQLServer } from "graphql-yoga";
import "reflect-metadata";
import { getSchema } from "./api";
import resultHandlerApi from "./services/result-handler-api";
import getPort from "get-port";
import * as parseArgs from "minimist";
import * as chromeLauncher from "chrome-launcher";
import * as opn from "open";
import "consola";
import { initializeStaticRoutes } from "./static-files";
import { root } from "./services/cli";
import * as readPkgUp from "read-pkg-up";
const pkg = readPkgUp.sync({
cwd: __dirname
}).pkg;
declare var consola: any;
const args = parseArgs(process.argv);
const defaultPort = args.port || 4000;
process.env.DEBUG_LOG = args.debug ? "log" : "";
if (args.root) {
process.env.ROOT = args.root;
}
if (args.version) {
console.log(`v${pkg.version}`);
process.exit();
}
(async () => {
if (cli.input.length > 0) {
await openPackage(cli.input[0]);
} else {
const result = readPkgUp.sync();
if (!result) {
console.error('You\'re not in an npm package');
process.exit(1);
}
await openPackage(result.package.name);
}
})();
async addModule(contextPath, modulePath, {env}) {
const isModuleExcluded = this.exclude.includes(modulePath) ||
(this.only && !this.only.includes(modulePath));
if (isModuleExcluded) {
return false;
}
const moduleName = modulePath.match(moduleRegex)[1];
const {pkg: {version, peerDependencies}} = await readPkgUp({cwd: resolvePkg(moduleName, {cwd: contextPath})});
const isModuleAlreadyLoaded = Boolean(this.modulesFromCdn[modulePath]);
if (isModuleAlreadyLoaded) {
const isSameVersion = this.modulesFromCdn[modulePath].version === version;
if (isSameVersion) {
return this.modulesFromCdn[modulePath].var;
}
return false;
}
const cdnConfig = await this.resolver(modulePath, version, {env});
if (cdnConfig == null) {
if (this.verbose) {
console.log(`❌ '${modulePath}' couldn't be found, please add it to https://github.com/mastilver/module-to-cdn/blob/master/modules.json`);
async function printDependenciesVersion() {
const { pkg } = await readPkgUp({ cwd: baseFolder });
for (let [key, value] of Object.entries(pkg.dependencies)) {
console.log(` - ${key}: ${value}`);
}
}
it('should extract github repo info from package.json', async () => {
readPkgUp.mockImplementationOnce(() => Promise.resolve({
pkg: {
name: 'gitmoji-changelog',
version: '0.0.1',
description: 'Gitmoji Changelog CLI',
},
}))
const result = await loadProjectInfo()
expect(result).toEqual({
name: 'gitmoji-changelog',
version: '0.0.1',
description: 'Gitmoji Changelog CLI',
})
})
})
const path = require('path');
const packageinfo = require("read-pkg-up").sync().package;
const camelCase = require("camelcase");
module.exports = {
entry: './src/index.ts',
output: {
path: path.resolve(path.join(__dirname, '.', 'dist')),
filename: 'mui-form-fields.js',
library: 'MuiFormFields',
libraryTarget: 'umd',
globalObject: 'this',
},
module: {
rules: [
{
test: /\.js$/,
function getStandard (editor) {
const result = readPgkUp.sync({cwd: Path.dirname(editor.getPath())})
if (result && result.pkg) {
const {dependencies, devDependencies} = result.pkg
if ((dependencies && 'standard' in dependencies) || (devDependencies && 'standard' in devDependencies)) {
const libPath = Path.join(Path.dirname(result.path), 'node_modules', 'standard')
return require(libPath)
}
}
if (!BUNDLED_STANDARD) BUNDLED_STANDARD = require('standard')
return BUNDLED_STANDARD
}
function hasClosestPackageJsonHasPackage (cwd, name) {
const result = readPgkUp.sync({cwd})
if (!result || !result.pkg) return false
const {dependencies, devDependencies} = result.pkg
return (dependencies && name in dependencies) || (devDependencies && name in devDependencies)
}