Skip to content

Commit

Permalink
feat: add Vite support (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
innocenzi authored Dec 12, 2024
1 parent 5abb74b commit 4099b40
Show file tree
Hide file tree
Showing 64 changed files with 2,741 additions and 6 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/coding-conventions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ jobs:
# env:
# PHP_CS_FIXER_IGNORE_ENV: true

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Run eslint
run: bun run lint

phpstan:
name: "Run Static Analysis: PHPStan"
runs-on: ubuntu-latest
Expand Down
38 changes: 37 additions & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,42 @@ on:
- cron: '0 0 * * *'

jobs:
vitest:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
php:
- 8.4
os:
- ubuntu-latest
- windows-latest

name: "Run Tests: ${{ matrix.os }}"

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, pcntl, fileinfo, pdo, sqlite, pdo_sqlite, pdo_mysql
coverage: pcov

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Run build
run: bun run build

- name: Run tests
run: bun run test

phpunit:
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -72,4 +108,4 @@ jobs:
uses: coverallsapp/github-action@v2
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
file: build/reports/clover.xml
file: build/reports/clover.xml
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ debug.log
tempest.log
public/static
tests/Unit/Log
log/
log/
node_modules
dist
Binary file added bun.lockb
Binary file not shown.
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
"tempest/router": "self.version",
"tempest/support": "self.version",
"tempest/validation": "self.version",
"tempest/view": "self.version"
"tempest/view": "self.version",
"tempest/vite": "self.version"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand All @@ -101,7 +102,8 @@
"Tempest\\Router\\": "src/Tempest/Router/src",
"Tempest\\Support\\": "src/Tempest/Support/src",
"Tempest\\Validation\\": "src/Tempest/Validation/src",
"Tempest\\View\\": "src/Tempest/View/src"
"Tempest\\View\\": "src/Tempest/View/src",
"Tempest\\Vite\\": "src/Tempest/Vite/src"
},
"files": [
"src/Tempest/CommandBus/src/functions.php",
Expand All @@ -113,7 +115,8 @@
"src/Tempest/Reflection/src/functions.php",
"src/Tempest/Router/src/functions.php",
"src/Tempest/Support/src/functions.php",
"src/Tempest/View/src/functions.php"
"src/Tempest/View/src/functions.php",
"src/Tempest/Vite/src/functions.php"
]
},
"autoload-dev": {
Expand All @@ -140,6 +143,7 @@
"Tempest\\Router\\Tests\\": "src/Tempest/Router/tests",
"Tempest\\Support\\Tests\\": "src/Tempest/Support/tests",
"Tempest\\Validation\\Tests\\": "src/Tempest/Validation/tests",
"Tempest\\Vite\\Tests\\": "src/Tempest/Vite/tests",
"Tests\\Tempest\\": "tests/"
}
},
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import defineEslintConfig from '@innocenzi/eslint-config'

export default defineEslintConfig()
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"private": true,
"workspaces": ["packages/*"],
"scripts": {
"qa": "bun lint:fix && bun run test run && bun run build",
"lint": "eslint packages",
"lint:fix": "eslint --fix packages",
"build": "bun --filter '*' build",
"dev": "bun --filter '*' build:stub",
"test": "vitest",
"release": "bumpp package.json --push --tag --commit \"release: v\""
},
"devDependencies": {
"@innocenzi/eslint-config": "^0.22.4",
"@types/bun": "latest",
"bumpp": "^9.9.0",
"eslint": "^9.16.0",
"typescript": "^5.7.2",
"unbuild": "^2.0.0",
"vite-plugin-tempest": "workspace:*",
"vitest": "^2.1.8"
}
}
9 changes: 9 additions & 0 deletions packages/vite-plugin-tempest/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
entries: [
'src/index',
],
clean: true,
declaration: true,
})
Binary file added packages/vite-plugin-tempest/bun.lockb
Binary file not shown.
34 changes: 34 additions & 0 deletions packages/vite-plugin-tempest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "vite-plugin-tempest",
"type": "module",
"version": "0.0.0",
"author": "Enzo Innocenzi",
"license": "MIT",
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs"
}
},
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"*.d.ts",
"dist"
],
"scripts": {
"build": "unbuild",
"build:stub": "unbuild --stub",
"test": "vitest"
},
"peerDependencies": {
"typescript": "^5.0.0",
"vite": "^6.0.3"
},
"dependencies": {
"@innocenzi/utils": "^0.3.0",
"picocolors": "^1.1.1"
}
}
14 changes: 14 additions & 0 deletions packages/vite-plugin-tempest/src/config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect, test } from 'vitest'
import { loadTempestConfiguration } from './config'
import { mockTempestConfiguration } from './test-utils'

test('the configuration can be loaded', async () => {
mockTempestConfiguration()

const config = await loadTempestConfiguration()

expect(config).toHaveProperty('build_directory')
expect(config).toHaveProperty('bridge_file_name')
expect(config).toHaveProperty('manifest')
expect(config).toHaveProperty('entrypoints')
})
22 changes: 22 additions & 0 deletions packages/vite-plugin-tempest/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { TempestViteConfiguration } from './types'
import { exec, php } from './utils'

const TEMPEST_BIN = 'tempest'
const VITE_CONFIG_COMMAND = 'vite:config'

export async function loadTempestConfiguration(): Promise<TempestViteConfiguration> {
try {
const { stdout } = await exec(`${php.value} ${TEMPEST_BIN} ${VITE_CONFIG_COMMAND}`)
const json = stdout.match(/\{.*\}/s)

return JSON.parse(json?.[0] as string)
} catch (e) {
console.error(`Could not load configuration from [${php.value} ${TEMPEST_BIN} ${VITE_CONFIG_COMMAND}].`)

if ((e as any).stdout) {
console.error((e as any).stdout)
}

throw e
}
}
3 changes: 3 additions & 0 deletions packages/vite-plugin-tempest/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as tempest } from './plugin'
export { default } from './plugin'
export { type TempestViteConfiguration } from './types'
37 changes: 37 additions & 0 deletions packages/vite-plugin-tempest/src/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import tempest from './plugin'
import { mockTempestConfiguration } from './test-utils'

describe('tempest', () => {
afterEach(() => {
vi.restoreAllMocks()
})

it('it returns a Vite plugin', () => {
mockTempestConfiguration()

const plugin = tempest()

expect(plugin).not.toBeNull()
})

it('it outputs a config', async () => {
mockTempestConfiguration({
build_directory: 'build/custom',
bridge_file_name: 'custom-bridge',
manifest: 'custom-manifest.json',
entrypoints: ['src/main.ts'],
})

const plugin = tempest()

// @ts-expect-error typing
const config = await plugin.config({}, { command: 'build' })

expect(config.base).toBe('/build/custom/')
expect(config.build.manifest).toBe('custom-manifest.json')
expect(config.build.rollupOptions).toEqual({ input: [
'src/main.ts',
] })
})
})
Loading

0 comments on commit 4099b40

Please sign in to comment.