Every line of 'yarn add dev dependency' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
16 public async add( 17 dependencyPath: PackagePath, 18 { 19 dev, 20 peer, 21 }: { 22 dev?: boolean 23 peer?: boolean 24 } = {} 25 ) { 26 // Special handling with yarn add when the dependency is a local file path 27 // In that case, for some reason it copies the node_modules directory of this path, which 28 // is not a wanted behavior, especially for react-native bundling as it will create 29 // haste module naming collisions 30 // As a temporaray work-around, we copy the whole package directory to a temporary one 31 // and remove node_modules from there and use this new path instead when yarn adding 32 // Issue has been opened here https://github.com/yarnpkg/yarn/issues/1334 33 // (still open as of this comment writing) 34 // [Note: We tried another lighter workaround being to just remove the node_modules 35 // directory contained within this package after yarn add is executed. Howver subsequent 36 // yarn add of a different dependency just reintroduce the error on previous package 37 // this is really weird] 38 if (dependencyPath.isFilePath) { 39 const tmpDirPath = createTmpDir() 40 shell.cp('-R', path.join(dependencyPath.basePath, '{.*,*}'), tmpDirPath) 41 shell.rm('-rf', path.join(tmpDirPath, 'node_modules')) 42 dependencyPath = PackagePath.fromString(`file:${tmpDirPath}`) 43 } 44 45 const cmd = `add ${dependencyPath.toString()} --ignore-engines --non-interactive --exact ${ 46 dev ? '--dev' : '' 47 } ${peer ? '--peer' : ''}` 48 return this.runYarnCommand(cmd) 49 }
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
117 function installDevDependencies(devDependencies) { 118 return new Promise(async (resolve, reject) => { 119 resolve(); 120 echo('Installing dev dependencies...'); 121 echo(devDependencies) 122 try { 123 await execute(`npm install --save-dev ${devDependencies.join(' ')}`, { 124 cwd: ROOT, 125 }); 126 127 // resolve(); 128 } catch (e) { 129 // echo(cli.red(e)); 130 // resolve(); 131 } 132 }); 133 }
50 function yarnLink(deps) { 51 // Link dependencies with yarn 52 deps.forEach(dep => { 53 yarn('link', dep); 54 }); 55 56 // Link binaries by hand (yarn doesn't do it) 57 deps.forEach(dep => { 58 const depPkgJson = readJsonSync( 59 path.join('.', 'node_modules', dep, 'package.json') 60 ); 61 62 const bins = depPkgJson.bin || {}; 63 64 Object.entries(bins).forEach(([bin, script]) => { 65 const scriptPath = path.join('..', dep, script); 66 const binPath = path.join('.', 'node_modules', '.bin', bin); 67 68 console.log('symlink', scriptPath, '->', binPath); 69 fs.ensureSymlinkSync(scriptPath, binPath); 70 }); 71 }); 72 }
39 addDevDependency(name, semver) { 40 name = this._escapeProp(name); 41 42 this.modifyJson(json => { 43 prop.set(json, `devDependencies.${name}`, semver); 44 }); 45 }
70 public devDependencyExists(name: string): string | false { 71 if (!this.pkg) { 72 return false; 73 } 74 75 return this.devDependencies[name] || false; 76 }
31 export function getDependencyFromYarn(entry: any): PackageDependency | null { 32 let entryList = convertEntryToList(entry); 33 const packages = getPackageList(); 34 if (!packages) { 35 return null; 36 } 37 38 const root = packages[".@."]; 39 if (!root || !root.dependencies) { 40 return; 41 } 42 43 entryList = entryList 44 .map(item => { 45 const version = root.dependencies[item]; 46 return version ? `${item}@${version}` : ""; 47 }) 48 .filter(item => !!item); 49 50 function findDependency( 51 entryList: string[], 52 history?: string[] 53 ): PackageDependency { 54 let m: PackageDependency = {}; 55 entryList.map(k => { 56 if (history && history.indexOf(k) >= 0) { 57 // skip circular dependency 58 return; 59 } 60 const info = packages[k]; 61 let item: YarnDependency = { 62 version: info.version 63 }; 64 if (info.dependencies) { 65 item.dependencies = findDependency( 66 Object.keys(info.dependencies).map( 67 k => `${k}@${info.dependencies[k]}` 68 ), 69 history ? [...history, k] : [k] 70 ); 71 } 72 73 m[k] = item; 74 }); 75 return m; 76 } 77 78 return findDependency(entryList); 79 }
13 async function addDependencies(npmOptions) { 14 const [ 15 storybookVersion, 16 notesVersion, 17 actionsVersion, 18 linksVersion, 19 addonsVersion, 20 ] = await getVersions( 21 npmOptions, 22 '@storybook/angular', 23 '@storybook/addon-notes', 24 '@storybook/addon-actions', 25 '@storybook/addon-links', 26 '@storybook/addons' 27 ); 28 29 const packageJson = getPackageJson(); 30 31 packageJson.dependencies = packageJson.dependencies || {}; 32 packageJson.devDependencies = packageJson.devDependencies || {}; 33 34 packageJson.scripts = packageJson.scripts || {}; 35 packageJson.scripts.storybook = 'start-storybook -p 6006'; 36 packageJson.scripts['build-storybook'] = 'build-storybook'; 37 38 writePackageJson(packageJson); 39 40 const babelDependencies = await getBabelDependencies(npmOptions, packageJson); 41 42 installDependencies(npmOptions, [ 43 `@storybook/angular@${storybookVersion}`, 44 `@storybook/addon-notes@${notesVersion}`, 45 `@storybook/addon-actions@${actionsVersion}`, 46 `@storybook/addon-links@${linksVersion}`, 47 `@storybook/addons@${addonsVersion}`, 48 ...babelDependencies, 49 ]); 50 }
109 removeYarnLockFile() { 110 let filePath = path.join(this.project.dir, "yarn.lock"); 111 if (fs.existsSync(filePath)) { 112 fs.unlinkSync(filePath); 113 } 114 }
9 export function installNPMDependencies(ctx: BuildContext) { 10 return new Promise((resolve, reject) => { 11 exec(`npm install`, { 12 cwd: ctx.projectFolder, 13 }, (error, stdout) => { 14 15 if (error === null) { 16 resolve(); 17 } else { 18 reject(Error(stdout)); 19 } 20 }); 21 }); 22 }
42 async install() { 43 console.log('about to install', [this.nameAndVersion], process.cwd()) 44 await npm.install([this.nameAndVersion], { save: true, cwd: process.cwd() }) 45 }