Skip to content

Commit 21ddb90

Browse files
committed
fix: install in action dist directory
1 parent 4c79631 commit 21ddb90

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/util/install.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ export function install(packages: string[], log: (msg: string) => void): Promise
1616
if (missing.length) {
1717
log(`Install ${JSON.stringify(missing)}`)
1818

19+
// if logging function is core.info, we're in debug/test
20+
const isDebug = log === info
21+
1922
const args = ['install', '--no-save']
20-
if (log !== info) { // if logging function is core.info, we're in debug/test
23+
if (!isDebug) {
2124
args.push('--silent')
2225
}
2326
args.push('--', ...missing)
2427

25-
return spawn('npm', args, {})
28+
return spawn('npm', args, {
29+
cwd: __dirname,
30+
})
2631
}
2732

2833
return Promise.resolve('')

test/util/install.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
import { SpawnOptions } from 'child_process'
2+
import path from 'path'
13
import { install } from '../../src/util/install'
24

35
let resolveMock: jest.MockedFunction<(name: string) => string>
46
jest.mock('../../src/util/resolve', () => ({
57
resolve: (name: string) => resolveMock(name),
68
}))
79

8-
let spawnMock: jest.MockedFn<(cmd: string, args: string[]) => Promise<string>>
10+
let spawnMock: jest.MockedFn<(cmd: string, args: string[], opt: SpawnOptions) => Promise<string>>
911
jest.mock('../../src/util/spawn', () => ({
10-
spawn: (cmd: string, args: string[]) => spawnMock(cmd, args),
12+
spawn: (cmd: string, args: string[], opt: SpawnOptions) => spawnMock(cmd, args, opt),
1113
}))
1214

1315
test('skip present modules', async () => {
@@ -42,3 +44,15 @@ test('install missing modules', async () => {
4244
expect(spawnMock.mock.calls[0][1]).toContain('bar')
4345
expect(log).toEqual([expect.stringContaining('Install ["foo","bar"]')])
4446
})
47+
48+
test('install in dist', async () => {
49+
spawnMock = jest.fn()
50+
51+
await install(['foo'], () => undefined)
52+
53+
expect(spawnMock).toBeCalledTimes(1)
54+
expect(spawnMock.mock.calls[0][2]).toEqual(expect.objectContaining({
55+
// In test this should be the directory of the `install` util
56+
cwd: path.resolve(__dirname, '../../src/util'),
57+
}))
58+
})

0 commit comments

Comments
 (0)