Skip to content

Commit 93e8289

Browse files
rexxarsstipsan
authored andcommitted
feat: use esm-first approach, use vitest for tests
1 parent cd07aa4 commit 93e8289

14 files changed

+70
-69
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jspm_packages
4646
.cache
4747

4848
# Compiled portable text library + demo
49-
/dist
49+
/lib
5050
/demo/dist
5151

5252
*.iml

package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
1919
"type": "module",
2020
"exports": {
2121
".": {
22-
"types": "./dist/index.d.ts",
22+
"types": "./lib/index.d.ts",
2323
"source": "./src/index.ts",
24-
"require": "./dist/index.cjs",
24+
"require": "./lib/index.cjs",
2525
"node": {
26-
"module": "./dist/index.js",
27-
"import": "./dist/index.cjs.js"
26+
"module": "./lib/index.js",
27+
"import": "./lib/index.cjs.js"
2828
},
29-
"import": "./dist/index.js",
30-
"default": "./dist/index.js"
29+
"import": "./lib/index.js",
30+
"default": "./lib/index.js"
3131
},
3232
"./package.json": "./package.json"
3333
},
34-
"main": "./dist/index.cjs",
35-
"module": "./dist/index.js",
34+
"main": "./lib/index.cjs",
35+
"module": "./lib/index.js",
3636
"source": "./src/index.ts",
37-
"types": "./dist/index.d.ts",
37+
"types": "./lib/index.d.ts",
3838
"files": [
3939
"dist",
4040
"!dist/stats.html",

src/components/defaults.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type {PortableTextBlockStyle} from '@portabletext/types'
2-
import type {PortableTextBlockComponent, PortableTextReactComponents} from '../types'
3-
import {defaultMarks} from './marks'
4-
import {defaultLists, DefaultListItem} from './list'
2+
import type {PortableTextBlockComponent, PortableTextReactComponents} from '../types.js'
3+
import {defaultMarks} from './marks.js'
4+
import {defaultLists, DefaultListItem} from './list.js'
55
import {
66
DefaultUnknownType,
77
DefaultUnknownMark,
88
DefaultUnknownList,
99
DefaultUnknownListItem,
1010
DefaultUnknownBlockStyle,
11-
} from './unknown'
11+
} from './unknown.js'
1212

1313
export const DefaultHardBreak = () => <br />
1414

src/components/list.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {PortableTextListComponent, PortableTextListItemComponent} from '../types'
1+
import type {PortableTextListComponent, PortableTextListItemComponent} from '../types.js'
22

