Skip to content

Commit 0779459

Browse files
committed
chore: add try catch to release script to work around tailwindlabs/prettier-plugin-tailwindcss#321
1 parent 4a79990 commit 0779459

File tree

1 file changed

+101
-94
lines changed

1 file changed

+101
-94
lines changed

other/release.ts

Lines changed: 101 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -5,113 +5,120 @@ import { releaseChangelog, releasePublish, releaseVersion } from 'nx/release'
55
import { findMatchingProjects } from 'nx/src/utils/find-matching-projects.js'
66
import { default as yargs } from 'yargs'
77

8-
const options = await yargs(process.argv)
9-
.version(false) // don't use the default meaning of version in yargs
10-
.option('version', {
11-
description:
12-
'Explicit version specifier to use, if overriding conventional commits',
13-
type: 'string',
14-
})
15-
.option('dryRun', {
16-
alias: 'd',
17-
description:
18-
'Whether or not to perform a dry-run of the release process, defaults to true',
19-
type: 'boolean',
20-
default: true,
21-
})
22-
.option('verbose', {
23-
description: 'Whether or not to enable verbose logging, defaults to false',
24-
type: 'boolean',
25-
default: false,
26-
})
27-
.parseAsync()
28-
29-
// get the projects from the nx.json in the parent directory
30-
const nxJsonPath = path.join(workspaceRoot, 'nx.json')
31-
const nxJson = await fs.readJSON(nxJsonPath)
32-
const graph = await createProjectGraphAsync()
33-
const projects = findMatchingProjects(nxJson.release.projects, graph.nodes)
34-
const publishDir = path.join(workspaceRoot, 'publish')
35-
36-
await fs.remove(publishDir)
8+
try {
9+
const options = await yargs(process.argv)
10+
.version(false) // don't use the default meaning of version in yargs
11+
.option('version', {
12+
description:
13+
'Explicit version specifier to use, if overriding conventional commits',
14+
type: 'string',
15+
})
16+
.option('dryRun', {
17+
alias: 'd',
18+
description:
19+
'Whether or not to perform a dry-run of the release process, defaults to true',
20+
type: 'boolean',
21+
default: true,
22+
})
23+
.option('verbose', {
24+
description:
25+
'Whether or not to enable verbose logging, defaults to false',
26+
type: 'boolean',
27+
default: false,
28+
})
29+
.parseAsync()
3730

38-
for (const project of projects) {
39-
const projectNode = graph.nodes[project]
40-
if (!projectNode) {
41-
throw new Error('ahhhhhhhhhhhhhhhhhh! This should be unpossible!')
42-
}
31+
// get the projects from the nx.json in the parent directory
32+
const nxJsonPath = path.join(workspaceRoot, 'nx.json')
33+
const nxJson = await fs.readJSON(nxJsonPath)
34+
const graph = await createProjectGraphAsync()
35+
const projects = findMatchingProjects(nxJson.release.projects, graph.nodes)
36+
const publishDir = path.join(workspaceRoot, 'publish')
4337

44-
const srcPath = path.join(workspaceRoot, projectNode.data.root)
45-
const publishPath = path.join(publishDir, projectNode.data.root)
38+
await fs.remove(publishDir)
4639

47-
const packageJsonPath = path.join(srcPath, 'package.json')
48-
const packageJson = await fs.readJson(packageJsonPath)
49-
const hasBundleDependencies = packageJson.bundleDependencies?.length > 0
50-
const filesToCopy = [
51-
...(packageJson.files ?? []),
52-
'README.md',
53-
'package.json',
54-
hasBundleDependencies ? 'node_modules' : null,
55-
].filter(Boolean)
40+
for (const project of projects) {
41+
const projectNode = graph.nodes[project]
42+
if (!projectNode) {
43+
throw new Error('ahhhhhhhhhhhhhhhhhh! This should be unpossible!')
44+
}
5645

57-
await Promise.all(
58-
filesToCopy.map(async (file: string) => {
59-
const sourcePath = path.join(srcPath, file)
60-
const destinationPath = path.join(publishPath, file)
61-
if (await fs.pathExists(sourcePath)) {
62-
await fs.copy(sourcePath, destinationPath)
63-
}
64-
}),
65-
)
46+
const srcPath = path.join(workspaceRoot, projectNode.data.root)
47+
const publishPath = path.join(publishDir, projectNode.data.root)
6648

67-
if (hasBundleDependencies) {
68-
const exclude = [
69-
`${path.sep}.bin${path.sep}`,
70-
`${path.sep}.vite${path.sep}`,
71-
`${path.sep}.cache${path.sep}`,
72-
]
49+
const packageJsonPath = path.join(srcPath, 'package.json')
50+
const packageJson = await fs.readJson(packageJsonPath)
51+
const hasBundleDependencies = packageJson.bundleDependencies?.length > 0
52+
const filesToCopy = [
53+
...(packageJson.files ?? []),
54+
'README.md',
55+
'package.json',
56+
hasBundleDependencies ? 'node_modules' : null,
57+
].filter(Boolean)
7358

74-
await fs.copy(
75-
path.join(workspaceRoot, 'node_modules'),
76-
path.join(publishPath, 'node_modules'),
77-
{
78-
overwrite: false,
79-
dereference: false,
80-
filter: (srcPath: string) => !exclude.some((e) => srcPath.includes(e)),
81-
},
59+
await Promise.all(
60+
filesToCopy.map(async (file: string) => {
61+
const sourcePath = path.join(srcPath, file)
62+
const destinationPath = path.join(publishPath, file)
63+
if (await fs.pathExists(sourcePath)) {
64+
await fs.copy(sourcePath, destinationPath)
65+
}
66+
}),
8267
)
83-
}
84-
}
8568

86-
const { workspaceVersion, projectsVersionData } = await releaseVersion({
87-
gitCommit: false,
88-
stageChanges: false,
89-
gitTag: false,
90-
specifier: options.version,
91-
dryRun: options.dryRun,
92-
verbose: options.verbose,
93-
})
69+
if (hasBundleDependencies) {
70+
const exclude = [
71+
`${path.sep}.bin${path.sep}`,
72+
`${path.sep}.vite${path.sep}`,
73+
`${path.sep}.cache${path.sep}`,
74+
]
9475

95-
if (workspaceVersion === null) {
96-
console.log('No relevant changes detected, skipping release process.')
97-
process.exit(0)
98-
} else {
99-
if (process.env.CI || options.dryRun) {
100-
await releaseChangelog({
101-
gitCommit: false,
102-
stageChanges: false,
103-
gitTag: false,
104-
versionData: projectsVersionData,
105-
version: workspaceVersion,
106-
dryRun: options.dryRun,
107-
verbose: options.verbose,
108-
})
76+
await fs.copy(
77+
path.join(workspaceRoot, 'node_modules'),
78+
path.join(publishPath, 'node_modules'),
79+
{
80+
overwrite: false,
81+
dereference: false,
82+
filter: (srcPath: string) =>
83+
!exclude.some((e) => srcPath.includes(e)),
84+
},
85+
)
86+
}
10987
}
11088

111-
const result = await releasePublish({
89+
const { workspaceVersion, projectsVersionData } = await releaseVersion({
90+
gitCommit: false,
91+
stageChanges: false,
92+
gitTag: false,
93+
specifier: options.version,
11294
dryRun: options.dryRun,
11395
verbose: options.verbose,
11496
})
11597

116-
process.exit(result)
98+
if (workspaceVersion === null) {
99+
console.log('No relevant changes detected, skipping release process.')
100+
process.exit(0)
101+
} else {
102+
if (process.env.CI || options.dryRun) {
103+
await releaseChangelog({
104+
gitCommit: false,
105+
stageChanges: false,
106+
gitTag: false,
107+
versionData: projectsVersionData,
108+
version: workspaceVersion,
109+
dryRun: options.dryRun,
110+
verbose: options.verbose,
111+
})
112+
}
113+
114+
const result = await releasePublish({
115+
dryRun: options.dryRun,
116+
verbose: options.verbose,
117+
})
118+
119+
process.exit(result)
120+
}
121+
} catch (err) {
122+
console.error(err)
123+
process.exit(1)
117124
}

0 commit comments

Comments
 (0)