Using Bluebird with fs to read a file within each of an (variable length) array of directories I'm reading an array (of unknown length) of modules package.json files in order to extract the "style" property and store it in an array of its own:

var gulp = require('gulp')
  , path = require('path')
  , Promise = require('bluebird')
  , fs = Promise.promisifyAll(require('fs-extra'));

let components = [
    'comp1',
    'comp2',
    'comp3'
];
let npmScope = '@myscope';
gulp.task('getstyle', () =&gt; {
    let componentsBaseLocation = path.join(__dirname, 'node_modules', npmScope);
    Promise.map(components, (componentName) =&gt; {
        return fs.readFileAsync(path.join(componentsBaseLocation, componentName, 'package.json'), 'utf8')
    })
    .spread((...packageData) =&gt; {
        return packageData.map((packageDatum, i) =&gt; {
            packageDatum = JSON.parse(packageDatum);
            tempName = packageDatum.name.match(new RegExp(`${NpmScope}\/(.*?)$`))[1]
            tempStyle = path.join(componentsBaseLocation, tempName, packageDatum.style);
            return {
                name: tempName,
                style: tempStyle
            };
        });
    })
    .then(components =&gt; {
        console.log(JSON.stringify(components, null, 2));
    });
});


This works, but I wonder if there are smarter, better, more appropriate ways to use bluebird or promises in general.
Several things you could simplify:


You don't need to use .spread() since the data is already in an array.  
If you just process each file as it is read, you can avoid the .map() iteration entirely.
You can avoid some temporary variables.
You should declare all local variables with const, let or var as appropriate.


Here's modified code:

var gulp = require('gulp')
  , path = require('path')
  , Promise = require('bluebird')
  , fs = Promise.promisifyAll(require('fs-extra'));

let components = [
    'comp1',
    'comp2',
    'comp3'
];
let npmScope = '@myscope';
gulp.task('getstyle', () =&gt; {
    const componentsBaseLocation = path.join(__dirname, 'node_modules', npmScope);
    Promise.map(components, (componentName) =&gt; {
        return fs.readFileAsync(path.join(componentsBaseLocation, componentName, 'package.json'), 'utf8').then(data =&gt; {
            const packageDatum = JSON.parse(data);
            const tempName = packageDatum.name.match(new RegExp(`${NpmScope}\/(.*?)$`))[1];
            return {
                name: tempName,
                style: path.join(componentsBaseLocation, tempName, packageDatum.style)
            };
        });
    }).then(components =&gt; {
        console.log(JSON.stringify(components, null, 2));
    });
});


You may also want to handle a failure in JSON.parse() with a local try/catch handler so rather than end the entire operation, you can handle an individual error and continue with the rest of the processing, but that depends entirely upon how you're using this code and what you want to happen if a parse failure occurs.

You may also want to handle a failure in packageDatum.name.match().