@suss/adapter-typescript 0.5.5 → 0.5.6

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
@@ -1905,58 +1905,27 @@ function addImportersOfMatches(fileImports, matched, options) {
1905
1905
  }
1906
1906
  function internalSpecifierResolver(files, options) {
1907
1907
  const fileSet = new Set(files);
1908
- const probe = (base) => {
1909
- const stems = [base];
1910
- const swapped = base.replace(/\.(mjs|cjs|jsx|js)$/, "");
1911
- if (swapped !== base) {
1912
- stems.push(swapped);
1913
- }
1914
- for (const stem of stems) {
1915
- for (const candidate of [
1916
- stem,
1917
- `${stem}.ts`,
1918
- `${stem}.tsx`,
1919
- import_node_path.default.join(stem, "index.ts"),
1920
- import_node_path.default.join(stem, "index.tsx")
1921
- ]) {
1922
- if (fileSet.has(candidate)) {
1923
- return candidate;
1924
- }
1925
- }
1926
- }
1927
- return null;
1928
- };
1929
- const pathsBase = options.baseUrl ?? (typeof options.pathsBasePath === "string" ? options.pathsBasePath : "");
1930
- const aliasTargets = (spec) => {
1931
- const out = [];
1932
- for (const [pattern, targets] of Object.entries(options.paths ?? {})) {
1933
- const star = pattern.indexOf("*");
1934
- if (star === -1) {
1935
- if (spec === pattern) {
1936
- out.push(...targets);
1937
- }
1938
- continue;
1939
- }
1940
- const prefix = pattern.slice(0, star);
1941
- const suffix = pattern.slice(star + 1);
1942
- if (spec.length >= prefix.length + suffix.length && spec.startsWith(prefix) && spec.endsWith(suffix)) {
1943
- const filler = spec.slice(prefix.length, spec.length - suffix.length);
1944
- out.push(...targets.map((t) => t.replace("*", filler)));
1945
- }
1946
- }
1947
- return out.map((t) => import_node_path.default.resolve(pathsBase, t));
1948
- };
1908
+ const cache = import_ts_morph9.ts.createModuleResolutionCache(
1909
+ import_ts_morph9.ts.sys.getCurrentDirectory(),
1910
+ (name) => name,
1911
+ options
1912
+ );
1949
1913
  return (fromFile, spec) => {
1950
- if (spec.startsWith(".")) {
1951
- return probe(import_node_path.default.resolve(import_node_path.default.dirname(fromFile), spec));
1914
+ const resolved = import_ts_morph9.ts.resolveModuleName(
1915
+ spec,
1916
+ fromFile,
1917
+ options,
1918
+ import_ts_morph9.ts.sys,
1919
+ cache
1920
+ ).resolvedModule?.resolvedFileName;
1921
+ if (resolved === void 0) {
1922
+ return null;
1952
1923
  }
1953
- for (const target of aliasTargets(spec)) {
1954
- const hit = probe(target);
1955
- if (hit !== null) {
1956
- return hit;
1957
- }
1924
+ if (fileSet.has(resolved)) {
1925
+ return resolved;
1958
1926
  }
1959
- return null;
1927
+ const real = import_ts_morph9.ts.sys.realpath?.(resolved) ?? resolved;
1928
+ return fileSet.has(real) ? real : null;
1960
1929
  };
1961
1930
  }
1962
1931
  function collectAllGates(packs) {
package/dist/index.js CHANGED
@@ -1875,58 +1875,27 @@ function addImportersOfMatches(fileImports, matched, options) {
1875
1875
  }
1876
1876
  function internalSpecifierResolver(files, options) {
1877
1877
  const fileSet = new Set(files);
1878
- const probe = (base) => {
1879
- const stems = [base];
1880
- const swapped = base.replace(/\.(mjs|cjs|jsx|js)$/, "");
1881
- if (swapped !== base) {
1882
- stems.push(swapped);
1883
- }
1884
- for (const stem of stems) {
1885
- for (const candidate of [
1886
- stem,
1887
- `${stem}.ts`,
1888
- `${stem}.tsx`,
1889
- path.join(stem, "index.ts"),
1890
- path.join(stem, "index.tsx")
1891
- ]) {
1892
- if (fileSet.has(candidate)) {
1893
- return candidate;
1894
- }
1895
- }
1896
- }
1897
- return null;
1898
- };
1899
- const pathsBase = options.baseUrl ?? (typeof options.pathsBasePath === "string" ? options.pathsBasePath : "");
1900
- const aliasTargets = (spec) => {
1901
- const out = [];
1902
- for (const [pattern, targets] of Object.entries(options.paths ?? {})) {
1903
- const star = pattern.indexOf("*");
1904
- if (star === -1) {
1905
- if (spec === pattern) {
1906
- out.push(...targets);
1907
- }
1908
- continue;
1909
- }
1910
- const prefix = pattern.slice(0, star);
1911
- const suffix = pattern.slice(star + 1);
1912
- if (spec.length >= prefix.length + suffix.length && spec.startsWith(prefix) && spec.endsWith(suffix)) {
1913
- const filler = spec.slice(prefix.length, spec.length - suffix.length);
1914
- out.push(...targets.map((t) => t.replace("*", filler)));
1915
- }
1916
- }
1917
- return out.map((t) => path.resolve(pathsBase, t));
1918
- };
1878
+ const cache = ts.createModuleResolutionCache(
1879
+ ts.sys.getCurrentDirectory(),
1880
+ (name) => name,
1881
+ options
1882
+ );
1919
1883
  return (fromFile, spec) => {
1920
- if (spec.startsWith(".")) {
1921
- return probe(path.resolve(path.dirname(fromFile), spec));
1884
+ const resolved = ts.resolveModuleName(
1885
+ spec,
1886
+ fromFile,
1887
+ options,
1888
+ ts.sys,
1889
+ cache
1890
+ ).resolvedModule?.resolvedFileName;
1891
+ if (resolved === void 0) {
1892
+ return null;
1922
1893
  }
1923
- for (const target of aliasTargets(spec)) {
1924
- const hit = probe(target);
1925
- if (hit !== null) {
1926
- return hit;
1927
- }
1894
+ if (fileSet.has(resolved)) {
1895
+ return resolved;
1928
1896
  }
1929
- return null;
1897
+ const real = ts.sys.realpath?.(resolved) ?? resolved;
1898
+ return fileSet.has(real) ? real : null;
1930
1899
  };
1931
1900
  }
1932
1901
  function collectAllGates(packs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suss/adapter-typescript",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "type": "module",
5
5
  "description": "TypeScript adapter for suss — walks source files with ts-morph and emits raw extractions for the suss pipeline.",
6
6
  "keywords": [
@@ -46,10 +46,10 @@
46
46
  "typecheck": "tsc --noEmit"
47
47
  },
48
48
  "dependencies": {
49
- "@suss/behavioral-ir": "0.5.5",
50
- "@suss/datalog": "0.5.5",
51
- "@suss/extractor": "0.5.5",
52
- "@suss/resolution": "0.5.5",
49
+ "@suss/behavioral-ir": "0.5.6",
50
+ "@suss/datalog": "0.5.6",
51
+ "@suss/extractor": "0.5.6",
52
+ "@suss/resolution": "0.5.6",
53
53
  "graphql": "^16.8.0",
54
54
  "picomatch": "^4.0.4",
55
55
  "ts-morph": "^23.0.0"