Skip to content

Commit

Permalink
fix: wrapping of single string path in plugin arguments (close #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElMassimo committed Aug 9, 2022
1 parent e13d6aa commit 7f62e0f
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 35 deletions.
31 changes: 0 additions & 31 deletions .github/workflows/js-lint.yml

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Lint & Test

on: [push]

jobs:
build:
name: Lint & Test

strategy:
matrix:
os: [ubuntu-latest]
node: [14.x]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2.2.2
with:
version: 7.4.1

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'pnpm'

- run: pnpm install --frozen-lockfile

- name: Build
run: pnpm build

- name: Lint
run: pnpm lint

- name: Test
run: pnpm test
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@
"clean": "rm -rf ./dist",
"dev": "npm run build -- --watch",
"build": "tsup src/index.ts --dts --format cjs,esm --clean",
"lint": "lint-staged",
"lint": "eslint . --ext .ts,.js,.vue",
"postinstall": "husky install",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"prepublishOnly": "pinst --disable && npm run build",
"postpublish": "PACKAGE_VERSION=$(cat package.json | grep \\\"version\\\" | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag v$PACKAGE_VERSION && git push --tags && pinst --enable",
"release": "node scripts/release.cjs"
"release": "node scripts/release.cjs",
"test": "vitest"
},
"dependencies": {
"picocolors": "^1.0.0",
Expand All @@ -67,7 +68,8 @@
"semver": "^7.3.7",
"tsup": "^6.1.3",
"typescript": "^4.7.4",
"vite": "^3"
"vite": "^3",
"vitest": "^0.21.1"
},
"lint-staged": {
"*.{js,ts,tsx,jsx,vue}": [
Expand Down
116 changes: 116 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export interface Config {
root?: string
}

export function normalizePaths (root: string, path: string | string[]): string[] {
return (Array.isArray(path) ? path : [path]).map(path => resolve(root, path)).map(normalizePath)
}

/**
* Allows to automatically reload the page when a watched file changes.
*/
Expand All @@ -46,7 +50,7 @@ export default (paths: string | string[], config: Config = {}): PluginOption =>
configureServer ({ watcher, ws, config: { logger } }: ViteDevServer) {
const { root = process.cwd(), log = true, always = true, delay = 0 } = config

const files = Array.from(paths).map(path => resolve(root, path)).map(normalizePath)
const files = normalizePaths(root, paths)
const shouldReload = picomatch(files)
const checkReload = (path: string) => {
if (shouldReload(path)) {
Expand Down
18 changes: 18 additions & 0 deletions tests/paths.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { describe, expect, it } from 'vitest'
import { normalizePaths } from '../src'

const root = '/root'
const expectNormalized = (path: any) => expect(normalizePaths(root, path))

describe('normalizePaths', () => {
it('it handles strings and arrays', () => {
expectNormalized('/absolute/**/*.js')
.toEqual(['/absolute/**/*.js'])

expectNormalized('relative/**/*.vue')
.toEqual(['/root/relative/**/*.vue'])

expectNormalized(['/absolute/**/*.js', 'relative/**/*.vue'])
.toEqual(['/absolute/**/*.js', '/root/relative/**/*.vue'])
})
})

0 comments on commit 7f62e0f

Please sign in to comment.