Skip to content

Commit 88c4b02

Browse files
authored
Merge pull request #525 from dnum-mi/tech/fix-project-on-windows
Tech/fix project on windows
2 parents 51d23a6 + 6337d32 commit 88c4b02

File tree

10 files changed

+37
-50
lines changed

10 files changed

+37
-50
lines changed

ci/check-exports.mjs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
import { fileURLToPath, URL } from 'url'
23
import { readFile, writeFile } from 'fs/promises'
34
import inquirer from 'inquirer'
45
import chalk from 'chalk'
@@ -7,22 +8,25 @@ import path from 'path'
78

89
const isCI = process.argv.includes('--ci')
910

10-
const __dirname = path.dirname(new URL(import.meta.url).pathname)
11+
const getNormalizedDir = (relativeDir) => fileURLToPath(new URL(relativeDir, import.meta.url))
1112

12-
const sfcs = await globby([path.resolve(__dirname, '../src/components/**/*.vue')])
13-
const componentsDir = path.resolve(__dirname, '../src/components')
13+
// const sfcs = await globby(fileURLToPath(new URL('../src/components/**/*.vue', import.meta.url)))
14+
const sfcs = await globby('src/components/**/*.vue')
1415

15-
const projectFn = component => 'export { default as ' + path.basename(component, '.vue') + ' } from \'' + component.replace(componentsDir, '.') + '\''
16+
const projectFn = component => 'export { default as ' + path.basename(component, '.vue') + ' } from \'' + component.replace('src/components', '.') + '\''
1617

1718
const correctComponentList = sfcs.map(projectFn).sort()
1819
const correctString = correctComponentList.join('\n') + '\n'
1920

20-
const index = await readFile(path.resolve(__dirname, '../src/components/index.js'))
21+
const srcIndexFullpath = getNormalizedDir('../src/components') + path.sep + 'index.js'
22+
const typesIndexFullpath = getNormalizedDir('../types/components') + path.sep + 'index.d.ts'
23+
24+
const index = await readFile(getNormalizedDir('../src/components') + '/index.js')
2125
const currentFileContent = index.toString()
2226

