Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions packages/generators/src/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,17 @@ export const install =
const packageManager = await getCallable(packager, ctx)
const flags = dev ? [packageManager === 'yarn' ? '--dev' : '--save-dev'] : []

if (packageManager === 'pnpm') {
// Approve only the build scripts required by SQLite and the CLI's TypeScript loader.
const buildDependencies = { sqlite3: 'sqlite3', '@feathersjs/cli': 'esbuild' }

for (const [dependency, buildDependency] of Object.entries(buildDependencies)) {
if (dependencyList.some((name) => name === dependency || name.startsWith(`${dependency}@`))) {
flags.push(`--allow-build=${buildDependency}`)
}
}
}

return exec(packager, [packageManager === 'yarn' ? 'add' : 'install', ...dependencyList, ...flags])(ctx)
}

Expand Down
90 changes: 90 additions & 0 deletions packages/generators/test/install.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { deepStrictEqual, rejects, strictEqual } from 'assert'
import { getContext } from '@featherscloud/pinion'
import { install } from '../lib/commons'

describe('install dependencies', () => {
for (const packager of ['npm', 'yarn', 'pnpm']) {
for (const dev of [false, true]) {
it(`installs ${dev ? 'development' : 'production'} dependencies with ${packager}`, async () => {
const dependencies = ['knex', 'pg', 'sqlite3-other', '@feathersjs/client']
const calls: { command: string; args: string[] }[] = []
const ctx = getContext(
{ language: 'ts' as const },
{
exec: async (command, args) => {
calls.push({ command, args })
return 0
}
}
)
const result = await install(
() => dependencies,
dev,
() => packager
)(ctx)

strictEqual(result, ctx)
deepStrictEqual(calls, [
{
command: packager,
args: [
packager === 'yarn' ? 'add' : 'install',
...dependencies,
...(dev ? [packager === 'yarn' ? '--dev' : '--save-dev'] : [])
]
}
])
})
}

for (const [dependency, buildDependency] of [
['sqlite3', 'sqlite3'],
['sqlite3@^6.0.1', 'sqlite3'],
['@feathersjs/cli', 'esbuild'],
['@feathersjs/cli@5.0.50', 'esbuild']
]) {
it(`allows required build scripts when installing ${dependency} with ${packager}`, async () => {
const dependencies = ['knex', dependency]
const dev = buildDependency === 'esbuild'
const calls: { command: string; args: string[] }[] = []
const ctx = getContext(
{ language: 'ts' as const },
{
exec: async (command, args) => {
calls.push({ command, args })
return 0
}
}
)

await install(dependencies, dev, packager)(ctx)

deepStrictEqual(calls, [
{
command: packager,
args: [
packager === 'yarn' ? 'add' : 'install',
...dependencies,
...(dev ? [packager === 'yarn' ? '--dev' : '--save-dev'] : []),
...(packager === 'pnpm' ? [`--allow-build=${buildDependency}`] : [])
]
}
])
})
}
}

it('does not swallow installation failures', async () => {
const error = new Error('Installation failed')
const ctx = getContext(
{ language: 'ts' as const },
{
exec: async () => {
throw error
}
}
)

await rejects(install(['sqlite3'], false, 'pnpm')(ctx), (actual) => actual === error)
})
})
Loading