Skip to content

Commit 0070cf5

Browse files
committed
feat: restructure project files; update imports and add useLocalizer hook with Vite plugin support
1 parent b18d539 commit 0070cf5

File tree

11 files changed

+210
-255
lines changed

11 files changed

+210
-255
lines changed

__tests__/useLocalizer.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { usePage } from '@inertiajs/react';
22
import { renderHook } from '@testing-library/react';
3-
import { useLocalizer } from '../hooks/useLocalizer';
3+
import { useLocalizer } from '../src/useLocalizer';
44

55
// Mock usePage
66
const mockUsePage = usePage as jest.MockedFunction<typeof usePage>;

__tests__/vite-plugin.test.ts

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
import { laravelLocalizer } from '../vite-plugin';
1+
import { laravelLocalizer } from '../src/vite-plugin-laravel-localizer';
22

33
describe('laravelLocalizer Vite Plugin', () => {
44
it('should return a valid Vite plugin', () => {
55
const plugin = laravelLocalizer();
66

7-
expect(plugin).toHaveProperty('name', 'vite-plugin-laravel-localizer');
7+
expect(plugin).toHaveProperty('name', '@devwizard/vite-plugin-laravel-localizer');
88
expect(plugin).toHaveProperty('buildStart');
9-
expect(plugin).toHaveProperty('configureServer');
9+
expect(plugin).toHaveProperty('handleHotUpdate');
1010
});
1111

1212
it('should accept custom options', () => {
1313
const plugin = laravelLocalizer({
1414
command: 'php artisan custom:command',
15-
watch: ['custom/**'],
15+
patterns: ['custom/**'],
1616
debug: true,
17-
debounce: 500,
1817
});
1918

20-
expect(plugin.name).toBe('vite-plugin-laravel-localizer');
19+
expect(plugin.name).toBe('@devwizard/vite-plugin-laravel-localizer');
2120
});
2221

2322
it('should use default options when not provided', () => {
2423
const plugin = laravelLocalizer();
2524

26-
expect(plugin.name).toBe('vite-plugin-laravel-localizer');
25+
expect(plugin.name).toBe('@devwizard/vite-plugin-laravel-localizer');
2726
});
2827

2928
describe('buildStart hook', () => {
@@ -35,48 +34,26 @@ describe('laravelLocalizer Vite Plugin', () => {
3534
});
3635

3736
describe('configureServer hook', () => {
38-
it('should be defined', () => {
39-
const plugin = laravelLocalizer();
40-
41-
expect(typeof plugin.configureServer).toBe('function');
42-
});
43-
44-
it('should set up file watchers', () => {
37+
it('should be undefined (uses handleHotUpdate instead)', () => {
4538
const plugin = laravelLocalizer();
4639

47-
const mockWatcher = {
48-
on: jest.fn(),
49-
};
50-
51-
const mockServer = {
52-
watcher: mockWatcher,
53-
ws: {
54-
send: jest.fn(),
55-
},
56-
};
57-
58-
plugin.configureServer?.(mockServer as any);
59-
60-
// Should set up three watchers: change, add, unlink
61-
expect(mockWatcher.on).toHaveBeenCalledWith('change', expect.any(Function));
62-
expect(mockWatcher.on).toHaveBeenCalledWith('add', expect.any(Function));
63-
expect(mockWatcher.on).toHaveBeenCalledWith('unlink', expect.any(Function));
40+
expect(plugin.configureServer).toBeUndefined();
6441
});
6542
});
6643

6744
describe('Plugin options', () => {
6845
it('should accept empty options object', () => {
6946
const plugin = laravelLocalizer({});
7047

71-
expect(plugin.name).toBe('vite-plugin-laravel-localizer');
48+
expect(plugin.name).toBe('@devwizard/vite-plugin-laravel-localizer');
7249
});
7350

7451
it('should merge custom options with defaults', () => {
7552
const plugin = laravelLocalizer({
7653
debug: true,
7754
});
7855

79-
expect(plugin.name).toBe('vite-plugin-laravel-localizer');
56+
expect(plugin.name).toBe('@devwizard/vite-plugin-laravel-localizer');
8057
});
8158
});
8259

eslint.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export default tseslint.config(
3131
'@typescript-eslint/no-explicit-any': 'off',
3232
},
3333
},
34+
{
35+
files: ['**/vite-plugin-*.ts'],
36+
rules: {
37+
'@typescript-eslint/no-this-alias': 'off',
38+
},
39+
},
3440
{
3541
ignores: ['dist/**', 'node_modules/**', 'coverage/**', '*.cjs', '*.min.js', 'eslint.config.js'],
3642
}

eslint.config.min.js

Lines changed: 1 addition & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 64 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devwizard/laravel-localizer-react",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"type": "module",
55
"description": "React integration for Laravel Localizer with Vite plugin, useLocalizer hook, and automatic TypeScript generation",
66
"main": "dist/index.js",
@@ -82,6 +82,9 @@
8282
"react": "^18.0.0 || ^19.0.0",
8383
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
8484
},
85+
"dependencies": {
86+
"minimatch": "^10.1.1"
87+
},
8588
"devDependencies": {
8689
"@eslint/js": "^9.39.1",
8790
"@testing-library/jest-dom": "^6.8.0",

index.ts renamed to src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export type {
44
PageProps,
55
UseLocalizerReturn,
66
UseLocalizerOptions,
7-
} from './hooks/useLocalizer';
7+
} from './useLocalizer';
88

9-
export { useLocalizer } from './hooks/useLocalizer';
9+
export { useLocalizer } from './useLocalizer';

0 commit comments

Comments
 (0)