Skip to content

Commit 6dacd4f

Browse files
feat: Update example dependencies when publishing (#35)
* feat: Update example dependencies when publishing * Improve console messages
1 parent 35ed35b commit 6dacd4f

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/publish/index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import path from 'node:path'
55
import { execSync } from 'node:child_process'
6+
import { existsSync, readdirSync } from 'node:fs'
67
import chalk from 'chalk'
78
import * as semver from 'semver'
89
import currentGitBranch from 'current-git-branch'
@@ -365,6 +366,41 @@ export const publish = async (options) => {
365366
)
366367
}
367368

369+
if (existsSync(path.resolve(rootDir, 'examples'))) {
370+
console.info('Updating examples to use new package versions...')
371+
const examplePkgJsonArray = /** @type {string[]} */ (
372+
readdirSync(path.resolve(rootDir, 'examples'), {
373+
recursive: true,
374+
}).filter(
375+
(file) =>
376+
typeof file === 'string' &&
377+
file.includes('package.json') &&
378+
!file.includes('node_modules'),
379+
)
380+
)
381+
if (examplePkgJsonArray.length !== 0) {
382+
for (const examplePkgJson of examplePkgJsonArray) {
383+
await updatePackageJson(
384+
path.resolve(rootDir, 'examples', examplePkgJson),
385+
(config) => {
386+
for (const pkg of changedPackages) {
387+
if (config.dependencies?.[pkg.name]) {
388+
config.dependencies[pkg.name] = `^${version}`
389+
}
390+
if (config.devDependencies?.[pkg.name]) {
391+
config.devDependencies[pkg.name] = `^${version}`
392+
}
393+
}
394+
},
395+
)
396+
}
397+
if (existsSync(path.resolve(rootDir, 'pnpm-lock.yaml'))) {
398+
console.info('Updating examples to use new package versions...')
399+
execSync('pnpm install')
400+
}
401+
}
402+
}
403+
368404
if (!process.env.CI) {
369405
console.warn(
370406
`This is a dry run for version ${version}. Push to CI to publish for real or set CI=true to override!`,

0 commit comments

Comments
 (0)