mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
ci: @n8n/task-runner
package setup (no-changelog) (#11067)
This commit is contained in:
parent
4546649c61
commit
49c71469f4
|
@ -1,59 +0,0 @@
|
|||
{
|
||||
"name": "@n8n/task-runner",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"description": "",
|
||||
"main": "dist/start.js",
|
||||
"scripts": {
|
||||
"start": "node dist/start.js",
|
||||
"dev": "pnpm build && pnpm start",
|
||||
"build": "tsc -p ./tsconfig.build.json",
|
||||
"test": "jest",
|
||||
"lint": "eslint .",
|
||||
"lintfix": "eslint . --fix",
|
||||
"watch": "tsc -w -p ./tsconfig.build.json"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.15",
|
||||
"pnpm": ">=9.5"
|
||||
},
|
||||
"files": [
|
||||
"src/",
|
||||
"dist/",
|
||||
"package.json",
|
||||
"tsconfig.json"
|
||||
],
|
||||
"main": "dist/start.js",
|
||||
"module": "src/start.ts",
|
||||
"types": "dist/start.d.ts",
|
||||
"packageManager": "pnpm@9.6.0",
|
||||
"devDependencies": {
|
||||
"@n8n_io/eslint-config": "^0.0.2",
|
||||
"@types/jest": "^29.5.0",
|
||||
"@types/node": "^18.13.0",
|
||||
"@types/ws": "^8.5.12",
|
||||
"@typescript-eslint/eslint-plugin": "^6.1.0",
|
||||
"eslint": "^8.38.0",
|
||||
"eslint-config-airbnb-typescript": "^17.1.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-n8n-local-rules": "^1.0.0",
|
||||
"eslint-plugin-prettier": "^5.0.0",
|
||||
"eslint-plugin-unicorn": "^48.0.0",
|
||||
"eslint-plugin-unused-imports": "^3.0.0",
|
||||
"jest": "^29.5.0",
|
||||
"nodemon": "^2.0.20",
|
||||
"prettier": "^3.0.0",
|
||||
"ts-jest": "^29.1.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsc-alias": "^1.8.7",
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"jmespath": "^0.16.0",
|
||||
"luxon": "^3.5.0",
|
||||
"n8n-workflow": "workspace:*",
|
||||
"n8n-core": "workspace:*",
|
||||
"nanoid": "^3.3.6",
|
||||
"ws": "^8.18.0"
|
||||
}
|
||||
}
|
29
packages/@n8n/task-runner/package.json
Normal file
29
packages/@n8n/task-runner/package.json
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "@n8n/task-runner",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"clean": "rimraf dist .turbo",
|
||||
"start": "node dist/start.js",
|
||||
"dev": "pnpm build && pnpm start",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"build": "tsc -p ./tsconfig.build.json",
|
||||
"format": "biome format --write src",
|
||||
"format:check": "biome ci src",
|
||||
"test": "echo \"Error: no tests in this package\" && exit 0",
|
||||
"lint": "eslint . --quiet",
|
||||
"lintfix": "eslint . --fix",
|
||||
"watch": "tsc -p tsconfig.build.json --watch"
|
||||
},
|
||||
"main": "dist/start.js",
|
||||
"module": "src/start.ts",
|
||||
"types": "dist/start.d.ts",
|
||||
"files": [
|
||||
"dist/**/*"
|
||||
],
|
||||
"dependencies": {
|
||||
"n8n-workflow": "workspace:*",
|
||||
"n8n-core": "workspace:*",
|
||||
"nanoid": "^3.3.6",
|
||||
"ws": "^8.18.0"
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
import { ApplicationError } from 'n8n-workflow';
|
||||
import * as a from 'node:assert/strict';
|
||||
|
||||
export type AuthOpts = {
|
||||
|
@ -23,7 +24,9 @@ export async function authenticate(opts: AuthOpts) {
|
|||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Invalid response status ${response.status}: ${await response.text()}`);
|
||||
throw new ApplicationError(
|
||||
`Invalid response status ${response.status}: ${await response.text()}`,
|
||||
);
|
||||
}
|
||||
|
||||
const { data } = (await response.json()) as { data: { token: string } };
|
||||
|
@ -34,9 +37,11 @@ export async function authenticate(opts: AuthOpts) {
|
|||
} catch (e) {
|
||||
console.error(e);
|
||||
const error = e as Error;
|
||||
|
||||
throw new Error(`Could not connect to n8n message broker ${opts.n8nUri}: ${error.message}`, {
|
||||
cause: error,
|
||||
});
|
||||
throw new ApplicationError(
|
||||
`Could not connect to n8n message broker ${opts.n8nUri}: ${error.message}`,
|
||||
{
|
||||
cause: error,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
import { runInNewContext, type Context } from 'node:vm';
|
||||
import * as a from 'node:assert';
|
||||
|
||||
import { getAdditionalKeys } from 'n8n-core';
|
||||
import {
|
||||
type INode,
|
||||
type INodeType,
|
||||
|
@ -8,8 +6,6 @@ import {
|
|||
type IWorkflowExecuteAdditionalData,
|
||||
WorkflowDataProxy,
|
||||
type WorkflowParameters,
|
||||
} from 'n8n-workflow';
|
||||
import {
|
||||
type IDataObject,
|
||||
type IExecuteData,
|
||||
type INodeExecutionData,
|
||||
|
@ -19,7 +15,8 @@ import {
|
|||
Workflow,
|
||||
type WorkflowExecuteMode,
|
||||
} from 'n8n-workflow';
|
||||
import { getAdditionalKeys } from 'n8n-core';
|
||||
import * as a from 'node:assert';
|
||||
import { runInNewContext, type Context } from 'node:vm';
|
||||
|
||||
import type { TaskResultData } from './runner-types';
|
||||
import { type Task, TaskRunner } from './task-runner';
|
|
@ -1,10 +1,8 @@
|
|||
import { ApplicationError, ensureError } from 'n8n-workflow';
|
||||
import * as a from 'node:assert/strict';
|
||||
import { ensureError } from 'n8n-workflow';
|
||||
|
||||
import { JsTaskRunner } from './code';
|
||||
import { authenticate } from './authenticator';
|
||||
|
||||
let _runner: JsTaskRunner;
|
||||
import { JsTaskRunner } from './code';
|
||||
|
||||
type Config = {
|
||||
n8nUri: string;
|
||||
|
@ -16,7 +14,7 @@ function readAndParseConfig(): Config {
|
|||
const authToken = process.env.N8N_RUNNERS_AUTH_TOKEN;
|
||||
const grantToken = process.env.N8N_RUNNERS_GRANT_TOKEN;
|
||||
if (!authToken && !grantToken) {
|
||||
throw new Error(
|
||||
throw new ApplicationError(
|
||||
'Missing task runner authentication. Use either N8N_RUNNERS_AUTH_TOKEN or N8N_RUNNERS_GRANT_TOKEN to configure it',
|
||||
);
|
||||
}
|
||||
|
@ -42,7 +40,7 @@ void (async function start() {
|
|||
}
|
||||
|
||||
const wsUrl = `ws://${config.n8nUri}/runners/_ws`;
|
||||
_runner = new JsTaskRunner('javascript', wsUrl, grantToken, 5);
|
||||
new JsTaskRunner('javascript', wsUrl, grantToken, 5);
|
||||
})().catch((e) => {
|
||||
const error = ensureError(e);
|
||||
console.error('Task runner failed to start', { error });
|
|
@ -1,7 +1,7 @@
|
|||
import { URL } from 'node:url';
|
||||
import { ApplicationError, ensureError } from 'n8n-workflow';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { URL } from 'node:url';
|
||||
import { type MessageEvent, WebSocket } from 'ws';
|
||||
import { ensureError } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
RPC_ALLOW_LIST,
|
||||
|
@ -267,7 +267,7 @@ export abstract class TaskRunner {
|
|||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
async executeTask(_task: Task): Promise<TaskResultData> {
|
||||
throw new Error('Unimplemented');
|
||||
throw new ApplicationError('Unimplemented');
|
||||
}
|
||||
|
||||
async requestData<T = unknown>(
|
||||
|
@ -354,7 +354,7 @@ export abstract class TaskRunner {
|
|||
obj = obj[s];
|
||||
return;
|
||||
}
|
||||
obj[s] = async (...args: unknown[]) => this.makeRpcCall(taskId, r, args);
|
||||
obj[s] = async (...args: unknown[]) => await this.makeRpcCall(taskId, r, args);
|
||||
});
|
||||
}
|
||||
return rpcObject;
|
|
@ -1,10 +1,11 @@
|
|||
{
|
||||
"extends": ["./tsconfig.json", "../../../tsconfig.build.json"],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"rootDir": "src",
|
||||
"outDir": "dist",
|
||||
"tsBuildInfoFile": "dist/build.tsbuildinfo"
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
"exclude": ["test/**", "src/**/__tests__/**"]
|
||||
"exclude": ["src/**/__tests__/**"]
|
||||
}
|
|
@ -2,13 +2,11 @@
|
|||
"extends": ["../../../tsconfig.json", "../../../tsconfig.backend.json"],
|
||||
"compilerOptions": {
|
||||
"rootDir": ".",
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"baseUrl": "src",
|
||||
"paths": {
|
||||
"@/*": ["./*"]
|
||||
},
|
||||
"tsBuildInfoFile": "dist/typecheck.tsbuildinfo"
|
||||
},
|
||||
"include": ["src/**/*.ts", "test/**/*.ts"]
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
553
pnpm-lock.yaml
553
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue