Skip to content

Migrate to Jest 17, ESM, and config packages #944

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

Merged
merged 1 commit into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 0 additions & 6 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,3 @@
# Configuration
/config

# These have their own config files (not overrides)
/common/*
/exercises/*

# typescript-eslint can't lint correctly files in a project without extension
/scripts/*
11 changes: 1 addition & 10 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2020,
"sourceType": "module"
},
"extends": "@exercism/eslint-config-typescript",
"env": {
"jest": true
},
"overrides": [
{
"files": ["**/.meta/proof.ci.ts", "**/.meta/exemplar.ts", "**/*.test.ts"],
"files": [".meta/proof.ci.ts", ".meta/exemplar.ts", "*.test.ts"],
"excludedFiles": ["custom.test.ts"],
"extends": "@exercism/eslint-config-typescript/maintainers"
}
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/action-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ jobs:

- name: 'Format code'
run: ./bin/format.sh
env:
EXERCISM_PRETTIER_VERSION: '2.3.2'

- name: 'Commit formatted code'
run: |
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/verify-code-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ jobs:

- name: 'Verify formatting of all files'
run: ./bin/check-formatting.sh
env:
EXERCISM_PRETTIER_VERSION: '2.3.2'
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
/.github/workflows/sync-labels.yml
exercises/**/README.md
!/README.md

# These are formatted via configlet and will not match prettier
exercises/**/.meta/config.json
4 changes: 4 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
presets: ['@exercism/babel-preset-typescript'],
plugins: [],
}
20 changes: 0 additions & 20 deletions babel.config.js

This file was deleted.

24 changes: 24 additions & 0 deletions bin/check-formatting.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
#!/bin/bash

if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
echo "Pulling prettier version from package.json"
EXERCISM_PRETTIER_VERSION=$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')
fi

if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
echo "---------------------------------------------------"
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
echo "---------------------------------------------------"
echo "This is what yarn list reports:"
echo "$(yarn list --pattern prettier)"
echo ""
echo "This is the version that can be extracted:"
echo "$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')"
echo ""
echo "These files are found in the repo root:"
echo "$(ls -p | grep -v /)"
echo "---------------------------------------------------"
exit 1
else
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
fi

npx "prettier@$EXERCISM_PRETTIER_VERSION" --check "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"
24 changes: 21 additions & 3 deletions bin/format.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
#!/usr/bin/env bash

if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
echo "Please see https://github.com/exercism/v3/blob/master/docs/maintainers/style-guide.md for guidance."
exit 1
echo "Pulling prettier version from package.json"
EXERCISM_PRETTIER_VERSION=$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')
fi

if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
echo "---------------------------------------------------"
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
echo "---------------------------------------------------"
echo "This is what yarn list reports:"
echo "$(yarn list --pattern prettier)"
echo ""
echo "This is the version that can be extracted:"
echo "$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')"
echo ""
echo "These files are found in the repo root:"
echo "$(ls -p | grep -v /)"
echo "---------------------------------------------------"
exit 1
else
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
fi

