Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support to pnpm-lock.yaml file #853

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions node-src/lib/findChangedDependencies.test.ts
Expand Up @@ -220,6 +220,26 @@ describe('findChangedDependencies', () => {
);
});

it('uses pnpm-lock.yaml if yarn.lock is missing', async () => {
findFiles.mockImplementation((file) => {
if (file.endsWith('yarn.lock'))
return Promise.resolve([file.replace('yarn.lock', 'pnpm-lock.yaml')]);
return Promise.resolve(file.startsWith('**') ? [file.replace('**', 'subdir')] : [file]);
});

checkoutFile.mockImplementation((ctx, commit, file) => Promise.resolve(`${commit}.${file}`));
buildDepTree.mockResolvedValue({ dependencies: {} });

await expect(findChangedDependencies(getContext(['A']))).resolves.toEqual([]);

expect(buildDepTree).toHaveBeenCalledWith(
'/root',
'A.subdir/package.json',
'A.subdir/pnpm-lock.yaml',
true
);
});

it('uses package-lock.json if yarn.lock is missing', async () => {
findFiles.mockImplementation((file) => {
if (file.endsWith('yarn.lock'))
Expand Down
8 changes: 6 additions & 2 deletions node-src/lib/findChangedDependencies.ts
Expand Up @@ -8,6 +8,7 @@ import { matchesFile } from './utils';

const PACKAGE_JSON = 'package.json';
const PACKAGE_LOCK = 'package-lock.json';
const PNPM_LOCK = 'pnpm-lock.yaml';
const YARN_LOCK = 'yarn.lock';

// Yields a list of dependency names which have changed since the baseline.
Expand All @@ -28,7 +29,7 @@ export const findChangedDependencies = async (ctx: Context) => {

const rootPath = await getRepositoryRoot();
const [rootManifestPath] = await findFiles(PACKAGE_JSON);
const [rootLockfilePath] = await findFiles(YARN_LOCK, PACKAGE_LOCK);
const [rootLockfilePath] = await findFiles(YARN_LOCK, PNPM_LOCK, PACKAGE_LOCK);
if (!rootManifestPath || !rootLockfilePath) {
ctx.log.debug(
{ rootPath, rootManifestPath, rootLockfilePath },
Expand All @@ -45,6 +46,7 @@ export const findChangedDependencies = async (ctx: Context) => {
const dirname = path.dirname(manifestPath);
const [lockfilePath] = await findFiles(
`${dirname}/${YARN_LOCK}`,
`${dirname}/${PNPM_LOCK}`,
`${dirname}/${PACKAGE_LOCK}`
);
// Fall back to the root lockfile if we can't find one in the same directory.
Expand All @@ -55,7 +57,9 @@ export const findChangedDependencies = async (ctx: Context) => {
if (rootManifestPath && rootLockfilePath) {
pathPairs.unshift([rootManifestPath, rootLockfilePath]);
} else if (!pathPairs.length) {
throw new Error(`Could not find any pairs of ${PACKAGE_JSON} + ${PACKAGE_LOCK} / ${YARN_LOCK}`);
throw new Error(
`Could not find any pairs of ${PACKAGE_JSON} + ${PACKAGE_LOCK} / ${YARN_LOCK} / ${PNPM_LOCK}`
);
}

ctx.log.debug({ pathPairs }, `Found ${pathPairs.length} manifest/lockfile pairs to check`);
Expand Down
15 changes: 12 additions & 3 deletions node-src/lib/getDependentStoryFiles.test.ts
Expand Up @@ -375,7 +375,13 @@ describe('getDependentStoryFiles', () => {
});

it('does not bail on changed global file', async () => {
const changedFiles = ['src/foo.stories.js', 'package.json', 'package-lock.json', 'yarn.lock'];
const changedFiles = [
'src/foo.stories.js',
'package.json',
'package-lock.json',
'yarn.lock',
'pnpm-lock.yaml',
];
const modules = [
{
id: './src/foo.stories.js',
Expand Down Expand Up @@ -444,7 +450,9 @@ describe('getDependentStoryFiles', () => {
reasons: [{ moduleName: './.storybook/generated-stories-entry.js' }],
},
];
const rawContext = getContext({ untraced: ['**/(package.json|package-lock.json|yarn.lock)'] });
const rawContext = getContext({
untraced: ['**/(package.json|package-lock.json|yarn.lock|pnpm-lock.yaml)'],
});
const ctx = {
...rawContext,
// signifying the package.json file had dependency changes
Expand Down Expand Up @@ -675,6 +683,7 @@ describe('getDependentStoryFiles', () => {
'src/package.json',
'src/package-lock.json',
'src/yarn.lock',
'src/pnpm-lock.yaml',
];
const modules = [
{
Expand All @@ -699,7 +708,7 @@ describe('getDependentStoryFiles', () => {
},
];
const ctx = getContext({
untraced: ['**/(package**.json|yarn.lock)'],
untraced: ['**/(package**.json|yarn.lock|pnpm-lock.yaml)'],
});
const res = await getDependentStoryFiles(ctx, { modules }, statsPath, changedFiles);
expect(ctx.turboSnap.bailReason).toBeUndefined();
Expand Down
2 changes: 2 additions & 0 deletions node-src/lib/getDependentStoryFiles.ts
Expand Up @@ -14,8 +14,10 @@ type NormalizedName = string;
const LOCKFILES = [
/^package-lock\.json$/,
/^yarn\.lock$/,
/^pnpm-lock\.yaml$/,
/\/package-lock\.json$/,
/\/yarn\.lock$/,
/\/pnpm-lock\.yaml$/,
];

// Ignore these while tracing dependencies
Expand Down