Skip to content

Fix types generate #1266

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

Merged
merged 6 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"experimentalObjectRestSpread": true
},
"allowImportExportEverywhere": true,
"project": ["**/tsconfig.json", "tsconfig.test.json"]
"project": ["**/tsconfig.json"]
},
"plugins": ["@typescript-eslint", "react-hooks"],
"extends": [
Expand Down
5 changes: 1 addition & 4 deletions immutable/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// @ts-ignore
import useSWR from 'swr'

import useSWR, { Middleware, SWRHook } from 'swr'
import { withMiddleware } from '../src/utils/with-middleware'
import { Middleware, SWRHook } from '../src/types'

export const immutable: Middleware = useSWRNext => (key, fetcher, config) => {
// Always override all revalidate options.
Expand Down
2 changes: 1 addition & 1 deletion immutable/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "..",
"outDir": "./dist"
},
"include": [".", "../src"],
"exclude": ["./dist"]
Expand Down
4 changes: 1 addition & 3 deletions infinite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// hook where `key` and return type are not like the normal `useSWR` types.

import { useRef, useState, useCallback } from 'react'

// @ts-ignore
import useSWR from 'swr'

import defaultConfig from '../src/utils/config'
Expand All @@ -20,7 +18,7 @@ import {
SWRInfiniteResponse,
MutatorCallback,
Middleware
} from '../src/types'
} from 'swr'

