@openpkg-ts/extract 0.17.0 → 0.18.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/bin/tspec.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  extract
4
- } from "../shared/chunk-6p1dq6jb.js";
4
+ } from "../shared/chunk-c3pkvc28.js";
5
5
 
6
6
  // src/cli/spec.ts
7
7
  import * as fs from "node:fs";
@@ -1540,7 +1540,14 @@ function createProgram() {
1540
1540
  return program;
1541
1541
  }
1542
1542
  function findEntryPoint(cwd) {
1543
- const sourceEntries = ["src/index.ts", "index.ts", "lib/index.ts"];
1543
+ const sourceEntries = [
1544
+ "src/index.ts",
1545
+ "index.ts",
1546
+ "lib/index.ts",
1547
+ "src/index.js",
1548
+ "index.js",
1549
+ "lib/index.js"
1550
+ ];
1544
1551
  for (const entry of sourceEntries) {
1545
1552
  const fullPath = path.join(cwd, entry);
1546
1553
  if (fs.existsSync(fullPath))
@@ -1564,9 +1571,13 @@ function findEntryPoint(cwd) {
1564
1571
  }
1565
1572
  if (pkg.main) {
1566
1573
  const mainTs = pkg.main.replace(/\.js$/, ".ts");
1567
- const fullPath = path.join(cwd, mainTs);
1568
- if (fs.existsSync(fullPath))
1569
- return { path: fullPath, fromDts: false };
1574
+ const tsPath = path.join(cwd, mainTs);
1575
+ if (fs.existsSync(tsPath))
1576
+ return { path: tsPath, fromDts: false };
1577
+ const jsPath = path.join(cwd, pkg.main);
1578
+ if (pkg.main.endsWith(".js") && fs.existsSync(jsPath)) {
1579
+ return { path: jsPath, fromDts: false };
1580
+ }
1570
1581
  }
1571
1582
  } catch {}
1572
1583
  }
@@ -762,6 +762,18 @@ function isSymbolDeprecated(symbol) {
762
762
  // src/compiler/program.ts
763
763
  import * as path from "node:path";
764
764
  import ts4 from "typescript";
765
+ function isJsFile(file) {
766
+ return /\.(js|mjs|cjs|jsx)$/.test(file);
767
+ }
768
+ function getScriptKind(file) {
769
+ if (/\.tsx$/.test(file))
770
+ return ts4.ScriptKind.TSX;
771
+ if (/\.jsx$/.test(file))
772
+ return ts4.ScriptKind.JSX;
773
+ if (/\.(js|mjs|cjs)$/.test(file))
774
+ return ts4.ScriptKind.JS;
775
+ return ts4.ScriptKind.TS;
776
+ }
765
777
  var DEFAULT_COMPILER_OPTIONS = {
766
778
  target: ts4.ScriptTarget.Latest,
767
779
  module: ts4.ModuleKind.CommonJS,
@@ -774,21 +786,33 @@ function createProgram({
774
786
  baseDir = path.dirname(entryFile),
775
787
  content
776
788
  }) {
777
- const configPath = ts4.findConfigFile(baseDir, ts4.sys.fileExists, "tsconfig.json");
789
+ let configPath = ts4.findConfigFile(baseDir, ts4.sys.fileExists, "tsconfig.json");
790
+ if (!configPath) {
791
+ configPath = ts4.findConfigFile(baseDir, ts4.sys.fileExists, "jsconfig.json");
792
+ }
778
793
  let compilerOptions = { ...DEFAULT_COMPILER_OPTIONS };
779
794
  if (configPath) {
780
795
  const configFile = ts4.readConfigFile(configPath, ts4.sys.readFile);
781
796
  const parsedConfig = ts4.parseJsonConfigFileContent(configFile.config, ts4.sys, path.dirname(configPath));
782
797
  compilerOptions = { ...compilerOptions, ...parsedConfig.options };
783
798
  }
784
- const allowJsVal = compilerOptions.allowJs;
785
- if (typeof allowJsVal === "boolean" && allowJsVal) {
786
- compilerOptions = { ...compilerOptions, allowJs: false, checkJs: false };
799
+ if (isJsFile(entryFile)) {
800
+ compilerOptions = {
801
+ ...compilerOptions,
802
+ allowJs: true,
803
+ checkJs: true,
804
+ isolatedDeclarations: false
805
+ };
806
+ } else {
807
+ const allowJsVal = compilerOptions.allowJs;
808
+ if (typeof allowJsVal === "boolean" && allowJsVal) {
809
+ compilerOptions = { ...compilerOptions, allowJs: false, checkJs: false };
810
+ }
787
811
  }
788
812
  const compilerHost = ts4.createCompilerHost(compilerOptions, true);
789
813
  let inMemorySource;
790
814
  if (content !== undefined) {
791
- inMemorySource = ts4.createSourceFile(entryFile, content, ts4.ScriptTarget.Latest, true, ts4.ScriptKind.TS);
815
+ inMemorySource = ts4.createSourceFile(entryFile, content, ts4.ScriptTarget.Latest, true, getScriptKind(entryFile));
792
816
  const originalGetSourceFile = compilerHost.getSourceFile.bind(compilerHost);
793
817
  compilerHost.getSourceFile = (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
794
818
  if (fileName === entryFile) {
package/dist/src/index.js CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  serializeTypeAlias,
27
27
  serializeVariable,
28
28
  withDescription
29
- } from "../shared/chunk-6p1dq6jb.js";
29
+ } from "../shared/chunk-c3pkvc28.js";
30
30
  // src/schema/registry.ts
31
31
  function isTypeReference(type) {
32
32
  return !!(type.flags & 524288 && type.objectFlags && type.objectFlags & 4);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/extract",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "TypeScript export extraction to OpenPkg spec",
5
5
  "keywords": [
6
6
  "openpkg",