Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
fix: Stop fresh builds from failing (#81)
Browse files Browse the repository at this point in the history
* chore: Reenable package-lock.json

We really need some kind of lock for this (looks like we're aligning on
npm anyway), since master is currently completely unable to be compiled
due to lots of minor patches that have bitrotted the codebase.

I'm now going to try and fix all the issues so this is a standard,
compiling state to actually work from.

* fix: Correct the unknown error issues

Using instanceof since we know what the thrown error should be.

* fix: Tests now pass as expected

* fix: Lowest version we support is v14.0

While this is possibly controversial, v12 goes EOL in about a month, so
might as well set v14 as the baseline, which makes our lives a little
bit easier.

* feat: Use npm ci instead of npm i

Since we have a package-lock.json, we can download the dependencies much
faster with ci.

* feat: Hopefully improve cache performance

Done based on
https://www.voorhoede.nl/en/blog/super-fast-npm-install-on-github-actions/#fn1

* chore: update package-lock.json

* chore: remove type cast

* chore: rename variable to be more descriptive

* ci: ensure postinstall is run for patch-package

* ci: revert to state from main

Co-authored-by: Nathan Smyth <nathan.smyth@mongodb.com>
Co-authored-by: Stephan Meijer <stephan.meijer@gmail.com>
  • Loading branch information
3 people committed May 1, 2022
1 parent 21ac25e commit b81ce0b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -87,5 +87,8 @@
"hooks": {
"pre-commit": "lint-staged"
}
},
"engines": {
"node": ">=14.0.0"
}
}
4 changes: 4 additions & 0 deletions src/cache.ts
Expand Up @@ -57,6 +57,10 @@ export class InvalidCacheError extends Error {
this.name = 'InvalidCacheError';
this.path = path;
}

static wrap(e: Error, path: string): InvalidCacheError {
return new InvalidCacheError(e.message, path);
}
}

export async function resolveEntry<T>(
Expand Down
21 changes: 10 additions & 11 deletions src/index.ts
Expand Up @@ -274,21 +274,20 @@ export async function main(args: CliArguments): Promise<void> {
} catch (error) {
spinner.stop();

if (!(error instanceof Error)) {
console.error(`something weird happened: ${error}`);
process.exit(1);
}

// console.log is intercepted for output comparison, this helps debugging
if (process.env.NODE_ENV === 'test') {
if (process.env.NODE_ENV === 'test' && error instanceof Error) {
console.log(error.message);
}

console.error(
chalk.redBright(
error['path'] ? `\nFailed parsing ${error['path']}` : error.message,
),
);
if (error instanceof InvalidCacheError) {
console.error(chalk.redBright(`\nFailed parsing ${error['path']}`));
} else if (error instanceof Error) {
console.error(chalk.redBright(error.message));
} else {
// Who knows what this is, hopefully the .toString() is meaningful
console.error(`Unexpected value thrown: ${error}`);
}

process.exit(1);
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/traverse.ts
Expand Up @@ -13,7 +13,12 @@ import type {
} from '@typescript-eslint/types/dist/ast-spec';
import resolve from 'resolve';
import removeFlowTypes from 'flow-remove-types';
import { invalidateEntries, invalidateEntry, resolveEntry } from './cache';
import {
invalidateEntries,
invalidateEntry,
InvalidCacheError,
resolveEntry,
} from './cache';
import { log } from './log';
import { MapLike } from 'typescript';

Expand Down Expand Up @@ -357,8 +362,8 @@ export async function traverse(
});
}

if (error instanceof Error && !error['path']) {
error['path'] = path;
if (error instanceof Error && !(error instanceof InvalidCacheError)) {
throw InvalidCacheError.wrap(error, path);
}

throw error;
Expand Down

0 comments on commit b81ce0b

Please sign in to comment.