@jakubmazanec/carson-templates 5.0.2-unstable.fb513823 → 5.0.2
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.
package/package.json
CHANGED
|
@@ -88,7 +88,7 @@ jobs:
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
async function createChangeset(fileName, dependencyBumps, projects) {
|
|
91
|
-
console.log('Creating changeset
|
|
91
|
+
console.log('Creating changeset...');
|
|
92
92
|
|
|
93
93
|
let message = '';
|
|
94
94
|
|
|
@@ -104,7 +104,7 @@ jobs:
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
async function createChangesetForCarsonTemplates(fileName, dependencyBumps, projects) {
|
|
107
|
-
console.log('Creating changeset
|
|
107
|
+
console.log('Creating changeset for Carson templates update...');
|
|
108
108
|
|
|
109
109
|
let message = '';
|
|
110
110
|
|
|
@@ -182,9 +182,7 @@ jobs:
|
|
|
182
182
|
console.log('Updated projects:', updatedProjects);
|
|
183
183
|
console.log('Dependecy bumps (including the workspace):', Array.from(dependencyBumpsWithWorkspace));
|
|
184
184
|
|
|
185
|
-
if (
|
|
186
|
-
!updatedProjects.length && dependencyBumpsWithWorkspace.has('<%- TEMPLATE_PACKAGE_NAME %>')
|
|
187
|
-
) {
|
|
185
|
+
if (dependencyBumpsWithWorkspace.has('<%- TEMPLATE_PACKAGE_NAME %>')) {
|
|
188
186
|
updatedProjects = await getProjectsUsingCarsonTemplates();
|
|
189
187
|
|
|
190
188
|
await createChangesetForCarsonTemplates(changesetName, dependencyBumpsWithWorkspace, updatedProjects);
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
to: '.github/workflows/update-pull-request.yaml'
|
|
3
|
-
strategy: overwrite
|
|
4
|
-
---
|
|
5
|
-
#
|
|
6
|
-
# DO NOT EDIT!
|
|
7
|
-
# This file was autogenerated by Carson.
|
|
8
|
-
# Changes may cause incorrect behavior and will be lost when the file is regenerated.
|
|
9
|
-
#
|
|
10
|
-
# Run `npx carson update workspace` to regenerate.
|
|
11
|
-
#
|
|
12
|
-
|
|
13
|
-
name: Update pull request
|
|
14
|
-
|
|
15
|
-
on: [push, workflow_dispatch]
|
|
16
|
-
|
|
17
|
-
jobs:
|
|
18
|
-
update_pull_request:
|
|
19
|
-
name: Update pull request
|
|
20
|
-
if: ${{ contains(github.head_ref, 'renovate/') }}
|
|
21
|
-
runs-on: ubuntu-latest
|
|
22
|
-
timeout-minutes: 15
|
|
23
|
-
steps:
|
|
24
|
-
- uses: actions/checkout@v4
|
|
25
|
-
with:
|
|
26
|
-
ref: ${{ github.head_ref }}
|
|
27
|
-
token: ${{ secrets.PAT }}
|
|
28
|
-
fetch-depth: 0
|
|
29
|
-
|
|
30
|
-
- name: Configure git
|
|
31
|
-
run: |
|
|
32
|
-
git config user.email "bot@mazanec.dev"
|
|
33
|
-
git config user.name "Bot"
|
|
34
|
-
|
|
35
|
-
- uses: actions/setup-node@v4
|
|
36
|
-
with:
|
|
37
|
-
node-version: <%- semver.major(semver.minVersion(DEPENDENCY_VERSIONS.node)) %>
|
|
38
|
-
|
|
39
|
-
- name: Install packages
|
|
40
|
-
run: npm ci
|
|
41
|
-
|
|
42
|
-
- name: Generate changeset
|
|
43
|
-
uses: actions/github-script@v7
|
|
44
|
-
with:
|
|
45
|
-
script: |
|
|
46
|
-
let {promises: fs} = require('node:fs');
|
|
47
|
-
let path = require('node:path');
|
|
48
|
-
let semver = require('semver');
|
|
49
|
-
let _ = require('lodash');
|
|
50
|
-
|
|
51
|
-
async function checkCarsonTemplatesPackage(dependencyBumps) {
|
|
52
|
-
if (<%- !workspace.projects.some((project) => project.name === TEMPLATE_PACKAGE_NAME) %>) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
let constantsFilePath = '<%- `${workspace.projects.find((project) => project.name === TEMPLATE_PACKAGE_NAME)?.relativePath ?? ''}/source/constants.ts` %>';
|
|
57
|
-
let constantsFile = await fs.readFile(constantsFilePath, 'utf8');
|
|
58
|
-
|
|
59
|
-
for (let [dependencyName, bump] of dependencyBumps) {
|
|
60
|
-
let regexp = new RegExp(`(?<=('${_.escapeRegExp(dependencyName)}'|${_.escapeRegExp(dependencyName)}):\\s+')\\^\\d+\\.\\d+\\.\\d+(?='.*$)`, 'mi');
|
|
61
|
-
let result = regexp.exec(constantsFile);
|
|
62
|
-
|
|
63
|
-
if (result) {
|
|
64
|
-
let newMajorVersion = semver.major(semver.minVersion(bump));
|
|
65
|
-
let oldMajorVersion = semver.major(semver.minVersion(result[0]));
|
|
66
|
-
|
|
67
|
-
if (newMajorVersion > oldMajorVersion || dependencyName === 'node') { // Node.js is a special case, because it isn't specified in `dependencies` field
|
|
68
|
-
throw new Error(`Bumping major version of dependency "${dependencyName}" that is handled by Carson, update of the Carson template package is needed!`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function getProjects(files) {
|
|
77
|
-
let names = [];
|
|
78
|
-
|
|
79
|
-
for (let file of files) {
|
|
80
|
-
let packageJson = JSON.parse(await fs.readFile(file, 'utf8'));
|
|
81
|
-
|
|
82
|
-
names.push(packageJson.name);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return names;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function createChangeset(fileName, dependencyBumps, projects) {
|
|
89
|
-
console.log('Creating changeset', fileName, '...');
|
|
90
|
-
|
|
91
|
-
let message = '';
|
|
92
|
-
|
|
93
|
-
for (let [dependencyName, bump] of dependencyBumps) {
|
|
94
|
-
message = message + `Dependency \`${dependencyName}\` updated to version \`${bump}\`.\n`;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
message = message.replace('\n', ' ');
|
|
98
|
-
|
|
99
|
-
let header = projects.map((projectName) => `'${projectName}': patch`).join('\n');
|
|
100
|
-
|
|
101
|
-
await fs.writeFile(fileName, `---\n${header}\n---\n${message.trim()}\n`);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async function createChangesetForCarsonTemplates(fileName, dependencyBumps, projects) {
|
|
105
|
-
console.log('Creating changeset (Carson templates update)', fileName, '...');
|
|
106
|
-
|
|
107
|
-
let message = '';
|
|
108
|
-
|
|
109
|
-
for (let [dependencyName, bump] of dependencyBumps) {
|
|
110
|
-
message = message + `Applies templates from \`${dependencyName}\` updated to version \`${bump}\`.\n`;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
message = message.replace('\n', ' ');
|
|
114
|
-
|
|
115
|
-
let header = projects.map((projectName) => `'${projectName}': patch`).join('\n');
|
|
116
|
-
|
|
117
|
-
await fs.writeFile(fileName, `---\n${header}\n---\n${message.trim()}\n`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async function getBumps(files) {
|
|
121
|
-
let bumps = new Map();
|
|
122
|
-
|
|
123
|
-
for (let file of files) {
|
|
124
|
-
let {stdout: changes} = await exec.getExecOutput('git', ['show', file]);
|
|
125
|
-
|
|
126
|
-
for (let change of changes.split('\n')) {
|
|
127
|
-
if (!change.startsWith('+ ')) {
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
let match = change.match(/"(.*?)"/g);
|
|
132
|
-
|
|
133
|
-
bumps.set(match[0].replace(/"/g, ''), match[1].replace(/"/g, ''));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return bumps;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
async function getProjectsUsingCarsonTemplates(dir = process.cwd(), result = []) {
|
|
141
|
-
let entries = await fs.readdir(dir, {withFileTypes: true});
|
|
142
|
-
|
|
143
|
-
for (let entry of entries) {
|
|
144
|
-
let fullPath = path.join(dir, entry.name);
|
|
145
|
-
|
|
146
|
-
if (entry.isDirectory()) {
|
|
147
|
-
if (entry.name === '.carson' && dir !== process.cwd()) {
|
|
148
|
-
let packageJson = JSON.parse(await fs.readFile(path.join(dir, 'package.json'), 'utf8'));
|
|
149
|
-
|
|
150
|
-
result.push(packageJson.name);
|
|
151
|
-
} else {
|
|
152
|
-
await getProjectsUsingCarsonTemplates(fullPath, result);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return result;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
let diffOutput = await exec.getExecOutput('git diff --name-only HEAD~1');
|
|
161
|
-
let diffFiles = diffOutput.stdout.split('\n');
|
|
162
|
-
|
|
163
|
-
if (diffFiles.find((diffFile) => diffFile.startsWith('.changeset'))) {
|
|
164
|
-
console.log('Changeset already exists, skipping...');
|
|
165
|
-
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
let files = diffFiles
|
|
170
|
-
.filter((file) => file !== 'package.json') // skip workspace package.json
|
|
171
|
-
.filter((file) => file.includes('package.json'));
|
|
172
|
-
let filesWithWorkspace = diffFiles
|
|
173
|
-
.filter((file) => file.includes('package.json'));
|
|
174
|
-
let {stdout: shortHash} = await exec.getExecOutput('git rev-parse --short HEAD');
|
|
175
|
-
let changesetName = `.changeset/renovate-${shortHash.trim()}.md`;
|
|
176
|
-
let updatedProjects = await getProjects(files);
|
|
177
|
-
let dependencyBumpsWithWorkspace = await getBumps(filesWithWorkspace);
|
|
178
|
-
|
|
179
|
-
console.log('Changed package.json files:', files);
|
|
180
|
-
console.log('Updated projects:', updatedProjects);
|
|
181
|
-
console.log('Dependecy bumps (including the workspace):', Array.from(dependencyBumpsWithWorkspace));
|
|
182
|
-
|
|
183
|
-
if (
|
|
184
|
-
!updatedProjects.length && dependencyBumpsWithWorkspace.has('<%- TEMPLATE_PACKAGE_NAME %>')
|
|
185
|
-
) {
|
|
186
|
-
updatedProjects = await getProjectsUsingCarsonTemplates();
|
|
187
|
-
|
|
188
|
-
await createChangesetForCarsonTemplates(changesetName, dependencyBumpsWithWorkspace, updatedProjects);
|
|
189
|
-
|
|
190
|
-
return;
|
|
191
|
-
} else if (!updatedProjects.length) {
|
|
192
|
-
console.log('No package.json changes to published packages, skipping...');
|
|
193
|
-
|
|
194
|
-
await exec.exec('npx', ['changeset', '--empty']);
|
|
195
|
-
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
let dependencyBumps = await getBumps(files);
|
|
200
|
-
|
|
201
|
-
console.log('Dependecy bumps:', Array.from(dependencyBumps));
|
|
202
|
-
|
|
203
|
-
await createChangeset(changesetName, dependencyBumps, updatedProjects);
|
|
204
|
-
|
|
205
|
-
await checkCarsonTemplatesPackage(dependencyBumpsWithWorkspace);
|
|
206
|
-
|
|
207
|
-
- name: Update Carson
|
|
208
|
-
run: |
|
|
209
|
-
npm install
|
|
210
|
-
|
|
211
|
-
- name: Commit and push changes
|
|
212
|
-
run: |
|
|
213
|
-
git add . --all
|
|
214
|
-
git commit -m"Update"
|
|
215
|
-
git push --force
|