cnpm / cnpmjs.org

@@ -386,6 +386,13 @@
Loading
386 386
      continue;
387 387
    }
388 388
    // https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md#abbreviated-version-object
389 +
    var hasInstallScript;
390 +
    if (row.package.scripts) {
391 +
      // https://www.npmjs.com/package/fix-has-install-script
392 +
      if (row.package.scripts.install || row.package.scripts.preinstall || row.package.scripts.postinstall) {
393 +
        hasInstallScript = true;
394 +
      }
395 +
    }
389 396
    var pkg = {
390 397
      name: row.package.name,
391 398
      version: row.package.version,
@@ -404,6 +411,7 @@
Loading
404 411
      engines: row.package.engines,
405 412
      workspaces: row.package.workspaces,
406 413
      _hasShrinkwrap: row.package._hasShrinkwrap,
414 +
      hasInstallScript: hasInstallScript,
407 415
      publish_time: row.package.publish_time || row.publish_time,
408 416
    };
409 417
    common.setDownloadURL(pkg, ctx);

@@ -355,11 +355,22 @@
Loading
355 355
};
356 356
357 357
// https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md#abbreviated-version-object
358 -
exports.saveModuleAbbreviated = function* (mod) {
359 -
  var pkg = JSON.stringify(Object.assign({}, mod.package, {
360 -
    // ignore readme force
361 -
    readme: undefined,
362 -
  }));
358 +
exports.saveModuleAbbreviated = function* (mod, remoteAbbreviatedVersion) {
359 +
  // try to use remoteAbbreviatedVersion first
360 +
  var pkg;
361 +
  if (remoteAbbreviatedVersion) {
362 +
    pkg = Object.assign({}, remoteAbbreviatedVersion, {
363 +
      // override remote tarball
364 +
      dist: Object.assign({}, remoteAbbreviatedVersion.dist, mod.package.dist, {
365 +
        noattachment: undefined,
366 +
      }),
367 +
    });
368 +
  } else {
369 +
    pkg = Object.assign({}, mod.package, {
370 +
      // ignore readme force
371 +
      readme: undefined,
372 +
    });
373 +
  }
363 374
  var publish_time = mod.publish_time || Date.now();
364 375
  var item = yield models.ModuleAbbreviated.findByNameAndVersion(mod.name, mod.version);
365 376
  if (!item) {
@@ -369,7 +380,7 @@
Loading
369 380
    });
370 381
  }
371 382
  item.publish_time = publish_time;
372 -
  item.package = pkg;
383 +
  item.package = JSON.stringify(pkg);
373 384
374 385
  if (item.changed()) {
375 386
    item = yield item.save();

@@ -207,8 +207,8 @@
Loading
207 207
  // sync source, upstream registry
208 208
  // If you want to directly sync from official npm's registry
209 209
  // please drop them an email first
210 -
  sourceNpmRegistry: 'https://registry.npm.taobao.org',
211 -
  sourceNpmWeb: 'https://npm.taobao.org',
210 +
  sourceNpmRegistry: 'https://registry.npmmirror.com',
211 +
  sourceNpmWeb: 'https://npmmirror.com',
212 212
213 213
  // upstream registry is base on cnpm/cnpmjs.org or not
214 214
  // if your upstream is official npm registry, please turn it off

@@ -841,6 +841,8 @@
Loading
841 841
842 842
  // get package AbbreviatedMetadata
843 843
  var remoteAbbreviatedMetadatas = {};
844 +
  // store remote abbreviated versions
845 +
  var remoteAbbreviatedVersionsMap = {};
844 846
  if (config.enableAbbreviatedMetadata) {
845 847
    // use ?cache=0 tell registry dont use cache result
846 848
    var packageUrl = '/' + name.replace('/', '%2f') + '?cache=0&sync_timestamp=' + Date.now();
@@ -860,9 +862,9 @@
Loading
860 862
          name, err, result.headers, result.data);
861 863
      }
