Skip to content

Commit 1bf76ff

Browse files
committed
Fix packages with pre-release versions showing as outdated
1 parent ca3c2da commit 1bf76ff

2 files changed

Lines changed: 98 additions & 111 deletions

File tree

gulpfile.mjs

Lines changed: 83 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const libraries = getLibraries();
2424
*
2525
* @returns {Promise} A Promise which resolves when the folder is deleted
2626
*/
27-
function clean() {
28-
return deleteAsync('./_InstallPackages/');
27+
async function clean() {
28+
return await deleteAsync('./_InstallPackages/');
2929
}
3030

3131
/**
@@ -98,29 +98,22 @@ const defaultTask = gulp.series(
9898
*
9999
* @returns {Promise} A promise which resolves when the outdated table is complete
100100
*/
101-
function outdated() {
102-
const allUpgradesPromises = libraries.map((library) =>
103-
getUpgradeVersions(library).then((upgrades) =>
104-
Object.assign(library, { upgrades })
105-
)
106-
);
107-
108-
return Promise.all(allUpgradesPromises).then((allUpgrades) => {
109-
const validUpgrades = allUpgrades
110-
.filter(({ upgrades }) => upgrades.size > 0)
111-
.sort(({ name: a }, { name: b }) => compareStrings(a, b));
112-
113-
if (validUpgrades.length === 0) {
114-
log.warn(
115-
`All ${chalk.yellow(allUpgrades.length)} packages up-to-date`
116-
);
117-
118-
return;
119-
}
101+
async function outdated() {
102+
const allUpgradesPromises = libraries.map(async (library) => {
103+
const upgrades = await getUpgradeVersions(library);
104+
return Object.assign(library, { upgrades });
105+
});
120106

121-
log.info(`
107+
const allUpgrades = await Promise.all(allUpgradesPromises);
108+
const validUpgrades = allUpgrades
109+
.filter(({ upgrades }) => upgrades.size > 0)
110+
.sort(({ name: a }, { name: b }) => compareStrings(a, b));
111+
if (validUpgrades.length === 0) {
112+
log.warn(`All ${chalk.yellow(allUpgrades.length)} packages up-to-date`);
113+
return;
114+
}
115+
log.info(`
122116
${formatPackageUpgrades(validUpgrades)}`);
123-
});
124117
}
125118

126119
/**
@@ -130,89 +123,83 @@ ${formatPackageUpgrades(validUpgrades)}`);
130123
* @returns {Task} A Gulp task function
131124
*/
132125
function makeUpgradeTask(upgradeType) {
133-
const upgradeFn = () => {
126+
const upgradeFn = async () => {
134127
const allUpgradesPromises = libraries.map((library) =>
135128
getUpgradeVersions(library).then((upgrades) =>
136129
Object.assign(library, { upgrades })
137130
)
138131
);
139132

140-
return Promise.all(allUpgradesPromises).then((allUpgrades) => {
141-
const validUpgrades = allUpgrades.filter(({ upgrades }) =>
142-
upgrades.get(upgradeType)
143-
);
144-
145-
if (validUpgrades.length === 0) {
146-
log.warn(`No ${upgradeType} upgrades to process`);
133+
const allUpgrades = await Promise.all(allUpgradesPromises);
134+
const validUpgrades = allUpgrades.filter(({ upgrades: upgrades_1 }) =>
135+
upgrades_1.get(upgradeType)
136+
);
137+
if (validUpgrades.length === 0) {
138+
log.warn(`No ${upgradeType} upgrades to process`);
147139

148-
return;
149-
}
140+
return;
141+
}
142+
const upgradeWarnings = validUpgrades.map(
143+
({ name, version, upgrades: upgrades_2, manifest }) => {
144+
const newVersion = upgrades_2.get(upgradeType);
145+
log(
146+
`Upgrading ${chalk.magenta(name)} from ${chalk.yellow(
147+
version
148+
)} to ${chalk.yellow(newVersion)}`
149+
);
150150

151-
const upgradeWarnings = validUpgrades.map(
152-
({ name, version, upgrades, manifest }) => {
153-
const newVersion = upgrades.get(upgradeType);
154-
log(
155-
`Upgrading ${chalk.magenta(name)} from ${chalk.yellow(
156-
version
157-
)} to ${chalk.yellow(newVersion)}`
158-
);
159-
160-
spawn.sync(
161-
'yarn',
162-
[
163-
'upgrade',
164-
'--exact',
165-
'--non-interactive',
166-
`${name}@${newVersion}`,
167-
],
168-
{
169-
stdio: 'inherit',
170-
}
171-
);
172-
spawn.sync(
173-
'git',
174-
[
175-
'commit',
176-
'--all',
177-
'--message',
178-
`Upgrade ${name} to ${newVersion} (from ${version})`,
179-
],
180-
{ stdio: 'inherit' }
181-
);
182-
spawn.sync(
183-
'git',
184-
[
185-
'tag',
186-
'--message',
187-
`Automatic ${upgradeType} upgrade of ${name} to ${newVersion} (from ${version})`,
188-
`${name}_${newVersion}`,
189-
],
190-
{ stdio: 'inherit' }
191-
);
192-
193-
const fileGlobs = manifest.files.concat(
194-
manifest.resources || []
195-
);
196-
const hasExtraFiles = fileGlobs.some(
197-
(f) => f[0] !== '!' && !f.startsWith('node_modules')
198-
);
199-
200-
return hasExtraFiles ? name : null;
201-
}
202-
);
151+
spawn.sync(
152+
'yarn',
153+
[
154+
'upgrade',
155+
'--exact',
156+
'--non-interactive',
157+
`${name}@${newVersion}`,
158+
],
159+
{
160+
stdio: 'inherit',
161+
}
162+
);
163+
spawn.sync(
164+
'git',
165+
[
166+
'commit',
167+
'--all',
168+
'--message',
169+
`Upgrade ${name} to ${newVersion} (from ${version})`,
170+
],
171+
{ stdio: 'inherit' }
172+
);
173+
spawn.sync(
174+
'git',
175+
[
176+
'tag',
177+
'--message',
178+
`Automatic ${upgradeType} upgrade of ${name} to ${newVersion} (from ${version})`,
179+
`${name}_${newVersion}`,
180+
],
181+
{ stdio: 'inherit' }
182+
);
203183

204-
upgradeWarnings
205-
.filter((libraryName) => libraryName !== null)
206-
.forEach((libraryName) =>
207-
log.warn(
208-
`The library ${chalk.magenta(
209-
libraryName
210-
)} has some resources that do not come from ${chalk.gray(
211-
'node_modules'
212-
)}, please verify that the upgrade was complete`
213-
)
184+
const fileGlobs = manifest.files.concat(
185+
manifest.resources || []
214186
);
215-
});
187+
const hasExtraFiles = fileGlobs.some(
188+
(f) => f[0] !== '!' && !f.startsWith('node_modules')
189+
);
190+
191+
return hasExtraFiles ? name : null;
192+
}
193+
);
194+
upgradeWarnings
195+
.filter((libraryName) => libraryName !== null)
196+
.forEach((libraryName_1) =>
197+
log.warn(
198+
`The library ${chalk.magenta(libraryName_1)} has some resources that do not come from ${chalk.gray(
199+
'node_modules'
200+
)}, please verify that the upgrade was complete`
201+
)
202+
);
216203
};
217204

218205
upgradeFn.displayName = `Apply ${upgradeType} upgrades`;

utility/packages.mjs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ export function getLibraries() {
6262
* @param {object} library - A library object
6363
* @returns {Promise} A Promise which returns a Map with available version upgrades
6464
*/
65-
export function getUpgradeVersions(library) {
66-
return packageJson(library.name, {
65+
export async function getUpgradeVersions(library) {
66+
const { versions } = await packageJson(library.name, {
6767
allVersions: true,
68-
}).then(({ versions }) =>
69-
Object.keys(versions)
70-
.filter((version) => semver.gt(version, library.version))
71-
.sort(semver.compare)
72-
.reduce(
73-
(upgrades, version) =>
74-
upgrades.set(
75-
semver.diff(version, library.version),
76-
version
77-
),
78-
new Map()
79-
)
80-
);
68+
});
69+
return Object.keys(versions)
70+
.filter(
71+
(version) =>
72+
semver.gt(version, library.version) &&
73+
semver.prerelease(version) === null
74+
)
75+
.sort(semver.compare)
76+
.reduce(
77+
(upgrades, version) =>
78+
upgrades.set(semver.diff(version, library.version), version),
79+
new Map()
80+
);
8181
}

0 commit comments

Comments
 (0)