chore(parameters): add package to release process #1377
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of your changes
This PR addresses the requirement of adding the new Parameters utility to the release process. This utility exports its components in a slightly different way than the other existing utilities and for this reason it requires an ad-hoc process for packaging.
Based on the current folder structure and configs, whenever a package is built (
npm run build
) the contents end up in a folder calledlib
that resides within the package folder (i.e.packages/parameters/lib
). After that, when runningnpm pack
as part of thenpm publish
command, the content of thelib
folder is package in a tarball and published to npm with a similar folder structure:As previously mentioned, the Parameters utility has a different way of exporting its internals. This is due to the fact that we want to allow users to selectively import a provider without having to import all others. So for instance, if a user wants to use the
SSMProvider
, their code should not also import theDynamoDBProvider
, which also brings in its own dependencies.To achieve this, instead of providing a main entry point at
@aws-lambda-powertools/parameters
(withindex.js
), we are providing more scoped imports like:@aws-lambda-powertools/parameters/ssm
@aws-lambda-powertools/parameters/appconfig
This type of imports is not compatible with the current folder structure. The current folder structure would allow to import packages with
@aws-lambda-powertools/parameters/lib/ssm
(**notice thelib
in the path).To instead allow cleaner imports that also don't expose our internal folder structure, we need to take two steps:
npm pack
command to point to thelib
folder instead of the package folderlib/package.json
file"main": "./lib/index.js"
->"main": "./index.js"
"types": "./lib/index.d.ts"
->"types": "./index.d.ts"
To do so, this PR introduces the following changes:
publishConfig.directory
field supported bylerna
that points to thelib
folderprepack
script to the package that patches thepackage.json
file inside thelib
folder.The script is added to the
.github/scripts
folder and temporarily copied on demand during theprepack
lifecycle event.Given that we now have a script that runs right before the package is packed, I took the liberty of introducing two additional optimizations/changes:
package.json
so that only the fields needed for npm are included (i.e. excludescripts
and other internal ones)-beta
suffix to both the package'spackage.json
file and the one insidelib
, so that the number is picked up during packaging and publishingNote that
lerna
already runsgit restore
at the end of the publishing process, so the patched version number is restored to a non beta one, which will allow the next versioning to increase the version normally. The version of the beta packages will be aligned with the GA packages, except for the presence of a-beta
suffix. So for instance, the release after this one, will likely be1.8.1-beta
,1.9.0-beta
etc., based on the semantic versioning of all the packages.The patching script is written in a way that can be reused for other packages. Once we release the next major version of all the utilities, we'll likely apply the same export flattening to all of them.
How to verify this change
I have verified this change by running a local npm registry (
verdaccio
) and running thelerna version
andlerna publish
commands, and then verified that the published artifact complies with the expected structure.Related issues, RFCs
Issue number: #1040
Checklist
Breaking change checklist
Is it a breaking change?: NO
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.