From 1432e139bf4ff870c3263f7d558de88c9453b8be Mon Sep 17 00:00:00 2001 From: reggi Date: Wed, 22 Jan 2025 15:46:05 -0500 Subject: [PATCH 01/10] chore: stop publish smoke from check git clean --- scripts/publish.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/publish.js b/scripts/publish.js index 0a6ac1340a130..ab231c5d5ee66 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -146,4 +146,4 @@ const main = async (opts) => { } } -run(main).catch(resetdeps) +run(main) From a2069ed9e496be6f4135ccf06b1c9217c2d15af6 Mon Sep 17 00:00:00 2001 From: reggi Date: Wed, 22 Jan 2025 17:14:48 -0500 Subject: [PATCH 02/10] chore: fix publish.js --- scripts/publish.js | 43 ++++++++++++++++++++++++----------- scripts/smoke-publish-test.sh | 2 +- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/scripts/publish.js b/scripts/publish.js index ab231c5d5ee66..d23b653e45c4e 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -72,9 +72,10 @@ const getPublishes = async ({ force }) => { } const main = async (opts) => { - const { isLocal, smokePublish, packDestination } = opts - const isPack = !!packDestination - const publishes = await getPublishes({ force: isPack }) + const { smokePublish, packDestination } = opts + + const hasPackDest = !!packDestination + const publishes = await getPublishes({ force: smokePublish }) if (!publishes.length) { throw new Error( @@ -88,13 +89,15 @@ const main = async (opts) => { table.push([publish.name, publish.version, publish.tag]) } + const preformOperations = hasPackDest ? ['publish', 'pack'] : ['publish'] + const confirmMessage = [ - `Ready to ${isPack ? 'pack' : 'publish'} the following packages:`, + `Ready to ${preformOperations.join(',')} the following packages:`, table.toString(), - isPack ? null : 'Ok to proceed? ', + smokePublish ? null : 'Ok to proceed? ', ].filter(Boolean).join('\n') - if (isPack) { + if (smokePublish) { log.info(confirmMessage) } else { const confirm = await read({ prompt: confirmMessage, default: 'y' }) @@ -117,7 +120,8 @@ const main = async (opts) => { await npm('prune', '--omit=dev', '--no-save', '--no-audit', '--no-fund') await npm('install', '-w', 'docs', '--ignore-scripts', '--no-audit', '--no-fund') - if (isLocal && smokePublish) { + + if (smokePublish) { log.info(`Skipping git dirty check due to local smoke publish test being run`) } else { await git.dirty() @@ -127,16 +131,18 @@ const main = async (opts) => { const workspace = publish.workspace && `--workspace=${publish.name}` const publishPkg = (...args) => npm('publish', workspace, `--tag=${publish.tag}`, ...args) - await npm('version', 'prerelease', workspace, '--preid=smoke') - if (isPack) { + if (hasPackDest) { await npm( 'pack', workspace, opts.packDestination && `--pack-destination=${opts.packDestination}` ) - if (smokePublish) { - await publishPkg('--dry-run') - } + } + + if (smokePublish) { + // when we have a smoke test run we'd want to bump the version or else npm will throw an error even with dry-run + await npm('version', 'prerelease', workspace, '--preid=smoke') + await publishPkg('--dry-run') } else { await publishPkg( opts.dryRun && '--dry-run', @@ -146,4 +152,15 @@ const main = async (opts) => { } } -run(main) +const caughtMain = async (opts) => { + const { smokePublish } = opts + try { + await main(opts) + } catch (err) { + if (!smokePublish) { + await resetdeps() + } + } +} + +run(caughtMain) diff --git a/scripts/smoke-publish-test.sh b/scripts/smoke-publish-test.sh index 1d08a0adf2bc8..5de4f32931cf7 100755 --- a/scripts/smoke-publish-test.sh +++ b/scripts/smoke-publish-test.sh @@ -66,7 +66,7 @@ fi # were publishing it to the registry. The only difference is in the # publish.js script which will only pack and not publish node . version $NPM_VERSION --ignore-scripts --git-tag-version="$IS_CI" -node scripts/publish.js --pack-destination=$RUNNER_TEMP --smoke-publish=true --is-local="$IS_LOCAL" +node scripts/publish.js --pack-destination=$RUNNER_TEMP --smoke-publish=true NPM_TARBALL="$RUNNER_TEMP/npm-$NPM_VERSION.tgz" node . install --global $NPM_TARBALL From 8b9e76589ffa3d83cc17a0ee97de43f828dddf91 Mon Sep 17 00:00:00 2001 From: reggi Date: Wed, 22 Jan 2025 17:47:35 -0500 Subject: [PATCH 03/10] clean --- scripts/publish.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/scripts/publish.js b/scripts/publish.js index d23b653e45c4e..b055d3a49cad5 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -71,8 +71,17 @@ const getPublishes = async ({ force }) => { return publishPackages } +const getVersion = async (workspace) => { + const value = await npm('pkg', 'get', 'version', workspace, { out: true }) + return Object.values(JSON.parse(value))[0] +} + +const setVersion = async (workspace, version) => { + await npm('pkg', 'set', `version=${version}`, workspace) +} + const main = async (opts) => { - const { smokePublish, packDestination } = opts + const { otp, dryRun, smokePublish, packDestination } = opts const hasPackDest = !!packDestination const publishes = await getPublishes({ force: smokePublish }) @@ -135,21 +144,27 @@ const main = async (opts) => { await npm( 'pack', workspace, - opts.packDestination && `--pack-destination=${opts.packDestination}` + packDestination && `--pack-destination=${packDestination}` ) } if (smokePublish) { // when we have a smoke test run we'd want to bump the version or else npm will throw an error even with dry-run + const version = await getVersion(workspace) await npm('version', 'prerelease', workspace, '--preid=smoke') await publishPkg('--dry-run') + await setVersion(workspace, version) } else { await publishPkg( - opts.dryRun && '--dry-run', - opts.otp && `--otp=${opts.otp === 'op' ? await op() : opts.otp}` + dryRun && '--dry-run', + otp && `--otp=${otp === 'op' ? await op() : otp}` ) } } + + // this is done to make sure package-lock.json is in a good state + await npm('prune', '--omit=dev', '--no-save', '--no-audit', '--no-fund') + await npm('install', '-w', 'docs', '--ignore-scripts', '--no-audit', '--no-fund') } const caughtMain = async (opts) => { From 69fed255f6909791890f30de3562bfbb47f3f30a Mon Sep 17 00:00:00 2001 From: reggi Date: Wed, 22 Jan 2025 17:51:08 -0500 Subject: [PATCH 04/10] add log --- scripts/publish.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/publish.js b/scripts/publish.js index b055d3a49cad5..87cf13d801058 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -136,7 +136,9 @@ const main = async (opts) => { await git.dirty() } + let count = -1 for (const publish of publishes) { + log.info(`Publishing ${publish.name}@${publish.version} to ${publish.tag} ${count++}/${publishes.length}`) const workspace = publish.workspace && `--workspace=${publish.name}` const publishPkg = (...args) => npm('publish', workspace, `--tag=${publish.tag}`, ...args) From b20f06dedc7aad8736e02b86a7920316d7d2626d Mon Sep 17 00:00:00 2001 From: reggi Date: Fri, 24 Jan 2025 11:04:39 -0500 Subject: [PATCH 05/10] stash changes --- scripts/publish.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/scripts/publish.js b/scripts/publish.js index 87cf13d801058..944cd8a1a3218 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -153,9 +153,11 @@ const main = async (opts) => { if (smokePublish) { // when we have a smoke test run we'd want to bump the version or else npm will throw an error even with dry-run const version = await getVersion(workspace) - await npm('version', 'prerelease', workspace, '--preid=smoke') - await publishPkg('--dry-run') + await npm('version', 'prerelease', workspace, '--preid=smoke', '--ignore-scripts') + await publishPkg('--dry-run', '--ignore-scripts') await setVersion(workspace, version) + // undo the package lock changes + await npm('install', '--ignore-scripts', '--no-audit', '--no-fund') } else { await publishPkg( dryRun && '--dry-run', @@ -169,15 +171,17 @@ const main = async (opts) => { await npm('install', '-w', 'docs', '--ignore-scripts', '--no-audit', '--no-fund') } -const caughtMain = async (opts) => { - const { smokePublish } = opts - try { - await main(opts) - } catch (err) { - if (!smokePublish) { - await resetdeps() - } - } -} +run(main) + +// const caughtMain = async (opts) => { +// const { smokePublish } = opts +// try { +// await main(opts) +// } catch (err) { +// if (!smokePublish) { +// await resetdeps() +// } +// } +// } -run(caughtMain) +// run(caughtMain) From 32dcbe387b3fba0a4184bb1b7a9f72d767dba08d Mon Sep 17 00:00:00 2001 From: reggi Date: Fri, 24 Jan 2025 11:06:26 -0500 Subject: [PATCH 06/10] 11.0.1-smoke.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4d73307305e2d..35bed6a8e6fe7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "npm", - "version": "11.0.0", + "version": "11.0.1-smoke.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "npm", - "version": "11.0.0", + "version": "11.0.1-smoke.0", "bundleDependencies": [ "@isaacs/string-locale-compare", "@npmcli/arborist", diff --git a/package.json b/package.json index 8b5e9744ab765..228eab33dddea 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "11.0.0", + "version": "11.0.1-smoke.0", "name": "npm", "description": "a package manager for JavaScript", "workspaces": [ From 882f7251b36cf3e1fbe32d14aad02f3aa33b8baf Mon Sep 17 00:00:00 2001 From: reggi Date: Fri, 24 Jan 2025 11:14:30 -0500 Subject: [PATCH 07/10] undo --- package.json | 2 +- scripts/publish.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 228eab33dddea..8b5e9744ab765 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "11.0.1-smoke.0", + "version": "11.0.0", "name": "npm", "description": "a package manager for JavaScript", "workspaces": [ diff --git a/scripts/publish.js b/scripts/publish.js index 944cd8a1a3218..d4e343fb9a5f1 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -153,11 +153,9 @@ const main = async (opts) => { if (smokePublish) { // when we have a smoke test run we'd want to bump the version or else npm will throw an error even with dry-run const version = await getVersion(workspace) - await npm('version', 'prerelease', workspace, '--preid=smoke', '--ignore-scripts') + await npm('version', 'prerelease', workspace, '--preid=smoke', '--ignore-scripts', '--no-git-tag-version') await publishPkg('--dry-run', '--ignore-scripts') await setVersion(workspace, version) - // undo the package lock changes - await npm('install', '--ignore-scripts', '--no-audit', '--no-fund') } else { await publishPkg( dryRun && '--dry-run', From 4046e9ce0d3ec943b490a0c25ee2330b735fd21e Mon Sep 17 00:00:00 2001 From: reggi Date: Fri, 24 Jan 2025 11:15:34 -0500 Subject: [PATCH 08/10] undo --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 35bed6a8e6fe7..4d73307305e2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "npm", - "version": "11.0.1-smoke.0", + "version": "11.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "npm", - "version": "11.0.1-smoke.0", + "version": "11.0.0", "bundleDependencies": [ "@isaacs/string-locale-compare", "@npmcli/arborist", From 45f021aecaae3a0c38ca66a75d113239a269859a Mon Sep 17 00:00:00 2001 From: reggi Date: Fri, 24 Jan 2025 11:50:53 -0500 Subject: [PATCH 09/10] fix --- scripts/publish.js | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/scripts/publish.js b/scripts/publish.js index d4e343fb9a5f1..7aed7ae55d880 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -71,17 +71,8 @@ const getPublishes = async ({ force }) => { return publishPackages } -const getVersion = async (workspace) => { - const value = await npm('pkg', 'get', 'version', workspace, { out: true }) - return Object.values(JSON.parse(value))[0] -} - -const setVersion = async (workspace, version) => { - await npm('pkg', 'set', `version=${version}`, workspace) -} - const main = async (opts) => { - const { otp, dryRun, smokePublish, packDestination } = opts + const { test, otp, dryRun, smokePublish, packDestination } = opts const hasPackDest = !!packDestination const publishes = await getPublishes({ force: smokePublish }) @@ -121,7 +112,7 @@ const main = async (opts) => { await npm('rm', '--global', '--force', 'npm') await npm('link', '--force', '--ignore-scripts') - if (opts.test) { + if (test) { await npm('run', 'lint-all', '--ignore-scripts') await npm('run', 'postlint', '--ignore-scripts') await npm('run', 'test-all', '--ignore-scripts') @@ -152,10 +143,8 @@ const main = async (opts) => { if (smokePublish) { // when we have a smoke test run we'd want to bump the version or else npm will throw an error even with dry-run - const version = await getVersion(workspace) await npm('version', 'prerelease', workspace, '--preid=smoke', '--ignore-scripts', '--no-git-tag-version') await publishPkg('--dry-run', '--ignore-scripts') - await setVersion(workspace, version) } else { await publishPkg( dryRun && '--dry-run', @@ -163,23 +152,6 @@ const main = async (opts) => { ) } } - - // this is done to make sure package-lock.json is in a good state - await npm('prune', '--omit=dev', '--no-save', '--no-audit', '--no-fund') - await npm('install', '-w', 'docs', '--ignore-scripts', '--no-audit', '--no-fund') } -run(main) - -// const caughtMain = async (opts) => { -// const { smokePublish } = opts -// try { -// await main(opts) -// } catch (err) { -// if (!smokePublish) { -// await resetdeps() -// } -// } -// } - -// run(caughtMain) +run(main).then(resetdeps) From e217c2335ce29313b5056750ea063ac299188711 Mon Sep 17 00:00:00 2001 From: reggi Date: Fri, 24 Jan 2025 11:53:59 -0500 Subject: [PATCH 10/10] catch not then --- scripts/publish.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/publish.js b/scripts/publish.js index 7aed7ae55d880..5b5a38579a42d 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -154,4 +154,4 @@ const main = async (opts) => { } } -run(main).then(resetdeps) +run(main).catch(resetdeps)