Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const {
mainMap,
mainSource: mainSourceFilename,
asyncChunks,
} = this.getFilenamesFromChunks(compilation.chunks);
const sourceMappingRegex = /\/\/# sourceMappingURL=(.+)/;
const mainSource = compilation.assets[mainSourceFilename].source();
const sourceMappingMatch = new RegExp(sourceMappingRegex, 'g').exec(
mainSource
);
// Concatenate all chunks and its source maps. Chunks source needs to have source mapping URL
// removed, since it will be added at the end of the whole bundle.
const concat = new Concat(true, mainSourceFilename, '\n');
concat.add(
mainSourceFilename,
mainSource.replace(new RegExp(sourceMappingRegex, 'g'), ''),
this.sourceMap ? compilation.assets[mainMap].source() : undefined
);
asyncChunks.forEach(chunk => {
concat.add(
chunk.source,
(compilation.assets[chunk.source].source() as string).replace(
new RegExp(sourceMappingRegex, 'g'),
''
),
this.sourceMap ? compilation.assets[chunk.map].source() : undefined
);
});
test('uses source map', t => {
let concat = new Concat(true, 'all.css');
concat.add('a.css', 'a { }\n');
concat.add('b.css', '\nb {\n');
let error = parseError(concat.content, {
from: 'build/all.css',
map: { prev: concat.sourceMap }
});
t.deepEqual(error.file, path.resolve('b.css'));
t.deepEqual(error.line, 2);
t.deepEqual(typeof error.source, 'undefined');
t.deepEqual(error.input, {
file: path.resolve('build/all.css'),
line: 3,
column: 1,
const getExtracted = () => {
const fileName =
typeof postcssLoaderOptions.extract === 'string' ?
path.relative(dir, postcssLoaderOptions.extract) :
`${path.basename(file, path.extname(file))}.css`
const concat = new Concat(true, fileName, '\n')
const entries = Array.from(extracted.values())
const { modules } = bundle[path.relative(dir, file)]
if (modules) {
const fileList = Object.keys(modules)
entries.sort(
(a, b) => fileList.indexOf(a.id) - fileList.indexOf(b.id)
)
}
for (const res of entries) {
const relative = path.relative(dir, res.id)
const map = res.map || null
if (map) {
map.file = fileName
}
concat.add(relative, res.code, map)
export default function concat(input: string[] = [], output: string) {
if (Array.isArray(input) && input.length) {
const concatenator = new Concat(generateSourceMap, output, separator);
input
.filter(existsSync)
.forEach((filePath) => {
const fileContent = readFileSync(filePath);
const sourceMapPath = `${filePath}.map`;
let sourceMapContent;
if (existsSync(sourceMapPath)) {
const mapContent = JSON.parse(readFileSync(sourceMapPath, encoding));
mapContent.sources = mapContent.sources.map(sourcePath => (
resolve(dirname(sourceMapPath), sourcePath)
));
sourceMapContent = JSON.stringify(mapContent);