Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions scripts/releases-ci/__tests__/publish-npm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ describe('publish-npm', () => {
code: 0,
}));

process.env.NPM_CONFIG_OTP = 'otp';

await publishNpm('release');

expect(setVersionMock).not.toBeCalled();
Expand All @@ -303,7 +301,7 @@ describe('publish-npm', () => {
expect(publishPackageMock.mock.calls).toEqual([
[
path.join(REPO_ROOT, 'packages', 'react-native'),
{otp: process.env.NPM_CONFIG_OTP, tags: ['0.81-stable']},
{tags: ['0.81-stable']},
],
]);

Expand All @@ -322,8 +320,6 @@ describe('publish-npm', () => {
code: 0,
}));

process.env.NPM_CONFIG_OTP = 'otp';

await publishNpm('release');

expect(updateReactNativeArtifactsMock).not.toBeCalled();
Expand All @@ -341,10 +337,7 @@ describe('publish-npm', () => {
);

expect(publishPackageMock.mock.calls).toEqual([
[
path.join(REPO_ROOT, 'packages', 'react-native'),
{otp: process.env.NPM_CONFIG_OTP, tags: ['latest']},
],
[path.join(REPO_ROOT, 'packages', 'react-native'), {tags: ['latest']}],
]);

expect(consoleLogMock.mock.calls).toEqual([
Expand All @@ -365,8 +358,6 @@ describe('publish-npm', () => {
execMock.mockReturnValueOnce({code: 1});
isTaggedLatestMock.mockReturnValueOnce(true);

process.env.NPM_CONFIG_OTP = 'otp';

await expect(async () => {
await publishNpm('release');
}).rejects.toThrow(
Expand All @@ -388,10 +379,7 @@ describe('publish-npm', () => {
);

expect(publishPackageMock.mock.calls).toEqual([
[
path.join(REPO_ROOT, 'packages', 'react-native'),
{otp: process.env.NPM_CONFIG_OTP, tags: ['latest']},
],
[path.join(REPO_ROOT, 'packages', 'react-native'), {tags: ['latest']}],
]);
expect(consoleLogMock).not.toHaveBeenCalled();
});
Expand All @@ -406,8 +394,6 @@ describe('publish-npm', () => {
code: 0,
}));

process.env.NPM_CONFIG_OTP = 'otp';

await publishNpm('release');

expect(setVersionMock).not.toBeCalled();
Expand All @@ -425,10 +411,7 @@ describe('publish-npm', () => {
);

expect(publishPackageMock.mock.calls).toEqual([
[
path.join(REPO_ROOT, 'packages', 'react-native'),
{otp: process.env.NPM_CONFIG_OTP, tags: ['next']},
],
[path.join(REPO_ROOT, 'packages', 'react-native'), {tags: ['next']}],
]);
expect(consoleLogMock.mock.calls).toEqual([
[`Published react-native@${expectedVersion} to npm`],
Expand Down
2 changes: 0 additions & 2 deletions scripts/releases-ci/publish-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ async function publishMonorepoPackages(tag /*: ?string */) {
console.log(`Publishing ${packageInfo.name}...`);
const result = publishPackage(packageInfo.path, {
tags: [tag],
otp: process.env.NPM_CONFIG_OTP,
access: 'public',
});

Expand Down Expand Up @@ -122,7 +121,6 @@ async function publishNpm(buildType /*: BuildType */) /*: Promise<void> */ {
const packagePath = path.join(REPO_ROOT, 'packages', 'react-native');
const result = publishPackage(packagePath, {
tags: [tag],
otp: process.env.NPM_CONFIG_OTP,
});

if (result.code) {
Expand Down
2 changes: 0 additions & 2 deletions scripts/releases-ci/publish-updated-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const {execSync} = require('child_process');
const {parseArgs} = require('util');

const PUBLISH_PACKAGES_TAG = '#publish-packages-to-npm';
const NPM_CONFIG_OTP = process.env.NPM_CONFIG_OTP;

const config = {
options: {
Expand Down Expand Up @@ -139,7 +138,6 @@ function runPublish(
) {
const result = publishPackage(packagePath, {
tags,
otp: NPM_CONFIG_OTP,
});

if (result.code !== 0) {
Expand Down
26 changes: 12 additions & 14 deletions scripts/releases/utils/__tests__/npm-utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,35 @@ describe('npm-utils', () => {
it('should run publish command', () => {
publishPackage(
'path/to/my-package',
{tags: ['latest'], otp: 'otp'},
{tags: ['latest']},
{silent: true, cwd: 'i/expect/this/to/be/overriden'},
);
expect(execMock).toHaveBeenCalledWith(
'npm publish --tag latest --otp otp',
{silent: true, cwd: 'path/to/my-package'},
);
expect(execMock).toHaveBeenCalledWith('npm publish --tag latest', {
silent: true,
cwd: 'path/to/my-package',
});
});

it('should run publish command when no execOptions', () => {
publishPackage('path/to/my-package', {tags: ['latest'], otp: 'otp'});
expect(execMock).toHaveBeenCalledWith(
'npm publish --tag latest --otp otp',
{cwd: 'path/to/my-package'},
);
publishPackage('path/to/my-package', {tags: ['latest']});
expect(execMock).toHaveBeenCalledWith('npm publish --tag latest', {
cwd: 'path/to/my-package',
});
});

it('should handle multiple tags', () => {
publishPackage('path/to/my-package', {
tags: ['next', '0.72-stable'],
otp: 'otp',
});
expect(execMock).toHaveBeenCalledWith(
'npm publish --tag next --tag 0.72-stable --otp otp',
'npm publish --tag next --tag 0.72-stable',
{cwd: 'path/to/my-package'},
);
});

it('should handle -no-tag', () => {
publishPackage('path/to/my-package', {tags: ['--no-tag'], otp: 'otp'});
expect(execMock).toHaveBeenCalledWith('npm publish --no-tag --otp otp', {
publishPackage('path/to/my-package', {tags: ['--no-tag']});
expect(execMock).toHaveBeenCalledWith('npm publish --no-tag', {
cwd: 'path/to/my-package',
});
});
Expand Down
6 changes: 2 additions & 4 deletions scripts/releases/utils/npm-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type PackageJSON = {
}
type NpmPackageOptions = {
tags: ?Array<string> | ?Array<?string>,
otp: ?string,
access?: ?('public' | 'restricted')
}
*/
Expand Down Expand Up @@ -130,7 +129,7 @@ function publishPackage(
packageOptions /*: NpmPackageOptions */,
execOptions /*: ?ExecOptsSync */,
) /*: ShellString */ {
const {otp, tags, access} = packageOptions;
const {tags, access} = packageOptions;

let tagsFlag = '';
if (tags != null) {
Expand All @@ -142,13 +141,12 @@ function publishPackage(
.join('');
}

const otpFlag = otp != null ? ` --otp ${otp}` : '';
const accessFlag = access != null ? ` --access ${access}` : '';
const options /*: ExecOptsSync */ = execOptions
? {...execOptions, cwd: packagePath}
: {cwd: packagePath};

return exec(`npm publish${tagsFlag}${otpFlag}${accessFlag}`, options);
return exec(`npm publish${tagsFlag}${accessFlag}`, options);
}

/**
Expand Down
Loading