node-publisher 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ### v3.2.1 (2025-07-11)
2
+
3
+ #### Pull requests
4
+
5
+ - [#62](https://github.com/zendesk/node-publisher/pull/62) Fix yarn v2+ versioning ([Daria Radu](mailto:daria.radu@zendesk.com))
6
+
7
+ #### Commits to master
8
+
9
+ - [v3.2.1](https://github.com/zendesk/node-publisher/commit/1f0f25c7aec1e507d7a9c4fab6252ce00588e073) ([Sune Simonsen](mailto:sune@we-knowhow.dk))
10
+ - [Update changelog](https://github.com/zendesk/node-publisher/commit/b444d894d713c2f4572b6b5211c09d8ff77cedac) ([Sune Simonsen](mailto:sune@we-knowhow.dk))
11
+
12
+ ### v3.2.0 (2025-07-10)
13
+
14
+ #### Pull requests
15
+
16
+ - [#61](https://github.com/zendesk/node-publisher/pull/61) Update node version ([Daria Radu](mailto:daria.radu@zendesk.com), [Sune Simonsen](mailto:sune@we-knowhow.dk))
17
+ - [#60](https://github.com/zendesk/node-publisher/pull/60) Run different publish command based on yarn version ([Daria Radu](mailto:daria.radu@zendesk.com))
18
+ - [#59](https://github.com/zendesk/node-publisher/pull/59) Fix custom release branch setup to the correct parameter ([Daria Radu](mailto:daria.radu@zendesk.com))
19
+
20
+ #### Commits to master
21
+
22
+ - [v3.2.0](https://github.com/zendesk/node-publisher/commit/989ecec13e467b13217ff482f422bafe61e61dbf) ([Sune Simonsen](mailto:sune@we-knowhow.dk))
23
+ - [Update changelog](https://github.com/zendesk/node-publisher/commit/e19ff455cae89cbd2796c00699ca4debaded6fac) ([Sune Simonsen](mailto:sune@we-knowhow.dk))
24
+
1
25
  ### v3.1.0 (2024-01-24)
2
26
 
3
27
  #### Pull requests
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-publisher",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "A configurable release automation tool inspired by create-react-app and Travis CI.",
5
5
  "author": "Attila Večerek <avecerek@zendesk.com>",
6
6
  "homepage": "https://github.com/zendesk/node-publisher#readme",
@@ -0,0 +1,25 @@
1
+ const { packageJson } = require('../utils/package');
2
+
3
+ const version = str => {
4
+ if (str[0] === 'v') {
5
+ return str;
6
+ }
7
+
8
+ return `v${str}`;
9
+ };
10
+
11
+ const publish = ({ nextVersion, execCommand, env }) => {
12
+ execCommand(`yarn version ${nextVersion}`);
13
+
14
+ const pkg = packageJson();
15
+
16
+ execCommand(`git add package.json yarn.lock`);
17
+ execCommand(`git commit -m "${version(pkg.version)}"`);
18
+ execCommand(`git tag "${version(pkg.version)}"`);
19
+ execCommand(`git push origin ${env.branch || 'master'} --follow-tags`);
20
+ execCommand(`yarn npm publish`);
21
+ };
22
+
23
+ module.exports = {
24
+ publish
25
+ };
@@ -0,0 +1,104 @@
1
+ const { publish } = require('./yarn-berry');
2
+ const { packageJson } = require('../utils/package');
3
+
4
+ jest.mock('../utils/package');
5
+
6
+ describe('publish', () => {
7
+ beforeEach(() => {
8
+ jest.clearAllMocks();
9
+ });
10
+
11
+ describe('without preid', () => {
12
+ const options = {
13
+ nextVersion: 'patch',
14
+ preid: undefined,
15
+ env: { branch: 'main' },
16
+ execCommand: jest.fn()
17
+ };
18
+
19
+ beforeEach(() => {
20
+ packageJson.mockReturnValue({ version: '1.0.1' });
21
+ });
22
+
23
+ it('publishes new version using yarn v2+ syntax', () => {
24
+ expect(() => publish(options)).not.toThrow();
25
+
26
+ expect(options.execCommand).toHaveBeenNthCalledWith(
27
+ 1,
28
+ 'yarn version patch'
29
+ );
30
+
31
+ expect(options.execCommand).toHaveBeenNthCalledWith(
32
+ 2,
33
+ 'git add package.json yarn.lock'
34
+ );
35
+
36
+ expect(options.execCommand).toHaveBeenNthCalledWith(
37
+ 3,
38
+ 'git commit -m "v1.0.1"'
39
+ );
40
+
41
+ expect(options.execCommand).toHaveBeenNthCalledWith(
42
+ 4,
43
+ 'git tag "v1.0.1"'
44
+ );
45
+
46
+ expect(options.execCommand).toHaveBeenNthCalledWith(
47
+ 5,
48
+ 'git push origin main --follow-tags'
49
+ );
50
+
51
+ expect(options.execCommand).toHaveBeenNthCalledWith(
52
+ 6,
53
+ 'yarn npm publish'
54
+ );
55
+ });
56
+ });
57
+
58
+ describe('with preid', () => {
59
+ const options = {
60
+ nextVersion: 'major',
61
+ preid: 'alpha',
62
+ env: { main: 'master' },
63
+ execCommand: jest.fn()
64
+ };
65
+
66
+ beforeEach(() => {
67
+ packageJson.mockReturnValue({ version: '2.0.0-alpha.0' });
68
+ });
69
+
70
+ it('publishes new version using yarn v2+ syntax', () => {
71
+ expect(() => publish(options)).not.toThrow();
72
+
73
+ expect(options.execCommand).toHaveBeenNthCalledWith(
74
+ 1,
75
+ 'yarn version major'
76
+ );
77
+
78
+ expect(options.execCommand).toHaveBeenNthCalledWith(
79
+ 2,
80
+ 'git add package.json yarn.lock'
81
+ );
82
+
83
+ expect(options.execCommand).toHaveBeenNthCalledWith(
84
+ 3,
85
+ 'git commit -m "v2.0.0-alpha.0"'
86
+ );
87
+
88
+ expect(options.execCommand).toHaveBeenNthCalledWith(
89
+ 4,
90
+ 'git tag "v2.0.0-alpha.0"'
91
+ );
92
+
93
+ expect(options.execCommand).toHaveBeenNthCalledWith(
94
+ 5,
95
+ 'git push origin master --follow-tags'
96
+ );
97
+
98
+ expect(options.execCommand).toHaveBeenNthCalledWith(
99
+ 6,
100
+ 'yarn npm publish'
101
+ );
102
+ });
103
+ });
104
+ });
@@ -1,27 +1,5 @@
1
- const { execSync } = require('child_process');
2
-
3
- const getYarnVersion = () => {
4
- try {
5
- const output = execSync('yarn --version', { encoding: 'utf8' });
6
- return output.trim();
7
- } catch (error) {
8
- // Default to yarn v1 if version detection fails
9
- return '1.0.0';
10
- }
11
- };
12
-
13
- const isYarnV2OrHigher = () => {
14
- const version = getYarnVersion();
15
- const majorVersion = parseInt(version.split('.')[0], 10);
16
- return majorVersion >= 2;
17
- };
18
-
19
1
  const publish = ({ nextVersion, execCommand }) => {
20
- if (isYarnV2OrHigher()) {
21
- execCommand(`yarn npm publish --tag ${nextVersion}`);
22
- } else {
23
- execCommand(`yarn publish --new-version ${nextVersion}`);
24
- }
2
+ execCommand(`yarn publish --new-version ${nextVersion}`);
25
3
  };
26
4
 
27
5
  module.exports = {
@@ -47,61 +47,4 @@ describe('publish', () => {
47
47
  });
48
48
  });
49
49
  });
50
-
51
- describe('with yarn v2+', () => {
52
- beforeEach(() => {
53
- execSync.mockReturnValue('4.1.0');
54
- });
55
-
56
- describe('without preid', () => {
57
- const options = {
58
- nextVersion: 'patch',
59
- preid: undefined,
60
- execCommand: jest.fn()
61
- };
62
-
63
- it('publishes new version using yarn v2+ syntax', () => {
64
- expect(() => publish(options)).not.toThrow();
65
- expect(options.execCommand.mock.calls[0][0]).toBe(
66
- 'yarn npm publish --tag patch'
67
- );
68
- });
69
- });
70
-
71
- describe('with preid', () => {
72
- const options = {
73
- nextVersion: 'major',
74
- preid: 'alpha',
75
- execCommand: jest.fn()
76
- };
77
-
78
- it('publishes new version using yarn v2+ syntax', () => {
79
- expect(() => publish(options)).not.toThrow();
80
- expect(options.execCommand.mock.calls[0][0]).toBe(
81
- 'yarn npm publish --tag major'
82
- );
83
- });
84
- });
85
- });
86
-
87
- describe('when yarn version detection fails', () => {
88
- beforeEach(() => {
89
- execSync.mockImplementation(() => {
90
- throw new Error('Command failed');
91
- });
92
- });
93
-
94
- const options = {
95
- nextVersion: 'patch',
96
- preid: undefined,
97
- execCommand: jest.fn()
98
- };
99
-
100
- it('defaults to yarn v1 syntax', () => {
101
- expect(() => publish(options)).not.toThrow();
102
- expect(options.execCommand.mock.calls[0][0]).toBe(
103
- 'yarn publish --new-version patch'
104
- );
105
- });
106
- });
107
50
  });
@@ -1,6 +1,7 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
  const { LERNA_JSON_PATH } = require('../constants');
4
+ const { isYarnBerry } = require('../yarn');
4
5
 
5
6
  const npmClient = () => {
6
7
  const clientMap = {
@@ -15,6 +16,10 @@ const npmClient = () => {
15
16
  }
16
17
  }
17
18
 
19
+ if (client === 'yarn' && isYarnBerry()) {
20
+ client = 'yarn-berry';
21
+ }
22
+
18
23
  if (!client) {
19
24
  throw new Error(
20
25
  'Client could not be detected, make sure you use one of the supported clients.'
@@ -1,10 +1,15 @@
1
1
  const { npmClient, publishClient } = require('./');
2
+ const { isYarnBerry } = require('../yarn');
2
3
 
3
4
  jest.mock('fs');
4
5
 
6
+ jest.mock('../yarn');
7
+
5
8
  describe('npmClient', () => {
6
9
  beforeEach(() => {
7
10
  require('fs').__setMockFiles([]);
11
+
12
+ isYarnBerry.mockImplementation(() => false);
8
13
  });
9
14
 
10
15
  describe('when client cannot be detected', () => {
@@ -28,6 +33,32 @@ describe('npmClient', () => {
28
33
  });
29
34
  });
30
35
 
36
+ describe('when yarn.lock found', () => {
37
+ const MOCKED_FILES = ['yarn.lock'];
38
+
39
+ describe('and yarn version is 1', () => {
40
+ it('returns yarn', () => {
41
+ require('fs').__setMockFiles(MOCKED_FILES);
42
+
43
+ expect(npmClient).not.toThrow();
44
+ expect(npmClient()).toBe('yarn');
45
+ });
46
+ });
47
+
48
+ describe('and yarn version is 4', () => {
49
+ beforeEach(() => {
50
+ isYarnBerry.mockImplementation(() => true);
51
+ });
52
+
53
+ it('returns yarn berry', () => {
54
+ require('fs').__setMockFiles(MOCKED_FILES);
55
+
56
+ expect(npmClient).not.toThrow();
57
+ expect(npmClient()).toBe('yarn-berry');
58
+ });
59
+ });
60
+ });
61
+
31
62
  describe('when both package-lock.json and yarn.lock are found', () => {
32
63
  const MOCKED_FILES = ['package-lock.json', 'yarn.lock'];
33
64
 
@@ -3,9 +3,11 @@ const yaml = require('js-yaml');
3
3
  const readReleaseConfig = str => yaml.safeLoad(str);
4
4
 
5
5
  const buildReleaseConfig = env => {
6
- const client = env.npmClient;
6
+ const client = env.npmClient === 'yarn-berry' ? 'yarn' : env.npmClient;
7
7
  const binPathPrefix = './node_modules/.bin/';
8
- const scriptRunner = client === 'yarn' ? 'yarn' : 'npm run';
8
+ const scriptRunner = ['yarn', 'yarn-berry'].includes(client)
9
+ ? 'yarn'
10
+ : 'npm run';
9
11
 
10
12
  const config = {
11
13
  rollback: true,
@@ -1,19 +1,14 @@
1
1
  const fs = require('fs');
2
2
  const { PACKAGE_JSON_PATH } = require('../constants');
3
3
 
4
- let pkg;
5
4
  const packageJson = () => {
6
- if (pkg) return pkg;
7
-
8
5
  try {
9
- pkg = JSON.parse(fs.readFileSync(PACKAGE_JSON_PATH, 'utf8'));
6
+ return JSON.parse(fs.readFileSync(PACKAGE_JSON_PATH, 'utf8'));
10
7
  } catch (e) {
11
8
  throw new Error(
12
9
  'Your package.json could not be parsed. Make sure the manifest is valid.'
13
10
  );
14
11
  }
15
-
16
- return pkg;
17
12
  };
18
13
 
19
14
  module.exports = {
@@ -0,0 +1,22 @@
1
+ const { execSync } = require('child_process');
2
+
3
+ const getYarnVersion = () => {
4
+ try {
5
+ const output = execSync('yarn --version', { encoding: 'utf8' });
6
+ return output.trim();
7
+ } catch (error) {
8
+ // Default to yarn v1 if version detection fails
9
+ return '1.0.0';
10
+ }
11
+ };
12
+
13
+ const isYarnBerry = () => {
14
+ const version = getYarnVersion();
15
+ const majorVersion = parseInt(version.split('.')[0], 10);
16
+ return majorVersion >= 2;
17
+ };
18
+
19
+ module.exports = {
20
+ getYarnVersion,
21
+ isYarnBerry
22
+ };