Skip to content

Commit ecd2fd6

Browse files
committed
Use external composer.json in base package
1 parent 6abed83 commit ecd2fd6

File tree

3 files changed

+55
-27
lines changed

3 files changed

+55
-27
lines changed

src/main.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const repo = require('./repository');
22
const {setArchiveBaseDir, createPackagesForTag, createPackageForTag} = require('./package-modules');
3-
const {compareTags} = require('./utils');
3+
const {compareTags, httpSlurp} = require('./utils');
44

55
/**
66
* package(s) | from | modules-folder | repo url
@@ -17,6 +17,7 @@ const {compareTags} = require('./utils');
1717
* ------------------------------------------------------------------------------------------------------------------
1818
* magento/zendframework1 | 1.13.0 | '' | https://github.com/mage-os/mirror-zf1.git
1919
* | | | single package, but requires exclude config
20+
* | | | version not in release composer.json files
2021
* ------------------------------------------------------------------------------------------------------------------
2122
*/
2223

@@ -37,38 +38,47 @@ async function createPackagesSinceTag(url, from, modulesPath, excludes) {
3738
return tags;
3839
}
3940

40-
async function createPackageSinceTag(url, from, modulesPath, excludes) {
41+
async function createPackageSinceTag(url, from, modulesPath, excludes, composerJsonUrl) {
4142
const tags = await listTagsFrom(url, from);
4243
for (const tag of tags) {
43-
await createPackageForTag(url, modulesPath, excludes, tag);
44+
await createPackageForTag(url, modulesPath, excludes, tag, composerJsonUrl.replace('{{version}}', tag));
4445
}
4546
return tags;
4647
}
4748

4849
(async function () {
49-
let tags;
50-
51-
tags = await createPackagesSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'app/code/Magento')
50+
let tags, exclude, composerJsonUrl;
51+
52+
exclude = [];
53+
tags = await createPackagesSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'app/code/Magento', exclude)
5254
console.log('app/code/Magento modules', tags)
5355

54-
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', '', [".github/", "app/code/", "app/design/frontend/", "app/design/adminhtml/", "app/i18n/", "lib/internal/Magento/Framework/", "composer.lock",])
55-
console.log('magento/magento2ce', tags);
56+
exclude = [".github/", "app/code/", "app/design/frontend/", "app/design/adminhtml/", "app/i18n/", "lib/internal/Magento/Framework/", "composer.lock"];
57+
composerJsonUrl = 'https://raw.githubusercontent.com/mage-os/magento2-base-composer-json/main/{{version}}/magento2-base/composer.json';
58+
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', '', exclude, composerJsonUrl)
59+
console.log('magento/magento2-base', tags)
5660

57-
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework', ['lib/internal/Magento/Framework/Amqp/', 'lib/internal/Magento/Framework/Bulk/', 'lib/internal/Magento/Framework/MessageQueue/'])
61+
exclude = ['lib/internal/Magento/Framework/Amqp/', 'lib/internal/Magento/Framework/Bulk/', 'lib/internal/Magento/Framework/MessageQueue/'];
62+
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework', exclude)
5863
console.log('magento/framework', tags)
5964

60-
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework/Amqp', [])
65+
exclude = [];
66+
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework/Amqp', exclude)
6167
console.log('magento/framework-amqp', tags)
6268

63-
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework/Bulk', [])
69+
exclude = [];
70+
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework/Bulk', exclude)
6471
console.log('magento/framework-bulk', tags);
6572

66-
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework/MessageQueue', [])
73+
exclude = [];
74+
tags = await createPackageSinceTag('https://github.com/mage-os/mirror-magento2.git', '2.4.0', 'lib/internal/Magento/Framework/MessageQueue', exclude)
6775
console.log('magento/framework-message-queue', tags)
6876

69-
tags = await createPackagesSinceTag('https://github.com/mage-os/mirror-security-package.git', '1.0.0', '', ['.github/', '_metapackage/'])
77+
exclude = ['.github/', '_metapackage/'];
78+
tags = await createPackagesSinceTag('https://github.com/mage-os/mirror-security-package.git', '1.0.0', '', exclude)
7079
console.log('security packages', tags)
7180

72-
tags = await createPackagesSinceTag('https://github.com/mage-os/mirror-inventory.git', '1.1.5', '', ['.github/', '_metapackage/', 'dev/'])
81+
exclude = ['.github/', '_metapackage/', 'dev/'];
82+
tags = await createPackagesSinceTag('https://github.com/mage-os/mirror-inventory.git', '1.1.5', '', exclude)
7383
console.log('inventory packages', tags)
74-
})()
84+
})()

