Skip to content

Commit 858082d

Browse files
authored
ci: fix atomic-angular pnpm release from a dist folder (#6414)
1 parent 47d1b97 commit 858082d

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed
Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,53 @@
1-
import {resolve} from 'node:path';
1+
import {readFileSync, writeFileSync} from 'node:fs';
2+
import {dirname, resolve} from 'node:path';
3+
import {fileURLToPath} from 'node:url';
24

3-
process.env.INIT_CWD = resolve('./projects/atomic-angular/dist');
5+
const scriptsDir = dirname(fileURLToPath(import.meta.url));
6+
const packageDir = resolve(scriptsDir, '..');
7+
const packagesDir = resolve(packageDir, '..');
8+
const distDir = resolve(packageDir, 'projects/atomic-angular/dist');
9+
const distPackageJsonPath = resolve(distDir, 'package.json');
10+
11+
const resolveWorkspaceVersions = () => {
12+
const distPackageJson = JSON.parse(
13+
readFileSync(distPackageJsonPath, {encoding: 'utf-8'})
14+
);
15+
const entries = [
16+
{
17+
section: 'dependencies',
18+
name: '@coveo/atomic',
19+
source: resolve(packagesDir, 'atomic/package.json'),
20+
},
21+
{
22+
section: 'peerDependencies',
23+
name: '@coveo/headless',
24+
source: resolve(packagesDir, 'headless/package.json'),
25+
},
26+
];
27+
for (const {section, name, source} of entries) {
28+
const sectionData = distPackageJson[section];
29+
if (!sectionData) {
30+
continue;
31+
}
32+
const currentValue = sectionData[name];
33+
if (
34+
typeof currentValue !== 'string' ||
35+
!currentValue.startsWith('workspace:')
36+
) {
37+
continue;
38+
}
39+
const {version} = JSON.parse(readFileSync(source, {encoding: 'utf-8'}));
40+
if (!version) {
41+
throw new Error(`Missing version in ${source}`);
42+
}
43+
sectionData[name] = version;
44+
}
45+
writeFileSync(
46+
distPackageJsonPath,
47+
`${JSON.stringify(distPackageJson, null, 2)}\n`
48+
);
49+
};
50+
51+
resolveWorkspaceVersions();
52+
process.env.INIT_CWD = distDir;
453
await import('@coveo/ci/npm-publish-package.mjs');

0 commit comments

Comments
 (0)