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 ({
148148 source : code ,
149149 rootPath : root ,
150150 filePath : id ,
151- packageName : pkg . name ,
151+ packageName : pkg ? .name ,
152152 identOption : identifiers ,
153153 globalAdapterIdentifier,
154154 } ) ;
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ interface AddFileScopeParams {
1111 source : string ;
1212 filePath : string ;
1313 rootPath : string ;
14- packageName : string ;
14+ packageName ? : string ;
1515 globalAdapterIdentifier ?: string ;
1616}
1717export function addFileScope ( {
@@ -29,20 +29,26 @@ export function addFileScope({
2929 if ( source . includes ( '@vanilla-extract/css/fileScope' ) ) {
3030 source = source . replace (
3131 / s e t F i l e S c o p e \( ( ( \n | .) * ?) \) / ,
32- `setFileScope("${ normalizedPath } ", "${ packageName } ")` ,
32+ `setFileScope("${ normalizedPath } "${
33+ packageName ? `, "${ packageName } "` : ''
34+ } )`,
3335 ) ;
3436 } else {
3537 if ( hasESM && ! isMixed ) {
3638 source = dedent ( `
3739 import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
38- setFileScope("${ normalizedPath } ", "${ packageName } ");
40+ setFileScope("${ normalizedPath } "${
41+ packageName ? `, "${ packageName } "` : ''
42+ } );
3943 ${ source }
4044 endFileScope();
4145 ` ) ;
4246 } else {
4347 source = dedent ( `
4448 const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
45- __vanilla_filescope__.setFileScope("${ normalizedPath } ", "${ packageName } ");
49+ __vanilla_filescope__.setFileScope("${ normalizedPath } "${
50+ packageName ? `, "${ packageName } "` : ''
51+ } );
4652 ${ source }
4753 __vanilla_filescope__.endFileScope();
4854 ` ) ;
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export const vanillaExtractTransformPlugin = ({
2929 source : originalSource ,
3030 filePath : path ,
3131 rootPath : build . initialOptions . absWorkingDir ! ,
32- packageName : packageInfo . name ,
32+ packageName : packageInfo ? .name ,
3333 identOption :
3434 identOption ?? ( build . initialOptions . minify ? 'short' : 'debug' ) ,
3535 } ) ;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export interface PackageInfo {
88 dirname : string ;
99}
1010
11- function getClosestPackageInfo ( directory : string ) {
11+ function getClosestPackageInfo ( directory : string ) : PackageInfo | undefined {
1212 const packageJsonPath = findUp . sync ( 'package.json' , {
1313 cwd : directory ,
1414 } ) ;
@@ -26,7 +26,7 @@ function getClosestPackageInfo(directory: string) {
2626
2727const packageInfoCache = new Map < string , PackageInfo > ( ) ;
2828
29- export function getPackageInfo ( cwd ?: string | null ) : PackageInfo {
29+ export function getPackageInfo ( cwd ?: string | null ) : PackageInfo | undefined {
3030 const resolvedCwd = cwd ?? process . cwd ( ) ;
3131 const cachedValue = packageInfoCache . get ( resolvedCwd ) ;
3232
@@ -43,9 +43,7 @@ export function getPackageInfo(cwd?: string | null): PackageInfo {
4343 }
4444
4545 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 ;
4947 }
5048
5149 packageInfoCache . set ( resolvedCwd , packageInfo ) ;
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ interface TransformParams {
1010 source : string ;
1111 filePath : string ;
1212 rootPath : string ;
13- packageName : string ;
13+ packageName ? : string ;
1414 identOption : IdentifierOption ;
1515 globalAdapterIdentifier ?: string ;
1616}
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ export function vanillaExtractPlugin({
6565 let config : ResolvedConfig ;
6666 let configEnv : ConfigEnv ;
6767 let server : ViteDevServer ;
68- let packageName : string ;
68+ let packageName : string | undefined ;
6969 let compiler : Compiler | undefined ;
7070 const vitePromise = import ( 'vite' ) ;
7171
@@ -127,7 +127,7 @@ export function vanillaExtractPlugin({
127127 } ,
128128 async configResolved ( _resolvedConfig ) {
129129 config = _resolvedConfig ;
130- packageName = getPackageInfo ( config . root ) . name ;
130+ packageName = getPackageInfo ( config . root ) ? .name ;
131131 } ,
132132 async buildStart ( ) {
133133 // 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