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

Remove child-process-promise from dependencies #1559

Merged
merged 4 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Replace child-process-promise with execa
  • Loading branch information
Castro, Mario committed Dec 5, 2024
commit 092bacca48be6aef9dab78cbb00310202843f6f3
597 changes: 280 additions & 317 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@oclif/core": "3.15.0",
"@oclif/plugin-help": "^5",
"chalk": "^2.4.2",
"child-process-promise": "^2.2.1",
"execa": "^2.0.3",
"fp-ts": "^2.11.0",
"fs-extra": "^8.1.0",
Expand All @@ -35,7 +34,6 @@
"@oclif/test": "^3.0.3",
"@types/chai": "4.2.18",
"@types/chai-as-promised": "7.1.4",
"@types/child-process-promise": "^2.2.1",
"@types/faker": "5.1.5",
"@types/fs-extra": "^9.0.13",
"@types/inflected": "1.1.29",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/services/process/live.impl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as childProcess from 'child-process-promise'
import * as execa from 'execa'
import * as process from 'process'
import { ProcessError, ProcessService } from '.'
import { Layer, tryCatch, tryCatchPromise } from '@boostercloud/framework-types/dist/effect'
Expand All @@ -7,7 +7,7 @@ import { unknownToError } from '../../common/errors'
const exec = (command: string, cwd?: string) =>
tryCatchPromise(
async () => {
const { stdout, stderr } = await childProcess.exec(command, { cwd })
const { stdout, stderr } = await execa.command(command, { cwd })
const result = `
${stderr ? `There were some issues running the command: ${stderr}\n` : ''}
${stdout}
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/services/project-initializer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs-extra'
import { exec } from 'child-process-promise'
import { command } from 'execa'
import * as Mustache from 'mustache'
import * as path from 'path'
import * as tsConfig from '../templates/project/tsconfig-json'
Expand Down Expand Up @@ -59,7 +59,7 @@ export async function generateRootDirectory(config: ProjectInitializerConfig): P

export async function initializeGit(config: ProjectInitializerConfig): Promise<void> {
try {
await exec('git init && git add -A && git commit -m "Initial commit"', { cwd: projectDir(config) })
await command('git init && git add -A && git commit -m "Initial commit"', { cwd: projectDir(config) })
} catch (e) {
throw wrapExecError(e, 'Could not initialize git repository')
}
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/test/services/process/live.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as process from 'process'
import * as childProcessPromise from 'child-process-promise'
import * as execa from 'execa'
import { fake, replace, restore } from 'sinon'
import { Effect, gen, mapError, pipe, unsafeRunEffect } from '@boostercloud/framework-types/dist/effect'
import { LiveProcess } from '../../../src/services/process/live.impl'
Expand All @@ -10,7 +10,7 @@ import { ProcessService } from '../../../src/services/process'
describe('Process - Live Implementation', () => {
beforeEach(() => {
replace(process, 'cwd', fake.returns(''))
replace(childProcessPromise, 'exec', fake.resolves({}))
replace(execa, 'command', fake.resolves({ stdout: '', stderr: '' }))
})

afterEach(() => {
Expand All @@ -35,7 +35,7 @@ describe('Process - Live Implementation', () => {
expect(process.cwd).to.have.been.called
})

it('uses child-process-promise.exec', async () => {
it('uses execa.command', async () => {
const command = 'command'
const cwd = 'cwd'

Expand All @@ -48,6 +48,6 @@ describe('Process - Live Implementation', () => {
layer: LiveProcess,
onError: guardError('An error ocurred'),
})
expect(childProcessPromise.exec).to.have.been.calledWith(command, { cwd })
expect(execa.command).to.have.been.calledWith(command, { cwd })
})
})
12 changes: 5 additions & 7 deletions packages/cli/test/services/project-initializer.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as fs from 'fs-extra'
import * as childProcessPromise from 'child-process-promise'
import * as execa from 'execa'
import {
generateConfigFiles,
installDependencies,
generateRootDirectory,
initializeGit,
installDependencies,
ProjectInitializerConfig,
} from '../../src/services/project-initializer'
import { restore, replace, fake } from 'sinon'
import { fake, replace, restore } from 'sinon'
import { expect } from '../expect'
import { makeTestPackageManager } from './package-manager/test.impl'
import * as PackageManager from '../../src/services/package-manager/live.impl'
Expand All @@ -16,7 +16,7 @@ describe('project initializer', (): void => {
beforeEach(() => {
replace(fs, 'mkdirs', fake.resolves({}))
replace(fs, 'outputFile', fake.resolves({}))
replace(childProcessPromise, 'exec', fake.resolves({}))
replace(execa, 'command', fake.resolves({ stdout: '', stderr: '' }))
})

afterEach(() => {
Expand All @@ -42,9 +42,7 @@ describe('project initializer', (): void => {

it('initialize Git', async () => {
await initializeGit(defaultProjectInitializerConfig)
expect(childProcessPromise.exec).to.have.been.calledWithMatch(
'git init && git add -A && git commit -m "Initial commit"'
)
expect(execa.command).to.have.been.calledWithMatch('git init && git add -A && git commit -m "Initial commit"')
})

it('Generate root directory', async () => {
Expand Down
5 changes: 2 additions & 3 deletions packages/framework-common-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@
},
"dependencies": {
"@boostercloud/framework-types": "workspace:^2.18.6",
"child-process-promise": "^2.2.1",
"tslib": "^2.4.0",
"@effect-ts/core": "^0.60.4",
"class-transformer": "~0.5.1"
"class-transformer": "~0.5.1",
"execa": "^2.0.3"
},
"devDependencies": {
"@boostercloud/eslint-config": "workspace:^2.18.6",
"@types/chai": "4.2.18",
"@types/chai-as-promised": "7.1.4",
"@types/child-process-promise": "^2.2.1",
"@types/mocha": "10.0.1",
"@types/node": "^18.18.2",
"@types/rewire": "^2.5.28",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exec } from 'child-process-promise'
import { command } from 'execa'
import * as path from 'path'
import * as fs from 'fs'

Expand Down Expand Up @@ -35,5 +35,5 @@ function overrideWithLocalDeps(dependencies: Record<string, string>): void {
}

export async function forceRepoRebuild(): Promise<void> {
await exec('rush update && rush rebuild')
await command('rush update && rush rebuild')
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path'
import { expect } from 'chai'
import { sandboxPathFor, removeFolders, fileExists } from '../../helper/file-helper'
import { exec } from 'child-process-promise'
import { fileExists, removeFolders, sandboxPathFor } from '../../helper/file-helper'
import { command } from 'execa'
// Imported from another package to avoid duplication
// It is OK-ish, since integration tests are always run in the context of the whole monorepo
import { createSandboxProject } from '../../../../cli/src/common/sandbox'
Expand All @@ -26,7 +26,7 @@ describe('Build', () => {
['boost build', 'Checking project structure', 'Building project', 'Build complete'].join('(.|\n)*')
)

const { stdout } = await exec(`${cliPath} build`, { cwd: buildSandboxDir })
const { stdout } = await command(`${cliPath} build`, { cwd: buildSandboxDir })

expect(stdout).to.match(expectedOutputRegex)
expect(fileExists(path.join(buildSandboxDir, 'dist', 'index.js'))).to.be.true
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('Compile fallback', () => {
['boost build', 'Checking project structure', 'Building project', 'Build complete'].join('(.|\n)*')
)

const { stdout } = await exec(`${cliPath} build`, { cwd: compileSandboxDir })
const { stdout } = await command(`${cliPath} build`, { cwd: compileSandboxDir })

expect(stdout).to.match(expectedOutputRegex)
expect(fileExists(path.join(compileSandboxDir, 'eureka'))).to.be.true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path'
import { expect } from 'chai'
import { sandboxPathFor, removeFolders, fileExists } from '../../helper/file-helper'
import { exec } from 'child-process-promise'
import { fileExists, removeFolders, sandboxPathFor } from '../../helper/file-helper'
import { command } from 'execa'
// Imported from another package to avoid duplication
// It is OK-ish, since integration tests are always run in the context of the whole monorepo
import { createSandboxProject } from '../../../../cli/src/common/sandbox'
Expand All @@ -21,19 +21,18 @@ describe('Clean', () => {

context('Valid clean', () => {
it('should clean the project after build', async () => {

await exec(`${cliPath} build`, { cwd: cleanSandboxDir })

expect(fileExists(path.join(cleanSandboxDir,'dist'))).to.be.true

await command(`${cliPath} build`, { cwd: cleanSandboxDir })

expect(fileExists(path.join(cleanSandboxDir, 'dist'))).to.be.true

const expectedCleanOutputRegex = new RegExp(
['boost clean', 'Checking project structure', 'Cleaning project', 'Clean complete'].join('(.|\n)*')
)

const { stdout } = await exec(`${cliPath} clean`, { cwd: cleanSandboxDir })
const { stdout } = await command(`${cliPath} clean`, { cwd: cleanSandboxDir })

expect(stdout).to.match(expectedCleanOutputRegex)
expect(fileExists(path.join(cleanSandboxDir,'dist'))).to.be.false
expect(fileExists(path.join(cleanSandboxDir, 'dist'))).to.be.false
})
})
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path'
import { expect } from 'chai'
import { loadFixture, readFileContent, removeFolders, sandboxPathFor, writeFileContent } from '../../helper/file-helper'
import { exec } from 'child-process-promise'
import { command } from 'execa'
// Imported from another package to avoid duplication
// It is OK-ish, since integration tests are always run in the context of the whole monorepo
import { createSandboxProject } from '../../../../cli/src/common/sandbox'
Expand Down Expand Up @@ -29,7 +29,7 @@ describe('Command', () => {
['boost new:command', 'Verifying project', 'Creating new command', 'Command generated'].join('(.|\n)*')
)

const { stdout } = await exec(`${cliPath} new:command ChangeCart`, { cwd: commandSandboxDir })
const { stdout } = await command(`${cliPath} new:command ChangeCart`, { cwd: commandSandboxDir })
expect(stdout).to.match(expectedOutputRegex)

const expectedCommandContent = loadFixture('commands/change-cart.ts')
Expand All @@ -46,7 +46,7 @@ describe('Command', () => {
it('should create a new command with fields', async () => {
const changeCartWithFieldsCommandPath = `${commandSandboxDir}/src/commands/change-cart-with-fields.ts`

await exec(`${cliPath} new:command ChangeCartWithFields --fields cartId:UUID sku:string quantity:number`, {
await command(`${cliPath} new:command ChangeCartWithFields --fields cartId:UUID sku:string quantity:number`, {
cwd: commandSandboxDir,
})

Expand All @@ -65,7 +65,7 @@ describe('Command', () => {
context('Invalid command', () => {
describe('missing command name', () => {
it('should fail', async () => {
const { stderr } = await exec(`${cliPath} new:command`, { cwd: commandSandboxDir })
const { stderr } = await command(`${cliPath} new:command`, { cwd: commandSandboxDir })

expect(stderr).to.match(/You haven't provided a command name, but it is required, run with --help for usage/)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai'
import { readFileContent, writeFileContent, loadFixture, removeFolders, sandboxPathFor } from '../../helper/file-helper'
import { loadFixture, readFileContent, removeFolders, sandboxPathFor, writeFileContent } from '../../helper/file-helper'
import * as path from 'path'
import { exec } from 'child-process-promise'
import { command } from 'execa'
// Imported from another package to avoid duplication
// It is OK-ish, since integration tests are always run in the context of the whole monorepo
import { createSandboxProject } from '../../../../cli/src/common/sandbox'
Expand Down Expand Up @@ -29,7 +29,7 @@ describe('Entity', () => {
['boost new:entity', 'Verifying project', 'Creating new entity', 'Entity generated'].join('(.|\n)*'),
'm'
)
const { stdout } = await exec(`${cliPath} new:entity Post`, { cwd: entitySandboxDir })
const { stdout } = await command(`${cliPath} new:entity Post`, { cwd: entitySandboxDir })
expect(stdout).to.match(expectedOutputRegex)

const expectedEntityContent = readFileContent('integration/fixtures/entities/post.ts')
Expand All @@ -44,7 +44,7 @@ describe('Entity', () => {
['boost new:entity', 'Verifying project', 'Creating new entity', 'Entity generated'].join('(.|\n)*'),
'm'
)
const { stdout } = await exec(`${cliPath} new:entity PostWithFields --fields title:string body:string`, {
const { stdout } = await command(`${cliPath} new:entity PostWithFields --fields title:string body:string`, {
cwd: entitySandboxDir,
})
expect(stdout).to.match(expectedOutputRegex)
Expand All @@ -61,7 +61,7 @@ describe('Entity', () => {
const FILE_POST_CREATED_EVENT = `${entitySandboxDir}/src/events/post-created.ts`

// Create event
await exec(`${cliPath} new:event PostCreated --fields postId:UUID title:string body:string`, {
await command(`${cliPath} new:event PostCreated --fields postId:UUID title:string body:string`, {
cwd: entitySandboxDir,
})

Expand All @@ -75,7 +75,7 @@ describe('Entity', () => {
writeFileContent(FILE_POST_CREATED_EVENT, updatedEventContent)

// Create entity
await exec(`${cliPath} new:entity PostWithReducer --fields title:string body:string --reduces PostCreated`, {
await command(`${cliPath} new:entity PostWithReducer --fields title:string body:string --reduces PostCreated`, {
cwd: entitySandboxDir,
})
const expectedEntityContent = loadFixture('entities/post-with-reducer.ts')
Expand All @@ -96,7 +96,7 @@ describe('Entity', () => {
context('invalid entity', () => {
describe('missing entity name', () => {
it('should fail', async () => {
const { stderr } = await exec(`${cliPath} new:entity`, { cwd: entitySandboxDir })
const { stderr } = await command(`${cliPath} new:entity`, { cwd: entitySandboxDir })

expect(stderr).to.match(/You haven't provided an entity name, but it is required, run with --help for usage/m)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path'
import { expect } from 'chai'
import { loadFixture, readFileContent, removeFolders, sandboxPathFor } from '../../helper/file-helper'
import { exec } from 'child-process-promise'
import { command } from 'execa'
// Imported from another package to avoid duplication
// It is OK-ish, since integration tests are always run in the context of the whole monorepo
import { createSandboxProject } from '../../../../cli/src/common/sandbox'
Expand All @@ -27,7 +27,7 @@ describe('Event handler', () => {
)
)

const { stdout } = await exec(`${cliPath} new:event-handler HandleCartChange -e CartItemChanged`, {
const { stdout } = await command(`${cliPath} new:event-handler HandleCartChange -e CartItemChanged`, {
cwd: eventHandlerSandboxDir,
})
expect(stdout).to.match(expectedOutputRegex)
Expand All @@ -42,7 +42,7 @@ describe('Event handler', () => {
describe('Invalid event handler', () => {
context('without name and event', () => {
it('should fail', async () => {
const { stderr } = await exec(`${cliPath} new:event-handler`, { cwd: eventHandlerSandboxDir })
const { stderr } = await command(`${cliPath} new:event-handler`, { cwd: eventHandlerSandboxDir })

expect(stderr).to.match(
/You haven't provided an event handler name, but it is required, run with --help for usage/
Expand All @@ -52,7 +52,7 @@ describe('Event handler', () => {

context('Without name', () => {
it('should fail', async () => {
const { stderr } = await exec(`${cliPath} new:event-handler -e CartPaid`, { cwd: eventHandlerSandboxDir })
const { stderr } = await command(`${cliPath} new:event-handler -e CartPaid`, { cwd: eventHandlerSandboxDir })

expect(stderr).to.match(
/You haven't provided an event handler name, but it is required, run with --help for usage/
Expand All @@ -62,7 +62,7 @@ describe('Event handler', () => {

context('Without event', () => {
it('should fail', async () => {
const { stderr } = await exec(`${cliPath} new:event-handler CartPaid`, { cwd: eventHandlerSandboxDir })
const { stderr } = await command(`${cliPath} new:event-handler CartPaid`, { cwd: eventHandlerSandboxDir })

expect(stderr).to.match(/You haven't provided an event, but it is required, run with --help for usage/)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
sandboxPathFor,
writeFileContent,
} from '../../helper/file-helper'
import { exec } from 'child-process-promise'
import { command } from 'execa'
// Imported from another package to avoid duplication
// It is OK-ish, since integration tests are always run in the context of the whole monorepo
import { createSandboxProject } from '../../../../cli/src/common/sandbox'
Expand All @@ -34,7 +34,7 @@ describe('Event', () => {
['boost new:event', 'Verifying project', 'Creating new event', 'Event generated'].join('(.|\n)*')
)

const { stdout } = await exec(`${cliPath} new:event CartChanged`, { cwd: eventSandboxDir })
const { stdout } = await command(`${cliPath} new:event CartChanged`, { cwd: eventSandboxDir })
expect(stdout).to.match(expectedOutputRegex)
})

Expand All @@ -43,7 +43,7 @@ describe('Event', () => {
const FILE_CART_CHANGED_EVENT = `${eventSandboxDir}/src/events/cart-changed.ts`
removeFiles([FILE_CART_CHANGED_EVENT])

await exec(`${cliPath} new:event CartChanged`, { cwd: eventSandboxDir })
await command(`${cliPath} new:event CartChanged`, { cwd: eventSandboxDir })

const expectedEventContent = loadFixture('events/cart-changed.ts')
const eventContent = readFileContent(FILE_CART_CHANGED_EVENT)
Expand All @@ -60,7 +60,7 @@ describe('Event', () => {
it('should create new event', async () => {
const FILE_CART_CHANGED_WITH_FIELDS_EVENT = `${eventSandboxDir}/src/events/cart-changed-with-fields.ts`

await exec(`${cliPath} new:event CartChangedWithFields --fields cartId:UUID sku:string quantity:number`, {
await command(`${cliPath} new:event CartChangedWithFields --fields cartId:UUID sku:string quantity:number`, {
cwd: eventSandboxDir,
})

Expand All @@ -79,7 +79,7 @@ describe('Event', () => {
context('Invalid event', () => {
describe('missing event name', () => {
it('should fail', async () => {
const { stderr } = await exec(`${cliPath} new:event`, { cwd: eventSandboxDir })
const { stderr } = await command(`${cliPath} new:event`, { cwd: eventSandboxDir })

expect(stderr).to.match(/You haven't provided an event name, but it is required, run with --help for usage/)
})
Expand Down
Loading