-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
7,523 additions
and
18,982 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
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,49 +1,29 @@ | ||
dist/* | ||
# node | ||
node_modules | ||
|
||
# Yarn | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/releases | ||
!.yarn/plugins | ||
!.yarn/sdks | ||
!.yarn/versions | ||
!.yarnrc.yml | ||
.pnp.* | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
*.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
# Coverage | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
*.lcov | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity |
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 @@ | ||
nodeLinker: node-modules |
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
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,80 @@ | ||
#!/usr/bin/env node | ||
|
||
import path from 'node:path' | ||
import {promises, createWriteStream} from 'node:fs' | ||
import {promisify} from 'node:util' | ||
import child_process from 'node:child_process' | ||
|
||
async function read(file, options = {}) { | ||
let filehandle | ||
let content | ||
try { | ||
filehandle = await promises.open(file, 'r') | ||
content = await filehandle.readFile(options) | ||
} finally { | ||
if (filehandle) { | ||
await filehandle.close() | ||
} | ||
} | ||
return content | ||
} | ||
|
||
const exec = promisify(child_process.exec) | ||
const packageFile = path.resolve(process.cwd(), 'package.json') | ||
const packageBuf = await read(packageFile) | ||
const packageJson = JSON.parse(packageBuf) | ||
|
||
const { | ||
dependencies, | ||
devDependencies | ||
} = packageJson | ||
|
||
let cc = 0 | ||
|
||
function _error(message) { | ||
process.stderr.write(message) | ||
process.exit(1) | ||
} | ||
|
||
function getLatestVersionPackage(data, prop) { | ||
if (!data) { | ||
return Promise.resolve('no data to show') | ||
} | ||
|
||
const keys = Object.keys(data) | ||
return Promise.allSettled(keys.map(async name => { | ||
const cmd = `npm show ${name} version` | ||
try { | ||
let {stdout: version} = await exec(cmd) | ||
version = String(version).replace('\n', '') | ||
if (version && data[name] !== String(version)) { | ||
cc++ | ||
process.stdout.write(`${name} --> ${version}\n`) | ||
packageJson[prop][name] = version | ||
return {name, version} | ||
} | ||
} catch {} | ||
return Promise.reject() | ||
})) | ||
} | ||
|
||
try { | ||
await Promise.all([ | ||
getLatestVersionPackage(dependencies, 'dependencies'), | ||
getLatestVersionPackage(devDependencies, 'devDependencies') | ||
]) | ||
|
||
createWriteStream(packageFile) | ||
.on('finish', () => { | ||
process.stdout.write(cc > 0 ? 'All writes are now complete.' : 'No updates') | ||
}) | ||
.on('close', () => { | ||
process.exit(0) | ||
}) | ||
.on('error', error => { | ||
_error(error.message) | ||
}) | ||
.end(JSON.stringify(packageJson, undefined, ' ')) | ||
} catch (error) { | ||
_error(error.message) | ||
} |
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
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.