Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

fix: fix shellUtils stubbing with ES modules #983

Merged
merged 3 commits into from
Feb 8, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/runtimes/go/builder.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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