Skip to content

Commit

Permalink
fix(deps): leverage execa without the wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
travi committed Nov 13, 2024
1 parent 61dfc03 commit 6a0fe0a
Show file tree
Hide file tree
Showing 24 changed files with 467 additions and 118 deletions.
491 changes: 420 additions & 71 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@
"@form8ion/config-file": "^1.1.1",
"@form8ion/core": "^4.0.0",
"@form8ion/eslint": "^6.1.0",
"@form8ion/execa-wrapper": "^1.0.0-alpha.1",
"@form8ion/husky": "^5.3.0",
"@form8ion/husky": "^6.0.0-beta.2",
"@form8ion/javascript-core": "^12.0.0-beta.1",
"@form8ion/overridable-prompts": "^1.2.0",
"@form8ion/prettier": "^2.0.0",
Expand All @@ -74,6 +73,7 @@
"@travi/language-scaffolder-prompts": "^2.0.0-beta.1",
"camelcase": "^8.0.0",
"deepmerge": "^4.2.2",
"execa": "^9.5.1",
"filedirname": "^3.0.0",
"ini": "^5.0.0",
"joi": "^17.5.0",
Expand Down
2 changes: 1 addition & 1 deletion src/corepack/lifter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import execa from '../../thirdparty-wrappers/execa.js';
import {execa} from 'execa';

