Skip to content

Commit

Permalink
🚧 UPDATE: remove nx!
Browse files Browse the repository at this point in the history
  • Loading branch information
jycouet committed Dec 28, 2024
1 parent 095c477 commit fa92b22
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 663 deletions.
26 changes: 7 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,14 @@ jobs:
pnpmVersion: 9
nodeVersion: 22.11.0

# - name: 🛠️ Prepare nx 1/2
# uses: nrwl/nx-set-shas@v4
- name: 🚧 Build Packages
run: pnpm -r build

# - name: 🛠️ Prepare nx 2/2
# run: git branch --track main origin/main
- name: 🧹 Lint Check
run: pnpm -r lint

# - name: 👌 Run nx affected
# run: pnpm nx:affected

- name: 👌 Run nx all
run: pnpm nx:all

# - name: 🚧 Build Packages
# run: pnpm run build

# - name: 🧹 Lint Check
# run: pnpm run lint

# - name: 👌 Run Tests
# run: pnpm run test:ci
- name: 👌 Run Tests
run: pnpm -r test:ci

# verify_create:
# name: Verify Create
Expand All @@ -63,7 +51,7 @@ jobs:
# pnpmVersion: 9
# nodeVersion: 22.11.0

# - name: 🚧 Run nx build
# - name: 🚧 Run build
# run: pnpm build

# - name: ➕ Create template
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ coverage/
.DS_Store

stats.html

.nx
17 changes: 17 additions & 0 deletions devbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.13.7/.schema/devbox.schema.json",
"packages": ["nodejs@22"],
"env": {
"DEVBOX_COREPACK_ENABLED": "true"
},
"shell": {
"init_hook": [
"echo 'Welcome to devbox!' > /dev/null"
],
"scripts": {
"test": [
"echo \"Error: no test specified\" && exit 1"
]
}
}
}
70 changes: 70 additions & 0 deletions devbox.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"lockfile_version": "1",
"packages": {
"nodejs@22": {
"last_modified": "2024-12-03T12:40:06Z",
"plugin_version": "0.0.2",
"resolved": "github:NixOS/nixpkgs/566e53c2ad750c84f6d31f9ccb9d00f823165550#nodejs_22",
"source": "devbox-search",
"version": "22.10.0",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/3r50cvcf5d7fahnkx4nkr2nk3h377h4s-nodejs-22.10.0",
"default": true
},
{
"name": "libv8",
"path": "/nix/store/6rgrpzdbylr432xa1r4mi9wc5i2bgvw0-nodejs-22.10.0-libv8"
}
],
"store_path": "/nix/store/3r50cvcf5d7fahnkx4nkr2nk3h377h4s-nodejs-22.10.0"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/ayfg2m6gwh5047hapf316jrilxd8kk4k-nodejs-22.10.0",
"default": true
},
{
"name": "libv8",
"path": "/nix/store/649q0xdwl617h2s8j50f7880df60w37a-nodejs-22.10.0-libv8"
}
],
"store_path": "/nix/store/ayfg2m6gwh5047hapf316jrilxd8kk4k-nodejs-22.10.0"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/4rmbk8pg2lvv22aqjk8b539pfspsm98m-nodejs-22.10.0",
"default": true
},
{
"name": "libv8",
"path": "/nix/store/g1bmrm6lq74zdid30q8hh3102qxpk7p7-nodejs-22.10.0-libv8"
}
],
"store_path": "/nix/store/4rmbk8pg2lvv22aqjk8b539pfspsm98m-nodejs-22.10.0"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/0xvgzkl74v6jrh79ibh7ss770dh4hb69-nodejs-22.10.0",
"default": true
},
{
"name": "libv8",
"path": "/nix/store/j0nfkz29q3iigzl6ly1a75bivd1bsqc3-nodejs-22.10.0-libv8"
}
],
"store_path": "/nix/store/0xvgzkl74v6jrh79ibh7ss770dh4hb69-nodejs-22.10.0"
}
}
}
}
}
19 changes: 0 additions & 19 deletions nx.json

This file was deleted.

11 changes: 2 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@
"type": "module",
"scripts": {
"dev:w": "cd website && npm run dev",
"lint": "pnpm nx run-many --target=lint",
"format": "pnpm nx run-many --target=format",
"release:version": "npm run changeset version",
"release": "npm run build && changeset publish",
"build": "rimraf packages/*/dist && pnpm nx run-many --target=build --exclude=create-kitql-*",
"nx:graph": "pnpm nx graph",
"nx:all": "pnpm nx run-many --target=build,lint,test:ci --exclude=create-kitql-*",
"nx:affected": "pnpm nx affected --target=build,lint,test:ci --exclude=create-kitql-*",
"nx:reset": "pnpm nx reset",
"reset": "git clean -xdf",
"up-dep": "pnpm -r up --latest"
},
Expand All @@ -23,8 +16,8 @@
"@changesets/cli": "2.27.7",
"@vitest/coverage-v8": "2.1.8",
"esbuild": "0.24.0",
"nx": "20.2.0",
"prettier": "3.4.2",
"rimraf": "6.0.1"
}
},
"packageManager": "[email protected]"
}
8 changes: 5 additions & 3 deletions packages/vite-plugin-watch-and-run/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ const log = new Log('Watch-and-Run')

