mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Added sourceRoot
key to sourcemaps before asset-delivery
runs (#18849)
no issue - Follow up toa382cd8a91
andfb34e285fc
- The `sourcemap-postprocess` addon was ineffective because the assets were being copied to `/ghost/core/core/built` before the addon was run, so the changes weren't being applied in staging/production - This change makes the required modifications to the sourcemaps before copying them
This commit is contained in:
parent
dffc547219
commit
85fca5891f
4 changed files with 11 additions and 39 deletions
|
@ -63,11 +63,20 @@ module.exports = {
|
|||
// copy the index.html file
|
||||
fs.copySync(`${results.directory}/index.html`, `${assetsOut}/index.html`, {overwrite: true, dereference: true});
|
||||
|
||||
// copy all the `/assets` files, except the `icons` folder
|
||||
// get all the `/assets` files, except the `icons` folder
|
||||
const assets = walkSync(results.directory + '/assets', {
|
||||
ignore: ['icons']
|
||||
});
|
||||
|
||||
// loop over any sourcemaps and add a "sourceRoot" key to each one before copying
|
||||
assets.filter((file) => file.endsWith('.map')).forEach((file) => {
|
||||
const mapFilePath = `${results.directory}/assets/${file}`;
|
||||
const mapFile = JSON.parse(fs.readFileSync(mapFilePath, 'utf8'));
|
||||
mapFile.sourceRoot = '../';
|
||||
fs.writeFileSync(mapFilePath, JSON.stringify(mapFile));
|
||||
});
|
||||
|
||||
// copy the assets to assetsOut
|
||||
assets.forEach(function (relativePath) {
|
||||
if (relativePath.slice(-1) === '/') { return; }
|
||||
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
/* eslint-disable */
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
name: 'sourcemap-postprocess',
|
||||
|
||||
isDevelopingAddon() {
|
||||
return true;
|
||||
},
|
||||
|
||||
postBuild: function (results) {
|
||||
// read all .map files in the /assets directory
|
||||
const assets = fs.readdirSync(path.join(results.directory, 'assets'));
|
||||
const mapFiles = assets.filter((file) => file.endsWith('.map'));
|
||||
|
||||
// loop over the mapfiles and add a "sourceRoot" key to each one
|
||||
mapFiles.forEach((file) => {
|
||||
const mapFilePath = path.join(results.directory, 'assets', file);
|
||||
const mapFile = JSON.parse(fs.readFileSync(mapFilePath, 'utf8'));
|
||||
const sources = mapFile.sources;
|
||||
for (let i = 0; i < sources.length; i++) {
|
||||
sources[i] = sources[i].replace('assets/', '');
|
||||
}
|
||||
fs.writeFileSync(mapFilePath, JSON.stringify(mapFile));
|
||||
});
|
||||
}
|
||||
};
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"name": "sourcemap-postprocess",
|
||||
"keywords": [
|
||||
"ember-addon"
|
||||
]
|
||||
}
|
|
@ -151,8 +151,7 @@
|
|||
"paths": [
|
||||
"lib/asset-delivery",
|
||||
"lib/ember-power-calendar-moment",
|
||||
"lib/ember-power-calendar-utils",
|
||||
"lib/sourcemap-postprocess"
|
||||
"lib/ember-power-calendar-utils"
|
||||
]
|
||||
},
|
||||
"resolutions": {
|
||||
|
|
Loading…
Reference in a new issue