-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor to more generic code #12
Merged
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.nyc_output | ||
.tap | ||
node_modules | ||
package-lock.json |
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,123 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
const semver = require('semver') | ||
|
||
const ltsNames = { | ||
4: 'argon', | ||
6: 'boron', | ||
8: 'carbon', | ||
10: 'dubnium', | ||
12: 'erbium', | ||
14: 'fermium', | ||
16: 'gallium', | ||
18: 'hydrogen' | ||
} | ||
|
||
class Linker { | ||
#links = new Map() | ||
#dirs = [] | ||
#baseDir | ||
#docsDir | ||
constructor ({ baseDir, docsDir }) { | ||
this.#baseDir = baseDir | ||
this.#docsDir = docsDir | ||
} | ||
|
||
async getLinks (allDirectories, readDir) { | ||
const allDirs = allDirectories | ||
.map((d) => path.basename(d)) | ||
.map((d) => { | ||
try { | ||
return semver.parse(d) | ||
/* c8 ignore next 3 */ | ||
} catch (e) { | ||
return null | ||
} | ||
}) | ||
.filter(Boolean) | ||
|
||
this.#makeDocsLinks(allDirs.map((d) => d.raw)) | ||
|
||
this.#dirs = allDirs.filter((d) => semver.satisfies(d, '~0.10 || ~0.12 || >= 1.0')).map((d) => d.raw) | ||
this.#dirs.sort((d1, d2) => semver.compare(d1, d2)) | ||
|
||
this.#link('0.10') | ||
this.#link(0.12) | ||
|
||
for (let i = 1; ; i++) { | ||
if (!this.#link(i) && i >= 4) { | ||
break | ||
} | ||
} | ||
|
||
const max = this.#link(null) | ||
const tbreg = new RegExp(`(\\w+)-${max}.tar.gz`) | ||
const latestDir = path.join(this.#baseDir, 'latest') | ||
|
||
let tarball = (await readDir(this.#links.get(latestDir) || latestDir)).filter((f) => tbreg.test(f)) | ||
|
||
/* c8 ignore next 3 */ | ||
if (tarball.length !== 1) { | ||
throw new Error('Could not find latest.tar.gz') | ||
} | ||
|
||
tarball = tarball[0] | ||
const name = tarball.match(tbreg)[1] | ||
const dst = path.join(this.#baseDir, `${name}-latest.tar.gz`) | ||
this.#links.set(dst, path.join(this.#baseDir, 'latest', tarball)) | ||
return this.#links | ||
} | ||
|
||
#makeDocsLinks (versions) { | ||
if (!this.#docsDir) { | ||
return | ||
} | ||
|
||
for (const version of versions) { | ||
const src = path.join(this.#baseDir, version, 'docs') | ||
const dst = path.join(this.#docsDir, version) | ||
this.#links.set(dst, src) | ||
} | ||
} | ||
|
||
#link (version) { | ||
const line = version && `${version}.x` | ||
const range = version ? `${Number(version) < 1 ? '~' : '^'}${line}` : '*' | ||
const max = semver.maxSatisfying(this.#dirs, range) | ||
|
||
if (!max) { | ||
return false | ||
} | ||
|
||
const symlink = (name) => { | ||
const dst = path.join(this.#baseDir, name) | ||
const src = path.join(this.#baseDir, max) | ||
|
||
this.#links.set(dst, src) | ||
|
||
if (!this.#docsDir) { | ||
return | ||
} | ||
|
||
const dsrc = path.join(this.#baseDir, max, 'docs') | ||
const ddst = path.join(this.#docsDir, name) | ||
this.#links.set(ddst, dsrc) | ||
} | ||
|
||
if (line) { | ||
symlink(`latest-v${line}`) | ||
if (ltsNames[version]) { | ||
symlink(`latest-${ltsNames[version]}`) | ||
} | ||
} else { | ||
symlink('latest') | ||
} | ||
|
||
return max | ||
} | ||
} | ||
|
||
module.exports = { | ||
Linker | ||
} |
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
"main": "latest-linker.js", | ||
"scripts": { | ||
"lint": "standard", | ||
"test": "npm run lint && tap test.js" | ||
"test": "npm run lint && tap --allow-incomplete-coverage test.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|
@@ -14,15 +14,14 @@ | |
"author": "Rod <[email protected]> (http://r.va.gg/)", | ||
"license": "MIT", | ||
"dependencies": { | ||
"map-async": "^0.1.1", | ||
"semver": "^7.3.2" | ||
}, | ||
"bin": { | ||
"nodejs-latest-linker": "latest-linker.js" | ||
}, | ||
"preferGlobal": true, | ||
"devDependencies": { | ||
"tap": "^14.10.8", | ||
"standard": "^14.3.4" | ||
"standard": "^17.1.0", | ||
"tap": "^18.4.0" | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep testing on Node.js 12 until we can upgrade the version of Node.js used to run this tool on our server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, that breaks using modern javascript async/await ect :/
What is needed to upgrade node.js on the www server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current server is running Ubuntu 16.04 and using nodesource to install Node.js. I'm not sure whether Nodesource provide later versions of Node.js on Ubuntu 16.04. I'd like to update the OS on the server but it's risky given how dependent we are on that droplet at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so we would either need to adjust this to run on node 12 or upgrade node without using nodesource, since upgrading the OS is not trivial
I prefer the second option, is that possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Node.js 18 is a non-starter on Ubuntu 16.04 due to glibc versions. Node.js 16 is a possibility -- there may even be a Nodesource distribution for it (I'd suggest testing in a separate Ubuntu 16.04 system first).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MoLow Yes, it should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the fact that https://deb.nodesource.com/node_16.x/dists/xenial/Release returns something, I think v16.x can be installed using the NodeSource distribution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was able to install node16 on ubuntu 16.04 using nodesource. let me check these changes work on node 16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests have passed. @richardlau should I go ahead and update www nodejs version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MoLow Yes (and keep an eye on tomorrow's nightly to check the indexer still runs ok). If you could also update https://github.com/nodejs/build/blob/b8b63ade1e76d8ccf669335ee384ed2ee34a3abe/ansible/www-standalone/tasks/base.yaml#L1-L3 (which says Node.js 8 but we are definitely running with 12 on the server) that would be great.