aberlaas-release 2.21.1 → 2.22.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.
@@ -0,0 +1,106 @@
1
+ import path from 'node:path';
2
+ import { _, pMap } from 'golgoth';
3
+ import { consoleInfo, firostError, run as firostRun } from 'firost';
4
+
5
+ export let __;
6
+
7
+ /**
8
+ * Ensures that all packages in the release have the correct files that will be published
9
+ * @param {object} releaseData - The release data containing package information
10
+ * @param {Array} releaseData.allPackages - Array of all packages to be released
11
+ * @returns {boolean} True when all packages have been verified
12
+ */
13
+ export async function ensureCorrectPublishedFiles(releaseData) {
14
+ const { allPackages } = releaseData;
15
+ __.consoleInfo('Checking files to publish...');
16
+ await pMap(allPackages, __.ensureSameFilesPublishedWithYarnOrNpm, {
17
+ concurrency: 5,
18
+ });
19
+ return true;
20
+ }
21
+
22
+ __ = {
23
+ async ensureSameFilesPublishedWithYarnOrNpm(packageData) {
24
+ const packageName = packageData.content.name;
25
+ const npmFiles = await __.getNpmPublishedFiles(packageData);
26
+ const yarnFiles = await __.getYarnPublishedFiles(packageData);
27
+
28
+ if (_.isEqual(npmFiles, yarnFiles)) {
29
+ return true;
30
+ }
31
+
32
+ const onlyInNpm = _.difference(npmFiles, yarnFiles);
33
+ const onlyInYarn = _.difference(yarnFiles, npmFiles);
34
+ const message = [
35
+ `[${packageName}] Files published by npm and yarn will be different:\n`,
36
+ ];
37
+ if (!_.isEmpty(onlyInNpm)) {
38
+ message.push('Only in npm:');
39
+ message.push(' - ' + onlyInNpm.join('\n - '));
40
+ message.push('');
41
+ }
42
+ if (!_.isEmpty(onlyInYarn)) {
43
+ message.push('Only in yarn:');
44
+ message.push(' - ' + onlyInYarn.join('\n - '));
45
+ }
46
+ message.push('\nPlease check your .files key in package.json');
47
+ throw firostError(
48
+ 'ABERLAAS_RELEASE_NPM_YARN_DIFFERENT_PUBLISHED_FILES',
49
+ message.join('\n'),
50
+ );
51
+ },
52
+
53
+ /**
54
+ * Gets the list of files that would be published to npm for a given package
55
+ * @param {object} packageData - Package data object containing filepath and content
56
+ * @param {string} packageData.filepath - Path to the package.json file
57
+ * @returns {string[]} Sorted array of file paths that would be published
58
+ */
59
+ async getNpmPublishedFiles(packageData) {
60
+ const packageJsonPath = packageData.filepath;
61
+ const packageJsonDir = path.dirname(packageJsonPath);
62
+ const { stdout } = await __.firostRun('npm publish --dry-run --json', {
63
+ cwd: packageJsonDir,
64
+ stdout: false,
65
+ stderr: false,
66
+ });
67
+
68
+ return __.parseNpmPublishOutput(stdout);
69
+ },
70
+ parseNpmPublishOutput(stdout) {
71
+ const parsedOutput = JSON.parse(stdout);
72
+
73
+ // Output either contains directly an object with all info, or the object
74
+ // itself is in a key with the name of the package (in case of workspaces)
75
+ const keys = _.keys(parsedOutput);
76
+ const root = keys.length === 1 ? parsedOutput[keys[0]] : parsedOutput;
77
+
78
+ return _.chain(root).get('files').map('path').sort().value();
79
+ },
80
+ /**
81
+ * Gets the list of files that would be published to npm for a package using yarn
82
+ * @param {object} packageData - Package data object containing file information
83
+ * @param {string} packageData.filepath - Path to the package.json file
84
+ * @returns {string[]} Sorted array of file paths that would be published
85
+ */
86
+ async getYarnPublishedFiles(packageData) {
87
+ const packageJsonPath = packageData.filepath;
88
+ const packageJsonDir = path.dirname(packageJsonPath);
89
+ const { stdout } = await __.firostRun('yarn npm publish --dry-run --json', {
90
+ cwd: packageJsonDir,
91
+ stdout: false,
92
+ stderr: false,
93
+ });
94
+
95
+ return _.chain(stdout)
96
+ .split('\n')
97
+ .last()
98
+ .thru(JSON.parse)
99
+ .get('files')
100
+ .sort()
101
+ .value();
102
+ },
103
+
104
+ consoleInfo,
105
+ firostRun,
106
+ };
package/lib/main.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { consoleInfo, run as firostRun } from 'firost';
2
+ import { ensureCorrectPublishedFiles } from './ensureCorrectPublishedFiles.js';
2
3
  import { ensureValidSetup } from './ensureValidSetup.js';
