link-module-alias
Advanced tools
+19
-15
@@ -28,3 +28,2 @@ #!/usr/bin/env node | ||
| const writeFile = promisify(fs.writeFile); | ||
| const execFile = promisify(child_process.execFile); | ||
| const unlink = promisify(fs.unlink); | ||
@@ -40,9 +39,9 @@ const readdir = promisify(fs.readdir); | ||
| if(type === 'none') { | ||
| moduleName = chalk.red(moduleName); | ||
| return chalk.red(moduleName) + ` -> ${chalk.bold(chalk.red('ALREADY EXISTS'))}`; | ||
| } else if(type === 'symlink') { | ||
| moduleName = chalk.cyan(moduleName); | ||
| return chalk.cyan(moduleName) + ` -> ${chalk.bold(target)}`; | ||
| } else if(type === 'proxy') { | ||
| moduleName = chalk.green(moduleName); | ||
| return chalk.green(moduleName) + ` -> ${chalk.bold(target)}`; | ||
| } | ||
| return `${moduleName} -> ${chalk.bold(target)}`; | ||
| return `${moduleName} `; | ||
| } | ||
@@ -71,9 +70,8 @@ | ||
| async function unlinkModule(moduleName) { | ||
| const moduleDir = path.join('node_modules', moduleName); | ||
| let statKey; | ||
| try { | ||
| statKey = await lstat(`node_modules/${moduleName}`); | ||
| statKey = await lstat(moduleDir); | ||
| } catch(err) {} | ||
| const moduleDir = path.join('node_modules', moduleName); | ||
| let type; | ||
@@ -105,3 +103,4 @@ if(statKey && statKey.isSymbolicLink()) { | ||
| async function linkModule(moduleName) { | ||
| const moduleExists = await exists(`node_modules/${moduleName}`); | ||
| const moduleDir = path.join('node_modules', moduleName); | ||
| const moduleExists = await exists(moduleDir); | ||
| const linkExists = moduleExists && await exists(`node_modules/.link-module-alias-${moduleName}`); | ||
@@ -112,3 +111,3 @@ const target = moduleAliases[moduleName]; | ||
| if(moduleExists && !linkExists) { | ||
| console.error(`Module ${moduleName} already exists and wasn't created by us, skipping`); | ||
| console.error(chalk.red(`Module ${moduleName} already exists and wasn't created by us, skipping`)); | ||
| type = 'none'; | ||
@@ -122,4 +121,4 @@ return { moduleName, type, target }; | ||
| // console.log(`Target ${target} is a direct link, creating proxy require`); | ||
| await mkdir(`node_modules/${moduleName}`); | ||
| await writeFile(`node_modules/${moduleName}/package.json`, js` | ||
| await mkdir(moduleDir); | ||
| await writeFile(path.join(moduleDir, 'package.json'), js` | ||
| { | ||
@@ -138,6 +137,6 @@ "name": ${moduleName}, | ||
| } | ||
| await symlink(path.join('../', target), `node_modules/${moduleName}`); | ||
| await symlink(path.join('../', target), moduleDir, 'dir'); | ||
| type = 'symlink'; | ||
| } | ||
| await writeFile(`node_modules/.link-module-alias-${moduleName}`, ''); | ||
| await writeFile(path.join('node_modules', `.link-module-alias-${moduleName}`), ''); | ||
| return { moduleName, type, target }; | ||
@@ -147,2 +146,3 @@ } | ||
| async function linkModules() { | ||
| try { await mkdir('node_modules'); } catch(err) {} | ||
| const modules = await Promise.all(Object.keys(moduleAliases).map(async key => { | ||
@@ -155,2 +155,6 @@ return linkModule(key); | ||
| async function unlinkModules() { | ||
| const nodeModulesExists = await exists('node_modules'); | ||
| if(!nodeModulesExists) { | ||
| return; | ||
| } | ||
| const allModules = await readdir('node_modules'); | ||
@@ -168,3 +172,3 @@ | ||
| console.log('link-module-alias: Cleaned ', unlinkedModules.filter(v => { | ||
| return v !== 'none'; | ||
| return v.type !== 'none'; | ||
| }).map(addColorUnlink).join(' ')); | ||
@@ -171,0 +175,0 @@ } else { |
+1
-1
| { | ||
| "name": "link-module-alias", | ||
| "version": "1.1.2", | ||
| "version": "1.1.3", | ||
| "description": "Create permanent links for _moduleAliases", | ||
@@ -5,0 +5,0 @@ "bin": "index.js", |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
6741
2.82%154
3.36%