diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3cc59e4..9b5009e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,72 +1,64 @@ -name: CI +name: ๐Ÿงช Continuous Integration on: push: - branches: - - main - - master + branches-ignore: [master] pull_request: - branches: - - main - - master + branches: [master] jobs: - linting: - name: Biome linting and formatting + test: + name: ๐Ÿงช Test Suite runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: ๐Ÿ“ฅ Checkout code + uses: actions/checkout@v4 - - name: Cache bun - uses: actions/cache@v3 - id: bun-cache + - name: ๐ŸŸข Setup Bun + uses: oven-sh/setup-bun@v1 with: - path: ~/.bun/bin - key: bun-v1.2.16 - - - name: Install Bun v1.2.16 - if: steps.bun-cache.outputs.cache-hit != 'true' - run: | - curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.16" - - - name: Add bun to PATH - run: echo "$HOME/.bun/bin" >> $GITHUB_PATH + bun-version: latest - - name: Install dependencies + - name: ๐Ÿ“ฆ Install dependencies run: bun install - - name: Run Biome checks - run: bunx biome check + - name: ๐Ÿงช Run tests + run: bun test - bun-tests: - name: Bun test suite - runs-on: ubuntu-latest + - name: ๐Ÿ” Lint and format check + run: bun run check - steps: - - name: Checkout code - uses: actions/checkout@v3 + - name: ๐Ÿ—๏ธ Test build + run: bun run build - - name: Cache bun - uses: actions/cache@v3 - id: bun-cache - with: - path: ~/.bun/bin - key: bun-v1.2.16 - - - name: Install Bun v1.2.16 - if: steps.bun-cache.outputs.cache-hit != 'true' + - name: ๐Ÿ“ Check bundle size run: | - curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.16" - - name: Add bun to PATH - run: echo "$HOME/.bun/bin" >> $GITHUB_PATH + BUNDLE_SIZE=$(du -sh dist/ | cut -f1) + echo "๐Ÿ“ฆ Bundle size: $BUNDLE_SIZE" + echo "bundle-size=$BUNDLE_SIZE" >> $GITHUB_OUTPUT + + compatibility: + name: ๐ŸŒ Compatibility Test + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ“ฅ Checkout code + uses: actions/checkout@v4 - - name: Verify Bun - run: bun --version + - name: ๐ŸŸข Setup Bun + uses: oven-sh/setup-bun@v1 - - name: Install dependencies + - name: ๐Ÿ“ฆ Install dependencies run: bun install - - name: Run tests - run: bun test + - name: ๐Ÿ—๏ธ Build package + run: bun run build + + - name: ๐Ÿงช Test package installation + run: | + # Test local package installation + npm pack + PACKAGE=$(ls *.tgz) + mkdir test-install && cd test-install + npm init -y + npm install ../$PACKAGE + echo "โœ… Package installation test passed" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..707c0b9 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,125 @@ +name: ๐Ÿš€ Publish to NPM + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + test: + name: ๐Ÿงช Test & Quality Check + runs-on: ubuntu-latest + steps: + - name: ๐Ÿ“ฅ Checkout code + uses: actions/checkout@v4 + + - name: ๐ŸŸข Setup Bun + uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + + - name: ๐Ÿ“ฆ Install dependencies + run: bun install + + - name: ๐Ÿงช Run tests + run: bun test + + - name: ๐Ÿ” Run linting and formatting checks + run: bun run check + + - name: ๐Ÿ—๏ธ Test build + run: bun run build + + - name: ๐Ÿ“Š Upload coverage reports + if: success() + run: echo "โœ… All quality checks passed" + + publish: + name: ๐Ÿ“ฆ Publish to NPM + needs: test + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/master' && github.event_name == 'push' + steps: + - name: ๐Ÿ“ฅ Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: ๐ŸŸข Setup Bun + uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + + - name: ๐Ÿ“ฆ Install dependencies + run: bun install + + - name: ๐Ÿ—๏ธ Build package + run: bun run build + + - name: ๐Ÿ”– Determine version bump + id: version + run: | + # Get the last commit message + COMMIT_MSG=$(git log -1 --pretty=%B) + echo "Commit message: $COMMIT_MSG" + + # Determine version bump based on conventional commits + if echo "$COMMIT_MSG" | grep -q "BREAKING CHANGE\|!:"; then + echo "bump=major" >> $GITHUB_OUTPUT + echo "๐Ÿ”ฅ Major version bump detected" + elif echo "$COMMIT_MSG" | grep -q "^feat"; then + echo "bump=minor" >> $GITHUB_OUTPUT + echo "โœจ Minor version bump detected" + elif echo "$COMMIT_MSG" | grep -q "^fix\|^perf\|^refactor"; then + echo "bump=patch" >> $GITHUB_OUTPUT + echo "๐Ÿ› Patch version bump detected" + else + echo "bump=patch" >> $GITHUB_OUTPUT + echo "๐Ÿ“ Default patch version bump" + fi + + - name: ๐Ÿ”– Bump version + run: | + npm version ${{ steps.version.outputs.bump }} --no-git-tag-version + NEW_VERSION=$(node -p "require('./package.json').version") + echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV + echo "๐Ÿ“ˆ Version bumped to $NEW_VERSION" + + - name: ๐Ÿท๏ธ Create Git tag + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add package.json + git commit -m "๐Ÿ”– chore: bump version to $NEW_VERSION [skip ci]" + git tag "v$NEW_VERSION" + git push origin master --tags + + - name: ๐Ÿ“ฆ Publish to NPM + run: | + echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc + npm publish --access public + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: ๐Ÿ“ Create GitHub Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ env.NEW_VERSION }} + release_name: Release v${{ env.NEW_VERSION }} + body: | + ## ๐ŸŽ‰ What's Changed + + This release was automatically generated from the latest changes in master. + + ### ๐Ÿ“ฆ Installation + ```bash + npm install mini-react@${{ env.NEW_VERSION }} + ``` + + ### ๐Ÿ”— NPM Package + https://www.npmjs.com/package/mini-react/v/${{ env.NEW_VERSION }} + draft: false + prerelease: false diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..6f5cd70 --- /dev/null +++ b/.npmignore @@ -0,0 +1,46 @@ +# Source files (we publish compiled dist/) +src/ +index.ts + +# Build configuration +tsconfig.json +tsconfig.build.json +biome.json +bunfig.toml + +# Tests and examples +tests/ +example/ +*.test.ts +*.test.tsx +*.test.js +*.test.jsx + +# Development files +.gitignore +.cursor +.vscode/ +.idea/ + +# Logs and caches +*.log +.cache +.DS_Store +coverage/ +.nyc_output/ + +# Lock files and package managers +bun.lock +yarn.lock +package-lock.json +.pnpm-debug.log* + +# Build artifacts not needed +*.tsbuildinfo +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Environment files +.env* \ No newline at end of file diff --git a/bun.lock b/bun.lock index 18bee19..aeae3ee 100644 --- a/bun.lock +++ b/bun.lock @@ -7,6 +7,7 @@ "@biomejs/biome": "1.9.4", "@happy-dom/global-registrator": "^17.5.6", "@types/bun": "latest", + "typescript": "^5.0.0", }, "peerDependencies": { "typescript": "^5.0.0", diff --git a/package.json b/package.json index b0aff95..76ea231 100644 --- a/package.json +++ b/package.json @@ -1,35 +1,47 @@ { "name": "mini-react", - "version": "1.0.0", + "version": "0.0.0", "description": "A minimal React implementation with JSX support", - "main": "index.ts", - "module": "index.ts", + "main": "./dist/index.js", + "module": "./dist/index.js", + "types": "./dist/index.d.ts", "exports": { ".": { - "import": "./index.ts", - "require": "./index.ts" + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.js" }, "./jsx-runtime": { - "import": "./src/jsx-runtime.ts", - "require": "./src/jsx-runtime.ts" + "types": "./dist/src/jsx-runtime.d.ts", + "import": "./dist/src/jsx-runtime.js", + "require": "./dist/src/jsx-runtime.js" }, "./jsx-dev-runtime": { - "import": "./src/jsx-dev-runtime.ts", - "require": "./src/jsx-dev-runtime.ts" + "types": "./dist/src/jsx-dev-runtime.d.ts", + "import": "./dist/src/jsx-dev-runtime.js", + "require": "./dist/src/jsx-dev-runtime.js" } }, + "files": ["dist/**/*", "README.md", "LICENSE"], "devDependencies": { "@biomejs/biome": "1.9.4", "@happy-dom/global-registrator": "^17.5.6", - "@types/bun": "latest" + "@types/bun": "latest", + "typescript": "^5.0.0" }, "scripts": { + "build": "tsc -p tsconfig.build.json", + "clean": "rm -rf dist", + "prebuild": "npm run clean", + "prepare": "npm run build", + "test": "bun test", "lint": "biome lint .", "format": "biome format .", "check": "biome check .", "lint:write": "biome lint --write .", "format:write": "biome format --write .", - "check:write": "biome check --write ." + "check:write": "biome check --write .", + "prepublishOnly": "npm run test && npm run check && npm run build" }, "peerDependencies": { "typescript": "^5.0.0" diff --git a/src/types.ts b/src/types.ts index bc1e898..0f1dba3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -126,7 +126,6 @@ export interface RefHook { type: "ref"; current: T; } - /** * Union type for hooks stored in component instances. * Note: The generic parameter T only applies to StateHook and ContextHook, EffectHook ignores it. @@ -185,7 +184,6 @@ export type MutableRefObject = { }; export type UseRefHook = (initialValue: T) => MutableRefObject; - // ******************* // // VDOM Instance Types // // ******************* // diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..51e7d36 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,25 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./dist", + "rootDir": "./", + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "noEmit": false, + "emitDeclarationOnly": false, + "skipLibCheck": true, + "moduleResolution": "node", + "allowImportingTsExtensions": false, + "verbatimModuleSyntax": false + }, + "include": ["src/**/*", "index.ts"], + "exclude": [ + "tests/**/*", + "example/**/*", + "**/*.test.ts", + "**/*.test.tsx", + "dist/**/*", + "node_modules/**/*" + ] +}