Skip to content

Ensure module map is only generated once #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ethul opened this issue Jun 27, 2017 · 2 comments
Closed

Ensure module map is only generated once #97

ethul opened this issue Jun 27, 2017 · 2 comments
Assignees

Comments

@ethul
Copy link
Owner

ethul commented Jun 27, 2017

// map of PS module names to their source path
function psModuleMap(options, cache) {
  if (cache.psModuleMap) return cache.psModuleMap;
  else {
    var globs = [].concat(options.src).concat(options.ffi);

    cache.psModuleMap = globby(globs).then(function (paths) {
      return Promise.props(paths.reduce(function (map, file) {
        map[file] = fs.readFileAsync(file, 'utf8');
        return map;
      }, {})).then(function (fileMap) {
        return Object.keys(fileMap).reduce(function (map, file) {
          var source = fileMap[file];
          var ext = path.extname(file);
          var isPurs = ext.match(/purs$/i);
          var moduleRegex = isPurs ? srcModuleRegex : ffiModuleRegex;
          var moduleName = match(moduleRegex, source);
          map[moduleName] = map[moduleName] || {};
          if (isPurs) {
            map[moduleName].src = path.resolve(file);
          } else {
            map[moduleName].ffi = path.resolve(file);
          }
          return map;
        }, {});
      });
    });

    return cache.psModuleMap;
  }
}
@ethul ethul self-assigned this Jun 27, 2017
@ethul
Copy link
Owner Author

ethul commented Jun 27, 2017

Check if this issue is present in recent versions.

ethul added a commit that referenced this issue Jun 27, 2017
@ethul
Copy link
Owner Author

ethul commented Aug 23, 2017

Indeed this issue is present in the latest version:

if (!cache.psModuleMap) {
debug('module mapping does not exist');
return PsModuleMap.makeMap(options.src).then(map => {
cache.psModuleMap = map;
return cache.psModuleMap;
});
}
else {
return PsModuleMap.makeMapEntry(filePurs).then(result => {
const map = Object.assign(cache.psModuleMap, result);
cache.psModuleMap = map;
return cache.psModuleMap;
});
}

purs-loader/src/index.js

Lines 253 to 257 in 466c006

PsModuleMap.makeMap(options.src).then(map => {
debug('rebuilt module map after unknown module forced a recompilation');
cache.psModuleMap = map;
})

purs-loader/src/index.js

Lines 321 to 325 in 466c006

PsModuleMap.makeMap(options.src).then(map => {
debug('rebuilt module map after compilation');
cache.psModuleMap = map;
})

We can apply the same style of fix where the module map is set to be a promise.

ethul added a commit that referenced this issue Aug 24, 2017
ethul added a commit that referenced this issue Aug 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant