From 4d9ed298d98589c3f84bc48e9ba19350f5e42ad6 Mon Sep 17 00:00:00 2001 From: laxmanpokhrel Date: Mon, 26 Feb 2024 17:15:14 +0545 Subject: [PATCH] fix: project type module --- .github/scripts/release.sh | 39 +++++++++++++++++++++++----------- .github/workflows/release.yaml | 10 +++++---- .gitignore | 3 ++- .release/config.json | 3 ++- .release/release-notes.md | 2 -- .release/release-notes.txt | 1 + package.json | 13 ++++++------ tsconfig.json | 3 ++- 8 files changed, 47 insertions(+), 27 deletions(-) delete mode 100644 .release/release-notes.md create mode 100644 .release/release-notes.txt diff --git a/.github/scripts/release.sh b/.github/scripts/release.sh index 1e9329f..5125474 100644 --- a/.github/scripts/release.sh +++ b/.github/scripts/release.sh @@ -7,7 +7,8 @@ echo "==========================================================" # Declerations RELEASE_CONFIG_FILE=null -RELEASE_TYPE=null +VERSION_UPGRADE_TYPE=null +RELEASE_TYPE='' TAG=null PACKAGEJSON=$(cat package.json) @@ -30,15 +31,27 @@ fi # Check if release config file has `versionUpgradeType` echo "- reading 'versionUpgradeType'" if [ "$(echo "$RELEASE_CONFIG_FILE" | jq -r ".versionUpgradeType")" != "null" ]; then - RELEASE_TYPE=$(echo "$RELEASE_CONFIG_FILE" | jq -r ".versionUpgradeType") - echo "- 'versionUpgradeType': $RELEASE_TYPE" + VERSION_UPGRADE_TYPE=$(echo "$RELEASE_CONFIG_FILE" | jq -r ".versionUpgradeType") + echo "- 'versionUpgradeType': $VERSION_UPGRADE_TYPE" else - RELEASE_TYPE=null + VERSION_UPGRADE_TYPE=null echo "- no 'versionUpgradeType' provided" echo "- abort" exit 1 fi +# Check if release config file has `releaseType` +echo "- reading 'releaseType'" +if [ "$(echo "$RELEASE_CONFIG_FILE" | jq -r ".releaseType")" != "null" ]; then + RELEASE_TYPE=$(echo "$RELEASE_CONFIG_FILE" | jq -r ".releaseType") + echo "- 'releaseType': $RELEASE_TYPE" +else + RELEASE_TYPE='' + echo "- no 'releaseType' provided" + # echo "- abort" + # exit 1 +fi + # Check if npm view command succeeded or failed echo "- reading package version from npm" PACKAGE_NPM_VERSION=$(npm view $PACKAGE_NAME version 2>/dev/null) @@ -54,7 +67,7 @@ else FINAL_RELEASE_VERSION=$PACKAGE_VERSION fi -# Function to update version based on RELEASE_TYPE +# Function to update version based on VERSION_UPGRADE_TYPE update_version() { local current_version=$1 local release_type=$2 @@ -84,14 +97,14 @@ update_version() { if [ "$PACKAGE_NPM_VERSION" == "null" ]; then FINAL_RELEASE_VERSION=$PACKAGE_VERSION else - case $RELEASE_TYPE in + case $VERSION_UPGRADE_TYPE in "major" | "minor" | "patch") echo "- analysing version" - FINAL_RELEASE_VERSION=$(update_version "$PACKAGE_NPM_VERSION" "$RELEASE_TYPE") TAG=$FINAL_RELEASE_VERSION + FINAL_RELEASE_VERSION=$(update_version "$PACKAGE_NPM_VERSION" "$VERSION_UPGRADE_TYPE") TAG=$FINAL_RELEASE_VERSION echo "- analysed deployable version $FINAL_RELEASE_VERSION" ;; *) - echo "- invalid release type: $RELEASE_TYPE" + echo "- invalid release type: $VERSION_UPGRADE_TYPE" ;; esac fi @@ -108,7 +121,7 @@ fi # Check if release notes are available echo "- reading release notes" -RELEASE_NOTES=$(cat .release/release-notes.md) +RELEASE_NOTES=$(cat .release/release-notes.txt) if [ $? != 0 ]; then echo "- release notes not provided" @@ -121,12 +134,14 @@ echo "- RELEASE_NOTES: $RELEASE_NOTES" echo "- PACKAGE_NAME: $PACKAGE_NAME" echo "- PACKAGE_VERSION: $PACKAGE_VERSION" echo "- FINAL_RELEASE_VERSION: $FINAL_RELEASE_VERSION" -echo "- RELEASE_TYPE:$RELEASE_TYPE" -echo "- TAG:$TAG" +echo "- VERSION_UPGRADE_TYPE: $VERSION_UPGRADE_TYPE" +echo "- TAG: $TAG" +echo "- RELEASE_TYPE: $RELEASE_TYPE" # Set output echo "tag=$(echo $TAG)" >>$GITHUB_OUTPUT echo "release-notes=$(echo $RELEASE_NOTES)" >>$GITHUB_OUTPUT echo "final-release-version=$(echo $FINAL_RELEASE_VERSION)" >>$GITHUB_OUTPUT -echo "release-type=$(echo $RELEASE_TYPE)" >>$GITHUB_OUTPUT +echo "release-type=$(echo $VERSION_UPGRADE_TYPE)" >>$GITHUB_OUTPUT echo "package-version=$(echo $PACKAGE_VERSION)" >>$GITHUB_OUTPUT +echo "release-type=$(echo $RELEASE_TYPE)" >>$GITHUB_OUTPUT diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index fd3783a..7a105ce 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,5 +1,6 @@ name: Deploy and Release on: + workflow_dispatch: push: branches: - main @@ -59,11 +60,10 @@ jobs: echo "package-version: ${{steps.read-release-props.outputs.package-version}}" echo "release-type: ${{steps.read-release-props.outputs.release-type}}" echo "final-release-version: ${{steps.read-release-props.outputs.final-release-version}}" - echo "final-release-version: ${{steps.read-release-props.outputs.final-release-version}}" + echo "release-type: ${{steps.read-release-props.outputs.release-type}}" + echo "isPrerelease: ${{steps.read-release-props.outputs.release-type}} == '--prerelease'" - name: Checkout to new branch and update package json with new version - # if: steps.read-release-props.outcome.package-version != steps.read-release-props.outputs.final-release-version - # continue-on-error: true id: branch-checkout-details run: | # Read current branch @@ -107,9 +107,11 @@ jobs: gh release create "$tag" \ --repo="$GITHUB_REPOSITORY" \ --title="$title" \ - --notes="${{ steps.read-release-props.outputs.release-notes }}" + --notes="${{ steps.read-release-props.outputs.release-notes }}" \ + ${{steps.read-release-props.outputs.release-type}} - name: Push and raise a PR + if: ${{steps.read-release-props.outputs.release-type != '--prerelease'}} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | diff --git a/.gitignore b/.gitignore index bb24127..6408089 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ yarn-error.log* .vscode/* test.ts -lib +lib/ +@types/ diff --git a/.release/config.json b/.release/config.json index eac4b63..b1d4ecb 100644 --- a/.release/config.json +++ b/.release/config.json @@ -1,3 +1,4 @@ { - "versionUpgradeType": "patch" + "versionUpgradeType": "patch", + "releaseType": "--prerelease" } \ No newline at end of file diff --git a/.release/release-notes.md b/.release/release-notes.md deleted file mode 100644 index 42bca77..0000000 --- a/.release/release-notes.md +++ /dev/null @@ -1,2 +0,0 @@ -# Improvements -- module resolution bundler diff --git a/.release/release-notes.txt b/.release/release-notes.txt new file mode 100644 index 0000000..60e1815 --- /dev/null +++ b/.release/release-notes.txt @@ -0,0 +1 @@ +## This release for testing subpath modules and their declerations diff --git a/package.json b/package.json index ddb3e72..dea3c3a 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "type": "git", "url": "https://github.com/laxmanpokhrel/xmanscript-utils.git" }, + "type": "module", "exports": { "./abbreviateCurrencyValue": "./lib/abbreviateCurrencyValue", "./areObjectsEqual": "./lib/areObjectsEqual", @@ -19,8 +20,8 @@ "./distributePercentageEquallyWithRemainder": "./lib/distributePercentageEquallyWithRemainder", "./formatNumberToCommaString": "./lib/formatNumberToCommaString", "./getDifferenceObject": { - "types": "./dist/getDifferenceObject/index.d.ts", - "default": "./dist/getDifferenceObject/index.js" + "types": "./lib/getDifferenceObject/index.d.ts", + "default": "./lib/getDifferenceObject/index.js" }, "./getFileExtension": "./lib/getFileExtension", "./getMinMax": "./lib/getMinMax", @@ -34,15 +35,15 @@ "./partitionObjectsByKey": "./lib/partitionObjectsByKey", "./removeObjectFromArray": "./lib/removeObjectFromArray", "./scrollToComponent": { - "types":"./dist/scrollToComponent/index.d.ts", - "default": "./dist/scrollToComponent/index.js" + "types":"./lib/scrollToComponent/index.d.ts", + "default": "./lib/scrollToComponent/index.js" }, "./setKeysToValueInObjects": "./lib/setKeysToValueInObjects", "./setValueOfKeyForMatchingValuesOfAKey": "./lib/setValueOfKeyForMatchingValuesOfAKey", "./splitArrayIntoChunks": "./lib/splitArrayIntoChunks", "./strictIntersectObjects": { - "types": "./dist/strictIntersectObjects/index.d.ts", - "default": "./dist/strictIntersectObjects/index.js" + "types": "./lib/strictIntersectObjects/index.d.ts", + "default": "./lib/strictIntersectObjects/index.js" }, "./toggleObjectInArray": "./lib/toggleObjectInArray", "./uniqueValuesOfKey": "./lib/uniqueValuesOfKey", diff --git a/tsconfig.json b/tsconfig.json index c18f767..b3b5499 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,7 +19,8 @@ "noFallthroughCasesInSwitch": true, "esModuleInterop": true, "allowSyntheticDefaultImports": false, - "moduleResolution": "Bundler" + // "declarationDir": "./@types" + }, "exclude": ["node_modules"], "include": [".eslintrc.js", "src", "src/**/*.ts"]