forked from silverwind/updates
misc tweaks
This commit is contained in:
parent
e6fa251dfb
commit
6d54ef538b
@ -11,4 +11,3 @@ insert_final_newline = true
|
|||||||
|
|
||||||
[Makefile]
|
[Makefile]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
indent_size = 2
|
|
||||||
|
12
Makefile
12
Makefile
@ -2,43 +2,51 @@ node_modules: package-lock.json
|
|||||||
npm install --no-save
|
npm install --no-save
|
||||||
@touch node_modules
|
@touch node_modules
|
||||||
|
|
||||||
|
.PHONY: deps
|
||||||
deps: node_modules
|
deps: node_modules
|
||||||
|
|
||||||
|
.PHONY: lint
|
||||||
lint: node_modules
|
lint: node_modules
|
||||||
npx eslint --color .
|
npx eslint --color .
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
test: node_modules lint build
|
test: node_modules lint build
|
||||||
NODE_OPTIONS="--experimental-vm-modules --no-warnings" npx jest --color
|
NODE_OPTIONS="--experimental-vm-modules --no-warnings" npx jest --color
|
||||||
|
|
||||||
|
.PHONY: unittest
|
||||||
unittest: node_modules
|
unittest: node_modules
|
||||||
NODE_OPTIONS="--experimental-vm-modules --no-warnings" npx jest --color --watchAll
|
NODE_OPTIONS="--experimental-vm-modules --no-warnings" npx jest --color --watchAll
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
build: node_modules
|
build: node_modules
|
||||||
npx ncc build updates.js -q -m -o bin
|
npx ncc build updates.js -q -m -o bin
|
||||||
mv bin/index.js bin/updates.js
|
mv bin/index.js bin/updates.js
|
||||||
perl -0777 -p -i -e 's#\n?\/\*![\s\S]*?\*\/\n?##g' bin/updates.js
|
perl -0777 -p -i -e 's#\n?\/\*![\s\S]*?\*\/\n?##g' bin/updates.js
|
||||||
chmod +x bin/updates.js
|
chmod +x bin/updates.js
|
||||||
|
|
||||||
|
.PHONY: publish
|
||||||
publish: node_modules
|
publish: node_modules
|
||||||
git push -u --tags origin master
|
git push -u --tags origin master
|
||||||
npm publish
|
npm publish
|
||||||
|
|
||||||
|
.PHONY: update
|
||||||
update: node_modules build
|
update: node_modules build
|
||||||
node bin/updates.js -cu -e registry-auth-token
|
node bin/updates.js -cu -e registry-auth-token
|
||||||
rm package-lock.json
|
rm package-lock.json
|
||||||
npm install
|
npm install
|
||||||
@touch node_modules
|
@touch node_modules
|
||||||
|
|
||||||
|
.PHONY: patch
|
||||||
patch: node_modules test
|
patch: node_modules test
|
||||||
npx versions -Cc 'make --no-print-directory build' patch
|
npx versions -Cc 'make --no-print-directory build' patch
|
||||||
@$(MAKE) --no-print-directory publish
|
@$(MAKE) --no-print-directory publish
|
||||||
|
|
||||||
|
.PHONY: minor
|
||||||
minor: node_modules test
|
minor: node_modules test
|
||||||
npx versions -Cc 'make --no-print-directory build' minor
|
npx versions -Cc 'make --no-print-directory build' minor
|
||||||
@$(MAKE) --no-print-directory publish
|
@$(MAKE) --no-print-directory publish
|
||||||
|
|
||||||
|
.PHONY: major
|
||||||
major: node_modules test
|
major: node_modules test
|
||||||
npx versions -Cc 'make --no-print-directory build' major
|
npx versions -Cc 'make --no-print-directory build' major
|
||||||
@$(MAKE) --no-print-directory publish
|
@$(MAKE) --no-print-directory publish
|
||||||
|
|
||||||
.PHONY: lint test unittest build publish deps update patch minor major
|
|
||||||
|
30
updates.js
30
updates.js
@ -234,13 +234,11 @@ if (args.types) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let pkg, pkgStr;
|
let pkg, pkgStr;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
pkgStr = readFileSync(packageFile, "utf8");
|
pkgStr = readFileSync(packageFile, "utf8");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
finish(new Error(`Unable to open package.json: ${err.message}`));
|
finish(new Error(`Unable to open package.json: ${err.message}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
pkg = JSON.parse(pkgStr);
|
pkg = JSON.parse(pkgStr);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -301,9 +299,7 @@ function getAuthAndRegistry(name, registry) {
|
|||||||
if (url !== registry) {
|
if (url !== registry) {
|
||||||
try {
|
try {
|
||||||
const newAuth = registryAuthToken(url, authTokenOpts);
|
const newAuth = registryAuthToken(url, authTokenOpts);
|
||||||
if (newAuth?.token) {
|
if (newAuth?.token) return [newAuth, url];
|
||||||
return [newAuth, url];
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
return [registryAuthToken(registry, authTokenOpts), registry];
|
return [registryAuthToken(registry, authTokenOpts), registry];
|
||||||
}
|
}
|
||||||
@ -326,8 +322,8 @@ async function fetchInfo(name, type, originalRegistry) {
|
|||||||
|
|
||||||
const packageName = type === "resolutions" ? resolutionsBasePackage(name) : name;
|
const packageName = type === "resolutions" ? resolutionsBasePackage(name) : name;
|
||||||
const urlName = packageName.replace(/\//g, "%2f");
|
const urlName = packageName.replace(/\//g, "%2f");
|
||||||
|
|
||||||
const url = `${registry}/${urlName}`;
|
const url = `${registry}/${urlName}`;
|
||||||
|
|
||||||
if (args.verbose) console.error(`${magenta("fetch")} ${url}`);
|
if (args.verbose) console.error(`${magenta("fetch")} ${url}`);
|
||||||
|
|
||||||
const res = await fetch(url, opts);
|
const res = await fetch(url, opts);
|
||||||
@ -369,10 +365,10 @@ function getInfoUrl({repository, homepage}, registry, name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let url = infoUrl || homepage || "";
|
let url = infoUrl || homepage || "";
|
||||||
// force https for github.com
|
|
||||||
if (url) {
|
if (url) {
|
||||||
const u = new URL(url);
|
const u = new URL(url);
|
||||||
if (u.hostname === "github.com" && u.protocol === "http:") {
|
// force https for github.com
|
||||||
|
if (u.protocol === "http:" && u.hostname === "github.com") {
|
||||||
u.protocol = "https:";
|
u.protocol = "https:";
|
||||||
url = String(u);
|
url = String(u);
|
||||||
}
|
}
|
||||||
@ -427,8 +423,6 @@ function finish(obj, opts = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch.clearCache();
|
|
||||||
|
|
||||||
if (args["error-on-outdated"]) {
|
if (args["error-on-outdated"]) {
|
||||||
exit(Object.keys(deps).length ? 2 : 0);
|
exit(Object.keys(deps).length ? 2 : 0);
|
||||||
} else if (args["error-on-unchanged"]) {
|
} else if (args["error-on-unchanged"]) {
|
||||||
@ -492,7 +486,7 @@ function formatDeps() {
|
|||||||
function updatePackageJson() {
|
function updatePackageJson() {
|
||||||
let newPkgStr = pkgStr;
|
let newPkgStr = pkgStr;
|
||||||
for (const key of Object.keys(deps)) {
|
for (const key of Object.keys(deps)) {
|
||||||
const [_type, name] = key.split(sep);
|
const name = key.split(sep)[1];
|
||||||
const re = new RegExp(`"${esc(name)}": +"${esc(deps[key].old)}"`, "g");
|
const re = new RegExp(`"${esc(name)}": +"${esc(deps[key].old)}"`, "g");
|
||||||
newPkgStr = newPkgStr.replace(re, `"${name}": "${deps[key].new}"`);
|
newPkgStr = newPkgStr.replace(re, `"${name}": "${deps[key].new}"`);
|
||||||
}
|
}
|
||||||
@ -654,9 +648,7 @@ async function checkUrlDep([key, dep], {useGreatest} = {}) {
|
|||||||
if (!semver.valid(lastTagBare)) return;
|
if (!semver.valid(lastTagBare)) return;
|
||||||
|
|
||||||
if (semver.neq(oldRefBare, lastTagBare)) {
|
if (semver.neq(oldRefBare, lastTagBare)) {
|
||||||
const newRange = lastTag;
|
return {key, newRange: lastTag, user, repo, oldRef, newRef: lastTag};
|
||||||
const newRef = lastTag;
|
|
||||||
return {key, newRange, user, repo, oldRef, newRef};
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let greatestTag = oldRef;
|
let greatestTag = oldRef;
|
||||||
@ -671,9 +663,7 @@ async function checkUrlDep([key, dep], {useGreatest} = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (semver.neq(oldRefBare, greatestTagBare)) {
|
if (semver.neq(oldRefBare, greatestTagBare)) {
|
||||||
const newRange = greatestTag;
|
return {key, newRange: greatestTag, user, repo, oldRef, newRef: greatestTag};
|
||||||
const newRef = greatestTag;
|
|
||||||
return {key, newRange, user, repo, oldRef, newRef};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -705,9 +695,7 @@ async function main() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
for (const [data, type, registry, name] of entries) {
|
for (const [data, type, registry, name] of entries) {
|
||||||
if (data?.error) {
|
if (data?.error) throw new Error(data.error);
|
||||||
throw new Error(data.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
const useGreatest = typeof greatest === "boolean" ? greatest : greatest.has(data.name);
|
const useGreatest = typeof greatest === "boolean" ? greatest : greatest.has(data.name);
|
||||||
const usePre = typeof prerelease === "boolean" ? prerelease : prerelease.has(data.name);
|
const usePre = typeof prerelease === "boolean" ? prerelease : prerelease.has(data.name);
|
||||||
@ -738,7 +726,7 @@ async function main() {
|
|||||||
|
|
||||||
if (Object.keys(maybeUrlDeps).length) {
|
if (Object.keys(maybeUrlDeps).length) {
|
||||||
let results = await Promise.all(Object.entries(maybeUrlDeps).map(([key, dep]) => {
|
let results = await Promise.all(Object.entries(maybeUrlDeps).map(([key, dep]) => {
|
||||||
const [_, name] = key.split(sep);
|
const name = key.split(sep)[1];
|
||||||
const useGreatest = typeof greatest === "boolean" ? greatest : greatest.has(name);
|
const useGreatest = typeof greatest === "boolean" ? greatest : greatest.has(name);
|
||||||
return checkUrlDep([key, dep], {useGreatest});
|
return checkUrlDep([key, dep], {useGreatest});
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user