Skip to content

Commit

Permalink
Initial work to mjs, ESLint 9, and newwer jest
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessByte committed Oct 18, 2024
1 parent 8f87893 commit d4028e4
Show file tree
Hide file tree
Showing 34 changed files with 7,721 additions and 12,840 deletions.
16 changes: 0 additions & 16 deletions .eslintignore

This file was deleted.

14 changes: 0 additions & 14 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/node_modules
/bin/configlet
/bin/configlet.exe
/pnpm-lock.yaml
/package-lock.json
/yarn.lock
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
presets: ['@exercism/babel-preset-javascript'],
presets: [['@exercism/babel-preset-javascript', { corejs: '3.38' }]],
plugins: [],
};
45 changes: 34 additions & 11 deletions bin/check-formatting.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
#!/bin/bash
#!/usr/bin/env bash

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

if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
echo "[format] pulling prettier version from pnpm list using sed"
EXERCISM_PRETTIER_VERSION="$(corepack pnpm list prettier --parseable | sed -n -e '1,$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p')"
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
fi

if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
echo "[format] pulling prettier version via pnpm-lock.yaml using grep"
EXERCISM_PRETTIER_VERSION="$(cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+')"
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
fi

if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
echo "Version could not be pulled using sed or grep" >&2
echo ""
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 npm list reports:"
echo "$(npm list prettier)"
echo "$(corepack pnpm -v)"
echo ""
echo "This is what corepack pnpm list reports:"
echo "$ corepack pnpm list prettier --parseable"
echo "$(corepack pnpm list prettier --parseable)"
echo ""
echo "And corepack pnpm info reports the following:"
echo "$ corepack pnpm info prettier"
echo "$(corepack pnpm info prettier)"
echo ""
echo "This is the version that can be extracted using sed:"
echo "$ corepack pnpm list prettier --parseable | sed -n -e '1,\$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p'"
echo "└─ $(corepack pnpm list prettier --parseable | sed -n -e '1,$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p')"
echo ""
echo "This is the version that can be extracted:"
echo "$(npm list prettier | grep -Po '.*\sprettier@\K.*')"
echo "This is the version that can be extracted using grep:"
echo "$ cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+'"
echo "└─ $(cat pnpm-lock.yaml | grep -Po ' prettier@\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"
echo "[format] running with prettier@$EXERCISM_PRETTIER_VERSION"
fi

npx "prettier@$EXERCISM_PRETTIER_VERSION" --check "*/**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"
corepack pnpm dlx "prettier@$EXERCISM_PRETTIER_VERSION" --check "**/*.{js,jsx,cjs,mjs,ts,tsx,css,sass,scss,html,json,md,yml}"
43 changes: 33 additions & 10 deletions bin/format.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
#!/usr/bin/env bash

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

if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
echo "[format] pulling prettier version from pnpm list using sed"
EXERCISM_PRETTIER_VERSION="$(corepack pnpm list prettier --parseable | sed -n -e '1,$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p')"
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
fi

if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
echo "[format] pulling prettier version via pnpm-lock.yaml using grep"
EXERCISM_PRETTIER_VERSION="$(cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+')"
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
fi

if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
echo "Version could not be pulled using sed or grep" >&2
echo ""
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 npm list reports:"
echo "$(npm list prettier)"
echo "$(corepack pnpm -v)"
echo ""
echo "This is what corepack pnpm list reports:"
echo "$ corepack pnpm list prettier --parseable"
echo "$(corepack pnpm list prettier --parseable)"
echo ""
echo "And corepack pnpm info reports the following:"
echo "$ corepack pnpm info prettier"
echo "$(corepack pnpm info prettier)"
echo ""
echo "This is the version that can be extracted using sed:"
echo "$ corepack pnpm list prettier --parseable | sed -n -e '1,\$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p'"
echo "└─ $(corepack pnpm list prettier --parseable | sed -n -e '1,$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p')"
echo ""
echo "This is the version that can be extracted:"
echo "$(npm list prettier | grep -Po '.*\sprettier@\K.*')"
echo "This is the version that can be extracted using grep:"
echo "$ cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+'"
echo "└─ $(cat pnpm-lock.yaml | grep -Po ' prettier@\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"
echo "[format] running with prettier@$EXERCISM_PRETTIER_VERSION"
fi

