Skip to content

Commit b9300f4

Browse files
authored
refactor: replace fileURLToPath with import.meta.dirname (#2366)
1 parent 4da792c commit b9300f4

9 files changed

+14
-22
lines changed

playwright.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import process from 'node:process'
2-
import { fileURLToPath } from 'node:url'
2+
import { join } from 'node:path'
33
import { defineConfig, devices } from '@playwright/test'
44
import type { ConfigOptions } from '@nuxt/test-utils/playwright'
55

@@ -19,14 +19,14 @@ export default defineConfig<ConfigOptions>({
1919
timeout: 60_000,
2020
},
2121
// Start/stop mock connector server before/after all tests (teardown via returned closure)
22-
globalSetup: fileURLToPath(new URL('./test/e2e/global-setup.ts', import.meta.url)),
22+
globalSetup: join(import.meta.dirname, 'test/e2e/global-setup.ts'),
2323
// We currently only test on one browser on one platform
2424
snapshotPathTemplate: '{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{ext}',
2525
use: {
2626
baseURL,
2727
trace: 'on-first-retry',
2828
nuxt: {
29-
rootDir: fileURLToPath(new URL('.', import.meta.url)),
29+
rootDir: import.meta.dirname,
3030
host: baseURL,
3131
},
3232
},

scripts/compare-translations.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ import type { LocaleObject } from '@nuxtjs/i18n'
33
import * as process from 'node:process'
44
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
55
import { basename, join, resolve } from 'node:path'
6-
import { fileURLToPath } from 'node:url'
76
import { deepCopy } from '@intlify/shared'
87
import { countryLocaleVariants, currentLocales } from '../config/i18n.ts'
98
import { COLORS } from './utils.ts'
109

11-
const LOCALES_DIRECTORY = fileURLToPath(new URL('../i18n/locales', import.meta.url))
10+
const LOCALES_DIRECTORY = join(import.meta.dirname, '../i18n/locales')
1211
const REFERENCE_FILE_NAME = 'en.json'
1312

1413
type NestedObject = { [key: string]: unknown }

scripts/find-invalid-translations.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/* eslint-disable no-console */
22
import { join } from 'node:path'
3-
import { fileURLToPath } from 'node:url'
43
import { createI18NReport, type I18NItem } from 'vue-i18n-extract'
54
import { colors } from './utils/colors.ts'
65

7-
const LOCALES_DIRECTORY = fileURLToPath(new URL('../i18n/locales', import.meta.url))
6+
const LOCALES_DIRECTORY = join(import.meta.dirname, '../i18n/locales')
87
const REFERENCE_FILE_NAME = 'en.json'
98
const VUE_FILES_GLOB = './app/**/*.?(vue|ts|js)'
109

scripts/generate-fixtures.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212

1313
import { writeFileSync, mkdirSync, existsSync } from 'node:fs'
1414
import { dirname, join } from 'node:path'
15-
import { fileURLToPath } from 'node:url'
1615

17-
const FIXTURES_DIR = fileURLToPath(new URL('../test/fixtures', import.meta.url))
16+
const FIXTURES_DIR = join(import.meta.dirname, '../test/fixtures')
1817

1918
const NPM_REGISTRY = 'https://registry.npmjs.org'
2019
const NPM_API = 'https://api.npmjs.org'

scripts/generate-i18n-schema.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/* oxlint-disable no-console */
22
import { readFile, writeFile } from 'node:fs/promises'
33
import { join } from 'node:path'
4-
import { fileURLToPath } from 'node:url'
54
import { colors } from './utils/colors.ts'
65

7-
const I18N_DIRECTORY = fileURLToPath(new URL('../i18n', import.meta.url))
6+
const I18N_DIRECTORY = join(import.meta.dirname, '../i18n')
87
const LOCALES_DIRECTORY = join(I18N_DIRECTORY, 'locales')
98
const REFERENCE_FILE_NAME = 'en.json'
109
const SCHEMA_FILE_NAME = 'schema.json'

scripts/remove-unused-translations.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/* eslint-disable no-console */
22
import { join } from 'node:path'
3-
import { fileURLToPath } from 'node:url'
43
import { createI18NReport, type I18NItem } from 'vue-i18n-extract'
54
import { colors } from './utils/colors.ts'
65
import { readdir, readFile, writeFile } from 'node:fs/promises'
76

8-
const LOCALES_DIRECTORY = fileURLToPath(new URL('../i18n/locales', import.meta.url))
7+
const LOCALES_DIRECTORY = join(import.meta.dirname, '../i18n/locales')
98
const REFERENCE_FILE_NAME = 'en.json'
109
const VUE_FILES_GLOB = './app/**/*.?(vue|ts|js)'
1110

scripts/unocss-checker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Dirent } from 'node:fs'
22
import { glob, readFile } from 'node:fs/promises'
3-
import { fileURLToPath } from 'node:url'
43
import { resolve } from 'node:path'
54
import { createGenerator } from 'unocss'
65
import { presetRtl } from '../uno-preset-rtl.ts'
@@ -9,7 +8,7 @@ import { COLORS } from './utils.ts'
98
import { presetWind4 } from 'unocss'
109

1110
const argvFiles = process.argv.slice(2)
12-
const APP_DIRECTORY = fileURLToPath(new URL('../app', import.meta.url))
11+
const APP_DIRECTORY = resolve(import.meta.dirname, '../app')
1312

1413
async function checkFile(path: Dirent): Promise<string | undefined> {
1514
if (path.isDirectory() || !path.name.endsWith('.vue')) {

test/unit/a11y-component-coverage.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import fs from 'node:fs'
1212
import path from 'node:path'
1313
import { assert, describe, it } from 'vitest'
14-
import { fileURLToPath } from 'node:url'
1514

1615
/**
1716
* Components explicitly skipped from a11y testing with reasons.
@@ -152,9 +151,9 @@ function getTestedComponents(
152151
}
153152

154153
describe('a11y component test coverage', () => {
155-
const componentsDir = fileURLToPath(new URL('../../app/components', import.meta.url))
156-
const componentsDtsPath = fileURLToPath(new URL('../../.nuxt/components.d.ts', import.meta.url))
157-
const testFilePath = fileURLToPath(new URL('../nuxt/a11y.spec.ts', import.meta.url))
154+
const componentsDir = path.join(import.meta.dirname, '../../app/components')
155+
const componentsDtsPath = path.join(import.meta.dirname, '../../.nuxt/components.d.ts')
156+
const testFilePath = path.join(import.meta.dirname, '../nuxt/a11y.spec.ts')
158157

159158
it('should have accessibility tests for all components (or be explicitly skipped)', () => {
160159
// Get all Vue components

vite.config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { fileURLToPath } from 'node:url'
21
import { defineConfig } from 'vite-plus'
32
import { defineVitestProject } from '@nuxt/test-utils/config'
43
import { playwright } from 'vite-plus/test/browser-playwright'
54

6-
const rootDir = fileURLToPath(new URL('.', import.meta.url))
5+
const rootDir = import.meta.dirname
76

87
export default defineConfig({
98
run: {
@@ -187,7 +186,7 @@ export default defineConfig({
187186
environment: 'nuxt',
188187
environmentOptions: {
189188
nuxt: {
190-
rootDir: fileURLToPath(new URL('.', import.meta.url)),
189+
rootDir,
191190
overrides: {
192191
vue: {
193192
runtimeCompiler: true,

0 commit comments

Comments
 (0)