@@ -4,35 +4,44 @@ import glob from 'tiny-glob/sync.js';
4
4
import { load_config } from './src/core/config/index.js' ;
5
5
import * as sync from './src/core/sync/sync.js' ;
6
6
7
- const cwd = process . env . INIT_CWD ?? process . cwd ( ) ;
8
- process . chdir ( cwd ) ;
7
+ try {
8
+ const cwd = process . env . INIT_CWD ?? process . cwd ( ) ;
9
+ process . chdir ( cwd ) ;
9
10
10
- const pkg = JSON . parse ( fs . readFileSync ( 'package.json' , 'utf8' ) ) ;
11
+ if ( fs . existsSync ( 'package.json' ) ) {
12
+ const pkg = JSON . parse ( fs . readFileSync ( 'package.json' , 'utf8' ) ) ;
11
13
12
- const directories = [ ] ;
14
+ const directories = [ ] ;
13
15
14
- if ( pkg . workspaces ) {
15
- for ( const directory of pkg . workspaces ) {
16
- directories . push ( ...glob ( directory , { cwd } ) . map ( ( dir ) => path . resolve ( cwd , dir ) ) ) ;
17
- }
18
- } else {
19
- directories . push ( cwd ) ;
20
- }
16
+ if ( pkg . workspaces ) {
17
+ // we have to do this because of https://classic.yarnpkg.com/blog/2018/02/15/nohoist/
18
+ const packages = Array . isArray ( pkg . workspaces ) ? pkg . workspaces : pkg . workspaces . packages ;
21
19
22
- for ( const cwd of directories ) {
23
- process . chdir ( cwd ) ;
20
+ for ( const directory of packages ) {
21
+ directories . push ( ...glob ( directory , { cwd } ) . map ( ( dir ) => path . resolve ( cwd , dir ) ) ) ;
22
+ }
23
+ } else {
24
+ directories . push ( cwd ) ;
25
+ }
26
+
27
+ for ( const cwd of directories ) {
28
+ process . chdir ( cwd ) ;
24
29
25
- if ( ! fs . existsSync ( 'package.json' ) ) continue ;
26
- if ( ! fs . existsSync ( 'svelte.config.js' ) ) continue ;
30
+ if ( ! fs . existsSync ( 'package.json' ) ) continue ;
31
+ if ( ! fs . existsSync ( 'svelte.config.js' ) ) continue ;
27
32
28
- const pkg = JSON . parse ( fs . readFileSync ( 'package.json' , 'utf8' ) ) ;
29
- if ( ! pkg . dependencies ?. [ '@sveltejs/kit' ] && ! pkg . devDependencies ?. [ '@sveltejs/kit' ] ) continue ;
33
+ const pkg = JSON . parse ( fs . readFileSync ( 'package.json' , 'utf8' ) ) ;
34
+ if ( ! pkg . dependencies ?. [ '@sveltejs/kit' ] && ! pkg . devDependencies ?. [ '@sveltejs/kit' ] ) continue ;
30
35
31
- try {
32
- const config = await load_config ( ) ;
33
- await sync . all ( config , 'development' ) ;
34
- } catch ( e ) {
35
- console . log ( 'Error while trying to sync SvelteKit config' ) ;
36
- console . log ( e ) ;
36
+ try {
37
+ const config = await load_config ( ) ;
38
+ await sync . all ( config , 'development' ) ;
39
+ } catch ( error ) {
40
+ console . log ( 'Error while trying to sync SvelteKit config' ) ;
41
+ console . log ( error . stack ) ;
42
+ }
43
+ }
37
44
}
45
+ } catch ( error ) {
46
+ console . error ( error . stack ) ;
38
47
}
0 commit comments