@@ -10,6 +10,20 @@ import { knownDevicePcas } from '../device';
1010import { nrfModules , semver } from '../MetaFiles' ;
1111import { parseWithPrettifiedErrorMessage } from './parseJson' ;
1212
13+ const packageJson = z . object ( {
14+ name : z . string ( ) ,
15+ version : semver ,
16+
17+ displayName : z . string ( ) . optional ( ) ,
18+ } ) ;
19+
20+ export type PackageJson = z . infer < typeof packageJson > ;
21+
22+ export const parsePackageJson =
23+ parseWithPrettifiedErrorMessage < PackageJson > ( packageJson ) ;
24+
25+ // Apps have more required fields in their package.json
26+
1327const nrfConnectForDesktop = z . object ( {
1428 supportedDevices : z . enum ( knownDevicePcas ) . array ( ) . nonempty ( ) . optional ( ) ,
1529 nrfutil : nrfModules . optional ( ) ,
@@ -22,12 +36,7 @@ const engines = recordOfOptionalStrings.and(
2236 z . object ( { nrfconnect : z . string ( ) } )
2337) ;
2438
25- const packageJson = z . object ( {
26- name : z . string ( ) ,
27- version : semver ,
28-
29- author : z . string ( ) . optional ( ) ,
30- bin : z . string ( ) . or ( recordOfOptionalStrings ) . optional ( ) ,
39+ const packageJsonApp = packageJson . extend ( {
3140 dependencies : recordOfOptionalStrings . optional ( ) ,
3241 description : z . string ( ) ,
3342 homepage : z . string ( ) . url ( ) . optional ( ) ,
@@ -36,34 +45,29 @@ const packageJson = z.object({
3645 engines,
3746 nrfConnectForDesktop,
3847 files : z . string ( ) . array ( ) . optional ( ) ,
39- license : z . string ( ) . optional ( ) ,
40- main : z . string ( ) . optional ( ) ,
4148 peerDependencies : recordOfOptionalStrings . optional ( ) ,
4249 repository : z
4350 . object ( {
4451 type : z . string ( ) ,
4552 url : z . string ( ) . url ( ) ,
4653 } )
4754 . optional ( ) ,
48- scripts : recordOfOptionalStrings . optional ( ) ,
4955} ) ;
5056
51- export type PackageJson = z . infer < typeof packageJson > ;
57+ export type PackageJsonApp = z . infer < typeof packageJsonApp > ;
5258
53- export const parsePackageJson =
54- parseWithPrettifiedErrorMessage < PackageJson > ( packageJson ) ;
59+ export const parsePackageJsonApp =
60+ parseWithPrettifiedErrorMessage < PackageJsonApp > ( packageJsonApp ) ;
5561
5662// In the launcher we want to handle that the whole nrfConnectForDesktop may be missing
5763// and the html in it can also be undefined, so there we need to use this legacy variant
58- const legacyPackageJson = packageJson . merge (
59- z . object ( {
60- nrfConnectForDesktop : nrfConnectForDesktop
61- . partial ( { html : true } )
62- . optional ( ) ,
63- } )
64- ) ;
64+ const packageJsonLegacyApp = packageJsonApp . extend ( {
65+ nrfConnectForDesktop : nrfConnectForDesktop
66+ . partial ( { html : true } )
67+ . optional ( ) ,
68+ } ) ;
6569
66- export type LegacyPackageJson = z . infer < typeof legacyPackageJson > ;
70+ export type PackageJsonLegacyApp = z . infer < typeof packageJsonLegacyApp > ;
6771
68- export const parseLegacyPackageJson =
69- parseWithPrettifiedErrorMessage < LegacyPackageJson > ( legacyPackageJson ) ;
72+ export const parsePackageJsonLegacyApp =
73+ parseWithPrettifiedErrorMessage < PackageJsonLegacyApp > ( packageJsonLegacyApp ) ;
0 commit comments