Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chatty-pots-read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rnx-kit/align-deps": minor
---

Notify users when a newer version of a preset is available
44 changes: 42 additions & 2 deletions packages/align-deps/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { info } from "@rnx-kit/console";
import { readPackage } from "@rnx-kit/tools-node/package";
import type { Capability } from "@rnx-kit/types-kit-config";
import { spawn } from "node:child_process";
import * as nodefs from "node:fs";
import { findPackageJSON } from "node:module";
import { pathToFileURL } from "node:url";
import semverCoerce from "semver/functions/coerce.js";
import semverGreater from "semver/functions/gt.js";
import semverSatisfies from "semver/functions/satisfies.js";
import semverValidRange from "semver/ranges/valid.js";
import { gatherRequirements } from "./dependencies.ts";
Expand All @@ -12,6 +19,36 @@ type Resolution = {
capabilities: Capability[];
};

const notifyLatestVersion = (() => {
const cache = new Set<string>();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be stored somewhere so we don't check too often

return (preset: string, fs = nodefs): void => {
if (cache.has(preset)) {
return;
}

cache.add(preset);

const manifestPath = findPackageJSON(pathToFileURL(preset));
if (!manifestPath) {
return;
}

const { name, version } = readPackage(manifestPath, fs);

const shell = process.platform === "win32";
const opts = { shell, windowsVerbatimArguments: true };

spawn("npm", ["view", name, "version"], opts).stdout.on("data", (data) => {
const latestVersion = data.toString().trim();
if (semverGreater(latestVersion, version)) {
info(
`A newer version of '${name}' was found: ${latestVersion} (current: ${version})`
);
}
});
};
})();

function loadPreset(
preset: string,
projectRoot: string,
Expand All @@ -20,8 +57,11 @@ function loadPreset(
switch (preset) {
case "microsoft/react-native":
return reactNativePreset;
default:
return require(resolve(preset, { paths: [projectRoot] }));
default: {
const spec = resolve(preset, { paths: [projectRoot] });
notifyLatestVersion(spec);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users should be able to disable this check

return require(spec);
}
}
}

Expand Down
Loading