diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 208c790d..023bdd0b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,14 +44,13 @@ each published separately to npm. ### Local Development -Run `npm install` to install all necessary dependencies. +Run `yarn install` to install all necessary dependencies. -As a post-install step, all Lerna dependencies are [hoisted](https://github.com/lerna/lerna/blob/master/doc/hoist.md), +`yarn build` ensures all Lerna dependencies are [hoisted](https://github.com/lerna/lerna/blob/master/doc/hoist.md), and hence internally reliant packages (e.g., `rich-text-html-renderer`, which depends upon `rich-text-types`) will resolve their modules via symlink. In other -words, `npm install` will _both_ install external dependencies for each project, -_and_ ensure packages that pull in other packages in this repository as -dependencies are linked to the local version (rather than whatever the state +words, `yarn build` ensure packages that pull in other packages in this repository +as dependencies are linked to the local version (rather than whatever the state of those packages is on npm). Each package is written in [TypeScript](https://www.typescriptlang.org/) and diff --git a/packages/rich-text-links/src/__test__/index.test.ts b/packages/rich-text-links/src/__test__/index.test.ts index a5b7c9ac..4cd62951 100644 --- a/packages/rich-text-links/src/__test__/index.test.ts +++ b/packages/rich-text-links/src/__test__/index.test.ts @@ -491,19 +491,39 @@ describe('getRichTextEntityLinks', () => { }, content: [], }, + { + nodeType: INLINES.EMBEDDED_ENTRY, + data: { + target: { + sys: { + linkType: 'Entry', + type: 'Link', + id: 'baz', + }, + }, + }, + content: [], + }, ], }, ], }; it('ignores all links of different types', () => { - expect(getRichTextEntityLinks(document, BLOCKS.EMBEDDED_ENTRY)).toEqual({ + expect( + getRichTextEntityLinks(document, BLOCKS.EMBEDDED_ENTRY, INLINES.EMBEDDED_ENTRY), + ).toEqual({ Entry: [ { linkType: 'Entry', type: 'Link', id: 'foo', }, + { + linkType: 'Entry', + type: 'Link', + id: 'baz', + }, ], Asset: [], }); diff --git a/packages/rich-text-links/src/index.ts b/packages/rich-text-links/src/index.ts index 19c25d6a..8d8b7a01 100644 --- a/packages/rich-text-links/src/index.ts +++ b/packages/rich-text-links/src/index.ts @@ -83,8 +83,10 @@ export function getRichTextEntityLinks( /** * Node type. Only the entity links with given node type will be extracted. */ - type?: string, + ...type: (BLOCKS | INLINES | string)[] ): EntityLinks { + const types = new Set(type); + const entityLinks: EntityLinkMaps = { Entry: new Map(), Asset: new Map(), @@ -92,7 +94,7 @@ export function getRichTextEntityLinks( // const content = (document && document.content) || ([] as Node[]); const addLink = ({ data, nodeType }: Node) => { - const hasRequestedNodeType = !type || nodeType === type; + const hasRequestedNodeType = !types.size || types.has(nodeType); if (hasRequestedNodeType && isLinkObject(data)) { entityLinks[data.target.sys.linkType].set(data.target.sys.id, data.target.sys);