Skip to content

Commit

Permalink
fix: import file properly
Browse files Browse the repository at this point in the history
  • Loading branch information
imranbarbhuiya committed Jul 16, 2023
1 parent 0b81611 commit 1c884b7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const glob = new Glob(options.inputs, {
});

let errorCount = 0;
let warningCount = 0;

for await (const file of glob) {
log(`Parsing ${file}`, 'debug', options);
Expand All @@ -68,6 +69,7 @@ for await (const file of glob) {
for (const node of translationNodes) {
if (!node.isStaticKey) {
log(new ValidationError('Dynamic keys are not supported yet. Skipping', node.path, node.positions), 'warn', options);
warningCount++;
} else if (!node.key || !node.namespace) {
log(new ValidationError('Missing translation key or namespace', node.path, node.positions), 'error', options);
errorCount++;
Expand All @@ -79,9 +81,9 @@ for await (const file of glob) {
}

if (errorCount > 0) {
log(`Found ${errorCount} errors`, 'error', options);
log(`Found ${errorCount} errors and ${warningCount} warnings`, 'info', options);
process.exit(1);
} else {
log(`Found ${errorCount} errors`, 'info', options);
log(`Found ${errorCount} errors and ${warningCount} warnings`, 'info', options);
process.exit(0);
}
3 changes: 2 additions & 1 deletion src/parseOptionsFile.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import process from 'node:process';
import { URL } from 'node:url';

export type LogLevel = 'debug' | 'error' | 'info' | 'warn';
Expand Down Expand Up @@ -96,7 +97,7 @@ export type OptionsWithDefault = typeof defaultOption;

export async function parseOptionsFile(cliOptions: OptionsWithDefault): Promise<OptionsWithDefault> {
const config = cliOptions.config;
const configUrl = new URL(config, import.meta.url);
const configUrl = new URL(config, process.cwd());
const options = await import(configUrl.toString()).catch(() => ({}));

return {
Expand Down
3 changes: 2 additions & 1 deletion src/validateKey.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import process from 'node:process';
import { URL } from 'node:url';

import { ValidationError } from './Error.js';
Expand Down Expand Up @@ -27,7 +28,7 @@ export const validateKey = async (node: TranslationNode, options: OptionsWithDef

log(`Fetching translation keys from ${filePath}`, 'debug', options);

const url = new URL(filePath, import.meta.url);
const url = new URL(filePath, process.cwd());

const json: Record<string, unknown> = await importLocaleFile(url.toString()).catch(() => ({}));

Expand Down

0 comments on commit 1c884b7

Please sign in to comment.