screw-up 1.29.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.
Files changed (43) hide show
  1. package/dist/index.cjs +471 -67
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.mjs +472 -68
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/main.cjs +4 -4
  6. package/dist/main.cjs.map +1 -1
  7. package/dist/main.mjs +5 -5
  8. package/dist/main.mjs.map +1 -1
  9. package/dist/{metadata-file-CyQ2yue9.js → metadata-file-CpFkBJPS.js} +3 -3
  10. package/dist/{metadata-file-CyQ2yue9.js.map → metadata-file-CpFkBJPS.js.map} +1 -1
  11. package/dist/{packageMetadata-K_w0Knb7.cjs → packageMetadata-Lj9bVuVM.cjs} +5 -5
  12. package/dist/{packageMetadata-K_w0Knb7.cjs.map → packageMetadata-Lj9bVuVM.cjs.map} +1 -1
  13. package/dist/{packageMetadata-DnXbVLQ5.js → packageMetadata-YWwXZbaj.js} +6 -6
  14. package/dist/{packageMetadata-DnXbVLQ5.js.map → packageMetadata-YWwXZbaj.js.map} +1 -1
  15. package/dist/{packageMetadata-CpakAG0S.cjs → packageMetadata-zaiRRUve.cjs} +3 -3
  16. package/dist/src/analyzer.d.ts +2 -2
  17. package/dist/src/analyzer.d.ts.map +1 -1
  18. package/dist/src/cli-internal.d.ts +3 -3
  19. package/dist/src/cli-internal.d.ts.map +1 -1
  20. package/dist/src/cli.d.ts +3 -3
  21. package/dist/src/cli.d.ts.map +1 -1
  22. package/dist/src/declaration-import-fix.d.ts +21 -0
  23. package/dist/src/declaration-import-fix.d.ts.map +1 -0
  24. package/dist/src/default-import-fix.d.ts +2 -2
  25. package/dist/src/default-import-fix.d.ts.map +1 -1
  26. package/dist/src/fast-tags.d.ts +2 -2
  27. package/dist/src/fast-tags.d.ts.map +1 -1
  28. package/dist/src/generated/packageMetadata.d.ts +4 -4
  29. package/dist/src/git-operations.d.ts +3 -3
  30. package/dist/src/git-operations.d.ts.map +1 -1
  31. package/dist/src/index.d.ts +4 -4
  32. package/dist/src/index.d.ts.map +1 -1
  33. package/dist/src/internal.d.ts +3 -3
  34. package/dist/src/main.d.ts +2 -2
  35. package/dist/src/metadata-file.d.ts +4 -4
  36. package/dist/src/metadata-file.d.ts.map +1 -1
  37. package/dist/src/text-edits.d.ts +24 -0
  38. package/dist/src/text-edits.d.ts.map +1 -0
  39. package/dist/src/types.d.ts +7 -2
  40. package/dist/src/types.d.ts.map +1 -1
  41. package/dist/src/vite-plugin.d.ts +3 -3
  42. package/dist/src/vite-plugin.d.ts.map +1 -1
  43. package/package.json +14 -10
package/dist/index.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.29.0
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: 3833f6ef842d9e5a0b4f7277ca3b118f26fd4a6b
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.29.0";
202
- var git_commit_hash = "3833f6ef842d9e5a0b4f7277ca3b118f26fd4a6b";
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) => {
@@ -2458,6 +2458,375 @@ var getFetchGitMetadata = (targetDir, checkWorkingDirectoryStatus, logger) => {
2458
2458
  };
2459
2459
  };
2460
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
2461
2830
  //#region src/default-import-fix.ts
