代码拉取完成,页面将自动刷新
同步操作将从 唐志远/webpack-sourcemap-unpacker 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env node
const path = require('path');
const fse = require('fs-extra');
const glob = require('glob');
const SourceMapConsumer = require('source-map').SourceMapConsumer;
const program = require('commander');
const config = require('./package.json');
const dataUriToBuffer = require('data-uri-to-buffer');
program.version(config.version, '-v, --version').description('Unpack the sourcemaps generated by Webpack to a project folder').usage('[options]').option('-p, --prefix [webpack:///]', 'filter the path with certain prefix').option('-i, --input [glob-pattern]',
'a glob patterns to describe sourcemap files to be unpacked, default to *.map').option('-o, --output [folder]', 'set the output folder, default to current folder');
program.action((options) => {
options.input = options.input || '*.map';
options.output = options.output || '.';
options.prefix = options.prefix || 'webpack:///';
let files = glob.sync(options.input);
if (!files.length) {
console.warn(`There is no ${options.input} in current directory`);
return;
}
console.info(`output src to ${options.output}`);
files.forEach(async function(filepath) {
console.info(`extract sourcemap: ${filepath}`);
const mapSource = fse.readFileSync(path.resolve(filepath));
const consumer = await new SourceMapConsumer(mapSource.toString());
const paths = consumer._absoluteSources;
const sources = consumer.sourcesContent;
paths.forEach((p, idx) => {
const relativePath = path.relative(options.prefix, p).replace(/\\/g, '/');
const parts = relativePath.match(/([0-9a-zA-Z_/.\-@]+?)(\?\w{4})?$/);
if (!parts) {
// ignore special path
console.log(`ignore file: ${p}`);
return;
}
// handle filename ends with hash
const folder = path.resolve(path.join(options.output, path.dirname(parts[1])));
const basename = path.basename(parts[1]);
const extname = path.extname(basename);
const filename = (parts[2] ? path.basename(basename, extname) + parts[2] + extname : basename);
let absPath = path.resolve(path.join(folder, filename));
if (path.relative(path.resolve(), absPath).startsWith('..')) {
console.error(`Do not write files to ancestor folder: ${p}. Please check the prefix option: ${options.prefix}`);
process.exit(1);
}
console.info(`output to file: ${absPath}`);
let source;
switch (extname) {
// plain text files
case '.glsl':
source = evalModule(sources[idx]).exports;
break;
// base64 files
case '.jpg':
case '.gif':
case '.png':
case '.obj':
const exports = evalModule(sources[idx]).exports;
try {
source = dataUriToBuffer(exports);
} catch (e) {
console.info(`It's not a binary file: ${absPath}`);
source = sources[idx];
absPath += '.js';
}
break;
default:
source = sources[idx];
}
fse.ensureDirSync(folder);
fse.writeFileSync(absPath, source);
});
});
});
program.parse(process.argv);
function evalModule(source) {
return eval(`
let module = {};
let __webpack_public_path__ = '';
${source}
module;
`);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。