From 0528709c11a154b4091a6a0392d049b85d62231c Mon Sep 17 00:00:00 2001 From: Josh Stillman Date: Sat, 28 Sep 2024 16:08:08 -0400 Subject: [PATCH] use remote pinned versions json --- .../installDependencies.ts | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/installDependencies/installDependencies.ts b/src/installDependencies/installDependencies.ts index 5f1cf93..92d4bfc 100644 --- a/src/installDependencies/installDependencies.ts +++ b/src/installDependencies/installDependencies.ts @@ -27,7 +27,7 @@ export const installDeps = async ({ const installProcess = execa(useYarn ? 'yarn' : 'npm', [ useYarn ? 'add' : 'install', - ...getDepList({ node, react, styleLint, sass, lintStaged, pinned }), + ...(await getDepList({ node, react, styleLint, sass, lintStaged, pinned })), '-E', '-D', ]); @@ -48,9 +48,8 @@ export const installDeps = async ({ // } }; -export const getDepList = ({ +export const getDepList = async ({ react, - node, styleLint, sass, @@ -64,6 +63,27 @@ export const getDepList = ({ lintStaged: boolean; pinned: boolean; }) => { + let pinnedJson = PINNED_VERSIONS; + + if (pinned) { + // fetch updated list of pinned versions, falling back to version from published package + try { + const remotePinned = await fetch( + 'https://raw.githubusercontent.com/josh-stillman/lintier/refs/heads/main/src/installDependencies/pinnedVersions.json' + ); + + const json = (await remotePinned.json()) as typeof PINNED_VERSIONS; + + pinnedJson = json; + + console.log(`Using pinned versions from ${pinnedJson['_UPDATED_AT']}`); + } catch (error) { + console.error( + `Error fetching remote list of pinned versions, falling back to list from ${PINNED_VERSIONS['_UPDATED_AT']}\n\n${error}` + ); + } + } + return [ 'eslint', 'prettier', @@ -88,20 +108,22 @@ export const getDepList = ({ ...(lintStaged ? ['simple-git-hooks', 'lint-staged'] : []), ].map( packageName => - `${packageName}@${getVersion({ packageName, usePinned: pinned })}` + `${packageName}@${getVersion({ packageName, usePinned: pinned, pinnedJson })}` ); }; export const getVersion = ({ packageName, usePinned, + pinnedJson, }: { packageName: string; usePinned: boolean; + pinnedJson: typeof PINNED_VERSIONS; }) => !usePinned ? 'latest' - : PINNED_VERSIONS[packageName as keyof typeof PINNED_VERSIONS] || 'latest'; + : pinnedJson[packageName as keyof typeof PINNED_VERSIONS] || 'latest'; // const installAirBnb = async ({ // useYarn,