Skip to content

Commit

Permalink
feat: allow peerDeps as import entry points (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
beerose authored Jan 27, 2022
1 parent f8f7ce2 commit 755981d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export function validateDependencies (ctx: BuildContext) {
if (
!ctx.options.externals.includes(id) &&
!id.startsWith('chunks/') &&
!ctx.options.dependencies.includes(getpkg(id))
!ctx.options.dependencies.includes(getpkg(id)) &&
!ctx.options.peerDependencies.includes(getpkg(id))
) {
implicitDependnecies.add(id)
}
Expand Down
76 changes: 75 additions & 1 deletion test/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import jiti from 'jiti'
import { expect } from 'chai'
import consola from 'consola'
import { join } from 'pathe'
import { validateDependencies } from '../src/validate'
import { BuildEntry } from '../src/types'

const { validatePackage } = jiti(import.meta.url)('../src/validate') as typeof import('../src/validate')

describe('validatePackage', () => {
it('detects missing files', () => {
const logs: string[] = []
consola.mock(type => type === 'warn' ? (str: string) => logs.push(str) : () => {})
consola.mock(type => type === 'warn' ? (str: string) => logs.push(str) : () => { })

validatePackage({
main: './dist/test',
Expand All @@ -31,3 +33,75 @@ describe('validatePackage', () => {
}
})
})

describe('validateDependecies', () => {
it('detects implicit deps', () => {
const logs: string[] = []
consola.mock(type => type === 'warn' ? (str: string) => logs.push(str) : () => { })

validateDependencies({
pkg: {},
buildEntries: [],
hooks: [] as any,
usedImports: new Set(['pkg-a/core']),
options: {
externals: [],
dependencies: ['react'],
peerDependencies: [],
devDependencies: [],
rootDir: '.',
entries: [] as BuildEntry[],
clean: false,
outDir: 'dist',
stub: false,
alias: {},
replace: {},
rollup: {
replace: false,
alias: false,
resolve: false,
json: false,
esbuild: false,
commonjs: false
}
}
})

expect(logs[0]).to.include('Potential implicit dependencies found:')
})

it('does not print implicit deps warning for peerDependencies', () => {
const logs: string[] = []
consola.mock(type => type === 'warn' ? (str: string) => logs.push(str) : () => { })

validateDependencies({
pkg: {},
buildEntries: [],
hooks: [] as any,
usedImports: new Set(['pkg-a/core']),
options: {
externals: [],
dependencies: ['react'],
peerDependencies: ['pkg-a'],
devDependencies: [],
rootDir: '.',
entries: [] as BuildEntry[],
clean: false,
outDir: 'dist',
stub: false,
alias: {},
replace: {},
rollup: {
replace: false,
alias: false,
resolve: false,
json: false,
esbuild: false,
commonjs: false
}
}
})

expect(logs.length).to.eq(0)
})
})

0 comments on commit 755981d

Please sign in to comment.