Skip to content

Commit 19d0a58

Browse files
committed
chore: 📦 Remove react-scripts dependency
1 parent a237781 commit 19d0a58

File tree

5 files changed

+157
-2383
lines changed

5 files changed

+157
-2383
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
process() {
3+
// Return empty object
4+
return 'module.exports = {}'
5+
},
6+
getCacheKey() {
7+
// The output is always the same.
8+
return 'cssTransform'
9+
},
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const path = require('path')
2+
const camelcase = require('camelcase')
3+
4+
// Based on https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/config/jest/fileTransform.js
5+
6+
module.exports = {
7+
process(src, filename) {
8+
const assetFilename = JSON.stringify(path.basename(filename))
9+
10+
if (filename.match(/\.svg$/)) {
11+
// Based on how SVGR generates a component name:
12+
// https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6
13+
const pascalCaseFilename = camelcase(path.parse(filename).name, {
14+
pascalCase: true,
15+
})
16+
const componentName = `Svg${pascalCaseFilename}`
17+
return `const React = require('react')
18+
module.exports = {
19+
__esModule: true,
20+
default: ${assetFilename},
21+
ReactComponent: React.forwardRef(function ${componentName}(props, ref) {
22+
return {
23+
$$typeof: Symbol.for('react.element'),
24+
type: 'svg',
25+
ref: ref,
26+
key: null,
27+
props: Object.assign({}, props, {
28+
children: ${assetFilename}
29+
})
30+
}
31+
}),
32+
}`
33+
}
34+
35+
return `module.exports = ${assetFilename}`
36+
},
37+
}

packages/jest-config-accurapp/index.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@ module.exports = {
1414

1515
// Transform simple css files in an empty object
1616
// https://jestjs.io/docs/en/webpack.html
17-
'\\.css$': 'react-scripts/config/jest/cssTransform',
17+
'\\.css$': 'jest-config-accurapp/cssTransform',
1818

1919
// Transform all other files into just the filename string
20-
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': 'react-scripts/config/jest/fileTransform',
20+
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': 'jest-config-accurapp/fileTransform',
2121
},
2222

2323
// Don't transform css modules into an empty object
24-
transformIgnorePatterns: [
25-
'\\.module\\.(css)$',
26-
],
24+
transformIgnorePatterns: ['\\.module\\.(css)$'],
2725

2826
// Instead use identity-obj-proxy which outputs the classnames
2927
moduleNameMapper: {

packages/jest-config-accurapp/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
"dependencies": {
1818
"@babel/core": "7.9.0",
1919
"babel-jest": "25.4.0",
20+
"camelcase": "6.0.0",
2021
"identity-obj-proxy": "3.0.0",
2122
"jest": "25.4.0",
2223
"jest-environment-jsdom-sixteen": "1.0.3",
2324
"jest-watch-typeahead": "0.5.0",
24-
"react-app-polyfill": "1.0.6",
25-
"react-scripts": "3.4.1"
25+
"react-app-polyfill": "1.0.6"
2626
}
27-
}
27+
}

0 commit comments

Comments
 (0)