diff --git a/generators/app/templates/ext-command-ts/tsconfig.json b/generators/app/templates/ext-command-ts/tsconfig.json index 6954702e..356580f8 100644 --- a/generators/app/templates/ext-command-ts/tsconfig.json +++ b/generators/app/templates/ext-command-ts/tsconfig.json @@ -8,7 +8,7 @@ ], "sourceMap": true, "rootDir": "src", - "strict": true /* enable all strict type-checking options */ + "strict": true, /* enable all strict type-checking options */ /* Additional Checks */ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ diff --git a/generators/app/templates/ext-command-ts/vscode-esbuild/tsconfig.json b/generators/app/templates/ext-command-ts/vscode-esbuild/tsconfig.json index 8a79f20f..cb353759 100644 --- a/generators/app/templates/ext-command-ts/vscode-esbuild/tsconfig.json +++ b/generators/app/templates/ext-command-ts/vscode-esbuild/tsconfig.json @@ -7,7 +7,7 @@ ], "sourceMap": true, "rootDir": "src", - "strict": true /* enable all strict type-checking options */ + "strict": true, /* enable all strict type-checking options */ /* Additional Checks */ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ diff --git a/generators/app/templates/ext-command-ts/vscode-webpack/tsconfig.json b/generators/app/templates/ext-command-ts/vscode-webpack/tsconfig.json index 8a79f20f..cb353759 100644 --- a/generators/app/templates/ext-command-ts/vscode-webpack/tsconfig.json +++ b/generators/app/templates/ext-command-ts/vscode-webpack/tsconfig.json @@ -7,7 +7,7 @@ ], "sourceMap": true, "rootDir": "src", - "strict": true /* enable all strict type-checking options */ + "strict": true, /* enable all strict type-checking options */ /* Additional Checks */ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ diff --git a/generators/app/templates/ext-command-web/tsconfig.json b/generators/app/templates/ext-command-web/tsconfig.json index 1d76149b..94a5d0c2 100644 --- a/generators/app/templates/ext-command-web/tsconfig.json +++ b/generators/app/templates/ext-command-web/tsconfig.json @@ -8,7 +8,7 @@ ], "sourceMap": true, "rootDir": "src", - "strict": true /* enable all strict type-checking options */ + "strict": true, /* enable all strict type-checking options */ /* Additional Checks */ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ diff --git a/generators/app/templates/ext-notebook-renderer/src/tsconfig-base.json b/generators/app/templates/ext-notebook-renderer/src/tsconfig-base.json index 49118c93..b25268f1 100644 --- a/generators/app/templates/ext-notebook-renderer/src/tsconfig-base.json +++ b/generators/app/templates/ext-notebook-renderer/src/tsconfig-base.json @@ -7,7 +7,7 @@ ], "types": ["node"], "sourceMap": true, - "strict": true /* enable all strict type-checking options */ + "strict": true, /* enable all strict type-checking options */ /* Additional Checks */ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ diff --git a/package-lock.json b/package-lock.json index 16fe090c..d6be9e4d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "devDependencies": { "@types/mocha": "^10.0.9", "@types/node": "^18.19.57", + "jsonc-parser": "^3.3.1", "mocha": "^10.7.3", "yeoman-environment": "^4.4.3", "yeoman-test": "^10.0.1" @@ -3280,6 +3281,13 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/jsonc-parser": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.3.1.tgz", + "integrity": "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ==", + "dev": true, + "license": "MIT" + }, "node_modules/jsonparse": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz", diff --git a/package.json b/package.json index 069eafad..a8ba52c8 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "@types/node": "^18.19.57", "mocha": "^10.7.3", "yeoman-environment": "^4.4.3", - "yeoman-test": "^10.0.1" + "yeoman-test": "^10.0.1", + "jsonc-parser": "^3.3.1" } } diff --git a/test/test.mjs b/test/test.mjs index 2287204e..720dd94d 100644 --- a/test/test.mjs +++ b/test/test.mjs @@ -4,39 +4,9 @@ import * as path from 'path'; import { fileURLToPath } from 'url'; -import { RunResult, createHelpers } from 'yeoman-test'; +import { createHelpers } from 'yeoman-test'; +import { parse } from 'jsonc-parser'; import * as env from '../generators/app/env.js'; -import { cwd } from 'process'; - -function stripComments(content) { - /** - * First capturing group matches double quoted string - * Second matches single quotes string - * Third matches block comments - * Fourth matches line comments - */ - const regexp = /("(?:[^\\\"]*(?:\\.)?)*")|('(?:[^\\\']*(?:\\.)?)*')|(\/\*(?:\r?\n|.)*?\*\/)|(\/{2,}.*?(?:(?:\r?\n)|$))/g; - const result = content.replace(regexp, (match, m1, m2, m3, m4) => { - // Only one of m1, m2, m3, m4 matches - if (m3) { - // A block comment. Replace with nothing - return ''; - } else if (m4) { - // A line comment. If it ends in \r?\n then keep it. - const length = m4.length; - if (length > 2 && m4[length - 1] === '\n') { - return m4[length - 2] === '\r' ? '\r\n' : '\n'; - } else { - return ''; - } - } else { - // We match a string - return match; - } - }); - return result; -} - describe('test code generator', function () { this.timeout(10000); @@ -753,7 +723,7 @@ describe('test code generator', function () { runResult.assertJsonFileContent('testCom/package.json', expectedPackageJSON); - const tsconfigBody = JSON.parse(stripComments(runResult.fs.read('testCom/tsconfig.json'))); + const tsconfigBody = parse(runResult.fs.read('testCom/tsconfig.json')); runResult.assertObjectContent(tsconfigBody, expectedTsConfig); } finally { cleanup(runResult); @@ -833,7 +803,7 @@ describe('test code generator', function () { runResult.assertJsonFileContent('testCom/package.json', expectedPackageJSON); - const tsconfigBody = JSON.parse(stripComments(runResult.fs.read('testCom/tsconfig.json'))); + const tsconfigBody = parse(runResult.fs.read('testCom/tsconfig.json')); runResult.assertObjectContent(tsconfigBody, expectedTsConfig); } finally { cleanup(runResult); @@ -1196,7 +1166,7 @@ describe('test code generator', function () { ] }; - const jsconfigBody = JSON.parse(stripComments(runResult.fs.read('testCom/jsconfig.json'))); + const jsconfigBody = parse(runResult.fs.read('testCom/jsconfig.json')); runResult.assertObjectContent(jsconfigBody, expectedJSConfig); } finally { cleanup(runResult);