1- // @ts -check
2-
31import fs from 'node:fs' ;
42import path from 'node:path' ;
5- import { getToolVersion , hasJestConfig } from './src/preinstall/tool-versions.js' ;
3+ import { getToolVersion , hasJestConfig } from './src/preinstall/tool-versions.ts' ;
4+ import type { PackageManifest } from './src/utils/projectRoot.ts' ;
65
7- /**
8- * @typedef {() => boolean } ConditionalCheck
9- */
6+ type ConditionalCheck = ( ) => boolean ;
107
118/**
129 * Conditionally add a dependency to the given dependencies object if it is not already present
13- * @param {string[] } depsToAdd
14- * @param {import('./src/utils/projectRoot.ts').PackageManifest } manifest
15- * @param {ConditionalCheck | boolean | undefined } condition
16- * @returns {Record<string, string> }
1710 */
18- function conditionallyAdd ( depsToAdd , manifest , condition ) {
19- /** @type {Record<string, string> } */
20- const newDeps = { } ;
11+ function conditionallyAdd (
12+ depsToAdd : string [ ] ,
13+ manifest : PackageManifest ,
14+ condition : ConditionalCheck | boolean | undefined ,
15+ ) : Record < string , string > {
16+ const newDeps : Record < string , string > = { } ;
2117 if ( ! condition || ( typeof condition === 'function' ? condition ( ) : condition ) ) {
2218 for ( const dep of depsToAdd ) {
2319 if ( ! manifest . dependencies ?. [ dep ] && ! manifest . devDependencies ?. [ dep ] ) {
@@ -36,29 +32,23 @@ function conditionallyAdd(depsToAdd, manifest, condition) {
3632}
3733
3834/**
39- * @param {import('./src/utils/projectRoot.ts').PackageManifest } manifest - The package manifest.
40- * @returns {boolean } true if oxfmt should be added based on the manifest's prettier scripts
35+ * Returns true if oxfmt should be added based on the manifest's prettier scripts.
4136 */
42- function addOxfmt ( manifest ) {
37+ function addOxfmt ( manifest : PackageManifest ) : boolean {
4338 return Boolean ( manifest && manifest . scripts && ( manifest . scripts . format || manifest . scripts [ 'format:fix' ] ) ) ;
4439}
4540
4641/**
4742 * Check if Jest is already in the manifest or if a Jest script is defined.
48- * @param {string } cwd - The current working directory.
49- * @param {import('./src/utils/projectRoot.ts').PackageManifest } manifest - The package manifest.
50- * @returns {boolean } - True if Jest should be added, false otherwise.
5143 */
52- function addJest ( cwd , manifest ) {
44+ function addJest ( cwd : string , manifest : PackageManifest ) : boolean {
5345 return Boolean ( manifest . scripts ?. test && hasJestConfig ( cwd ) ) ;
5446}
5547
5648/**
5749 * Get the dynamic dependencies for the given package given the package root directory and its manifest.
58- * @param {{cwd: string, manifest: import('./src/utils/projectRoot.ts').PackageManifest} } param0
59- * @returns { { dependencies: Record<string, string> } }
6050 */
61- export default function ( { cwd, manifest } ) {
51+ export default function ( { cwd, manifest } : { cwd : string ; manifest : PackageManifest } ) : { dependencies : Record < string , string > } {
6252 const enableLinting = Boolean ( manifest . scripts && manifest . scripts . lint ) ;
6353
6454 return {
0 commit comments