Skip to content

Commit

Permalink
Integrating langauge tests again in generator and enhancing tests
Browse files Browse the repository at this point in the history
- Updated relevant dependencies and aligned version in the repo
  • Loading branch information
kaisalmen committed Jun 14, 2024
1 parent 3aac21b commit ea748fa
Show file tree
Hide file tree
Showing 21 changed files with 730 additions and 566 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ indent_size = 4
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"javascript",
"typescript"
],
"vitest.enable": true,
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/arithmetics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
},
"dependencies": {
"chalk": "~5.3.0",
"commander": "~11.0.0",
"commander": "~11.1.0",
"langium": "~3.0.0",
"vscode-languageclient": "~9.0.1",
"vscode-languageserver": "~9.0.1"
Expand Down
2 changes: 1 addition & 1 deletion examples/domainmodel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"dependencies": {
"chalk": "~5.3.0",
"commander": "~11.0.0",
"commander": "~11.1.0",
"langium": "~3.0.0",
"lodash": "~4.17.21",
"vscode-languageclient": "~9.0.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/requirements/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
},
"dependencies": {
"chalk": "~5.3.0",
"commander": "~11.0.0",
"commander": "~11.1.0",
"langium": "~3.0.0",
"vscode-languageclient": "~9.0.1",
"vscode-languageserver": "~9.0.1"
Expand Down
2 changes: 1 addition & 1 deletion examples/statemachine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"dependencies": {
"chalk": "~5.3.0",
"commander": "~11.0.0",
"commander": "~11.1.0",
"langium": "~3.0.0",
"vscode-languageclient": "~9.0.1",
"vscode-languageserver": "~9.0.1"
Expand Down
880 changes: 431 additions & 449 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"lint": "npm run lint --workspaces",
"test": "vitest",
"test-ui": "vitest --ui",
"test:run": "vitest run",
"coverage": "vitest run --coverage",
"validate-exports": "npm run validate-exports --workspace=langium",
"version:dependencies": "node ./scripts/update-version.js && npm install",
Expand All @@ -27,16 +28,16 @@
"@types/vscode": "~1.67.0",
"@typescript-eslint/eslint-plugin": "~6.4.1",
"@typescript-eslint/parser": "~6.4.1",
"@vitest/coverage-v8": "~1.0.0",
"@vitest/ui": "~1.5.0",
"@vitest/coverage-v8": "~1.6.0",
"@vitest/ui": "~1.6.0",
"concurrently": "~8.2.1",
"esbuild": "~0.19.2",
"eslint": "~8.56.0",
"eslint-plugin-header": "~3.1.1",
"editorconfig": "~2.0.0",
"shx": "~0.3.4",
"typescript": "~5.1.6",
"vitest": "~1.5.0"
"vitest": "~1.6.0"
},
"overrides": {
"@types/node": "~16.18.41"
Expand Down
4 changes: 2 additions & 2 deletions packages/generator-langium/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
"chalk": "~5.3.0",
"lodash": "~4.17.21",
"which": "~4.0.0",
"yeoman-generator": "~7.1.1"
"yeoman-generator": "~7.1.0"
},
"devDependencies": {
"@types/lodash": "~4.17.0",
"@types/lodash": "~4.17.5",
"@types/which": "~3.0.3",
"@yeoman/types": "~1.2.0",
"yeoman-test": "~8.2.0",
Expand Down
68 changes: 30 additions & 38 deletions packages/generator-langium/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export class LangiumGenerator extends Generator {
const pathBase = path.join(__dirname, BASE_DIR);
this.sourceRoot(pathBase);
const mainPackageJson = this.fs.readJSON(path.join(this.sourceRoot(), 'package.json'));
const tsConfigBuildJson = this.fs.readJSON(path.join(this.sourceRoot(), 'tsconfig.build.json'));

const baseFiles = [
'.eslintrc.json',
Expand All @@ -197,18 +198,19 @@ export class LangiumGenerator extends Generator {
this.fs.copy(this.templatePath('gitignore.txt'), this._extensionPath('.gitignore'));

this.sourceRoot(path.join(__dirname, `${BASE_DIR}/${PACKAGE_LANGUAGE}`));
// omit .vscode-extensions.json for now
const languageFiles = [
'package.json',
'langium-config.json',
'langium-quickstart.md',
'tsconfig.json',
'tsconfig.src.json',
'tsconfig.test.json',
'vitest.config.ts',
'src',
'test'
];
if (this.answers.includeTest) {
languageFiles.push('tsconfig.test.json');
languageFiles.push('test');
}
for (const path of languageFiles) {
this.fs.copy(
this.templatePath(path),
Expand All @@ -217,6 +219,24 @@ export class LangiumGenerator extends Generator {
);
}

if (this.answers.includeTest) {
mainPackageJson.scripts.test = 'npm run --workspace packages/language test';

// ensure reference is directly behind ./packages/language/tsconfig.src.json
tsConfigBuildJson.references.push({ path: './packages/language/tsconfig.test.json' });

const languagePackageJson = this.fs.readJSON(this._extensionPath('packages/language/package.json'));
languagePackageJson.devDependencies.vitest = '~1.6.0';
languagePackageJson.scripts.test = 'vitest run';
this.fs.delete(this._extensionPath('packages/language/package.json'));
this.fs.writeJSON(this._extensionPath('packages/language/package.json'), languagePackageJson, undefined, 4);

const extensionsJson = this.fs.readJSON(this._extensionPath('.vscode/extensions.json'));
extensionsJson.recommendations.push('vitest.explorer');
this.fs.delete(this._extensionPath('.vscode/extensions.json'));
this.fs.writeJSON(this._extensionPath('.vscode/extensions.json'), extensionsJson, undefined, 4);
}

if (this.answers.includeCLI) {
this.sourceRoot(path.join(__dirname, `${BASE_DIR}/${PACKAGE_CLI}`));
const cliFiles = [
Expand All @@ -233,6 +253,7 @@ export class LangiumGenerator extends Generator {
);
}
mainPackageJson.workspaces.push('packages/cli');
tsConfigBuildJson.references.push({ path: './packages/cli/tsconfig.json' });
}

if (this.answers.includeWeb) {
Expand All @@ -254,6 +275,7 @@ export class LangiumGenerator extends Generator {
);
}
mainPackageJson.workspaces.push('packages/web');
tsConfigBuildJson.references.push({ path: './packages/web/tsconfig.json' });
}

if (this.answers.includeVSCode) {
Expand All @@ -274,44 +296,14 @@ export class LangiumGenerator extends Generator {
);
}
mainPackageJson.workspaces.push('packages/extension');
tsConfigBuildJson.references.push({ path: './packages/extension/tsconfig.json' });
}

this.fs.writeJSON(this._extensionPath('.package.json'), mainPackageJson, undefined, 4);
this.fs.copy(
this._extensionPath('.package.json'),
this._extensionPath('package.json'),
templateCopyOptions
);
this.fs.delete(this._extensionPath('.package.json'));

// if (this.answers.includeTest) {
// this.sourceRoot(path.join(__dirname, TEMPLATE_TEST_DIR));

// this.fs.copy(
// this.templatePath('.'),
// this._extensionPath(),
// templateCopyOptions
// );

// // update the scripts section in the package.json to use 'tsconfig.src.json' for building
// const pkgJson = this.fs.readJSON(this.templatePath('.package.json'));
// this.fs.extendJSON(this._extensionPath('package-template.json'), pkgJson, undefined, 4);

// // update the 'includes' property in the existing 'tsconfig.json' and adds '"noEmit": true'
// const tsconfigJson = this.fs.readJSON(this.templatePath('.tsconfig.json'));
// this.fs.extendJSON(this._extensionPath('tsconfig.json'), tsconfigJson, undefined, 4);

// // the initial '.vscode/extensions.json' can't be extended as above, as it contains comments, which is tolerated by vscode,
// // but not by `this.fs.extendJSON(...)`, so
// this.fs.copy(this.templatePath('.vscode-extensions.json'), this._extensionPath('.vscode/extensions.json'), templateCopyOptions);
// }

// this.fs.copy(
// this._extensionPath('package-template.json'),
// this._extensionPath('package.json'),
// templateCopyOptions
// );
// this.fs.delete(this._extensionPath('package-template.json'));
this.fs.move(this._extensionPath('.package.json'), this._extensionPath('package.json'), templateCopyOptions);

this.fs.writeJSON(this._extensionPath('.tsconfig.build.json'), tsConfigBuildJson, undefined, 4);
this.fs.move(this._extensionPath('.tsconfig.build.json'), this._extensionPath('tsconfig.build.json'), templateCopyOptions);
}

async install(): Promise<void> {
Expand Down
4 changes: 0 additions & 4 deletions packages/generator-langium/templates/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"langium.langium-vscode"
]
Expand Down
11 changes: 5 additions & 6 deletions packages/generator-langium/templates/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "<%= extension-name %>",
"name": "<%= extension-name %>-base",
"description": "Base workspace package",
"version": "0.0.1",
"type": "module",
"private": true,
"private": true,
"files": [
"out",
"src"
Expand All @@ -14,13 +14,12 @@
"build": "npm run compile && npm run build --workspaces",
"lint": "eslint src --ext ts",
"langium:generate": "npm run --workspace packages/language langium:generate",
"langium:watch": "npm run --workspace packages/language langium:watch",
"test": "vitest run"
"langium:watch": "npm run --workspace packages/language langium:watch"
},
"devDependencies": {
"@types/node": "^18.0.0",
"@typescript-eslint/parser": "~7.11.0",
"@typescript-eslint/eslint-plugin": "~7.11.0",
"@typescript-eslint/parser": "~7.13.0",
"@typescript-eslint/eslint-plugin": "~7.13.0",
"eslint": "~8.57.0",
"typescript": "~5.4.5"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
"dependencies": {
"<%= extension-name %>-language": "0.0.1",
"chalk": "~5.3.0",
"commander": "~11.0.0"
},
"devDependencies": {
"commander": "~11.1.0"
},
"volta": {
"node": "18.20.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
"devDependencies": {
"@types/vscode": "~1.67.0",
"concurrently": "~8.2.1",
"esbuild": "~0.20.2"
"esbuild": "~0.21.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"langium": "~3.0.0"
},
"devDependencies": {
"langium-cli": "~3.0.3",
"vitest": "~1.6.0"
"langium-cli": "~3.0.3"
},
"volta": {
"node": "18.20.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
},
"devDependencies": {
"@codingame/esbuild-import-meta-url-plugin": "~1.0.2",
"vite": "~5.2.12",
"http-server": "~14.1.1"
"vite": "~5.2.13",
"http-server": "~14.1.1"
},
"volta": {
"node": "18.20.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable header/header */
import { defineConfig } from 'vite';
import * as path from 'path';
import importMetaUrlPlugin from '@codingame/esbuild-import-meta-url-plugin';
Expand Down
6 changes: 1 addition & 5 deletions packages/generator-langium/templates/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"files": [],
"references": [
{ "path": "./packages/language/tsconfig.src.json" },
{ "path": "./packages/language/tsconfig.test.json" },
{ "path": "./packages/cli/tsconfig.json" },
{ "path": "./packages/web/tsconfig.json" },
{ "path": "./packages/extension/tsconfig.json" }
{ "path": "./packages/language/tsconfig.src.json" }
]
}
Loading

0 comments on commit ea748fa

Please sign in to comment.