export const watchAndRun = (
params: Options[],
): PluginOption & { getCheckedConf: () => StateDetail[],
configureServer: (server: ViteDevServer) => void } => {
): PluginOption & {
getCheckedConf: () => StateDetail[]
configureServer: (server: ViteDevServer) => void
} => {
return {
name: 'watch-and-run',

Expand All @@ -257,7 +259,7 @@ export const watchAndRun = (
// watch files outside of Vite root directory
for (const conf of watchAndRunConf) {
if (conf.watch) {
server.watcher.add(conf.watch);
server.watcher.add(conf.watch)
}
}

Expand Down
106 changes: 61 additions & 45 deletions packages/vite-plugin-watch-and-run/src/lib/plugins.checkConf.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { describe, expect, it } from 'vitest'
import { vi, beforeEach, afterEach } from 'vitest'
import type { ViteDevServer } from 'vite'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'

import { watchAndRun } from './index.js'

Expand All @@ -26,17 +25,19 @@ describe('vite-plugin-watch-and-run', () => {
it('Should throw an error as no run', async () => {
const p = watchAndRun([{ watch: 'hello!' } as any])
try {
p.getCheckedConf()
p.getCheckedConf()
} catch (error: any) {
expect(error.message).toEqual('plugin watch-and-run, `run` is missing.')
}
})

it('Should have a valid conf, with default all defaults', async () => {
const p = watchAndRun([{
watch: ['**/*.(gql|graphql)', '**/*.ts'],
run: 'npm run gen'
}])
const p = watchAndRun([
{
watch: ['**/*.(gql|graphql)', '**/*.ts'],
run: 'npm run gen',
},
])

expect(p.getCheckedConf()).toMatchInlineSnapshot(`
[
Expand Down Expand Up @@ -71,7 +72,7 @@ describe('vite-plugin-watch-and-run', () => {

describe('configureServer', () => {
let mockServer: ViteDevServer

beforeEach(() => {
// Create mock watcher with all required methods
const mockWatcher = {
Expand All @@ -91,21 +92,25 @@ describe('configureServer', () => {

it('should add watch patterns to server watcher', async () => {
const watchPattern = '**/*.(gql|graphql)'
const p = watchAndRun([{
watch: watchPattern,
run: 'npm run gen'
}])
const p = watchAndRun([
{
watch: watchPattern,
run: 'npm run gen',
},
])

await p.configureServer(mockServer)

expect(mockServer.watcher.add).toHaveBeenCalledWith(watchPattern)
})

it('should set up watchers for all kindWithPath events', async () => {
const p = watchAndRun([{
watch: '**/*.(gql|graphql)',
run: 'npm run gen'
}])
const p = watchAndRun([
{
watch: '**/*.(gql|graphql)',
run: 'npm run gen',
},
])

await p.configureServer(mockServer)

Expand All @@ -118,10 +123,12 @@ describe('configureServer', () => {
})

it('should set up watchers for all kindWithoutPath events', async () => {
const p = watchAndRun([{
watch: '**/*.(gql|graphql)',
run: 'npm run gen'
}])
const p = watchAndRun([
{
watch: '**/*.(gql|graphql)',
run: 'npm run gen',
},
])

await p.configureServer(mockServer)

Expand All @@ -134,21 +141,25 @@ describe('configureServer', () => {

it('should handle multiple watch patterns', async () => {
const watchPatterns = ['**/*.gql', '**/*.graphql']
const p = watchAndRun([{
watch: watchPatterns,
run: 'npm run gen'
}])
const p = watchAndRun([
{
watch: watchPatterns,
run: 'npm run gen',
},
])

await p.configureServer(mockServer)

expect(mockServer.watcher.add).toHaveBeenCalledWith(watchPatterns)
})

it('should not add watcher if no watch pattern is provided', async () => {
const p = watchAndRun([{
watchFile: async () => true,
run: 'npm run gen'
}])
const p = watchAndRun([
{
watchFile: async () => true,
run: 'npm run gen',
},
])

await p.configureServer(mockServer)

Expand All @@ -157,14 +168,17 @@ describe('configureServer', () => {

it('should handle array of watch patterns with different file types', async () => {
const watchPatterns = ['**/*.gql', '**/*.graphql', '**/*.ts', 'src/**/*.json']
const p = watchAndRun([{
watch: watchPatterns,
run: 'npm run gen'
}, {
// Add a second config to ensure multiple configs work with arrays
watch: ['**/*.css', '**/*.scss'],
run: 'npm run build:css'
}])
const p = watchAndRun([
{
watch: watchPatterns,
run: 'npm run gen',
},
{
// Add a second config to ensure multiple configs work with arrays
watch: ['**/*.css', '**/*.scss'],
run: 'npm run build:css',
},
])

await p.configureServer(mockServer)

Expand All @@ -181,22 +195,24 @@ describe('configureServer', () => {

it('should handle watch patterns outside of project root', async () => {
const watchPatterns = [
'../../shared/**/*.ts', // Parent directories
'../../shared/**/*.ts', // Parent directories
'../sibling-project/**/*.graphql', // Sibling directory
'/absolute/path/**/*.json', // Absolute path
'./src/**/*.ts' // Regular project path
'/absolute/path/**/*.json', // Absolute path
'./src/**/*.ts', // Regular project path
]

const p = watchAndRun([{
watch: watchPatterns,
run: 'npm run gen'
}])

const p = watchAndRun([
{
watch: watchPatterns,
run: 'npm run gen',
},
])

await p.configureServer(mockServer)

// Verify that external patterns are added to the watcher
expect(mockServer.watcher.add).toHaveBeenCalledWith(watchPatterns)

// Verify watchers are set up for file events
expect(mockServer.watcher.on).toHaveBeenCalledWith('add', expect.any(Function))
expect(mockServer.watcher.on).toHaveBeenCalledWith('change', expect.any(Function))
Expand Down
Loading

0 comments on commit fa92b22

Please sign in to comment.