Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throwing an error when using in a pnpm monorepo #1040

Open
sibelius opened this issue Aug 5, 2024 · 2 comments
Open

throwing an error when using in a pnpm monorepo #1040

sibelius opened this issue Aug 5, 2024 · 2 comments

Comments

@sibelius
Copy link

sibelius commented Aug 5, 2024

🐛 Bug Report

When running parser inside a monorepo, it is throwing an error

NODE_OPTIONS='--enable-source-maps --trace-warnings --trace-deprecation' i18next --config i18next-parser.config.js


i18next Parser
--------------
  Input:
Output: packages/i18n/src/locales/$LOCALE.json

node:events:497
throw er; // Unhandled 'error' event
^

Error: ENOENT: no such file or directory, stat 'app/packages/testutils/node_modules/.bin/nanoid'
Emitted 'error' event on Transform instance at:
  at ReadableState.afterDestroy (app/node_modules/streamx/index.js:500:19)
at Transform._destroy (app/node_modules/streamx/index.js:636:5)
at ReadableState.updateNonPrimary (app/node_modules/streamx/index.js:393:16)
at ReadableState.update (app/node_modules/streamx/index.js:374:71)
at ReadableState.updateReadNT (app/node_modules/streamx/index.js:543:10)
at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {

To Reproduce

try to run this inside a pnpm monorepo

module.exports = {
  input: [
    'packages/**/src/**/*.{ts,tsx}',
    '!packages/**/*.spec.{ts,tsx}',
    '!packages/**/*.graphql.{ts,tsx}',
    '!**/node_modules/**/*',
    '!**/.bin/**',
    // Use ! to filter out files or directories
    // '!app/**/*.spec.{js,jsx}',
    // '!app/i18n/**',
    // '!**/node_modules/**',
  ],
  output: 'packages/i18n/src/locales/$LOCALE.json',

  contextSeparator: '_',
  pluralSeparator: '_',
  namespaceSeparator: false,
  keySeparator: false,

  // resetDefaultValueLocale: 'en',
  resetDefaultValueLocale: null,
  verbose: true,
  keepRemoved: false,
  failOnWarnings: false,
  failOnUpdate: false,
  createOldCatalogs: false,

  locales: ['pt-BR', 'en', 'es'],

  indentation: 2,
  lineEnding: 'lf',

  defaultNamespace: 'translation',
  defaultValue: (lng, ns, key) => {
    if (process.env.I18N_KEY_DEFAULT === 'true') {
      return key;
    }

    if (lng === 'en') {
      // Return key as the default value for English language
      return key;
    }

    // Return the string '__NOT_TRANSLATED__' for other languages
    return '__STRING_NOT_TRANSLATED__';
  },

  lexers: {
    ts: [
      {
        lexer: 'JavascriptLexer',
        functions: ['t', 'context.t'],
      },
    ],
    tsx: [
      {
        lexer: 'JsxLexer',
        functions: ['t', 'context.t'],
      },
    ],
  },

  // sort: true,
  sort: (a, b) => {
    if (a > b) {
      return 1;
    }

    if (a < b) {
      return -1;
    }

    return 0;
  },
};

Expected behavior

A clear and concise description of what you expected to happen.

it should work

// Paste the expected results here

Your Environment

  • runtime version: node 20
  • i18next version: 9
  • os: Mac, Windows, Linux: mac
@bobbonius
Copy link

Experiencing a similar error in a monorepo

@sibelius
Copy link
Author

sibelius commented Aug 7, 2024

here is a version that works well for now

import fs from 'fs/promises';
import { globSync } from 'glob';
import { transform as Transform } from 'i18next-parser';

import config from '../../i18next-parser.config';

const transform = new Transform({
  ...config,
});

const pattern = config.input.find((s) => !s.startsWith('!'));
const ignore = config.input
  .filter((s) => s.startsWith('!'))
  .map((s) => s.replace('!', ''));

(async () => {
  const files = globSync(pattern, { ignore });

  transform.on('data', (file) => {
    // eslint-disable-next-line
    console.log(file.path);
    fs.writeFile(file.path, file.contents);
  });

  await Promise.all(
    files.map((path) =>
      transform._transform({ path, isBuffer: () => false }, 'utf8', () => {}),
    ),
  );

  transform._flush(() => {});
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants