-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deps): no longer depending on @semantic-release/npm
- Loading branch information
Showing
11 changed files
with
370 additions
and
413 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import semver from "semver"; | ||
|
||
export default function (channel) { | ||
return 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import path from "path"; | ||
import { readPackage } from "read-pkg"; | ||
import AggregateError from "aggregate-error"; | ||
import getError from "./get-error.js"; | ||
|
||
export default async function ({ pkgRoot }, { cwd }) { | ||
try { | ||
const pkg = await readPackage({ cwd: pkgRoot ? path.resolve(cwd, String(pkgRoot)) : cwd }); | ||
|
||
if (!pkg.name) { | ||
throw getError("ENOPKGNAME"); | ||
} | ||
|
||
return pkg; | ||
} catch (error) { | ||
if (error.code === "ENOENT") { | ||
throw new AggregateError([getError("ENOPKG")]); | ||
} | ||
|
||
throw new AggregateError([error]); | ||
} | ||
} |
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,18 @@ | ||
import path from "path"; | ||
import rc from "rc"; | ||
import getRegistryUrl from "registry-auth-token/registry-url.js"; | ||
|
||
export default function ({ publishConfig: { registry } = {}, name }, { cwd, env }) { | ||
return ( | ||
registry || | ||
env.NPM_CONFIG_REGISTRY || | ||
getRegistryUrl( | ||
name.split("/")[0], | ||
rc( | ||
"npm", | ||
{ registry: "https://registry.npmjs.org/" }, | ||
{ config: env.NPM_CONFIG_USERCONFIG || path.resolve(cwd, ".npmrc") }, | ||
), | ||
) | ||
); | ||
} |
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,17 @@ | ||
import normalizeUrl from "normalize-url"; | ||
|
||
export default function ( | ||
{ name }, | ||
{ env: { DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org/" }, nextRelease: { version } }, | ||
distTag, | ||
registry, | ||
) { | ||
return { | ||
name: `npm package (@${distTag} dist-tag)`, | ||
url: | ||
normalizeUrl(registry) === normalizeUrl(DEFAULT_NPM_REGISTRY) | ||
? `https://www.npmjs.com/package/${name}/v/${version}` | ||
: undefined, | ||
channel: distTag, | ||
}; | ||
} |
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,42 @@ | ||
import path from "path"; | ||
import rc from "rc"; | ||
import fs from "fs-extra"; | ||
import getAuthToken from "registry-auth-token"; | ||
import nerfDart from "nerf-dart"; | ||
import AggregateError from "aggregate-error"; | ||
import getError from "./get-error.js"; | ||
|
||
export default async function ( | ||
npmrc, | ||
registry, | ||
{ cwd, env: { NPM_TOKEN, NPM_CONFIG_USERCONFIG }, logger }, | ||
) { | ||
logger.log("Verify authentication for registry %s", registry); | ||
const { configs, ...rcConfig } = rc( | ||
"npm", | ||
{ registry: "https://registry.npmjs.org/" }, | ||
{ config: NPM_CONFIG_USERCONFIG || path.resolve(cwd, ".npmrc") }, | ||
); | ||
|
||
if (configs) { | ||
logger.log("Reading npm config from %s", configs.join(", ")); | ||
} | ||
|
||
const currentConfig = configs | ||
? (await Promise.all(configs.map((config) => fs.readFile(config)))).join("\n") | ||
: ""; | ||
|
||
if (getAuthToken(registry, { npmrc: rcConfig })) { | ||
await fs.outputFile(npmrc, currentConfig); | ||
return; | ||
} | ||
|
||
if (NPM_TOKEN) { | ||
const oldConfig = currentConfig ? `${currentConfig}\n` : ""; | ||
const newConfig = `${nerfDart(registry)}:_authToken = \${NPM_TOKEN}`; | ||
await fs.outputFile(npmrc, `${oldConfig}${newConfig}`); | ||
logger.log(`Wrote NPM_TOKEN to ${npmrc}`); | ||
} else { | ||
throw new AggregateError([getError("ENONPMTOKEN", { registry })]); | ||
} | ||
} |
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,20 @@ | ||
import { isBoolean, isNil, isString } from "lodash-es"; | ||
import getError from "./get-error.js"; | ||
|
||
const isNonEmptyString = (value) => isString(value) && value.trim(); | ||
|
||
const VALIDATORS = { | ||
npmPublish: isBoolean, | ||
tarballDir: isNonEmptyString, | ||
pkgRoot: isNonEmptyString, | ||
}; | ||
|
||
export default function ({ npmPublish, tarballDir, pkgRoot }) { | ||
return Object.entries({ npmPublish, tarballDir, pkgRoot }).reduce( | ||
(errors, [option, value]) => | ||
!isNil(value) && !VALIDATORS[option](value) | ||
? [...errors, getError(`EINVALID${option.toUpperCase()}`, { [option]: value })] | ||
: errors, | ||
[], | ||
); | ||
} |
Oops, something went wrong.