misc tweaks

This commit is contained in:
silverwind 2022-08-25 01:13:46 +02:00
parent e6fa251dfb
commit 6d54ef538b
Signed by untrusted user: silverwind
GPG Key ID: 2E62B41C93869443
3 changed files with 19 additions and 24 deletions

@ -11,4 +11,3 @@ insert_final_newline = true
[Makefile]
indent_style = tab
indent_size = 2

@ -2,43 +2,51 @@ node_modules: package-lock.json
npm install --no-save
@touch node_modules
.PHONY: deps
deps: node_modules
.PHONY: lint
lint: node_modules
npx eslint --color .
.PHONY: test
test: node_modules lint build
NODE_OPTIONS="--experimental-vm-modules --no-warnings" npx jest --color
.PHONY: unittest
unittest: node_modules
NODE_OPTIONS="--experimental-vm-modules --no-warnings" npx jest --color --watchAll
.PHONY: build
build: node_modules
npx ncc build updates.js -q -m -o bin
mv bin/index.js bin/updates.js
perl -0777 -p -i -e 's#\n?\/\*![\s\S]*?\*\/\n?##g' bin/updates.js
chmod +x bin/updates.js
.PHONY: publish
publish: node_modules
git push -u --tags origin master
npm publish
.PHONY: update
update: node_modules build
node bin/updates.js -cu -e registry-auth-token
rm package-lock.json
npm install
@touch node_modules
.PHONY: patch
patch: node_modules test
npx versions -Cc 'make --no-print-directory build' patch
@$(MAKE) --no-print-directory publish
.PHONY: minor
minor: node_modules test
npx versions -Cc 'make --no-print-directory build' minor
@$(MAKE) --no-print-directory publish
.PHONY: major
major: node_modules test
npx versions -Cc 'make --no-print-directory build' major
@$(MAKE) --no-print-directory publish
.PHONY: lint test unittest build publish deps update patch minor major

@ -234,13 +234,11 @@ if (args.types) {
}
let pkg, pkgStr;
try {
pkgStr = readFileSync(packageFile, "utf8");
} catch (err) {
finish(new Error(`Unable to open package.json: ${err.message}`));
}
try {
pkg = JSON.parse(pkgStr);
} catch (err) {
@ -301,9 +299,7 @@ function getAuthAndRegistry(name, registry) {
if (url !== registry) {
try {
const newAuth = registryAuthToken(url, authTokenOpts);
if (newAuth?.token) {
return [newAuth, url];
}
if (newAuth?.token) return [newAuth, url];
} catch {
return [registryAuthToken(registry, authTokenOpts), registry];
}
@ -326,8 +322,8 @@ async function fetchInfo(name, type, originalRegistry) {
const packageName = type === "resolutions" ? resolutionsBasePackage(name) : name;
const urlName = packageName.replace(/\//g, "%2f");
const url = `${registry}/${urlName}`;
if (args.verbose) console.error(`${magenta("fetch")} ${url}`);
const res = await fetch(url, opts);
@ -369,10 +365,10 @@ function getInfoUrl({repository, homepage}, registry, name) {
}
let url = infoUrl || homepage || "";
// force https for github.com
if (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:";
url = String(u);
}
@ -427,8 +423,6 @@ function finish(obj, opts = {}) {
}
}
fetch.clearCache();
if (args["error-on-outdated"]) {
exit(Object.keys(deps).length ? 2 : 0);
} else if (args["error-on-unchanged"]) {
@ -492,7 +486,7 @@ function formatDeps() {
function updatePackageJson() {
let newPkgStr = pkgStr;
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");
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.neq(oldRefBare, lastTagBare)) {
const newRange = lastTag;
const newRef = lastTag;
return {key, newRange, user, repo, oldRef, newRef};
return {key, newRange: lastTag, user, repo, oldRef, newRef: lastTag};
}
} else {
let greatestTag = oldRef;
@ -671,9 +663,7 @@ async function checkUrlDep([key, dep], {useGreatest} = {}) {
}
}
if (semver.neq(oldRefBare, greatestTagBare)) {
const newRange = greatestTag;
const newRef = greatestTag;
return {key, newRange, user, repo, oldRef, newRef};
return {key, newRange: greatestTag, user, repo, oldRef, newRef: greatestTag};
}
}
}
@ -705,9 +695,7 @@ async function main() {
}));
for (const [data, type, registry, name] of entries) {
if (data?.error) {
throw new Error(data.error);
}
if (data?.error) throw new Error(data.error);
const useGreatest = typeof greatest === "boolean" ? greatest : greatest.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) {
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);
return checkUrlDep([key, dep], {useGreatest});
}));