Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require file extensions for imports and exports #4001

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,21 @@ module.exports = {
'no-console': ['warn', { allow: ['warn', 'error'] }],
semi: ['error', 'never'],
'import/order': 'off',
'import/extensions': 'off',
'import/extensions': ['error', 'ignorePackages'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know if this is autofixeable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it is. The only way to get something like that is to convert all of the packages to use moduleResolution: NodeNext, and then TypeScript will suggest imports with .js endings from the start.

I can try that, if you all are open to it. It's a bigger change / commitment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I briefly tried locally, and it creates a bunch of TS type resolution issues that need to be resolved. The project builds, but there are lots of type issues that appear in the editor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you attempt that after merging this, see ProseMirror/prosemirror#1305, where we discussed issues here in depth. In order to build with NodeNext, here's what I did to start:

  1. Update main tsconfig.json moduleResolution to "NodeNext"
  2. Override moduleResolution in tests/tsconfig.json to be "node", so cypress tests still build/run
  3. Update all prosemirror packages to get the compatible dependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bdbch is auto-fixability a blocker?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not really. I just need another review from @svenadlung since we share PR responsibilities.

Copy link
Contributor Author

@benasher44 benasher44 Jan 3, 2024

Choose a reason for hiding this comment

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

Heads up that there is now the "typescript.preferences.importModuleSpecifierEnding": "js" for VSCode, which will make .js endings the default when auto-importing!

'no-restricted-imports': ['error',
{
paths: [
{
name: '..',
message: 'Import from ../index.js instead.',
},
{
name: '.',
message: 'Import from ./index.js instead.',
},
],
},
],
'import/no-extraneous-dependencies': 'off',
'import/no-unresolved': 'off',
'import/no-dynamic-require': 'off',
Expand Down
2 changes: 1 addition & 1 deletion demos/preview/Shiki.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// otherwise the `onig.wasm` file is missing in the dist folder
import 'shiki/dist/onig.wasm?url'

import Worker from './shiki.worker?worker'
import Worker from './shiki.worker.js?worker'

export default {
props: {
Expand Down
2 changes: 1 addition & 1 deletion demos/setup/js.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'iframe-resizer/js/iframeResizer.contentWindow'
import './style.scss'

import { debug } from './helper'
import { debug } from './helper.js'

export default function init(name: string, source: any) {
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion demos/setup/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import './style.scss'
import React from 'react'
import { createRoot } from 'react-dom/client'

import { debug, splitName } from './helper'
import { debug, splitName } from './helper.js'

export default function init(name: string, source: any) {
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion demos/setup/svelte.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'iframe-resizer/js/iframeResizer.contentWindow'
import './style.scss'

import { debug, splitName } from './helper'
import { debug, splitName } from './helper.js'

export default function init(name: string, source: any) {
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion demos/setup/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './style.scss'

import { createApp } from 'vue'

import { debug, splitName } from './helper'
import { debug, splitName } from './helper.js'

export default function init(name: string, source: any) {
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Examples/CodeBlockLanguage/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import html from 'highlight.js/lib/languages/xml'
import { lowlight } from 'lowlight'
import React from 'react'

import CodeBlockComponent from './CodeBlockComponent'
import CodeBlockComponent from './CodeBlockComponent.jsx'

lowlight.registerLanguage('html', html)
lowlight.registerLanguage('css', css)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './MenuBar.scss'

import React, { Fragment } from 'react'

import MenuItem from './MenuItem'
import MenuItem from './MenuItem.jsx'

export default ({ editor }) => {
const items = [
Expand Down
4 changes: 2 additions & 2 deletions demos/src/Examples/CollaborativeEditing/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import React, {
} from 'react'
import * as Y from 'yjs'

import { variables } from '../../../variables'
import MenuBar from './MenuBar'
import { variables } from '../../../variables.js'
import MenuBar from './MenuBar.jsx'

const colors = ['#958DF1', '#F98181', '#FBBC88', '#FAF594', '#70CFF8', '#94FADB', '#B9F18D']
const names = [
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Examples/CollaborativeEditing/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import StarterKit from '@tiptap/starter-kit'
import { Editor, EditorContent } from '@tiptap/vue-3'
import * as Y from 'yjs'

import { variables } from '../../../variables'
import { variables } from '../../../variables.js'
import MenuBar from './MenuBar.vue'

const getRandomElement = list => {
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Examples/Community/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Text from '@tiptap/extension-text'
import { EditorContent, useEditor } from '@tiptap/react'
import React from 'react'

import suggestion from './suggestion'
import suggestion from './suggestion.js'

export default () => {
const limit = 280
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Examples/Community/React/suggestion.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactRenderer } from '@tiptap/react'
import tippy from 'tippy.js'

import { MentionList } from './MentionList'
import { MentionList } from './MentionList.jsx'

export default {
items: ({ query }) => {
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Examples/Community/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import { Editor, EditorContent } from '@tiptap/vue-3'

import suggestion from './suggestion'
import suggestion from './suggestion.js'

export default {
components: {
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Examples/Drawing/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Document from '@tiptap/extension-document'
import Text from '@tiptap/extension-text'
import { Editor, EditorContent } from '@tiptap/vue-3'

import Paper from './Paper'
import Paper from './Paper.js'

export default {
components: {
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Examples/Savvy/React/ColorHighlighter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Extension } from '@tiptap/core'
import { Plugin } from '@tiptap/pm/state'

import findColors from './findColors'
import findColors from './findColors.js'

export const ColorHighlighter = Extension.create({
name: 'colorHighlighter',
Expand Down
4 changes: 2 additions & 2 deletions demos/src/Examples/Savvy/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import Typography from '@tiptap/extension-typography'
import { EditorContent, useEditor } from '@tiptap/react'
import React from 'react'

import { ColorHighlighter } from './ColorHighlighter'
import { SmilieReplacer } from './SmilieReplacer'
import { ColorHighlighter } from './ColorHighlighter.ts'
import { SmilieReplacer } from './SmilieReplacer.ts'

export default () => {
const editor = useEditor({
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Examples/Savvy/Vue/ColorHighlighter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Extension } from '@tiptap/core'
import { Plugin } from '@tiptap/pm/state'

import findColors from './findColors'
import findColors from './findColors.js'

export const ColorHighlighter = Extension.create({
name: 'colorHighlighter',
Expand Down
4 changes: 2 additions & 2 deletions demos/src/Examples/Savvy/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import Text from '@tiptap/extension-text'
import Typography from '@tiptap/extension-typography'
import { Editor, EditorContent } from '@tiptap/vue-3'

import { ColorHighlighter } from './ColorHighlighter'
import { SmilieReplacer } from './SmilieReplacer'
import { ColorHighlighter } from './ColorHighlighter.ts'
import { SmilieReplacer } from './SmilieReplacer.ts'

export default {
components: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Plugin, PluginKey } from '@tiptap/pm/state'
import * as Y from 'yjs'

import { AnnotationState } from './AnnotationState'
import { AnnotationState } from './AnnotationState.js'

export const AnnotationPluginKey = new PluginKey('annotation')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
} from 'y-prosemirror'
import * as Y from 'yjs'

import { AnnotationItem } from './AnnotationItem'
import { AnnotationPluginKey } from './AnnotationPlugin'
import { AnnotationItem } from './AnnotationItem.js'
import { AnnotationPluginKey } from './AnnotationPlugin.js'
import {
AddAnnotationAction,
DeleteAnnotationAction,
UpdateAnnotationAction,
} from './collaboration-annotation'
} from './collaboration-annotation.js'

export interface AnnotationStateOptions {
HTMLAttributes: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Extension } from '@tiptap/core'
import * as Y from 'yjs'

import { AnnotationPlugin, AnnotationPluginKey } from './AnnotationPlugin'
import { AnnotationPlugin, AnnotationPluginKey } from './AnnotationPlugin.js'

export interface AddAnnotationAction {
type: 'addAnnotation',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CollaborationAnnotation } from './collaboration-annotation'
import { CollaborationAnnotation } from './collaboration-annotation.js'

export * from './collaboration-annotation'
export * from './collaboration-annotation.js'

export default CollaborationAnnotation
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import Text from '@tiptap/extension-text'
import { Editor, EditorContent } from '@tiptap/vue-3'
import * as Y from 'yjs'

import CollaborationAnnotation from './extension'
import CollaborationAnnotation from './extension/index.ts'

export default {
components: {
Expand Down
4 changes: 2 additions & 2 deletions demos/src/Experiments/Commands/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import StarterKit from '@tiptap/starter-kit'
import { Editor, EditorContent } from '@tiptap/vue-3'

import Commands from './commands'
import suggestion from './suggestion'
import Commands from './commands.js'
import suggestion from './suggestion.js'

export default {
components: {
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Experiments/Embeds/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import StarterKit from '@tiptap/starter-kit'
import { Editor, EditorContent } from '@tiptap/vue-3'

import Iframe from './iframe'
import Iframe from './iframe.ts'

export default {
components: {
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Experiments/ExtensionStorage/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Text from '@tiptap/extension-text'
import { EditorContent, useEditor } from '@tiptap/react'
import React from 'react'

import { CustomExtension } from './CustomExtension'
import { CustomExtension } from './CustomExtension.ts'

export default () => {
const editor = useEditor({
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Experiments/ExtensionStorage/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import { Editor, EditorContent } from '@tiptap/vue-3'

import { CustomExtension } from './CustomExtension'
import { CustomExtension } from './CustomExtension.ts'

export default {
components: {
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Experiments/Figure/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Image from '@tiptap/extension-image'
import StarterKit from '@tiptap/starter-kit'
import { Editor, EditorContent } from '@tiptap/vue-3'

import { Figure } from './figure'
import { Figure } from './figure.ts'

export default {
components: {
Expand Down
4 changes: 2 additions & 2 deletions demos/src/Experiments/GenericFigure/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import TableRow from '@tiptap/extension-table-row'
import StarterKit from '@tiptap/starter-kit'
import { Editor, EditorContent } from '@tiptap/vue-3'

import { Figcaption } from './figcaption'
import { Figure } from './figure'
import { Figcaption } from './figcaption.ts'
import { Figure } from './figure.ts'

const ImageFigure = Figure.extend({
name: 'capturedImage',
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Experiments/IsolatingClear/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import TextStyle from '@tiptap/extension-text-style'
import { EditorContent, Node, useEditor } from '@tiptap/react'
import React from 'react'

import { content } from '../content'
import { content } from '../content.ts'

const WrapperBlock = Node.create({
name: 'wrapperBlock',
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Experiments/Linter/Vue/extension/Linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Node as ProsemirrorNode } from '@tiptap/pm/model'
import { Plugin, PluginKey, TextSelection } from '@tiptap/pm/state'
import { Decoration, DecorationSet } from '@tiptap/pm/view'

import LinterPlugin, { Result as Issue } from './LinterPlugin'
import LinterPlugin, { Result as Issue } from './LinterPlugin.js'

interface IconDivElement extends HTMLDivElement {
issue?: Issue
Expand Down
10 changes: 5 additions & 5 deletions demos/src/Experiments/Linter/Vue/extension/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Linter } from './Linter'
import { Linter } from './Linter.js'

export * from './Linter'
export * from './Linter.js'
export default Linter

export { BadWords } from './plugins/BadWords'
export { HeadingLevel } from './plugins/HeadingLevel'
export { Punctuation } from './plugins/Punctuation'
export { BadWords } from './plugins/BadWords.js'
export { HeadingLevel } from './plugins/HeadingLevel.js'
export { Punctuation } from './plugins/Punctuation.js'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import LinterPlugin from '../LinterPlugin'
import LinterPlugin from '../LinterPlugin.js'

export class BadWords extends LinterPlugin {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EditorView } from '@tiptap/pm/view'

import LinterPlugin, { Result as Issue } from '../LinterPlugin'
import LinterPlugin, { Result as Issue } from '../LinterPlugin.js'

export class HeadingLevel extends LinterPlugin {
fixHeader(level: number) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EditorView } from '@tiptap/pm/view'

import LinterPlugin, { Result as Issue } from '../LinterPlugin'
import LinterPlugin, { Result as Issue } from '../LinterPlugin.js'

export class Punctuation extends LinterPlugin {
public regex = / ([,.!?:]) ?/g
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Experiments/Linter/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import { Editor, EditorContent } from '@tiptap/vue-3'

import Linter, { BadWords, HeadingLevel, Punctuation } from './extension'
import Linter, { BadWords, HeadingLevel, Punctuation } from './extension/index.ts'

export default {
components: {
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Experiments/TrailingNode/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import StarterKit from '@tiptap/starter-kit'
import { Editor, EditorContent } from '@tiptap/vue-3'

import { TrailingNode } from './trailing-node'
import { TrailingNode } from './trailing-node.ts'

export default {
components: {
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Nodes/Mention/React/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EditorContent, useEditor } from '@tiptap/react'
import StarterKit from '@tiptap/starter-kit'
import React from 'react'

import suggestion from './suggestion'
import suggestion from './suggestion.js'

export default () => {
const editor = useEditor({
Expand Down
2 changes: 1 addition & 1 deletion demos/src/Nodes/Mention/Vue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Mention from '@tiptap/extension-mention'
import StarterKit from '@tiptap/starter-kit'
import { Editor, EditorContent } from '@tiptap/vue-3'

import suggestion from './suggestion'
import suggestion from './suggestion.js'

export default {
components: {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/CommandManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { EditorState, Transaction } from '@tiptap/pm/state'

import { Editor } from './Editor'
import { createChainableState } from './helpers/createChainableState'
import { Editor } from './Editor.js'
import { createChainableState } from './helpers/createChainableState.js'
import {
AnyCommands, CanCommands, ChainedCommands, CommandProps, SingleCommands,
} from './types'
} from './types.js'

export class CommandManager {
editor: Editor
Expand Down