@scalar/import 0.5.28 → 0.5.29

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @scalar/import
2
2
 
3
+ ## 0.5.29
4
+
5
+ ### Patch Changes
6
+
7
+ - [#10411](https://github.com/scalar/scalar/pull/10411): Import API descriptions from reference page URLs, including Hono pages, and retain discovered document URLs for watch mode.
8
+
9
+ Ignore JSON-LD website metadata during URL discovery and preserve link and escaped-JSON fallbacks for URLs with unsupported JavaScript escapes.
10
+
3
11
  ## 0.5.28
4
12
 
5
13
  ## 0.5.27
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAsB,OAAO,CAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,EACrB,OAAO,CAAC,EAAE;IACR;;OAEG;IACH,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC3C,GACA,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC,CAyHnD;AA6ED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAiBtE;AAgCD;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAqB1E"}
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAsB,OAAO,CAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,EACrB,OAAO,CAAC,EAAE;IACR;;OAEG;IACH,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC3C,GACA,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC,CAyHnD;AAyFD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAiBtE;AAgCD;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAqB1E"}
package/dist/resolve.js CHANGED
@@ -156,10 +156,19 @@ function parseHtml(html) {
156
156
  if (scriptContent) {
157
157
  return scriptContent;
158
158
  }
159
+ // SEO metadata describes the website rather than its API description.
160
+ // Preserve a separator so excluding metadata cannot join surrounding text into a new match.
161
+ const htmlWithoutMetadata = html.replace(/<script\b[^>]*\btype\s*=\s*(?:"application\/ld\+json"|'application\/ld\+json'|application\/ld\+json(?=[\s>]))[^>]*>[\s\S]*?<\/script\s*>/gi, ' ');
159
162
  // Check for configuration in script tag
160
- const scriptConfigMatch = html.match(/url:\s*["']([^"']+)["']/i);
163
+ const scriptConfigMatch = htmlWithoutMetadata.match(/(?:["']url["']|\burl)\s*:\s*("(?:\\.|[^"\\])*"|'[^']*')/i);
161
164
  if (scriptConfigMatch?.[1]) {
162
- return scriptConfigMatch?.[1];
165
+ try {
166
+ // JSON serialization escapes characters in quoted URLs, including inline-script escapes.
167
+ return scriptConfigMatch[1].startsWith('"') ? JSON.parse(scriptConfigMatch[1]) : scriptConfigMatch[1].slice(1, -1);
168
+ }
169
+ catch {
170
+ // JS-only escapes are not JSON; keep trying the remaining discovery methods.
171
+ }
163
172
  }
164
173
  // Check for OpenAPI URLs in the HTML
165
174
  const linkMatch = html.match(/<a[^>]*href=["']([^"']+\.(?:yaml|yml|json))["'][^>]*>/i);
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "postman",
17
17
  "scalar"
18
18
  ],
19
- "version": "0.5.28",
19
+ "version": "0.5.29",
20
20
  "engines": {
21
21
  "node": ">=22"
22
22
  },
@@ -38,7 +38,9 @@
38
38
  "@scalar/helpers": "0.16.0",
39
39
  "yaml": "^2.9.0"
40
40
  },
41
- "devDependencies": {},
41
+ "devDependencies": {
42
+ "@scalar/client-side-rendering": "0.4.8"
43
+ },
42
44
  "scripts": {
43
45
  "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
44
46
  "dev": "tsx watch playground/index.ts",