Skip to content

Commit

Permalink
fix(core-utils): remove domino from the codebase (#1833)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocavue committed Sep 8, 2022
1 parent 3c5e69d commit d3248ad
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 50 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-vans-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@remirror/core-utils': patch
---

Removes `domino` from the codebase.
53 changes: 53 additions & 0 deletions packages/remirror__core-utils/__tests__/core-utils.node.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @jest-environment node
*/

import { doc, p, schema as testSchema } from 'jest-prosemirror';

import { htmlToProsemirrorNode, prosemirrorNodeToDom } from '../';

describe('toDOM', () => {
const node = doc(p('hello'));

it('allows for custom document to be passed in', async () => {
const { JSDOM } = await import('jsdom');
const customDocument = new JSDOM().window.document;
expect(prosemirrorNodeToDom(node, customDocument)).toBeObject();

const wrongDocument = {} as Document;
expect(() => prosemirrorNodeToDom(node, customDocument)).not.toThrow();
expect(() => prosemirrorNodeToDom(node, wrongDocument)).toThrow();
});
});

describe('htmlToProsemirrorNode', () => {
const content = `<p>Hello</p>`;

it('allows for custom document to be passed in', async () => {
const { JSDOM } = await import('jsdom');
const customDocument = new JSDOM().window.document;
expect(
htmlToProsemirrorNode({
content: content,
schema: testSchema,
document: customDocument,
}),
).toEqualProsemirrorNode(doc(p('Hello')));

const wrongDocument = {} as Document;
expect(() =>
htmlToProsemirrorNode({
content: content,
schema: testSchema,
document: customDocument,
}),
).not.toThrow();
expect(() =>
htmlToProsemirrorNode({
content: content,
schema: testSchema,
document: wrongDocument,
}),
).toThrow();
});
});
19 changes: 4 additions & 15 deletions packages/remirror__core-utils/__tests__/core-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import domino from 'domino';
/**
* @jest-environment jsdom
*/

import {
a,
atomInline,
Expand Down Expand Up @@ -735,10 +738,6 @@ describe('toDOM', () => {
it('transforms a doc into a documentFragment', () => {
expect(prosemirrorNodeToDom(node)).toBeInstanceOf(DocumentFragment);
});

it('allows for custom document to be passed in', () => {
expect(prosemirrorNodeToDom(node, domino.createDocument())).toBeObject();
});
});

describe('htmlToProsemirrorNode', () => {
Expand All @@ -749,16 +748,6 @@ describe('htmlToProsemirrorNode', () => {
doc(p('Hello')),
);
});

it('allows for custom document to be passed in', () => {
expect(
htmlToProsemirrorNode({
content: content,
schema: testSchema,
document: domino.createDocument(),
}),
).toEqualProsemirrorNode(doc(p('Hello')));
});
});

test('getRemirrorJSON', () => {
Expand Down
5 changes: 0 additions & 5 deletions packages/remirror__core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,17 @@
"@remirror/pm": "^2.0.0-beta.14",
"@types/jsdom": "^16.2.13",
"@types/node": "^16.3.3",
"domino": "^2.1.6",
"jsdom": "^17.0.0"
},
"peerDependencies": {
"@remirror/pm": "^2.0.0-beta.14",
"@types/node": "*",
"domino": "*",
"jsdom": "*"
},
"peerDependenciesMeta": {
"@types/node": {
"optional": true
},
"domino": {
"optional": true
},
"jsdom": {
"optional": true
}
Expand Down
2 changes: 1 addition & 1 deletion packages/remirror__core-utils/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ This is included by default when you install the recommended `remirror` package.

If you plan to support SSR and need to parse the html contents of the editor in an SSR environment then `min-document` is automatically added to all node environments.

However, `min-document` can't actually parse the content properly since the implementation is intentionally underpowered. To properly parse content from a html string you will need to install either `jsdom` or `domino`. These dependencies are only included within non-browser builds and won't bloat your bundle size in the browser.
However, `min-document` can't actually parse the content properly since the implementation is intentionally underpowered. To properly parse content from a html string you will need to install `jsdom`. These dependencies are only included within non-browser builds and won't bloat your bundle size in the browser.
7 changes: 0 additions & 7 deletions packages/remirror__core-utils/src/core-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1220,13 +1220,6 @@ export function getDocument(): Document {
// ignore
}

try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
return require('domino').createDocument();
} catch {
// ignore
}

try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
return require('min-document');
Expand Down
44 changes: 23 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion support/root/.size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
"ignore": [
"@remirror/pm",
"@types/node",
"domino",
"jsdom",
"@remirror/core-constants",
"@remirror/core-helpers",
Expand Down

1 comment on commit d3248ad

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.