n8n-nodes-fasttext-language-detector 0.1.1 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -195,9 +195,31 @@ class FastTextLanguageDetector {
195
195
  }
196
196
  // Динамически загружаем fasttext.js только когда он нужен
197
197
  // Это предотвращает загрузку WASM при старте n8n
198
- const fastText = await Promise.resolve().then(() => __importStar(require('fasttext.js')));
199
- model = new fastText.Classifier(modelPath);
200
- FastTextLanguageDetector.modelCache.set(modelPath, model);
198
+ // Используем require для CommonJS модуля, обернутый в Promise
199
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-var-requires
200
+ const fastTextModule = await new Promise((resolve, reject) => {
201
+ try {
202
+ // Используем require для загрузки CommonJS модуля
203
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
204
+ const fastText = require('fasttext.js');
205
+ resolve(fastText);
206
+ }
207
+ catch (error) {
208
+ reject(error);
209
+ }
210
+ });
211
+ // Обрабатываем разные варианты экспорта (CommonJS/ESM)
212
+ // fasttext.js может экспортировать через default или напрямую
213
+ const FastTextClassifier = fastTextModule.Classifier ||
214
+ (fastTextModule.default && fastTextModule.default.Classifier) ||
215
+ fastTextModule.default;
216
+ if (!FastTextClassifier || typeof FastTextClassifier !== 'function') {
217
+ const availableExports = Object.keys(fastTextModule).join(', ');
218
+ throw new n8n_workflow_1.ApplicationError(`Failed to load fastText module: Classifier not found. Available exports: ${availableExports}`, { level: 'error' });
219
+ }
220
+ const loadedModel = new FastTextClassifier(modelPath);
221
+ model = loadedModel;
222
+ FastTextLanguageDetector.modelCache.set(modelPath, loadedModel);
201
223
  }
202
224
  }
203
225
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-fasttext-language-detector",
3
- "version": "0.1.1",
3
+ "version": "0.1.4",
4
4
  "description": "n8n node for language detection using fastText",
5
5
  "author": {
6
6
  "name": "Your Name",