Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ jobs:
matrix:
node: ['24']
runs-on: ubuntu-24.04
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_CACHE: 'remote:rw'
steps:
- uses: actions/checkout@v6
- uses: pnpm/action-setup@v5.0.0
Expand All @@ -25,7 +22,7 @@ jobs:
- name: build
run: |
pnpm install --frozen-lockfile
pnpm run build
pnpm build

typecheck:
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -61,9 +58,6 @@ jobs:
lint:
runs-on: ubuntu-24.04
needs: [build]
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_CACHE: 'remote:rw'
steps:
- uses: actions/checkout@v6
- uses: pnpm/action-setup@v5.0.0
Expand All @@ -75,9 +69,8 @@ jobs:
- name: lint
run: |
pnpm install --frozen-lockfile
pnpm run build
pnpm run format:ci
pnpm run oxc:quiet
pnpm build
pnpm check

test:
runs-on: ubuntu-24.04
Expand All @@ -94,7 +87,7 @@ jobs:
check-latest: true
cache: 'pnpm'
- run: pnpm install
- run: pnpm run test:coverage
- run: pnpm test
- uses: codecov/codecov-action@v5.5.4
with:
files: packages/**/coverage/cobertura-coverage.xml
Expand All @@ -116,4 +109,4 @@ jobs:
check-latest: true
cache: 'pnpm'
- run: pnpm install
- run: pnpm run test:types
- run: pnpm test:types
43 changes: 33 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ $ git clone git@github.com:scaleway/scaleway-lib.git
$ cd scaleway-lib
$ pnpm install
$ # ... do your changes ...
$ pnpm run lint
$ pnpm run test
$ pnpm vp check
$ pnpm vp test
```

### Link against another project (with `yalc`) => FAVORED
Expand Down Expand Up @@ -182,17 +182,17 @@ $ pnpm link @scaleway/example_package
### Linting

```bash
$ pnpm run oxc
$ pnpm run oxc:fix
$ pnpm vp check
$ pnpm vp check --fix
```

### Unit Test

```bash
$ pnpm run test # Will run all tests
$ pnpm run test --updateSnapshot # Will update all snapshots
$ pnpm run test:watch # Will watch tests and only rerun the one who are modified
$ pnpm run test:coverage # Will generate a coverage report
$ pnpm vp test # Will run all tests
$ pnpm vp test --updateSnapshot # Will update all snapshots
$ pnpm vp test # Will watch tests and only rerun the one who are modified (built-in watch mode)
$ pnpm vp test --coverage # Will generate a coverage report
```

## Lerna
Expand All @@ -211,6 +211,29 @@ $ cd packages/package_name && pnpm add new_dependency
$ cd packages/package_name && pnpm remove old_dependency
```

## Vite+

