File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ import { expect , test } from "vitest" ;
2+ import { packageId } from "./package-id" ;
3+
4+ test ( "bare package, root subpath" , ( ) => {
5+ expect ( packageId ( "foo" , "." ) ) . toMatchInlineSnapshot ( `"foo"` ) ;
6+ } ) ;
7+
8+ test ( "scoped package, root subpath" , ( ) => {
9+ expect ( packageId ( "@foo/bar" , "." ) ) . toMatchInlineSnapshot ( `"@foo/bar"` ) ;
10+ } ) ;
11+
12+ test ( "bare package, other subpath" , ( ) => {
13+ expect ( packageId ( "foo" , "my/subpath" ) ) . toMatchInlineSnapshot ( `"foo/my/subpath"` ) ;
14+ } ) ;
15+
16+ test ( "scoped package, other subpath" , ( ) => {
17+ expect ( packageId ( "@foo/bar" , "my/subpath" ) ) . toMatchInlineSnapshot ( `"@foo/bar/my/subpath"` ) ;
18+ } ) ;
Original file line number Diff line number Diff line change 1+ export function packageId ( pkg : string , subpath : string ) : string {
2+ // Assume subpath was already normalized.
3+ if ( subpath === "." ) return pkg ;
4+ return `${ pkg } /${ subpath } ` ;
5+ }
You can’t perform that action at this time.
0 commit comments