From c5f25d90fbf3853992b2463b9118d93785fee99e Mon Sep 17 00:00:00 2001 From: "M. Afifudin" Date: Mon, 16 Oct 2023 09:17:25 +0700 Subject: [PATCH] fix: conditional preact build --- .github/workflows/ci.yml | 16 +++++++++++++--- package.json | 6 +++++- scripts/preact.ts | 24 +++++++++++++++++++++--- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11f2a8e..68a8235 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: Code Quality Check & Publish on: push: - branches: [main, alpha, beta] + branches: [main, beta, alpha, experimental] pull_request: types: [opened, synchronize] @@ -49,7 +49,12 @@ jobs: publish: name: Publish to NPM needs: [lint, type-check, test] - if: github.repository == 'afiiif/floppy-disk' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/alpha' || github.ref == 'refs/heads/beta') + if: | + github.repository == 'afiiif/floppy-disk' + && (github.ref == 'refs/heads/main' + || github.ref == 'refs/heads/beta' + || github.ref == 'refs/heads/alpha' + || github.ref == 'refs/heads/experimental') runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -63,7 +68,12 @@ jobs: npm pkg delete 'engines' npm pkg delete 'devDependencies' - name: Build package - run: yarn build + run: | + if [ "${{ github.ref }}" = "refs/heads/experimental" ]; then + PREACT=true yarn build + else + yarn build + fi - name: Release package run: yarn semantic-release env: diff --git a/package.json b/package.json index 8f06030..7281d60 100644 --- a/package.json +++ b/package.json @@ -92,12 +92,16 @@ "release": { "branches": [ "main", + { + "name": "beta", + "prerelease": true + }, { "name": "alpha", "prerelease": true }, { - "name": "beta", + "name": "experimental", "prerelease": true } ] diff --git a/scripts/preact.ts b/scripts/preact.ts index 6d3ddce..f8ccd88 100644 --- a/scripts/preact.ts +++ b/scripts/preact.ts @@ -7,7 +7,7 @@ if (process.env.PREACT !== 'true') process.exit(); const reactFilesPath = './src/react'; const preactFilesPath = './src/preact'; -async function copyAndReplace() { +const copyAndReplace = async () => { try { const files = await readdir(reactFilesPath); @@ -46,6 +46,24 @@ async function copyAndReplace() { } catch (error) { console.error('An error occurred:', error); } -} +}; -copyAndReplace(); +const updatePackageJson = async () => { + const packageJsonContent = await readFile('./package.json', 'utf8'); + const packageJson = JSON.parse(packageJsonContent); + packageJson.exports['./preact'] = { + types: './lib/preact/index.d.ts', + import: { + types: './esm/preact/index.d.ts', + default: './esm/preact/index.js', + }, + module: './esm/preact/index.js', + default: './lib/preact/index.js', + }; + await writeFile('./package.json', JSON.stringify(packageJson, null, 2), 'utf8'); +}; + +(async () => { + await copyAndReplace(); + await updatePackageJson(); +})();