Skip to content

Commit

Permalink
feat: Indicate lack of support for missing "files" in package.jsons u…
Browse files Browse the repository at this point in the history
…sed by linkable
  • Loading branch information
Iku-turso committed Apr 24, 2023
1 parent c4e2db4 commit e0d14e6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/linkable/src/create-links.injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getInjectable } from '@ogre-tools/injectable';
import { createSymlinksInjectable } from './create-symlinks/create-symlinks.injectable';
import getConfigInjectable from './config/get-config.injectable';
import createEmptyConfigInjectable from './config/create-empty-config.injectable';
import { PackageJsonAndPath } from './shared/package-json-and-path';

export type CreateLinks = () => Promise<void>;

Expand All @@ -30,8 +31,26 @@ export const createLinksInjectable = getInjectable({

const packageJsons = await getPackageJsons(config);

checkForMissingPropertyForFiles(packageJsons);

await ensureEmptyLinkDirectories(packageJsons);
await createSymlinks(packageJsons);
};
},
});

const checkForMissingPropertyForFiles = (
packageJsons: PackageJsonAndPath[],
) => {
const bad = packageJsons
.filter(x => x.content.files === undefined)
.map(x => x.packageJsonPath);

if (bad.length) {
throw new Error(
`Tried create links of linkable, but some package.jsons didn't specify property "files": "${bad.join(
'", "',
)}"`,
);
}
};
32 changes: 32 additions & 0 deletions packages/linkable/src/linkable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,38 @@ describe('creation of "npm pack" -like symlinks', () => {
});
});

describe('given some of the packages do not specify "files", when all contents resolve', () => {
beforeEach(async () => {
existsMock.mockClear();

readJsonFileMock.resolveSpecific(
([path]) => path === '/some-directory/some-module/package.json',
{
files: undefined,
name: '@some-scope/some-module',
main: 'irrelevant',
},
);

readJsonFileMock.resolveSpecific(
([path]) =>
path ===
'/some-other-directory/some-other-module/package.json',
{
name: 'irrelevant',
files: ['irrelevant'],
main: 'irrelevant',
},
);
});

it('rejects entire script', () => {
return expect(actualPromise).rejects.toThrow(
'Tried create links of linkable, but some package.jsons didn\'t specify property "files": "/some-directory/some-module/package.json"',
);
});
});

describe('given some of the packages have globs as files, when all contents resolve', () => {
beforeEach(async () => {
existsMock.mockClear();
Expand Down

0 comments on commit e0d14e6

Please sign in to comment.