@ckeditor/ckeditor5-dev-release-tools 44.0.0-alpha.5 → 44.1.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.
Files changed (48) hide show
  1. package/lib/index.js +1 -0
  2. package/lib/tasks/cleanuppackages.js +24 -28
  3. package/lib/tasks/commitandtag.js +16 -21
  4. package/lib/tasks/creategithubrelease.js +11 -23
  5. package/lib/tasks/generatechangelogformonorepository.js +62 -55
  6. package/lib/tasks/generatechangelogforsinglepackage.js +17 -14
  7. package/lib/tasks/preparerepository.js +19 -19
  8. package/lib/tasks/publishpackages.js +88 -31
  9. package/lib/tasks/push.js +4 -4
  10. package/lib/tasks/reassignnpmtags.js +8 -8
  11. package/lib/tasks/updatedependencies.js +23 -43
  12. package/lib/tasks/updateversions.js +22 -96
  13. package/lib/tasks/verifypackagespublishedcorrectly.js +18 -12
  14. package/lib/utils/assertfilestopublish.js +6 -6
  15. package/lib/utils/assertnpmauthorization.js +1 -1
  16. package/lib/utils/assertnpmtag.js +10 -24
  17. package/lib/utils/assertpackages.js +4 -4
  18. package/lib/utils/checkversionavailability.js +8 -24
  19. package/lib/utils/configurereleaseoptions.js +1 -1
  20. package/lib/utils/confirmincludingpackage.js +1 -1
  21. package/lib/utils/confirmnpmtag.js +3 -3
  22. package/lib/utils/displaycommits.js +4 -4
  23. package/lib/utils/executeinparallel.js +24 -29
  24. package/lib/utils/findpathstopackages.js +78 -0
  25. package/lib/utils/generatechangelog.js +23 -23
  26. package/lib/utils/getchangedfilesforcommit.js +2 -2
  27. package/lib/utils/getchangelog.js +2 -2
  28. package/lib/utils/getchangesforversion.js +3 -3
  29. package/lib/utils/getcommits.js +7 -6
  30. package/lib/utils/getformatteddate.js +1 -1
  31. package/lib/utils/getnewversiontype.js +1 -1
  32. package/lib/utils/getnpmtagfromversion.js +11 -2
  33. package/lib/utils/getpackagejson.js +2 -2
  34. package/lib/utils/getpackagespaths.js +9 -9
  35. package/lib/utils/getwriteroptions.js +1 -1
  36. package/lib/utils/isversionpublishablefortag.js +8 -10
  37. package/lib/utils/parallelworker.js +2 -2
  38. package/lib/utils/providenewversionformonorepository.js +28 -12
  39. package/lib/utils/providetoken.js +1 -1
  40. package/lib/utils/provideversion.js +41 -24
  41. package/lib/utils/publishpackageonnpmcallback.js +10 -20
  42. package/lib/utils/savechangelog.js +2 -2
  43. package/lib/utils/transformcommitfactory.js +27 -27
  44. package/lib/utils/transformcommitutils.js +13 -13
  45. package/lib/utils/truncatechangelog.js +2 -2
  46. package/lib/utils/validaterepositorytorelease.js +6 -6
  47. package/lib/utils/versions.js +17 -16
  48. package/package.json +3 -2
@@ -4,44 +4,50 @@
4
4
  */
5
5
 
6
6
  import upath from 'upath';
7
- import { glob } from 'glob';
7
+ import fs from 'fs-extra';
8
8
  import assertNpmAuthorization from '../utils/assertnpmauthorization.js';
9
9
  import assertPackages from '../utils/assertpackages.js';
10
10
  import assertNpmTag from '../utils/assertnpmtag.js';
11
11
  import assertFilesToPublish from '../utils/assertfilestopublish.js';
12
12
  import executeInParallel from '../utils/executeinparallel.js';
13
13
  import publishPackageOnNpmCallback from '../utils/publishpackageonnpmcallback.js';
14
+ import checkVersionAvailability from '../utils/checkversionavailability.js';
15
+ import findPathsToPackages from '../utils/findpathstopackages.js';
14
16
 