npx "prettier@$EXERCISM_PRETTIER_VERSION" --write "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}"
corepack pnpm dlx "prettier@$EXERCISM_PRETTIER_VERSION" --write "**/*.{js,jsx,cjs,mjs,ts,tsx,css,sass,scss,html,json,md,yml}"
30 changes: 15 additions & 15 deletions bin/generate-config-tree
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
#!/usr/bin/env node

const { exercises } = require('../config.json')
const TAG_CORE = '__core'
const TAG_BONUS = '__bonus'
const { exercises } = require('../config.json');
const TAG_CORE = '__core';
const TAG_BONUS = '__bonus';

// node inter-opt exports
exports.TAG_CORE = TAG_CORE
exports.TAG_BONUS = TAG_BONUS
exports.TAG_CORE = TAG_CORE;
exports.TAG_BONUS = TAG_BONUS;

exports.tree = exercises.reduce((result, exercise) => {
const tag = exercise.slug
const tag = exercise.slug;
const item = {
slug: tag,
difficulty: exercise.difficulty,
}
};

if (exercise.core) {
const current = result[TAG_CORE] || []
const current = result[TAG_CORE] || [];

if (result[tag]) {
console.warn(`${tag} is not ordered correctly in config.json`)
console.warn(`${tag} is not ordered correctly in config.json`);
}

return {
...result,
__core: current.concat([item]),
[tag]: result[tag] || []
}
[tag]: result[tag] || [],
};
}

const parent = exercise.unlocked_by || TAG_BONUS
const current = result[parent] || []
return { ...result, [parent]: current.concat([item]) }
}, {})
const parent = exercise.unlocked_by || TAG_BONUS;
const current = result[parent] || [];
return { ...result, [parent]: current.concat([item]) };
}, {});
6 changes: 6 additions & 0 deletions bin/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -euo pipefail

corepack enable pnpm
corepack pnpm lint
44 changes: 22 additions & 22 deletions bin/print-config-tree
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
#!/usr/bin/env node

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

const { tree, TAG_BONUS, TAG_CORE } = actions
const { [TAG_BONUS]: __bonus, [TAG_CORE]: __core, ...track } = tree
const { tree, TAG_BONUS, TAG_CORE } = actions;
const { [TAG_BONUS]: __bonus, [TAG_CORE]: __core, ...track } = tree;

function printLn(line) {
process.stdout.write(`${line}\n`)
process.stdout.write(`${line}\n`);
}

function printList(items) {
items.forEach(item => {
printLn(`- ${item.slug} (${item.difficulty})`)
})
items.forEach((item) => {
printLn(`- ${item.slug} (${item.difficulty})`);
});
}

printLn('Core (matches config.json) of this track:')
printList(__core)
printLn('\n')
printLn('core')
printLn('----')
Object.keys(track).forEach(slug => {
printLn(`├─ ${slug}`)
printLn('Core (matches config.json) of this track:');
printList(__core);
printLn('\n');
printLn('core');
printLn('----');
Object.keys(track).forEach((slug) => {
printLn(`├─ ${slug}`);
track[slug].forEach((side, index, self) => {
junction = index === self.length - 1 ? '└─' : '├─'
printLn(`│ ${junction} ${side.slug} (${side.difficulty})`)
})
printLn('│')
})
junction = index === self.length - 1 ? '└─' : '├─';
printLn(`│ ${junction} ${side.slug} (${side.difficulty})`);
});
printLn('│');
});

printLn('bonus')
printLn('----')
printList(__bonus)
printLn('bonus');
printLn('----');
printList(__bonus);
41 changes: 41 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// @ts-check

import config from '@exercism/eslint-config-javascript';
import maintainersConfig from '@exercism/eslint-config-javascript/maintainers.mjs';

import globals from 'globals';

export default [
...config,
{
files: ['.meta/proof.ci.js', '.meta/exemplar.js', '*.spec.js'],
extends: maintainersConfig,
},
{
files: ['scripts/**/*.mjs'],
languageOptions: {
globals: {
...globals.node,
},
},
},
{
ignores: [
// # Protected or generated
'/.appends/**/*',
'/.github/**/*',
'/.vscode/**/*',

// # Binaries
'/bin/*',

// # Configuration
'/config',
'/babel.config.js',

// # Typings
'/exercises/**/global.d.ts',
'/exercises/**/env.d.ts',
],
},
];
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
verbose: true,
modulePathIgnorePatterns: ['package.json'],
transform: {
'^.+\\.[t|j]sx?$': 'babel-jest',
},
reporters: [],
};
Loading

0 comments on commit d4028e4

Please sign in to comment.