Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ci: provide a fix for broken lerna symlinks on windows * Update appveyor.yml
- Loading branch information
Showing
5 changed files
with
167 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${file}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/usr/bin/env node | ||
|
||
// See: https://github.com/microsoft/vscode-languageserver-node/blob/master/build/bin/linking.js | ||
|
||
const path = require('path'); | ||
const shell = require('shelljs'); | ||
|
||
const fs = require('fs'); | ||
const promisify = require('util').promisify; | ||
const mkdir = promisify(fs.mkdir); | ||
const exists = promisify(fs.exists); | ||
const readdir = promisify(fs.readdir); | ||
const readFile = promisify(fs.readFile); | ||
|
||
/** | ||
* @param {string} module | ||
* @param {string} name | ||
* @param {string} source | ||
*/ | ||
async function symlink(module, name, source) { | ||
const current = process.cwd(); | ||
try { | ||
const nodeModules = path.join(module, 'node_modules'); | ||
if (!await exists(nodeModules)) { | ||
await mkdir(nodeModules); | ||
} | ||
process.chdir(nodeModules); | ||
if (await exists(name)) { | ||
shell.rm('-rf' , name); | ||
} | ||
shell.ln('-s', source, name); | ||
} finally { | ||
process.chdir(current); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param {string} file | ||
* @returns {Object|undefined} | ||
*/ | ||
async function readPackage(file) { | ||
if (!(await exists(file))) { | ||
return undefined; | ||
} | ||
|
||
const json = await readFile(file, 'utf8'); | ||
return JSON.parse(json); | ||
} | ||
|
||
/** | ||
* | ||
* @param {string} dir | ||
* @returns {Object[]} returns the contents of package.json keyed by the directory | ||
*/ | ||
async function readPackages(dir) { | ||
const packageDirs = await readdir(dir); | ||
|
||
const packages = []; | ||
for (const package of packageDirs) { | ||
const packageDir = path.join(dir, package); | ||
const p = await readPackage(path.join(packageDir, 'package.json')); | ||
if (p) { | ||
p._packageDir = packageDir; | ||
packages.push(p); | ||
} | ||
} | ||
|
||
return packages; | ||
} | ||
|
||
/** | ||
* @param {Object[]} packages | ||
* @returns {Map<string,string} | ||
*/ | ||
function mapByPackageName(packages) { | ||
const map = new Map( | ||
packages | ||
.filter(p => !!p.name) | ||
.map(p => [p.name, p._packageDir]) | ||
); | ||
return map; | ||
} | ||
|
||
function extractDependencies(package) { | ||
return Object.keys(package.dependencies || {}).concat(Object.keys(package.devDependencies || {})); | ||
} | ||
|
||
/** | ||
* | ||
* @param {Object[]} packages | ||
*/ | ||
async function symLinkPackages(packages) { | ||
const mapByName = mapByPackageName(packages); | ||
|
||
for (const package of packages) { | ||
console.log('Linking ' + package.name) | ||
const deps = extractDependencies(package); | ||
for (dep of deps) { | ||
const location = mapByName.get(dep); | ||
if (location) { | ||
console.log(' SymLink ' + dep) | ||
await symlink(package._packageDir, dep, location) | ||
} | ||
} | ||
} | ||
} | ||
|
||
async function main() { | ||
const packagesRoot = path.resolve(process.argv[2] || 'packages'); | ||
const packages = await readPackages(packagesRoot); | ||
symLinkPackages(packages); | ||
} | ||
|
||
main(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters