-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Properly work in workspace mode. Previously setting the workspace meant the entire package was unpublished. Now it follows the convention of acting as if you were running from the workspace directory. - Better checking of when you are unpublishing the last version of a package. npm checks the actual manifest and compares it to the version you are asking to unpublish. - Error on ranges and tags. npm doesn't unpublish ranges or tags, and giving those as inputs would give unexepected results. - Proper output of what was unpublished. Previously the package (and sometimes version) displayed would not match what was actually unpublished. - Updated docs specifying that unpublishing with no parameters will only unpublish the version represented by the local package.json
- Loading branch information
Showing
3 changed files
with
126 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,10 +26,10 @@ t.test('no args --force success', async t => { | |
authorization: 'test-auth-token', | ||
}) | ||
const manifest = registry.manifest({ name: pkg }) | ||
await registry.package({ manifest, query: { write: true } }) | ||
await registry.package({ manifest, query: { write: true }, times: 2 }) | ||
registry.unpublish({ manifest }) | ||
await npm.exec('unpublish', []) | ||
t.equal(joinedOutput(), '- test-package@1.0.0') | ||
t.equal(joinedOutput(), '- test-package') | ||
}) | ||
|
||
t.test('no args --force missing package.json', async t => { | ||
|
@@ -63,11 +63,11 @@ t.test('no args --force error reading package.json', async t => { | |
) | ||
}) | ||
|
||
t.test('no args entire project', async t => { | ||
t.test('no force entire project', async t => { | ||
const { npm } = await loadMockNpm(t) | ||
|
||
await t.rejects( | ||
npm.exec('unpublish', []), | ||
npm.exec('unpublish', ['@npmcli/unpublish-test']), | ||
/Refusing to delete entire project/ | ||
) | ||
}) | ||
|
@@ -82,6 +82,26 @@ t.test('too many args', async t => { | |
) | ||
}) | ||
|
||
t.test('range', async t => { | ||
const { npm } = await loadMockNpm(t) | ||
|
||
await t.rejects( | ||
npm.exec('unpublish', ['a@>1.0.0']), | ||
{ code: 'EUSAGE' }, | ||
/single version/ | ||
) | ||
}) | ||
|
||
t.test('tag', async t => { | ||
const { npm } = await loadMockNpm(t) | ||
|
||
await t.rejects( | ||
npm.exec('unpublish', ['a@>1.0.0']), | ||
{ code: 'EUSAGE' }, | ||
/single version/ | ||
) | ||
}) | ||
|
||
t.test('unpublish <pkg>@version not the last version', async t => { | ||
const { joinedOutput, npm } = await loadMockNpm(t, { | ||
config: { | ||
|
@@ -129,7 +149,24 @@ t.test('unpublish <pkg>@version last version', async t => { | |
) | ||
}) | ||
|
||
t.test('no version found in package.json', async t => { | ||
t.test('no version found in package.json no force', async t => { | ||
const { npm } = await loadMockNpm(t, { | ||
config: { | ||
...auth, | ||
}, | ||
prefixDir: { | ||
'package.json': JSON.stringify({ | ||
name: pkg, | ||
}, null, 2), | ||
}, | ||
}) | ||
await t.rejects( | ||
npm.exec('unpublish', []), | ||
/Refusing to delete entire project/ | ||
) | ||
}) | ||
|
||
t.test('no version found in package.json with force', async t => { | ||
const { joinedOutput, npm } = await loadMockNpm(t, { | ||
config: { | ||
force: true, | ||
|
@@ -147,7 +184,7 @@ t.test('no version found in package.json', async t => { | |
authorization: 'test-auth-token', | ||
}) | ||
const manifest = registry.manifest({ name: pkg }) | ||
await registry.package({ manifest, query: { write: true } }) | ||
await registry.package({ manifest, query: { write: true }, times: 2 }) | ||
registry.unpublish({ manifest }) | ||
|
||
await npm.exec('unpublish', []) | ||
|
@@ -219,7 +256,7 @@ t.test('workspaces', async t => { | |
'workspace-b': { | ||
'package.json': JSON.stringify({ | ||
name: 'workspace-b', | ||
version: '1.2.3-n', | ||
version: '1.2.3-b', | ||
repository: 'https://github.com/npm/workspace-b', | ||
}), | ||
}, | ||
|
@@ -231,20 +268,20 @@ t.test('workspaces', async t => { | |
}, | ||
} | ||
|
||
t.test('no force', async t => { | ||
t.test('with package name no force', async t => { | ||
const { npm } = await loadMockNpm(t, { | ||
config: { | ||
workspaces: true, | ||
workspace: ['workspace-a'], | ||
}, | ||
prefixDir, | ||
}) | ||
await t.rejects( | ||
npm.exec('unpublish', []), | ||
npm.exec('unpublish', ['workspace-a']), | ||
/Refusing to delete entire project/ | ||
) | ||
}) | ||
|
||
t.test('all workspaces --force', async t => { | ||
t.test('all workspaces last version --force', async t => { | ||
const { joinedOutput, npm } = await loadMockNpm(t, { | ||
config: { | ||
workspaces: true, | ||
|
@@ -258,9 +295,9 @@ t.test('workspaces', async t => { | |
registry: npm.config.get('registry'), | ||
authorization: 'test-auth-token', | ||
}) | ||
const manifestA = registry.manifest({ name: 'workspace-a' }) | ||
const manifestB = registry.manifest({ name: 'workspace-b' }) | ||
const manifestN = registry.manifest({ name: 'workspace-n' }) | ||
const manifestA = registry.manifest({ name: 'workspace-a', versions: ['1.2.3-a'] }) | ||
const manifestB = registry.manifest({ name: 'workspace-b', versions: ['1.2.3-b'] }) | ||
const manifestN = registry.manifest({ name: 'workspace-n', versions: ['1.2.3-n'] }) | ||
await registry.package({ manifest: manifestA, query: { write: true }, times: 2 }) | ||
await registry.package({ manifest: manifestB, query: { write: true }, times: 2 }) | ||
await registry.package({ manifest: manifestN, query: { write: true }, times: 2 }) | ||
|
@@ -271,28 +308,6 @@ t.test('workspaces', async t => { | |
await npm.exec('unpublish', []) | ||
t.equal(joinedOutput(), '- workspace-a\n- workspace-b\n- workspace-n') | ||
}) | ||
|
||
t.test('one workspace --force', async t => { | ||
const { joinedOutput, npm } = await loadMockNpm(t, { | ||
config: { | ||
workspace: ['workspace-a'], | ||
force: true, | ||
...auth, | ||
}, | ||
prefixDir, | ||
}) | ||
const registry = new MockRegistry({ | ||
tap: t, | ||
registry: npm.config.get('registry'), | ||
authorization: 'test-auth-token', | ||
}) | ||
const manifestA = registry.manifest({ name: 'workspace-a' }) | ||
await registry.package({ manifest: manifestA, query: { write: true }, times: 2 }) | ||
registry.nock.delete(`/workspace-a/-rev/${manifestA._rev}`).reply(201) | ||
|
||
await npm.exec('unpublish', []) | ||
t.equal(joinedOutput(), '- workspace-a') | ||
}) | ||
}) | ||
|
||
t.test('dryRun with spec', async t => { | ||
|
@@ -331,6 +346,16 @@ t.test('dryRun with no args', async t => { | |
}, null, 2), | ||
}, | ||
}) | ||
const registry = new MockRegistry({ | ||
tap: t, | ||
registry: npm.config.get('registry'), | ||
authorization: 'test-auth-token', | ||
}) | ||
const manifest = registry.manifest({ | ||
name: pkg, | ||
packuments: ['1.0.0', '1.0.1'], | ||
}) | ||
await registry.package({ manifest, query: { write: true } }) | ||
|
||
await npm.exec('unpublish', []) | ||
t.equal(joinedOutput(), '- [email protected]') | ||
|
@@ -360,10 +385,10 @@ t.test('publishConfig no spec', async t => { | |
authorization: 'test-other-token', | ||
}) | ||
const manifest = registry.manifest({ name: pkg }) | ||
await registry.package({ manifest, query: { write: true } }) | ||
await registry.package({ manifest, query: { write: true }, times: 2 }) | ||
registry.unpublish({ manifest }) | ||
await npm.exec('unpublish', []) | ||
t.equal(joinedOutput(), '- test-package@1.0.0') | ||
t.equal(joinedOutput(), '- test-package') | ||
}) | ||
|
||
t.test('publishConfig with spec', async t => { | ||
|
@@ -421,7 +446,7 @@ t.test('scoped registry config', async t => { | |
authorization: 'test-other-token', | ||
}) | ||
const manifest = registry.manifest({ name: scopedPkg }) | ||
await registry.package({ manifest, query: { write: true } }) | ||
await registry.package({ manifest, query: { write: true }, times: 2 }) | ||
registry.unpublish({ manifest }) | ||
await npm.exec('unpublish', [scopedPkg]) | ||
}) | ||
|