Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .husky/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

node scripts/post-checkout.mjs "$1" "$2" "$3"
1 change: 1 addition & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm typecheck --minimumFailingSeverity warning
2 changes: 0 additions & 2 deletions .remarkrc.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-check

import remarkFrontmatter from 'remark-frontmatter';
import remarkMdx from 'remark-mdx';
import remarkPresetLintRecommended from 'remark-preset-lint-recommended';
Expand Down
30 changes: 23 additions & 7 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import astro from 'eslint-plugin-astro';
import globals from 'globals';
import process from 'node:process';
import tseslint from 'typescript-eslint';

export default [
{ ignores: ['dist/', '.astro/', 'node_modules/', 'scripts/'] },
import { defineConfig } from 'eslint/config';
export default defineConfig([
{ ignores: ['dist/', '.astro/', 'node_modules/'] },

js.configs.recommended,

Expand All @@ -18,16 +21,29 @@ export default [
{ argsIgnorePattern: '^_' },
],
'@typescript-eslint/no-explicit-any': 'error',
'no-undef': 'off',
// ci runs `astro check` which runs a full typescript checker
'no-undef': process.env.CI ? 'off' : 'error',
},
},

{
files: ['**/*.astro'],
files: ['scripts/*', 'src/plugins/*'],
languageOptions: {
globals: {
// scripts and plugins run in a node env
...globals.node,
},
},
},
{
// also catch astro virtual files
files: ['**/*.astro', '**/*.astro/**/*.ts'],
languageOptions: {
globals: {
ImageMetadata: 'readonly',
},
},
rules: {
'no-undef': 'off',
},
},
];
]);
17 changes: 17 additions & 0 deletions lint-staged.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** @type {import('lint-staged').Configuration} */
export default {
'**/*': (files) => `prettier --write --ignore-unknown ${files.join(' ')}`,
'**/*.{astro,ts,mjs,js}': (files) => `eslint --fix ${files.join(' ')}`,
'src/content/**/*.{md,mdx}': (files) => [
`pnpm remark ${files.join(' ')} --ext mdx --frail --no-stdout --quiet`,
],
'examples/**/*.{java,gradle}': () => [
`./examples/gradlew -p examples spotlessApply`,
],
'src/data/glossary.ts': () => [
'pnpm generate:glossary',
'git add src/content/docs/resources/glossary.mdx',
],
// Yes, I know this should be a FunctionTask but those are kinda bad until https://github.com/lint-staged/lint-staged/issues/1826 is resolved
'package.json': () => 'pnpm tsx scripts/syncLockfile.lint.ts',
};
12 changes: 1 addition & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,12 @@
"remark-frontmatter": "^5.0.0",
"remark-lint-no-dead-urls": "^2.0.1",
"remark-mdx": "^3.1.1",
"globals": "^16.5.0",
"remark-preset-lint-recommended": "^7.0.1",
"starlight-links-validator": "^0.20.0",
"tsx": "^4.22.4",
"typescript": "^6.0.3",
"typescript-eslint": "^8.61.1",
"vfile": "^6.0.3"
},
"lint-staged": {
"**/*": [
"pnpm format",
"pnpm lint"
],
"examples/**/*.java": "sh -c 'cd examples && ./gradlew spotlessApply'",
"src/data/glossary.ts": [
"pnpm generate:glossary",
"git add src/content/docs/resources/glossary.mdx"
]
}
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions scripts/post-checkout.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env node

import { execSync } from 'node:child_process';
import { hashLockfile, readStamp } from './stamp.mjs';

function main() {
const [, , , , isBranchCheckoutArg] = process.argv;

if (isBranchCheckoutArg !== '1') {
process.exit(0);
}

const currentHash = hashLockfile();
if (!currentHash) {
process.exit(0);
}

if (currentHash === readStamp()) {
process.exit(0);
}

console.log('lockfile changed since last checkout, running `pnpm install`');

try {
execSync('pnpm install', { stdio: 'inherit' });
} catch {
console.error('pnpm install failed. retry manually.');
process.exit(1);
}
}

if (!process.env.CI) {
main();
}
22 changes: 22 additions & 0 deletions scripts/postinstall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { hashLockfile, STAMP, writeStamp } from './stamp.mjs';
import { existsSync, unlinkSync } from 'node:fs';

function updateHash(): void {
const hash = hashLockfile();
if (!hash) {
// no lockfile for some reason, remove stale stamp if it exists
if (existsSync(STAMP)) {
unlinkSync(STAMP);
}
process.exit(0);
}
writeStamp(hash);
}
// main function. put other functions in here to run on postinstall. do not put loose code in main, make your own method
function main(): void {
updateHash();
}

if (!process.env.CI) {
main();
}
27 changes: 27 additions & 0 deletions scripts/stamp.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { createHash } from 'node:crypto';
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:path';

export const LOCKFILE = resolve(process.cwd(), 'pnpm-lock.yaml');
export const STAMP = resolve(process.cwd(), 'node_modules', '.checksum.sha1');

/**
* @returns {string | null} the hash or null if the lockfile doesn't exist
*/
export function hashLockfile() {
if (!existsSync(LOCKFILE)) return null;
const contents = readFileSync(LOCKFILE);
return createHash('sha1').update(contents).digest('hex');
}
/**
* @returns {string} the hash from the stamp file, or an empty string if it doesn't exist
*/
export function readStamp() {
return existsSync(STAMP) ? readFileSync(STAMP, 'utf-8').trim() : '';
}
/**
* @param {string} hash
*/
export function writeStamp(hash) {
writeFileSync(STAMP, hash, 'utf-8');
}
13 changes: 13 additions & 0 deletions scripts/syncLockfile.lint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Script to check if pnpm-lock.yaml is in sync with package.json.
import { exec } from 'node:child_process';
import { promisify } from 'node:util';

await promisify(exec)(
// check if lockfile is in sync, don't run scripts, don't modify node_modules or lockfile
'pnpm install --frozen-lockfile --lockfile-only --ignore-scripts',
).catch(() => {
console.error(
'pnpm-lock.yaml is out of sync with package.json. Run `pnpm install` to update the lockfile.',
);
process.exit(1);
});
1 change: 0 additions & 1 deletion src/plugins/remark-no-inline-code-fences.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-check
/// <reference types="mdast-util-mdx" />
import { visit } from 'unist-util-visit';

Expand Down