screw-up 1.28.0 → 1.30.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/index.cjs +543 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +472 -68
- package/dist/index.mjs.map +1 -1
- package/dist/main.cjs +76 -7
- package/dist/main.cjs.map +1 -1
- package/dist/main.mjs +5 -5
- package/dist/main.mjs.map +1 -1
- package/dist/{metadata-file-DtvzENuT.js → metadata-file-CpFkBJPS.js} +75 -6
- package/dist/{metadata-file-DtvzENuT.js.map → metadata-file-CpFkBJPS.js.map} +1 -1
- package/dist/{packageMetadata-D1X6rTp_.cjs → packageMetadata-Lj9bVuVM.cjs} +5 -5
- package/dist/{packageMetadata-D1X6rTp_.cjs.map → packageMetadata-Lj9bVuVM.cjs.map} +1 -1
- package/dist/{packageMetadata-11MbeI_K.js → packageMetadata-YWwXZbaj.js} +6 -6
- package/dist/{packageMetadata-11MbeI_K.js.map → packageMetadata-YWwXZbaj.js.map} +1 -1
- package/dist/{packageMetadata-CCdz0AMJ.cjs → packageMetadata-zaiRRUve.cjs} +3 -3
- package/dist/src/analyzer.d.ts +2 -2
- package/dist/src/analyzer.d.ts.map +1 -1
- package/dist/src/cli-internal.d.ts +3 -3
- package/dist/src/cli-internal.d.ts.map +1 -1
- package/dist/src/cli.d.ts +3 -3
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/declaration-import-fix.d.ts +21 -0
- package/dist/src/declaration-import-fix.d.ts.map +1 -0
- package/dist/src/default-import-fix.d.ts +2 -2
- package/dist/src/default-import-fix.d.ts.map +1 -1
- package/dist/src/fast-tags.d.ts +2 -2
- package/dist/src/fast-tags.d.ts.map +1 -1
- package/dist/src/generated/packageMetadata.d.ts +4 -4
- package/dist/src/git-operations.d.ts +3 -3
- package/dist/src/git-operations.d.ts.map +1 -1
- package/dist/src/index.d.ts +4 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/internal.d.ts +3 -3
- package/dist/src/main.d.ts +2 -2
- package/dist/src/metadata-file.d.ts +4 -4
- package/dist/src/metadata-file.d.ts.map +1 -1
- package/dist/src/text-edits.d.ts +24 -0
- package/dist/src/text-edits.d.ts.map +1 -0
- package/dist/src/types.d.ts +7 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/vite-plugin.d.ts +3 -3
- package/dist/src/vite-plugin.d.ts.map +1 -1
- package/package.json +14 -10
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: screw-up
|
|
3
|
-
* version: 1.
|
|
3
|
+
* version: 1.30.0
|
|
4
4
|
* description: Simply package metadata inserter on Vite plugin
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/screw-up.git
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: ac6785ada0880218ecbaef699721d3a169362e76
|
|
9
9
|
*/
|
|
10
10
|
//#region \0rolldown/runtime.js
|
|
11
11
|
var __create = Object.create;
|
|
@@ -198,8 +198,8 @@ createLogicalContext(Symbol("[root]"));
|
|
|
198
198
|
//#endregion
|
|
199
199
|
//#region src/generated/packageMetadata.ts
|
|
200
200
|
var name = "screw-up";
|
|
201
|
-
var version = "1.
|
|
202
|
-
var git_commit_hash = "
|
|
201
|
+
var version = "1.30.0";
|
|
202
|
+
var git_commit_hash = "ac6785ada0880218ecbaef699721d3a169362e76";
|
|
203
203
|
//#endregion
|
|
204
204
|
//#region node_modules/json5/dist/index.js
|
|
205
205
|
var require_dist = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
@@ -2237,12 +2237,81 @@ var getRelatedBranches = async (repositoryPath, commitHash) => {
|
|
|
2237
2237
|
* @param repositoryPath - Local Git repository directory
|
|
2238
2238
|
* @returns Modified files
|
|
2239
2239
|
*/
|
|
2240
|
+
var isModifiedFile = ([, head, workdir, stage]) => {
|
|
2241
|
+
return workdir === 2 || stage === 2 || stage === 3 || head === 1 && workdir === 0 || head === 0 && workdir === 1;
|
|
2242
|
+
};
|
|
2243
|
+
var getStatusRow = async (filepath, entries) => {
|
|
2244
|
+
const [head, workdir, stage] = entries;
|
|
2245
|
+
const [headType, workdirType, stageType] = await Promise.all([
|
|
2246
|
+
head ? head.type() : void 0,
|
|
2247
|
+
workdir ? workdir.type() : void 0,
|
|
2248
|
+
stage ? stage.type() : void 0
|
|
2249
|
+
]);
|
|
2250
|
+
const isBlob = [
|
|
2251
|
+
headType,
|
|
2252
|
+
workdirType,
|
|
2253
|
+
stageType
|
|
2254
|
+
].includes("blob");
|
|
2255
|
+
if ((headType === "tree" || headType === "special") && !isBlob) return;
|
|
2256
|
+
if (headType === "commit") return;
|
|
2257
|
+
if ((workdirType === "tree" || workdirType === "special") && !isBlob) return;
|
|
2258
|
+
if (stageType === "commit") return;
|
|
2259
|
+
if ((stageType === "tree" || stageType === "special") && !isBlob) return;
|
|
2260
|
+
const headOid = headType === "blob" ? await head.oid() : void 0;
|
|
2261
|
+
const stageOid = stageType === "blob" ? await stage.oid() : void 0;
|
|
2262
|
+
let workdirOid;
|
|
2263
|
+
if (headType !== "blob" && workdirType === "blob" && stageType !== "blob") workdirOid = "42";
|
|
2264
|
+
else if (workdirType === "blob") workdirOid = await workdir.oid();
|
|
2265
|
+
const entry = [
|
|
2266
|
+
void 0,
|
|
2267
|
+
headOid,
|
|
2268
|
+
workdirOid,
|
|
2269
|
+
stageOid
|
|
2270
|
+
];
|
|
2271
|
+
const statusValues = entry.map((value) => entry.indexOf(value));
|
|
2272
|
+
return [
|
|
2273
|
+
filepath,
|
|
2274
|
+
statusValues[1],
|
|
2275
|
+
statusValues[2],
|
|
2276
|
+
statusValues[3]
|
|
2277
|
+
];
|
|
2278
|
+
};
|
|
2279
|
+
var reduceModifiedFiles = async (parent, children) => {
|
|
2280
|
+
const modifiedFiles = parent ? [parent] : [];
|
|
2281
|
+
for (const child of children) modifiedFiles.push(...child);
|
|
2282
|
+
return modifiedFiles;
|
|
2283
|
+
};
|
|
2284
|
+
var iterateSequentially = async (walk, children) => {
|
|
2285
|
+
const results = [];
|
|
2286
|
+
for (const child of children) results.push(await walk(child));
|
|
2287
|
+
return results;
|
|
2288
|
+
};
|
|
2240
2289
|
var getModifiedFiles = async (repositoryPath) => {
|
|
2241
2290
|
try {
|
|
2242
|
-
return
|
|
2291
|
+
return await isomorphic_git.walk({
|
|
2243
2292
|
fs: fs_promises.default,
|
|
2244
|
-
dir: repositoryPath
|
|
2245
|
-
|
|
2293
|
+
dir: repositoryPath,
|
|
2294
|
+
trees: [
|
|
2295
|
+
isomorphic_git.TREE({ ref: "HEAD" }),
|
|
2296
|
+
isomorphic_git.WORKDIR(),
|
|
2297
|
+
isomorphic_git.STAGE()
|
|
2298
|
+
],
|
|
2299
|
+
map: async (filepath, entries) => {
|
|
2300
|
+
const [head, workdir, stage] = entries;
|
|
2301
|
+
if (!head && !stage && workdir) {
|
|
2302
|
+
if (await isomorphic_git.isIgnored({
|
|
2303
|
+
fs: fs_promises.default,
|
|
2304
|
+
dir: repositoryPath,
|
|
2305
|
+
filepath
|
|
2306
|
+
})) return null;
|
|
2307
|
+
}
|
|
2308
|
+
const statusRow = await getStatusRow(filepath, entries);
|
|
2309
|
+
if (!statusRow || !isModifiedFile(statusRow)) return;
|
|
2310
|
+
return statusRow;
|
|
2311
|
+
},
|
|
2312
|
+
reduce: reduceModifiedFiles,
|
|
2313
|
+
iterate: iterateSequentially
|
|
2314
|
+
});
|
|
2246
2315
|
} catch (_unused5) {
|
|
2247
2316
|
return [];
|
|
2248
2317
|
}
|
|
@@ -2389,6 +2458,375 @@ var getFetchGitMetadata = (targetDir, checkWorkingDirectoryStatus, logger) => {
|
|
|
2389
2458
|
};
|
|
2390
2459
|
};
|
|
2391
2460
|
//#endregion
|
|
2461
|
+
//#region node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
2462
|
+
var comma = ",".charCodeAt(0);
|
|
2463
|
+
var semicolon = ";".charCodeAt(0);
|
|
2464
|
+
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
2465
|
+
var intToChar = new Uint8Array(64);
|
|
2466
|
+
var charToInt = new Uint8Array(128);
|
|
2467
|
+
for (let i = 0; i < chars.length; i++) {
|
|
2468
|
+
const c = chars.charCodeAt(i);
|
|
2469
|
+
intToChar[i] = c;
|
|
2470
|
+
charToInt[c] = i;
|
|
2471
|
+
}
|
|
2472
|
+
function decodeInteger(reader, relative) {
|
|
2473
|
+
let value = 0;
|
|
2474
|
+
let shift = 0;
|
|
2475
|
+
let integer = 0;
|
|
2476
|
+
do {
|
|
2477
|
+
integer = charToInt[reader.next()];
|
|
2478
|
+
value |= (integer & 31) << shift;
|
|
2479
|
+
shift += 5;
|
|
2480
|
+
} while (integer & 32);
|
|
2481
|
+
const shouldNegate = value & 1;
|
|
2482
|
+
value >>>= 1;
|
|
2483
|
+
if (shouldNegate) value = -2147483648 | -value;
|
|
2484
|
+
return relative + value;
|
|
2485
|
+
}
|
|
2486
|
+
function encodeInteger(builder, num, relative) {
|
|
2487
|
+
let delta = num - relative;
|
|
2488
|
+
delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
|
|
2489
|
+
do {
|
|
2490
|
+
let clamped = delta & 31;
|
|
2491
|
+
delta >>>= 5;
|
|
2492
|
+
if (delta > 0) clamped |= 32;
|
|
2493
|
+
builder.write(intToChar[clamped]);
|
|
2494
|
+
} while (delta > 0);
|
|
2495
|
+
return num;
|
|
2496
|
+
}
|
|
2497
|
+
function hasMoreVlq(reader, max) {
|
|
2498
|
+
if (reader.pos >= max) return false;
|
|
2499
|
+
return reader.peek() !== comma;
|
|
2500
|
+
}
|
|
2501
|
+
var bufLength = 1024 * 16;
|
|
2502
|
+
var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? { decode(buf) {
|
|
2503
|
+
return Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength).toString();
|
|
2504
|
+
} } : { decode(buf) {
|
|
2505
|
+
let out = "";
|
|
2506
|
+
for (let i = 0; i < buf.length; i++) out += String.fromCharCode(buf[i]);
|
|
2507
|
+
return out;
|
|
2508
|
+
} };
|
|
2509
|
+
var StringWriter = class {
|
|
2510
|
+
constructor() {
|
|
2511
|
+
this.pos = 0;
|
|
2512
|
+
this.out = "";
|
|
2513
|
+
this.buffer = new Uint8Array(bufLength);
|
|
2514
|
+
}
|
|
2515
|
+
write(v) {
|
|
2516
|
+
const { buffer } = this;
|
|
2517
|
+
buffer[this.pos++] = v;
|
|
2518
|
+
if (this.pos === bufLength) {
|
|
2519
|
+
this.out += td.decode(buffer);
|
|
2520
|
+
this.pos = 0;
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
flush() {
|
|
2524
|
+
const { buffer, out, pos } = this;
|
|
2525
|
+
return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
|
|
2526
|
+
}
|
|
2527
|
+
};
|
|
2528
|
+
var StringReader = class {
|
|
2529
|
+
constructor(buffer) {
|
|
2530
|
+
this.pos = 0;
|
|
2531
|
+
this.buffer = buffer;
|
|
2532
|
+
}
|
|
2533
|
+
next() {
|
|
2534
|
+
return this.buffer.charCodeAt(this.pos++);
|
|
2535
|
+
}
|
|
2536
|
+
peek() {
|
|
2537
|
+
return this.buffer.charCodeAt(this.pos);
|
|
2538
|
+
}
|
|
2539
|
+
indexOf(char) {
|
|
2540
|
+
const { buffer, pos } = this;
|
|
2541
|
+
const idx = buffer.indexOf(char, pos);
|
|
2542
|
+
return idx === -1 ? buffer.length : idx;
|
|
2543
|
+
}
|
|
2544
|
+
};
|
|
2545
|
+
function decode(mappings) {
|
|
2546
|
+
const { length } = mappings;
|
|
2547
|
+
const reader = new StringReader(mappings);
|
|
2548
|
+
const decoded = [];
|
|
2549
|
+
let genColumn = 0;
|
|
2550
|
+
let sourcesIndex = 0;
|
|
2551
|
+
let sourceLine = 0;
|
|
2552
|
+
let sourceColumn = 0;
|
|
2553
|
+
let namesIndex = 0;
|
|
2554
|
+
do {
|
|
2555
|
+
const semi = reader.indexOf(";");
|
|
2556
|
+
const line = [];
|
|
2557
|
+
let sorted = true;
|
|
2558
|
+
let lastCol = 0;
|
|
2559
|
+
genColumn = 0;
|
|
2560
|
+
while (reader.pos < semi) {
|
|
2561
|
+
let seg;
|
|
2562
|
+
genColumn = decodeInteger(reader, genColumn);
|
|
2563
|
+
if (genColumn < lastCol) sorted = false;
|
|
2564
|
+
lastCol = genColumn;
|
|
2565
|
+
if (hasMoreVlq(reader, semi)) {
|
|
2566
|
+
sourcesIndex = decodeInteger(reader, sourcesIndex);
|
|
2567
|
+
sourceLine = decodeInteger(reader, sourceLine);
|
|
2568
|
+
sourceColumn = decodeInteger(reader, sourceColumn);
|
|
2569
|
+
if (hasMoreVlq(reader, semi)) {
|
|
2570
|
+
namesIndex = decodeInteger(reader, namesIndex);
|
|
2571
|
+
seg = [
|
|
2572
|
+
genColumn,
|
|
2573
|
+
sourcesIndex,
|
|
2574
|
+
sourceLine,
|
|
2575
|
+
sourceColumn,
|
|
2576
|
+
namesIndex
|
|
2577
|
+
];
|
|
2578
|
+
} else seg = [
|
|
2579
|
+
genColumn,
|
|
2580
|
+
sourcesIndex,
|
|
2581
|
+
sourceLine,
|
|
2582
|
+
sourceColumn
|
|
2583
|
+
];
|
|
2584
|
+
} else seg = [genColumn];
|
|
2585
|
+
line.push(seg);
|
|
2586
|
+
reader.pos++;
|
|
2587
|
+
}
|
|
2588
|
+
if (!sorted) sort(line);
|
|
2589
|
+
decoded.push(line);
|
|
2590
|
+
reader.pos = semi + 1;
|
|
2591
|
+
} while (reader.pos <= length);
|
|
2592
|
+
return decoded;
|
|
2593
|
+
}
|
|
2594
|
+
function sort(line) {
|
|
2595
|
+
line.sort(sortComparator);
|
|
2596
|
+
}
|
|
2597
|
+
function sortComparator(a, b) {
|
|
2598
|
+
return a[0] - b[0];
|
|
2599
|
+
}
|
|
2600
|
+
function encode(decoded) {
|
|
2601
|
+
const writer = new StringWriter();
|
|
2602
|
+
let sourcesIndex = 0;
|
|
2603
|
+
let sourceLine = 0;
|
|
2604
|
+
let sourceColumn = 0;
|
|
2605
|
+
let namesIndex = 0;
|
|
2606
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
2607
|
+
const line = decoded[i];
|
|
2608
|
+
if (i > 0) writer.write(semicolon);
|
|
2609
|
+
if (line.length === 0) continue;
|
|
2610
|
+
let genColumn = 0;
|
|
2611
|
+
for (let j = 0; j < line.length; j++) {
|
|
2612
|
+
const segment = line[j];
|
|
2613
|
+
if (j > 0) writer.write(comma);
|
|
2614
|
+
genColumn = encodeInteger(writer, segment[0], genColumn);
|
|
2615
|
+
if (segment.length === 1) continue;
|
|
2616
|
+
sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
|
|
2617
|
+
sourceLine = encodeInteger(writer, segment[2], sourceLine);
|
|
2618
|
+
sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
|
|
2619
|
+
if (segment.length === 4) continue;
|
|
2620
|
+
namesIndex = encodeInteger(writer, segment[4], namesIndex);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
return writer.flush();
|
|
2624
|
+
}
|
|
2625
|
+
//#endregion
|
|
2626
|
+
//#region src/text-edits.ts
|
|
2627
|
+
var readNewlineAt = (value, index) => {
|
|
2628
|
+
if (index < 0 || index >= value.length) return;
|
|
2629
|
+
if (value.startsWith("\r\n", index)) return "\r\n";
|
|
2630
|
+
const char = value[index];
|
|
2631
|
+
if (char === "\n" || char === "\r") return char;
|
|
2632
|
+
};
|
|
2633
|
+
var findFirstNewline = (value) => {
|
|
2634
|
+
for (let index = 0; index < value.length; index++) {
|
|
2635
|
+
const newline = readNewlineAt(value, index);
|
|
2636
|
+
if (newline) return newline;
|
|
2637
|
+
}
|
|
2638
|
+
};
|
|
2639
|
+
var findPreviousNewline = (value, index) => {
|
|
2640
|
+
for (let current = index - 1; current >= 0; current--) {
|
|
2641
|
+
if (value[current] === "\n") return current > 0 && value[current - 1] === "\r" ? "\r\n" : "\n";
|
|
2642
|
+
if (value[current] === "\r") return "\r";
|
|
2643
|
+
}
|
|
2644
|
+
};
|
|
2645
|
+
var applyTextEdits = (value, edits) => {
|
|
2646
|
+
if (edits.length === 0) return value;
|
|
2647
|
+
const sorted = [...edits].sort((lhs, rhs) => rhs.start - lhs.start);
|
|
2648
|
+
let result = value;
|
|
2649
|
+
let previousStart = value.length;
|
|
2650
|
+
for (const edit of sorted) {
|
|
2651
|
+
if (edit.start > edit.end) throw new Error(`Invalid text edit range: ${edit.start} > ${edit.end}`);
|
|
2652
|
+
if (edit.end > previousStart) throw new Error("Overlapping text edits are not supported");
|
|
2653
|
+
result = result.slice(0, edit.start) + edit.text + result.slice(edit.end);
|
|
2654
|
+
previousStart = edit.start;
|
|
2655
|
+
}
|
|
2656
|
+
return result;
|
|
2657
|
+
};
|
|
2658
|
+
var detectPreferredNewline = (value, start, end) => {
|
|
2659
|
+
var _findFirstNewline;
|
|
2660
|
+
const within = findFirstNewline(value.slice(start, end));
|
|
2661
|
+
if (within) return within;
|
|
2662
|
+
const adjacent = readNewlineAt(value, end);
|
|
2663
|
+
if (adjacent) return adjacent;
|
|
2664
|
+
const after = findFirstNewline(value.slice(end));
|
|
2665
|
+
if (after) return after;
|
|
2666
|
+
const before = findPreviousNewline(value, start);
|
|
2667
|
+
if (before) return before;
|
|
2668
|
+
return (_findFirstNewline = findFirstNewline(value)) !== null && _findFirstNewline !== void 0 ? _findFirstNewline : "\n";
|
|
2669
|
+
};
|
|
2670
|
+
var collectLineStarts = (value) => {
|
|
2671
|
+
const starts = [0];
|
|
2672
|
+
for (let index = 0; index < value.length; index++) {
|
|
2673
|
+
const char = value[index];
|
|
2674
|
+
if (char === "\r") {
|
|
2675
|
+
if (value[index + 1] === "\n") index += 1;
|
|
2676
|
+
starts.push(index + 1);
|
|
2677
|
+
continue;
|
|
2678
|
+
}
|
|
2679
|
+
if (char === "\n") starts.push(index + 1);
|
|
2680
|
+
}
|
|
2681
|
+
return starts;
|
|
2682
|
+
};
|
|
2683
|
+
var getLineColumnOffset = (lineStarts, offset) => {
|
|
2684
|
+
let low = 0;
|
|
2685
|
+
let high = lineStarts.length - 1;
|
|
2686
|
+
while (low <= high) {
|
|
2687
|
+
const middle = low + high >> 1;
|
|
2688
|
+
const lineStart = lineStarts[middle];
|
|
2689
|
+
const nextStart = middle + 1 < lineStarts.length ? lineStarts[middle + 1] : Number.MAX_SAFE_INTEGER;
|
|
2690
|
+
if (offset < lineStart) {
|
|
2691
|
+
high = middle - 1;
|
|
2692
|
+
continue;
|
|
2693
|
+
}
|
|
2694
|
+
if (offset >= nextStart) {
|
|
2695
|
+
low = middle + 1;
|
|
2696
|
+
continue;
|
|
2697
|
+
}
|
|
2698
|
+
return {
|
|
2699
|
+
line: middle,
|
|
2700
|
+
column: offset - lineStart
|
|
2701
|
+
};
|
|
2702
|
+
}
|
|
2703
|
+
const lastLine = Math.max(0, lineStarts.length - 1);
|
|
2704
|
+
return {
|
|
2705
|
+
line: lastLine,
|
|
2706
|
+
column: offset - lineStarts[lastLine]
|
|
2707
|
+
};
|
|
2708
|
+
};
|
|
2709
|
+
//#endregion
|
|
2710
|
+
//#region src/declaration-import-fix.ts
|
|
2711
|
+
var declarationFilePattern = /\.d\.(?:cts|mts|ts)$/;
|
|
2712
|
+
var isRelativeSpecifier = (specifier) => specifier.startsWith("./") || specifier.startsWith("../");
|
|
2713
|
+
var hasExplicitExtension = (specifier) => path.posix.extname(specifier) !== "";
|
|
2714
|
+
var getDeclarationRuntimeSuffix = (declarationPath) => {
|
|
2715
|
+
if (declarationPath.endsWith(".d.mts")) return ".mjs";
|
|
2716
|
+
if (declarationPath.endsWith(".d.cts")) return ".cjs";
|
|
2717
|
+
return ".js";
|
|
2718
|
+
};
|
|
2719
|
+
var createCandidateDeclarationPaths = (resolvedPath) => [
|
|
2720
|
+
`${resolvedPath}.d.ts`,
|
|
2721
|
+
`${resolvedPath}.d.mts`,
|
|
2722
|
+
`${resolvedPath}.d.cts`,
|
|
2723
|
+
(0, path.join)(resolvedPath, "index.d.ts"),
|
|
2724
|
+
(0, path.join)(resolvedPath, "index.d.mts"),
|
|
2725
|
+
(0, path.join)(resolvedPath, "index.d.cts")
|
|
2726
|
+
];
|
|
2727
|
+
var resolveSpecifierSuffix = (specifier, importerPath, declarationFiles, logger) => {
|
|
2728
|
+
if (!isRelativeSpecifier(specifier) || hasExplicitExtension(specifier)) return;
|
|
2729
|
+
const resolvedPath = (0, path.resolve)((0, path.dirname)(importerPath), specifier);
|
|
2730
|
+
const matches = createCandidateDeclarationPaths(resolvedPath).filter((path$1) => declarationFiles.has(path$1));
|
|
2731
|
+
if (matches.length === 0) return;
|
|
2732
|
+
if (matches.length >= 2) {
|
|
2733
|
+
logger === null || logger === void 0 || logger.warn(`[fixDeclarationImports] Skipped ambiguous declaration import: ${specifier} (${matches.map((path$2) => {
|
|
2734
|
+
var _path$split$pop;
|
|
2735
|
+
return (_path$split$pop = path$2.split(/[/\\]/).pop()) !== null && _path$split$pop !== void 0 ? _path$split$pop : path$2;
|
|
2736
|
+
}).join(", ")})`);
|
|
2737
|
+
return;
|
|
2738
|
+
}
|
|
2739
|
+
const match = matches[0];
|
|
2740
|
+
const runtimeSuffix = getDeclarationRuntimeSuffix(match);
|
|
2741
|
+
const indexPrefix = (0, path.join)(resolvedPath, "index.");
|
|
2742
|
+
return match.startsWith(indexPrefix) ? `/index${runtimeSuffix}` : runtimeSuffix;
|
|
2743
|
+
};
|
|
2744
|
+
var collectModuleSpecifierEdits = (ts, sourceFile, importerPath, declarationFiles, logger) => {
|
|
2745
|
+
const edits = [];
|
|
2746
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2747
|
+
const pushSpecifierEdit = (literal) => {
|
|
2748
|
+
const suffix = resolveSpecifierSuffix(literal.text, importerPath, declarationFiles, logger);
|
|
2749
|
+
if (!suffix) return;
|
|
2750
|
+
const insertionPoint = literal.getEnd() - 1;
|
|
2751
|
+
if (seen.has(insertionPoint)) return;
|
|
2752
|
+
seen.add(insertionPoint);
|
|
2753
|
+
edits.push({
|
|
2754
|
+
start: insertionPoint,
|
|
2755
|
+
end: insertionPoint,
|
|
2756
|
+
text: suffix
|
|
2757
|
+
});
|
|
2758
|
+
};
|
|
2759
|
+
const visit = (node) => {
|
|
2760
|
+
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
2761
|
+
if (node.moduleSpecifier && ts.isStringLiteralLike(node.moduleSpecifier)) pushSpecifierEdit(node.moduleSpecifier);
|
|
2762
|
+
} else if (ts.isImportTypeNode(node)) {
|
|
2763
|
+
const argument = node.argument;
|
|
2764
|
+
if (ts.isLiteralTypeNode(argument) && ts.isStringLiteralLike(argument.literal)) pushSpecifierEdit(argument.literal);
|
|
2765
|
+
}
|
|
2766
|
+
node.forEachChild(visit);
|
|
2767
|
+
};
|
|
2768
|
+
sourceFile.forEachChild(visit);
|
|
2769
|
+
return edits;
|
|
2770
|
+
};
|
|
2771
|
+
var isDeclarationFilePath = (filePath) => declarationFilePattern.test(filePath);
|
|
2772
|
+
var fixDeclarationImportSpecifiers = (ts, code, filePath, declarationFiles, logger) => {
|
|
2773
|
+
const edits = collectModuleSpecifierEdits(ts, ts.createSourceFile(filePath, code, ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS), filePath, declarationFiles, logger);
|
|
2774
|
+
if (edits.length === 0) return {
|
|
2775
|
+
changed: false,
|
|
2776
|
+
code,
|
|
2777
|
+
edits
|
|
2778
|
+
};
|
|
2779
|
+
return {
|
|
2780
|
+
changed: true,
|
|
2781
|
+
code: applyTextEdits(code, edits),
|
|
2782
|
+
edits
|
|
2783
|
+
};
|
|
2784
|
+
};
|
|
2785
|
+
var adjustSourceMapForDeclarationEdits = (source, originalCode, edits) => {
|
|
2786
|
+
if (edits.length === 0) return;
|
|
2787
|
+
const original = typeof source === "string" ? source : Buffer.from(source).toString("utf-8");
|
|
2788
|
+
let map;
|
|
2789
|
+
try {
|
|
2790
|
+
map = JSON.parse(original);
|
|
2791
|
+
} catch (_unused) {
|
|
2792
|
+
return;
|
|
2793
|
+
}
|
|
2794
|
+
if (!map || typeof map.mappings !== "string") return;
|
|
2795
|
+
const lineStarts = collectLineStarts(originalCode);
|
|
2796
|
+
const lineDeltas = /* @__PURE__ */ new Map();
|
|
2797
|
+
for (const edit of edits) {
|
|
2798
|
+
var _lineDeltas$get;
|
|
2799
|
+
if (edit.start !== edit.end) return;
|
|
2800
|
+
if (edit.text.includes("\n") || edit.text.includes("\r")) return;
|
|
2801
|
+
const position = getLineColumnOffset(lineStarts, edit.start);
|
|
2802
|
+
const entries = (_lineDeltas$get = lineDeltas.get(position.line)) !== null && _lineDeltas$get !== void 0 ? _lineDeltas$get : [];
|
|
2803
|
+
entries.push({
|
|
2804
|
+
column: position.column,
|
|
2805
|
+
delta: edit.text.length
|
|
2806
|
+
});
|
|
2807
|
+
lineDeltas.set(position.line, entries);
|
|
2808
|
+
}
|
|
2809
|
+
if (lineDeltas.size === 0) return;
|
|
2810
|
+
const decodedMappings = decode(map.mappings);
|
|
2811
|
+
for (const [line, entries] of lineDeltas.entries()) {
|
|
2812
|
+
const segments = decodedMappings[line];
|
|
2813
|
+
if (!segments || segments.length === 0) continue;
|
|
2814
|
+
const sortedEntries = [...entries].sort((lhs, rhs) => lhs.column - rhs.column);
|
|
2815
|
+
let entryIndex = 0;
|
|
2816
|
+
let cumulativeDelta = 0;
|
|
2817
|
+
for (const segment of segments) {
|
|
2818
|
+
while (entryIndex < sortedEntries.length && sortedEntries[entryIndex].column <= segment[0]) {
|
|
2819
|
+
cumulativeDelta += sortedEntries[entryIndex].delta;
|
|
2820
|
+
entryIndex += 1;
|
|
2821
|
+
}
|
|
2822
|
+
segment[0] += cumulativeDelta;
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
map.mappings = encode(decodedMappings);
|
|
2826
|
+
const serialized = JSON.stringify(map);
|
|
2827
|
+
return original.endsWith("\n") ? `${serialized}\n` : serialized;
|
|
2828
|
+
};
|
|
2829
|
+
//#endregion
|
|
2392
2830
|
//#region src/default-import-fix.ts
|
|
2393
2831
|
var importConditions = [
|
|
2394
2832
|
"import",
|
|
@@ -2530,45 +2968,46 @@ var cjsInteropGlobalFlagAssignmentPattern = new RegExp(`\\bglobalThis\\.${cjsInt
|
|
|
2530
2968
|
var createCjsInteropHelperId = (seed) => {
|
|
2531
2969
|
return (0, crypto$1.createHash)("sha256").update(seed).digest("hex").slice(0, cjsInteropIdLength);
|
|
2532
2970
|
};
|
|
2533
|
-
var buildHelperFunctionSource = (helperId) =>
|
|
2534
|
-
globalThis.${cjsInteropGlobalFlagPrefix}${helperId} = false
|
|
2535
|
-
function __resolveDefaultExport<T>(module: T | { default?: T }, isESM: boolean): T {
|
|
2536
|
-
const __isInCJS =
|
|
2537
|
-
typeof globalThis !== 'undefined' &&
|
|
2538
|
-
(globalThis as any).${cjsInteropGlobalFlagPrefix}${helperId} === true
|
|
2539
|
-
const maybe = module as { default?: T };
|
|
2540
|
-
const hasDefault = !!(maybe && typeof maybe === 'object' && 'default' in maybe);
|
|
2541
|
-
const unwrapNamespaceDefault = (value: unknown): unknown => {
|
|
2542
|
-
if (!value || typeof value !== 'object') {
|
|
2543
|
-
return value;
|
|
2544
|
-
}
|
|
2545
|
-
const inner = value as any;
|
|
2546
|
-
const isModule =
|
|
2547
|
-
inner.__esModule === true ||
|
|
2548
|
-
(typeof Symbol !== 'undefined' &&
|
|
2549
|
-
(inner as any)[Symbol.toStringTag] === 'Module');
|
|
2550
|
-
if (isModule && 'default' in inner) {
|
|
2551
|
-
return inner.default;
|
|
2552
|
-
}
|
|
2553
|
-
return value;
|
|
2554
|
-
};
|
|
2555
|
-
const resolvedDefault = hasDefault
|
|
2556
|
-
? unwrapNamespaceDefault((maybe as any).default)
|
|
2557
|
-
: undefined;
|
|
2558
|
-
|
|
2559
|
-
if (__isInCJS) {
|
|
2560
|
-
return hasDefault ? ((resolvedDefault as T) ?? (module as T)) : (module as T);
|
|
2561
|
-
}
|
|
2562
|
-
|
|
2563
|
-
if (isESM) {
|
|
2564
|
-
if (hasDefault) {
|
|
2565
|
-
return resolvedDefault as T;
|
|
2566
|
-
}
|
|
2567
|
-
throw new Error('Default export not found.');
|
|
2568
|
-
}
|
|
2569
|
-
|
|
2570
|
-
return hasDefault ? ((resolvedDefault as T) ?? (module as T)) : (module as T);
|
|
2571
|
-
}
|
|
2971
|
+
var buildHelperFunctionSource = (helperId, newline) => [
|
|
2972
|
+
`globalThis.${cjsInteropGlobalFlagPrefix}${helperId} = false;`,
|
|
2973
|
+
"function __resolveDefaultExport<T>(module: T | { default?: T }, isESM: boolean): T {",
|
|
2974
|
+
" const __isInCJS =",
|
|
2975
|
+
" typeof globalThis !== 'undefined' &&",
|
|
2976
|
+
` (globalThis as any).${cjsInteropGlobalFlagPrefix}${helperId} === true;`,
|
|
2977
|
+
" const maybe = module as { default?: T };",
|
|
2978
|
+
" const hasDefault = !!(maybe && typeof maybe === 'object' && 'default' in maybe);",
|
|
2979
|
+
" const unwrapNamespaceDefault = (value: unknown): unknown => {",
|
|
2980
|
+
" if (!value || typeof value !== 'object') {",
|
|
2981
|
+
" return value;",
|
|
2982
|
+
" }",
|
|
2983
|
+
" const inner = value as any;",
|
|
2984
|
+
" const isModule =",
|
|
2985
|
+
" inner.__esModule === true ||",
|
|
2986
|
+
" (typeof Symbol !== 'undefined' &&",
|
|
2987
|
+
" (inner as any)[Symbol.toStringTag] === 'Module');",
|
|
2988
|
+
" if (isModule && 'default' in inner) {",
|
|
2989
|
+
" return inner.default;",
|
|
2990
|
+
" }",
|
|
2991
|
+
" return value;",
|
|
2992
|
+
" };",
|
|
2993
|
+
" const resolvedDefault = hasDefault",
|
|
2994
|
+
" ? unwrapNamespaceDefault((maybe as any).default)",
|
|
2995
|
+
" : undefined;",
|
|
2996
|
+
"",
|
|
2997
|
+
" if (__isInCJS) {",
|
|
2998
|
+
" return hasDefault ? ((resolvedDefault as T) ?? (module as T)) : (module as T);",
|
|
2999
|
+
" }",
|
|
3000
|
+
"",
|
|
3001
|
+
" if (isESM) {",
|
|
3002
|
+
" if (hasDefault) {",
|
|
3003
|
+
" return resolvedDefault as T;",
|
|
3004
|
+
" }",
|
|
3005
|
+
" throw new Error('Default export not found.');",
|
|
3006
|
+
" }",
|
|
3007
|
+
"",
|
|
3008
|
+
" return hasDefault ? ((resolvedDefault as T) ?? (module as T)) : (module as T);",
|
|
3009
|
+
"}"
|
|
3010
|
+
].join(newline);
|
|
2572
3011
|
var injectCjsInteropFlag = (code) => {
|
|
2573
3012
|
let changed = false;
|
|
2574
3013
|
return {
|
|
@@ -2679,7 +3118,8 @@ var transformDefaultImports = async (ts, code, id, resolveModuleKind) => {
|
|
|
2679
3118
|
if (importClause.namedBindings && ts.isNamedImports(importClause.namedBindings)) replacementImports.push(buildNamedImport(moduleName, importClause.namedBindings));
|
|
2680
3119
|
}
|
|
2681
3120
|
const interopSource = (_namespaceName = namespaceName) !== null && _namespaceName !== void 0 ? _namespaceName : defaultImportName;
|
|
2682
|
-
const
|
|
3121
|
+
const newline = detectPreferredNewline(code, statement.getStart(sourceFile), statement.getEnd());
|
|
3122
|
+
const replacement = `${replacementImports.join(newline)}${newline}const ${defaultName} = __resolveDefaultExport(${interopSource}, ${isESM});`;
|
|
2683
3123
|
edits.push({
|
|
2684
3124
|
start: statement.getStart(sourceFile),
|
|
2685
3125
|
end: statement.getEnd(),
|
|
@@ -2695,20 +3135,17 @@ var transformDefaultImports = async (ts, code, id, resolveModuleKind) => {
|
|
|
2695
3135
|
const importStatements = sourceFile.statements.filter(ts.isImportDeclaration);
|
|
2696
3136
|
const lastImport = importStatements[importStatements.length - 1];
|
|
2697
3137
|
if (lastImport) {
|
|
2698
|
-
const newline = code.
|
|
3138
|
+
const newline = detectPreferredNewline(code, lastImport.getStart(sourceFile), lastImport.getEnd());
|
|
2699
3139
|
const helperId = createCjsInteropHelperId(normalizedId);
|
|
2700
3140
|
edits.push({
|
|
2701
3141
|
start: lastImport.getEnd(),
|
|
2702
3142
|
end: lastImport.getEnd(),
|
|
2703
|
-
text: `${newline}${buildHelperFunctionSource(helperId)}${newline}`
|
|
3143
|
+
text: `${newline}${buildHelperFunctionSource(helperId, newline)}${newline}`
|
|
2704
3144
|
});
|
|
2705
3145
|
}
|
|
2706
3146
|
}
|
|
2707
|
-
edits.sort((a, b) => b.start - a.start);
|
|
2708
|
-
let nextCode = code;
|
|
2709
|
-
for (const edit of edits) nextCode = nextCode.slice(0, edit.start) + edit.text + nextCode.slice(edit.end);
|
|
2710
3147
|
return {
|
|
2711
|
-
code:
|
|
3148
|
+
code: applyTextEdits(code, edits),
|
|
2712
3149
|
changed: true
|
|
2713
3150
|
};
|
|
2714
3151
|
};
|
|
@@ -2880,7 +3317,7 @@ var screwUp = (options = {}) => {
|
|
|
2880
3317
|
"license",
|
|
2881
3318
|
"repository.url",
|
|
2882
3319
|
"git.commit.hash"
|
|
2883
|
-
], checkWorkingDirectoryStatus = true, alwaysOverrideVersionFromGit = true, insertMetadataBanner = true } = options;
|
|
3320
|
+
], checkWorkingDirectoryStatus = true, alwaysOverrideVersionFromGit = true, insertMetadataBanner = true, fixDeclarationImportExtensions = true } = options;
|
|
2884
3321
|
const assetFiltersRegex = assetFilters.map((filter) => new RegExp(filter));
|
|
2885
3322
|
const generateMetadataSourceLocker = createMutex();
|
|
2886
3323
|
const resolveModuleKind = createNodeModuleKindResolver();
|
|
@@ -3059,29 +3496,65 @@ var screwUp = (options = {}) => {
|
|
|
3059
3496
|
}
|
|
3060
3497
|
},
|
|
3061
3498
|
writeBundle: async (options) => {
|
|
3062
|
-
if (!
|
|
3499
|
+
if (!options.dir) return;
|
|
3063
3500
|
try {
|
|
3064
3501
|
const files = await (0, fs_promises.readdir)(options.dir, { recursive: true });
|
|
3065
|
-
|
|
3502
|
+
const declarationFiles = new Set(files.filter((file) => isDeclarationFilePath(file)).map((file) => (0, path.resolve)(options.dir, file)));
|
|
3503
|
+
const ts = fixDeclarationImportExtensions ? await loadTypeScript() : void 0;
|
|
3504
|
+
let bannerCount = 0;
|
|
3505
|
+
let declarationCount = 0;
|
|
3066
3506
|
for (const file of files) {
|
|
3067
3507
|
const filePath = (0, path.join)(options.dir, file);
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3508
|
+
const isAssetTarget = assetFiltersRegex.some((filter) => filter.test(file));
|
|
3509
|
+
const isDeclarationTarget = fixDeclarationImportExtensions && !!ts && isDeclarationFilePath(filePath);
|
|
3510
|
+
if (!isAssetTarget && !isDeclarationTarget) continue;
|
|
3511
|
+
try {
|
|
3512
|
+
let content = await (0, fs_promises.readFile)(filePath, "utf-8");
|
|
3513
|
+
let contentChanged = false;
|
|
3514
|
+
let mapLoaded = false;
|
|
3515
|
+
let mapContent;
|
|
3516
|
+
const mapPath = `${filePath}.map`;
|
|
3517
|
+
const loadMapContent = async () => {
|
|
3518
|
+
if (mapLoaded) return mapContent;
|
|
3519
|
+
mapLoaded = true;
|
|
3075
3520
|
try {
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3521
|
+
mapContent = await (0, fs_promises.readFile)(mapPath, "utf-8");
|
|
3522
|
+
} catch (_unused2) {
|
|
3523
|
+
mapContent = void 0;
|
|
3524
|
+
}
|
|
3525
|
+
return mapContent;
|
|
3526
|
+
};
|
|
3527
|
+
if (insertMetadataBanner && isAssetTarget && !content.includes(banner)) {
|
|
3528
|
+
const bannerBlock = `${banner}\n`;
|
|
3529
|
+
content = insertBannerHeader(content, bannerBlock);
|
|
3530
|
+
contentChanged = true;
|
|
3531
|
+
const currentMapContent = await loadMapContent();
|
|
3532
|
+
if (currentMapContent !== void 0) {
|
|
3533
|
+
const adjusted = applyLineOffsetToSourceMap(currentMapContent, countInsertedLines(bannerBlock));
|
|
3534
|
+
if (adjusted !== void 0) mapContent = adjusted;
|
|
3535
|
+
}
|
|
3536
|
+
bannerCount++;
|
|
3537
|
+
}
|
|
3538
|
+
if (isDeclarationTarget) {
|
|
3539
|
+
const declarationResult = fixDeclarationImportSpecifiers(ts, content, filePath, declarationFiles, logger);
|
|
3540
|
+
if (declarationResult.changed) {
|
|
3541
|
+
const currentMapContent = await loadMapContent();
|
|
3542
|
+
if (currentMapContent !== void 0) {
|
|
3543
|
+
const adjusted = adjustSourceMapForDeclarationEdits(currentMapContent, content, declarationResult.edits);
|
|
3544
|
+
if (adjusted !== void 0) mapContent = adjusted;
|
|
3545
|
+
}
|
|
3546
|
+
content = declarationResult.code;
|
|
3547
|
+
contentChanged = true;
|
|
3548
|
+
declarationCount++;
|
|
3549
|
+
}
|
|
3080
3550
|
}
|
|
3081
|
-
|
|
3551
|
+
if (contentChanged) await (0, fs_promises.writeFile)(filePath, content);
|
|
3552
|
+
if (mapLoaded && mapContent !== void 0) await (0, fs_promises.writeFile)(mapPath, mapContent);
|
|
3553
|
+
} catch (_unused3) {}
|
|
3082
3554
|
}
|
|
3083
|
-
if (
|
|
3084
|
-
|
|
3555
|
+
if (bannerCount >= 1) logger.debug(`writeBundle: Banner header inserted: ${bannerCount} file(s)`);
|
|
3556
|
+
if (declarationCount >= 1) logger.debug(`writeBundle: Declaration imports fixed: ${declarationCount} file(s)`);
|
|
3557
|
+
} catch (_unused4) {}
|
|
3085
3558
|
}
|
|
3086
3559
|
};
|
|
3087
3560
|
};
|