Skip to content

Commit

Permalink
Merge pull request #38 from rwjblue/compat-with-release-it-14
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue authored Sep 8, 2020
2 parents 268235c + 0ca21d2 commit afa46d6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:

jobs:
build:
name: "Node ${{ matrix.node-version }}"

runs-on: ubuntu-latest

Expand All @@ -19,11 +20,28 @@ jobs:

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: install dependencies
run: yarn install --non-interactive
- name: test
run: yarn test
run: yarn install --non-interactive --frozen-lockfile
- run: yarn test

release-it-compat:
name: "release-it@${{ matrix.release-it-version }}"

runs-on: ubuntu-latest

strategy:
matrix:
release-it-version: [13, 14]

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 14
- name: install dependencies
run: yarn install --non-interactive --frozen-lockfile
- run: yarn add --dev release-it@^${{ matrix.release-it-version }}
- run: yarn test
27 changes: 19 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const urlJoin = require('url-join');
const walkSync = require('walk-sync');
const detectNewline = require('detect-newline');
const detectIndent = require('detect-indent');
const { rejectAfter } = require('release-it/lib/util');
const { npmTimeoutError, npmAuthError } = require('release-it/lib/errors');
const { Plugin } = require('release-it');

const options = { write: false };
Expand All @@ -18,6 +16,16 @@ const NPM_BASE_URL = 'https://www.npmjs.com';
const NPM_DEFAULT_REGISTRY = 'https://registry.npmjs.org';
const DETECT_TRAILING_WHITESPACE = /\s+$/;

function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

async function rejectAfter(ms, error) {
await sleep(ms);

throw error;
}

function resolveWorkspaces(workspaces) {
if (Array.isArray(workspaces)) {
return workspaces;
Expand Down Expand Up @@ -150,16 +158,19 @@ module.exports = class YarnWorkspacesPlugin extends Plugin {

const validations = Promise.all([this.isRegistryUp(), this.isAuthenticated()]);

await Promise.race([validations, rejectAfter(REGISTRY_TIMEOUT)]);
await Promise.race([
validations,
rejectAfter(REGISTRY_TIMEOUT, new Error(`Timed out after ${REGISTRY_TIMEOUT}ms.`)),
]);

const [isRegistryUp, isAuthenticated] = await validations;

if (!isRegistryUp) {
throw new npmTimeoutError(REGISTRY_TIMEOUT);
throw new Error(`Unable to reach npm registry (timed out after ${REGISTRY_TIMEOUT}ms).`);
}

if (!isAuthenticated) {
throw new npmAuthError();
throw new Error('Not authenticated with npm. Please `npm login` and try again.');
}
}

Expand Down Expand Up @@ -187,7 +198,7 @@ module.exports = class YarnWorkspacesPlugin extends Plugin {
});

const task = async () => {
const { isDryRun } = this.global;
const { isDryRun } = this.config;

const updateVersion = (pkgInfo) => {
let { pkg } = pkgInfo;
Expand Down Expand Up @@ -289,7 +300,7 @@ module.exports = class YarnWorkspacesPlugin extends Plugin {
}

_updateDependencies(pkgInfo, newVersion) {
const { isDryRun } = this.global;
const { isDryRun } = this.config;
const workspaces = this.getWorkspaces();
const { pkg } = pkgInfo;

Expand Down Expand Up @@ -382,7 +393,7 @@ module.exports = class YarnWorkspacesPlugin extends Plugin {
const isScoped = workspaceInfo.name.startsWith('@');
const otpArg = otp.value ? ` --otp ${otp.value}` : '';
const accessArg = access ? ` --access ${access}` : '';
const dryRunArg = this.global.isDryRun ? ' --dry-run' : '';
const dryRunArg = this.config.isDryRun ? ' --dry-run' : '';

if (workspaceInfo.isPrivate) {
this.log.warn(`${workspaceInfo.name}: Skip publish (package is private)`);
Expand Down

0 comments on commit afa46d6

Please sign in to comment.