Skip to content

Commit

Permalink
chore: add logging for postinstall script
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanaubrey committed Oct 15, 2023
1 parent 15c2702 commit a3c17cc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/new/_templates/repo/library/package.ejs.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
to: package.json
sh: "<%= packageManager %> install && <%= packageManager %> add -D @repodog/cli @repodog/babel-config @repodog/commitlint-config @repodog/eslint-config @repodog/eslint-config-jest @repodog/jest-config @repodog/markdownlint-config @repodog/prettier-config @repodog/rollup-config @repodog/syncpack-config @repodog/ts-config @repodog/cli && <%= packageManager %> run repodog -- postinstall <%= newType %> <%= newSubType %>"
sh: "<%= packageManager %> install && <%= packageManager %> add -D @repodog/cli @repodog/babel-config @repodog/commitlint-config @repodog/eslint-config @repodog/eslint-config-jest @repodog/jest-config @repodog/markdownlint-config @repodog/prettier-config @repodog/rollup-config @repodog/syncpack-config @repodog/ts-config && <%= packageManager %> run repodog -- postinstall <%= newType %> <%= newSubType %>"
---
{
"name": "<%= name %>",
Expand Down
4 changes: 4 additions & 0 deletions cli/postinstall/src/utils/getPeerDependenciesToInstall.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { verboseLog } from '@repodog/cli-utils';
import { type PackageJson } from 'type-fest';

export const getPeerDependenciesToInstall = async (name: string) => {
const nameAndVersion: [string, string][] = [];

try {
verboseLog(`Getting ${name} peerDependency names`);
const packageJson = (await import(`${name}/package.json`)) as PackageJson;

if (!packageJson.peerDependencies) {
verboseLog(`${name} peerDependencies: 'none'`);
return nameAndVersion;
}

Expand All @@ -18,6 +21,7 @@ export const getPeerDependenciesToInstall = async (name: string) => {
}
}

verboseLog(`${name} peerDependencies: ${nameAndVersion.join(', ')}`);
return nameAndVersion;
} catch {
return nameAndVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { jest } from '@jest/globals';
jest.unstable_mockModule('@repodog/cli-utils', () => ({
asyncExec: jest.fn(),
getPackageManager: jest.fn().mockReturnValue('pnpm'),
verboseLog: jest.fn(),
}));

jest.unstable_mockModule('./getRepoDogDevDependencyNames.ts', () => ({
Expand Down
16 changes: 10 additions & 6 deletions cli/postinstall/src/utils/installRepoDogPeerDependencies.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { asyncExec, getPackageManager } from '@repodog/cli-utils';
import { asyncExec, getPackageManager, verboseLog } from '@repodog/cli-utils';
import { getPeerDependenciesToInstall } from './getPeerDependenciesToInstall.ts';
import { getRepoDogDevDependencyNames } from './getRepoDogDevDependencyNames.ts';

export const installRepoDogPeerDependencies = async () => {
const packageManager = getPackageManager()!;
verboseLog('Getting @repodog devDependency names');
const names = getRepoDogDevDependencyNames();
verboseLog(`@repodog devDependency names: ${names.length > 0 ? names.join(', ') : 'none'}`);
const runners: ReturnType<typeof import('@repodog/cli-utils')['asyncExec']>[] = [];

for (const name of names) {
verboseLog(`Getting peerDependencies to install for ${name}`);
const peerDependenciesToIntall = await getPeerDependenciesToInstall(name);

runners.push(
asyncExec(
`${packageManager} add -D ${peerDependenciesToIntall.map(([name, semver]) => `${name}@"${semver}"`).join(' ')}`
)
);
const cmd = `${packageManager} add -D ${peerDependenciesToIntall
.map(([name, semver]) => `${name}@"${semver}"`)
.join(' ')}`;

verboseLog(`Executing cmd: "${cmd}`);
runners.push(asyncExec(cmd));
}

return Promise.allSettled(runners);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@
"syncpack": "^9.8.6",
"typescript": "^5.0.3"
}
}
}

0 comments on commit a3c17cc

Please sign in to comment.