Skip to content

Commit

Permalink
Handle windows unpacking
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthonyzou committed Jun 22, 2022
1 parent 279b71a commit efd187c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "source-map-unpacker",
"version": "1.5.5",
"version": "2.0.0",
"description": "",
"main": "unmap.js",
"bin": {
"unpack": "unmap.js"
},
"type": "module",
"engines": {
"node": ">10"
},
Expand All @@ -27,6 +28,7 @@
"license": "MIT",
"dependencies": {
"commander": "9.3.0",
"filenamify": "5.1.1",
"fs-extra": "10.1.0"
},
"devDependencies": {
Expand Down
33 changes: 33 additions & 0 deletions pnpm-lock.yaml

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

22 changes: 14 additions & 8 deletions unmap.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#!/usr/bin/env node

const fs = require("fs-extra");
const { resolve } = require("path");
const { Command } = require("commander");
import fs from "fs-extra";
import filenamify from "filenamify";
import os from "os";
import { resolve } from "path";
import { Command } from "commander";
const program = new Command();
const isWindows = os.platform() == "win32";

const opts = program
.name("unmap")
.requiredOption("-p, --path <p>", "input source map file")
.option("-f, --filter <f>", "filter out file names")
.option("-o, --output <o>", "output folder", "./")
.requiredOption("-p, --path <p>", "Input source map file")
.option("-f, --filter <f>", "Filter out file names")
.option("-o, --output <o>", "Output folder", "./")
.parse(process.argv)
.opts();

fs.readFile(opts.path)
.catch(async (e) => {
if (e.errno == -13) {
console.log("Insufficient permissions to read the tnput file.");
console.log("Insufficient permissions to read the input file.");
}
if (e.errno == -2) {
console.log("Input file does not exists.");
Expand All @@ -29,7 +32,10 @@ fs.readFile(opts.path)
const files = js.sources
.filter((path) => (opts.filter ? path.includes(opts.filter) : true))
.map((path, idx) => {
const outpath = resolve(opts.output, path);
const outpath = resolve(
opts.output,
isWindows ? filenamify(path) : path
);
return fs.outputFile(outpath, js.sourcesContent[idx]);
});
return Promise.all(files);
Expand Down

0 comments on commit efd187c

Please sign in to comment.