npx "prettier@$EXERCISM_PRETTIER_VERSION" --write "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"
5 changes: 3 additions & 2 deletions common/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
node_modules/*

# Configuration files
babel.config.js
jest.config.js
.eslintrc.cjs
babel.config.cjs
jest.config.cjs
23 changes: 0 additions & 23 deletions common/.eslintrc

This file was deleted.

38 changes: 38 additions & 0 deletions common/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module.exports = {
root: true,
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
overrides: [
// Student provided files
{
files: ['*.ts'],
excludedFiles: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
extends: '@exercism/eslint-config-typescript',
},
// Exercism given tests
{
files: ['*.test.ts'],
excludedFiles: ['custom.test.ts'],
env: {
jest: true,
},
extends: '@exercism/eslint-config-typescript/maintainers',
},
// Student provided tests
{
files: ['custom.test.ts'],
env: {
jest: true,
},
extends: '@exercism/eslint-config-typescript',
},
// Exercism provided files
{
files: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
excludedFiles: ['custom.test.ts'],
extends: '@exercism/eslint-config-typescript/maintainers',
},
],
}
4 changes: 4 additions & 0 deletions common/babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
presets: ['@exercism/babel-preset-typescript'],
plugins: [],
}
20 changes: 0 additions & 20 deletions common/babel.config.js

This file was deleted.

File renamed without changes.
25 changes: 12 additions & 13 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@
"type": "git",
"url": "https://github.com/exercism/typescript"
},
"type": "module",
"engines": {
"node": "^14.13.1 || >=16.0.0"
},
"devDependencies": {
"@babel/core": "^7.16.5",
"@babel/plugin-proposal-class-properties": "^7.16.5",
"@babel/plugin-proposal-object-rest-spread": "^7.16.5",
"@babel/plugin-syntax-bigint": "^7.8.3",
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.16.5",
"@types/jest": "^26.0.24",
"@types/node": "^16.11.20",
"@exercism/babel-preset-typescript": "^0.1.0",
"@exercism/eslint-config-typescript": "^0.4.0",
"babel-jest": "^26.6.3",
"core-js": "^3.19.3",
"eslint": "^8.7.0",
"eslint-plugin-import": "^2.25.4",
"jest": "^26.6.3",
"@types/jest": "^27.4.0",
"@types/node": "^16.11.24",
"babel-jest": "^27.5.1",
"core-js": "^3.21.0",
"eslint": "^8.9.0",
"jest": "^27.5.1",
"prettier": "^2.5.1",
"typescript": "^4.5.4"
},
"scripts": {
Expand Down
23 changes: 16 additions & 7 deletions common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
{
"display": "Configuration for Node LTS",
"display": "Configuration for Exercism TypeScript Exercises",
"compilerOptions": {
"lib": ["es2020", "dom"],
"module": "commonjs",
"target": "es2020",
// Allows you to use the newest syntax, and have access to console.log
// https://www.typescriptlang.org/tsconfig#lib
"lib": ["ESNEXT", "dom"],
// Make sure typescript is configured to output ESM
// https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm
"module": "ES2020",
// Since this project is using babel, TypeScript may target something very
// high, and babel will make sure it runs on your local Node version.
// https://babeljs.io/docs/en/
"target": "ESNext", // ESLint doesn't support this yet: "es2022",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,

// Because we'll be using babel
// Ensure that Babel can safely transpile files in the TypeScript project
// Because we'll be using babel: ensure that Babel can safely transpile
// files in the TypeScript project.
//
// https://babeljs.io/docs/en/babel-plugin-transform-typescript/#caveats
"isolatedModules": true
},
"include": ["*", ".meta/*"],
"include": ["*.ts", "*.tsx", ".meta/*.ts", ".meta/*.tsx"],
"exclude": ["node_modules"]
}
5 changes: 3 additions & 2 deletions exercises/practice/accumulate/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
node_modules/*

# Configuration files
babel.config.js
jest.config.js
.eslintrc.cjs
babel.config.cjs
jest.config.cjs
23 changes: 0 additions & 23 deletions exercises/practice/accumulate/.eslintrc

This file was deleted.

38 changes: 38 additions & 0 deletions exercises/practice/accumulate/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module.exports = {
root: true,
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
overrides: [
// Student provided files
{
files: ['*.ts'],
excludedFiles: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
extends: '@exercism/eslint-config-typescript',
},
// Exercism given tests
{
files: ['*.test.ts'],
excludedFiles: ['custom.test.ts'],
env: {
jest: true,
},
extends: '@exercism/eslint-config-typescript/maintainers',
},
// Student provided tests
{
files: ['custom.test.ts'],
env: {
jest: true,
},
extends: '@exercism/eslint-config-typescript',
},
// Exercism provided files
{
files: ['.meta/proof.ci.ts', '.meta/exemplar.ts', '*.test.ts'],
excludedFiles: ['custom.test.ts'],
extends: '@exercism/eslint-config-typescript/maintainers',
},
],
}
4 changes: 4 additions & 0 deletions exercises/practice/accumulate/babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
presets: ['@exercism/babel-preset-typescript'],
plugins: [],
}
Loading