Skip to content

Commit

Permalink
add missing awaits for getPackageVersion calls (#317)
Browse files Browse the repository at this point in the history
* add missing await for Relevant Packages info

* add eslint rules to help with Promises & Async/Await
  • Loading branch information
dario-piotrowicz authored Jun 22, 2023
1 parent cad492b commit b1c3a33
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-ducks-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudflare/next-on-pages': patch
---

fix --info showing [object Promise] for relevant packages instead of their versions
5 changes: 5 additions & 0 deletions .changeset/pink-actors-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudflare/next-on-pages': patch
---

fix vercel command not found issue
35 changes: 21 additions & 14 deletions internal-packages/eslint-config-next-on-pages/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
module.exports = {
"env": {
"es2021": true,
"node": true
env: {
es2021: true,
node: true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
"project": true
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
overrides: [],
parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: "module",
project: true
},
"plugins": ["@typescript-eslint"],
"rules": {
plugins: ["@typescript-eslint"],
rules: {
"no-case-declarations": "error",
"no-console": "error",
"prefer-const": "error",
"no-mixed-spaces-and-tabs": "off", // off because it conflicts with prettier
"eqeqeq": "error",

"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/consistent-type-imports": "error"
"@typescript-eslint/consistent-type-imports": "error",

// Promises & async/await
"no-async-promise-executor": "error",
"no-promise-executor-return": "error",
"no-return-await": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/promise-function-async": "error",
},
"ignorePatterns": ["vitest.config.ts"]
ignorePatterns: ["vitest.config.ts"]
};
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async function getVercelBuildChildProcess(
async function isVercelPackageInstalled(
pkgMng: PackageManager
): Promise<boolean> {
const packageVersion = getPackageVersion('vercel', pkgMng);
const packageVersion = await getPackageVersion('vercel', pkgMng);
return !!packageVersion;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/next-on-pages/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ export async function printEnvInfo(): Promise<void> {
Package Manager Used: ${await getCurrentPackageManager()}
Relevant Packages:
@cloudflare/next-on-pages: ${nextOnPagesVersion}
vercel: ${getPackageVersion('vercel', packageManager) ?? 'N/A'}
next: ${getPackageVersion('next', packageManager) ?? 'N/A'}
vercel: ${(await getPackageVersion('vercel', packageManager)) ?? 'N/A'}
next: ${(await getPackageVersion('next', packageManager)) ?? 'N/A'}
`);

// eslint-disable-next-line no-console
Expand Down
10 changes: 5 additions & 5 deletions packages/next-on-pages/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { watch } from 'chokidar';
import pLimit from 'p-limit';
import type { CliOptions } from './cli';
import { cliWarn } from './cli';
import { cliWarn, cliError } from './cli';
import { cliLog, parseCliArgs, printCliHelpMessage, printEnvInfo } from './cli';
import { buildApplication } from './buildApplication';
import { nextOnPagesVersion } from './utils';

const limit = pLimit(1);

runNextOnPages();
void runNextOnPages();

function runNextOnPages(): void {
async function runNextOnPages(): Promise<void> {
const args = parseCliArgs();

if (args.version) {
Expand All @@ -19,7 +19,7 @@ function runNextOnPages(): void {
return;
}
if (args.info) {
printEnvInfo();
await printEnvInfo();
return;
}

Expand Down Expand Up @@ -62,7 +62,7 @@ function runBuild(options: CliOptions) {
`);
}
}
});
}).catch(error => cliError(`Watch mode unexpected error: ${error}`));
}

function setWatchMode(fn: () => void): void {
Expand Down
8 changes: 3 additions & 5 deletions packages/next-on-pages/src/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async function validatePathType(path: string, type: 'file' | 'directory') {
* @param path Path to check.
* @returns Whether a file exists at the given path.
*/
export function validateFile(path: string) {
export async function validateFile(path: string) {
return validatePathType(path, 'file');
}

Expand All @@ -86,7 +86,7 @@ export function validateFile(path: string) {
* @param path Path to check.
* @returns Whether a directory exists at the given path.
*/
export function validateDir(path: string) {
export async function validateDir(path: string) {
return validatePathType(path, 'directory');
}

Expand All @@ -104,9 +104,7 @@ export async function readPathsRecursively(dir: string): Promise<string[]> {
files.map(async file => {
const path = resolve(dir, file);

return (await validateDir(path))
? await readPathsRecursively(path)
: [path];
return (await validateDir(path)) ? readPathsRecursively(path) : [path];
})
);

Expand Down

0 comments on commit b1c3a33

Please sign in to comment.