Skip to content

Commit d4028e4

Browse files
committed
Initial work to mjs, ESLint 9, and newwer jest
1 parent 8f87893 commit d4028e4

34 files changed

+7721
-12840
lines changed

.eslintignore

Lines changed: 0 additions & 16 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 14 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/node_modules
22
/bin/configlet
33
/bin/configlet.exe
4-
/pnpm-lock.yaml
4+
/package-lock.json
55
/yarn.lock

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
presets: ['@exercism/babel-preset-javascript'],
2+
presets: [['@exercism/babel-preset-javascript', { corejs: '3.38' }]],
33
plugins: [],
44
};

bin/check-formatting.sh

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,50 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
4-
echo "Pulling prettier version from package.json"
5-
EXERCISM_PRETTIER_VERSION=$(npm list prettier | grep -Po '.*\sprettier@\K.*')
3+
set -uo pipefail
4+
5+
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
6+
echo "[format] pulling prettier version from pnpm list using sed"
7+
EXERCISM_PRETTIER_VERSION="$(corepack pnpm list prettier --parseable | sed -n -e '1,$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p')"
8+
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
9+
fi
10+
11+
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
12+
echo "[format] pulling prettier version via pnpm-lock.yaml using grep"
13+
EXERCISM_PRETTIER_VERSION="$(cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+')"
14+
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
615
fi
716

8-
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
17+
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
18+
echo "Version could not be pulled using sed or grep" >&2
19+
echo ""
920
echo "---------------------------------------------------"
1021
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
1122
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
1223
echo "---------------------------------------------------"
13-
echo "This is what npm list reports:"
14-
echo "$(npm list prettier)"
24+
echo "$(corepack pnpm -v)"
25+
echo ""
26+
echo "This is what corepack pnpm list reports:"
27+
echo "$ corepack pnpm list prettier --parseable"
28+
echo "$(corepack pnpm list prettier --parseable)"
29+
echo ""
30+
echo "And corepack pnpm info reports the following:"
31+
echo "$ corepack pnpm info prettier"
32+
echo "$(corepack pnpm info prettier)"
33+
echo ""
34+
echo "This is the version that can be extracted using sed:"
35+
echo "$ corepack pnpm list prettier --parseable | sed -n -e '1,\$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p'"
36+
echo "└─ $(corepack pnpm list prettier --parseable | sed -n -e '1,$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p')"
1537
echo ""
16-
echo "This is the version that can be extracted:"
17-
echo "$(npm list prettier | grep -Po '.*\sprettier@\K.*')"
38+
echo "This is the version that can be extracted using grep:"
39+
echo "$ cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+'"
40+
echo "└─ $(cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+')"
1841
echo ""
1942
echo "These files are found in the repo root:"
2043
echo "$(ls -p | grep -v /)"
2144
echo "---------------------------------------------------"
2245
exit 1
2346
else
24-
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
47+
echo "[format] running with prettier@$EXERCISM_PRETTIER_VERSION"
2548
fi
2649

27-
npx "prettier@$EXERCISM_PRETTIER_VERSION" --check "*/**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"
50+
corepack pnpm dlx "prettier@$EXERCISM_PRETTIER_VERSION" --check "**/*.{js,jsx,cjs,mjs,ts,tsx,css,sass,scss,html,json,md,yml}"

bin/format.sh

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,50 @@
11
#!/usr/bin/env bash
22

3-
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
4-
echo "Pulling prettier version from package.json"
5-
EXERCISM_PRETTIER_VERSION=$(npm list prettier | grep -Po '.*\sprettier@\K.*')
3+
set -uo pipefail
4+
5+
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
6+
echo "[format] pulling prettier version from pnpm list using sed"
7+
EXERCISM_PRETTIER_VERSION="$(corepack pnpm list prettier --parseable | sed -n -e '1,$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p')"
8+
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
9+
fi
10+
11+
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
12+
echo "[format] pulling prettier version via pnpm-lock.yaml using grep"
13+
EXERCISM_PRETTIER_VERSION="$(cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+')"
14+
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
615
fi
716

8-
if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
17+
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
18+
echo "Version could not be pulled using sed or grep" >&2
19+
echo ""
920
echo "---------------------------------------------------"
1021
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
1122
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
1223
echo "---------------------------------------------------"
13-
echo "This is what npm list reports:"
14-
echo "$(npm list prettier)"
24+
echo "$(corepack pnpm -v)"
25+
echo ""
26+
echo "This is what corepack pnpm list reports:"
27+
echo "$ corepack pnpm list prettier --parseable"
28+
echo "$(corepack pnpm list prettier --parseable)"
29+
echo ""
30+
echo "And corepack pnpm info reports the following:"
31+
echo "$ corepack pnpm info prettier"
32+
echo "$(corepack pnpm info prettier)"
33+
echo ""
34+
echo "This is the version that can be extracted using sed:"
35+
echo "$ corepack pnpm list prettier --parseable | sed -n -e '1,\$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p'"
36+
echo "└─ $(corepack pnpm list prettier --parseable | sed -n -e '1,$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p')"
1537
echo ""
16-
echo "This is the version that can be extracted:"
17-
echo "$(npm list prettier | grep -Po '.*\sprettier@\K.*')"
38+
echo "This is the version that can be extracted using grep:"
39+
echo "$ cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+'"
40+
echo "└─ $(cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+')"
1841
echo ""
1942
echo "These files are found in the repo root:"
2043
echo "$(ls -p | grep -v /)"
2144
echo "---------------------------------------------------"
2245
exit 1
2346
else
24-
echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION"
47+
echo "[format] running with prettier@$EXERCISM_PRETTIER_VERSION"
2548
fi
2649

