@biffo/cli 0.199.6 → 0.199.8
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/index.js +43 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2309,9 +2309,50 @@ function stampCarriedFrom(content, templateFile) {
|
|
|
2309
2309
|
return content.replace(REVISION_RE, (m) => `${CARRIED_FROM_MARKER} ${templateFile}
|
|
2310
2310
|
${m}`);
|
|
2311
2311
|
}
|
|
2312
|
-
var
|
|
2312
|
+
var DOCSTRING_OPEN_RE = /^[rRuU]?("""|''')/;
|
|
2313
|
+
var DEF_OR_CLASS_RE = /^(async\s+def|def|class)\b/;
|
|
2314
|
+
var HEADER_END_RE = /:\s*(#.*)?$/;
|
|
2315
|
+
function stripPythonDocstrings(source) {
|
|
2316
|
+
const lines = source.split("\n");
|
|
2317
|
+
const out = [];
|
|
2318
|
+
let expectDocstring = true;
|
|
2319
|
+
let inHeader = false;
|
|
2320
|
+
let i = 0;
|
|
2321
|
+
while (i < lines.length) {
|
|
2322
|
+
const line = lines[i];
|
|
2323
|
+
const trimmed = line.trim();
|
|
2324
|
+
if (trimmed === "" || trimmed.startsWith("#")) {
|
|
2325
|
+
out.push(line);
|
|
2326
|
+
i++;
|
|
2327
|
+
continue;
|
|
2328
|
+
}
|
|
2329
|
+
const open = expectDocstring ? DOCSTRING_OPEN_RE.exec(trimmed) : null;
|
|
2330
|
+
if (open) {
|
|
2331
|
+
const delim = open[1];
|
|
2332
|
+
expectDocstring = false;
|
|
2333
|
+
if (trimmed.slice(open[0].length).includes(delim)) {
|
|
2334
|
+
i++;
|
|
2335
|
+
continue;
|
|
2336
|
+
}
|
|
2337
|
+
i++;
|
|
2338
|
+
while (i < lines.length && !lines[i].includes(delim)) i++;
|
|
2339
|
+
if (i < lines.length) i++;
|
|
2340
|
+
continue;
|
|
2341
|
+
}
|
|
2342
|
+
if (inHeader || DEF_OR_CLASS_RE.test(trimmed)) {
|
|
2343
|
+
const closed = HEADER_END_RE.test(line.trimEnd());
|
|
2344
|
+
inHeader = !closed;
|
|
2345
|
+
expectDocstring = closed;
|
|
2346
|
+
} else {
|
|
2347
|
+
expectDocstring = false;
|
|
2348
|
+
}
|
|
2349
|
+
out.push(line);
|
|
2350
|
+
i++;
|
|
2351
|
+
}
|
|
2352
|
+
return out.join("\n");
|
|
2353
|
+
}
|
|
2313
2354
|
function migrationBodyHash(content) {
|
|
2314
|
-
const normalised = content
|
|
2355
|
+
const normalised = stripPythonDocstrings(content).split("\n").map((line) => line.trimEnd()).filter(
|
|
2315
2356
|
(line) => !REVISION_RE.test(line) && !DOWN_REVISION_RE.test(line) && !line.trimStart().startsWith("#") && line !== ""
|
|
2316
2357
|
).join("\n");
|
|
2317
2358
|
return createHash("sha256").update(normalised).digest("hex");
|