This project uses [Vite+](https://viteplus.dev/) as the unified development toolchain. Vite+ provides:

- **Fast builds** with Vite and Rolldown
- **Linting and formatting** with Oxc (50-100× faster than ESLint/Prettier)
- **Type checking** with tsgo
- **Testing** with Vitest
- **Task orchestration** with built-in caching

### Common commands

```bash
$ pnpm vp dev # Start development server
$ pnpm vp build # Build for production
$ pnpm vp check # Lint, format, and type check
$ pnpm vp check --fix # Auto-fix linting and formatting issues
$ pnpm vp test # Run tests
$ pnpm vp test --coverage # Run tests with coverage
$ pnpm vp typecheck # Run type checking
$ pnpm vp run <task> # Run tasks with dependency-aware execution
```

## Notes

### On build targets
Expand Down Expand Up @@ -239,7 +262,7 @@ We enforce the [conventionnal commits](https://www.conventionalcommits.org) conv

### On git hooks

We have a [husky](https://github.com/typicode/husky) hook on `pre-commit` and `pre-push` which will ensure the file you committed matches the configured formating (`eslint` + `prettier`)
We have a [husky](https://github.com/typicode/husky) hook on `pre-commit` and `pre-push` which will ensure the file you committed matches the configured formating (Vite+ check)

We also have one on `commit-msg` which will ensure you commit message respects our commit convention

Expand All @@ -252,5 +275,5 @@ We follow the [semver](http://semver.org/) semantic.
## Contributing Guidelines

- Ensure tests are still ok and code coverage have not decreased
- Follow linter rules ([tldr](#linting)).
- Follow linter rules (Vite+ check).
- CI is enforced, you won't be able to merge unless pipeline is successful.
45 changes: 20 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
"type": "module",
"scripts": {
"lint:catalog": "pnpm check-catalog-usage",
"oxc": "pnpm oxlint -c .oxlintrc.json --type-aware --type-check",
"oxc:quiet": "pnpm oxc --quiet",
"oxc:fix": "pnpm oxc --fix",
"build": "pnpm turbo build",
"typecheck": "pnpm turbo typecheck",
"typecheck:generate": "pnpm turbo typecheck:generate",
"typecheck:go": "pnpm turbo typecheck:go",
"typecheck:generate:go": "pnpm turbo typecheck:generate:go",
"commit": "npx git-cz -a",
"format": "oxfmt --write .",
"format:check": "oxfmt --check .",
"format:ci": "oxfmt --check .",
"test:unit": "pnpm turbo test:unit",
"test:coverage": "pnpm test:unit -- --coverage",
"typecheck:global": "pnpm tsc --noEmit",
"dev": "pnpm -r --parallel run dev",
"build": "vp run --filter '@scaleway/*' build",
"check": "vp check",
"format": "vp fmt . --write",
"check:fix": "vp check --fix",
"test": "vp run --filter '@scaleway/*' --filter '!@scaleway/biome' --filter '!@scaleway/oxlint-config' --filter '!@scaleway/tsconfig' --filter '!@scaleway/utils' test",
"test:unit": "vp run --filter '@scaleway/*' test:unit",
"test:coverage": "vp run --filter '@scaleway/*' test:coverage",
"typecheck": "vp run --filter '@scaleway/*' typecheck",
"typecheck:global": "vp run --filter '@scaleway/*' typecheck",
"typecheck:generate": "vp run --filter '@scaleway/*' type:generate",
"typecheck:go": "pnpm typecheck",
"typecheck:generate:go": "pnpm typecheck:generate",
"test:types": "tstyche",
"release": "pnpm build && pnpm changeset publish",
"prepare": "husky install"
"prepare": "husky install",
"run": "pnpm run"
},
"devDependencies": {
"@babel/core": "catalog:",
Expand All @@ -39,7 +39,6 @@
"@manypkg/cli": "catalog:",
"@rudderstack/analytics-js": "catalog:",
"@scaleway/changesets-renovate": "workspace:*",
"@scaleway/oxlint-config": "workspace:*",
"@scaleway/tsconfig": "workspace:*",
"@scaleway/use-segment": "catalog:",
"@scaleway/utils": "workspace:*",
Expand All @@ -66,32 +65,28 @@
"jsdom": "catalog:",
"lint-staged": "catalog:",
"mockdate": "catalog:",
"oxfmt": "catalog:",
"oxlint": "catalog:",
"oxlint-tsgolint": "catalog:",
"read-pkg": "catalog:",
"shx": "catalog:",
"tstyche": "catalog:",
"turbo": "catalog:",
"typescript": "catalog:",
"vite": "catalog:",
"vite-plus": "catalog:",
"vitest": "catalog:",
"vitest-localstorage-mock": "catalog:",
"wait-for-expect": "catalog:"
},
"lint-staged": {
"*.ts?(x)": [
"pnpm run format",
"pnpm run oxc:fix --quiet"
"vp check --fix"
],
"*.y?(a)ml": [
"oxfmt --write ."
"vp check --fix"
],
"*.json": [
"oxfmt --write ."
"vp check --fix"
],
"*.mdx": [
"oxfmt --write ."
"vp check --fix"
],
"(*package).json": [
"pnpm exec manypkg check"
Expand Down
3 changes: 2 additions & 1 deletion packages/changesets-renovate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
"access": "public"
},
"scripts": {
"prebuild": "shx rm -rf dist",
"check": "vp check",
"typecheck": "tsgo --noEmit",
"type:generate": "tsgo --declaration -p tsconfig.build.json",
"build": "vite build --config vite.config.ts && pnpm run type:generate",
"build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
"test": "vitest --run --config vite.config.ts",
"test:unit": "vitest --run --config vite.config.ts",
"test:unit:coverage": "pnpm test:unit --coverage"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/cookie-consent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
"access": "public"
},
"scripts": {
"prebuild": "shx rm -rf dist",
"check": "vp check",
"typecheck": "tsgo --noEmit",
"type:generate": "tsgo --declaration -p tsconfig.build.json",
"build": "vite build --config vite.config.ts && pnpm run type:generate",
"build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
"test": "vitest --run --config vite.config.ts",
"test:unit": "vitest --run --config vite.config.ts",
"test:unit:coverage": "pnpm test:unit --coverage"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const CookieConsentContext: Context<CookieContext | undefined> = createContext<
CookieContext | undefined
>(undefined)

export const useCookieConsent: () => CookieContext = (): CookieContext => {
const useCookieConsent = (): CookieContext => {
const context = useContext(CookieConsentContext)
if (context === undefined) {
throw new Error(
Expand All @@ -64,9 +64,7 @@ type CookieConsentProviderProps = PropsWithChildren<{
cookiesOptions?: SerializeOptions
}>

export const CookieConsentProvider: ComponentType<
CookieConsentProviderProps
> = ({
const CookieConsentProvider: ComponentType<CookieConsentProviderProps> = ({
children,
isConsentRequired,
essentialIntegrations,
Expand Down Expand Up @@ -258,3 +256,6 @@ export const CookieConsentProvider: ComponentType<
</CookieConsentContext.Provider>
)
}

export { CookieConsentProvider }
export { useCookieConsent }
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ describe('cookieConsent - useSegmentIntegrations', () => {
useSegmentIntegrations({ segment: null }),
)

await waitFor(() => {
expect(result.current.integrations).toStrictEqual([])
})
await waitFor(
() => {
expect(result.current.integrations).toStrictEqual([])
},
{ timeout: 1000 },
)
expect(result.current.isLoaded).toBeTruthy()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { renderHook, waitFor } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { useSegmentIntegrations } from '../../useSegmentIntegrations'

globalThis.fetch = vi.fn(async () =>
globalThis.fetch = vi.fn<() => Promise<Response>>(async () =>
Promise.resolve({ ok: false } as unknown as Response),
)

Expand All @@ -17,13 +17,19 @@ describe('cookieConsent - useSegmentIntegrations', () => {
}),
)

await waitFor(() => {
expect(result.current.integrations).toStrictEqual([])
})
await waitFor(
() => {
expect(result.current.integrations).toStrictEqual([])
},
{ timeout: 1000 },
)

await waitFor(() => {
expect(globalThis.fetch).toHaveBeenCalled()
})
await waitFor(
() => {
expect(globalThis.fetch).toHaveBeenCalled()
},
{ timeout: 1000 },
)

expect(result.current.isLoaded).toBeTruthy()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { renderHook, waitFor } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { useSegmentIntegrations } from '../../useSegmentIntegrations'

globalThis.fetch = vi.fn(async () => Promise.reject(new Error('randomError')))
globalThis.fetch = vi.fn<() => Promise<Response>>(async () =>
Promise.reject(new Error('randomError')),
)

describe('cookieConsent - useSegmentIntegrations', () => {
it('should call segment and return empty array if any error occurs in the fetch', async () => {
Expand All @@ -15,13 +17,19 @@ describe('cookieConsent - useSegmentIntegrations', () => {
}),
)

await waitFor(() => {
expect(result.current.integrations).toStrictEqual([])
})
await waitFor(
() => {
expect(result.current.integrations).toStrictEqual([])
},
{ timeout: 1000 },
)

await waitFor(() => {
expect(globalThis.fetch).toHaveBeenCalled()
})
await waitFor(
() => {
expect(globalThis.fetch).toHaveBeenCalled()
},
{ timeout: 1000 },
)
expect(result.current.isLoaded).toBeTruthy()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { renderHook, waitFor } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { useSegmentIntegrations } from '../../useSegmentIntegrations'

globalThis.fetch = vi.fn(async () =>
globalThis.fetch = vi.fn<() => Promise<Response>>(async () =>
Promise.resolve({
json: async () =>
Promise.resolve([
{
category: 'Analytics',
creationName: 'Google Analytics',
description:
'Google Universal Analytics is the most popular analytics tool for the web. Its free and provides a wide range of features. Its especially good at measuring traffic sources and ad campaigns.',
'Google Universal Analytics is the most popular analytics tool for the web. It's free and provides a wide range of features. It's especially good at measuring traffic sources and ad campaigns.',
name: 'Google Universal Analytics',
website: 'http://google.com/analytics',
},
Expand Down Expand Up @@ -98,7 +98,14 @@ describe('cookieConsent - useSegmentIntegrations', () => {
name: 'Amplitude (Actions)',
},
])
})
}, { timeout: 1000 })

await waitFor(() => {
expect(globalThis.fetch).toHaveBeenCalled()
}, { timeout: 1000 })
expect(result.current.isLoaded).toBeTruthy()
})
})

await waitFor(() => {
expect(globalThis.fetch).toHaveBeenCalled()
Expand Down
Loading
Loading