n8n-nodes-fasttext-language-detector 0.1.5 → 0.1.7

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.
@@ -36,6 +36,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.FastTextLanguageDetector = void 0;
37
37
  const n8n_workflow_1 = require("n8n-workflow");
38
38
  const fs = __importStar(require("fs"));
39
+ // Полифилл для fetch API, если не доступен глобально
40
+ if (typeof globalThis.fetch === 'undefined') {
41
+ try {
42
+ // Пробуем использовать node-fetch, если установлен
43
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
44
+ const nodeFetch = require('node-fetch');
45
+ globalThis.fetch = nodeFetch;
46
+ globalThis.Headers = nodeFetch.Headers;
47
+ globalThis.Request = nodeFetch.Request;
48
+ globalThis.Response = nodeFetch.Response;
49
+ }
50
+ catch (error) {
51
+ // Если node-fetch не установлен, выбросим ошибку при использовании
52
+ console.warn('fetch API not available. Install node-fetch or use Node.js 18+');
53
+ }
54
+ }
39
55
  class FastTextLanguageDetector {
40
56
  constructor() {
41
57
  this.description = {
@@ -195,17 +211,25 @@ class FastTextLanguageDetector {
195
211
  }
196
212
  // Динамически загружаем fasttext.js только когда он нужен
197
213
  // Это предотвращает загрузку WASM при старте n8n
198
- // Используем require для CommonJS модуля, обернутый в Promise
214
+ // ВАЖНО: используем прямой путь к lib/index.js для корректной загрузки
199
215
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-var-requires
200
216
  const fastTextModule = await new Promise((resolve, reject) => {
201
217
  try {
202
- // Используем require для загрузки CommonJS модуля
218
+ // Используем прямой путь к index.js для загрузки модуля
203
219
  // eslint-disable-next-line @typescript-eslint/no-var-requires
204
- const FastText = require('fasttext.js');
220
+ const FastText = require('fasttext.js/lib/index');
205
221
  resolve(FastText);
206
222
  }
207
223
  catch (error) {
208
- reject(error);
224
+ // Если прямой путь не работает, пробуем обычный require
225
+ try {
226
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
227
+ const FastText = require('fasttext.js');
228
+ resolve(FastText);
229
+ }
230
+ catch (fallbackError) {
231
+ reject(fallbackError);
232
+ }
209
233
  }
210
234
  });
211
235
  // fasttext.js экспортирует класс FastText напрямую
@@ -217,9 +241,11 @@ class FastTextLanguageDetector {
217
241
  throw new n8n_workflow_1.ApplicationError(`Failed to load fastText module: FastText class not found. Available exports: ${availableExports}`, { level: 'error' });
218
242
  }
219
243
  // Создаем экземпляр FastText с путем к модели
244
+ // ВАЖНО: включаем WASM для работы с fasttext.js
220
245
  const fastTextInstance = new FastTextClass({
221
246
  loadModel: modelPath,
222
247
  predict: {
248
+ wasm: true, // Включаем WASM
223
249
  mostlikely: topK,
224
250
  verbosity: 0,
225
251
  normalize: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-fasttext-language-detector",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "n8n node for language detection using fastText",
5
5
  "author": {
6
6
  "name": "Your Name",
@@ -38,8 +38,9 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "^20.10.0",
41
- "@typescript-eslint/parser": "^6.13.0",
41
+ "@types/node-fetch": "^2.6.13",
42
42
  "@typescript-eslint/eslint-plugin": "^6.13.0",
43
+ "@typescript-eslint/parser": "^6.13.0",
43
44
  "eslint": "^8.57.1",
44
45
  "eslint-plugin-n8n-nodes-base": "^1.11.0",
45
46
  "gulp": "^4.0.2",
@@ -49,7 +50,8 @@
49
50
  "typescript": "^5.3.0"
50
51
  },
51
52
  "dependencies": {
52
- "fasttext.js": "^1.1.4"
53
+ "fasttext.js": "^1.1.4",
54
+ "node-fetch": "^2.7.0"
53
55
  },
54
56
  "peerDependencies": {
55
57
  "n8n-workflow": "*"