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

Drop core-js in favour of custom fallbacks #1725

Merged
merged 5 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
21 changes: 17 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
'react-hooks',
'import',
'jest',
'es5',
],
env: {
es6: true,
Expand Down Expand Up @@ -62,7 +63,7 @@ module.exports = {
'no-plusplus': 'off',

// Always enforcing the use of curly braces for if statements
'curly': ['error', 'all'],
curly: ['error', 'all'],

'no-restricted-syntax': [
// Nicer booleans #1
Expand Down Expand Up @@ -102,14 +103,16 @@ module.exports = {
// No usage of `tiny-invariant`. Must use our own invariant for error flow
{
selector: 'ImportDeclaration[source.value="tiny-invariant"]',
message: 'Please use our own invariant function (src/invariant.js) to ensure correct error flow'
message:
'Please use our own invariant function (src/invariant.js) to ensure correct error flow',
},

// Must use invariant to throw
{
selector: 'ThrowStatement',
message: 'Please use invariant (src/invariant.js) for throwing. This is to ensure correct error flows'
}
message:
'Please use invariant (src/invariant.js) for throwing. This is to ensure correct error flows',
},
],

// Allowing Math.pow rather than forcing `**`
Expand Down Expand Up @@ -206,4 +209,14 @@ module.exports = {
// don't need to initialize state in a constructor
'react/state-in-constructor': 'off',
},
overrides: [
// Forbid using not es5 methods
{
files: 'src/**/*.js',
rules: {
'es5/no-es6-methods': 'error',
'es5/no-es6-static-methods': 'error',
},
},
],
};
24 changes: 12 additions & 12 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"dist/react-beautiful-dnd.js": {
"bundled": 379875,
"minified": 139571,
"gzipped": 41966
"bundled": 365453,
"minified": 134037,
"gzipped": 39824
},
"dist/react-beautiful-dnd.min.js": {
"bundled": 321489,
"minified": 115006,
"gzipped": 34084
"bundled": 307232,
"minified": 109522,
"gzipped": 31948
},
"dist/react-beautiful-dnd.esm.js": {
"bundled": 241086,
"minified": 125714,
"gzipped": 32875,
"bundled": 241497,
"minified": 125757,
"gzipped": 32899,
"treeshaked": {
"rollup": {
"code": 21306,
"import_statements": 788
"code": 21158,
"import_statements": 503
},
"webpack": {
"code": 24963
"code": 24653
}
}
}
Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
presets: ['@babel/react', '@babel/flow', ['@babel/env', { loose: true }]],
plugins: [
'@babel/transform-object-assign',
['@babel/proposal-class-properties', { loose: true }],
// used for stripping out the `invariant` messages in production builds
'dev-expression',
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"prepublishOnly": "yarn build"
},
"dependencies": {
"@babel/runtime-corejs2": "^7.6.3",
"@babel/runtime": "^7.6.3",
Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks for sorting this!

"css-box-model": "^1.2.0",
"memoize-one": "^5.1.1",
"raf-schd": "^4.0.2",
Expand All @@ -70,6 +70,7 @@
"@babel/core": "^7.6.4",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-transform-modules-commonjs": "^7.6.0",
"@babel/plugin-transform-object-assign": "^7.8.3",
Copy link
Collaborator

Choose a reason for hiding this comment

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

just to confirm - this won't polyfill, it is just ponyfill?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

"@babel/plugin-transform-runtime": "^7.6.2",
"@babel/preset-env": "^7.6.3",
"@babel/preset-flow": "^7.0.0",
Expand All @@ -96,6 +97,7 @@
"eslint-config-prettier": "^6.4.0",
"eslint-plugin-cypress": "^2.7.0",
"eslint-plugin-emotion": "^10.0.14",
"eslint-plugin-es5": "^1.4.1",
"eslint-plugin-flowtype": "^4.3.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^22.20.0",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const excludeAllExternals = id => !id.startsWith('.') && !id.startsWith('/');
const getBabelOptions = ({ useESModules }) => ({
exclude: 'node_modules/**',
runtimeHelpers: true,
plugins: [['@babel/transform-runtime', { corejs: 2, useESModules }]],
plugins: [['@babel/transform-runtime', { useESModules }]],
});

const snapshotArgs =
Expand Down
23 changes: 20 additions & 3 deletions src/native-with-fallback.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
// @flow
/* eslint-disable es5/no-es6-methods */
/* eslint-disable no-restricted-globals */

type Map<T> = {
[key: string]: T,
};

// @babel/runtime-corejs2 will replace Object.values
// Number.isInteger is not forbidden yet
// https://github.com/nkt/eslint-plugin-es5/pull/37
export function isInteger(value: mixed): boolean {
if (Number.isInteger) {
return Number.isInteger(value);
}
return (
typeof value === 'number' && isFinite(value) && Math.floor(value) === value
);
}

// Using this helper to ensure there are correct flow types
// https://github.com/facebook/flow/issues/2221
export function values<T>(map: Map<T>): T[] {
// $FlowFixMe - Object.values currently does not have good flow support
return Object.values(map);
if (Object.values) {
// $FlowFixMe - Object.values currently does not have good flow support
return Object.values(map);
}

return Object.keys(map).map(key => map[key]);
}

// Could also extend to pass index and list
Expand Down
4 changes: 2 additions & 2 deletions src/view/draggable/use-validation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import { useRef } from 'react';
import { invariant } from '../../invariant';
import { isInteger } from '../../native-with-fallback';
import type { DraggableId, ContextId } from '../../types';
import type { Props } from './draggable-types';
import checkIsValidInnerRef from '../check-is-valid-inner-ref';
Expand All @@ -21,7 +22,6 @@ export function useValidation(

// wrapping entire block for better minification
const id: ?DraggableId = props.draggableId;
// Number.isInteger will be provided by @babel/runtime-corejs2
invariant(id, 'Draggable requires a draggableId');
invariant(
typeof id === 'string',
Expand All @@ -30,7 +30,7 @@ export function useValidation(
);

invariant(
Number.isInteger(props.index),
isInteger(props.index),
`${prefix(id)} requires an integer index prop`,
);

Expand Down
1 change: 1 addition & 0 deletions src/view/use-announcer/use-announcer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function useAnnouncer(contextId: ContextId): Announce {
el.setAttribute('aria-atomic', 'true');

// hide the element visually
// eslint-disable-next-line es5/no-es6-static-methods
Object.assign(el.style, visuallyHidden);

// Add to body
Expand Down
2 changes: 1 addition & 1 deletion src/view/use-lift-instruction/use-lift-instruction.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function useLiftInstruction(

// Using `display: none` prevent screen readers from reading this element in the document flow
// This element is used as a `aria-labelledby` reference for *other elements* and will be read out for those
Object.assign(el.style, { display: 'none' });
el.style.display = 'none';

// Add to body
getBodyElement().appendChild(el);
Expand Down
34 changes: 25 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz#bbb3fbee98661c569034237cc03967ba99b4f250"
integrity sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA==

"@babel/helper-plugin-utils@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.8.3.tgz#9ea293be19babc0f52ff8ca88b34c3611b208670"
integrity sha512-j+fq49Xds2smCUNYmEHF9kGNkhbet6yVIBp4e6oeQpH1RUs/Ir06xUKzDjDkGcaaokPiTNs2JBWHjaE4csUkZQ==

"@babel/helper-regex@^7.0.0", "@babel/helper-regex@^7.4.4":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/helper-regex/-/helper-regex-7.5.5.tgz#0aa6824f7100a2e0e89c1527c23936c152cab351"
Expand Down Expand Up @@ -633,6 +638,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.0.0"

"@babel/plugin-transform-object-assign@^7.8.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-object-assign/-/plugin-transform-object-assign-7.8.3.tgz#dc3b8dd50ef03837868a37b7df791f64f288538e"
integrity sha512-i3LuN8tPDqUCRFu3dkzF2r1Nx0jp4scxtm7JxtIqI9he9Vk20YD+/zshdzR9JLsoBMlJlNR82a62vQExNEVx/Q==
dependencies:
"@babel/helper-plugin-utils" "^7.8.3"

"@babel/plugin-transform-object-super@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-object-super/-/plugin-transform-object-super-7.5.5.tgz#c70021df834073c65eb613b8679cc4a381d1a9f9"
Expand Down Expand Up @@ -992,14 +1004,6 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-transform-typescript" "^7.6.0"

"@babel/runtime-corejs2@^7.6.3":
version "7.6.3"
resolved "https://registry.yarnpkg.com/@babel/runtime-corejs2/-/runtime-corejs2-7.6.3.tgz#de3f446b3fb688b98cbd220474d1a7cad909bcb8"
integrity sha512-nuA2o+rgX2+PrNTZ063ehncVcg7sn+tU71BB81SaWRVUbGwCOlb0+yQA1e0QqmzOfRSYOxfvf8cosYqFbJEiwQ==
dependencies:
core-js "^2.6.5"
regenerator-runtime "^0.13.2"

"@babel/runtime@7.3.4":
version "7.3.4"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.3.4.tgz#73d12ba819e365fcf7fd152aed56d6df97d21c83"
Expand All @@ -1021,6 +1025,13 @@
dependencies:
regenerator-runtime "^0.13.2"

"@babel/runtime@^7.6.3":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.8.3.tgz#0811944f73a6c926bb2ad35e918dcc1bfab279f1"
integrity sha512-fVHx1rzEmwB130VTkLnxR+HmxcTjGzH12LYQcFFoBwakMd3aOMD4OsRN7tGG/UOYE2ektgFrS8uACAoRk1CY0w==
dependencies:
regenerator-runtime "^0.13.2"

"@babel/template@^7.1.0", "@babel/template@^7.4.0", "@babel/template@^7.4.4", "@babel/template@^7.6.0":
version "7.6.0"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.6.0.tgz#7f0159c7f5012230dad64cca42ec9bdb5c9536e6"
Expand Down Expand Up @@ -4048,7 +4059,7 @@ core-js@^1.0.0:
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
integrity sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=

core-js@^2.4.0, core-js@^2.4.1, core-js@^2.6.5:
core-js@^2.4.0, core-js@^2.4.1:
version "2.6.9"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.9.tgz#6b4b214620c834152e179323727fc19741b084f2"
integrity sha512-HOpZf6eXmnl7la+cUdMnLvUxKNqLUzJvgIziQ0DiF3JwSImNphIqdGqzj6hIKyX04MmV0poclQ7+wjWvxQyR2A==
Expand Down Expand Up @@ -5063,6 +5074,11 @@ eslint-plugin-emotion@^10.0.14:
resolved "https://registry.yarnpkg.com/eslint-plugin-emotion/-/eslint-plugin-emotion-10.0.14.tgz#c643ff2f34f85ae77a65b2056915e939cf7e8129"
integrity sha512-kI0hTPA5oo7MAc2YcdF1JcT36TZ1Ci0S5sbA9aojZ3leEPyCH34YBB76/8NQ3/9gybqrekIEuEhr8MP6JZf95Q==

eslint-plugin-es5@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-es5/-/eslint-plugin-es5-1.4.1.tgz#258fe89bc5f72fbd9f5f7936c840151766821f1e"
integrity sha512-kktkmkF2O7pnSZYgrMiYMbt3wCKRIiXePwILv8USDG95YgP0PzhIxSIROLLKmiQQ/Z6LuhDGWTHK04gnbXBvkg==

eslint-plugin-flowtype@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-4.3.0.tgz#06d0837ac341caf369e7e6dbb112dd7fd21acf17"
Expand Down