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

Jayvee goes ESM (Langium Upgrade) #558

Merged
merged 39 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
05f47bf
Change build targets to esbuild esm
joluj May 2, 2024
a8142ea
Fix import of JSZip
georg-schwarz May 2, 2024
0fb701b
Fix import from langium in DefaultLogger
georg-schwarz May 2, 2024
d19b341
Adjust imports to make esbuild work
georg-schwarz May 2, 2024
12299a0
Simplify imports from fp-ts
georg-schwarz May 2, 2024
0499a33
Turn off importHelpers as it led to warnings in VSCode IDE
georg-schwarz May 2, 2024
b73964e
Make VSCode extension work with new build setup
georg-schwarz May 2, 2024
4e6b30f
Upgrade vscode-uri to get rid of weird imports
georg-schwarz May 2, 2024
62d297a
Upgrade langium to version 3.0.0
georg-schwarz May 2, 2024
3928f8e
Remove solved work around comments
georg-schwarz May 2, 2024
bd00ecb
Separate docs-generator as standalone app to keep docs as commonjs
georg-schwarz May 3, 2024
46ed68b
Fix build of web-worker
georg-schwarz May 3, 2024
b491022
Fix linter errors in tests
georg-schwarz May 3, 2024
0a1ebf8
Add global setup for vitest
georg-schwarz May 3, 2024
1644295
Use vitest in language-server instead of jest
georg-schwarz May 3, 2024
34acd6f
Use vitest in execution instead of jest
georg-schwarz May 3, 2024
2f9de07
Use vitest in extensions instead of jest
georg-schwarz May 3, 2024
37a302a
Use vitest in interpreter-lib instead of jest
georg-schwarz May 3, 2024
ae4e2a0
Remove test setup from monaco-editor
georg-schwarz May 3, 2024
b306ad1
Remove test setup from docs app
georg-schwarz May 3, 2024
8a16686
Remove test setup from vs-code-extension app
georg-schwarz May 3, 2024
5b6969d
Remove test setup from language-server-web-worker
georg-schwarz May 3, 2024
182a132
Use vitest in interpreter app instead of jest
georg-schwarz May 3, 2024
7fd7b68
Remove test job from docs app
georg-schwarz May 3, 2024
49b2680
Remove remainders of previous jest setup
georg-schwarz May 3, 2024
a7c9b8c
Add license headers to newly added files
georg-schwarz May 3, 2024
37510d0
Exclude vite.config.ts files from production builds
georg-schwarz May 3, 2024
1f4b93e
Define tsconfig path locally in lib/app instead of globally to make v…
georg-schwarz May 6, 2024
9c0e267
Update vscode extension recommendations
georg-schwarz May 6, 2024
e542558
Update testing docs to change to vitest
georg-schwarz May 6, 2024
204618f
Add linter rule "unicorn/prefer-node-protocol"
georg-schwarz May 6, 2024
5f74ce5
Add linter rule "unicorn/import-style"
georg-schwarz May 6, 2024
e42b705
Merge branch 'main' into jayvee-goes-esm-esbuild
georg-schwarz May 6, 2024
318651c
Don't import from "node:assert" to keep browser compatibility
georg-schwarz May 6, 2024
2c1963b
Prevent import from "node:assert"
georg-schwarz May 6, 2024
bac368b
Don't run docs generation for docs app in parallel
georg-schwarz May 6, 2024
9e6c1c3
Apply code review feedback
georg-schwarz May 6, 2024
b203542
Remove unnecessary __esModule flag from mocks
georg-schwarz May 6, 2024
7345e03
Apply further code review feedback
georg-schwarz May 6, 2024
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
30 changes: 21 additions & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"extends": "@jvalue/eslint-config-jvalue",
"ignorePatterns": ["**/*"],
"plugins": ["@nx"],
"parserOptions": {
"project": ["./tsconfig.base.json"]
},
"overrides": [
{
"files": ["*.ts", ".tsx"],
Expand Down Expand Up @@ -37,6 +34,25 @@
]
}
},
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"plugins": ["unicorn"],
"rules": {
"unicorn/prefer-node-protocol": "warn",
"unicorn/import-style": "warn",
"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "node:assert",
"message": "Please use the library `assert` instead to keep browser compatibility. You might need to disable rule `unicorn/prefer-node-protocol` to do so."
}
]
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nx/typescript"],
Expand All @@ -49,14 +65,10 @@
},
{
"files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
"plugins": ["jest"],
"env": {
"jest": true
},
"plugins": ["vitest"],
"rules": {
// you should turn the original rule off *only* for test files
"@typescript-eslint/unbound-method": "off",
"jest/unbound-method": "error"
"@typescript-eslint/unbound-method": "off"
}
}
]
Expand Down
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"recommendations": [
"nrwl.angular-console",
"langium.langium-vscode",
"firsttris.vscode-jest-runner"
"esbenp.prettier-vscode",
"vitest.explorer"
]
}
21 changes: 21 additions & 0 deletions apps/docs-generator/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"parserOptions": {
"project": ["apps/docs-generator/tsconfig.app.json"]
},
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
3 changes: 3 additions & 0 deletions apps/docs-generator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
30 changes: 30 additions & 0 deletions apps/docs-generator/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "docs-generator",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/docs-generator/src",
"projectType": "application",
"targets": {
"build": {
"dependsOn": ["generate-language-server"],
"options": {
"main": "{projectRoot}/src/main.ts",
"tsConfig": "{projectRoot}/tsconfig.app.json"
}
},
"start": {
"executor": "@nx/js:node",
"options": {
"watch": false,
"buildTarget": "docs-generator:build"
}
},
"generate-language-server": {
"executor": "nx:run-commands",
"options": {
"commands": ["nx run language-server:generate"],
"parallel": false
}
}
},
"tags": []
}
58 changes: 21 additions & 37 deletions apps/docs/generator/src/main.ts → apps/docs-generator/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
//
// SPDX-License-Identifier: AGPL-3.0-only

