diff --git a/ghost/admin/lib/asset-delivery/index.js b/ghost/admin/lib/asset-delivery/index.js index 09f3422925..54b3ccb2e7 100644 --- a/ghost/admin/lib/asset-delivery/index.js +++ b/ghost/admin/lib/asset-delivery/index.js @@ -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; } diff --git a/ghost/admin/lib/sourcemap-postprocess/index.js b/ghost/admin/lib/sourcemap-postprocess/index.js deleted file mode 100644 index d2c2d8ceca..0000000000 --- a/ghost/admin/lib/sourcemap-postprocess/index.js +++ /dev/null @@ -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)); - }); - } -}; diff --git a/ghost/admin/lib/sourcemap-postprocess/package.json b/ghost/admin/lib/sourcemap-postprocess/package.json deleted file mode 100644 index 1c4c13d860..0000000000 --- a/ghost/admin/lib/sourcemap-postprocess/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "sourcemap-postprocess", - "keywords": [ - "ember-addon" - ] -} diff --git a/ghost/admin/package.json b/ghost/admin/package.json index ea187f4ded..b43c5f2d37 100644 --- a/ghost/admin/package.json +++ b/ghost/admin/package.json @@ -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": {