8
8
echo ,
9
9
exit ,
10
10
getPackageJSON ,
11
+ getPackageJSONDependencies ,
11
12
readFile ,
12
13
} from "isaacscript-common-node" ;
13
14
import { isKebabCase } from "isaacscript-common-ts" ;
@@ -229,12 +230,6 @@ function packageJSONLint(
229
230
}
230
231
}
231
232
232
- const { files } = packageJSON ;
233
- if ( files !== undefined ) {
234
- echo ( `File has a "files" field: ${ packageJSONPath } ` ) ;
235
- return false ;
236
- }
237
-
238
233
if ( ! isTemplateFile && rootDeps !== undefined ) {
239
234
const { dependencies } = packageJSON ;
240
235
if ( ! checkDeps ( dependencies , rootDeps , packageJSONPath ) ) {
@@ -255,24 +250,17 @@ function packageJSONLint(
255
250
256
251
/** Gets the dependencies of the root monorepo "package.json" file. */
257
252
function getDeps ( packageJSONPath : string ) : Record < string , string > {
258
- const packageJSONString = readFile ( packageJSONPath ) ;
259
- const packageJSON = getPackageJSON ( packageJSONString ) ;
260
-
261
- let { dependencies, devDependencies, peerDependencies } = packageJSON ;
262
- if ( typeof dependencies !== "object" ) {
263
- dependencies = { } ;
264
- }
265
- if ( typeof devDependencies !== "object" ) {
266
- devDependencies = { } ;
267
- }
268
- if ( typeof peerDependencies !== "object" ) {
269
- peerDependencies = { } ;
270
- }
253
+ const dependencies =
254
+ getPackageJSONDependencies ( packageJSONPath , "dependencies" ) ?? { } ;
255
+ const devDependencies =
256
+ getPackageJSONDependencies ( packageJSONPath , "devDependencies" ) ?? { } ;
257
+ const peerDependencies =
258
+ getPackageJSONDependencies ( packageJSONPath , "peerDependencies" ) ?? { } ;
271
259
272
260
const deps = {
273
- ...( dependencies as Record < string , string > ) ,
274
- ...( devDependencies as Record < string , string > ) ,
275
- ...( peerDependencies as Record < string , string > ) ,
261
+ ...dependencies ,
262
+ ...devDependencies ,
263
+ ...peerDependencies ,
276
264
} ;
277
265
278
266
// `eslint-plugin-isaacscript` is not a root dependency of the monorepo, so it has to be
@@ -292,8 +280,7 @@ function getVersionForSpecificPackage(packageName: string): string {
292
280
packageName ,
293
281
"package.json" ,
294
282
) ;
295
- const packageJSONString = readFile ( packageJSONPath ) ;
296
- const packageJSON = getPackageJSON ( packageJSONString ) ;
283
+ const packageJSON = getPackageJSON ( packageJSONPath ) ;
297
284
const packageVersion = packageJSON [ "version" ] ;
298
285
if ( typeof packageVersion !== "string" ) {
299
286
throw new TypeError ( `Failed to parse the version from: ${ packageJSONPath } ` ) ;
@@ -325,8 +312,7 @@ function checkDeps(
325
312
key ,
326
313
PACKAGE_JSON ,
327
314
) ;
328
- const depPackageJSONString = readFile ( depPackageJSONPath ) ;
329
- const depPackageJSON = getPackageJSON ( depPackageJSONString ) ;
315
+ const depPackageJSON = getPackageJSON ( depPackageJSONPath ) ;
330
316
const depVersion = depPackageJSON [ "version" ] ;
331
317
if ( typeof depVersion !== "string" ) {
332
318
throw new TypeError (
@@ -360,8 +346,7 @@ function checkRootDepsUpToDate(
360
346
continue ;
361
347
}
362
348
363
- const packageJSONString = readFile ( matchingPackageJSONPath ) ;
364
- const packageJSON = getPackageJSON ( packageJSONString ) ;
349
+ const packageJSON = getPackageJSON ( matchingPackageJSONPath ) ;
365
350
366
351
const { version } = packageJSON ;
367
352
if ( typeof version !== "string" || version === "" ) {
0 commit comments