Skip to content

Commit 58d5a93

Browse files
authored
Merge pull request #631 from nextcloud-libraries/feat/vite
feat: Use vite for transpiling and vitest for testing
2 parents ee2db24 + 73a8737 commit 58d5a93

File tree

9 files changed

+3873
-8406
lines changed

9 files changed

+3873
-8406
lines changed

.npmignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

package-lock.json

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

package.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@
22
"name": "@nextcloud/auth",
33
"version": "2.2.1",
44
"description": "Nextcloud helpers related to authentication and the current user",
5-
"main": "dist/index.js",
5+
"type": "module",
6+
"main": "dist/index.cjs",
67
"types": "dist/index.d.ts",
78
"exports": {
89
"types": "./dist/index.d.ts",
9-
"import": "./dist/index.es.mjs",
10-
"require": "./dist/index.js"
10+
"import": "./dist/index.mjs",
11+
"require": "./dist/index.cjs"
1112
},
1213
"files": [
1314
"dist/"
1415
],
1516
"scripts": {
16-
"build": "rollup --config rollup.config.mjs",
17+
"build": "vite --mode production build",
1718
"build:doc": "typedoc --out dist/doc lib/index.ts && touch dist/doc/.nojekyll",
18-
"check-types": "tsc --noEmit",
19-
"dev": "rollup --config rollup.config.mjs --watch",
20-
"lint": "eslint lib *js",
21-
"lint:fix": "eslint --fix lib",
22-
"test": "jest",
23-
"test:watch": "jest --watchAll"
19+
"dev": "vite --mode development run --watch",
20+
"lint": "eslint lib test *.ts",
21+
"lint:fix": "eslint --fix lib test",
22+
"test": "vitest run",
23+
"test:coverage": "vitest run --coverage",
24+
"test:watch": "vitest watch"
2425
},
2526
"keywords": [
2627
"nextcloud"
@@ -38,14 +39,14 @@
3839
"devDependencies": {
3940
"@nextcloud/eslint-config": "^8.3.0",
4041
"@nextcloud/typings": "^1.8.0",
41-
"@rollup/plugin-typescript": "^11.1.6",
42+
"@nextcloud/vite-config": "^1.2.2",
43+
"@vitest/coverage-v8": "^1.5.0",
4244
"eslint": "^8.57.0",
43-
"jest": "^29.7.0",
44-
"jest-environment-jsdom": "^29.7.0",
45-
"rollup": "^4.16.0",
46-
"tslib": "^2.6.2",
45+
"happy-dom": "^14.7.1",
4746
"typedoc": "^0.25.13",
48-
"typescript": "^5.4.5"
47+
"typescript": "^5.4.5",
48+
"vite": "^5.2.10",
49+
"vitest": "^1.5.0"
4950
},
5051
"engines": {
5152
"node": "^20.0.0",

rollup.config.mjs

Lines changed: 0 additions & 35 deletions
This file was deleted.

test/request-token.test.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

test/request-token.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { emit } from '@nextcloud/event-bus'
2+
import { beforeEach, describe, expect, test, vi } from 'vitest'
3+
4+
import { getRequestToken, onRequestTokenUpdate } from '../lib/index'
5+
6+
describe('request token', () => {
7+
beforeEach(() => {
8+
emit('csrf-token-update', {
9+
token: undefined,
10+
})
11+
})
12+
13+
test('updates token via event', () => {
14+
expect(getRequestToken()).toBe(null)
15+
})
16+
17+
test('find correct value', () => {
18+
emit('csrf-token-update', {
19+
token: 'token123',
20+
})
21+
22+
expect(getRequestToken()).toBe('token123')
23+
})
24+
25+
test('request token observer is called', () => {
26+
const observer = vi.fn(() => { })
27+
28+
onRequestTokenUpdate(observer)
29+
emit('csrf-token-update', {
30+
token: 'token123',
31+
})
32+
33+
expect(observer.mock.calls.length).toBe(1)
34+
})
35+
})

tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"include": ["./lib/**/*.ts"],
2+
"include": ["./lib/**.ts"],
33
"compilerOptions": {
44
"allowSyntheticDefaultImports": true,
5-
"moduleResolution": "node",
5+
"moduleResolution": "Bundler",
66
"target": "ESNext",
7-
"module": "esnext",
7+
"module": "ESNext",
88
"declaration": true,
99
"strict": true,
1010
"noImplicitAny": false,

vite.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { createLibConfig } from '@nextcloud/vite-config'
2+
3+
export default createLibConfig(
4+
{
5+
index: `${__dirname}/lib/index.ts`,
6+
},
7+
{
8+
libraryFormats: ['cjs', 'es'],
9+
},
10+
)

vitest.config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { UserConfig } from 'vite'
2+
import viteConfig from './vite.config'
3+
4+
export default async (env) => {
5+
const config = typeof viteConfig === 'function' ? await viteConfig(env) : viteConfig
6+
// node-externals conflicts with vitest
7+
config.plugins = config.plugins!.filter((plugin) => plugin && (!('name' in plugin) || plugin?.name !== 'node-externals'))
8+
9+
return {
10+
...config,
11+
test: {
12+
environment: 'happy-dom',
13+
coverage: {
14+
reporter: ['text', 'lcov'],
15+
},
16+
},
17+
} as UserConfig
18+
}

0 commit comments

Comments
 (0)