Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support
nextRelease.channel
property in publish
step
- Loading branch information
Showing
7 changed files
with
43 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const semver = require('semver'); | ||
|
||
module.exports = channel => (channel ? (semver.validRange(channel) ? `release-${channel}` : channel) : 'latest'); |
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 |
---|---|---|
@@ -1,18 +1,7 @@ | ||
const execa = require('execa'); | ||
const normalizeUrl = require('normalize-url'); | ||
|
||
module.exports = async ( | ||
{name, publishConfig: {tag} = {}}, | ||
{cwd, env: {DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org/', ...env}}, | ||
registry | ||
) => { | ||
const distTag = tag || (await execa.stdout('npm', ['config', 'get', 'tag'], {cwd, env})) || 'latest'; | ||
|
||
return { | ||
name: `npm package (@${distTag} dist-tag)`, | ||
url: | ||
normalizeUrl(registry) === normalizeUrl(DEFAULT_NPM_REGISTRY) | ||
? `https://www.npmjs.com/package/${name}` | ||
: undefined, | ||
}; | ||
}; | ||
module.exports = async ({name}, {env: {DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org/'}}, distTag, registry) => ({ | ||
name: `npm package (@${distTag} dist-tag)`, | ||
url: | ||
normalizeUrl(registry) === normalizeUrl(DEFAULT_NPM_REGISTRY) ? `https://www.npmjs.com/package/${name}` : undefined, | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import test from 'ava'; | ||
import getChannel from '../lib/get-channel'; | ||
|
||
test.serial('Get default channel', t => { | ||
t.is(getChannel(undefined), 'latest'); | ||
}); | ||
|
||
test.serial('Get passed channel if valid', t => { | ||
t.is(getChannel('next'), 'next'); | ||
}); | ||
|
||
test.serial('Prefix channel with "release-" if invalid', t => { | ||
t.is(getChannel('1.x'), 'release-1.x'); | ||
t.is(getChannel('1.0.0'), 'release-1.0.0'); | ||
}); |
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 |
---|---|---|
@@ -1,79 +1,16 @@ | ||
import path from 'path'; | ||
import test from 'ava'; | ||
import {writeFile} from 'fs-extra'; | ||
import tempy from 'tempy'; | ||
import getReleaseInfo from '../lib/get-release-info'; | ||
|
||
test.beforeEach(() => { | ||
// Delete all `npm_config` environment variable set by CI as they take precedence over the `.npmrc` because the process that runs the tests is started before the `.npmrc` is created | ||
for (let i = 0, keys = Object.keys(process.env); i < keys.length; i++) { | ||
if (keys[i].startsWith('npm_')) { | ||
delete process.env[keys[i]]; | ||
} | ||
} | ||
}); | ||
|
||
test('Default registry and tag', async t => { | ||
const cwd = tempy.directory(); | ||
|
||
t.deepEqual(await getReleaseInfo({name: 'module'}, {cwd, env: {}}, 'https://registry.npmjs.org/'), { | ||
name: 'npm package (@latest dist-tag)', | ||
url: 'https://www.npmjs.com/package/module', | ||
}); | ||
}); | ||
|
||
test('Default registry, tag and scoped module', async t => { | ||
const cwd = tempy.directory(); | ||
|
||
t.deepEqual(await getReleaseInfo({name: '@scope/module'}, {cwd, env: {}}, 'https://registry.npmjs.org/'), { | ||
test('Default registry and scoped module', async t => { | ||
t.deepEqual(await getReleaseInfo({name: '@scope/module'}, {env: {}}, 'latest', 'https://registry.npmjs.org/'), { | ||
name: 'npm package (@latest dist-tag)', | ||
url: 'https://www.npmjs.com/package/@scope/module', | ||
}); | ||
}); | ||
|
||
test('Custom registry, tag and scoped module', async t => { | ||
const cwd = tempy.directory(); | ||
|
||
t.deepEqual(await getReleaseInfo({name: '@scope/module'}, {cwd, env: {}}, 'https://custom.registry.org/'), { | ||
test('Custom registry and scoped module', async t => { | ||
t.deepEqual(await getReleaseInfo({name: '@scope/module'}, {env: {}}, 'latest', 'https://custom.registry.org/'), { | ||
name: 'npm package (@latest dist-tag)', | ||
url: undefined, | ||
}); | ||
}); | ||
|
||
test('Default registry and tag from .npmrc', async t => { | ||
const cwd = tempy.directory(); | ||
await writeFile(path.resolve(cwd, '.npmrc'), 'tag=npmrc'); | ||
|
||
t.deepEqual( | ||
await getReleaseInfo({name: 'module', publishConfig: {}}, {cwd, env: {}}, 'https://registry.npmjs.org/'), | ||
{ | ||
name: 'npm package (@npmrc dist-tag)', | ||
url: 'https://www.npmjs.com/package/module', | ||
} | ||
); | ||
}); | ||
|
||
test('Default registry and tag from package.json', async t => { | ||
const cwd = tempy.directory(); | ||
|
||
await writeFile(path.resolve(cwd, '.npmrc'), 'tag=npmrc'); | ||
|
||
t.deepEqual( | ||
await getReleaseInfo({name: 'module', publishConfig: {tag: 'pkg'}}, {cwd, env: {}}, 'https://registry.npmjs.org/'), | ||
{name: 'npm package (@pkg dist-tag)', url: 'https://www.npmjs.com/package/module'} | ||
); | ||
}); | ||
|
||
test('Default tag', async t => { | ||
const cwd = tempy.directory(); | ||
|
||
await writeFile(path.resolve(cwd, '.npmrc'), 'tag='); | ||
|
||
t.deepEqual( | ||
await getReleaseInfo({name: 'module', publishConfig: {}}, {cwd, env: {}}, 'https://registry.npmjs.org/'), | ||
{ | ||
name: 'npm package (@latest dist-tag)', | ||
url: 'https://www.npmjs.com/package/module', | ||
} | ||
); | ||
}); |
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