15
17
  /**
16
18
  * The purpose of the script is to validate the packages prepared for the release and then release them on npm.
17
19
  *
18
20
  * The validation contains the following steps in each package:
19
21
  * - User must be logged to npm on the specified account.
20
- * - The package directory mmust contain `package.json` file.
22
+ * - The package directory must contain `package.json` file.
21
23
  * - All other files expected to be released must exist in the package directory.
22
24
  * - The npm tag must match the tag calculated from the package version.
23
25
  *
24
26
  * When the validation for each package passes, packages are published on npm. Optional callback is called for confirmation whether to
25
27
  * continue.
26
28
  *
27
- * @param {Object} options
28
- * @param {String} options.packagesDirectory Relative path to a location of packages to release.
29
- * @param {String} options.npmOwner The account name on npm, which should be used to publish the packages.
30
- * @param {ListrTaskObject} options.listrTask An instance of `ListrTask`.
29
+ * If a package has already been published, the script does not try to publish it again. Instead, it treats the package as published.
30
+ * Whenever a communication between the script and npm fails, it tries to re-publish a package (up to three attempts).
31
+ *
32
+ * @param {object} options
33
+ * @param {string} options.packagesDirectory Relative path to a location of packages to release.
34
+ * @param {string} options.npmOwner The account name on npm, which should be used to publish the packages.
35
+ * @param {ListrTaskObject} [options.listrTask] An instance of `ListrTask`.
31
36
  * @param {AbortSignal|null} [options.signal=null] Signal to abort the asynchronous process.
32
- * @param {String} [options.npmTag='staging'] The npm distribution tag.
33
- * @param {Object.<String, Array.<String>>|null} [options.optionalEntries=null] Specifies which entries from the `files` field in the
37
+ * @param {string} [options.npmTag='staging'] The npm distribution tag.
38
+ * @param {Object.<string, Array.<string>>|null} [options.optionalEntries=null] Specifies which entries from the `files` field in the
34
39
  * `package.json` are optional. The key is a package name, and its value is an array of optional entries from the `files` field, for which
35
40
  * it is allowed not to match any file. The `options.optionalEntries` object may also contain the `default` key, which is used for all
36
41
  * packages that do not have own definition.
37
- * @param {String} [options.confirmationCallback=null] An callback whose response decides to continue the publishing packages. Synchronous
38
- * and asynchronous callbacks are supported.
39
- * @param {Boolean} [options.requireEntryPoint=false] Whether to verify if packages to publish define an entry point. In other words,
42
+ * @param {function|null} [options.confirmationCallback=null] An callback whose response decides to continue the publishing packages.
43
+ * Synchronous and asynchronous callbacks are supported.
44
+ * @param {boolean} [options.requireEntryPoint=false] Whether to verify if packages to publish define an entry point. In other words,
40
45
  * whether their `package.json` define the `main` field.
41
- * @param {Array.<String>} [options.optionalEntryPointPackages=[]] If the entry point validator is enabled (`requireEntryPoint=true`),
46
+ * @param {Array.<string>} [options.optionalEntryPointPackages=[]] If the entry point validator is enabled (`requireEntryPoint=true`),
42
47
  * this array contains a list of packages that will not be checked. In other words, they do not have to define the entry point.
43
- * @param {String} [options.cwd=process.cwd()] Current working directory from which all paths will be resolved.
44
- * @param {Number} [options.concurrency=4] Number of CPUs that will execute the task.
48
+ * @param {string} [options.cwd=process.cwd()] Current working directory from which all paths will be resolved.
49
+ * @param {number} [options.concurrency=4] Number of CPUs that will execute the task.
50
+ * @param {number} [options.attempts=3] Number of attempts. After reaching 0, it won't be publishing packages again.
45
51
  * @returns {Promise}
46
52
  */
