Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/ordered-imports': 'off',
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/bundlewatch-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: Borales/[email protected]
- run: yarn install
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- run: pnpm run bootstrap
- uses: jackyef/bundlewatch-gh-action@master
with:
build-script: yarn build:minify
build-script: pnpm run build:minify
bundlewatch-github-token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
8 changes: 5 additions & 3 deletions .github/workflows/bundlewatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: Borales/[email protected]
- run: yarn install
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- run: pnpm run bootstrap
- uses: jackyef/bundlewatch-gh-action@master
with:
build-script: yarn build:minify
build-script: pnpm run build:minify
bundlewatch-github-token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
8 changes: 5 additions & 3 deletions .github/workflows/coverage-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: Borales/[email protected]
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- name: 'Setup'
run: yarn install
run: pnpm run bootstrap
- name: 'Run tests'
run: yarn test:coverage
run: pnpm run test:coverage
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }} #required
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: Borales/[email protected]
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- name: 'Setup'
run: yarn install
run: pnpm run bootstrap
- name: 'Run tests'
run: yarn test:coverage
run: pnpm run test:coverage
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }} #required
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
link-workspace-packages = true
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { useData } from 'react-isomorphic-data';

const SFCWithHook: React.SFC<{ id: number }> = ({ id }) => {
const { data, loading, refetch } = useData(
const { data, loading, refetch } = useData<{ randomNumber: string }>(
`http://localhost:3000/some-rest-api/8-24-siblings-${id}`,
{},
{}, // options that can be accepted by the native `fetch` API
Expand Down
3 changes: 2 additions & 1 deletion examples/ssr/src/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const server = express();

server.disable('x-powered-by');
server.use(bodyParser());
// eslint-disable-next-line
// @ts-ignore
// eslint-disable-next-line
server.use(express.static(process.env.RAZZLE_PUBLIC_DIR!));
server.use(compression());

Expand Down
29 changes: 13 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,25 @@
"private": true,
"version": "0.0.1",
"description": "Work in progress",
"workspaces": {
"packages": [
"examples/*",
"packages/*"
]
"engines": {
"pnpm": ">=4.9.0"
},
"scripts": {
"bootstrap": "lerna bootstrap",
"build": "lerna run build --scope=react-isomorphic-data --stream",
"bootstrap": "pnpm recursive install",
Copy link

Choose a reason for hiding this comment

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

pnpm install will work the same way as pnpm recursive install in a monorepo

"build": "pnpm run build --filter react-isomorphic-data",
"build:minify": "bnr build:minify",
"dev": "lerna run dev --scope=react-isomorphic-data --stream",
"example": "lerna run start --scope=client --stream",
"example:ssr": "lerna run start --scope=ssr --stream",
"deploy": "yarn test && HUSKY_SKIP_HOOKS=true lerna publish --conventional-commits --create-release github",
"deploy:dryrun": "yarn test && HUSKY_SKIP_HOOKS=true lerna version --no-commit-hooks --no-git-tag-version --no-push",
"docgen:api": "yarn typedoc --out docusaurus/docs/api packages/react-isomorphic-data/src --tsconfig packages/react-isomorphic-data/tsconfig.json --theme docusaurus",
"test": "lerna run test --scope=react-isomorphic-data --stream",
"test:coverage": "lerna run test:coverage --scope=react-isomorphic-data --stream"
"dev": "pnpm run dev --filter react-isomorphic-data",
"example": "pnpm run start --filter client",
"example:ssr": "pnpm run start --filter ssr",
"deploy": "pnpm run test && HUSKY_SKIP_HOOKS=true lerna publish --conventional-commits --create-release github",
Copy link

Choose a reason for hiding this comment

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

pnpm test would also work

"deploy:dryrun": "pnpm run test && HUSKY_SKIP_HOOKS=true lerna version --no-commit-hooks --no-git-tag-version --no-push",
"docgen:api": "pnpx typedoc --out docusaurus/docs/api packages/react-isomorphic-data/src --tsconfig packages/react-isomorphic-data/tsconfig.json --theme docusaurus",
"test": "pnpm run test --filter react-isomorphic-data",
"test:coverage": "pnpm run test:coverage --filter react-isomorphic-data"
},
"betterScripts": {
"build:minify": {
"command": "lerna run build --scope=react-isomorphic-data --stream",
"command": "pnpm run build --filter react-isomorphic-data",
"env": {
"MINIFY": true
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react-isomorphic-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test": "jest",
"test:coverage": "jest --coverage --watchAll=false",
"build": "NODE_ENV=production rollup -c",
"prepack": "yarn build",
"prepack": "pnpm run build",
"deploy": "npm publish"
},
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import useData from '../useData';

const fetchMock = fetch as FetchMock;

interface TestingDataInterface {
message: string;
};

describe('useData hook tests', () => {
const onError = (e: Event) => {
e.preventDefault();
Expand All @@ -29,7 +33,7 @@ describe('useData hook tests', () => {
const client = createDataClient();

const Comp = () => {
const { data, loading } = useData(
const { data, loading } = useData<TestingDataInterface>(
'http://localhost/somewhere',
{},
{},
Expand Down Expand Up @@ -63,7 +67,7 @@ describe('useData hook tests', () => {
const client = createDataClient();

const Comp = () => {
const { data, loading } = useData(
const { data, loading } = useData<TestingDataInterface>(
'http://localhost/somewhere',
{},
{},
Expand Down Expand Up @@ -111,7 +115,7 @@ describe('useData hook tests', () => {
}

const Comp = () => {
const { data, loading } = useData('http://localhost/somewhere');
const { data, loading } = useData<TestingDataInterface>('http://localhost/somewhere');

return loading || !data ? (
<div>loading...</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { withLazyData, withData } from '../../hoc';

const fetchMock = fetch as FetchMock;

interface TestDataInterface {
message: string;
};

describe('Server-side rendering utilities test', () => {
beforeEach(() => {
fetchMock.resetMocks();
Expand All @@ -23,9 +27,9 @@ describe('Server-side rendering utilities test', () => {
const url = 'http://localhost:3000/some-rest-api';
const client = createDataClient({ initialCache: {}, ssr: true });
const Component = () => {
const { loading, data } = useData(url);
const { loading, data } = useData<TestDataInterface>(url);

return loading ? <div>loading...</div> : <div>{data.message}</div>;
return loading || !data ? <div>loading...</div> : <div>{data.message}</div>;
};

const App = (
Expand All @@ -42,9 +46,9 @@ describe('Server-side rendering utilities test', () => {
it('Should render a HTML markup with fetched data correctly', async () => {
const client = createDataClient({ initialCache: {}, ssr: true });
const Component = () => {
const { loading, data } = useData('http://localhost:3000/some-rest-api');
const { loading, data } = useData<TestDataInterface>('http://localhost:3000/some-rest-api');

return loading ? <div>loading...</div> : <div>{data.message}</div>;
return loading || !data ? <div>loading...</div> : <div>{data.message}</div>;
};

const App = (
Expand All @@ -61,11 +65,11 @@ describe('Server-side rendering utilities test', () => {
it('Should render a HTML markup with nested data fetching correctly', async () => {
const client = createDataClient({ initialCache: {}, ssr: true });
const ComponentB = () => {
const { loading, data } = useData(
const { loading, data } = useData<TestDataInterface>(
'http://localhost:3000/some-rest-api/2',
);

return loading ? (
return loading || !data ? (
<div>loading...</div>
) : (
<div>{`ComponentB: ${data.message}`}</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dev": "rollup -c --watch",
"test": "echo \"Error: no test specified\" && exit 1",
"build": "NODE_ENV=production rollup -c",
"prepack": "yarn build",
"prepack": "pnpm run build",
"deploy": "npm publish"
},
"files": [
Expand Down
Loading