2462
2831
  var importConditions = [
2463
2832
  "import",
@@ -2599,45 +2968,46 @@ var cjsInteropGlobalFlagAssignmentPattern = new RegExp(`\\bglobalThis\\.${cjsInt
2599
2968
  var createCjsInteropHelperId = (seed) => {
2600
2969
  return (0, crypto$1.createHash)("sha256").update(seed).digest("hex").slice(0, cjsInteropIdLength);
2601
2970
  };
2602
- var buildHelperFunctionSource = (helperId) => `
2603
- globalThis.${cjsInteropGlobalFlagPrefix}${helperId} = false;
2604
- function __resolveDefaultExport<T>(module: T | { default?: T }, isESM: boolean): T {
2605
- const __isInCJS =
2606
- typeof globalThis !== 'undefined' &&
2607
- (globalThis as any).${cjsInteropGlobalFlagPrefix}${helperId} === true;
2608
- const maybe = module as { default?: T };
2609
- const hasDefault = !!(maybe && typeof maybe === 'object' && 'default' in maybe);
2610
- const unwrapNamespaceDefault = (value: unknown): unknown => {
2611
- if (!value || typeof value !== 'object') {
2612
- return value;
2613
- }
2614
- const inner = value as any;
2615
- const isModule =
2616
- inner.__esModule === true ||
2617
- (typeof Symbol !== 'undefined' &&
2618
- (inner as any)[Symbol.toStringTag] === 'Module');
2619
- if (isModule && 'default' in inner) {
2620
- return inner.default;
2621
- }
2622
- return value;
2623
- };
2624
- const resolvedDefault = hasDefault
2625
- ? unwrapNamespaceDefault((maybe as any).default)
2626
- : undefined;
2627
-
2628
- if (__isInCJS) {
2629
- return hasDefault ? ((resolvedDefault as T) ?? (module as T)) : (module as T);
2630
- }
2631
-
2632
- if (isESM) {
2633
- if (hasDefault) {
2634
- return resolvedDefault as T;
2635
- }
2636
- throw new Error('Default export not found.');
2637
- }
2638
-
2639
- return hasDefault ? ((resolvedDefault as T) ?? (module as T)) : (module as T);
2640
- }`;
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);
2641
3011
  var injectCjsInteropFlag = (code) => {
2642
3012
  let changed = false;
2643
3013
  return {
@@ -2748,7 +3118,8 @@ var transformDefaultImports = async (ts, code, id, resolveModuleKind) => {
2748
3118
  if (importClause.namedBindings && ts.isNamedImports(importClause.namedBindings)) replacementImports.push(buildNamedImport(moduleName, importClause.namedBindings));
2749
3119
  }
2750
3120
  const interopSource = (_namespaceName = namespaceName) !== null && _namespaceName !== void 0 ? _namespaceName : defaultImportName;
2751
- const replacement = `${replacementImports.join("\n")}\nconst ${defaultName} = __resolveDefaultExport(${interopSource}, ${isESM});`;
3121
+ const newline = detectPreferredNewline(code, statement.getStart(sourceFile), statement.getEnd());
3122
+ const replacement = `${replacementImports.join(newline)}${newline}const ${defaultName} = __resolveDefaultExport(${interopSource}, ${isESM});`;
2752
3123
  edits.push({
2753
3124
  start: statement.getStart(sourceFile),
2754
3125
  end: statement.getEnd(),
@@ -2764,20 +3135,17 @@ var transformDefaultImports = async (ts, code, id, resolveModuleKind) => {
2764
3135
  const importStatements = sourceFile.statements.filter(ts.isImportDeclaration);
2765
3136
  const lastImport = importStatements[importStatements.length - 1];
2766
3137
  if (lastImport) {
2767
- const newline = code.includes("\r\n") ? "\r\n" : "\n";
3138
+ const newline = detectPreferredNewline(code, lastImport.getStart(sourceFile), lastImport.getEnd());
2768
3139
  const helperId = createCjsInteropHelperId(normalizedId);
2769
3140
  edits.push({
2770
3141
  start: lastImport.getEnd(),
2771
3142
  end: lastImport.getEnd(),
2772
- text: `${newline}${buildHelperFunctionSource(helperId)}${newline}`
3143
+ text: `${newline}${buildHelperFunctionSource(helperId, newline)}${newline}`
2773
3144
  });
2774
3145
  }
2775
3146
  }
2776
- edits.sort((a, b) => b.start - a.start);
2777
- let nextCode = code;
2778
- for (const edit of edits) nextCode = nextCode.slice(0, edit.start) + edit.text + nextCode.slice(edit.end);
2779
3147
  return {
2780
- code: nextCode,
3148
+ code: applyTextEdits(code, edits),
2781
3149
  changed: true
2782
3150
  };
2783
3151
  };
@@ -2949,7 +3317,7 @@ var screwUp = (options = {}) => {
2949
3317
  "license",
2950
3318
  "repository.url",
2951
3319
  "git.commit.hash"
2952
- ], checkWorkingDirectoryStatus = true, alwaysOverrideVersionFromGit = true, insertMetadataBanner = true } = options;
3320
+ ], checkWorkingDirectoryStatus = true, alwaysOverrideVersionFromGit = true, insertMetadataBanner = true, fixDeclarationImportExtensions = true } = options;
2953
3321
  const assetFiltersRegex = assetFilters.map((filter) => new RegExp(filter));
2954
3322
  const generateMetadataSourceLocker = createMutex();
2955
3323
  const resolveModuleKind = createNodeModuleKindResolver();
@@ -3128,29 +3496,65 @@ var screwUp = (options = {}) => {
3128
3496
  }
3129
3497
  },
3130
3498
  writeBundle: async (options) => {
3131
- if (!insertMetadataBanner || !options.dir) return;
3499
+ if (!options.dir) return;
3132
3500
  try {
3133
3501
  const files = await (0, fs_promises.readdir)(options.dir, { recursive: true });
3134
- let count = 0;
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;
3135
3506
  for (const file of files) {
3136
3507
  const filePath = (0, path.join)(options.dir, file);
3137
- if (assetFiltersRegex.some((filter) => filter.test(file))) try {
3138
- const content = await (0, fs_promises.readFile)(filePath, "utf-8");
3139
- if (!content.includes(banner)) {
3140
- const bannerBlock = `${banner}\n`;
3141
- await (0, fs_promises.writeFile)(filePath, insertBannerHeader(content, bannerBlock));
3142
- const lineOffset = countInsertedLines(bannerBlock);
3143
- const mapPath = `${filePath}.map`;
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;
3144
3520
  try {
3145
- const adjusted = applyLineOffsetToSourceMap(await (0, fs_promises.readFile)(mapPath, "utf-8"), lineOffset);
3146
- if (adjusted !== void 0) await (0, fs_promises.writeFile)(mapPath, adjusted);
3147
- } catch (_unused2) {}
3148
- count++;
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
+ }
3149
3550
  }
3150
- } catch (error) {}
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) {}
3151
3554
  }
3152
- if (count >= 1) logger.debug(`writeBundle: Banner header inserted: ${count} file(s)`);
3153
- } catch (error) {}
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) {}
3154
3558
  }
3155
3559
  };
3156
3560
  };