Skip to content

Commit

Permalink
feat!: add strict ESM support
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Apr 9, 2024
1 parent 1032444 commit f8ed232
Show file tree
Hide file tree
Showing 31 changed files with 6,225 additions and 3,866 deletions.
5 changes: 2 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
"sanity",
"sanity/typescript",
"sanity/react",
"plugin:react-hooks/recommended",
"plugin:prettier/recommended",
"plugin:react/jsx-runtime",
"prettier"
],
"plugins": ["simple-import-sort"],
"rules": {
"react/prop-types": "off",
"react/require-default-props": "off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error"
"simple-import-sort/exports": "error",
"@typescript-eslint/no-explicit-any": "off"
}
}
9,918 changes: 6,140 additions & 3,778 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions package.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ export default defineConfig({
dist: 'dist',
tsconfig: 'tsconfig.dist.json',

// Avoid ttyl, os and other node specific deps
external: ['@sanity/mutator'],

// Remove this block to enable strict export validation
extract: {
rules: {
Expand Down
58 changes: 27 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@
},
"license": "MIT",
"author": "Sanity.io <[email protected]>",
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"source": "./src/index.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"node": {
"module": "./dist/index.esm.js",
"import": "./dist/index.cjs.mjs"
},
"import": "./dist/index.esm.js",
"default": "./dist/index.esm.js"
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
Expand All @@ -41,7 +37,7 @@
"v2-incompatible.js"
],
"scripts": {
"build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
"build": "run-s clean && pkg-utils build --strict && pkg-utils --strict",
"clean": "rimraf dist",
"format": "prettier --write --cache --ignore-unknown .",
"link-watch": "plugin-kit link-watch",
Expand All @@ -51,49 +47,49 @@
"prepare": "husky install"
},
"dependencies": {
"@sanity/icons": "^2.2.2",
"@sanity/icons": "^2.11.7",
"@sanity/incompatible-plugin": "^1.0.4",
"@sanity/ui": "^1.2.2",
"@sanity/ui": "^2.1.0",
"@sanity/uuid": "^3.0.2",
"sanity-plugin-internationalized-array": "^1.10.3",
"sanity-plugin-utils": "^1.6.2"
"sanity-plugin-internationalized-array": "^2.0.0",
"sanity-plugin-utils": "^1.6.4"
},
"devDependencies": {
"@commitlint/cli": "^18.2.0",
"@commitlint/config-conventional": "^18.1.0",
"@sanity/pkg-utils": "2.4.10",
"@commitlint/cli": "^19.2.1",
"@commitlint/config-conventional": "^19.1.0",
"@sanity/pkg-utils": "6.1.0",
"@sanity/plugin-kit": "^3.1.10",
"@sanity/semantic-release-preset": "^4.1.7",
"@types/react": "^18.0.27",
"@types/styled-components": "^5.1.26",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"@types/react": "^18.2.75",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"eslint-config-sanity": "^6.0.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.32.2",
"eslint-config-prettier": "^9.1.0",
"eslint-config-sanity": "^7.1.2",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-simple-import-sort": "^12.0.0",
"husky": "^8.0.3",
"lint-staged": "^15.0.2",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.4",
"prettier-plugin-packagejson": "^2.4.2",
"prettier": "^3.2.5",
"prettier-plugin-packagejson": "^2.4.14",
"react": "^18",
"react-dom": "^18",
"react-is": "^18",
"rimraf": "^4.1.2",
"sanity": "3.19.0",
"sanity": "^3.37.0",
"semantic-release": "^23.0.7",
"typescript": "4.9.5"
"typescript": "5.4.2"
},
"peerDependencies": {
"@sanity/ui": "^1.0 || ^2.0",
"@sanity/mutator": "^3.37.0",
"@sanity/ui": "^2.1",
"react": "^18",
"react-dom": "^18",
"sanity": "^3.0.0",
"styled-components": "^5.0 || ^6.0"
"sanity": "^3.37.0",
"styled-components": "^6.1"
},
"engines": {
"node": ">=14"
Expand Down
10 changes: 5 additions & 5 deletions src/actions/DeleteMetadataAction.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {TrashIcon} from '@sanity/icons'
import {ButtonTone, useToast} from '@sanity/ui'
import {type ButtonTone, useToast} from '@sanity/ui'
import {useCallback, useMemo, useState} from 'react'
import {
DocumentActionComponent,
KeyedObject,
Reference,
TypedObject,
type DocumentActionComponent,
type KeyedObject,
type Reference,
type TypedObject,
useClient,
} from 'sanity'

Expand Down
8 changes: 6 additions & 2 deletions src/actions/DeleteTranslationAction.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import {TrashIcon} from '@sanity/icons'
import {ButtonTone, useToast} from '@sanity/ui'
import {type ButtonTone, useToast} from '@sanity/ui'
import {useCallback, useState} from 'react'
import {DocumentActionComponent, SanityDocument, useClient} from 'sanity'
import {
type DocumentActionComponent,
type SanityDocument,
useClient,
} from 'sanity'

import DeleteTranslationDialog from '../components/DeleteTranslationDialog'
import DeleteTranslationFooter from '../components/DeleteTranslationFooter'
Expand Down
2 changes: 1 addition & 1 deletion src/badges/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {DocumentBadgeDescription, DocumentBadgeProps} from 'sanity'
import type {DocumentBadgeDescription, DocumentBadgeProps} from 'sanity'

import {useDocumentInternationalizationContext} from '../components/DocumentInternationalizationContext'

Expand Down
2 changes: 1 addition & 1 deletion src/components/BulkPublish/DocumentCheck.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Card, Spinner} from '@sanity/ui'
import React, {useEffect, useMemo} from 'react'
import {useEffect, useMemo} from 'react'
import {Preview, useEditState, useSchema, useValidationStatus} from 'sanity'

type DocumentCheckProps = {
Expand Down
7 changes: 4 additions & 3 deletions src/components/BulkPublish/InfoIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Box, ButtonTone, Text, Tooltip} from '@sanity/ui'
import React, {PropsWithChildren} from 'react'
import {Box, type ButtonTone, Text, Tooltip} from '@sanity/ui'
import type {ComponentType, PropsWithChildren} from 'react'
import {TextWithTone} from 'sanity'

type InfoIconProps = PropsWithChildren & {
icon: React.ComponentType
icon: ComponentType
tone: ButtonTone
text?: string
}
Expand All @@ -14,6 +14,7 @@ export default function InfoIcon(props: InfoIconProps) {

return (
<Tooltip
animate
portal
content={
children ? (
Expand Down
5 changes: 3 additions & 2 deletions src/components/BulkPublish/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Button, Card, Dialog, Inline, Stack, Text, useToast} from '@sanity/ui'
import React, {useCallback, useState} from 'react'
import {useCallback, useState} from 'react'
import {TextWithTone, useClient, useWorkspace} from 'sanity'

import {API_VERSION} from '../../constants'
import {TranslationReference} from '../../types'
import type {TranslationReference} from '../../types'
import DocumentCheck from './DocumentCheck'
import Info from './Info'

Expand Down Expand Up @@ -102,6 +102,7 @@ export default function BulkPublish(props: BulkPublishProps) {

{open && (
<Dialog
animate
header="Bulk publishing"
id="bulk-publish-dialog"
onClose={onClose}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ConstrainedBox.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Box} from '@sanity/ui'
import styled from 'styled-components'
import {styled} from 'styled-components'

export default styled(Box)`
max-width: 280px;
Expand Down
2 changes: 1 addition & 1 deletion src/components/DeleteTranslationDialog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Card, Flex, Spinner, Stack, Text} from '@sanity/ui'
import {useEffect, useMemo} from 'react'
import {SanityDocument} from 'sanity'
import type {SanityDocument} from 'sanity'
import {useListeningQuery} from 'sanity-plugin-utils'

import DocumentPreview from './DocumentPreview'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SanityDocument} from 'sanity'
import type {SanityDocument} from 'sanity'

import {METADATA_SCHEMA_NAME} from '../../constants'

Expand Down
4 changes: 2 additions & 2 deletions src/components/DocumentInternationalizationContext.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {useContext} from 'react'
import {createContext} from 'react'
import {LayoutProps, useClient, useWorkspace} from 'sanity'
import {type LayoutProps, useClient, useWorkspace} from 'sanity'
import {suspend} from 'suspend-react'

import {DEFAULT_CONFIG} from '../constants'
import {PluginConfig, PluginConfigContext} from '../types'
import type {PluginConfig, PluginConfigContext} from '../types'

const DocumentInternationalizationContext =
createContext<PluginConfigContext>(DEFAULT_CONFIG)
Expand Down
5 changes: 3 additions & 2 deletions src/components/DocumentInternationalizationMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
useClickOutside,
} from '@sanity/ui'
import {uuid} from '@sanity/uuid'
import {FormEvent, useCallback, useMemo, useState} from 'react'
import {type FormEvent, useCallback, useMemo, useState} from 'react'
import {useEditState} from 'sanity'

import {useTranslationMetadata} from '../hooks/useLanguageMetadata'
import {DocumentInternationalizationMenuProps} from '../types'
import type {DocumentInternationalizationMenuProps} from '../types'
import {useDocumentInternationalizationContext} from './DocumentInternationalizationContext'
import LanguageManage from './LanguageManage'
import LanguageOption from './LanguageOption'
Expand Down Expand Up @@ -203,6 +203,7 @@ export function DocumentInternationalizationMenu(

return (
<Popover
animate
constrainSize
content={content}
open={open}
Expand Down
1 change: 1 addition & 0 deletions src/components/LanguageManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default function LanguageManage(props: LanguageManageProps) {

return (
<Tooltip
animate
content={
id ? null : (
<Box padding={2}>
Expand Down
6 changes: 4 additions & 2 deletions src/components/LanguageOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
} from '@sanity/ui'
import {uuid} from '@sanity/uuid'
import {useCallback} from 'react'
import {ObjectSchemaType, SanityDocument, useClient} from 'sanity'
import {type ObjectSchemaType, type SanityDocument, useClient} from 'sanity'

import {METADATA_SCHEMA_NAME} from '../constants'
import {useOpenInNewPane} from '../hooks/useOpenInNewPane'
import {Language, Metadata, TranslationReference} from '../types'
import type {Language, Metadata, TranslationReference} from '../types'
import {createReference} from '../utils/createReference'
import {removeExcludedPaths} from '../utils/excludePaths'
import {useDocumentInternationalizationContext} from './DocumentInternationalizationContext'
Expand Down Expand Up @@ -156,6 +156,7 @@ export default function LanguageOption(props: LanguageOptionProps) {
source,
sourceLanguageId,
toast,
weakReferences,
])

let message
Expand All @@ -170,6 +171,7 @@ export default function LanguageOption(props: LanguageOptionProps) {

return (
<Tooltip
animate
content={
<Box padding={2}>
<Text muted size={1}>
Expand Down
4 changes: 2 additions & 2 deletions src/components/LanguagePatch.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {EditIcon} from '@sanity/icons'
import {Badge, Box, Button, Flex, Text, useToast} from '@sanity/ui'
import {useCallback} from 'react'
import {SanityDocument, useClient} from 'sanity'
import {type SanityDocument, useClient} from 'sanity'

import {Language} from '../types'
import type {Language} from '../types'
import {useDocumentInternationalizationContext} from './DocumentInternationalizationContext'

type LanguagePatchProps = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/OptimisticallyStrengthen/ReferencePatcher.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {useEffect} from 'react'
import {PatchEvent, unset, useClient, useEditState} from 'sanity'
import {useDocumentPane} from 'sanity/desk'
import {useDocumentPane} from 'sanity/structure'

import {API_VERSION} from '../../constants'
import {TranslationReference} from '../../types'
import type {TranslationReference} from '../../types'

type ReferencePatcherProps = {
translation: TranslationReference
Expand Down
2 changes: 1 addition & 1 deletion src/components/OptimisticallyStrengthen/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TranslationReference} from '../../types'
import type {TranslationReference} from '../../types'
import ReferencePatcher from './ReferencePatcher'

type OptimisticallyStrengthenProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Warning.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Card, Flex, Text} from '@sanity/ui'
import {PropsWithChildren} from 'react'
import type {PropsWithChildren} from 'react'

import ConstrainedBox from './ConstrainedBox'

Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {PluginConfigContext} from './types'
import type {PluginConfigContext} from './types'

export const METADATA_SCHEMA_NAME = `translation.metadata`
export const TRANSLATIONS_ARRAY_NAME = `translations`
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLanguageMetadata.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {useListeningQuery} from 'sanity-plugin-utils'

import {METADATA_SCHEMA_NAME} from '../constants'
import {Metadata} from '../types'
import type {Metadata} from '../types'

// Using references() seemed less reliable for updating the listener
// results than querying raw values in the array
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useOpenInNewPane.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useCallback, useContext} from 'react'
import {usePaneRouter} from 'sanity/desk'
import {RouterContext} from 'sanity/router'
import {usePaneRouter} from 'sanity/structure'

export function useOpenInNewPane(id?: string, type?: string) {
const routerContext = useContext(RouterContext)
Expand All @@ -11,7 +11,7 @@ export function useOpenInNewPane(id?: string, type?: string) {
return
}

// No panes open, function might be called outside Desk
// No panes open, function might be called outside Structure
if (!routerPanesState.length) {
routerContext.navigateIntent('edit', {id, type})
return
Expand Down
Loading

0 comments on commit f8ed232

Please sign in to comment.