Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix]: support Node versions 10-14 #35

Merged
merged 2 commits into from
Feb 22, 2023
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# main (unreleased)

-[[bugfix]: support Node versions 10-14](https://github.com/upgradejs/depngn/pull/35)

# 0.3.0
-[[feature]: add the ability to perform the check in the specified path using --cwd option](https://github.com/upgradejs/depngn/pull/30)

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

4 changes: 2 additions & 2 deletions src/cli/reporter/html.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writeFile } from 'fs/promises';
import { writeFile } from '../../utils';
import { CompatData } from '../../types';

export async function createHtml(compatData: Record<string, CompatData>, version: string, path: string = 'compat.html') {
Expand Down Expand Up @@ -71,4 +71,4 @@ export async function createHtml(compatData: Record<string, CompatData>, version

await writeFile(path, out);
console.log(`File generated at ${path}`);
}
}
3 changes: 2 additions & 1 deletion src/cli/reporter/json.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { writeFile } from 'fs/promises';
import { writeFile } from '../../utils';
import { CompatData } from '../../types';

export async function createJson(compatData: Record<string, CompatData>, version: string, path: string = 'compat.json') {
const out = JSON.stringify({
node: version,
dependencies: compatData,
}, null, 2);

await writeFile(path, out);
console.log(`File generated at ${path}`);
}
4 changes: 0 additions & 4 deletions src/queries/exec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/queries/getDependencies.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { asyncExec } from './exec';
import { asyncExec } from '../utils';
import { PackageList, Manager } from '../types';

export async function getDependencies(manager: Manager): Promise<PackageList> {
Expand Down
2 changes: 1 addition & 1 deletion src/queries/getEngines.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { asyncExec } from './exec';
import { asyncExec } from '../utils';
import { Manager, PackageList, PackageManagerName } from '../types';

export async function getEngines(deps: PackageList, manager: Manager) {
Expand Down
2 changes: 1 addition & 1 deletion src/queries/getPackageManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { access } from 'fs/promises';
import { access } from '../utils';
import { Manager, PackageManagerName } from '../types';

const PACKAGE_MANAGER: Record<string, Manager> = {
Expand Down
1 change: 0 additions & 1 deletion src/queries/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './getCompatData';
export * from './exec';
14 changes: 14 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { exec } from 'child_process';
import { promisify } from 'util';
import { writeFile as syncWriteFile, access as syncAccess } from 'fs';

// `fs/promises` is only available from Node v14 onwards
// so we import the sync versions of `writeFile` and `access` and transform them into
// async versions using `promisify` (available from Node v8 onwards)
// if we ever decided to drop support for Node <v14, we can revert to using `fs/promises`
//
// `exec` doesn't have a promise version so we have to promisify it no matter what

export const access = promisify(syncAccess);
export const asyncExec = promisify(exec);
export const writeFile = promisify(syncWriteFile);