47
53
  export default async function publishPackages( options ) {
@@ -56,15 +62,14 @@ export default async function publishPackages( options ) {
56
62
  requireEntryPoint = false,
57
63
  optionalEntryPointPackages = [],
58
64
  cwd = process.cwd(),
59
- concurrency = 4
65
+ concurrency = 4,
66
+ attempts = 3
60
67
  } = options;
61
68
 
69
+ const remainingAttempts = attempts - 1;
62
70
  await assertNpmAuthorization( npmOwner );
63
71
 
64
- const packagePaths = await glob( '*/', {
65
- cwd: upath.join( cwd, packagesDirectory ),
66
- absolute: true
67
- } );
72
+ const packagePaths = await findPathsToPackages( cwd, packagesDirectory );
68
73
 
69
74
  await assertPackages( packagePaths, { requireEntryPoint, optionalEntryPointPackages } );
70
75
  await assertFilesToPublish( packagePaths, optionalEntries );
@@ -72,17 +77,69 @@ export default async function publishPackages( options ) {
72
77
 
73
78
  const shouldPublishPackages = confirmationCallback ? await confirmationCallback() : true;
74
79
 
75
- if ( shouldPublishPackages ) {
76
- await executeInParallel( {
77
- cwd,
78
- packagesDirectory,
79
- listrTask,
80
- taskToExecute: publishPackageOnNpmCallback,
81
- taskOptions: {
82
- npmTag
83
- },
84
- signal,
85
- concurrency
86
- } );
80
+ if ( !shouldPublishPackages ) {
81
+ return Promise.resolve();
87
82
  }
83
+
84
+ await removeAlreadyPublishedPackages( packagePaths );
85
+
86
+ await executeInParallel( {
87
+ cwd,
88
+ packagesDirectory,
89
+ listrTask,
90
+ taskToExecute: publishPackageOnNpmCallback,
91
+ taskOptions: {
92
+ npmTag
93
+ },
94
+ signal,
95
+ concurrency
96
+ } );
97
+
98
+ const packagePathsAfterPublishing = await findPathsToPackages( cwd, packagesDirectory );
99
+
100
+ // All packages have been published. No need for re-executing.
101
+ if ( !packagePathsAfterPublishing.length ) {
102
+ return Promise.resolve();
103
+ }
104
+
105
+ // No more attempts. Abort.
106
+ if ( remainingAttempts <= 0 ) {
107
+ throw new Error( 'Some packages could not be published.' );
108
+ }
109
+
110
+ // Let's give an npm a moment for taking a breath...
111
+ await wait( 1000 );
112
+
113
+ // ...and try again.
114
+ return publishPackages( {
115
+ packagesDirectory,
116
+ npmOwner,
117
+ listrTask,
118
+ signal,
119
+ npmTag,
120
+ optionalEntries,
121
+ requireEntryPoint,
122
+ optionalEntryPointPackages,
123
+ cwd,
124
+ concurrency,
125
+ confirmationCallback: null, // Do not ask again if already here.
126
+ attempts: remainingAttempts
127
+ } );
128
+ }
129
+
130
+ async function removeAlreadyPublishedPackages( packagePaths ) {
131
+ for ( const absolutePackagePath of packagePaths ) {
132
+ const pkgJson = await fs.readJson( upath.join( absolutePackagePath, 'package.json' ) );
133
+ const isAvailable = await checkVersionAvailability( pkgJson.version, pkgJson.name );
134
+
135
+ if ( !isAvailable ) {
136
+ await fs.remove( absolutePackagePath );
137
+ }
138
+ }
139
+ }
140
+
141
+ function wait( time ) {
142
+ return new Promise( resolve => {
143
+ setTimeout( resolve, time );
144
+ } );
88
145
  }
package/lib/tasks/push.js CHANGED
@@ -9,10 +9,10 @@ import shellEscape from 'shell-escape';
9
9
  /**
10
10
  * Push the local changes to a remote server.
11
11
  *
12
- * @param {Object} options
13
- * @param {String} options.releaseBranch A name of the branch that should be used for releasing packages.
14
- * @param {String} options.version Name of tag connected with the release.
15
- * @param {String} [options.cwd] Root of the repository to prepare. `process.cwd()` by default.
12
+ * @param {object} options
13
+ * @param {string} options.releaseBranch A name of the branch that should be used for releasing packages.
14
+ * @param {string} options.version Name of tag connected with the release.
15
+ * @param {string} [options.cwd] Root of the repository to prepare. `process.cwd()` by default.
16
16
  * @returns {Promise}
17
17
  */
18
18
  export default async function push( options ) {
@@ -19,10 +19,10 @@ const execPromise = util.promisify( exec );
19
19
  * Used to switch the tags from `staging` to `latest` for specified array of packages.
20
20
  * Each operation will be retried up to 3 times in case of failure.
21
21
  *
22
- * @param {Object} options
23
- * @param {String} options.npmOwner User that is authorized to release packages.
24
- * @param {String} options.version Specifies the version of packages to reassign the tags for.
25
- * @param {Array.<String>} options.packages Array of packages' names to reassign tags for.
22
+ * @param {object} options
23
+ * @param {string} options.npmOwner User that is authorized to release packages.
24
+ * @param {string} options.version Specifies the version of packages to reassign the tags for.
25
+ * @param {Array.<string>} options.packages Array of packages' names to reassign tags for.
26
26
  * @returns {Promise}
27
27
  */
28
28
  export default async function reassignNpmTags( { npmOwner, version, packages } ) {
@@ -79,16 +79,16 @@ export default async function reassignNpmTags( { npmOwner, version, packages } )
79
79
  }
80
80
 
81
81
  /**
82
- * @param {String} message
83
- * @returns {String}
82
+ * @param {string} message
83
+ * @returns {string}
84
84
  */
85
85
  function trimErrorMessage( message ) {
86
86
  return message.replace( /npm ERR!.*\n/g, '' ).trim();
87
87
  }
88
88
 
89
89
  /**
90
- * @param {Function} callback
91
- * @param {Number} times
90
+ * @param {function} callback
91
+ * @param {number} times
92
92
  * @returns {RetryCallback}
93
93
  */
94
94
  function retry( callback, times = 3 ) {
@@ -4,8 +4,10 @@
4
4
  */
5
5
 
6
6
  import fs from 'fs-extra';
7
- import { glob } from 'glob';
8
7
  import upath from 'upath';
8
+ import findPathsToPackages from '../utils/findpathstopackages.js';
9
+
10
+ const { normalizeTrim } = upath;
9
11
 
10
12
  /**
11
13
  * The purpose of this script is to update all eligible dependencies to a version specified in the `options.version`. The following packages
@@ -17,16 +19,16 @@ import upath from 'upath';
17
19
  * The eligible dependencies are distinguished by the return value from the `options.shouldUpdateVersionCallback` function. Only if this
18
20
  * callback returns a truthy value for a given dependency, its version will be updated.
19
21
  *
20
- * @param {Object} options
21
- * @param {String} options.version Target version or a range version to which all eligible dependencies will be updated.
22
+ * @param {object} options
23
+ * @param {string} options.version Target version or a range version to which all eligible dependencies will be updated.
22
24
  * Examples: `1.0.0`, `^1.0.0`, etc.
23
25
  * @param {UpdateVersionCallback} options.shouldUpdateVersionCallback Callback function that decides whether to update a version
24
26
  * for a dependency. It receives a package name as an argument and should return a boolean value.
25
27
  * @param {UpdateDependenciesPackagesDirectoryFilter|null} [options.packagesDirectoryFilter=null] An optional callback allowing
26
28
  * filtering out directories/packages that should not be touched by the task.
27
- * @param {String} [options.packagesDirectory] Relative path to a location of packages to update their dependencies. If not specified,
29
+ * @param {string} [options.packagesDirectory] Relative path to a location of packages to update their dependencies. If not specified,
28
30
  * only the root package is checked.
29
- * @param {String} [options.cwd=process.cwd()] Current working directory from which all paths will be resolved.
31
+ * @param {string} [options.cwd=process.cwd()] Current working directory from which all paths will be resolved.
30
32
  * @returns {Promise}
31
33
  */
32
34
  export default async function updateDependencies( options ) {
@@ -38,15 +40,15 @@ export default async function updateDependencies( options ) {
38
40
  cwd = process.cwd()
39
41
  } = options;
40
42
 
41
- const globPatterns = [ 'package.json' ];
42
-
43
- if ( packagesDirectory ) {
44
- const packagesDirectoryPattern = upath.join( packagesDirectory, '*', 'package.json' );
45
-
46
- globPatterns.push( packagesDirectoryPattern );
47
- }
48
-
49
- const pkgJsonPaths = await getPackageJsonPaths( cwd, globPatterns, packagesDirectoryFilter );
43
+ const pkgJsonPaths = await findPathsToPackages(
44
+ cwd,
45
+ packagesDirectory ? normalizeTrim( packagesDirectory ) : null,
46
+ {
47
+ includePackageJson: true,
48
+ includeCwd: true,
49
+ packagesDirectoryFilter
50
+ }
51
+ );
50
52
 
51
53
  for ( const pkgJsonPath of pkgJsonPaths ) {
52
54
  const pkgJson = await fs.readJson( pkgJsonPath );
@@ -62,9 +64,9 @@ export default async function updateDependencies( options ) {
62
64
  /**
63
65
  * Updates the version for each eligible dependency.
64
66
  *
65
- * @param {String} version
66
- * @param {Function} callback
67
- * @param {Object} [dependencies]
67
+ * @param {string} version
68
+ * @param {function} callback
69
+ * @param {object} [dependencies]
68
70
  */
69
71
  function updateVersion( version, callback, dependencies ) {
70
72
  if ( !dependencies ) {
@@ -78,40 +80,18 @@ function updateVersion( version, callback, dependencies ) {
78
80
  }
79
81
  }
80
82
 
81
- /**
82
- * @param {String} cwd
83
- * @param {Array.<String>} globPatterns
84
- * @param {UpdateDependenciesPackagesDirectoryFilter|null} packagesDirectoryFilter
85
- * @returns {Promise.<Array.<String>>}
86
- */
87
- async function getPackageJsonPaths( cwd, globPatterns, packagesDirectoryFilter ) {
88
- const globOptions = {
89
- cwd,
90
- nodir: true,
91
- absolute: true
92
- };
93
-
94
- const pkgJsonPaths = await glob( globPatterns, globOptions );
95
-
96
- if ( !packagesDirectoryFilter ) {
97
- return pkgJsonPaths;
98
- }
99
-
100
- return pkgJsonPaths.filter( packagesDirectoryFilter );
101
- }
102
-
103
83
  /**
104
84
  * @callback UpdateVersionCallback
105
85
  *
106
- * @param {String} packageName A package name.
86
+ * @param {string} packageName A package name.
107
87
  *
108
- * @returns {Boolean} Whether to update (`true`) or ignore (`false`) bumping the package version.
88
+ * @returns {boolean} Whether to update (`true`) or ignore (`false`) bumping the package version.
109
89
  */
110
90
 
111
91
  /**
112
92
  * @callback UpdateDependenciesPackagesDirectoryFilter
113
93
  *
114
- * @param {String} packageJsonPath An absolute path to a `package.json` file.
94
+ * @param {string} packageJsonPath An absolute path to a `package.json` file.
115
95
  *
116
- * @returns {Boolean} Whether to include (`true`) or skip (`false`) processing the given directory/package.
96
+ * @returns {boolean} Whether to include (`true`) or skip (`false`) processing the given directory/package.
117
97
  */
@@ -5,11 +5,10 @@
5
5
 
6
6
  import upath from 'upath';
7
7
  import fs from 'fs-extra';
8
- import { glob } from 'glob';
9
8
  import semver from 'semver';
10
- import checkVersionAvailability from '../utils/checkversionavailability.js';
9
+ import findPathsToPackages from '../utils/findpathstopackages.js';
11
10
 
12
- const { normalizeTrim, toUnix, dirname, join } = upath;
11
+ const { normalizeTrim } = upath;
13
12
 
14
13
  /**
15
14
  * The purpose of the script is to update the version of a root package found in the current working
@@ -22,13 +21,13 @@ const { normalizeTrim, toUnix, dirname, join } = upath;
22
21
  * Exception: passing a version starting with the `0.0.0-nightly` string. It is used for publishing
23
22
  * a nightly release.
24
23
  *
25
- * @param {Object} options
26
- * @param {String} options.version Version to store in a `package.json` file under the `version` key.
24
+ * @param {object} options
25
+ * @param {string} options.version Version to store in a `package.json` file under the `version` key.
27
26
  * @param {UpdateVersionsPackagesDirectoryFilter|null} [options.packagesDirectoryFilter=null] An optional callback allowing filtering out
28
27
  * directories/packages that should not be touched by the task.
29
- * @param {String} [options.packagesDirectory] Relative path to a location of packages to update. If not specified,
28
+ * @param {string} [options.packagesDirectory] Relative path to a location of packages to update. If not specified,
30
29
  * only the root package is checked.
31
- * @param {String} [options.cwd=process.cwd()] Current working directory from which all paths will be resolved.
30
+ * @param {string} [options.cwd=process.cwd()] Current working directory from which all paths will be resolved.
32
31
  * @returns {Promise}
33
32
  */
34
33
  export default async function updateVersions( options ) {
@@ -38,24 +37,18 @@ export default async function updateVersions( options ) {
38
37
  packagesDirectoryFilter = null,
39
38
  cwd = process.cwd()
40
39
  } = options;
41
- const normalizedCwd = toUnix( cwd );
42
- const normalizedPackagesDir = packagesDirectory ? normalizeTrim( packagesDirectory ) : null;
43
40
 
44
- const globPatterns = getGlobPatterns( normalizedPackagesDir );
45
- const pkgJsonPaths = await getPackageJsonPaths( cwd, globPatterns, packagesDirectoryFilter );
46
-
47
- const randomPackagePath = getRandomPackagePath( pkgJsonPaths, normalizedPackagesDir );
48
-
49
- const { version: rootPackageVersion } = await readPackageJson( normalizedCwd );
50
- const { name: randomPackageName } = await readPackageJson( randomPackagePath );
51
-
52
- checkIfVersionIsValid( version, rootPackageVersion );
41
+ const pkgJsonPaths = await findPathsToPackages(
42
+ cwd,
43
+ packagesDirectory ? normalizeTrim( packagesDirectory ) : null,
44
+ {
45
+ includePackageJson: true,
46
+ includeCwd: true,
47
+ packagesDirectoryFilter
48
+ }
49
+ );
53
50
 
54
- const isVersionAvailable = await checkVersionAvailability( version, randomPackageName );
55
-
56
- if ( !isVersionAvailable ) {
57
- throw new Error( `The "${ randomPackageName }@${ version }" already exists in the npm registry.` );
58
- }
51
+ checkIfVersionIsValid( version );
59
52
 
60
53
  for ( const pkgJsonPath of pkgJsonPaths ) {
61
54
  const pkgJson = await fs.readJson( pkgJsonPath );
@@ -66,85 +59,18 @@ export default async function updateVersions( options ) {
66
59
  }
67
60
 
68
61
  /**
69
- * @param {String} cwd
70
- * @param {Array.<String>} globPatterns
71
- * @param {UpdateVersionsPackagesDirectoryFilter|null} packagesDirectoryFilter
72
- * @returns {Promise.<Array.<String>>}
73
- */
74
- async function getPackageJsonPaths( cwd, globPatterns, packagesDirectoryFilter ) {
75
- const pkgJsonPaths = await glob( globPatterns, {
76
- cwd,
77
- absolute: true,
78
- nodir: true
79
- } );
80
-
81
- if ( !packagesDirectoryFilter ) {
82
- return pkgJsonPaths;
83
- }
84
-
85
- return pkgJsonPaths.filter( packagesDirectoryFilter );
86
- }
87
-
88
- /**
89
- * @param {String} packagesDirectory
90
- * @returns {Promise.<Object>}
62
+ * @param {string} version
91
63
  */
92
- function readPackageJson( packagesDirectory ) {
93
- const packageJsonPath = join( packagesDirectory, 'package.json' );
94
-
95
- return fs.readJson( packageJsonPath );
96
- }
97
-
98
- /**
99
- * @param {String|null} packagesDirectory
100
- * @returns {Array.<String>}
101
- */
102
- function getGlobPatterns( packagesDirectory ) {
103
- const patterns = [ 'package.json' ];
104
-
105
- if ( packagesDirectory ) {
106
- patterns.push( packagesDirectory + '/*/package.json' );
107
- }
108
-
109
- return patterns;
110
- }
111
-
112
- /**
113
- * @param {Array.<String>} pkgJsonPaths
114
- * @param {String|null} packagesDirectory
115
- * @returns {Object}
116
- */
117
- function getRandomPackagePath( pkgJsonPaths, packagesDirectory ) {
118
- const randomPkgJsonPaths = packagesDirectory ?
119
- pkgJsonPaths.filter( packagePath => packagePath.includes( packagesDirectory ) ) :
120
- pkgJsonPaths;
121
- const randomPkgJsonPath = randomPkgJsonPaths[ Math.floor( Math.random() * randomPkgJsonPaths.length ) ];
122
-
123
- return dirname( randomPkgJsonPath );
124
- }
125
-
126
- /**
127
- * Checks if the specified version is greater than the current one.
128
- *
129
- * A nightly version is always considered as valid.
130
- *
131
- * @param {String} newVersion
132
- * @param {String} currentVersion
133
- */
134
- function checkIfVersionIsValid( newVersion, currentVersion ) {
135
- if ( newVersion.startsWith( '0.0.0-nightly' ) ) {
136
- return;
137
- }
138
-
139
- if ( !semver.gt( newVersion, currentVersion ) ) {
140
- throw new Error( `Provided version ${ newVersion } must be greater than ${ currentVersion } or match pattern 0.0.0-nightly.` );
64
+ function checkIfVersionIsValid( version ) {
65
+ if ( !semver.valid( version ) ) {
66
+ throw new Error( `Provided version ${ version } must follow the "Semantic Versioning" standard.` );
141
67
  }
142
68
  }
143
69
 
144
70
  /**
145
71
  * @callback UpdateVersionsPackagesDirectoryFilter
146
72
  *
147
- * @param {String} packageJsonPath An absolute path to a `package.json` file.
73
+ * @param {string} packageJsonPath An absolute path to a `package.json` file.
148
74
  *
149
- * @returns {Boolean} Whether to include (`true`) or skip (`false`) processing the given directory/package.
75
+ * @returns {boolean} Whether to include (`true`) or skip (`false`) processing the given directory/package.
150
76
  */
@@ -12,13 +12,23 @@ import checkVersionAvailability from '../utils/checkversionavailability.js';
12
12
  * Npm sometimes throws incorrect error 409 while publishing, while the package uploads correctly.
13
13
  * The purpose of the script is to validate if packages that threw 409 are uploaded correctly to npm.
14
14
  *
15
- * @param {Object} options
16
- * @param {String} options.packagesDirectory Relative path to a location of packages to release.
17
- * @param {String} options.version Version of the current release.
18
- * @param {Function} options.onSuccess Callback fired when function is successful.
15
+ * @param {object} options
16
+ * @param {string} options.packagesDirectory Relative path to a location of packages to release.
17
+ * @param {string} options.version Version of the current release.
18
+ * @param {function} options.onSuccess Callback fired when function is successful.
19
19
  * @returns {Promise}
20
20
  */
21
21
  export default async function verifyPackagesPublishedCorrectly( options ) {
22
+ process.emitWarning(
23
+ 'The `verifyPackagesPublishedCorrectly()` function is deprecated and will be removed in the upcoming release (v45). ' +
24
+ 'Its responsibility has been merged with `publishPackages()`.',
25
+ {
26
+ type: 'DeprecationWarning',
27
+ code: 'DEP0001',
28
+ detail: 'https://github.com/ckeditor/ckeditor5-dev/blob/master/DEPRECATIONS.md#dep0001-verifypackagespublishedcorrectly'
29
+ }
30
+ );
31
+
22
32
  const { packagesDirectory, version, onSuccess } = options;
23
33
  const packagesToVerify = await glob( upath.join( packagesDirectory, '*' ), { absolute: true } );
24
34
  const errors = [];
@@ -32,16 +42,12 @@ export default async function verifyPackagesPublishedCorrectly( options ) {
32
42
  for ( const packageToVerify of packagesToVerify ) {
33
43
  const packageJson = await fs.readJson( upath.join( packageToVerify, 'package.json' ) );
34
44
 
35
- try {
36
- const packageWasUploadedCorrectly = !await checkVersionAvailability( version, packageJson.name );
45
+ const isPackageVersionAvailable = await checkVersionAvailability( version, packageJson.name );
37
46
 
38
- if ( packageWasUploadedCorrectly ) {
39
- await fs.remove( packageToVerify );
40
- } else {
41
- errors.push( packageJson.name );
42
- }
43
- } catch {
47
+ if ( isPackageVersionAvailable ) {
44
48
  errors.push( packageJson.name );
49
+ } else {
50
+ await fs.remove( packageToVerify );
45
51
  }
46
52
  }
47
53
 
@@ -10,8 +10,8 @@ import { glob } from 'glob';
10
10
  /**
11
11
  * Checks if all files expected to be released actually exist in the package directory. Verification takes place for all packages.
12
12
  *
13
- * @param {String} packagePaths
14
- * @param {Object.<String, Array.<String>>|null} optionalEntries
13
+ * @param {string} packagePaths
14
+ * @param {Object.<string, Array.<string>>|null} optionalEntries
15
15
  * @returns {Promise}
16
16
  */
17
17
  export default async function assertFilesToPublish( packagePaths, optionalEntries = null ) {
@@ -62,10 +62,10 @@ export default async function assertFilesToPublish( packagePaths, optionalEntrie
62
62
  /**
63
63
  * Filters out the optional entries from the `files` field and returns only the required ones.
64
64
  *
65
- * @param {Array.<String>} entries
66
- * @param {String} packageName
67
- * @param {Object.<String, Array.<String>>|null} optionalEntries
68
- * @returns {Array.<String>}
65
+ * @param {Array.<string>} entries
66
+ * @param {string} packageName
67
+ * @param {Object.<string, Array.<string>>|null} optionalEntries
68
+ * @returns {Array.<string>}
69
69
  */
70
70
  function getRequiredEntries( entries, packageName, optionalEntries ) {
71
71
  if ( !optionalEntries ) {
@@ -8,7 +8,7 @@ import { tools } from '@ckeditor/ckeditor5-dev-utils';
8
8
  /**
9
9
  * Checks whether a user is logged to npm as the provided account name.
10
10
  *
11
- * @param {String} npmOwner Expected npm account name that should be logged into npm.
11
+ * @param {string} npmOwner Expected npm account name that should be logged into npm.
12
12
  * @returns {Promise}
13
13
  */
14
14
  export default async function assertNpmAuthorization( npmOwner ) {
@@ -5,13 +5,18 @@
5
5
 
6
6
  import fs from 'fs-extra';
7
7
  import upath from 'upath';
8
- import semver from 'semver';
8
+ import getNpmTagFromVersion from './getnpmtagfromversion.js';
9
+
10
+ const ALLOWED_NPM_LATEST_TAGS = [
11
+ 'staging',
12
+ 'next'
13
+ ];
9
14
 
10
15
  /**
11
16
  * Checks if the npm tag matches the tag calculated from the package version. Verification takes place for all packages.
12
17
  *
13
- * @param {Array.<String>} packagePaths
14
- * @param {String} npmTag
18
+ * @param {Array.<string>} packagePaths
19
+ * @param {string} npmTag
15
20
  * @returns {Promise}
16
21
  */
17
22
  export default async function assertNpmTag( packagePaths, npmTag ) {
@@ -20,13 +25,13 @@ export default async function assertNpmTag( packagePaths, npmTag ) {
20
25
  for ( const packagePath of packagePaths ) {
21
26
  const packageJsonPath = upath.join( packagePath, 'package.json' );
22
27
  const packageJson = await fs.readJson( packageJsonPath );
23
- const versionTag = getVersionTag( packageJson.version );
28
+ const versionTag = getNpmTagFromVersion( packageJson.version );
24
29
 
25
30
  if ( versionTag === npmTag ) {
26
31
  continue;
27
32
  }
28
33
 
29
- if ( versionTag === 'latest' && npmTag === 'staging' ) {
34
+ if ( versionTag === 'latest' && ALLOWED_NPM_LATEST_TAGS.includes( npmTag ) ) {
30
35
  continue;
31
36
  }
32
37
 
@@ -37,22 +42,3 @@ export default async function assertNpmTag( packagePaths, npmTag ) {
37
42
  throw new Error( errors.join( '\n' ) );
38
43
  }
39
44
  }
40
-
41
- /**
42
- * Returns the version tag for the package.
43
- *
44
- * For the official release, returns the "latest" tag. For a non-official release (pre-release), returns the version tag extracted from
45
- * the package version.
46
- *
47
- * @param {String} version
48
- * @returns {String}
49
- */
50
- function getVersionTag( version ) {
51
- const [ versionTag ] = semver.prerelease( version ) || [ 'latest' ];
52
-
53
- if ( versionTag.startsWith( 'nightly' ) ) {
54
- return 'nightly';
55
- }
56
-
57
- return versionTag;
58
- }
@@ -9,11 +9,11 @@ import upath from 'upath';
9
9
  /**
10
10
  * Checks if all packages in the provided directories contain the `package.json` file.
11
11
  *
12
- * @param {Array.<String>} packagePaths
13
- * @param {Object} options
14
- * @param {Boolean} options.requireEntryPoint Whether to verify if packages to publish define an entry point. In other words,
12
+ * @param {Array.<string>} packagePaths
13
+ * @param {object} options
14
+ * @param {boolean} options.requireEntryPoint Whether to verify if packages to publish define an entry point. In other words,
15
15
  * whether their `package.json` define the `main` field.
16
- * @param {Array.<String>} options.optionalEntryPointPackages If the entry point validator is enabled (`requireEntryPoint=true`),
16
+ * @param {Array.<string>} options.optionalEntryPointPackages If the entry point validator is enabled (`requireEntryPoint=true`),
17
17
  * this array contains a list of packages that will not be checked. In other words, they do not have to define the entry point.
18
18
  * @returns {Promise}
19
19
  */