27-
npx "prettier@$EXERCISM_PRETTIER_VERSION" --write "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"
50+
corepack pnpm dlx "prettier@$EXERCISM_PRETTIER_VERSION" --write "**/*.{js,jsx,cjs,mjs,ts,tsx,css,sass,scss,html,json,md,yml}"

bin/generate-config-tree

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
#!/usr/bin/env node
22

3-
const { exercises } = require('../config.json')
4-
const TAG_CORE = '__core'
5-
const TAG_BONUS = '__bonus'
3+
const { exercises } = require('../config.json');
4+
const TAG_CORE = '__core';
5+
const TAG_BONUS = '__bonus';
66

77
// node inter-opt exports
8-
exports.TAG_CORE = TAG_CORE
9-
exports.TAG_BONUS = TAG_BONUS
8+
exports.TAG_CORE = TAG_CORE;
9+
exports.TAG_BONUS = TAG_BONUS;
1010

1111
exports.tree = exercises.reduce((result, exercise) => {
12-
const tag = exercise.slug
12+
const tag = exercise.slug;
1313
const item = {
1414
slug: tag,
1515
difficulty: exercise.difficulty,
16-
}
16+
};
1717

1818
if (exercise.core) {
19-
const current = result[TAG_CORE] || []
19+
const current = result[TAG_CORE] || [];
2020

2121
if (result[tag]) {
22-
console.warn(`${tag} is not ordered correctly in config.json`)
22+
console.warn(`${tag} is not ordered correctly in config.json`);
2323
}
2424

2525
return {
2626
...result,
2727
__core: current.concat([item]),
28-
[tag]: result[tag] || []
29-
}
28+
[tag]: result[tag] || [],
29+
};
3030
}
3131

32-
const parent = exercise.unlocked_by || TAG_BONUS
33-
const current = result[parent] || []
34-
return { ...result, [parent]: current.concat([item]) }
35-
}, {})
32+
const parent = exercise.unlocked_by || TAG_BONUS;
33+
const current = result[parent] || [];
34+
return { ...result, [parent]: current.concat([item]) };
35+
}, {});

bin/lint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
corepack enable pnpm
6+
corepack pnpm lint

bin/print-config-tree

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
#!/usr/bin/env node
22

3-
const actions = require('./generate-config-tree')
3+
const actions = require('./generate-config-tree');
44

5-
const { tree, TAG_BONUS, TAG_CORE } = actions
6-
const { [TAG_BONUS]: __bonus, [TAG_CORE]: __core, ...track } = tree
5+
const { tree, TAG_BONUS, TAG_CORE } = actions;
6+
const { [TAG_BONUS]: __bonus, [TAG_CORE]: __core, ...track } = tree;
77

88
function printLn(line) {
9-
process.stdout.write(`${line}\n`)
9+
process.stdout.write(`${line}\n`);
1010
}
1111

1212
function printList(items) {
13-
items.forEach(item => {
14-
printLn(`- ${item.slug} (${item.difficulty})`)
15-
})
13+
items.forEach((item) => {
14+
printLn(`- ${item.slug} (${item.difficulty})`);
15+
});
1616
}
1717

18-
printLn('Core (matches config.json) of this track:')
19-
printList(__core)
20-
printLn('\n')
21-
printLn('core')
22-
printLn('----')
23-
Object.keys(track).forEach(slug => {
24-
printLn(`├─ ${slug}`)
18+
printLn('Core (matches config.json) of this track:');
19+
printList(__core);
20+
printLn('\n');
21+
printLn('core');
22+
printLn('----');
23+
Object.keys(track).forEach((slug) => {
24+
printLn(`├─ ${slug}`);
2525
track[slug].forEach((side, index, self) => {
26-
junction = index === self.length - 1 ? '└─' : '├─'
27-
printLn(`│ ${junction} ${side.slug} (${side.difficulty})`)
28-
})
29-
printLn('│')
30-
})
26+
junction = index === self.length - 1 ? '└─' : '├─';
27+
printLn(`│ ${junction} ${side.slug} (${side.difficulty})`);
28+
});
29+
printLn('│');
30+
});
3131

32-
printLn('bonus')
33-
printLn('----')
34-
printList(__bonus)
32+
printLn('bonus');
33+
printLn('----');
34+
printList(__bonus);

eslint.config.mjs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// @ts-check
2+
3+
import config from '@exercism/eslint-config-javascript';
4+
import maintainersConfig from '@exercism/eslint-config-javascript/maintainers.mjs';
5+
6+
import globals from 'globals';
7+
8+
export default [
9+
...config,
10+
{
11+
files: ['.meta/proof.ci.js', '.meta/exemplar.js', '*.spec.js'],
12+
extends: maintainersConfig,
13+
},
14+
{
15+
files: ['scripts/**/*.mjs'],
16+
languageOptions: {
17+
globals: {
18+
...globals.node,
19+
},
20+
},
21+
},
22+
{
23+
ignores: [
24+
// # Protected or generated
25+
'/.appends/**/*',
26+
'/.github/**/*',
27+
'/.vscode/**/*',
28+
29+
// # Binaries
30+
'/bin/*',
31+
32+
// # Configuration
33+
'/config',
34+
'/babel.config.js',
35+
36+
// # Typings
37+
'/exercises/**/global.d.ts',
38+
'/exercises/**/env.d.ts',
39+
],
40+
},
41+
];

0 commit comments

Comments
 (0)