refactor: Convert shrinkwrap extractor tool to package-lock - #1551
refactor: Convert shrinkwrap extractor tool to package-lock#1551d3xter666 wants to merge 11 commits into
Conversation
ab9b808 to
96c7db8
Compare
| @@ -0,0 +1,340 @@ | |||
| import {readFile, mkdtemp, writeFile, rm} from "node:fs/promises"; | |||
There was a problem hiding this comment.
This file is actually renamed internal/shrinkwrap-extractor/lib/convertPackageLockToShrinkwrap.js. I don't know why GitHub splits them this way
96c7db8 to
3ca822d
Compare
252206e to
9d8b208
Compare
| # Strip devDependencies so npm ci only installs production deps matching the lock file | ||
| node -e " | ||
| const fs = require('fs'); | ||
| const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); | ||
| delete pkg.devDependencies; | ||
| fs.writeFileSync('package.json', JSON.stringify(pkg, null, '\t')); | ||
| " |
There was a problem hiding this comment.
We need this explicit devDependencies strip since the lockfile-extractor provides only the prod dependencies. Any npm ci (even npm ci --omit=dev) call wil fail if we don't do this.
|
I assume we will still need #1228? Since the renaming will likely cause some conflicts, which one would you like to get in first? |
7e72929 to
d4b3b7b
Compare
| @@ -0,0 +1,85 @@ | |||
| name: Bundle and Publish @ui5/cli | |||
There was a problem hiding this comment.
This is an actual copy of shrinkwrap/lockfile-extractor run + package deployment to NPM from release-please.yaml
Now it has a dry run flag, so we can integrate this flow into our current CI environment. This way, we can ensure that every merge in the main branch won't break the release process.
854d15f to
5bbcf74
Compare
RandomByte
left a comment
There was a problem hiding this comment.
I'm still think we might not handle all cases of dependency hoisting correctly, as the added test in #1569 was supposed to show. At the same time, I don't see how this process would catch such problems. Therefore I'm hesitant to approve this without any planned follow-up work to address those concerns.
npm ci will install packages as specified in the generated package-lock.json. I believe it does not validate whether hoisted dependencies match with the nested project's requirements (i.e. whether the hoisted dependency's version matches the specified range).
For npm publish I believe that it would pack whatever is provided in node_modules, again without further validation whether that matches with the dependency's requirements.
I might be wrong on both points here, and I would appreciate to get some well founded reassurance if that is the case. Otherwise I fear that the package-lock.json we "extract" would silently lead to incorrect dependency versions getting installed. Note that this can not be tested at runtime. Only by validating the dependency tree.
a4874fb to
0f1d300
Compare
Migrates from the deprecated npm-shrinkwrap.json (npm/cli#9262) to bundleDependencies: true. The lockfile-extractor now generates a standalone package-lock.json; the package is then copied outside the workspace, installed via npm ci, and packed via npm pack to bundle all production node_modules.
Co-authored-by: Merlin Beutlberger <m.beutlberger@sap.com>
Co-authored-by: Merlin Beutlberger <m.beutlberger@sap.com>
This license file has been left here by accident. We now manage those licenses centrally
The LICENSES/Apache-2.0.txt file is required per-package: the REUSE compliance workflow runs with --root <package> lint, so each package needs its own LICENSES/ directory. Restores the file that was incorrectly removed.
d480b7d to
aaff26a
Compare
|
After rebasing this PR onto This is the dependency-hoisting edge case addressed by #1569. I have also prepared a48a15e that gives direct dependencies of the new root package priority in the root |
JIRA: CPOUI5FOUNDATION-1283
Shrinkwrap is being deprecated (npm/cli#9262) in node, but we want to keep and guard the dependencies that we ship with the
UI5 CLI.We have decided to go with NPM's packge.json
bundeDependenciespropertybundleDependencieshas its own issues when working with monorepos. The core issue is that it simply bundles anything that's within that package'snode_modules/folder and does not consider any hoisted packages that monorepos naturally have.With this context in mind, we have decided to leverage our internal tool
shrinkwrap-extractorand adjust it to fit for thebundleDependenciescase.Here's the expected workflow:
shrinkwrap-extractorto something more meaningful in the new context. Proposal:lockfile-extractorlockfile-extractorforpackages/cli. This will result inpackage-lock.jsonfile extraction suitable just for the@ui5/clipackage.packages/cliout of the scope of the monorepo by copying its files in a $TEMP dir.devDependencies) frompackage.jsonnpm ci, so that dependencies are installed with the exact same versions that are defined within the generated earlierpackage-lock.jsonnpm packandnpm publish, so that the generated tarball taht includes also thebundledependenciesgets published on NPMNote: This PR simply renames the shrinkwrap-extractor to lockfile-extractor. The only real change is the handling of publish GH Action: https://github.com/UI5/cli/pull/1551/changes#diff-2c84033033d49186c63e6adcd705f63b11ae6814cd76c152c9c486d389fbccf3