screw-up 1.24.0 → 1.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/index.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: screw-up
3
- * version: 1.24.0
3
+ * version: 1.26.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: f42bca9fbfabb81d8b48ffa76953eafbf8b9d280
8
+ * git.commit.hash: 482a79d9b3fc68a60c1b8696b7d95a776b91468e
9
9
  */
10
10
 
11
11
  "use strict";
@@ -34,7 +34,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
34
34
  const fs$1 = require("fs/promises");
35
35
  const fs = require("fs");
36
36
  const path = require("path");
37
- const packageMetadata = require("./metadata-file-RkyZOp_d.cjs");
37
+ const packageMetadata = require("./metadata-file-6Y1AngPB.cjs");
38
38
  const crypto = require("crypto");
39
39
  const __NOOP_HANDLER = () => {
40
40
  };
@@ -421,23 +421,37 @@ function __resolveDefaultExport<T>(module: T | { default?: T }, isESM: boolean):
421
421
  typeof globalThis !== 'undefined' &&
422
422
  (globalThis as any).${cjsInteropGlobalFlagPrefix}${helperId} === true;
423
423
  const maybe = module as { default?: T };
424
+ const hasDefault = !!(maybe && typeof maybe === 'object' && 'default' in maybe);
425
+ const unwrapNamespaceDefault = (value: unknown): unknown => {
426
+ if (!value || typeof value !== 'object') {
427
+ return value;
428
+ }
429
+ const inner = value as any;
430
+ const isModule =
431
+ inner.__esModule === true ||
432
+ (typeof Symbol !== 'undefined' &&
433
+ (inner as any)[Symbol.toStringTag] === 'Module');
434
+ if (isModule && 'default' in inner) {
435
+ return inner.default;
436
+ }
437
+ return value;
438
+ };
439
+ const resolvedDefault = hasDefault
440
+ ? unwrapNamespaceDefault((maybe as any).default)
441
+ : undefined;
424
442
 
425
443
  if (__isInCJS) {
426
- return maybe && typeof maybe === 'object' && 'default' in maybe
427
- ? (maybe.default ?? (module as T))
428
- : (module as T);
444
+ return hasDefault ? ((resolvedDefault as T) ?? (module as T)) : (module as T);
429
445
  }
430
446
 
431
447
  if (isESM) {
432
- if (maybe && typeof maybe === 'object' && 'default' in maybe) {
433
- return maybe.default as T;
448
+ if (hasDefault) {
449
+ return resolvedDefault as T;
434
450
  }
435
451
  throw new Error('Default export not found.');
436
452
  }
437
453
 
438
- return maybe && typeof maybe === 'object' && 'default' in maybe
439
- ? (maybe.default ?? (module as T))
440
- : (module as T);
454
+ return hasDefault ? ((resolvedDefault as T) ?? (module as T)) : (module as T);
441
455
  }`;
442
456
  const injectCjsInteropFlag = (code) => {
443
457
  let changed = false;
@@ -572,14 +586,26 @@ const transformDefaultImports = async (ts, code, id, resolveModuleKind) => {
572
586
  continue;
573
587
  }
574
588
  const isESM = moduleKind === "esm";
589
+ const isCJS = moduleKind === "cjs";
575
590
  const defaultName = importClause.name.text;
576
591
  const replacementImports = [];
577
592
  let namespaceName;
593
+ let defaultImportName;
578
594
  if (importClause.namedBindings && ts.isNamespaceImport(importClause.namedBindings)) {
579
595
  namespaceName = importClause.namedBindings.name.text;
580
596
  replacementImports.push(
581
597
  `import * as ${namespaceName} from ${formatModuleSpecifier(moduleName)};`
582
598
  );
599
+ } else if (isCJS) {
600
+ defaultImportName = usedNamespace("__screwUpDefaultImportModule");
601
+ replacementImports.push(
602
+ `import ${defaultImportName} from ${formatModuleSpecifier(moduleName)};`
603
+ );
604
+ if (importClause.namedBindings && ts.isNamedImports(importClause.namedBindings)) {
605
+ replacementImports.push(
606
+ buildNamedImport(moduleName, importClause.namedBindings)
607
+ );
608
+ }
583
609
  } else {
584
610
  namespaceName = usedNamespace("__screwUpDefaultImportModule");
585
611
  replacementImports.push(
@@ -591,8 +617,9 @@ const transformDefaultImports = async (ts, code, id, resolveModuleKind) => {
591
617
  );
592
618
  }
593
619
  }
620
+ const interopSource = namespaceName != null ? namespaceName : defaultImportName;
594
621
  const replacement = `${replacementImports.join("\n")}
595
- const ${defaultName} = __resolveDefaultExport(${namespaceName}, ${isESM});`;
622
+ const ${defaultName} = __resolveDefaultExport(${interopSource}, ${isESM});`;
596
623
  edits.push({
597
624
  start: statement.getStart(sourceFile),
598
625
  end: statement.getEnd(),