screw-up 1.25.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.25.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: 8275b6db6558235b0fe73f99368acf3f9a6e1b29
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-3UqfivKm.cjs");
37
+ const packageMetadata = require("./metadata-file-6Y1AngPB.cjs");
38
38
  const crypto = require("crypto");
39
39
  const __NOOP_HANDLER = () => {
40
40
  };
@@ -586,14 +586,26 @@ const transformDefaultImports = async (ts, code, id, resolveModuleKind) => {
586
586
  continue;
587
587
  }
588
588
  const isESM = moduleKind === "esm";
589
+ const isCJS = moduleKind === "cjs";
589
590
  const defaultName = importClause.name.text;
590
591
  const replacementImports = [];
591
592
  let namespaceName;
593
+ let defaultImportName;
592
594
  if (importClause.namedBindings && ts.isNamespaceImport(importClause.namedBindings)) {
593
595
  namespaceName = importClause.namedBindings.name.text;
594
596
  replacementImports.push(
595
597
  `import * as ${namespaceName} from ${formatModuleSpecifier(moduleName)};`
596
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
+ }
597
609
  } else {
598
610
  namespaceName = usedNamespace("__screwUpDefaultImportModule");
599
611
  replacementImports.push(
@@ -605,8 +617,9 @@ const transformDefaultImports = async (ts, code, id, resolveModuleKind) => {
605
617
  );
606
618
  }
607
619
  }
620
+ const interopSource = namespaceName != null ? namespaceName : defaultImportName;
608
621
  const replacement = `${replacementImports.join("\n")}
609
- const ${defaultName} = __resolveDefaultExport(${namespaceName}, ${isESM});`;
622
+ const ${defaultName} = __resolveDefaultExport(${interopSource}, ${isESM});`;
610
623
  edits.push({
611
624
  start: statement.getStart(sourceFile),
612
625
  end: statement.getEnd(),