Skip to content

Commit

Permalink
fix: fix shellUtils stubbing with ES modules (#983)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
ehmicky and kodiakhq[bot] committed Feb 8, 2022
1 parent fe96bc0 commit dc12508
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/runtimes/go/builder.ts
@@ -1,14 +1,14 @@
import { promises as fs } from 'fs'
import { basename } from 'path'

import { runCommand } from '../../utils/shell'
import { shellUtils } from '../../utils/shell'
import type { RuntimeName } from '../runtime'

const build = async ({ destPath, mainFile, srcDir }: { destPath: string; mainFile: string; srcDir: string }) => {
const functionName = basename(srcDir)

try {
await runCommand('go', ['build', '-o', destPath, '-ldflags', '-s -w'], {
await shellUtils.runCommand('go', ['build', '-o', destPath, '-ldflags', '-s -w'], {
cwd: srcDir,
env: {
CGO_ENABLED: '0',
Expand Down
10 changes: 5 additions & 5 deletions src/runtimes/rust/builder.ts
Expand Up @@ -5,7 +5,7 @@ import tmp from 'tmp-promise'
import toml from 'toml'

import { FunctionConfig } from '../../config'
import { runCommand } from '../../utils/shell'
import { shellUtils } from '../../utils/shell'
import type { RuntimeName } from '../runtime'

import { CargoManifest } from './cargo_manifest'
Expand Down Expand Up @@ -55,7 +55,7 @@ const cargoBuild = async ({
targetDirectory: string
}) => {
try {
await runCommand('cargo', ['build', '--target', BUILD_TARGET, '--release'], {
await shellUtils.runCommand('cargo', ['build', '--target', BUILD_TARGET, '--release'], {
cwd: srcDir,
env: {
CARGO_TARGET_DIR: targetDirectory,
Expand All @@ -79,7 +79,7 @@ const cargoBuild = async ({

const checkRustToolchain = async () => {
try {
await runCommand('cargo', ['-V'])
await shellUtils.runCommand('cargo', ['-V'])

return true
} catch {
Expand Down Expand Up @@ -113,8 +113,8 @@ let toolchainInstallation: Promise<void>
// `BUILD_TARGET`. The Promise is saved to `toolchainInstallation`, so
// that we run the command just once for multiple Rust functions.
const installToolchain = async () => {
await runCommand('rustup', ['default', 'stable'])
await runCommand('rustup', ['target', 'add', BUILD_TARGET])
await shellUtils.runCommand('rustup', ['default', 'stable'])
await shellUtils.runCommand('rustup', ['target', 'add', BUILD_TARGET])
}

const installToolchainOnce = () => {
Expand Down
3 changes: 1 addition & 2 deletions src/utils/shell.ts
@@ -1,4 +1,3 @@
import execa from 'execa'

// eslint-disable-next-line unicorn/prefer-export-from
export { execa as runCommand }
export const shellUtils = { runCommand: execa }
2 changes: 1 addition & 1 deletion tests/main.js
Expand Up @@ -22,7 +22,7 @@ require('source-map-support').install()
// We must require this file first because we need to stub it before the main
// functions are required.
// eslint-disable-next-line import/order
const shellUtils = require('../dist/utils/shell')
const { shellUtils } = require('../dist/utils/shell')

const shellUtilsStub = sinon.stub(shellUtils, 'runCommand')

Expand Down

1 comment on commit dc12508

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

largeDepsEsbuild: 7.5s

largeDepsZisi: 56.9s

Please sign in to comment.