diff options
| author | ST-DDT <[email protected]> | 2023-11-14 17:28:37 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-14 17:28:37 +0100 |
| commit | 932a87502c4b3ab34edbba6c46f6c9c1c91d5bf3 (patch) | |
| tree | 3956a12a9b2836e5d9404d047b1ec54b2ffef2b7 /scripts | |
| parent | 7e3c92e802614ae5e9f621d9e679dfd6f6d63cf1 (diff) | |
| download | faker-932a87502c4b3ab34edbba6c46f6c9c1c91d5bf3.tar.xz faker-932a87502c4b3ab34edbba6c46f6c9c1c91d5bf3.zip | |
infra(unicorn): prefer-module (#2510)
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/apidoc/utils.ts | 5 | ||||
| -rw-r--r-- | scripts/generate-locales.ts | 13 |
2 files changed, 10 insertions, 8 deletions
diff --git a/scripts/apidoc/utils.ts b/scripts/apidoc/utils.ts index 18176da5..f26c6cdd 100644 --- a/scripts/apidoc/utils.ts +++ b/scripts/apidoc/utils.ts @@ -1,5 +1,6 @@ import { createHash } from 'node:crypto'; -import { resolve } from 'node:path'; +import { dirname, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; import type { Method } from '../../docs/.vitepress/components/api-docs/method'; // Types @@ -31,7 +32,7 @@ export interface DocsApiDiff { // Paths -const pathRoot = resolve(__dirname, '..', '..'); +const pathRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..'); export const pathDocsDir = resolve(pathRoot, 'docs'); const pathPublicDir = resolve(pathDocsDir, 'public'); export const nameDocsDiffIndexFile = 'api-diff-index.json'; diff --git a/scripts/generate-locales.ts b/scripts/generate-locales.ts index d2e9513e..ebc06670 100644 --- a/scripts/generate-locales.ts +++ b/scripts/generate-locales.ts @@ -21,7 +21,8 @@ import { readFileSync, writeFileSync, } from 'node:fs'; -import { resolve } from 'node:path'; +import { dirname, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; import type { Options } from 'prettier'; import { format } from 'prettier'; import options from '../.prettierrc.js'; @@ -29,7 +30,7 @@ import type { LocaleDefinition, MetadataDefinition } from '../src/definitions'; // Constants -const pathRoot = resolve(__dirname, '..'); +const pathRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..'); const pathLocale = resolve(pathRoot, 'src', 'locale'); const pathLocales = resolve(pathRoot, 'src', 'locales'); const pathLocaleIndex = resolve(pathLocale, 'index.ts'); @@ -359,8 +360,8 @@ async function normalizeLocaleFile(filePath: string, definitionKey: string) { } const fileContentPreData = fileContent.substring(0, compareIndex); - // eslint-disable-next-line @typescript-eslint/no-var-requires - const localeData = normalizeDataRecursive(require(filePath).default); + const fileImport = await import(`file:${filePath}`); + const localeData = normalizeDataRecursive(fileImport.default); // We reattach the content before the actual data implementation to keep stuff like comments. // In the long term we should probably define a whether we want those in the files at all. @@ -388,8 +389,8 @@ async function main(): Promise<void> { const pathMetadata = resolve(pathModules, 'metadata.ts'); let localeTitle = 'No title found'; try { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const metadata: MetadataDefinition = require(pathMetadata).default; + const metadataImport = await import(`file:${pathMetadata}`); + const metadata: MetadataDefinition = metadataImport.default; const { title } = metadata; if (!title) { throw new Error( |