import { readFileSync, readdirSync, writeFileSync } from 'fs';
import { join } from 'path';
import { readFileSync, readdirSync, writeFileSync } from 'node:fs';
import path, { join } from 'node:path';
import { fileURLToPath } from 'node:url';

import {
type JayveeServices,
Expand All @@ -16,35 +17,33 @@ import { NodeFileSystem } from 'langium/node';

import { UserDocGenerator } from './user-doc-generator';

/** ESM does not know __filename and __dirname, so defined here */
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

async function main(): Promise<void> {
const rootPath = join(__dirname, '..', '..', '..', '..');
const docsAppPath = join(__dirname, '..', '..', '..', 'apps', 'docs');
const jayveeExamplesPath = join(__dirname, '..', '..', '..', 'example');
joluj marked this conversation as resolved.
Show resolved Hide resolved

const services = createJayveeServices(NodeFileSystem).Jayvee;
await initializeWorkspace(services);

generateBlockTypeDocs(services, rootPath);
generateConstraintTypeDocs(services, rootPath);
generateValueTypeDocs(services, rootPath);
generateExampleDocs(rootPath);
generateBlockTypeDocs(services, docsAppPath);
generateConstraintTypeDocs(services, docsAppPath);
generateValueTypeDocs(services, docsAppPath);
generateExampleDocs(jayveeExamplesPath, docsAppPath);
}

function generateBlockTypeDocs(
services: JayveeServices,
rootPath: string,
docsAppPath: string,
): void {
const blockTypes = getAllBuiltinBlockTypes(
services.shared.workspace.LangiumDocuments,
services.WrapperFactories,
);

const docsPath = join(
rootPath,
'apps',
'docs',
'docs',
'user',
'block-types',
);
const docsPath = join(docsAppPath, 'docs', 'user', 'block-types');

for (const blockType of blockTypes) {
const userDocBuilder = new UserDocGenerator(services);
Expand All @@ -60,16 +59,9 @@ function generateBlockTypeDocs(

function generateConstraintTypeDocs(
services: JayveeServices,
rootPath: string,
docsAppPath: string,
): void {
const docsPath = join(
rootPath,
'apps',
'docs',
'docs',
'user',
'constraint-types',
);
const docsPath = join(docsAppPath, 'docs', 'user', 'constraint-types');
const constraintTypes = getAllBuiltinConstraintTypes(
services.shared.workspace.LangiumDocuments,
services.WrapperFactories,
Expand All @@ -90,16 +82,9 @@ function generateConstraintTypeDocs(

function generateValueTypeDocs(
services: JayveeServices,
rootPath: string,
docsAppPath: string,
): void {
const docsPath = join(
rootPath,
'apps',
'docs',
'docs',
'user',
'value-types',
);
const docsPath = join(docsAppPath, 'docs', 'user', 'value-types');
const userDocBuilder = new UserDocGenerator(services);
const valueTypeDoc = userDocBuilder.generateValueTypesDoc(
services.ValueTypeProvider.Primitives.getAll(),
Expand All @@ -112,9 +97,8 @@ function generateValueTypeDocs(
console.info(`Generated file ${fileName}`);
}

function generateExampleDocs(rootPath: string): void {
const docsPath = join(rootPath, 'apps', 'docs', 'docs', 'user', 'examples');
const examplesPath = join(rootPath, 'example');
function generateExampleDocs(examplesPath: string, docsAppPath: string): void {
const docsPath = join(docsAppPath, 'docs', 'user', 'examples');

for (const file of readdirSync(examplesPath)) {
if (file.endsWith('.jv')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// SPDX-License-Identifier: AGPL-3.0-only

// eslint-disable-next-line unicorn/prefer-node-protocol
import { strict as assert } from 'assert';

import {
Expand Down
8 changes: 8 additions & 0 deletions apps/docs-generator/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"types": ["node"]
},
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
13 changes: 13 additions & 0 deletions apps/docs-generator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
}
],
"compilerOptions": {
"esModuleInterop": true
}
}
3 changes: 3 additions & 0 deletions apps/docs-generator/tsconfig.json.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg

SPDX-License-Identifier: AGPL-3.0-only
12 changes: 11 additions & 1 deletion apps/docs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*", "**/.docusaurus/**", "**/theme/prism-jayvee.js"],
"ignorePatterns": [
"!**/*",
"**/.docusaurus/**",
"**/theme/prism-jayvee.js",
"*.config.js",
"**/prism-include-languages.js",
"**/sidebars.js"
],
"parserOptions": {
"project": ["apps/docs/tsconfig.app.json"]
},
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
Expand Down
4 changes: 3 additions & 1 deletion apps/docs/docs/dev/04-guides/02-working-with-the-ast.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ After calling `assert`, the type system of TypeScript assumes the condition to b
Here is an example of how to use it in practice:

```typescript
// Import the `assert` function like this:
// We use the `assert` function from the `assert` library, not `node:assert` (to preserve browser compatibility)

// eslint-disable-next-line unicorn/prefer-node-protocol
import { strict as assert } from 'assert';

import { A, B, isB } from './ast';
Expand Down
Loading
Loading