export const infinite = ((<Data, Error>(useSWRNext: SWRHook) => (
getKey: KeyLoader<Data>,
Expand Down
2 changes: 1 addition & 1 deletion infinite/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "..",
"outDir": "./dist"
},
"include": [".", "../src"],
"exclude": ["./dist"]
Expand Down
5 changes: 3 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ module.exports = {
modulePathIgnorePatterns: ['<rootDir>/examples/'],
setupFilesAfterEnv: ['<rootDir>/jest-setup.ts'],
moduleNameMapper: {
'^swr$': '<rootDir>/src'
'^swr$': '<rootDir>/src',
'^@swr-internal/(.*)': '<rootDir>/src/$1'
},
globals: {
'ts-jest': {
tsconfig: 'tsconfig.test.json'
tsconfig: 'test/tsconfig.json'
}
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"homepage": "https://swr.vercel.app",
"license": "MIT",
"scripts": {
"clean": "rm -rf dist infinite/dist immutable/dist",
"build": "yarn build:core && yarn build:infinite && yarn build:immutable",
"watch": "concurrently \"yarn watch:core\" \"yarn watch:infinite\" \"yarn watch:immutable\"",
"watch:core": "bunchee src/index.ts --watch",
Expand All @@ -42,7 +43,7 @@
"build:core": "bunchee src/index.ts -m --no-sourcemap",
"build:infinite": "bunchee index.ts --cwd infinite -m --no-sourcemap",
"build:immutable": "bunchee index.ts --cwd immutable -m --no-sourcemap",
"prepublishOnly": "rm -rf dist infinite/dist immutable/dist && yarn build",
"prepublishOnly": "yarn clean && yarn build",
"types:check": "tsc --noEmit",
"format": "prettier --write \"{src,infinite,immutable,test,examples}/**/*.{ts,tsx}\"",
"lint": "eslint \"{src,infinite,immutable,test,examples}/**/*.{ts,tsx}\"",
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export {
KeyLoader,
SWRResponse,
Cache,
SWRHook,
Fetcher,
MutatorCallback,
Middleware,
// Legacy, for backwards compatibility
ConfigInterface,
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.test.json → test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"extends": "./tsconfig.json",
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"rootDir": "..",
"strict": false
},
"include": [
"..",
"./test",
"./jest-setup.ts"
Copy link
Member

Choose a reason for hiding this comment

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

Maybe:

Suggested change
"..",
"./test",
"./jest-setup.ts"
"../test",
"../jest-setup.ts"

]
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-cache.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, fireEvent, render, screen } from '@testing-library/react'
import React, { useState } from 'react'
import useSWR, { createCache, SWRConfig } from '../src'
import useSWR, { createCache, SWRConfig } from 'swr'
import { sleep, createKey } from './utils'

describe('useSWR - cache', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-concurrent-rendering.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('useSWR - concurrent rendering', () => {
React = require('react')
ReactDOM = require('react-dom')
act = require('react-dom/test-utils').act
useSWR = require('../src').default
useSWR = require('swr').default
})

it('should fetch data in concurrent rendering', async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-config-callbacks.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, render, screen, fireEvent } from '@testing-library/react'
import React from 'react'
import useSWR from '../src'
import useSWR from 'swr'
import { sleep, createResponse } from './utils'

describe('useSWR - config callbacks', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-configs.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, render, screen, fireEvent } from '@testing-library/react'
import React, { useEffect, useState } from 'react'
import useSWR, { mutate, SWRConfig } from '../src'
import useSWR, { mutate, SWRConfig } from 'swr'
import { sleep } from './utils'

describe('useSWR - configs', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-context-config.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, render, screen } from '@testing-library/react'
import React from 'react'
import useSWR, { mutate } from '../src'
import useSWR, { mutate } from 'swr'
import { createResponse } from './utils'

describe('useSWR - context configs', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-error.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, fireEvent, render, screen } from '@testing-library/react'
import React, { useEffect, useState } from 'react'
import useSWR, { mutate } from '../src'
import useSWR, { mutate } from 'swr'
import { sleep, createResponse } from './utils'

describe('useSWR - error', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-focus.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, fireEvent, render, screen } from '@testing-library/react'
import React, { useState } from 'react'
import useSWR from '../src'
import useSWR from 'swr'
import { sleep } from './utils'

const waitForNextTick = () => act(() => sleep(1))
Expand Down
4 changes: 2 additions & 2 deletions test/use-swr-immutable.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen, act, fireEvent } from '@testing-library/react'
import React, { useState } from 'react'
import useSWR from '../src'
import useSWRImmutable from '../immutable'
import useSWR from 'swr'
import useSWRImmutable from 'swr/immutable'
import { sleep, createKey } from './utils'

const waitForNextTick = () => act(() => sleep(1))
Expand Down
4 changes: 2 additions & 2 deletions test/use-swr-infinite.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react'
import { render, fireEvent, act, screen } from '@testing-library/react'
import { mutate } from '../src'
import useSWRInfinite from '../infinite'
import { mutate } from 'swr'
import useSWRInfinite from 'swr/infinite'
import { sleep, createResponse } from './utils'

describe('useSWRInfinite', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-integration.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, render, screen, fireEvent } from '@testing-library/react'
import React, { useState, useEffect } from 'react'
import useSWR from '../src'
import useSWR from 'swr'
import { createResponse, sleep } from './utils'

const waitForNextTick = () => act(() => sleep(1))
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-key.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, fireEvent, render, screen } from '@testing-library/react'
import React, { useState, useEffect } from 'react'
import useSWR from '../src'
import useSWR from 'swr'
import { createResponse, sleep } from './utils'

describe('useSWR - key', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-loading.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, render, screen } from '@testing-library/react'
import React from 'react'
import useSWR from '../src'
import useSWR from 'swr'
import { createResponse, sleep } from './utils'

describe('useSWR - loading', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-local-mutation.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, render, screen, fireEvent } from '@testing-library/react'
import React, { useEffect, useState } from 'react'
import useSWR, { mutate, createCache, SWRConfig } from '../src'
import useSWR, { mutate, createCache, SWRConfig } from 'swr'
import { serialize } from '../src/utils/serialize'
import { createResponse, sleep } from './utils'

Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-middlewares.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, render, screen } from '@testing-library/react'
import React, { useState, useEffect, useRef } from 'react'
import useSWR, { Middleware, SWRConfig } from '../src'
import useSWR, { Middleware, SWRConfig } from 'swr'
import { createResponse, sleep, createKey } from './utils'

describe('useSWR - middlewares', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-offline.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, fireEvent, render, screen } from '@testing-library/react'
import React from 'react'
import useSWR from '../src'
import useSWR from 'swr'
import { sleep } from './utils'

const waitForNextTick = () => act(() => sleep(1))
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-refresh.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, fireEvent, render, screen } from '@testing-library/react'
import React, { useState } from 'react'
import useSWR, { createCache, SWRConfig } from '../src'
import useSWR, { createCache, SWRConfig } from 'swr'
import { sleep } from './utils'

// This has to be an async function to wait a microtask to flush updates
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-revalidate.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, fireEvent, render, screen } from '@testing-library/react'
import React from 'react'
import useSWR from '../src'
import useSWR from 'swr'
import { createResponse, sleep } from './utils'

const waitForNextTick = () => act(() => sleep(1))
Expand Down
2 changes: 1 addition & 1 deletion test/use-swr-suspense.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, fireEvent, render, screen } from '@testing-library/react'
import React, { ReactNode, Suspense, useEffect, useState } from 'react'
import useSWR, { mutate } from '../src'
import useSWR, { mutate } from 'swr'
import { createResponse, sleep } from './utils'

class ErrorBoundary extends React.Component<{ fallback: ReactNode }> {
Expand Down
6 changes: 6 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
"rootDir": "src",
"strict": true,
"target": "es5",
"baseUrl": ".",
"paths": {
"swr": ["./src/index.ts"],
"swr/infinite": ["./infinite/index.ts"],
"swr/immutable": ["./immutable/index.ts"]
},
"typeRoots": ["./src/types", "./node_modules/@types"]
},
"include": ["src"],
Expand Down