Skip to content

Commit

Permalink
fix: Dont validate packages if theres no packemon block. (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Feb 5, 2023
1 parent c40d20d commit e355314
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/packemon/src/Package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,22 @@ export class Package {

readonly workspaceRoot: Path;

constructor(path: Path, contents: PackemonPackage, workspaceRoot?: Path) {
constructor(path: Path, contents: Partial<PackemonPackage>, workspaceRoot?: Path) {
this.path = path;
this.jsonPath = this.path.append('package.json');
this.json = contents;
this.json = contents as PackemonPackage;
this.workspaceRoot = workspaceRoot ?? path;
this.debug = createDebugger(['packemon', 'package', this.getSlug()]);

if (!isObject(contents.packemon) && !Array.isArray(contents.packemon)) {
throw new Error(
`Invalid \`packemon\` configuration for ${contents.name}, must be an object or array of objects.`,
);
}
if (contents.packemon) {
if (!isObject(contents.packemon) && !Array.isArray(contents.packemon)) {
throw new Error(
`Invalid \`packemon\` configuration for ${contents.name}, must be an object or array of objects.`,
);
}

this.setConfigs(toArray(contents.packemon));
this.setConfigs(toArray(contents.packemon));
}
}

async build(options: BuildOptions, packemonConfig: ConfigFile): Promise<void> {
Expand Down
11 changes: 11 additions & 0 deletions packages/packemon/tests/Package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ describe('Package', () => {
);
});

it('supports packages without a `packemon` block', () => {
expect(() => {
pkg = new Package(new Path(getFixturePath('project')), {
name: 'test',
version: '0.0.0',
description: 'Test',
keywords: ['test'],
});
}).not.toThrow();
});

describe('build()', () => {
let writeSpy: jest.SpyInstance;
let config: ConfigFile;
Expand Down

0 comments on commit e355314

Please sign in to comment.