diff --git a/packages/helia/src/index.ts b/packages/helia/src/index.ts index 06fe4dd2f..f977b1b72 100644 --- a/packages/helia/src/index.ts +++ b/packages/helia/src/index.ts @@ -64,8 +64,11 @@ export interface HeliaInit { * If node options are passed, they will be merged with the default * config for the current platform. In this case all passed config * keys will replace those from the default config. + * + * The libp2p `start` option is not supported, instead please pass `start` in + * the root of the HeliaInit object. */ - libp2p?: T | Libp2pOptions + libp2p?: T | Omit /** * The blockstore is where blocks are stored @@ -152,7 +155,13 @@ export async function createHelia (init: HeliaInit = {}): Promise { } else { libp2p = await createLibp2p({ ...init, - libp2p: init.libp2p, + libp2p: { + ...init.libp2p, + + // ignore the libp2p start parameter as it should be on the main init + // object instead + start: undefined + }, datastore }) } diff --git a/packages/helia/test/libp2p.spec.ts b/packages/helia/test/libp2p.spec.ts index 57aff7c0b..068c7b630 100644 --- a/packages/helia/test/libp2p.spec.ts +++ b/packages/helia/test/libp2p.spec.ts @@ -44,4 +44,28 @@ describe('libp2p', () => { expect(helia.libp2p).to.equal(libp2p) }) + + it('ignores libp2p start param when it is false', async () => { + helia = await createHelia({ + libp2p: { + // @ts-expect-error start is omitted from libp2p init type + start: false + }, + start: true + }) + + expect(helia.libp2p.status).to.equal('started') + }) + + it('ignores libp2p start param when it is true', async () => { + helia = await createHelia({ + libp2p: { + // @ts-expect-error start is omitted from libp2p init type + start: true + }, + start: false + }) + + expect(helia.libp2p.status).to.equal('stopped') + }) })