862 864
      if (data) {
863 -
        var versions = data && data.versions || {};
864 -
        for (var version in versions) {
865 -
          const item = versions[version];
865 +
        remoteAbbreviatedVersionsMap = data && data.versions || {};
866 +
        for (var version in remoteAbbreviatedVersionsMap) {
867 +
          const item = remoteAbbreviatedVersionsMap[version];
866 868
          if (!item) {
867 869
            continue;
868 870
          }
@@ -874,7 +876,8 @@
Loading
874 876
            metaData._hasShrinkwrap = item._hasShrinkwrap;
875 877
          }
876 878
877 -
          const metaDataKeys = [ 'peerDependenciesMeta', 'os', 'cpu', 'workspaces' ];
879 +
          // https://github.com/cnpm/cnpmjs.org/issues/1667
880 +
          const metaDataKeys = [ 'peerDependenciesMeta', 'os', 'cpu', 'workspaces', 'hasInstallScript' ];
878 881
          for (const key of metaDataKeys) {
879 882
            if (key in item) {
880 883
              hasMetaData = true;
@@ -1079,8 +1082,8 @@
Loading
1079 1082
        if (abbreviatedMetadata) {
1080 1083
          for (var key in abbreviatedMetadata) {
1081 1084
            const value = abbreviatedMetadata[key];
1082 -
            // boolean: _hasShrinkwrap
1083 -
            if (key === '_hasShrinkwrap' && typeof value === 'boolean') {
1085 +
            // boolean: _hasShrinkwrap, hasInstallScript
1086 +
            if ((key === '_hasShrinkwrap' || key === 'hasInstallScript') && typeof value === 'boolean') {
1084 1087
              if (!(key in exists.package) || abbreviatedMetadata[key] !== exists.package[key]) {
1085 1088
                missingAbbreviatedMetadatas.push(Object.assign({
1086 1089
                  id: exists.id,
@@ -1171,7 +1174,7 @@
Loading
1171 1174
    var tries = 3;
1172 1175
    while (true) {
1173 1176
      try {
1174 -
        yield that._syncOneVersion(index, syncModule);
1177 +
        yield that._syncOneVersion(index, syncModule, remoteAbbreviatedVersionsMap[syncModule.version]);
1175 1178
        syncedVersionNames.push(syncModule.version);
1176 1179
        break;
1177 1180
      } catch (err) {
@@ -1322,7 +1325,7 @@
Loading
1322 1325
    that.log('  [%s] saving %d missing moduleAbbreviateds', name, missingModuleAbbreviateds.length);
1323 1326
1324 1327
    var res = yield gather(missingModuleAbbreviateds.map(function (item) {
1325 -
      return packageService.saveModuleAbbreviated(item);
1328 +
      return packageService.saveModuleAbbreviated(item, remoteAbbreviatedVersionsMap[item.version]);
1326 1329
    }));
1327 1330
1328 1331
    for (var i = 0; i < res.length; i++) {
@@ -1541,7 +1544,7 @@
Loading
1541 1544
  return syncedVersionNames;
1542 1545
};
1543 1546
1544 -
SyncModuleWorker.prototype._syncOneVersion = function *(versionIndex, sourcePackage) {
1547 +
SyncModuleWorker.prototype._syncOneVersion = function *(versionIndex, sourcePackage, remoteAbbreviatedVersion) {
1545 1548
  var delay = Date.now() - sourcePackage.publish_time;
1546 1549
  logger.syncInfo('[sync_module_worker] delay: %s ms, publish_time: %s, start sync %s@%s',
1547 1550
    delay, utility.logDate(new Date(sourcePackage.publish_time)),
@@ -1678,7 +1681,7 @@
Loading
1678 1681
      throw err;
1679 1682
    }
1680 1683
    logger.syncInfo('[sync_module_worker] uploaded, saving %j to database', result);
1681 -
    var r = yield afterUpload(result);
1684 +
    var r = yield afterUpload(result, remoteAbbreviatedVersion);
1682 1685
    logger.syncInfo('[sync_module_worker] sync %s@%s done!',
1683 1686
      sourcePackage.name, sourcePackage.version);
1684 1687
    return r;
@@ -1687,7 +1690,7 @@
Loading
1687 1690
    fs.unlink(filepath, utility.noop);
1688 1691
  }
1689 1692
1690 -
  function *afterUpload(result) {
1693 +
  function *afterUpload(result, remoteAbbreviatedVersion) {
1691 1694
    //make sure sync module have the correct author info
1692 1695
    //only if can not get maintainers, use the username
1693 1696
    var author = username;
@@ -1731,7 +1734,7 @@
Loading
1731 1734
    var r = yield packageService.saveModule(mod);
1732 1735
    var moduleAbbreviatedId = null;
1733 1736
    if (config.enableAbbreviatedMetadata) {
1734 -
      var moduleAbbreviatedResult = yield packageService.saveModuleAbbreviated(mod);
1737 +
      var moduleAbbreviatedResult = yield packageService.saveModuleAbbreviated(mod, remoteAbbreviatedVersion);
1735 1738
      moduleAbbreviatedId = moduleAbbreviatedResult.id;
1736 1739
    }
1737 1740
Files Coverage
common 66.67%
controllers 86.31%
middleware 94.34%
models 90.42%
routes 100.00%
servers 90.91%
services 90.86%
sync 89.61%
config/index.js 75.51%
lib/common.js 89.19%
Project Totals (97 files) 87.81%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading