Skip to content

Commit 77b039b

Browse files
committed
fix(package) Refactoring for use in current node version
1 parent 0ee2912 commit 77b039b

18 files changed

Lines changed: 1322 additions & 1359 deletions

__tests__/components/svg-filters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import { render, unmountComponentAtNode } from 'react-dom'
3-
import Filter from '../../src/components/svg-filters'
3+
import Filter from '../../src/components/svg-filters.js'
44
import React from 'react'
55
import { act } from 'react-dom/test-utils'
66

__tests__/hooks/useIntersectionObserver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import { render, unmountComponentAtNode } from 'react-dom'
3-
import useIntersectionObserver, { ExtendedIntersectionObserver, observers } from '../../src/hooks/useIntersectionObserver'
3+
import useIntersectionObserver, { ExtendedIntersectionObserver, observers } from '../../src/hooks/useIntersectionObserver.js'
44
import React from 'react'
55
import { act } from 'react-dom/test-utils'
66

__tests__/hooks/useSVGMousePosition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { render, unmountComponentAtNode } from 'react-dom'
33
import React from 'react'
44
import { act } from 'react-dom/test-utils'
5-
import useSVGMousePosition from '../../src/hooks/useSVGMousePosition'
5+
import useSVGMousePosition from '../../src/hooks/useSVGMousePosition.js'
66

77
let container
88

__tests__/hooks/useScrollIntoView.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
import { render, unmountComponentAtNode } from 'react-dom'
3-
import useScrollIntoView, { TOUCH_BUTTON_ID, TOUCH_SENSITIVITY, WHEEL_BUTTON_ID } from '../../src/hooks/useScrollIntoView'
3+
import useScrollIntoView, { TOUCH_BUTTON_ID, TOUCH_SENSITIVITY, WHEEL_BUTTON_ID } from '../../src/hooks/useScrollIntoView.js'
44
import React from 'react'
55
import { act } from 'react-dom/test-utils'
6-
import { observers } from '../../src/hooks/useIntersectionObserver'
6+
import { observers } from '../../src/hooks/useIntersectionObserver.js'
77

88
const touches = jest.spyOn(TouchEvent.prototype, 'touches', 'get')
99

__tests__/lib/intersectionObserver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import IntersectionObserver from '../../src/lib/intersectionObserver'
2+
import IntersectionObserver from '../../src/lib/intersectionObserver.js'
33

44
const elements = [{ id: 'element-1' }, { id: 'element-2' }, { id: 'element-3' }]
55
const callback = jest.fn((entries, observer) => callbackReturnValues.push({ entries, observer }))

__tests__/lib/task.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import task from '../../src/lib/task'
2+
import task from '../../src/lib/task.js'
33

