diff --git a/package.json b/package.json index 61de20f5..d1f6989e 100644 --- a/package.json +++ b/package.json @@ -56,8 +56,7 @@ "meow": "^9.0.0", "ncp": "^2.0.0", "prettier": "3.3.3", - "rimraf": "3.0.2", - "write-file-atomic": "^4.0.0" + "rimraf": "3.0.2" }, "devDependencies": { "@npm/types": "^2.0.0", @@ -72,7 +71,6 @@ "@types/rimraf": "^3.0.0", "@types/sinon": "^17.0.0", "@types/tmp": "^0.2.0", - "@types/write-file-atomic": "^4.0.0", "c8": "^10.1.2", "cross-spawn": "^7.0.3", "fs-extra": "^11.0.0", diff --git a/src/init.ts b/src/init.ts index 0f161d3e..ec781144 100644 --- a/src/init.ts +++ b/src/init.ts @@ -19,7 +19,6 @@ import * as inquirer from 'inquirer'; import * as path from 'path'; import {ncp} from 'ncp'; import * as util from 'util'; -import * as writeFileAtomic from 'write-file-atomic'; import { getPkgManagerCommand, @@ -168,7 +167,7 @@ async function writePackageJson( ): Promise { options.logger.log('Writing package.json...'); if (!options.dryRun) { - await writeFileAtomic('./package.json', formatJson(packageJson)); + await fs.promises.writeFile('./package.json', formatJson(packageJson)); } const preview = { scripts: packageJson.scripts, @@ -216,7 +215,7 @@ async function generateConfigFile( if (writeFile) { options.logger.log(`Writing ${filename}...`); if (!options.dryRun) { - await writeFileAtomic(filename, contents); + await fs.promises.writeFile(filename, contents); } options.logger.log(contents); } diff --git a/test/kitchen.ts b/test/kitchen.ts index 75266e74..9e99575b 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -14,20 +14,21 @@ const keep = !!process.env.GTS_KEEP_TEMPDIRS; const stagingDir = tmp.dirSync({keep, unsafeCleanup: true}); const stagingPath = stagingDir.name; const execOpts = { - cwd: `${stagingPath}${path.sep}kitchen`, - encoding: 'utf8' as BufferEncoding, -}; + cwd: path.join(stagingPath, 'kitchen'), + encoding: 'utf8', +} as const; const action = process.platform !== 'win32' ? describe : describe.skip; action('🚰 kitchen sink', () => { const fixturesPath = path.join('test', 'fixtures'); const gtsPath = path.join('node_modules', '.bin', 'gts'); - const kitchenPath = path.join(stagingPath, 'kitchen'); + const kitchenPath = execOpts.cwd; // Create a staging directory with temp fixtures used to test on a fresh application. before(() => { console.log(`${chalk.blue(`${__filename} staging area: ${stagingPath}`)}`); + console.log('directory pre-pack:', fs.readdirSync('.')); cp.execSync('npm pack'); const tarball = `${pkg.name}-${pkg.version}.tgz`; fs.renameSync(tarball, 'gts.tgz'); @@ -36,6 +37,7 @@ action('🚰 kitchen sink', () => { fs.moveSync('gts.tgz', targetPath); fs.copySync(fixturesPath, path.join(stagingPath, path.sep)); }); + // CLEAN UP - remove the staging directory when done. after('cleanup staging', () => { if (!keep) { @@ -75,9 +77,15 @@ action('🚰 kitchen sink', () => { it('should use as a non-locally installed module', () => { // Use from a directory different from where we have locally installed. This // simulates use as a globally installed module. - const GTS = path.resolve(stagingPath, 'kitchen/node_modules/.bin/gts'); + const GTS = path.resolve( + stagingPath, + 'kitchen', + 'node_modules', + '.bin', + 'gts' + ); const tmpDir = tmp.dirSync({keep, unsafeCleanup: true}); - const opts = {cwd: path.join(tmpDir.name, 'kitchen')}; + const opts = {cwd: path.join(tmpDir.name, 'kitchen')} as const; // Copy test files. fs.copySync(fixturesPath, tmpDir.name); @@ -86,6 +94,7 @@ action('🚰 kitchen sink', () => { path.join(stagingPath, 'gts.tgz'), path.join(tmpDir.name, 'gts.tgz'), ); + // It's important to use `-n` here because we don't want to overwrite // the version of gts installed, as it will trigger the npm install. spawn.sync(GTS, ['init', '-n'], opts);