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

feat(editor): Migrate codemirror-lang-n8n-expression into this monorepo (no-changelog) #9087

Merged
merged 21 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/units-tests-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ jobs:
if: ${{ inputs.collectCoverage == 'true' }}
uses: codecov/codecov-action@v3
with:
files: packages/@n8n/chat/coverage/cobertura-coverage.xml,packages/@n8n/nodes-langchain/coverage/cobertura-coverage.xml,packages/@n8n/permissions/coverage/cobertura-coverage.xml,packages/@n8n/client-oauth2/coverage/cobertura-coverage.xml,packages/cli/coverage/cobertura-coverage.xml,packages/core/coverage/cobertura-coverage.xml,packages/design-system/coverage/cobertura-coverage.xml,packages/editor-ui/coverage/cobertura-coverage.xml,packages/nodes-base/coverage/cobertura-coverage.xml,packages/workflow/coverage/cobertura-coverage.xml
files: packages/@n8n/chat/coverage/cobertura-coverage.xml,packages/@n8n/nodes-langchain/coverage/cobertura-coverage.xml,packages/@n8n/permissions/coverage/cobertura-coverage.xml,packages/@n8n/client-oauth2/coverage/cobertura-coverage.xml,packages/cli/coverage/cobertura-coverage.xml,packages/core/coverage/cobertura-coverage.xml,packages/design-system/coverage/cobertura-coverage.xml,packages/@n8n/codemirror-lang/coverage/cobertura-coverage.xml,packages/editor-ui/coverage/cobertura-coverage.xml,packages/nodes-base/coverage/cobertura-coverage.xml,packages/workflow/coverage/cobertura-coverage.xml
netroy marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"scripts": {
"preinstall": "node scripts/block-npm-install.js",
"build": "turbo run build",
"build:backend": "pnpm --filter=!@n8n/chat --filter=!n8n-design-system --filter=!n8n-editor-ui build",
"build:frontend": "pnpm --filter=@n8n/chat --filter=n8n-design-system --filter=n8n-editor-ui build",
"build:backend": "pnpm --filter=!@n8n/chat --filter=!@n8n/codemirror-lang --filter=!n8n-design-system --filter=!n8n-editor-ui build",
"build:frontend": "pnpm --filter=@n8n/chat --filter=@n8n/codemirror-lang --filter=n8n-design-system --filter=n8n-editor-ui build",
"typecheck": "turbo run typecheck",
"dev": "turbo run dev --parallel --filter=!n8n-design-system --filter=!@n8n/chat",
"dev:ai": "turbo run dev --parallel --filter=@n8n/nodes-langchain --filter=n8n --filter=n8n-core",
Expand All @@ -26,9 +26,9 @@
"start:tunnel": "./packages/cli/bin/n8n start --tunnel",
"start:windows": "cd packages/cli/bin && n8n",
"test": "turbo run test",
"test:backend": "pnpm --filter=!@n8n/chat --filter=!n8n-design-system --filter=!n8n-editor-ui --filter=!n8n-nodes-base test",
"test:backend": "pnpm --filter=!@n8n/chat --filter=!@n8n/codemirror-lang --filter=!n8n-design-system --filter=!n8n-editor-ui --filter=!n8n-nodes-base test",
"test:nodes": "pnpm --filter=n8n-nodes-base test",
"test:frontend": "pnpm --filter=@n8n/chat --filter=n8n-design-system --filter=n8n-editor-ui test",
"test:frontend": "pnpm --filter=@n8n/chat --filter=@n8n/codemirror-lang --filter=n8n-design-system --filter=n8n-editor-ui test",
"watch": "turbo run watch --parallel",
"webhook": "./packages/cli/bin/n8n webhook",
"worker": "./packages/cli/bin/n8n worker",
Expand Down
14 changes: 14 additions & 0 deletions packages/@n8n/codemirror-lang/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const sharedOptions = require('@n8n_io/eslint-config/shared');

/**
* @type {import('@types/eslint').ESLint.ConfigData}
*/
module.exports = {
extends: ['@n8n_io/eslint-config/frontend'],
netroy marked this conversation as resolved.
Show resolved Hide resolved

...sharedOptions(__dirname, 'frontend'),

ignorePatterns: [
'src/expressions/syntax*.ts'
]
};
7 changes: 7 additions & 0 deletions packages/@n8n/codemirror-lang/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/node_modules
package-lock.json
/dist
/src/*.js
/src/*.d.ts
src/expressions/syntax*.ts
.DS_Store
netroy marked this conversation as resolved.
Show resolved Hide resolved
42 changes: 42 additions & 0 deletions packages/@n8n/codemirror-lang/README.md
netroy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# @n8n/codemirror-lang

n8n expression language support for CodeMirror 6.

## Usage

Install n8n expression language support:

```sh
npm i @n8n/codemirror-lang
```

Install setup dependencies:

```sh
npm i @codemirror/language @lezer/common @lezer/javascript
```

Set up language support:

```js
import { parserWithMetaData as n8nParser } from '@n8n/codemirror-lang';
import { LanguageSupport, LRLanguage } from '@codemirror/language';
import { parseMixed } from '@lezer/common';
import { parser as jsParser } from '@lezer/javascript';

const n8nPlusJsParser = n8nParser.configure({
wrap: parseMixed((node) => {
if (node.type.isTop) return null;

return node.name === 'Resolvable'
? { parser: jsParser, overlay: (node) => node.type.name === 'Resolvable' }
: null;
}),
});

const n8nLanguage = LRLanguage.define({ parser: n8nPlusJsParser });

export function n8nExpressionLanguageSupport() {
return new LanguageSupport(n8nLanguage);
}
```
2 changes: 2 additions & 0 deletions packages/@n8n/codemirror-lang/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** @type {import('jest').Config} */
module.exports = require('../../../jest.config');
36 changes: 36 additions & 0 deletions packages/@n8n/codemirror-lang/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@n8n/codemirror-lang",
"version": "0.3.0",
"description": "n8n expression language support for CodeMirror 6",
netroy marked this conversation as resolved.
Show resolved Hide resolved
"private": true,
"sideEffects": false,
"main": "dist/index.js",
"module": "src/index.ts",
"types": "dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"import": "./src/index.ts",
"types": "./dist/index.d.ts"
},
"./*": "./*"
},
"scripts": {
"clean": "rimraf dist .turbo",
"typecheck": "tsc",
"generate:expressions:grammar": "lezer-generator --typeScript --output src/expressions/syntax.ts src/expressions/syntax.grammar",
"build": "pnpm generate:expressions:grammar && tsc -p tsconfig.build.json",
"test": "jest",
"lint": "eslint . --ext .js,.ts,.vue --quiet",
"lintfix": "eslint . --ext .js,.ts,.vue --fix",
"format": "prettier --write src/"
netroy marked this conversation as resolved.
Show resolved Hide resolved
},
"peerDependencies": {
"@codemirror/autocomplete": "*",
"@codemirror/language": "*",
"@lezer/highlight": "*"
},
"devDependencies": {
"@lezer/generator": "^1.7.0"
}
}
35 changes: 35 additions & 0 deletions packages/@n8n/codemirror-lang/src/expressions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { completeFromList } from '@codemirror/autocomplete';
import { LRLanguage, LanguageSupport, foldNodeProp, foldInside } from '@codemirror/language';
import { styleTags, tags as t } from '@lezer/highlight';
import { parser } from './syntax';