3
4
  import { getReleaseData } from './getReleaseData.js';
4
5
  import { publishToNpm } from './publishToNpm.js';
@@ -15,6 +16,8 @@ export async function run(cliArgs = {}) {
15
16
  await __.ensureValidSetup(cliArgs);
16
17
 
17
18
  const releaseData = await __.getReleaseData(cliArgs);
19
+ await __.ensureCorrectPublishedFiles(releaseData);
20
+
18
21
  __.consoleInfo(`Release new version ${releaseData.newVersion}`);
19
22
 
20
23
  await __.updateGitRepo(releaseData);
@@ -24,6 +27,7 @@ export async function run(cliArgs = {}) {
24
27
 
25
28
  __ = {
26
29
  ensureValidSetup,
30
+ ensureCorrectPublishedFiles,
27
31
  getReleaseData,
28
32
  publishToNpm,
29
33
  updateGitRepo,
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "aberlaas-release",
3
+ "version": "2.22.0",
3
4
  "type": "module",
4
- "sideEffects": false,
5
5
  "description": "aberlaas release command: Release and publish new versions",
6
- "version": "2.21.1",
7
- "repository": "pixelastic/aberlaas",
6
+ "author": "Tim Carry <tim@pixelastic.com>",
8
7
  "homepage": "https://projects.pixelastic.com/aberlaas/",
9
- "author": "Tim Carry (@pixelastic)",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/pixelastic/aberlaas"
11
+ },
12
+ "sideEffects": false,
10
13
  "license": "MIT",
11
14
  "files": [
12
15
  "lib/*.js"
@@ -15,13 +18,10 @@
15
18
  ".": "./lib/main.js"
16
19
  },
17
20
  "main": "./lib/main.js",
18
- "engines": {
19
- "node": ">=18.18.0"
20
- },
21
21
  "dependencies": {
22
- "aberlaas-helper": "2.21.1",
23
- "aberlaas-lint": "2.21.1",
24
- "aberlaas-test": "2.21.1",
22
+ "aberlaas-helper": "2.22.0",
23
+ "aberlaas-lint": "2.22.0",
24
+ "aberlaas-test": "2.22.0",
25
25
  "changelogen": "0.6.2",
26
26
  "cli-markdown": "3.5.1",
27
27
  "envfile": "7.1.0",
@@ -34,13 +34,13 @@
34
34
  "build": "cd ../docs && yarn run build",
35
35
  "build:prod": "cd ../docs && yarn run build:prod",
36
36
  "cms": "cd ../docs && yarn run cms",
37
- "serve": "cd ../docs && yarn run serve",
38
- "release": "cd ../.. && ./scripts/release",
39
- "test:meta": "cd ../.. && ./scripts/test-meta",
40
- "test": "cd ../.. && ./scripts/test",
41
- "test:watch": "cd ../.. && ./scripts/test-watch",
42
37
  "compress": "cd ../.. && ./scripts/compress",
43
38
  "lint": "cd ../.. && ./scripts/lint",
44
- "lint:fix": "cd ../.. && ./scripts/lint-fix"
39
+ "lint:fix": "cd ../.. && ./scripts/lint-fix",
40
+ "release": "cd ../.. && ./scripts/release",
41
+ "serve": "cd ../docs && yarn run serve",
42
+ "test": "cd ../.. && ./scripts/test",
43
+ "test:meta": "cd ../.. && ./scripts/test-meta",
44
+ "test:watch": "cd ../.. && ./scripts/test-watch"
45
45
  }
46
46
  }