src/package-modules.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require('fs');
22
const path = require('path');
33
const JSZip = require('jszip');
44
const repo = require("./repository");
5-
const {lastTwoDirs} = require('./utils');
5+
const {lastTwoDirs, httpSlurp} = require('./utils');
66

77
const cliProgress = require('cli-progress');
88
const multibar = new cliProgress.MultiBar({
@@ -58,8 +58,11 @@ function rtrim(str, c) {
5858
async function readComposerJson(url, dir, ref) {
5959
const file = ltrim(`${dir}/composer.json`, '/');
6060
return repo.readFile(url, file, ref)
61-
.then(b => Buffer.from(b).toString('utf8'))
62-
.then(JSON.parse);
61+
.then(b => Buffer.from(b).toString('utf8'));
62+
}
63+
64+
async function readComposerJsonUrl(url) {
65+
6366
}
6467

6568
function ensureArchiveDirectoryExists(archivePath) {
@@ -72,22 +75,23 @@ function archiveFilePath(name, version) {
7275
return path.join(prefix, archiveBaseDir, name + '-' + version + '.zip')
7376
}
7477

75-
async function createPackageForTag(url, moduleDir, excludes, ref) {
78+
async function createPackageForTag(url, moduleDir, excludes, ref, composerJsonUrl) {
7679

80+
excludes = excludes || [];
81+
excludes.push('composer.json');
7782
let magentoName = lastTwoDirs(moduleDir) || '';
7883

79-
const {version, name} = await readComposerJson(url, moduleDir, ref);
84+
const json = composerJsonUrl
85+
? await httpSlurp(composerJsonUrl)
86+
: await readComposerJson(url, moduleDir, ref);
87+
const {version, name} = JSON.parse(json);
8088
if (!version || !name) {
8189
console.error(`Unable find package name and/or version in composer.json for ${ref}, skipping ${magentoName}`);
8290
return;
8391
}
8492

85-
// use mtime of composer.json for all files and directories in package
86-
const mtime = await repo.lastCommitTimeForFile(url, ltrim(`${moduleDir}/composer.json`, '/'), ref);
87-
if (!mtime) {
88-
console.error(`Unable to find last commit affecting ${moduleDir}/composer.json in ${ref}, skipping ${magentoName||name}`);
89-
return;
90-
}
93+
// use fixed date for stable package checksum generation
94+
const mtime = new Date('2022-02-22 22:22:22');
9195

9296
const packageFilepath = archiveFilePath(name, version);
9397
if (fs.existsSync(packageFilepath)) {
@@ -101,12 +105,13 @@ async function createPackageForTag(url, moduleDir, excludes, ref) {
101105
})
102106
return ! isExcluded;
103107
})
104-
.sort()
105108
.map(file => {
106109
file.mtime = mtime;
107110
file.filepath = file.filepath.substr(moduleDir ? moduleDir.length + 1 : '');
108111
return file;
109112
});
113+
files.push({filepath: 'composer.json', contentBuffer: Buffer.from(json, 'utf8'), mtime, isExecutable: false});
114+
files.sort((a, b) => ('' + a.filepath).localeCompare('' + b.filepath));
110115

111116
ensureArchiveDirectoryExists(packageFilepath);
112117
const zip = zipFileWith(files);

src/utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const compareVersions = require("compare-versions");
2+
const http = require('https');
3+
const {URL} = require('url');
24

35
module.exports = {
46
/**
@@ -33,5 +35,16 @@ module.exports = {
3335
return -1; // only b has a patch version, so b is larger
3436
}
3537
return 0; // same base and patch versions
38+
},
39+
async httpSlurp(url) {
40+
return new Promise((resolve, reject) => {
41+
const request = http.request(new URL(url), function (res) {
42+
let data = '';
43+
res.on('data', chunk => data += chunk);
44+
res.on('end', () => resolve(data));
45+
});
46+
request.on('error', err => reject(e.message));
47+
request.end();
48+
});
3649
}
3750
}

0 commit comments

Comments
 (0)