Skip to content

Commit

Permalink
Merge pull request #18 from josh-stillman/js/remote-json-pinned-versions
Browse files Browse the repository at this point in the history
use remote json file for pinned versions
  • Loading branch information
josh-stillman authored Sep 28, 2024
2 parents 8eac3bc + 0528709 commit 53b6301
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 26 deletions.
34 changes: 28 additions & 6 deletions src/installDependencies/installDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import execa from 'execa';
import ora from 'ora';
import chalk from 'chalk';
import { PROGRESS_MESSAGES } from '../progressMessages';
import { PINNED_VERSIONS } from './pinnedVersions';
import PINNED_VERSIONS from './pinnedVersions.json';

export const installDeps = async ({
useYarn,
Expand All @@ -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',
]);
Expand All @@ -48,9 +48,8 @@ export const installDeps = async ({
// }
};

export const getDepList = ({
export const getDepList = async ({
react,

node,
styleLint,
sass,
Expand All @@ -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',
Expand All @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions src/installDependencies/pinnedVersions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"_UPDATED_AT": "9/28/2024",
"@eslint/js": "9.11.1",
"@types/eslint__js": "8.42.3",
"eslint": "9.11.1",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-n": "17.10.3",
"eslint-plugin-react": "7.36.1",
"globals": "15.9.0",
"lint-staged": "15.2.10",
"prettier": "3.3.3",
"simple-git-hooks": "2.11.1",
"stylelint": "16.9.0",
"stylelint-config-sass-guidelines": "12.1.0",
"stylelint-config-standard": "36.0.1",
"stylelint-prettier": "5.0.2",
"typescript-eslint": "8.7.0"
}
20 changes: 0 additions & 20 deletions src/installDependencies/pinnedVersions.ts

This file was deleted.

0 comments on commit 53b6301

Please sign in to comment.