44
describe('raf', () => {
55
it('should stub window.requestAnimationFrame() and window.cancelAnimationFrame()', () => {

babel.config.cjs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11

2-
module.exports = {
3-
exclude: /node_modules/,
4-
presets: [
5-
['@babel/preset-env', {
6-
corejs: '3.8',
7-
targets: { node: 'current' },
8-
useBuiltIns: 'usage',
9-
}],
10-
['@babel/preset-react'],
11-
],
2+
const { dependencies } = require('./package.json')
3+
const presetEnv = { corejs: dependencies['core-js'], useBuiltIns: 'usage' }
4+
const presets = [['@babel/preset-env', presetEnv], ['@babel/preset-react']]
5+
6+
module.exports = api => {
7+
8+
const env = api.env()
9+
10+
if (env === 'browser' || env === 'development') {
11+
presetEnv.targets = { esmodules: true }
12+
} else {
13+
presetEnv.targets = { node: true }
14+
}
15+
16+
if (env === 'browser') {
17+
return { exclude: /core-js/, presets }
18+
}
19+
20+
return { exclude: /node_modules/, presets }
1221
}

package-lock.json

Lines changed: 1228 additions & 1239 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"version": "0.9.1",
1111
"engines": {
12-
"node": ">= 14"
12+
"node": ">= 15"
1313
},
1414
"homepage": "https://github.com/creativewave/react-utils",
1515
"bugs": "https://github.com/creativewave/react-utils/issues",
@@ -18,14 +18,18 @@
1818
"test": "__tests__"
1919
},
2020
"files": [
21-
"dist"
21+
"dist",
22+
"src"
2223
],
2324
"type": "module",
24-
"main": "dist/es/index.js",
25-
"unpkg": "dist/umd/react-utils.min.js",
25+
"exports": {
26+
".": "./src/index.js",
27+
"./package.json": "./package.json"
28+
},
29+
"unpkg": "dist/react-utils.js",
2630
"scripts": {
2731
"prebuild": "rm -rf dist",
28-
"build": "rollup -c",
32+
"build": "rollup -c --environment NODE_ENV:browser",
2933
"lint": "eslint src __tests__",
3034
"safe-publish": "npm run lint && npm run test && npm run build && npm publish",
3135
"test": "jest",
@@ -34,21 +38,19 @@
3438
"test:watch": "jest --watchAll -b"
3539
},
3640
"dependencies": {
37-
"@babel/runtime": "^7.12.5",
3841
"core-js": "^3.8.3"
3942
},
4043
"devDependencies": {
41-
"@babel/core": "^7.12.10",
42-
"@babel/eslint-parser": "^7.12.1",
43-
"@babel/plugin-transform-runtime": "^7.12.10",
44-
"@babel/preset-env": "^7.12.11",
45-
"@babel/preset-react": "^7.12.10",
44+
"@babel/core": "^7.12.16",
45+
"@babel/eslint-parser": "^7.12.16",
46+
"@babel/preset-env": "^7.12.16",
47+
"@babel/preset-react": "^7.12.13",
4648
"@cdoublev/eslint-config": "^0.8.2",
47-
"@rollup/plugin-babel": "^5.2.2",
48-
"@rollup/plugin-commonjs": "^17.0.0",
49-
"@rollup/plugin-node-resolve": "^11.1.0",
49+
"@rollup/plugin-babel": "^5.2.3",
50+
"@rollup/plugin-commonjs": "^17.1.0",
51+
"@rollup/plugin-node-resolve": "^11.1.1",
5052
"@rollup/plugin-replace": "^2.3.4",
51-
"eslint": "^7.18.0",
53+
"eslint": "^7.20.0",
5254
"eslint-plugin-compat": "^3.9.0",
5355
"eslint-plugin-jest": "^24.1.3",
5456
"eslint-plugin-react": "^7.22.0",
@@ -58,14 +60,14 @@
5860
"prop-types": "^15.7.2",
5961
"react": "^17.0.1",
6062
"react-dom": "^17.0.1",
61-
"rollup": "^2.38.1",
63+
"rollup": "^2.39.0",
6264
"rollup-plugin-terser": "^7.0.2"
6365
},
6466
"peerDependencies": {
6567
"react": "^16.7.0-alpha.0 || ^17.0.0-rc.2"
6668
},
6769
"optionalDependencies": {
68-
"@cdoublev/animate": "^0.4.0"
70+
"@cdoublev/animate": "^0.5.0"
6971
},
7072
"publishConfig": {
7173
"access": "public"

rollup.config.js

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,28 @@
22
import babel from '@rollup/plugin-babel'
33
import commonjs from '@rollup/plugin-commonjs'
44
import nodeResolve from '@rollup/plugin-node-resolve'
5-
import pkg from './package.json'
65
import replace from '@rollup/plugin-replace'
76
import { terser } from 'rollup-plugin-terser'
7+
import { unpkg } from './package.json'
88

9-
const browserExternals = Object.keys({
10-
...pkg.optionalDependencies,
11-
...pkg.peerDependencies,
12-
}).concat('prop-types')
13-
const buildExternals = browserExternals.concat(Object.keys(pkg.dependencies))
14-
const buildExternalRegexp = new RegExp(`^(${buildExternals.join('|')})`)
15-
const browserExternalRegexp = new RegExp(`^(${browserExternals.join('|')})`)
16-
17-
const replaceEnv = replace({ 'process.env.NODE_ENV': process.env.NODE_ENV })
18-
19-
const getBabelConfig = targets => ({
20-
babelHelpers: 'runtime',
21-
exclude: /node_modules/,
22-
plugins: ['@babel/plugin-transform-runtime'],
23-
presets: [
24-
['@babel/preset-env', {
25-
corejs: '3.8',
26-
// debug: true,
27-
targets,
28-
useBuiltIns: 'usage',
29-
}],
30-
'@babel/preset-react',
31-
]
32-
})
33-
34-
export default [
35-
{
36-
external: id => buildExternalRegexp.test(id),
37-
input: 'src/index.js',
38-
output: {
39-
file: pkg.main,
40-
format: 'es',
41-
},
42-
plugins: [replaceEnv, babel(getBabelConfig({ esmodules: true }))],
43-
},
44-
{
45-
external: id => browserExternalRegexp.test(id),
46-
input: 'src/index.js',
47-
output: {
48-
file: pkg.unpkg,
49-
format: 'umd',
50-
globals: {
51-
'@cdoublev/animate': 'animate',
52-
'prop-types': 'PropTypes',
53-
'react': 'React',
54-
'react-dom': 'ReactDOM',
55-
},
56-
name: 'ReactUtils',
9+
export default {
10+
external: ['@cdoublev/animate', 'react', 'prop-types'],
11+
input: 'src/index.js',
12+
output: {
13+
file: unpkg,
14+
format: 'umd',
15+
globals: {
16+
'@cdoublev/animate': 'animate',
17+
'prop-types': 'PropTypes',
18+
'react': 'React',
5719
},
58-
plugins: [
59-
replaceEnv,
60-
nodeResolve(),
61-
babel(getBabelConfig('defaults')),
62-
commonjs(),
63-
terser(),
64-
],
20+
name: 'ReactUtils',
6521
},
66-
]
22+
plugins: [
23+
replace({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) }),
24+
nodeResolve(),
25+
babel({ babelHelpers: 'bundled' }),
26+
commonjs(),
27+
terser(),
28+
],
29+
}

0 commit comments

Comments
 (0)