versionary 0.25.0 → 0.26.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.
- package/dist/strategy/python.js +82 -5
- package/dist/strategy/rust.js +3 -0
- package/package.json +1 -1
package/dist/strategy/python.js
CHANGED
|
@@ -166,6 +166,67 @@ function readPyProjectFromCwd(cwd) {
|
|
|
166
166
|
const content = node_fs_1.default.readFileSync(target, "utf8");
|
|
167
167
|
return { parsed: parsePyProject(content, "pyproject.toml"), rawPath: target };
|
|
168
168
|
}
|
|
169
|
+
function packageNameFromParsed(parsed) {
|
|
170
|
+
const projectName = parsed.project?.name;
|
|
171
|
+
if (typeof projectName === "string" && projectName.trim().length > 0) {
|
|
172
|
+
return projectName.trim();
|
|
173
|
+
}
|
|
174
|
+
const poetryName = parsed.toolPoetry?.name;
|
|
175
|
+
if (typeof poetryName === "string" && poetryName.trim().length > 0) {
|
|
176
|
+
return poetryName.trim();
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
function normalizeModuleName(name) {
|
|
181
|
+
return name.replace(/[-.]+/gu, "_");
|
|
182
|
+
}
|
|
183
|
+
function findAuxiliaryInitPy(cwd, parsed) {
|
|
184
|
+
const packageName = packageNameFromParsed(parsed);
|
|
185
|
+
if (!packageName) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
const moduleName = normalizeModuleName(packageName);
|
|
189
|
+
const candidates = [
|
|
190
|
+
node_path_1.default.join("src", moduleName, "__init__.py"),
|
|
191
|
+
node_path_1.default.join(moduleName, "__init__.py"),
|
|
192
|
+
];
|
|
193
|
+
for (const candidate of candidates) {
|
|
194
|
+
const absolute = node_path_1.default.join(cwd, candidate);
|
|
195
|
+
if (!node_fs_1.default.existsSync(absolute)) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const content = node_fs_1.default.readFileSync(absolute, "utf8");
|
|
199
|
+
if (SOURCE_FILE_VERSION_PATTERN.test(content)) {
|
|
200
|
+
return candidate;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
function tryUpdateInitPyVersion(cwd, relativePath, version) {
|
|
206
|
+
const absolute = node_path_1.default.join(cwd, relativePath);
|
|
207
|
+
const existing = node_fs_1.default.readFileSync(absolute, "utf8");
|
|
208
|
+
if (!SOURCE_FILE_VERSION_PATTERN.test(existing)) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
const updated = writeSourceFileVersion(existing, relativePath, version);
|
|
212
|
+
node_fs_1.default.writeFileSync(absolute, updated, "utf8");
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
function tryUpdatePyProjectVersion(cwd, version) {
|
|
216
|
+
const target = node_path_1.default.join(cwd, "pyproject.toml");
|
|
217
|
+
if (!node_fs_1.default.existsSync(target)) {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
const content = node_fs_1.default.readFileSync(target, "utf8");
|
|
221
|
+
const parsed = parsePyProject(content, "pyproject.toml");
|
|
222
|
+
const { projectVersion, poetryVersion } = lookupPyProjectVersions(parsed);
|
|
223
|
+
if (!projectVersion && !poetryVersion) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
const updated = writePyProjectVersion(content, "pyproject.toml", version);
|
|
227
|
+
node_fs_1.default.writeFileSync(target, updated, "utf8");
|
|
228
|
+
return "pyproject.toml";
|
|
229
|
+
}
|
|
169
230
|
exports.pythonVersionStrategy = {
|
|
170
231
|
name: "python",
|
|
171
232
|
getVersionFile(config) {
|
|
@@ -209,11 +270,27 @@ exports.pythonVersionStrategy = {
|
|
|
209
270
|
throw new Error(`Versionary requires ${versionFile} to exist.`);
|
|
210
271
|
}
|
|
211
272
|
const existing = node_fs_1.default.readFileSync(versionPath, "utf8");
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
273
|
+
const written = [];
|
|
274
|
+
if (isSourceFileMode(versionFile)) {
|
|
275
|
+
const updated = writeSourceFileVersion(existing, versionFile, version);
|
|
276
|
+
node_fs_1.default.writeFileSync(versionPath, updated, "utf8");
|
|
277
|
+
written.push(versionFile);
|
|
278
|
+
const auxiliary = tryUpdatePyProjectVersion(cwd, version);
|
|
279
|
+
if (auxiliary && auxiliary !== versionFile) {
|
|
280
|
+
written.push(auxiliary);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
const updated = writePyProjectVersion(existing, versionFile, version);
|
|
285
|
+
node_fs_1.default.writeFileSync(versionPath, updated, "utf8");
|
|
286
|
+
written.push(versionFile);
|
|
287
|
+
const parsed = parsePyProject(updated, versionFile);
|
|
288
|
+
const initPy = findAuxiliaryInitPy(cwd, parsed);
|
|
289
|
+
if (initPy && tryUpdateInitPyVersion(cwd, initPy, version)) {
|
|
290
|
+
written.push(initPy);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return written;
|
|
217
294
|
},
|
|
218
295
|
readPackageName(cwd, _config) {
|
|
219
296
|
const found = readPyProjectFromCwd(cwd);
|
package/dist/strategy/rust.js
CHANGED
|
@@ -748,6 +748,9 @@ exports.rustVersionStrategy = {
|
|
|
748
748
|
const manifestToPath = new Map();
|
|
749
749
|
for (const pkg of packages) {
|
|
750
750
|
const manifest = pkg.versionFile;
|
|
751
|
+
if (node_path_1.default.posix.basename(normalizeSlashPath(manifest)) !== "Cargo.toml") {
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
751
754
|
candidateManifests.push(manifest);
|
|
752
755
|
manifestToPath.set(manifest, pkg.packagePath);
|
|
753
756
|
if (pkg.nextVersion) {
|