Skip to content

Commit

Permalink
Support SourceMap response header
Browse files Browse the repository at this point in the history
  • Loading branch information
omrilotan committed May 30, 2024
1 parent cd3a122 commit 05754bf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [2.2.0](https://github.com/omrilotan/isbot/compare/v2.1.0...v2.2.0)

- Support reading sourcemap location from [SourceMap header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/SourceMap)

## [2.1.0](https://github.com/omrilotan/isbot/compare/v2.0.0...v2.1.0)

- Support reading and creating a config file (`colombo --config`)
Expand Down
7 changes: 5 additions & 2 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { readFile } from "node:fs/promises";
import inquirer from "inquirer";
import chalk from "chalk";
import semver from "semver";
import sourceMappingURL from "source-map-url";
import { config } from "./lib/config/index.js";
import { getSourceCodeMapUrl } from "./lib/getSourceCodeMapUrl/index.js";
import { loader } from "./lib/loader/index.js";
Expand Down Expand Up @@ -90,9 +91,11 @@ async function start() {
`Failed to load file ${clean}: ${response.status} ${response.statusText}`,
);
}
const code = await response.text();
const file =
response.headers.get("SourceMap") ||
sourceMappingURL.getFrom(await response.text());
loader.end();
const mapUrl = getSourceCodeMapUrl(code, clean);
const mapUrl = getSourceCodeMapUrl(file, clean);

if (mapUrl) {
({ url } = await prompt([
Expand Down
5 changes: 0 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ async function getData(url, { headers } = {}) {
`Failed to load file ${url}: ${response.status} ${response.statusText}`,
);
}
if (!response.ok) {
throw new Error(
`${url} returned status ${response.status} ${response.statusText}`,
);
}
const data = await response.text();

if (
Expand Down
5 changes: 1 addition & 4 deletions lib/getSourceCodeMapUrl/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { dirname, join } from "node:path";
import { URL } from "node:url";
import sourceMappingURL from "source-map-url";

export function getSourceCodeMapUrl(source, url) {
const file = sourceMappingURL.getFrom(source);

export function getSourceCodeMapUrl(file, url) {
if (!file) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "colombo",
"version": "2.1.0",
"version": "2.2.0",
"description": "🕵️‍♂️ View Javascript source code using source-map from CLI",
"keywords": [
"sourcemap",
Expand Down

0 comments on commit 05754bf

Please sign in to comment.