summaryrefslogtreecommitdiffstatshomepage
path: root/core/scripts/js/assets/process/map.js
blob: f6efc38a581d3684c6d2224fd470e8f47efcd45b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * Process map files.
 *
 * In the `sources` member, remove all "../" values at the start of the file
 * names to avoid virtual files located outside of the library vendor folder.
 *
 * @param {object} data
 *  Object passed to the callback.
 * @param {string} data.contents
 *  Content of the file being processed.
 *
 * @return {Promise<[{contents: string}]>}
 *  Return a Promise that resolves into an array of file and content to create
 *  in the assets/vendor/ directory.
 */
module.exports = ({ contents }) => {
  const json = JSON.parse(contents);
  json.sources = json.sources.map((source) => source.replace(/^(\.\.\/)+/, ''));
  return [{ contents: JSON.stringify(json) }];
};