Check failure on line 4 in packages/@n8n/codemirror-lang/src/expressions/index.ts

View workflow job for this annotation

GitHub Actions / Lint changes

Unable to resolve path to module './syntax'

Check failure on line 4 in packages/@n8n/codemirror-lang/src/expressions/index.ts

View workflow job for this annotation

GitHub Actions / Lint changes

Missing file extension for "./syntax"
netroy marked this conversation as resolved.
Show resolved Hide resolved

export const parserWithMetaData = parser.configure({
props: [
foldNodeProp.add({
Application: foldInside,
}),
styleTags({
OpenMarker: t.brace,
CloseMarker: t.brace,
Plaintext: t.content,
Resolvable: t.string,
}),
],
});

export const n8nLanguage = LRLanguage.define({
parser: parserWithMetaData,
languageData: {
commentTokens: { line: ';' },
},
});

const completions = n8nLanguage.data.of({
autocomplete: completeFromList([
// { label: "test", type: "keyword" }, // to add in future
]),
});
netroy marked this conversation as resolved.
Show resolved Hide resolved

export function n8nExpression() {
return new LanguageSupport(n8nLanguage, [completions]);
}
21 changes: 21 additions & 0 deletions packages/@n8n/codemirror-lang/src/expressions/syntax.grammar
netroy marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@top Program { entity* }

entity { Plaintext | Resolvable }

@tokens {
Plaintext { ![{] Plaintext? | "{" (@eof | ![{] Plaintext?) }

OpenMarker[closedBy="CloseMarker"] { "{{" }

CloseMarker[openedBy="OpenMarker"] { "}}" }

Resolvable {
OpenMarker resolvableChar* CloseMarker
}

resolvableChar { unicodeChar | "}" ![}] | "\\}}" }

unicodeChar { $[\u0000-\u007C] | $[\u007E-\u1FFF] | $[\u20A0-\u20CF] | $[\u{1F300}-\u{1F64F}] }
}

@detectDelim
1 change: 1 addition & 0 deletions packages/@n8n/codemirror-lang/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { parserWithMetaData, n8nLanguage } from './expressions';
Loading
Loading