2327
if (currentFileContent !== correctString) {
2428
if (process.argv.includes('--fix')) {
25-
await writeFile(path.resolve(__dirname, '../src/components/index.js'), correctString)
29+
await writeFile(srcIndexFullpath, correctString)
2630
console.log('Fixed')
2731
process.exit(0)
2832
}
@@ -51,14 +55,14 @@ if (currentFileContent !== correctString) {
5155
}
5256

5357
if (onlyInCorrectList.length || onlyInCurrentFileList.length) {
54-
console.log('dans ' + chalk.yellow.bold(path.resolve(__dirname, '../src/components/index.js')))
58+
console.log('dans ' + chalk.yellow.bold(srcIndexFullpath))
5559
}
5660

5761
if (!isCI) {
5862
await inquirer.prompt(questions).then(async answers => {
5963
if (answers.fix.toLocaleLowerCase() === 'y') {
60-
await writeFile(path.resolve(__dirname, '../src/components/index.js'), correctString)
61-
await writeFile(path.resolve(__dirname, '../types/components/index.d.ts'), correctString)
64+
await writeFile(srcIndexFullpath, correctString)
65+
await writeFile(typesIndexFullpath, correctString)
6266
console.log(chalk.green.bold('Fichier corrigé !'))
6367
process.exit(0)
6468
}

src/components/DsfrButton/DsfrButtonGroup.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { fireEvent } from '@testing-library/dom'
33
import { render } from '@testing-library/vue'
44

55
// import '@gouvfr/dsfr/dist/core/core.module.js'
6-
import { spy } from '@/../tests/unit/test-utils.js'
6+
import { spy } from '@tests/unit/test-utils.js'
77

88
import DsfrButtonGroup from './DsfrButtonGroup.vue'
99

src/components/DsfrCallout/DsfrCallout.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { OhVueIcon as VIcon } from 'oh-vue-icons'
22
import { fireEvent, render } from '@testing-library/vue'
33

4-
import { spy } from '@/../tests/unit/test-utils.js'
4+
import { spy } from '@tests/unit/test-utils.js'
55

66
// import '@gouvfr/dsfr/dist/core/core.module.js'
77

src/components/DsfrNavigation/DsfrNavigation.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { render } from '@testing-library/vue'
44
import { createRouter, createWebHistory } from 'vue-router'
55
// import '@gouvfr/dsfr/dist/core/core.module.js'
66

7-
import { spy } from '@/../tests/unit/test-utils.js'
7+
import { spy } from '@tests/unit/test-utils.js'
88

99
import DsfrNavigation from './DsfrNavigation.vue'
1010

src/components/DsfrTable/DsfrTableCell.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { fireEvent, render } from '@testing-library/vue'
44
import DsfrTableCell from './DsfrTableCell.vue'
55
import DsfrTag from '../DsfrTag/DsfrTag.vue'
66

7-
import { spy } from '@/../tests/unit/test-utils.js'
7+
import { spy } from '@tests/unit/test-utils.js'
88

99
describe('DsfrTableCell', () => {
1010
it('should render simple cell', () => {

src/components/DsfrTable/DsfrTableHeader.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { fireEvent, render } from '@testing-library/vue'
33

44
import DsfrTableHeader from './DsfrTableHeader.vue'
55

6-
import { spy } from '@/../tests/unit/test-utils.js'
6+
import { spy } from '@tests/unit/test-utils.js'
77

88
describe('DsfrTableHeader', () => {
99
it('should render simple header cell', async () => {

src/components/DsfrTable/DsfrTableHeaders.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { fireEvent, render } from '@testing-library/vue'
33

44
import DsfrTableHeaders from './DsfrTableHeaders.vue'
55

6-
import { spy } from '@/../tests/unit/test-utils.js'
6+
import { spy } from '@tests/unit/test-utils.js'
77

88
describe('DsfrTableHeaders', () => {
99
it('should render simple header row', async () => {

src/components/DsfrTable/DsfrTableRow.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { fireEvent, render } from '@testing-library/vue'
22

33
import DsfrTableRow from './DsfrTableRow.vue'
44

5-
import { spy } from '@/../tests/unit/test-utils.js'
5+
import { spy } from '@tests/unit/test-utils.js'
66

77
describe('DsfrTableRow', () => {
88
it('should render simple row', () => {

vite.config.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { fileURLToPath, URL } from 'url'
12
import { dirname, resolve } from 'path'
23

34
import { defineConfig } from 'vite'
@@ -8,6 +9,8 @@ import visualizer from 'rollup-plugin-visualizer'
89

910
const projectDir = dirname(new URL(import.meta.url).pathname)
1011

12+
const getNormalizedDir = (relativeDir: string) => fileURLToPath(new URL(relativeDir, import.meta.url))
13+
1114
// https://vitejs.dev/config/
1215
export default defineConfig({
1316
plugins: [
@@ -17,11 +20,24 @@ export default defineConfig({
1720
}),
1821
visualizer(),
1922
],
23+
test: {
24+
globals: true,
25+
// environment: 'happy-dom',
26+
environment: 'jsdom',
27+
testTimeout: 2000,
28+
setupFiles: [
29+
'./tests/unit/vitest-setup.js',
30+
],
31+
},
2032
resolve: {
2133
alias: [
2234
{
2335
find: '@',
24-
replacement: resolve(projectDir, 'src'),
36+
replacement: getNormalizedDir('./src'),
37+
},
38+
{
39+
find: '@tests',
40+
replacement: getNormalizedDir('./tests'),
2541
},
2642
{
2743
find: 'vue',

vitest.config.js

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

0 commit comments

Comments
 (0)