Skip to content

Commit

Permalink
Bump source-map and skip any files missing contents
Browse files Browse the repository at this point in the history
`source-map` was incorrectly attempting to detect if we're in a browsers
context by checking if `typeof fetch === 'function'` which in never versions of
node if present. Because of this source-map was reqesting that we provide a
WASM file.

[read more here](mozilla/source-map#349)

Bumping to 0.8.0-beta.0 fixes this.

Also filters out any files in the sourcemap which don't have a file contents
associated with it.
  • Loading branch information
Georift committed Apr 12, 2024
1 parent b94ca8c commit 11ae622
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 14 deletions.
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ assert(removeQuerySuffix("./index.css?8415") === "./index.css");
}

const toWrite = sourceFiles.filter(([savePath]) => !duplicates.has(savePath));
const missingContent = toWrite.filter(([, , content]) => !content)
const withContent = toWrite.filter(([, , content]) => !!content)

if (missingContent.length > 0) {
console.log(`Skipping ${missingContent.length} files which the source map did not provide any contents\n`)
}

if (withContent.length === 0) {
console.error('We were unable to find any files which contained source code in this source map')
process.exit(-1)
}

const outputDirectory = resolve(
process.cwd(),
Expand All @@ -83,7 +94,7 @@ assert(removeQuerySuffix("./index.css?8415") === "./index.css");
}

// write to the output directory
toWrite.forEach(([savePath, _, content]) => {
withContent.forEach(([savePath, _, content]) => {
const outputPath = resolve(outputDirectory, savePath);
const directory = dirname(outputPath);

Expand Down
98 changes: 88 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "source-map-to-source",
"version": "0.0.1",
"version": "1.0.2",
"description": "",
"main": "index.js",
"type": "module",
Expand All @@ -11,10 +11,10 @@
"author": "",
"license": "MIT",
"dependencies": {
"source-map": "^0.7.3",
"source-map": "^0.8.0-beta.0",
"yargs": "^17.3.1"
},
"bin": {
"source-map-to-source": "./index.js"
"source-map-to-source": "index.js"
}
}

0 comments on commit 11ae622

Please sign in to comment.