export default async function () {
await execa('corepack', ['use', 'npm@latest']);
Expand Down
5 changes: 3 additions & 2 deletions src/corepack/lifter.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {execa} from 'execa';

import {describe, it, vi, expect, afterEach} from 'vitest';

import execa from '../../thirdparty-wrappers/execa.js';
import liftCorepack from './lifter.js';

vi.mock('../../thirdparty-wrappers/execa.js');
vi.mock('execa');

describe('corepack lifter', () => {
afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/dependencies/installer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {info, warn} from '@travi/cli-messages';
import {DEV_DEPENDENCY_TYPE, packageManagers} from '@form8ion/javascript-core';

import execa from '../../thirdparty-wrappers/execa.js';
import {execa} from 'execa';
import {getDependencyTypeFlag, getExactFlag, getInstallationCommandFor} from './package-managers.js';

export default async function (dependencies, dependenciesType, projectRoot, packageManager = packageManagers.NPM) {
Expand Down
4 changes: 2 additions & 2 deletions src/dependencies/installer.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {execa} from 'execa';
import {DEV_DEPENDENCY_TYPE, packageManagers} from '@form8ion/javascript-core';

import {vi, it, describe, expect, beforeEach} from 'vitest';
import any from '@travi/any';
import {when} from 'jest-when';

import execa from '../../thirdparty-wrappers/execa.js';
import {getDependencyTypeFlag, getInstallationCommandFor, getExactFlag} from './package-managers.js';
import install from './installer.js';

vi.mock('../../thirdparty-wrappers/execa.js');
vi.mock('execa');
vi.mock('./package-managers.js');

describe('dependencies installer', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/dependencies/remover.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import execa from '../../thirdparty-wrappers/execa.js';
import {execa} from 'execa';

export default async function ({packageManager, dependencies}) {
await execa(packageManager, ['remove', ...dependencies]);
Expand Down
5 changes: 3 additions & 2 deletions src/dependencies/remover.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {execa} from 'execa';

import any from '@travi/any';
import {describe, it, expect, vi} from 'vitest';

import execa from '../../thirdparty-wrappers/execa.js';
import removeDependencies from './remover.js';

vi.mock('../../thirdparty-wrappers/execa.js');
vi.mock('execa');

describe('dependency remover', () => {
it('should remove the dependencies using the named package manager', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/node-version/tasks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {info} from '@travi/cli-messages';

import execa from '../../thirdparty-wrappers/execa.js';
import {execa} from 'execa';

export async function determineLatestVersionOf(nodeVersionCategory) {
info('Determining version of node', {level: 'secondary'});
Expand Down
5 changes: 3 additions & 2 deletions src/node-version/tasks.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {execa} from 'execa';

import {it, expect, describe, afterEach, vi} from 'vitest';
import {when} from 'jest-when';
import any from '@travi/any';

import execa from '../../thirdparty-wrappers/execa.js';
import {determineLatestVersionOf, install} from './tasks.js';

vi.mock('../../thirdparty-wrappers/execa.js');
vi.mock('execa');

describe('node-version tasks', () => {
const majorVersion = any.integer();
Expand Down
2 changes: 1 addition & 1 deletion src/prompts/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {prompt as promptWithInquirer} from '@form8ion/overridable-prompts';
import {questionNames as commonQuestionNames, questions as commonQuestions} from '@travi/language-scaffolder-prompts';
import {warn} from '@travi/cli-messages';

import execa from '../../thirdparty-wrappers/execa.js';
import {execa} from 'execa';
import npmConfFactory from '../../thirdparty-wrappers/npm-conf.js';
import buildDialectChoices from '../dialects/prompt-choices.js';
import {
Expand Down
4 changes: 2 additions & 2 deletions src/prompts/questions.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {execa} from 'execa';
import * as commonPrompts from '@travi/language-scaffolder-prompts';
import * as prompts from '@form8ion/overridable-prompts';
import {packageManagers, projectTypes} from '@form8ion/javascript-core';
Expand All @@ -6,17 +7,16 @@ import {expect, describe, it, vi, beforeEach} from 'vitest';
import any from '@travi/any';
import {when} from 'jest-when';

import execa from '../../thirdparty-wrappers/execa.js';
import npmConfFactory from '../../thirdparty-wrappers/npm-conf.js';
import buildDialectChoices from '../dialects/prompt-choices.js';
import {questionNames} from './question-names.js';
import * as conditionals from './conditionals.js';
import {prompt} from './questions.js';
import * as validators from './validators.js';

vi.mock('execa');
vi.mock('@travi/language-scaffolder-prompts');
vi.mock('@form8ion/overridable-prompts');
vi.mock('../../thirdparty-wrappers/execa.js');
vi.mock('../../thirdparty-wrappers/npm-conf.js');
vi.mock('../dialects/prompt-choices.js');
vi.mock('./validators.js');
Expand Down
4 changes: 2 additions & 2 deletions test/integration/features/step_definitions/common-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function assertDevDependencyIsInstalled(execa, dependencyName) {
Before(async function () {
validateNpmPackageName(any.word());

this.execa = await td.replaceEsm('@form8ion/execa-wrapper');
this.execa = (await td.replaceEsm('execa')).execa;
this.projectRoot = process.cwd();

// eslint-disable-next-line import/no-extraneous-dependencies,import/no-unresolved
Expand Down Expand Up @@ -265,7 +265,7 @@ Then('the expected results for a(n) {string} are returned to the project scaffol

if (projectTypes.PACKAGE === type) {
assert.equal(scripts['lint:publish'], 'publint --strict');
assertDevDependencyIsInstalled(this.execa.default, 'publint');
assertDevDependencyIsInstalled(this.execa, 'publint');
}

if ('github' === this.vcs?.host && 'Public' === this.visibility && this.tested) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Then('nyc is not configured for code coverage', async function () {
assert.isFalse(await fileExists(`${process.cwd()}/.nycrc`));
assert.isFalse(await directoryExists(`${process.cwd()}/.nyc_output`));
assertDependenciesWereRemoved(
this.execa.default,
this.execa,
this.packageManager,
['nyc', '@istanbuljs/nyc-config-babel', 'babel-plugin-istanbul']
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export function assertDependenciesWereRemoved(execa, packageManager, dependencyN
}

Then('ls-engines is added as a dependency', async function () {
assertDevDependencyIsInstalled(this.execa.default, 'ls-engines');
assertDevDependencyIsInstalled(this.execa, 'ls-engines');
});
4 changes: 2 additions & 2 deletions test/integration/features/step_definitions/dialect-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Then('the {string} dialect is configured', async function (dialect) {
} = this;

if (dialects.BABEL === dialect) {
await assertBabelDialectDetailsAreCorrect(babelPreset, buildDirectory, this.execa.default);
await assertBabelDialectDetailsAreCorrect(babelPreset, buildDirectory, this.execa);
}

if (dialects.TYPESCRIPT === dialect) {
Expand All @@ -145,7 +145,7 @@ Then('the {string} dialect is configured', async function (dialect) {
testFilenamePattern,
projectType,
this.packageTypeChoiceAnswer,
this.execa.default
this.execa
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ Then('dependencies are defined for the additional configs', async function () {
return `${this.eslintConfigScope}/eslint-config-${config.name}`;
});

assertDevDependencyIsInstalled(this.execa.default, additionalConfigPackageNames.join(' '));
assertDevDependencyIsInstalled(this.execa, additionalConfigPackageNames.join(' '));
});
14 changes: 7 additions & 7 deletions test/integration/features/step_definitions/husky-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export async function assertHookContainsScript(hook, script) {

Given('husky v5 is installed', async function () {
td
.when(this.execa.default('npm', ['ls', 'husky', '--json']))
.when(this.execa('npm', ['ls', 'husky', '--json']))
.thenResolve({stdout: JSON.stringify({dependencies: {husky: {version: '5.0.0'}}})});
});

Given('husky v4 is installed', async function () {
td
.when(this.execa.default('npm', ['ls', 'husky', '--json']))
.when(this.execa('npm', ['ls', 'husky', '--json']))
.thenResolve({stdout: JSON.stringify({dependencies: {husky: {version: '4.5.6'}}})});
});

Expand All @@ -32,7 +32,7 @@ Given('husky is not installed', async function () {
error.stdout = JSON.stringify({});
error.command = 'npm ls husky --json';

td.when(this.execa.default('npm', ['ls', 'husky', '--json'])).thenReject(error);
td.when(this.execa('npm', ['ls', 'husky', '--json'])).thenReject(error);
});

Given('husky config is in v4 format', async function () {
Expand All @@ -44,7 +44,7 @@ Given('husky config is in v5 format', async function () {
});

Then('husky is configured for a {string} project', async function (packageManager) {
td.verify(this.execa.default(td.matchers.contains(/(npm install|yarn add).*husky/)), {ignoreExtraArgs: true});
td.verify(this.execa(td.matchers.contains(/(npm install|yarn add).*husky/)), {ignoreExtraArgs: true});

await assertHookContainsScript('pre-commit', `${packageManager} test`);
await assertHookContainsScript('commit-msg', 'npx --no-install commitlint --edit $1');
Expand All @@ -53,17 +53,17 @@ Then('husky is configured for a {string} project', async function (packageManage
Then('husky is configured for {string}', async function (packageManager) {
if (packageManagers.NPM === packageManager) {
td.verify(
this.execa.default(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && npm install')),
this.execa(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && npm install')),
{ignoreExtraArgs: true}
);
}
if (packageManagers.YARN === packageManager) {
td.verify(
this.execa.default(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && yarn add')),
this.execa(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && yarn add')),
{ignoreExtraArgs: true}
);
}
td.verify(this.execa.default(td.matchers.contains(/(npm install|yarn add).*husky@latest/)), {ignoreExtraArgs: true});
td.verify(this.execa(td.matchers.contains(/(npm install|yarn add).*husky@latest/)), {ignoreExtraArgs: true});
assert.equal(
JSON.parse(await fs.readFile(`${process.cwd()}/package.json`, 'utf-8')).scripts.prepare,
'husky'
Expand Down
8 changes: 4 additions & 4 deletions test/integration/features/step_definitions/npm-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ Given(/^the npm cli is logged in$/, function () {
error.stdout = JSON.stringify({});
error.command = 'npm ls husky --json';

td.when(this.execa.default('npm', ['whoami'])).thenResolve({stdout: this.npmAccount});
td.when(this.execa('npm', ['whoami'])).thenResolve({stdout: this.npmAccount});
td
.when(this.execa.default(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && npm install')))
.when(this.execa(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && npm install')))
.thenResolve({stdout: ''});
td.when(this.execa.default('npm', ['ls', 'husky', '--json'])).thenReject(error);
td.when(this.execa('npm', ['ls', 'husky', '--json'])).thenReject(error);
});

Then('the npm cli is configured for use', async function () {
Expand All @@ -176,7 +176,7 @@ Then('the npm cli is configured for use', async function () {
assert.equal(path, 'package-lock.json');
assert.equal(this.scaffoldResult.verificationCommand, 'npm run generate:md && npm test');
td.verify(
this.execa.default(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && npm install')),
this.execa(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && npm install')),
{ignoreExtraArgs: true}
);
});
4 changes: 2 additions & 2 deletions test/integration/features/step_definitions/nvm-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Given(/^nvm is properly configured$/, function () {
this.latestLtsMajorVersion = majorVersion;
this.latestLtsVersion = semverStringFactory();

td.when(this.execa.default('. ~/.nvm/nvm.sh && nvm ls-remote --lts', {shell: true}))
td.when(this.execa('. ~/.nvm/nvm.sh && nvm ls-remote --lts', {shell: true}))
.thenResolve({stdout: [...any.listOf(semverStringFactory), this.latestLtsVersion, ''].join('\n')});
td
.when(this.execa.default('. ~/.nvm/nvm.sh && nvm install', {shell: true}))
.when(this.execa('. ~/.nvm/nvm.sh && nvm install', {shell: true}))
.thenReturn({stdout: {pipe: () => undefined}});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Given('an {string} lockfile exists', async function (packageManager) {
await fs.writeFile(`${process.cwd()}/package-lock.json`, JSON.stringify(any.simpleObject()));

td
.when(this.execa.default(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && npm install')))
.when(this.execa(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && npm install')))
.thenResolve({stdout: ''});
}

if (packageManagers.YARN === packageManager) {
await fs.writeFile(`${process.cwd()}/yarn.lock`, any.string());

td
.when(this.execa.default(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && yarn add')))
.when(this.execa(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && yarn add')))
.thenResolve({stdout: ''});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Then('publint is configured', async function () {
const {scripts} = JSON.parse(await fs.readFile(`${process.cwd()}/package.json`, 'utf-8'));

assert.equal(scripts['lint:publish'], 'publint --strict');
assertDevDependencyIsInstalled(this.execa.default, 'publint');
assertDevDependencyIsInstalled(this.execa, 'publint');
});
8 changes: 4 additions & 4 deletions test/integration/features/step_definitions/yarn-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Given('the yarn cli is logged in', async function () {
error.stdout = JSON.stringify({});
error.command = 'npm ls husky --json';

td.when(this.execa.default(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && yarn add'))).thenResolve({stdout: ''});
td.when(this.execa.default('npm', ['ls', 'husky', '--json'])).thenResolve({stdout: JSON.stringify({})});
td.when(this.execa.default('npm', ['ls', 'husky', '--json'])).thenReject(error);
td.when(this.execa(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && yarn add'))).thenResolve({stdout: ''});
td.when(this.execa('npm', ['ls', 'husky', '--json'])).thenResolve({stdout: JSON.stringify({})});
td.when(this.execa('npm', ['ls', 'husky', '--json'])).thenReject(error);
});

Then('the yarn cli is configured for use', async function () {
Expand All @@ -35,7 +35,7 @@ Then('the yarn cli is configured for use', async function () {
assert.equal(path, 'yarn.lock');
assert.equal(this.scaffoldResult.verificationCommand, 'yarn generate:md && yarn test');
td.verify(
this.execa.default(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && yarn add')),
this.execa(td.matchers.contains('. ~/.nvm/nvm.sh && nvm use && yarn add')),
{ignoreExtraArgs: true}
);
});
3 changes: 0 additions & 3 deletions thirdparty-wrappers/execa.js

This file was deleted.

0 comments on commit 6a0fe0a

Please sign in to comment.