Skip to content

Commit

Permalink
Fix CI (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
72636c authored Sep 6, 2022
1 parent 3f57b5d commit 43b9ebd
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 200 deletions.
21 changes: 21 additions & 0 deletions .changeset/red-apples-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'skuba': patch
---

deps: Drop `package-json`

This circumvents the [following TypeScript compilation error](https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/62111) on a clean install:

```console
Error: node_modules/@types/cacheable-request/index.d.ts(0,0): error TS2709: Cannot use namespace 'ResponseLike' as a type.
```

If you run into this issue elsewhere in your project, you can temporarily work around it with a [resolution](https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/) in your `package.json`:

```json
{
"resolutions": {
"@types/responselike": "1.0.0"
}
}
```
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"normalize-package-data": "^4.0.0",
"npm-run-path": "^4.0.1",
"npm-which": "^3.0.1",
"package-json": "^7.0.0",
"picomatch": "^2.2.2",
"prettier": "~2.7.0",
"read-pkg-up": "^7.0.1",
Expand All @@ -50,7 +49,8 @@
"ts-node-dev": "^2.0.0",
"tsconfig-paths": "^4.0.0",
"tsconfig-seek": "1.0.2",
"typescript": "~4.8.2"
"typescript": "~4.8.2",
"validate-npm-package-name": "^4.0.0"
},
"description": "SEEK development toolkit for backend applications and packages",
"devDependencies": {
Expand All @@ -66,6 +66,7 @@
"@types/npm-which": "3.0.1",
"@types/picomatch": "2.3.0",
"@types/supertest": "2.0.12",
"@types/validate-npm-package-name": "4.0.0",
"enhanced-resolve": "5.10.0",
"express": "4.18.1",
"jsonfile": "6.1.0",
Expand Down
36 changes: 33 additions & 3 deletions src/utils/version.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,45 @@
import packageJson from 'package-json';
import path from 'path';

import validatePackageName from 'validate-npm-package-name';

import { getSkubaManifest } from './manifest';
import { isObject } from './validation';
import { withTimeout } from './wait';

const loadPackageJson = async (
packageName: string,
): Promise<Record<string, unknown>> => {
const { validForNewPackages } = validatePackageName(packageName);

if (!validForNewPackages) {
throw new Error(`Package "${packageName}" does not have a valid name`);
}

const message = `Package "${packageName}" does not have a valid package.json manifest`;

let packageJson: unknown;
try {
packageJson = await import(path.posix.join(packageName, 'package.json'));
} catch {
throw new Error(message);
}

if (!isObject(packageJson)) {
throw new Error(message);
}

return packageJson;
};

export const latestNpmVersion = async (
packageName: string,
): Promise<string> => {
const { version } = await packageJson(packageName);
const { version } = await loadPackageJson(packageName);

if (typeof version !== 'string') {
throw new Error(`No version found for package "${packageName}"`);
throw new Error(
`Package "${packageName}" does not have a valid version in its package.json manifest`,
);
}

return version;
Expand Down
3 changes: 3 additions & 0 deletions template/lambda-sqs-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
},
"license": "UNLICENSED",
"private": true,
"resolutions": {
"@types/responselike": "1.0.0"
},
"scripts": {
"build": "skuba build",
"deploy": "serverless deploy --force --verbose",
Expand Down
Loading

0 comments on commit 43b9ebd

Please sign in to comment.