source_downloader - SourceMapを元のJavaScriptファイルへ展開
JavaScriptはサイズを軽減したり、簡単に内容が読まれないように難読化(ミニファイ)して公開します。しかし、それではデバッグしづらいという問題があるため、SourceMapと呼ばれる仕組みがあります。 今回紹介するsource_downloaderはSourceMapファイルを読み込み、元のJavaScriptファイルを生成してくれるソフトウェアです。
source_downloaderの使い方
source_downloaderはリモートまたはローカルファイルを読み込めます。変換後はJavaScriptだけでなく、TypeScriptにも対応しています。
$ cat src/_bin.ts
import { join, resolve } from 'path'
import { start, Recoverable } from 'repl'
import { inspect } from 'util'
import arrify = require('arrify')
import Module = require('module')
import minimist = require('minimist')
import chalk from 'chalk'
import { diffLines } from 'diff'
import { Script } from 'vm'
import { register, VERSION, getFile, fileExists, TSError, parse, printError } from './index'
interface Argv {
eval?: string
print?: string
typeCheck?: boolean
cache?: boolean
cacheDirectory?: string
version?: boolean
help?: boolean
compiler?: string
project?: string
require?: string | string[]
ignore?: boolean | string | string[]
ignoreWarnings?: string | string[]
compilerOptions?: any
_: string[]
}
展開後はすべてのファイルディレクトリ構成も合わせて保存されるので、内容が確認しやすくなるでしょう。本番環境ではSourceMapファイルを置いていることは多くないと思いますが、このようにすべての内容を見られてしまうリスクがあるので注意してください。
source_downloaderはPython製のオープンソース・ソフトウェア(MIT License)です。