File tree 3 files changed +14
-4
lines changed
3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @sveltejs/package ' : patch
3
+ ---
4
+
5
+ fix: handle missing package.json gracefully
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export async function load_config({ cwd = process.cwd() } = {}) {
29
29
30
30
/**
31
31
* @param {string } cwd
32
- * @returns Record<string, any>
32
+ * @returns { Record<string, any> }
33
33
*/
34
34
export function load_pkg_json ( cwd = process . cwd ( ) ) {
35
35
const pkg_json_file = path . join ( cwd , 'package.json' ) ;
Original file line number Diff line number Diff line change 1
- import { readFileSync } from 'node:fs' ;
2
- import { join } from 'node:path' ;
3
1
import colors from 'kleur' ;
2
+ import { load_pkg_json } from './config.js' ;
4
3
5
4
/**
6
5
* @param {import("./types.js").Options } options
@@ -19,8 +18,14 @@ export function create_validator(options) {
19
18
} ,
20
19
validate ( ) {
21
20
/** @type {Record<string, any> } */
22
- const pkg = JSON . parse ( readFileSync ( join ( options . cwd , 'package.json' ) , 'utf-8' ) ) ;
21
+ const pkg = load_pkg_json ( options . cwd ) ;
23
22
const warnings = validate ( pkg ) ;
23
+ if ( Object . keys ( pkg ) . length === 0 ) {
24
+ warnings . push (
25
+ 'No package.json found in the current directory. Please create one or run this command in a directory containing one.'
26
+ ) ;
27
+ }
28
+
24
29
// Just warnings, not errors, because
25
30
// - would be annoying in watch mode (would have to restart the server)
26
31
// - maybe there's a custom post-build script that fixes some of these
You can’t perform that action at this time.
0 commit comments