npm install -g source-map-unpack
unpack <project-folder> <path-to-sourcemap>
For example:
unpack egghead js/egghead-bundle.js.map
Note:
The original minified file should be placed according to the path in sources map's file
variable.
Unpack ๐ your JS source maps ๐บ to original files and folders.
npm install -g source-map-unpack
unpack <project-folder> <path-to-sourcemap>
For example:
unpack egghead js/egghead-bundle.js.map
Note:
The original minified file should be placed according to the path in sources map's file
variable.
When running this tool under Node 18, the following error is thrown:
Error: You must provide the URL of lib/mappings.wasm by calling SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) before using SourceMapConsumer
I've found the explanation here: https://stackoverflow.com/a/77308483/2280444
Workaround: run under node 16 - tested, it works
Solution: upgrade source-map
package to 0.7.4 - not tested
To run this project, you have to use an older nodejs version. You can do that with nvm : nvm use v10.20.1
and then npm i -g source-map-unpack
.
If you don't have nvm, you can clone the repository and remove the ascii-progress dependency just like this : https://github.com/pavloko/source-map-unpack/pull/1/files
Doesn't work with Node.js 14.8
src/index.ts:49:40 - error TS2345: Argument of type 'string | null' is not assignable to parameter of type 'string | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | In...'.
Type 'null' is not assignable to type 'string | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | In...'.
49 fs.writeFileSync(filePath, content)
This seems to fix it
diff --git a/src/index.ts b/src/index.ts
index e3c3e67..f274fa5 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -46,7 +46,7 @@ try {
const content = consumer.sourceContentFor(source)
const filePath = `${process.cwd()}/${projectNameInput}/${source.substring(WEBPACK_SUBSTRING_INDEX)}`
mkdirp.sync(dirname(filePath))
- fs.writeFileSync(filePath, content)
+ fs.writeFileSync(filePath, content as string)
})
console.log(chalk.green('๐ All done! Enjoy exploring your code ๐ป'))
})
The source of the issue is the use of the prepublish
script in package.json. According to the documentation, prepublish
is deprecated and prepublishOnly
should be used instead.
I'm getting the same error as here, I've tried the solutions but they didn't work for me and I'm recreating it because the issue is closed.
Error:
>unpack output C:\Users\windows\Desktop\source\static\js\main.60f996d4.chunk.js.map
Unpacking ๐ your sourceย maps ๐บ
node:fs:590
handleErrorFromBinding(ctx);
^
Error: EISDIR: illegal operation on a directory, open 'C:\Users\alperen.saylar\cikmis\'
at Object.openSync (node:fs:590:3)
at Object.writeFileSync (node:fs:2202:35)
at C:\Users\alperen.saylar\AppData\Roaming\npm\node_modules\source-map-unpack\dist\index.js:47:16
at Array.forEach (<anonymous>)
at C:\Users\alperen.saylar\AppData\Roaming\npm\node_modules\source-map-unpack\dist\index.js:42:17
at C:\Users\alperen.saylar\AppData\Roaming\npm\node_modules\source-map-unpack\node_modules\source-map\lib\source-map-consumer.js:78:16 {
errno: -4068,
syscall: 'open',
code: 'EISDIR',
path: 'C:\\Users\\alperen.saylar\\cikmis\\'
}
I invested in the arrangement called here #23 but the problem persists:
if (!fs.existsSync(pathToProject)) {
console.log()
// Create project dir if it doesn't exist
try {
fs.mkdirSync(projectNameInput,'0777', true)
} catch (err) {
console.log(chalk.red(`Couldn't create project at: ${pathToProject}, please, check your permissions`))
}
console.log(chalk.red(`Project created at: ${pathToProject}`))
console.log()
process.exit()
}
The full code is as follows:
#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var fs = require("fs");
var path = require("path");
var chalk = require("chalk");
var mkdirp = require("mkdirp");
var minimist = require("minimist");
var source_map_1 = require("source-map");
var argv = minimist(process.argv.slice(2));
var projectNameInput = argv._[0];
var mapInput = argv._[1];
if (!projectNameInput || !mapInput) {
console.log();
console.log(chalk.white('Usage: unpack'), chalk.green('<folder-name-to-unpack-files-to)> <path-to-map-file>'));
console.log();
console.log(chalk.blue('Note: Minified javascript file should be placed under path specified in .map file.'));
console.log();
process.exit();
}
var pathToProject = path.join(process.cwd(), projectNameInput);
var pathToMap = path.isAbsolute(mapInput)
? mapInput
: path.join(process.cwd(), mapInput);
if (!fs.existsSync(pathToProject)) {
console.log()
// Create project dir if it doesn't exist
try {
fs.mkdirSync(projectNameInput,'0777', true)
} catch (err) {
console.log(chalk.red(`Couldn't create project at: ${pathToProject}, please, check your permissions`))
}
console.log(chalk.red(`Project created at: ${pathToProject}`))
console.log()
process.exit()
}
if (!fs.existsSync(pathToMap)) {
console.log();
console.log(chalk.red("Can't find map file under : " + pathToMap));
console.log();
process.exit();
}
try {
var mapFile = fs.readFileSync(pathToMap, 'utf8');
source_map_1.SourceMapConsumer.with(mapFile, null, function (consumer) {
console.log(chalk.green("Unpacking \uD83D\uDECD your source\u00A0maps \uD83D\uDDFA"));
var sources = consumer.sources;
sources.forEach(function (source) {
var WEBPACK_SUBSTRING_INDEX = 11;
var content = consumer.sourceContentFor(source);
var filePath = process.cwd() + "\\" + projectNameInput + "\\" + source.substring(WEBPACK_SUBSTRING_INDEX);
mkdirp.sync(path.dirname(filePath));
fs.writeFileSync(filePath, content);
});
console.log(chalk.green('๐ All done! Enjoy exploring your code ๐ป'));
});
}
catch (err) {
console.log(chalk.red('Oops! Something is wrong with the source map'), err);
console.log(chalk.red('Make sure .min.js is correctly placed under the path specified in .map file'));
console.log('STDERR: ');
console.log(err);
}
//# sourceMappingURL=index.js.map
The @types/node module is missing from the project.
source-map-unpack/src/index.ts
Lines 53 to 58 in 533b54c
process.exitCode
to 1
(recommended; the documentation on process.exit() explains why)process.exit(1)
index.d.ts still refers to the now-removed ascii-progress module and exposes the identifier in the global scope.
When running unpack
on attached source map I got the correct result, except the first letter of every top-level name was removed, like ain.js
instead of main.js
, pp.svelte
instead of App.svelte
, etc. All second level names and below are not affected.
Source maps (needs unzipping first): bundle.js.map.zip
source-map-unpack/tsconfig.json
Line 22 in 533b54c
baseUrl
should reside in the compilerOptions
object. The reason why the current set-up is working as expected is that TypeScript defaults baseUrl
to the directory in which tsconfig.json resides (which happens to be the same).
Remove baseUrl
from tsconfig.json or move it inside compilerOptions
.
First, let me thank you for this tool, it is awesome and it is helping us!
Could it be possible to have it go over all the *.map files in a directory and unpack all of them?
Our build outputs a bunch of bundles and chunks.
Thank you!
When I unpacked a .js.map
file I get these folders:
asics
omposites
However, they should be "basics" and "composites".
source-map-unpack/src/index.ts
Lines 54 to 58 in 73f626a
'webpack://'.length => 10
So the quick fix is probably to change WEBPACK_SUBSTRING_INDEX
to 10
. However, personally I think I'd prefer if you just did source.replaceAll('://', '/')
instead. Not sure if there could ever be another prefix other than webpack://
. ๐คท
C:\Users\Parthiv>unpack nau Downloads/main.5ff428f5.chunk.js.map
Unpacking ๐ your sourceย maps ๐บ
(node:12492) UnhandledPromiseRejectionWarning: Error: EISDIR: illegal operation on a directory, open 'C:\Users\Parthiv/nau/'
at Object.openSync (fs.js:476:3)
at Object.writeFileSync (fs.js:1467:35)
at C:\Users\Parthiv\AppData\Roaming\npm\node_modules\source-map-unpack\dist\index.js:47:16
at Array.forEach (<anonymous>)
at C:\Users\Parthiv\AppData\Roaming\npm\node_modules\source-map-unpack\dist\index.js:42:17
at C:\Users\Parthiv\AppData\Roaming\npm\node_modules\source-map-unpack\node_modules\source-map\lib\source-map-consumer.js:78:16
(Use `node --trace-warnings ...` to show where the warning was created)
(node:12492) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:12492) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Since this package is using source-map 0.7.3, it is suffering from mozilla/source-map#349.
$ unpack panel-js panel.js.map
/opt/homebrew/lib/node_modules/source-map-unpack/node_modules/source-map/lib/read-wasm.js:8
throw new Error("You must provide the URL of lib/mappings.wasm by calling " +
^
Error: You must provide the URL of lib/mappings.wasm by calling SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) before using SourceMapConsumer
at readWasm (/opt/homebrew/lib/node_modules/source-map-unpack/node_modules/source-map/lib/read-wasm.js:8:13)
at wasm (/opt/homebrew/lib/node_modules/source-map-unpack/node_modules/source-map/lib/wasm.js:25:16)
at /opt/homebrew/lib/node_modules/source-map-unpack/node_modules/source-map/lib/source-map-consumer.js:264:14
Node.js v18.16.1
Installing Node.js v16.20.1 makes it work.
If source-map is upgraded to 0.7.4 then this problem will be fixed.
I don't think this recommendation is necessary. Maybe it was different in older source map versions, but I think these days all of the necessary information is present in the .js.map
file. I don't need to have the compiled javascript file in the same directory.
source-map-unpack/src/index.ts
Lines 20 to 24 in 73f626a
Lines 14 to 16 in 73f626a
So this suggestion should probably be removed. If it is required in some special cases then hopefully the person using the program understands this already.
Packages provided by Definitely Typed (@types
packages) aren't guaranteed to work with the TypeScript version range required by the project (per this compatibility table):
source-map-unpack/package.json
Line 41 in 533b54c
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.