From 9c45b1770fd451e7d41ef5731ab68add7c163530 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Mon, 18 Mar 2024 13:38:10 +0100 Subject: [PATCH] refactor!: rename `path` to `cwd` in options For consistency with other packages in the ecosystem, like read-pkg and @npmcli/map-workspaces --- README.md | 12 ++++++------ lib/get-installed-data.js | 8 ++++---- lib/installed-check.js | 6 +++--- test/get-installed-data.spec.js | 2 +- test/installed-check.spec.js | 20 ++++++++++---------- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index b2d124b..f3b299c 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ type VersionRangeResult = VersionRangeItem & { ```javascript import { checkVersionRange, getInstalledData } from 'installed-check-core'; -const { installed, pkg } = await getInstalledData(path); +const { installed, pkg } = await getInstalledData(cwd); const result = await checkVersionRange( pkg, @@ -143,12 +143,12 @@ Is a simple wrapper around [`read-pkg`](https://github.com/sindresorhus/read-pkg #### Syntax ```ts -getInstalledData(path = '.') => Promise +getInstalledData(cwd = '.') => Promise ``` #### Arguments -* `path` – specifies the path to the package to be checked, with its `package.json` expected to be there and its installed `node_modules` as well. +* `cwd` – specifies the path of the package to be checked, with its `package.json` expected to exist in that path and its installed `node_modules` as well. #### Types @@ -202,7 +202,7 @@ type InstalledCheckResult = { errors: string[], warnings: string[] } #### Options -* `path = '.'` – specifies the path to the package to be checked, with its `package.json` expected to be there and its installed `node_modules` as well. +* `cwd = '.'` – specifies the path to the package to be checked, with its `package.json` expected to be there and its installed `node_modules` as well. * `ignores = string[]` – names of modules to exclude from checks. Supports [`picomatch`](https://www.npmjs.com/package/picomatch) globbing syntax, eg. `@types/*`. (Not supported by `version` checks) * `noDev = false` – exclude `devDependencies` from checks. `devDependencies` that are also in `peerDependencies` will not be ignored. (Not supported by `version` checks) * `strict = false` – converts most warnings into failures @@ -213,7 +213,7 @@ type InstalledCheckResult = { errors: string[], warnings: string[] } import { installedCheck } from 'installed-check-core'; const { errors, warnings } = await installedCheck(['engine', 'version'], { - path: 'path/to/module', + cwd: 'path/to/module', ignore: ['foo'], noDev: true, }); @@ -234,7 +234,7 @@ performInstalledCheck(checks, pkg, installed, options) => Promise} */ -export async function getInstalledData (path = '.') { +export async function getInstalledData (cwd = '.') { const [ pkg, installed, ] = await Promise.all([ - readPackage({ cwd: path }).catch(/** @param {Error} err */ err => { + readPackage({ cwd }).catch(/** @param {Error} err */ err => { throw new ErrorWithCause('Failed to read package.json', { cause: err }); }), - listInstalled(path).catch(/** @param {Error} err */ err => { + listInstalled(cwd).catch(/** @param {Error} err */ err => { throw new ErrorWithCause('Failed to list installed modules', { cause: err }); }), ]); diff --git a/lib/installed-check.js b/lib/installed-check.js index fd6ad6c..99733bf 100644 --- a/lib/installed-check.js +++ b/lib/installed-check.js @@ -3,13 +3,13 @@ import { performInstalledCheck } from './perform-installed-check.js'; /** * @param {import('./perform-installed-check.js').InstalledChecks[]} checks - * @param {import('./perform-installed-check.js').InstalledCheckOptions & { path?: string }} [options] + * @param {import('./perform-installed-check.js').InstalledCheckOptions & { cwd?: string }} [options] * @returns {Promise} */ export async function installedCheck (checks, options) { - const { path = '.', ...checkOptions } = options || {}; + const { cwd = '.', ...checkOptions } = options || {}; - const { installed, pkg } = await getInstalledData(path); + const { installed, pkg } = await getInstalledData(cwd); return performInstalledCheck(checks, pkg, installed, checkOptions); } diff --git a/test/get-installed-data.spec.js b/test/get-installed-data.spec.js index 529cb97..7afd5f9 100644 --- a/test/get-installed-data.spec.js +++ b/test/get-installed-data.spec.js @@ -18,7 +18,7 @@ describe('getInstalledData', () => { .and.have.nested.property('pkg.name', 'installed-check-core'); }); - it('should return data from path when specified', async () => { + it('should return data from cwd when specified', async () => { const result = await getInstalledData(join(import.meta.url, 'fixtures/valid')); result.should.be.an('object').with.keys('installed', 'pkg'); diff --git a/test/installed-check.spec.js b/test/installed-check.spec.js index 81fe3fa..a7ef483 100644 --- a/test/installed-check.spec.js +++ b/test/installed-check.spec.js @@ -27,14 +27,14 @@ describe('installedCheck()', () => { it('should error on missing package.json file', async () => { await installedCheck(['engine', 'version'], { - path: join(import.meta.url, 'fixtures/missing-package-json'), + cwd: join(import.meta.url, 'fixtures/missing-package-json'), }) .should.be.rejectedWith(/Failed to read package\.json/); }); it('should error on inability to list installed modules', async () => { await installedCheck(['engine', 'version'], { - path: join(import.meta.url, 'fixtures/missing-node-modules'), + cwd: join(import.meta.url, 'fixtures/missing-node-modules'), }) .should.be.rejectedWith(/Failed to list installed modules/); }); @@ -43,7 +43,7 @@ describe('installedCheck()', () => { describe('functionality', () => { it('should return an empty result on valid setup', async () => { await installedCheck(['engine', 'version'], { - path: join(import.meta.url, 'fixtures/valid'), + cwd: join(import.meta.url, 'fixtures/valid'), }) .should.eventually.deep.equal({ errors: [], @@ -53,7 +53,7 @@ describe('installedCheck()', () => { it('should return an empty result on an aliased setup', async () => { await installedCheck(['engine', 'version'], { - path: join(import.meta.url, 'fixtures/aliased'), + cwd: join(import.meta.url, 'fixtures/aliased'), }) .should.eventually.deep.equal({ errors: [], @@ -63,7 +63,7 @@ describe('installedCheck()', () => { it('should return errors and warnings on invalid setup', async () => { await installedCheck(['engine', 'version'], { - path: join(import.meta.url, 'fixtures/invalid'), + cwd: join(import.meta.url, 'fixtures/invalid'), }) .should.eventually.deep.equal({ 'errors': [ @@ -95,7 +95,7 @@ describe('installedCheck()', () => { it('should check engine even when no target engines are set', async () => { await installedCheck(['engine'], { - path: join(import.meta.url, 'fixtures/missing-engines'), + cwd: join(import.meta.url, 'fixtures/missing-engines'), }) .should.eventually.deep.equal({ 'errors': [ @@ -110,7 +110,7 @@ describe('installedCheck()', () => { it('should not suggest an engine configuration when engines are incompatible', async () => { await installedCheck(['engine'], { - path: join(import.meta.url, 'fixtures/incompatible-engines'), + cwd: join(import.meta.url, 'fixtures/incompatible-engines'), }) .should.eventually.deep.equal({ 'errors': [ @@ -123,7 +123,7 @@ describe('installedCheck()', () => { it('should handle engine ranges', async () => { await installedCheck(['engine'], { - path: join(import.meta.url, 'fixtures/engine-ranges'), + cwd: join(import.meta.url, 'fixtures/engine-ranges'), }) .should.eventually.deep.equal({ 'errors': [], @@ -133,7 +133,7 @@ describe('installedCheck()', () => { it('should handle ignores', async () => { await installedCheck(['engine'], { - path: join(import.meta.url, 'fixtures/invalid'), + cwd: join(import.meta.url, 'fixtures/invalid'), ignore: ['invalid-alias*', 'invalid-dependency-definition'], }) .should.eventually.deep.equal({ @@ -155,7 +155,7 @@ describe('installedCheck()', () => { it('should check peer dependencies', async () => { await installedCheck(['peer'], { - path: join(import.meta.url, 'fixtures/peer'), + cwd: join(import.meta.url, 'fixtures/peer'), }) .should.eventually.deep.equal({ 'errors': [