77 normalizeOptions ,
88} from '../src/utils' ;
99import type { CLIOptions , PackageManager } from '../src/types' ;
10+ import fs from 'node:fs' ;
11+ import os from 'node:os' ;
12+ import path from 'node:path' ;
1013
1114describe ( 'utils' , ( ) => {
1215 const packageManagers = [ 'npm' , 'pnpm' , 'yarn' ] ;
@@ -21,9 +24,6 @@ describe('utils', () => {
2124 originalCwd = process . cwd ( ) ;
2225
2326 // Create temporary directory for each test
24- const fs = require ( 'fs' ) ;
25- const os = require ( 'os' ) ;
26- const path = require ( 'path' ) ;
2727 tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'pm-test-' ) ) ;
2828 process . chdir ( tempDir ) ;
2929 } ) ;
@@ -39,7 +39,6 @@ describe('utils', () => {
3939 // Restore working directory and cleanup
4040 process . chdir ( originalCwd ) ;
4141 try {
42- const fs = require ( 'fs' ) ;
4342 fs . rmSync ( tempDir , { recursive : true , force : true } ) ;
4443 } catch ( error ) {
4544 // Ignore cleanup errors
@@ -48,33 +47,28 @@ describe('utils', () => {
4847
4948 describe ( 'lock file detection' , ( ) => {
5049 it ( 'should detect pnpm from pnpm-lock.yaml' , ( ) => {
51- const fs = require ( 'fs' ) ;
5250 fs . writeFileSync ( 'pnpm-lock.yaml' , 'lockfileVersion: 5.4' ) ;
5351 expect ( detectActivePackageManager ( ) ) . to . equal ( 'pnpm' ) ;
5452 } ) ;
5553
5654 it ( 'should detect yarn from yarn.lock' , ( ) => {
57- const fs = require ( 'fs' ) ;
5855 fs . writeFileSync ( 'yarn.lock' , '# yarn lockfile v1' ) ;
5956 expect ( detectActivePackageManager ( ) ) . to . equal ( 'yarn' ) ;
6057 } ) ;
6158
6259 it ( 'should detect npm from package-lock.json' , ( ) => {
63- const fs = require ( 'fs' ) ;
6460 fs . writeFileSync ( 'package-lock.json' , '{"lockfileVersion": 2}' ) ;
6561 expect ( detectActivePackageManager ( ) ) . to . equal ( 'npm' ) ;
6662 } ) ;
6763
6864 it ( 'should prioritize pnpm-lock.yaml over other lock files' , ( ) => {
69- const fs = require ( 'fs' ) ;
7065 fs . writeFileSync ( 'pnpm-lock.yaml' , 'lockfileVersion: 5.4' ) ;
7166 fs . writeFileSync ( 'yarn.lock' , '# yarn lockfile v1' ) ;
7267 fs . writeFileSync ( 'package-lock.json' , '{"lockfileVersion": 2}' ) ;
7368 expect ( detectActivePackageManager ( ) ) . to . equal ( 'pnpm' ) ;
7469 } ) ;
7570
7671 it ( 'should prioritize yarn.lock over package-lock.json' , ( ) => {
77- const fs = require ( 'fs' ) ;
7872 fs . writeFileSync ( 'yarn.lock' , '# yarn lockfile v1' ) ;
7973 fs . writeFileSync ( 'package-lock.json' , '{"lockfileVersion": 2}' ) ;
8074 expect ( detectActivePackageManager ( ) ) . to . equal ( 'yarn' ) ;
@@ -83,28 +77,24 @@ describe('utils', () => {
8377
8478 describe ( 'package.json packageManager field detection' , ( ) => {
8579 it ( 'should detect pnpm from package.json packageManager field' , ( ) => {
86- const fs = require ( 'fs' ) ;
8780 const packageJson = { packageManager : 'pnpm@8.6.0' } ;
8881 fs . writeFileSync ( 'package.json' , JSON . stringify ( packageJson ) ) ;
8982 expect ( detectActivePackageManager ( ) ) . to . equal ( 'pnpm' ) ;
9083 } ) ;
9184
9285 it ( 'should detect yarn from package.json packageManager field' , ( ) => {
93- const fs = require ( 'fs' ) ;
9486 const packageJson = { packageManager : 'yarn@1.22.19' } ;
9587 fs . writeFileSync ( 'package.json' , JSON . stringify ( packageJson ) ) ;
9688 expect ( detectActivePackageManager ( ) ) . to . equal ( 'yarn' ) ;
9789 } ) ;
9890
9991 it ( 'should detect npm from package.json packageManager field' , ( ) => {
100- const fs = require ( 'fs' ) ;
10192 const packageJson = { packageManager : 'npm@9.8.0' } ;
10293 fs . writeFileSync ( 'package.json' , JSON . stringify ( packageJson ) ) ;
10394 expect ( detectActivePackageManager ( ) ) . to . equal ( 'npm' ) ;
10495 } ) ;
10596
10697 it ( 'should prioritize lock files over package.json packageManager field' , ( ) => {
107- const fs = require ( 'fs' ) ;
10898 fs . writeFileSync ( 'yarn.lock' , '# yarn lockfile v1' ) ;
10999 const packageJson = { packageManager : 'pnpm@8.6.0' } ;
110100 fs . writeFileSync ( 'package.json' , JSON . stringify ( packageJson ) ) ;
@@ -141,14 +131,12 @@ describe('utils', () => {
141131 } ) ;
142132
143133 it ( 'should fall back to npm_execpath when package.json is invalid' , ( ) => {
144- const fs = require ( 'fs' ) ;
145134 fs . writeFileSync ( 'package.json' , 'invalid json' ) ;
146135 process . env . npm_execpath = '/path/to/yarn.js' ;
147136 expect ( detectActivePackageManager ( ) ) . to . equal ( 'yarn' ) ;
148137 } ) ;
149138
150139 it ( 'should fall back to npm_execpath when package.json has no packageManager field' , ( ) => {
151- const fs = require ( 'fs' ) ;
152140 const packageJson = { name : 'test-app' , version : '1.0.0' } ;
153141 fs . writeFileSync ( 'package.json' , JSON . stringify ( packageJson ) ) ;
154142 process . env . npm_execpath = '/path/to/pnpm.cjs' ;
@@ -158,7 +146,6 @@ describe('utils', () => {
158146
159147 describe ( 'priority and edge cases' , ( ) => {
160148 it ( 'should prioritize lock files over package.json over npm_execpath' , ( ) => {
161- const fs = require ( 'fs' ) ;
162149 fs . writeFileSync ( 'yarn.lock' , '# yarn lockfile v1' ) ;
163150 const packageJson = { packageManager : 'pnpm@8.6.0' } ;
164151 fs . writeFileSync ( 'package.json' , JSON . stringify ( packageJson ) ) ;
@@ -167,7 +154,6 @@ describe('utils', () => {
167154 } ) ;
168155
169156 it ( 'should prioritize package.json over npm_execpath when no lock files exist' , ( ) => {
170- const fs = require ( 'fs' ) ;
171157 const packageJson = { packageManager : 'pnpm@8.6.0' } ;
172158 fs . writeFileSync ( 'package.json' , JSON . stringify ( packageJson ) ) ;
173159 process . env . npm_execpath = '/path/to/yarn.js' ;
@@ -228,9 +214,6 @@ describe('utils', () => {
228214 originalCwd = process . cwd ( ) ;
229215
230216 // Create temporary directory for each test
231- const fs = require ( 'fs' ) ;
232- const os = require ( 'os' ) ;
233- const path = require ( 'path' ) ;
234217 tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'normalize-test-' ) ) ;
235218 process . chdir ( tempDir ) ;
236219 } ) ;
@@ -246,7 +229,6 @@ describe('utils', () => {
246229 // Restore working directory and cleanup
247230 process . chdir ( originalCwd ) ;
248231 try {
249- const fs = require ( 'fs' ) ;
250232 fs . rmSync ( tempDir , { recursive : true , force : true } ) ;
251233 } catch ( error ) {
252234 // Ignore cleanup errors
@@ -275,7 +257,6 @@ describe('utils', () => {
275257 } ) ;
276258
277259 it ( 'falls back to detected package manager from lock files' , ( ) => {
278- const fs = require ( 'fs' ) ;
279260 fs . writeFileSync ( 'yarn.lock' , '# yarn lockfile v1' ) ;
280261
281262 const options : CLIOptions = { } ;
@@ -287,7 +268,6 @@ describe('utils', () => {
287268 } ) ;
288269
289270 it ( 'falls back to detected package manager from package.json' , ( ) => {
290- const fs = require ( 'fs' ) ;
291271 const packageJson = { packageManager : 'pnpm@8.6.0' } ;
292272 fs . writeFileSync ( 'package.json' , JSON . stringify ( packageJson ) ) ;
293273
0 commit comments