n8n-nodes-fasttext-language-detector 0.1.0 → 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.
@@ -35,7 +35,6 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.FastTextLanguageDetector = void 0;
37
37
  const n8n_workflow_1 = require("n8n-workflow");
38
- const fastText = __importStar(require("fasttext.js"));
39
38
  const fs = __importStar(require("fs"));
40
39
  class FastTextLanguageDetector {
41
40
  constructor() {
@@ -194,9 +193,33 @@ class FastTextLanguageDetector {
194
193
  if (!fs.existsSync(modelPath)) {
195
194
  throw new n8n_workflow_1.ApplicationError(`Model file not found: ${modelPath}`, { level: 'error' });
196
195
  }
197
- // Загружаем модель
198
- model = new fastText.Classifier(modelPath);
199
- FastTextLanguageDetector.modelCache.set(modelPath, model);
196
+ // Динамически загружаем fasttext.js только когда он нужен
197
+ // Это предотвращает загрузку WASM при старте n8n
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);
200
223
  }
201
224
  }
202
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.0",
3
+ "version": "0.1.4",
4
4
  "description": "n8n node for language detection using fastText",
5
5
  "author": {
6
6
  "name": "Your Name",
@@ -8,49 +8,50 @@
8
8
  },
9
9
  "license": "MIT",
10
10
  "keywords": [
11
- "n8n-community-node-package",
12
- "fasttext",
13
- "language-detection",
14
- "nlp"
11
+ "n8n-community-node-package",
12
+ "fasttext",
13
+ "language-detection",
14
+ "nlp"
15
15
  ],
16
16
  "main": "index.js",
17
17
  "scripts": {
18
- "build": "rm -rf dist && tsc && gulp build:icons",
19
- "dev": "npm run build && npx n8n",
20
- "dev:watch": "tsc --watch",
21
- "format": "prettier nodes credentials --write",
22
- "lint": "eslint \"nodes/**/*.ts\" \"credentials/**/*.ts\" \"package.json\"",
23
- "lintfix": "eslint \"nodes/**/*.ts\" \"credentials/**/*.ts\" \"package.json\" --fix",
24
- "prepublishOnly": "npm run build && npm run lint -s"
18
+ "build": "rm -rf dist && tsc && gulp build:icons",
19
+ "dev": "npm run build && npx n8n",
20
+ "dev:watch": "tsc --watch",
21
+ "format": "prettier nodes credentials --write",
22
+ "lint": "eslint \"nodes/**/*.ts\" \"credentials/**/*.ts\" \"package.json\"",
23
+ "lintfix": "eslint \"nodes/**/*.ts\" \"credentials/**/*.ts\" \"package.json\" --fix",
24
+ "prepublishOnly": "npm run build && npm run lint -s"
25
25
  },
26
26
  "files": [
27
- "dist"
27
+ "dist",
28
+ "index.js"
28
29
  ],
29
30
  "n8n": {
30
- "n8nNodesApiVersion": 1,
31
- "credentials": [
32
- "dist/credentials/FastTextModel.credentials.js"
33
- ],
34
- "nodes": [
35
- "dist/nodes/FastTextLanguageDetector/FastTextLanguageDetector.node.js"
36
- ]
31
+ "n8nNodesApiVersion": 1,
32
+ "credentials": [
33
+ "dist/credentials/FastTextModel.credentials.js"
34
+ ],
35
+ "nodes": [
36
+ "dist/nodes/FastTextLanguageDetector/FastTextLanguageDetector.node.js"
37
+ ]
37
38
  },
38
39
  "devDependencies": {
39
- "@types/node": "^20.10.0",
40
- "@typescript-eslint/parser": "^6.13.0",
41
- "@typescript-eslint/eslint-plugin": "^6.13.0",
42
- "eslint": "^8.57.1",
43
- "eslint-plugin-n8n-nodes-base": "^1.11.0",
44
- "gulp": "^4.0.2",
45
- "n8n": "*",
46
- "n8n-workflow": "*",
47
- "prettier": "^3.1.0",
48
- "typescript": "^5.3.0"
40
+ "@types/node": "^20.10.0",
41
+ "@typescript-eslint/parser": "^6.13.0",
42
+ "@typescript-eslint/eslint-plugin": "^6.13.0",
43
+ "eslint": "^8.57.1",
44
+ "eslint-plugin-n8n-nodes-base": "^1.11.0",
45
+ "gulp": "^4.0.2",
46
+ "n8n": "*",
47
+ "n8n-workflow": "*",
48
+ "prettier": "^3.1.0",
49
+ "typescript": "^5.3.0"
49
50
  },
50
51
  "dependencies": {
51
- "fasttext.js": "^1.1.4"
52
+ "fasttext.js": "^1.1.4"
52
53
  },
53
54
  "peerDependencies": {
54
- "n8n-workflow": "*"
55
+ "n8n-workflow": "*"
55
56
  }
56
- }
57
+ }