Skip to content

Commit 0535ce4

Browse files
committed
feat: added more tests
feat: moved all files to es6 modules fix: babel assertVersion asserting with new version feat: changed indent from 2 to 4 fix: disabled no-unreachable-loop, throws errors with typescript feat: added `unicorn/no-static-only-class` and `unicorn/prefer-array-flat` feat: renamed postinstall .js files to .cjs files feat: upgraded deps feat: added new rule `unicorn/prefer-switch` feat: renamed default in testing-library to dom BREAKING CHANGE: upgraded node version to v12 and es modules
1 parent 5496e0a commit 0535ce4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1049
-561
lines changed

.github/workflows/test.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,8 @@ jobs:
4444
- name: "test and coverage"
4545
run: "yarn run test:coverage"
4646

47-
- name: "test stylelint"
47+
- name: "test stylelint config"
4848
run: "yarn test:stylelint"
49+
50+
- name: "test babel config"
51+
run: "yarn test:babel"

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,5 @@ common/deploy/
108108
common/temp/
109109
common/autoinstallers/*/.npmrc
110110
**/.rush/temp/
111+
112+
/packages/babel-preset/fixture/test.js

.husky/commit-msg

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
echo --------------------------------------------
99
echo Starting Git hook: commit-msg
1010

11-
yarn commitlint --edit $1 || exit $?
11+
yarn commitlint --config ./commitlint.config.cjs --edit $1 || exit $?
1212

1313
echo Finished Git hook: commit-msg
1414
echo --------------------------------------------

.prettierrc.js .prettierrc.cjs

File renamed without changes.

babel.config.cjs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": "current",
8+
},
9+
"modules": "auto"
10+
}
11+
]
12+
],
13+
"plugins": [
14+
"transform-es2015-modules-commonjs",
15+
]
16+
};
File renamed without changes.

jest.config.cjs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
testEnvironment: 'jest-environment-node',
3+
transform: {
4+
"\\.[jt]sx?$": "babel-jest",
5+
"\\.tsx?$": "ts-jest",
6+
},
7+
verbose: true,
8+
setupFiles: ["<rootDir>/setup-tests.js"],
9+
testMatch: ["**/__tests__/**/*.[jt]s?(x)"],
10+
"transformIgnorePatterns": [
11+
"src/node_modules/(?!read-pkg-up)"
12+
],
13+
testPathIgnorePatterns: [
14+
"/node_modules/",
15+
"<rootDir>/build/"
16+
],
17+
};

jest.config.js

-7
This file was deleted.

package.json

