File tree Expand file tree Collapse file tree 6 files changed +18
-14
lines changed Expand file tree Collapse file tree 6 files changed +18
-14
lines changed Original file line number Diff line number Diff line change @@ -148,7 +148,7 @@ const createViteServer = async ({
148
148
source : code ,
149
149
rootPath : root ,
150
150
filePath : id ,
151
- packageName : pkg . name ,
151
+ packageName : pkg ? .name ,
152
152
identOption : identifiers ,
153
153
globalAdapterIdentifier,
154
154
} ) ;
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ interface AddFileScopeParams {
11
11
source : string ;
12
12
filePath : string ;
13
13
rootPath : string ;
14
- packageName : string ;
14
+ packageName ? : string ;
15
15
globalAdapterIdentifier ?: string ;
16
16
}
17
17
export function addFileScope ( {
@@ -29,20 +29,26 @@ export function addFileScope({
29
29
if ( source . includes ( '@vanilla-extract/css/fileScope' ) ) {
30
30
source = source . replace (
31
31
/ s e t F i l e S c o p e \( ( ( \n | .) * ?) \) / ,
32
- `setFileScope("${ normalizedPath } ", "${ packageName } ")` ,
32
+ `setFileScope("${ normalizedPath } "${
33
+ packageName ? `, "${ packageName } "` : ''
34
+ } )`,
33
35
) ;
34
36
} else {
35
37
if ( hasESM && ! isMixed ) {
36
38
source = dedent ( `
37
39
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
38
- setFileScope("${ normalizedPath } ", "${ packageName } ");
40
+ setFileScope("${ normalizedPath } "${
41
+ packageName ? `, "${ packageName } "` : ''
42
+ } );
39
43
${ source }
40
44
endFileScope();
41
45
` ) ;
42
46
} else {
43
47
source = dedent ( `
44
48
const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
45
- __vanilla_filescope__.setFileScope("${ normalizedPath } ", "${ packageName } ");
49
+ __vanilla_filescope__.setFileScope("${ normalizedPath } "${
50
+ packageName ? `, "${ packageName } "` : ''
51
+ } );
46
52
${ source }
47
53
__vanilla_filescope__.endFileScope();
48
54
` ) ;
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export const vanillaExtractTransformPlugin = ({
29
29
source : originalSource ,
30
30
filePath : path ,
31
31
rootPath : build . initialOptions . absWorkingDir ! ,
32
- packageName : packageInfo . name ,
32
+ packageName : packageInfo ? .name ,
33
33
identOption :
34
34
identOption ?? ( build . initialOptions . minify ? 'short' : 'debug' ) ,
35
35
} ) ;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export interface PackageInfo {
8
8
dirname : string ;
9
9
}
10
10
11
- function getClosestPackageInfo ( directory : string ) {
11
+ function getClosestPackageInfo ( directory : string ) : PackageInfo | undefined {
12
12
const packageJsonPath = findUp . sync ( 'package.json' , {
13
13
cwd : directory ,
14
14
} ) ;
@@ -26,7 +26,7 @@ function getClosestPackageInfo(directory: string) {
26
26
27
27
const packageInfoCache = new Map < string , PackageInfo > ( ) ;
28
28
29
- export function getPackageInfo ( cwd ?: string | null ) : PackageInfo {
29
+ export function getPackageInfo ( cwd ?: string | null ) : PackageInfo | undefined {
30
30
const resolvedCwd = cwd ?? process . cwd ( ) ;
31
31
const cachedValue = packageInfoCache . get ( resolvedCwd ) ;
32
32
@@ -43,9 +43,7 @@ export function getPackageInfo(cwd?: string | null): PackageInfo {
43
43
}
44
44
45
45
if ( ! packageInfo || ! packageInfo . name ) {
46
- throw new Error (
47
- `Couldn't find parent package.json with a name field from '${ resolvedCwd } '` ,
48
- ) ;
46
+ return undefined ;
49
47
}
50
48
51
49
packageInfoCache . set ( resolvedCwd , packageInfo ) ;
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ interface TransformParams {
10
10
source : string ;
11
11
filePath : string ;
12
12
rootPath : string ;
13
- packageName : string ;
13
+ packageName ? : string ;
14
14
identOption : IdentifierOption ;
15
15
globalAdapterIdentifier ?: string ;
16
16
}
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ export function vanillaExtractPlugin({
65
65
let config : ResolvedConfig ;
66
66
let configEnv : ConfigEnv ;
67
67
let server : ViteDevServer ;
68
- let packageName : string ;
68
+ let packageName : string | undefined ;
69
69
let compiler : Compiler | undefined ;
70
70
const vitePromise = import ( 'vite' ) ;
71
71
@@ -127,7 +127,7 @@ export function vanillaExtractPlugin({
127
127
} ,
128
128
async configResolved ( _resolvedConfig ) {
129
129
config = _resolvedConfig ;
130
- packageName = getPackageInfo ( config . root ) . name ;
130
+ packageName = getPackageInfo ( config . root ) ? .name ;
131
131
} ,
132
132
async buildStart ( ) {
133
133
// Ensure we re-use the compiler instance between builds, e.g. in watch mode
You can’t perform that action at this time.
0 commit comments