Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jan 8, 2023
1 parent 3e99b90 commit 7147bc1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
11 changes: 8 additions & 3 deletions app/core/service/PackageManagerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,14 @@ export class PackageManagerService extends AbstractService {
delete cmd.packageJson.readme;
}

const publishTime = cmd.publishTime || new Date();

// add _cnpmcore_publish_time field to cmd.packageJson
if (!cmd.packageJson._cnpmcore_publish_time) {
cmd.packageJson._cnpmcore_publish_time = new Date();
cmd.packageJson._cnpmcore_publish_time = publishTime;
}
if (!cmd.packageJson.publish_time) {
cmd.packageJson.publish_time = publishTime.getTime();
}

// https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md#abbreviated-version-object
Expand Down Expand Up @@ -189,7 +194,7 @@ export class PackageManagerService extends AbstractService {
hasInstallScript,
// https://github.com/cnpm/npminstall/blob/13efc7eec21a61e509226e3772bfb75cd5605612/lib/install_package.js#L176
// npminstall require publish time to show the recently update versions
_cnpmcore_publish_time: cmd.packageJson._cnpmcore_publish_time,
publish_time: cmd.packageJson.publish_time,
});
const abbreviatedDistBytes = Buffer.from(abbreviated);
const abbreviatedDistIntegrity = await calculateIntegrity(abbreviatedDistBytes);
Expand All @@ -201,7 +206,7 @@ export class PackageManagerService extends AbstractService {
pkgVersion = PackageVersion.create({
packageId: pkg.packageId,
version: cmd.version,
publishTime: cmd.publishTime || new Date(),
publishTime,
manifestDist: pkg.createManifest(cmd.version, {
size: manifestDistBytes.length,
shasum: manifestDistIntegrity.shasum,
Expand Down
18 changes: 13 additions & 5 deletions test/port/controller/package/ShowPackageController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => {
const versionOne = pkg.versions['1.0.0'];
assert.equal(versionOne.dist.unpackedSize, 6497043);
assert(versionOne._cnpmcore_publish_time);
assert(versionOne.publish_time);
assert.equal(pkg._id, name);
assert(pkg._rev);
assert(versionOne._id);
Expand Down Expand Up @@ -214,6 +215,9 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => {
const versionOne = pkg.versions['1.0.0'];
assert(versionOne.dist.unpackedSize === 6497043);
assert(versionOne._cnpmcore_publish_time);
assert.equal(typeof versionOne._cnpmcore_publish_time, 'string');
assert(versionOne.publish_time);
assert.equal(typeof versionOne.publish_time, 'number');
assert(pkg._id === scopedName);
assert(pkg._rev);
assert(versionOne._id);
Expand Down Expand Up @@ -257,9 +261,9 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => {
// console.log(JSON.stringify(pkg, null, 2));
const versionOne = pkg.versions['2.0.0'];
assert.equal(versionOne.dist.unpackedSize, 6497043);
console.log('%o', versionOne);
assert(versionOne._cnpmcore_publish_time);
assert.equal(typeof versionOne._cnpmcore_publish_time, 'string');
assert(!versionOne._cnpmcore_publish_time);
assert(versionOne.publish_time);
assert.equal(typeof versionOne.publish_time, 'number');
assert(!pkg._rev);
assert(!pkg._id);
assert(!versionOne._id);
Expand Down Expand Up @@ -326,7 +330,9 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => {
// console.log(JSON.stringify(pkg, null, 2));
const versionOne = pkg.versions['2.0.0'];
assert.equal(versionOne.dist.unpackedSize, 6497043);
assert(versionOne._cnpmcore_publish_time);
assert(!versionOne._cnpmcore_publish_time);
assert(versionOne.publish_time);
assert.equal(typeof versionOne.publish_time, 'number');
assert(!pkg._rev);
assert(!pkg._id);
assert(!versionOne._id);
Expand All @@ -348,7 +354,9 @@ describe('test/port/controller/package/ShowPackageController.test.ts', () => {
// console.log(JSON.stringify(pkg, null, 2));
const versionOne = pkg.versions['2.0.0'];
assert(versionOne.dist.unpackedSize === 6497043);
assert(versionOne._cnpmcore_publish_time);
assert(!versionOne._cnpmcore_publish_time);
assert(versionOne.publish_time);
assert.equal(typeof versionOne.publish_time, 'number');
assert(!pkg._rev);
assert(!pkg._id);
assert(!versionOne._id);
Expand Down

0 comments on commit 7147bc1

Please sign in to comment.