Skip to content

Commit

Permalink
enhance: Include Object.hasOwn polyfill (#2309)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Dec 3, 2022
1 parent e3ee5ee commit 14b93f6
Show file tree
Hide file tree
Showing 36 changed files with 152 additions and 96 deletions.
5 changes: 1 addition & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = function (api) {
{
typing: 'typescript',
loose: true,
useBuiltIns: 'entry',
resolver: {
extensions: ['.ts.', '.tsx', '.js', '.jsx', '.es', '.es6', '.mjs'],
resolvePath(sourcePath, currentFile, opts) {
Expand All @@ -26,10 +27,6 @@ module.exports = function (api) {
},
],
],
plugins: [
process.env.BROWSERSLIST_ENV !== '2020' &&
'babel-plugin-transform-object-hasown',
].filter(p => p),
assumptions: {
noDocumentAll: true,
noClassCalls: true,
Expand Down
11 changes: 10 additions & 1 deletion docs/core/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,16 @@ export default function App({ Component, pageProps }: AppProps) {

Alternatively [integrate state with redux](../guides/redux.md)

<details><summary><b>Legacy (IE) browser support</b></summary>
<details><summary><b>Older browser support</b></summary>

If your application targets older browsers (a few years or more), be sure to load polyfills.
Typically this is done with [@babel/preset-env useBuiltIns: 'entry'](https://babeljs.io/docs/en/babel-preset-env#usebuiltins),
coupled with importing [https://www.npmjs.com/package/core-js] at the entrypoint of your application.

This ensures only the needed polyfills for your browser support targets are included in your application bundle.

</details>
<details><summary><b>Internet Explorer support</b></summary>

If you see `Uncaught TypeError: Class constructor Resource cannot be invoked without 'new'`,
follow the instructions to [add legacy browser support to packages](../guides/legacy-browser)
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"@types/react": "18.0.25",
"@typescript-eslint/eslint-plugin": "5.44.0",
"@typescript-eslint/parser": "5.44.0",
"babel-plugin-transform-object-hasown": "^1.1.0",
"benchmark": "^2.1.4",
"conventional-changelog-anansi": "^0.2.0",
"copyfiles": "^2.4.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@
"url": "https://github.com/coinbase/rest-hooks/issues"
},
"dependencies": {
"@babel/runtime": "^7.13.0",
"@babel/runtime": "^7.17.0",
"@rest-hooks/normalizr": "^9.3.1",
"core-js": "^3.17.0",
"flux-standard-action": "^2.1.1"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/manager/NetworkManager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'core-js/es/object/has-own';
import { RECEIVE_TYPE, FETCH_TYPE, RESET_TYPE } from '../actionTypes.js';
import Controller from '../controller/Controller.js';
import { initialState } from '../internal.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/endpoint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
"url": "https://github.com/coinbase/rest-hooks/issues"
},
"dependencies": {
"@babel/runtime": "^7.13.0"
"@babel/runtime": "^7.17.0",
"core-js": "^3.17.0"
},
"devDependencies": {
"@babel/cli": "7.19.3",
Expand Down
1 change: 1 addition & 0 deletions packages/endpoint/src/schemas/All.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'core-js/es/object/has-own';
import { EntityTable } from '../interface.js';
import { EntityInterface, EntityMap, SchemaFunction } from '../schema.js';
import ArraySchema from './Array.js';
Expand Down
1 change: 1 addition & 0 deletions packages/endpoint/src/schemas/Entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import 'core-js/es/object/has-own';
import type { Schema, NormalizedIndex, UnvisitFunction } from '../interface.js';
import { AbstractInstanceType } from '../normal.js';
import { isImmutable, denormalizeImmutable } from './ImmutableUtils.js';
Expand Down
2 changes: 2 additions & 0 deletions packages/endpoint/src/schemas/validatRequired.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'core-js/es/object/has-own';

export default function validateRequired(
processedEntity: any,
requiredDefaults: Record<string, unknown>,
Expand Down
2 changes: 1 addition & 1 deletion packages/experimental/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"url": "https://github.com/coinbase/rest-hooks/issues"
},
"dependencies": {
"@babel/runtime": "^7.13.0",
"@babel/runtime": "^7.17.0",
"@types/path-to-regexp": "^1.7.0",
"path-to-regexp": "^6.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"url": "https://github.com/coinbase/rest-hooks/issues"
},
"dependencies": {
"@babel/runtime": "^7.13.0",
"@babel/runtime": "^7.17.0",
"@rest-hooks/endpoint": "^3.2.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"url": "https://github.com/coinbase/rest-hooks/issues"
},
"dependencies": {
"@babel/runtime": "^7.13.0"
"@babel/runtime": "^7.17.0"
},
"peerDependencies": {
"@rest-hooks/endpoint": "^0.6.1 || ^1.0.0-0 || ^2.0.0-0 || ^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/img/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"url": "https://github.com/coinbase/rest-hooks/issues"
},
"dependencies": {
"@babel/runtime": "^7.13.0"
"@babel/runtime": "^7.17.0"
},
"peerDependencies": {
"@rest-hooks/endpoint": "^1.0.3 || ^2.0.0-0 || ^3.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"peerDependencies": {
"@rest-hooks/react": "^0.1.0 || ^0.2.0 || ^6.0.0 || ^7.0.0",
"@types/react": "^16.8.4 || ^17.0.0 || ^18.0.0-0",
"core-js": "^3.17.0",
"react": "^16.8.4 || ^17.0.0 || ^18.0.0-0"
},
"peerDependenciesMeta": {
Expand Down
1 change: 1 addition & 0 deletions packages/legacy/src/endpoint/shapeToEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Endpoint } from '@rest-hooks/endpoint';
import type { EndpointInstance } from '@rest-hooks/endpoint';

import type { FetchShape } from './shapes.js';
import 'core-js/es/object/has-own';

type ShapeTypeToSideEffect<T extends 'read' | 'mutate' | 'delete' | undefined> =
T extends 'read' | undefined ? undefined : true;
Expand Down
1 change: 1 addition & 0 deletions packages/legacy/src/resource/Entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { AbstractInstanceType, Schema, schema } from '@rest-hooks/endpoint';
import 'core-js/es/object/has-own';

import { isImmutable, denormalizeImmutable } from './ImmutableUtils.js';
import SimpleRecord from './SimpleRecord.js';
Expand Down
1 change: 1 addition & 0 deletions packages/legacy/src/resource/SimpleRecord.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { AbstractInstanceType, Schema } from '@rest-hooks/endpoint';
import 'core-js/es/object/has-own';

import { normalize, infer } from './Object.js';
import { NormalizedEntity } from './types.js';
Expand Down
1 change: 1 addition & 0 deletions packages/legacy/src/resource/SimpleResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
EndpointExtraOptions,
AbstractInstanceType,
} from '@rest-hooks/endpoint';
import 'core-js/es/object/has-own';

import { ReadShape, MutateShape, DeleteShape } from '../rest-3/legacy.js';
import Delete from './Delete.js';
Expand Down
1 change: 1 addition & 0 deletions packages/legacy/src/rest-3/SimpleResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
SchemaList,
} from '@rest-hooks/endpoint';
import type { AbstractInstanceType } from '@rest-hooks/endpoint';
import 'core-js/es/object/has-own';

import EntityRecord from './EntityRecord.js';
import { NotImplementedError } from './errors.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/normalizr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
"rollup-plugin-terser": "^7.0.2"
},
"dependencies": {
"@babel/runtime": "^7.13.0",
"@babel/runtime": "^7.17.0",
"core-js": "^3.17.0",
"npm-run-all": "^4.1.5"
}
}
1 change: 1 addition & 0 deletions packages/normalizr/src/WeakListMap.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'core-js/es/object/has-own';
/** Link in a chain */
class Link<K extends object, V> {
children = new WeakMap<K, Link<K, V>>();
Expand Down
1 change: 1 addition & 0 deletions packages/normalizr/src/denormalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
DenormalizeCache,
} from './types.js';
import WeakListMap from './WeakListMap.js';
import 'core-js/es/object/has-own';

const DRAFT = Symbol('draft');

Expand Down
5 changes: 3 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@
"url": "https://github.com/coinbase/rest-hooks/issues"
},
"dependencies": {
"@babel/runtime": "^7.13.0",
"@babel/runtime": "^7.17.0",
"@rest-hooks/core": "^4.1.0",
"@rest-hooks/use-enhanced-reducer": "^1.2.0"
"@rest-hooks/use-enhanced-reducer": "^1.2.0",
"core-js": "^3.17.0"
},
"peerDependencies": {
"@react-navigation/native": "^6.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/NetworkErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { NetworkError } from '@rest-hooks/core';
import React from 'react';
import 'core-js/es/object/has-own';

function isNetworkError(error: NetworkError | unknown): error is NetworkError {
return Object.hasOwn(error as any, 'status');
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/hooks/useCacheState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { State } from '@rest-hooks/core';
import React, { useContext } from 'react';
import 'core-js/es/object/has-own';

import { StateContext, StoreContext } from '../context.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/redux/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"url": "https://github.com/coinbase/rest-hooks/issues"
},
"dependencies": {
"@babel/runtime": "^7.13.0"
"@babel/runtime": "^7.17.0"
},
"peerDependencies": {
"@rest-hooks/react": "^0.1.0 || ^0.2.0 || ^6.0.0 || ^7.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/rest-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@
"url": "https://github.com/coinbase/rest-hooks/issues"
},
"dependencies": {
"@babel/runtime": "^7.13.0",
"@babel/runtime": "^7.17.0",
"@rest-hooks/endpoint": "^3.2.3",
"core-js": "^3.17.0",
"redux": "^4.0.0"
},
"peerDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/rest-hooks/src/endpoint/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { EndpointInterface } from '@rest-hooks/react';

import type { FetchShape } from './shapes.js';
import 'core-js/es/object/has-own';

type ShapeTypeToSideEffect<T extends 'read' | 'mutate' | 'delete' | undefined> =
T extends 'read' | undefined ? undefined : true;
Expand Down
3 changes: 2 additions & 1 deletion packages/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@
"url": "https://github.com/coinbase/rest-hooks/issues"
},
"dependencies": {
"@babel/runtime": "^7.13.0",
"@babel/runtime": "^7.17.0",
"@rest-hooks/endpoint": "^3.2.3",
"copyfiles": "^2.4.1",
"core-js": "^3.17.0",
"path-to-regexp": "^6.2.1"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/rest/src/RestHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { compile, PathFunction, parse } from 'path-to-regexp';
import 'core-js/es/object/has-own';

import { ShortenPath } from './pathTypes.js';

Expand Down
3 changes: 2 additions & 1 deletion packages/ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
"url": "https://github.com/coinbase/rest-hooks/issues"
},
"dependencies": {
"@babel/runtime": "^7.13.0"
"@babel/runtime": "^7.17.0",
"core-js": "^3.17.0"
},
"peerDependencies": {
"@rest-hooks/react": "^0.1.0 || ^0.2.0 || ^6.0.0 || ^7.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/ssr/src/nextjs/RestHooksDocument.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Document, {
DocumentContext,
DocumentInitialProps,
} from 'next/document.js';
import 'core-js/es/object/has-own';

import createPersistedStore from '../createPersistedStore.js';
import createServerDataComponent from '../createServerDataComponent.js';
Expand Down
5 changes: 3 additions & 2 deletions packages/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@
"url": "https://github.com/coinbase/rest-hooks/issues"
},
"dependencies": {
"@babel/runtime": "^7.13.0",
"@testing-library/react-hooks": "~8.0.0"
"@babel/runtime": "^7.17.0",
"@testing-library/react-hooks": "~8.0.0",
"core-js": "^3.17.0"
},
"peerDependencies": {
"@rest-hooks/react": "^0.2.0 || ^0.3.0 || ^1.0.0 || ^6.0.0 || ^7.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/test/src/MockResolver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '@rest-hooks/react';
import { useCallback, useContext, useMemo } from 'react';
import React from 'react';
import 'core-js/es/object/has-own';

import { Fixture, dispatchFixture } from './mockState.js';

Expand Down

0 comments on commit 14b93f6

Please sign in to comment.