From 0e789053ecef592874883ec56b3464243069b8de Mon Sep 17 00:00:00 2001 From: Justin Woo Date: Wed, 18 Nov 2015 01:21:35 +0100 Subject: [PATCH] fix installation from npm3 npm3 will flatten node_modules, so the nested node_modules that is used for copying the JSON over from Topojson will not be available in the package's relative node_modules. This commit uses a synchronous check to see if the path is valid and on failure with try to use the path expected from npm3 installations. --- tasks/util/constants.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tasks/util/constants.js b/tasks/util/constants.js index 4d62788e845..edf7255d5a9 100644 --- a/tasks/util/constants.js +++ b/tasks/util/constants.js @@ -1,11 +1,24 @@ +var fs = require('fs'); var path = require('path'); var pathToRoot = path.join(__dirname, '../../'); +var pathToRootParent = path.join(__dirname, '../../../../'); var pathToSrc = path.join(pathToRoot, 'src/'); var pathToImageTest = path.join(pathToRoot, 'test/image'); var pathToDist = path.join(pathToRoot, 'dist/'); var pathToBuild = path.join(pathToRoot, 'build/'); +var pathToTopojsonSrc; + +// npm3 flattens modules, so they won't be accessible through the old nested npm2 paths +// attempt a synchronous filestat check, and on error, use the npm3 path +try { + pathToTopojsonSrc = path.join(pathToRoot, 'node_modules/sane-topojson/dist/'); + fs.statSync(pathToTopojsonSrc); +} catch (e) { + pathToTopojsonSrc = path.join(pathToRootParent, 'node_modules/sane-topojson/dist/'); +} + module.exports = { pathToRoot: pathToRoot, pathToSrc: pathToSrc, @@ -17,7 +30,7 @@ module.exports = { pathToPlotlyDistMin: path.join(pathToDist, 'plotly.min.js'), pathToPlotlyDistWithMeta: path.join(pathToDist, 'plotly-with-meta.js'), - pathToTopojsonSrc: path.join(pathToRoot, 'node_modules/sane-topojson/dist/'), + pathToTopojsonSrc: pathToTopojsonSrc, pathToTopojsonDist: path.join(pathToDist, 'topojson/'), pathToPlotlyGeoAssetsSrc: path.join(pathToSrc, 'assets/geo_assets.js'), pathToPlotlyGeoAssetsDist: path.join(pathToDist, 'plotly-geo-assets.js'),