+11-13
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,25 @@
1313
},
1414
"license": "MIT",
1515
"author": "Daniel Bannert <[email protected]>",
16+
"type": "module",
1617
"workspaces": [
1718
"packages/*"
1819
],
1920
"scripts": {
2021
"postinstall": "husky install",
21-
"jest:coverage": "jest --coverageDirectory ./coverage --coverage",
2222
"lint:staged": "lint-staged",
2323
"lint:styles": "stylelint",
2424
"lint:text": "textlint ./.build/ISSUE_TEMPLATE/** ./src/** ./docs/** ./README.md ./UPGRADE.md --dry-run",
25-
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
25+
"prettier": "prettier --config=.prettierrc.cjs --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
2626
"sort-package-json": "sort-package-json packages/**/package.json",
27-
"test": "jest",
28-
"test:coverage": "jest",
29-
"test:stylelint": "stylelint --formatter verbose --config ./packages/stylelint-config/index.js ./packages/stylelint-config/__tests__/css/**/*.css --syntax css"
30-
},
31-
"commitlint": {
32-
"extends": [
33-
"@commitlint/config-conventional"
34-
]
27+
"test": "jest --config=./jest.config.cjs",
28+
"test:coverage": "jest --config=./jest.config.cjs --coverageDirectory=./coverage --coverage",
29+
"test:stylelint": "stylelint --formatter verbose --config ./packages/stylelint-config/index.js ./packages/stylelint-config/__tests__/css/**/*.css --syntax css",
30+
"test:babel": "babel --config-file=./packages/babel-preset/index.js ./packages/babel-preset/fixture/test.ts --out-file=./packages/babel-preset/fixture/test.js"
3531
},
3632
"lint-staged": {
3733
"*.{js,jsx,less,md,json}": [
38-
"prettier --write"
34+
"prettier --config=./.prettierrc.cjs --write"
3935
]
4036
},
4137
"config": {
@@ -58,11 +54,14 @@
5854
"@textlint-rule/textlint-rule-no-invalid-control-character": "1.2.0",
5955
"@textlint-rule/textlint-rule-no-unmatched-pair": "1.0.7",
6056
"@textlint-rule/textlint-rule-preset-google": "0.1.2",
57+
"babel-jest": "^26.6.3",
6158
"commitizen": "4.2.3",
6259
"conventional-changelog-conventionalcommits": "4.5.0",
60+
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
6361
"cz-conventional-changelog": "3.3.0",
6462
"husky": "6.0.0",
6563
"jest": "26.6.3",
64+
"jest-snapshot-serializer-raw": "1.1.0",
6665
"lint-staged": "10.5.4",
6766
"prettier": "2.2.1",
6867
"pretty-quick": "3.1.0",
@@ -83,8 +82,7 @@
8382
"textlint-rule-write-good": "1.6.2",
8483
"ts-jest": "26.5.5",
8584
"typescript": "4.2.4",
86-
"write-good": "1.0.8",
87-
"jest-snapshot-serializer-raw": "1.1.0"
85+
"write-good": "1.0.8"
8886
},
8987
"devDependencies": {
9088
"@types/jest": "26.0.22",

packages/babel-preset/.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package-lock.json
22

33
src
4+
fixture
45
__tests__
56
__stories__
67
.rpt2_cache

packages/babel-preset/index.js

+44-46
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const { declare } = require("@babel/helper-plugin-utils");
2-
const isModuleAvailable = require('./lib/is-module-available');
3-
const missing = require('./lib/missing');
1+
import { declare } from '@babel/helper-plugin-utils';
2+
import isModuleAvailable from './lib/is-module-available.js';
3+
import missing from './lib/missing.js';
44

5-
module.exports = declare((api, options) => {
5+
const bable = declare((api, options) => {
66
// see docs about api at https://babeljs.io/docs/en/config-files#apicache
7-
api.assertVersion("^7.0.0");
7+
api.assertVersion('^7.13');
88

99
const {
10-
modules = "auto",
10+
modules = 'auto',
1111
targets = null,
1212
removePropTypes = false,
1313
looseClasses = false,
@@ -21,14 +21,14 @@ module.exports = declare((api, options) => {
2121
runtimeHelpersUseESModules = !modules,
2222
} = options;
2323

24-
if (typeof modules !== "undefined" && typeof modules !== "boolean" && modules !== "auto") {
24+
if (typeof modules !== 'undefined' && typeof modules !== 'boolean' && modules !== 'auto') {
2525
throw new TypeError(
2626
'@anolilab/babel-preset only accepts `true`, `false`, or `"auto"` as the value of the "modules" option',
2727
);
2828
}
2929

3030
if (removePropTypes && !react) {
31-
throw new Error('"removePropTypes" can\'t be enabled if react is disabled.')
31+
throw new Error('removePropTypes can\'t be enabled if react is disabled.')
3232
}
3333

3434
let install = []
@@ -61,62 +61,62 @@ module.exports = declare((api, options) => {
6161
missing(install)
6262
}
6363

64-
const debug = typeof options.debug === "boolean" ? options.debug : false;
64+
const debug = typeof options.debug === 'boolean' ? options.debug : false;
6565
const development =
66-
typeof options.development === "boolean"
66+
typeof options.development === 'boolean'
6767
? options.development
68-
: api.cache.using(() => process.env.NODE_ENV === "development");
68+
: process.env.NODE_ENV === 'development';
6969

7070
return {
7171
presets: [
7272
[
73-
require("@babel/preset-env"),
73+
'@babel/preset-env',
7474
{
7575
debug,
76-
exclude: ["transform-async-to-generator", "transform-regenerator"],
77-
modules: modules === false ? false : "auto",
76+
exclude: ['transform-async-to-generator', 'transform-regenerator'],
77+
modules: modules === false ? false : 'auto',
7878
targets: targets,
7979
},
8080
],
8181
typescript
8282
? [
83-
require("@babel/preset-typescript"),
83+
'@babel/preset-typescript',
8484
{
8585
allExtensions: true,
8686
isTSX: true,
8787
},
8888
]
8989
: null,
90-
react ? [require("@babel/preset-react"), { development }] : null,
90+
react ? ['@babel/preset-react', { development }] : null,
9191
].filter(Boolean),
9292
plugins: [
9393
// class { handleClick = () => { } }
9494
// Enable loose mode to use assignment instead of defineProperty
9595
// See discussion in https://github.com/facebook/create-react-app/issues/4263
9696
[
97-
require("@babel/plugin-proposal-class-properties"),
97+
'@babel/plugin-proposal-class-properties',
9898
{
9999
loose: true,
100100
},
101101
],
102102
looseClasses
103103
? [
104-
require("@babel/plugin-transform-classes"),
104+
'@babel/plugin-transform-classes',
105105
{
106106
loose: true,
107107
},
108108
]
109109
: null,
110110
[
111-
require("@babel/plugin-proposal-decorators"),
111+
'@babel/plugin-proposal-decorators',
112112
{
113113
legacy: true,
114114
},
115115
],
116116
// https://babeljs.io/docs/en/babel-plugin-transform-computed-properties#loose
117117
looseComputedProperties
118118
? [
119-
require("@babel/plugin-transform-computed-properties"),
119+
'@babel/plugin-transform-computed-properties',
120120
{
121121
loose: true,
122122
},
@@ -125,7 +125,7 @@ module.exports = declare((api, options) => {
125125
// https://babeljs.io/docs/en/babel-plugin-transform-parameters#loose
126126
looseParameters
127127
? [
128-
require("@babel/plugin-transform-parameters"),
128+
'@babel/plugin-transform-parameters',
129129
{
130130
loose: true,
131131
},
@@ -134,62 +134,58 @@ module.exports = declare((api, options) => {
134134
// https://babeljs.io/docs/en/next/babel-plugin-transform-template-literals.html#loose
135135
looseTemplateLiterals
136136
? [
137-
require("@babel/plugin-transform-template-literals"),
137+
'@babel/plugin-transform-template-literals',
138138
{
139139
loose: false,
140140
},
141141
]
142142
: null,
143143
react && removePropTypes
144144
? [
145-
require("babel-plugin-transform-react-remove-prop-types"),
145+
'babel-plugin-transform-react-remove-prop-types',
146146
Object.assign(
147147
{
148-
mode: "wrap",
149-
ignoreFilenames: ["node_modules"],
148+
mode: 'wrap',
149+
ignoreFilenames: ['node_modules'],
150150
},
151151
removePropTypes,
152152
),
153153
]
154154
: null,
155-
require('@babel/plugin-proposal-export-namespace-from'),
156-
typescript ? require("@babel/plugin-transform-typescript") : null,
155+
'@babel/plugin-proposal-export-namespace-from',
156+
typescript ? '@babel/plugin-transform-typescript' : null,
157157
// Transform dynamic import to require
158158
[
159-
require("babel-plugin-dynamic-import-node"),
159+
'babel-plugin-dynamic-import-node',
160160
{
161161
noInterop: true,
162162
},
163163
],
164-
typescript ? require('@babel/plugin-syntax-jsx') : null,
164+
typescript ? '@babel/plugin-syntax-jsx' : null,
165165
// Adds syntax support for import()
166-
require("@babel/plugin-syntax-dynamic-import"),
167-
require("@babel/plugin-transform-property-mutators"),
168-
require("@babel/plugin-transform-member-expression-literals"),
169-
require("@babel/plugin-transform-property-literals"),
170-
require("@babel/plugin-proposal-nullish-coalescing-operator"),
171-
require("@babel/plugin-proposal-numeric-separator"),
172-
require("@babel/plugin-syntax-bigin"),
173-
require("@babel/plugin-proposal-optional-catch-binding"),
174-
require("@babel/plugin-proposal-optional-chaining"),
175-
require("@babel/plugin-syntax-bigint"),
166+
'@babel/plugin-syntax-dynamic-import',
167+
'@babel/plugin-transform-property-mutators',
168+
'@babel/plugin-transform-member-expression-literals',
169+
'@babel/plugin-transform-property-literals',
170+
'@babel/plugin-proposal-nullish-coalescing-operator',
171+
'@babel/plugin-proposal-numeric-separator',
172+
'@babel/plugin-proposal-optional-catch-binding',
173+
'@babel/plugin-proposal-optional-chaining',
174+
'@babel/plugin-syntax-bigint',
176175
[
177-
require("@babel/plugin-proposal-object-rest-spread"),
176+
'@babel/plugin-proposal-object-rest-spread',
178177
{
179178
useBuiltIns: true,
180179
},
181180
],
182181
// https://babeljs.io/docs/en/babel-plugin-syntax-async-generators
183-
require("@babel/plugin-syntax-async-generators"),
184-
// fast-async is a Babel plugin that implements the ES7 keywords async and await
185-
// using syntax transformation at compile-time, rather than generators.
186-
require("fast-async"),
182+
'@babel/plugin-syntax-async-generators',
187183
// Experimental macros support. Will be documented after it's had some time
188184
// in the wild.
189-
require("babel-plugin-macros"),
185+
'babel-plugin-macros',
190186
transformRuntime
191187
? [
192-
require("@babel/plugin-transform-runtime"),
188+
'@babel/plugin-transform-runtime',
193189
{
194190
absoluteRuntime: false,
195191
corejs: false,
@@ -203,3 +199,5 @@ module.exports = declare((api, options) => {
203199
].filter(Boolean),
204200
};
205201
});
202+
203+
export default bable

packages/babel-preset/lib/is-module-available.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function isModuleAvailable(name) {
1+
export default function isModuleAvailable(name) {
22
try {
33
require.resolve(name);
44
return true;

packages/babel-preset/lib/missing.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const atLatest = (pkg) => {
99
/**
1010
* @param {Array<string>} notInstalled
1111
*/
12-
module.exports = function (notInstalled) {
12+
export default function missing (notInstalled) {
1313
const s = notInstalled.length === 1 ? '' : 's';
1414

1515
console.log(`\nOops! Something went wrong! :(

0 commit comments

Comments
 (0)