From 6cf63a1b3f4fce8b9d219af7d4cf078c8197c8c2 Mon Sep 17 00:00:00 2001 From: Kelly Selden <602423+kellyselden@users.noreply.github.com> Date: Wed, 26 Feb 2025 09:18:28 -0500 Subject: [PATCH] fix: WIP don't detach private package Since the links left behind will fail to install from npm. Closes #535. --- test/detach-test.js | 54 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/test/detach-test.js b/test/detach-test.js index 465752b5..44ed9257 100644 --- a/test/detach-test.js +++ b/test/detach-test.js @@ -65,11 +65,11 @@ describe(detach, function() { prompt = this.stub(detach, 'inquirerPrompt'); tmpPath = await gitInit(); - - fixturify.writeSync(tmpPath, defaultWorkspace); }); it('package-a', async function() { + fixturify.writeSync(tmpPath, defaultWorkspace); + let cwd = path.resolve(tmpPath, './packages/package-a'); prompt.withArgs([this.match({ @@ -139,6 +139,8 @@ describe(detach, function() { }); it('package-b', async function() { + fixturify.writeSync(tmpPath, defaultWorkspace); + let cwd = path.resolve(tmpPath, './packages/package-b'); prompt.withArgs([this.match({ @@ -207,6 +209,8 @@ describe(detach, function() { }); it('package-c', async function() { + fixturify.writeSync(tmpPath, defaultWorkspace); + let cwd = path.resolve(tmpPath, './packages/package-c'); await detach({ cwd }); @@ -261,4 +265,50 @@ describe(detach, function() { }), }); }); + + it('can\'t detach private packages', async function() { + fixturify.writeSync(tmpPath, { + 'packages': { + 'package-a': { + 'package.json': stringifyJson({ + 'name': 'package-a', + 'version': '1.0.0', + 'private': true, + }), + }, + }, + 'package.json': stringifyJson({ + 'private': true, + 'workspaces': [ + 'packages/*', + ], + }), + }); + + let cwd = path.resolve(tmpPath, './packages/package-a'); + + await detach({ cwd }); + + let workspace = fixturify.readSync(tmpPath, { ignore: ['.git'] }); + + expect(prompt).to.not.be.called; + + expect(workspace).to.deep.equal({ + 'packages': { + 'package-a': { + 'package.json': stringifyJson({ + 'name': '@scope/package-a', + 'version': '1.0.0', + 'private': true, + }), + }, + }, + 'package.json': stringifyJson({ + 'private': true, + 'workspaces': [ + 'packages/*', + ], + }), + }); + }); });