33
export const defaultLists: Record<'number' | 'bullet', PortableTextListComponent> = {
44
number: ({children}) => <ol>{children}</ol>,

src/components/marks.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {TypedObject} from '@portabletext/types'
2-
import type {PortableTextMarkComponent} from '../types'
2+
import type {PortableTextMarkComponent} from '../types.js'
33

44
interface DefaultLink extends TypedObject {
55
_type: 'link'

src/components/merge.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {PortableTextReactComponents, PortableTextComponents} from '../types'
1+
import type {PortableTextReactComponents, PortableTextComponents} from '../types.js'
22

33
export function mergeComponents(
44
parent: PortableTextReactComponents,

src/components/unknown.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type {PortableTextReactComponents} from '../types'
2-
import {unknownTypeWarning} from '../warnings'
1+
import React from 'react'
2+
import type {PortableTextReactComponents} from '../types.js'
3+
import {unknownTypeWarning} from '../warnings.js'
34

45
const hidden = {display: 'none'}
56

src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export * from './types'
1+
export type * from './types.js'
22
export type {ToolkitListNestMode as ListNestMode} from '@portabletext/toolkit'
33
export {toPlainText} from '@portabletext/toolkit'
4-
export {PortableText} from './react-portable-text'
5-
export {mergeComponents} from './components/merge'
6-
export {defaultComponents} from './components/defaults'
4+
export {PortableText} from './react-portable-text.js'
5+
export {mergeComponents} from './components/merge.js'
6+
export {defaultComponents} from './components/defaults.js'

src/react-portable-text.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
ReactPortableTextList,
99
Serializable,
1010
SerializedBlock,
11-
} from './types'
11+
} from './types.js'
1212
import {
1313
LIST_NEST_MODE_HTML,
1414
isPortableTextBlock,
@@ -27,16 +27,16 @@ import type {
2727
PortableTextSpan,
2828
TypedObject,
2929
} from '@portabletext/types'
30-
import {mergeComponents} from './components/merge'
31-
import {defaultComponents} from './components/defaults'
30+
import {mergeComponents} from './components/merge.js'
31+
import {defaultComponents} from './components/defaults.js'
3232
import {
3333
printWarning,
3434
unknownBlockStyleWarning,
3535
unknownListItemStyleWarning,
3636
unknownListStyleWarning,
3737
unknownMarkWarning,
3838
unknownTypeWarning,
39-
} from './warnings'
39+
} from './warnings.js'
4040

4141
export function PortableText<B extends TypedObject = PortableTextBlock>({
4242
value: input,

test/components.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ReactDOM from 'react-dom/server'
22
import {test} from 'vitest'
3-
import {PortableTextProps} from '../src'
4-
import {PortableText} from '../src/react-portable-text'
3+
import type {PortableTextProps} from '../src/types.js'
4+
import {PortableText} from '../src/react-portable-text.js'
55

66
const render = (props: PortableTextProps) =>
77
ReactDOM.renderToStaticMarkup(<PortableText {...props} onMissingComponent={false} />)

test/fixtures/index.ts

+31-31
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import emptyBlock from './001-empty-block'
2-
import singleSpan from './002-single-span'
3-
import multipleSpans from './003-multiple-spans'
4-
import basicMarkSingleSpan from './004-basic-mark-single-span'
5-
import basicMarkMultipleAdjacentSpans from './005-basic-mark-multiple-adjacent-spans'
6-
import basicMarkNestedMarks from './006-basic-mark-nested-marks'
7-
import linkMarkDef from './007-link-mark-def'
8-
import plainHeaderBlock from './008-plain-header-block'
9-
import messyLinkText from './009-messy-link-text'
10-
import basicBulletList from './010-basic-bullet-list'
11-
import basicNumberedList from './011-basic-numbered-list'
12-
import nestedLists from './014-nested-lists'
13-
import allBasicMarks from './015-all-basic-marks'
14-
import deepWeirdLists from './016-deep-weird-lists'
15-
import allDefaultBlockStyles from './017-all-default-block-styles'
16-
import marksAllTheWayDown from './018-marks-all-the-way-down'
17-
import keyless from './019-keyless'
18-
import emptyArray from './020-empty-array'
19-
import listWithoutLevel from './021-list-without-level'
20-
import inlineNodes from './022-inline-nodes'
21-
import hardBreaks from './023-hard-breaks'
22-
import inlineObjects from './024-inline-objects'
23-
import inlineBlockWithText from './026-inline-block-with-text'
24-
import styledListItems from './027-styled-list-items'
25-
import customListItemType from './028-custom-list-item-type'
26-
import customBlockType from './050-custom-block-type'
27-
import customMarks from './052-custom-marks'
28-
import overrideDefaultMarks from './053-override-default-marks'
29-
import listIssue from './060-list-issue'
30-
import missingMarkComponent from './061-missing-mark-component'
31-
import customBlockTypeWithChildren from './062-custom-block-type-with-children'
1+
import emptyBlock from './001-empty-block.js'
2+
import singleSpan from './002-single-span.js'
3+
import multipleSpans from './003-multiple-spans.js'
4+
import basicMarkSingleSpan from './004-basic-mark-single-span.js'
5+
import basicMarkMultipleAdjacentSpans from './005-basic-mark-multiple-adjacent-spans.js'
6+
import basicMarkNestedMarks from './006-basic-mark-nested-marks.js'
7+
import linkMarkDef from './007-link-mark-def.js'
8+
import plainHeaderBlock from './008-plain-header-block.js'
9+
import messyLinkText from './009-messy-link-text.js'
10+
import basicBulletList from './010-basic-bullet-list.js'
11+
import basicNumberedList from './011-basic-numbered-list.js'
12+
import nestedLists from './014-nested-lists.js'
13+
import allBasicMarks from './015-all-basic-marks.js'
14+
import deepWeirdLists from './016-deep-weird-lists.js'
15+
import allDefaultBlockStyles from './017-all-default-block-styles.js'
16+
import marksAllTheWayDown from './018-marks-all-the-way-down.js'
17+
import keyless from './019-keyless.js'
18+
import emptyArray from './020-empty-array.js'
19+
import listWithoutLevel from './021-list-without-level.js'
20+
import inlineNodes from './022-inline-nodes.js'
21+
import hardBreaks from './023-hard-breaks.js'
22+
import inlineObjects from './024-inline-objects.js'
23+
import inlineBlockWithText from './026-inline-block-with-text.js'
24+
import styledListItems from './027-styled-list-items.js'
25+
import customListItemType from './028-custom-list-item-type.js'
26+
import customBlockType from './050-custom-block-type.js'
27+
import customMarks from './052-custom-marks.js'
28+
import overrideDefaultMarks from './053-override-default-marks.js'
29+
import listIssue from './060-list-issue.js'
30+
import missingMarkComponent from './061-missing-mark-component.js'
31+
import customBlockTypeWithChildren from './062-custom-block-type-with-children.js'
3232

3333
export {
3434
emptyBlock,

test/mutations.test.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import ReactDOM from 'react-dom/server'
22
import {test} from 'vitest'
3-
import {PortableText} from '../src/react-portable-text'
4-
import type {PortableTextReactComponents, PortableTextProps} from '../src/types'
5-
import * as fixtures from './fixtures'
3+
import {PortableText} from '../src/react-portable-text.js'
4+
import type {PortableTextReactComponents, PortableTextProps} from '../src/types.js'
5+
import * as fixtures from './fixtures/index.js'
66

77
const render = (props: PortableTextProps) =>
88
ReactDOM.renderToStaticMarkup(<PortableText {...props} onMissingComponent={false} />)

test/portable-text.test.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {Fragment} from 'react'
22
import ReactDOM from 'react-dom/server'
33
import {test} from 'vitest'
4-
import {PortableText} from '../src/react-portable-text'
5-
import {
4+
import {PortableText} from '../src/react-portable-text.js'
5+
import type {
66
PortableTextReactComponents,
77
PortableTextMarkComponent,
88
PortableTextProps,
99
MissingComponentHandler,
10-
} from '../src/types'
11-
import * as fixtures from './fixtures'
10+
} from '../src/types.js'
11+
import * as fixtures from './fixtures/index.js'
1212

1313
const render = (props: PortableTextProps) =>
1414
ReactDOM.renderToStaticMarkup(<PortableText onMissingComponent={false} {...props} />)

test/toPlainText.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {test} from 'vitest'
2-
import {toPlainText} from '../src'
3-
import * as fixtures from './fixtures'
2+
import {toPlainText} from '../src/index.js'
3+
import * as fixtures from './fixtures/index.js'
44

55
test('can extract text from all fixtures without crashing', ({expect}) => {
66
for (const [key, fixture] of Object.entries(fixtures)) {

0 commit comments

Comments
 (0)