From ad9dd6b6e4bb2c757fbb1c210fc10d2c729cda16 Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Tue, 1 Oct 2024 16:30:16 -0700 Subject: [PATCH 01/15] chore: Fix paths --- test/kitchen.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/kitchen.ts b/test/kitchen.ts index df1888e2..2d8c695c 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -14,7 +14,7 @@ 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`, + cwd: path.join(stagingPath, 'kitchen'), encoding: 'utf8' as BufferEncoding, }; @@ -73,7 +73,13 @@ describe('🚰 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')}; From ee9a12178723da696b5a80348befd140be0c6aba Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Tue, 1 Oct 2024 16:41:57 -0700 Subject: [PATCH 02/15] chore: add debug logs --- test/kitchen.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/kitchen.ts b/test/kitchen.ts index 2d8c695c..04a3c7d7 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -90,10 +90,27 @@ describe('🚰 kitchen sink', () => { path.join(stagingPath, 'gts.tgz'), path.join(tmpDir.name, 'gts.tgz') ); + + // TODO: DEBUG + console.dir( + { + LISTING_BEFORE: fs.readdirSync(path.join(tmpDir.name, 'kitchen')), + }, + {depth: 20} + ); + // 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); + // TODO: DEBUG + console.dir( + { + LISTING: fs.readdirSync(path.join(tmpDir.name, 'kitchen')), + }, + {depth: 20} + ); + // The `extends` field must use the local gts path. const tsconfigJson = fs.readFileSync( path.join(tmpDir.name, 'kitchen', 'tsconfig.json'), From 70fe05de42c2709462e89de16e2e6e1037d6adfb Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Wed, 2 Oct 2024 09:25:22 -0700 Subject: [PATCH 03/15] refactor: remove `write-file-atomic` --- package.json | 4 +--- src/init.ts | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 817c4943..9d992ac6 100644 --- a/package.json +++ b/package.json @@ -56,8 +56,7 @@ "meow": "^9.0.0", "ncp": "^2.0.0", "prettier": "3.2.5", - "rimraf": "3.0.2", - "write-file-atomic": "^4.0.0" + "rimraf": "3.0.2" }, "devDependencies": { "@npm/types": "^1.0.1", @@ -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": "^9.0.0", "cross-spawn": "^7.0.3", "fs-extra": "^11.0.0", diff --git a/src/init.ts b/src/init.ts index dd813ded..ead6cecc 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); } From 6b91ee8962136fc23281eb2d1133498dd9c4c908 Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Wed, 2 Oct 2024 09:45:26 -0700 Subject: [PATCH 04/15] chore: more debug logs --- test/kitchen.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/kitchen.ts b/test/kitchen.ts index 04a3c7d7..dfb7a86e 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -15,8 +15,8 @@ const stagingDir = tmp.dirSync({keep, unsafeCleanup: true}); const stagingPath = stagingDir.name; const execOpts = { cwd: path.join(stagingPath, 'kitchen'), - encoding: 'utf8' as BufferEncoding, -}; + encoding: 'utf8', +} as const; describe('🚰 kitchen sink', () => { const fixturesPath = path.join('test', 'fixtures'); @@ -34,6 +34,7 @@ describe('🚰 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) { @@ -81,7 +82,7 @@ describe('🚰 kitchen sink', () => { '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); @@ -101,7 +102,7 @@ describe('🚰 kitchen sink', () => { // 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); + console.dir(spawn.sync(GTS, ['init', '-n'], opts), {depth: 20}); // TODO: DEBUG console.dir( From 34eed2294e6958748fd1cc0099cd3416e97e0135 Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Wed, 2 Oct 2024 09:55:28 -0700 Subject: [PATCH 05/15] fix: make kitchen dir --- test/kitchen.ts | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/test/kitchen.ts b/test/kitchen.ts index dfb7a86e..eb0b382c 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -92,25 +92,12 @@ describe('🚰 kitchen sink', () => { path.join(tmpDir.name, 'gts.tgz') ); - // TODO: DEBUG - console.dir( - { - LISTING_BEFORE: fs.readdirSync(path.join(tmpDir.name, 'kitchen')), - }, - {depth: 20} - ); + // Make kitchen directory + fs.mkdirSync(opts.cwd); // 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. - console.dir(spawn.sync(GTS, ['init', '-n'], opts), {depth: 20}); - - // TODO: DEBUG - console.dir( - { - LISTING: fs.readdirSync(path.join(tmpDir.name, 'kitchen')), - }, - {depth: 20} - ); + spawn.sync(GTS, ['init', '-n'], opts); // The `extends` field must use the local gts path. const tsconfigJson = fs.readFileSync( From 86951e28aadf979df8a2d70867ea53e508f23400 Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Wed, 2 Oct 2024 09:59:28 -0700 Subject: [PATCH 06/15] fix: Create kitchen sink path in `before` No idea how this was working before --- test/kitchen.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/kitchen.ts b/test/kitchen.ts index eb0b382c..4a21bb21 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -21,10 +21,11 @@ const execOpts = { describe('🚰 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(() => { + fs.mkdirSync(kitchenPath); console.log(`${chalk.blue(`${__filename} staging area: ${stagingPath}`)}`); cp.execSync('npm pack'); const tarball = `${pkg.name}-${pkg.version}.tgz`; From 6133546fb19db29d94a3f3a788ce5118fa539918 Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Wed, 2 Oct 2024 10:04:27 -0700 Subject: [PATCH 07/15] chore: more logs --- test/kitchen.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/kitchen.ts b/test/kitchen.ts index 4a21bb21..0991154d 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -93,8 +93,17 @@ describe('🚰 kitchen sink', () => { path.join(tmpDir.name, 'gts.tgz') ); + console.log({ + a: tmpDir.name, + b: stagingPath, + }); + // Make kitchen directory - fs.mkdirSync(opts.cwd); + try { + fs.mkdirSync(opts.cwd); + } catch { + // . + } // 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. From 26118195b63706608dfab66348415785905f6686 Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Wed, 2 Oct 2024 10:15:14 -0700 Subject: [PATCH 08/15] chore: debug log --- test/kitchen.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/test/kitchen.ts b/test/kitchen.ts index 0991154d..30851dfc 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -25,7 +25,6 @@ describe('🚰 kitchen sink', () => { // Create a staging directory with temp fixtures used to test on a fresh application. before(() => { - fs.mkdirSync(kitchenPath); console.log(`${chalk.blue(`${__filename} staging area: ${stagingPath}`)}`); cp.execSync('npm pack'); const tarball = `${pkg.name}-${pkg.version}.tgz`; @@ -93,17 +92,12 @@ describe('🚰 kitchen sink', () => { path.join(tmpDir.name, 'gts.tgz') ); - console.log({ - a: tmpDir.name, - b: stagingPath, - }); - - // Make kitchen directory - try { - fs.mkdirSync(opts.cwd); - } catch { - // . - } + console.log( + path.resolve(stagingPath, 'kitchen', 'node_modules', '.bin'), + fs.readdirSync( + path.resolve(stagingPath, 'kitchen', 'node_modules', '.bin') + ) + ); // 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. From 84070b399c1a53aa63b880ad765f0a80065a55f2 Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Wed, 2 Oct 2024 10:21:30 -0700 Subject: [PATCH 09/15] chore: more logs --- test/kitchen.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/test/kitchen.ts b/test/kitchen.ts index 30851dfc..d7b04607 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -92,12 +92,26 @@ describe('🚰 kitchen sink', () => { path.join(tmpDir.name, 'gts.tgz') ); - console.log( - path.resolve(stagingPath, 'kitchen', 'node_modules', '.bin'), - fs.readdirSync( - path.resolve(stagingPath, 'kitchen', 'node_modules', '.bin') - ) - ); + try { + console.log( + path.resolve(stagingPath, 'kitchen'), + fs.readdirSync(path.resolve(stagingPath, 'kitchen')) + ); + + console.log( + path.resolve(stagingPath, 'kitchen', 'node_modules'), + fs.readdirSync(path.resolve(stagingPath, 'kitchen', 'node_modules')) + ); + + console.log( + path.resolve(stagingPath, 'kitchen', 'node_modules', '.bin'), + fs.readdirSync( + path.resolve(stagingPath, 'kitchen', 'node_modules', '.bin') + ) + ); + } catch (e) { + console.dir({e}); + } // 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. From 3a7c2dee43d2eb8bcceaa5f67adeed0c32e40e9d Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Wed, 9 Oct 2024 21:17:24 -0700 Subject: [PATCH 10/15] chore: list fixtures --- test/kitchen.ts | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/test/kitchen.ts b/test/kitchen.ts index d7b04607..e8133d8a 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -33,6 +33,7 @@ describe('🚰 kitchen sink', () => { console.log('moving packed tar to ', targetPath); fs.moveSync('gts.tgz', targetPath); fs.copySync(fixturesPath, path.join(stagingPath, path.sep)); + console.log('fixtures:', fs.readdirSync(path.join(stagingPath, path.sep))); }); // CLEAN UP - remove the staging directory when done. @@ -92,27 +93,6 @@ describe('🚰 kitchen sink', () => { path.join(tmpDir.name, 'gts.tgz') ); - try { - console.log( - path.resolve(stagingPath, 'kitchen'), - fs.readdirSync(path.resolve(stagingPath, 'kitchen')) - ); - - console.log( - path.resolve(stagingPath, 'kitchen', 'node_modules'), - fs.readdirSync(path.resolve(stagingPath, 'kitchen', 'node_modules')) - ); - - console.log( - path.resolve(stagingPath, 'kitchen', 'node_modules', '.bin'), - fs.readdirSync( - path.resolve(stagingPath, 'kitchen', 'node_modules', '.bin') - ) - ); - } catch (e) { - console.dir({e}); - } - // 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); From fa27bb8f21de6dcee9bfc1cfcd4027a674e2715c Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Wed, 9 Oct 2024 21:21:20 -0700 Subject: [PATCH 11/15] chore: log kitchen fixtures --- test/kitchen.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/kitchen.ts b/test/kitchen.ts index e8133d8a..6f425bfb 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -34,6 +34,10 @@ describe('🚰 kitchen sink', () => { fs.moveSync('gts.tgz', targetPath); fs.copySync(fixturesPath, path.join(stagingPath, path.sep)); console.log('fixtures:', fs.readdirSync(path.join(stagingPath, path.sep))); + console.log( + 'kitchen fixtures:', + fs.readdirSync(path.join(stagingPath, path.sep, 'kitchen')) + ); }); // CLEAN UP - remove the staging directory when done. From a8fca8bef256f20970268126fa0071a3dca20d70 Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Wed, 9 Oct 2024 21:34:31 -0700 Subject: [PATCH 12/15] chore: directory pre-pack --- test/kitchen.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/kitchen.ts b/test/kitchen.ts index 6f425bfb..89133eae 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -26,6 +26,7 @@ describe('🚰 kitchen sink', () => { // 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'); @@ -33,11 +34,6 @@ describe('🚰 kitchen sink', () => { console.log('moving packed tar to ', targetPath); fs.moveSync('gts.tgz', targetPath); fs.copySync(fixturesPath, path.join(stagingPath, path.sep)); - console.log('fixtures:', fs.readdirSync(path.join(stagingPath, path.sep))); - console.log( - 'kitchen fixtures:', - fs.readdirSync(path.join(stagingPath, path.sep, 'kitchen')) - ); }); // CLEAN UP - remove the staging directory when done. @@ -100,6 +96,7 @@ describe('🚰 kitchen sink', () => { // 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); + spawn.sync(GTS, ['init', '-n'], opts); // The `extends` field must use the local gts path. const tsconfigJson = fs.readFileSync( From 3b631c62f2437a2e21ef2f3b8af7a7b17f653f88 Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Wed, 9 Oct 2024 21:46:17 -0700 Subject: [PATCH 13/15] chore: `npm ci` --- test/kitchen.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/kitchen.ts b/test/kitchen.ts index 89133eae..ff2899d9 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -54,6 +54,7 @@ describe('🚰 kitchen sink', () => { '-n', ]; + spawn.sync('npm', ['ci'], execOpts); const res = spawn.sync('npx', args, execOpts); console.log('out: ', res.stdout + ''); console.log('error: ', res.stderr + ''); From 6f7da61da3a67f5b6dd9e723344c186009bb8ed0 Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Wed, 9 Oct 2024 21:46:46 -0700 Subject: [PATCH 14/15] chore: `npm ci` --- test/kitchen.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/kitchen.ts b/test/kitchen.ts index ff2899d9..cecc108b 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -54,10 +54,10 @@ describe('🚰 kitchen sink', () => { '-n', ]; - spawn.sync('npm', ['ci'], execOpts); const res = spawn.sync('npx', args, execOpts); console.log('out: ', res.stdout + ''); console.log('error: ', res.stderr + ''); + spawn.sync('npm', ['ci'], execOpts); // Ensure config files got generated. fs.accessSync(path.join(kitchenPath, 'tsconfig.json')); From f54ee2f96ea14e964eae1646931dc74f2c247e84 Mon Sep 17 00:00:00 2001 From: Daniel Bankhead Date: Wed, 9 Oct 2024 21:51:52 -0700 Subject: [PATCH 15/15] chore: cleanup --- test/kitchen.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/kitchen.ts b/test/kitchen.ts index cecc108b..a1abfc1a 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -57,7 +57,6 @@ describe('🚰 kitchen sink', () => { const res = spawn.sync('npx', args, execOpts); console.log('out: ', res.stdout + ''); console.log('error: ', res.stderr + ''); - spawn.sync('npm', ['ci'], execOpts); // Ensure config files got generated. fs.accessSync(path.join(kitchenPath, 'tsconfig.json')); @@ -97,7 +96,6 @@ describe('🚰 kitchen sink', () => { // 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); - spawn.sync(GTS, ['init', '-n'], opts); // The `extends` field must use the local gts path. const tsconfigJson = fs.readFileSync(