virmator 4.1.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,6 +49,7 @@ const baseConfig = {
49
49
  'noopener',
50
50
  'noreferrer',
51
51
  'npmignore',
52
+ 'nycrc',
52
53
  'packagejson',
53
54
  'parens',
54
55
  'pdfs',
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ const baseConfig = {
4
+ /** Run thresholds on each individual file */
5
+ perFile: 100,
6
+ /** Caches cause problems. */
7
+ cache: false,
8
+ /** Fail when 100% test coverage is not met */
9
+ checkCoverage: true,
10
+ /** Print report to console and also to html files. */
11
+ reporter: [
12
+ 'html',
13
+ 'text',
14
+ ],
15
+ /** Don't show files that meet 100% test coverage. */
16
+ skipFull: true,
17
+ tempDir: './node_modules/.nyc-output/',
18
+
19
+ /** Require 100% test coverage in all things */
20
+ branches: 100,
21
+ functions: 100,
22
+ lines: 100,
23
+ statements: 100,
24
+ };
25
+
26
+ module.exports = baseConfig;
File without changes
@@ -0,0 +1,7 @@
1
+ const baseOptions = require('virmator/base-configs/base-nyc.js');
2
+
3
+ const nycConfig = {
4
+ ...baseOptions,
5
+ };
6
+
7
+ module.exports = nycConfig;
@@ -12,8 +12,9 @@
12
12
  "spellcheck": "virmator spellcheck",
13
13
  "start": "npm install && virmator frontend",
14
14
  "test": "virmator test && npm run test:types",
15
- "test:all": "npm run test:types && npm test && npm run spellcheck && virmator format check && npm run test:docs",
15
+ "test:all": "npm run test:types && npm test && npm run spellcheck && npm run test:format && npm run test:docs",
16
16
  "test:docs": "virmator code-in-markdown check",
17
+ "test:format": "virmator format check",
17
18
  "test:types": "tsc --noEmit",
18
19
  "test:web": "virmator test-web"
19
20
  }
@@ -5,9 +5,9 @@
5
5
  "rootDir": "./src"
6
6
  },
7
7
  "exclude": [
8
- "./configs/",
9
- "./dist/",
10
- "./node_modules/",
11
- "./test-files/"
8
+ "./configs",
9
+ "./dist",
10
+ "./node_modules",
11
+ "./test-files"
12
12
  ]
13
13
  }
@@ -6,3 +6,4 @@ export declare function readAllDirContents({ dir, recursive, }: {
6
6
  recursive?: boolean;
7
7
  }): Promise<DirContents>;
8
8
  export declare function writeFiles(dir: string, allFileContents: DirContents): Promise<void>;
9
+ export declare function recursivelyUpwardsSearchForDir(startDirPath: string, check: (dirPath: string) => boolean): Promise<string>;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeFiles = exports.readAllDirContents = void 0;
3
+ exports.recursivelyUpwardsSearchForDir = exports.writeFiles = exports.readAllDirContents = void 0;
4
4
  const augment_vir_1 = require("augment-vir");
5
+ const fs_1 = require("fs");
5
6
  const promises_1 = require("fs/promises");
6
7
  const path_1 = require("path");
7
8
  async function readAllDirContents({ dir, recursive = false, }) {
@@ -40,3 +41,17 @@ async function writeFiles(dir, allFileContents) {
40
41
  });
41
42
  }
42
43
  exports.writeFiles = writeFiles;
44
+ async function recursivelyUpwardsSearchForDir(startDirPath, check) {
45
+ if (!(0, fs_1.existsSync)(startDirPath) || !startDirPath) {
46
+ throw new Error(`Could not search in "${startDirPath}": it does not exist.`);
47
+ }
48
+ if (check(startDirPath)) {
49
+ return startDirPath;
50
+ }
51
+ const parent = (0, path_1.dirname)(startDirPath);
52
+ if (parent === startDirPath) {
53
+ throw new Error(`Cannot recurse any higher, already at "${parent}"`);
54
+ }
55
+ return recursivelyUpwardsSearchForDir(parent, check);
56
+ }
57
+ exports.recursivelyUpwardsSearchForDir = recursivelyUpwardsSearchForDir;
@@ -45,7 +45,7 @@ exports.codeInMarkdownCommandDefinition = (0, define_command_1.defineCommand)({
45
45
  },
46
46
  ],
47
47
  };
48
- }, (inputs) => {
48
+ }, async (inputs) => {
49
49
  const args = inputs.filteredInputArgs.length
50
50
  ? inputs.filteredInputArgs
51
51
  : [`\"./**/*.md\"`];
@@ -56,7 +56,7 @@ exports.codeInMarkdownCommandDefinition = (0, define_command_1.defineCommand)({
56
56
  stderr: (stderrInput) => stderrInput.replace('Run without --check to update.', 'Run without the "check" sub-command in order to update.'),
57
57
  };
58
58
  return {
59
- mainCommand: (0, package_paths_1.getNpmBinPath)('md-code'),
59
+ mainCommand: await (0, package_paths_1.getNpmBinPath)('md-code'),
60
60
  logTransforms,
61
61
  args: [
62
62
  subCommand,
@@ -37,12 +37,12 @@ exports.compileCommandDefinition = (0, define_command_1.defineCommand)({
37
37
  },
38
38
  ],
39
39
  };
40
- }, (inputs) => {
40
+ }, async (inputs) => {
41
41
  const shouldNotEmit = inputs.filteredInputArgs.join(' ').includes('--noEmit') ||
42
42
  inputs.inputSubCommands.includes(inputs.subCommands.check);
43
43
  const resetCommand = shouldNotEmit ? '' : 'rm -rf dist && ';
44
44
  const noEmit = shouldNotEmit ? '--noEmit' : '';
45
- const mainCommand = `${resetCommand}${(0, package_paths_1.getNpmBinPath)('tsc')}`;
45
+ const mainCommand = `${resetCommand}${await (0, package_paths_1.getNpmBinPath)('tsc')}`;
46
46
  return {
47
47
  mainCommand,
48
48
  args: [
@@ -91,7 +91,7 @@ exports.formatCommandDefinition = (0, define_command_1.defineCommand)({
91
91
  },
92
92
  ],
93
93
  };
94
- }, (inputs) => {
94
+ }, async (inputs) => {
95
95
  const formatArgs = extractFormatArgs(inputs.filteredInputArgs);
96
96
  const shouldCheckOnly = inputs.inputSubCommands.includes(inputs.subCommands.check) ||
97
97
  formatArgs.prettierFlags.includes('--check');
@@ -110,7 +110,7 @@ exports.formatCommandDefinition = (0, define_command_1.defineCommand)({
110
110
  .replace('All matched files use Prettier code style!\n', ''),
111
111
  };
112
112
  return {
113
- mainCommand: (0, package_paths_1.getNpmBinPath)('prettier'),
113
+ mainCommand: await (0, package_paths_1.getNpmBinPath)('prettier'),
114
114
  args: [
115
115
  '--color',
116
116
  listDifferentFlag,
@@ -32,7 +32,7 @@ exports.frontendCommandDefinition = (0, define_command_1.defineCommand)({
32
32
  ],
33
33
  examples: [],
34
34
  };
35
- }, (inputs) => {
35
+ }, async (inputs) => {
36
36
  const needToBuild = !!inputs.inputSubCommands.length;
37
37
  const useDefaultConfigArgs = !inputs.filteredInputArgs.includes('--config');
38
38
  const configString = useDefaultConfigArgs
@@ -42,7 +42,7 @@ exports.frontendCommandDefinition = (0, define_command_1.defineCommand)({
42
42
  packageDir: package_paths_1.virmatorPackageDir,
43
43
  })}`
44
44
  : '';
45
- const viteBinPath = (0, package_paths_1.getNpmBinPath)('vite');
45
+ const viteBinPath = await (0, package_paths_1.getNpmBinPath)('vite');
46
46
  const removeOutput = needToBuild ? 'rm -rf dist' : '';
47
47
  const mainCommand = `${removeOutput}${viteBinPath}`;
48
48
  const subCommandArgs = needToBuild
@@ -28,14 +28,14 @@ exports.spellcheckCommandDefinition = (0, define_command_1.defineCommand)({
28
28
  ],
29
29
  examples: [],
30
30
  };
31
- }, (inputs) => {
31
+ }, async (inputs) => {
32
32
  const containsNonFlagArgs = inputs.filteredInputArgs.some((arg) => !arg.startsWith('-'));
33
33
  const fileArg = containsNonFlagArgs ? '' : '"**/*"';
34
34
  const configArg = inputs.filteredInputArgs.includes('--config')
35
35
  ? ''
36
36
  : `--config ${inputs.configFiles.cspell.copyToPathRelativeToRepoDir}`;
37
37
  return {
38
- mainCommand: (0, package_paths_1.getNpmBinPath)('cspell'),
38
+ mainCommand: await (0, package_paths_1.getNpmBinPath)('cspell'),
39
39
  args: [
40
40
  configArg,
41
41
  '--color',
@@ -46,13 +46,13 @@ exports.testWebCommandDefinition = (0, define_command_1.defineCommand)({
46
46
  },
47
47
  ],
48
48
  };
49
- }, (inputs) => {
49
+ }, async (inputs) => {
50
50
  const shouldUseConfig = !inputs.filteredInputArgs.includes('--config');
51
51
  const configString = shouldUseConfig
52
52
  ? `--config ${inputs.configFiles.webTestRunner.copyToPathRelativeToRepoDir}`
53
53
  : '';
54
54
  return {
55
- mainCommand: (0, package_paths_1.getNpmBinPath)('web-test-runner'),
55
+ mainCommand: await (0, package_paths_1.getNpmBinPath)('web-test-runner'),
56
56
  logTransforms: {
57
57
  stdout: testWebTransform,
58
58
  },
@@ -2,11 +2,16 @@ export declare const testCommandDefinition: import("../api/command/define-comman
2
2
  commandName: "test";
3
3
  subCommandDescriptions: {};
4
4
  configFiles: {
5
- readonly mocharc: {
5
+ readonly mochaConfig: {
6
+ readonly copyFromInternalPath: string;
7
+ readonly copyToPathRelativeToRepoDir: string;
8
+ readonly required: true;
9
+ };
10
+ readonly nycConfig: {
6
11
  readonly copyFromInternalPath: string;
7
12
  readonly copyToPathRelativeToRepoDir: string;
8
13
  readonly required: true;
9
14
  };
10
15
  };
11
- npmDeps: readonly ["@types/chai", "@types/mocha", "chai", "mocha-spec-reporter-with-file-names", "mocha", "ts-node"];
16
+ npmDeps: readonly ["@types/chai", "@types/mocha", "chai", "mocha-spec-reporter-with-file-names", "mocha", "ts-node", "nyc"];
12
17
  }>;
@@ -8,9 +8,14 @@ exports.testCommandDefinition = (0, define_command_1.defineCommand)({
8
8
  commandName: 'test',
9
9
  subCommandDescriptions: {},
10
10
  configFiles: {
11
- mocharc: {
12
- copyFromInternalPath: (0, path_1.join)(package_paths_1.virmatorConfigsDir, 'configs', '.mocharc.js'),
13
- copyToPathRelativeToRepoDir: (0, path_1.join)('configs', '.mocharc.js'),
11
+ mochaConfig: {
12
+ copyFromInternalPath: (0, path_1.join)(package_paths_1.virmatorConfigsDir, 'configs', 'mocha.config.js'),
13
+ copyToPathRelativeToRepoDir: (0, path_1.join)('configs', 'mocha.config.js'),
14
+ required: true,
15
+ },
16
+ nycConfig: {
17
+ copyFromInternalPath: (0, path_1.join)(package_paths_1.virmatorConfigsDir, 'configs', 'nyc.config.js'),
18
+ copyToPathRelativeToRepoDir: (0, path_1.join)('configs', 'nyc.config.js'),
14
19
  required: true,
15
20
  },
16
21
  },
@@ -21,6 +26,7 @@ exports.testCommandDefinition = (0, define_command_1.defineCommand)({
21
26
  'mocha-spec-reporter-with-file-names',
22
27
  'mocha',
23
28
  'ts-node',
29
+ 'nyc',
24
30
  ],
25
31
  }, ({ commandName, packageBinName }) => {
26
32
  return {
@@ -53,14 +59,22 @@ exports.testCommandDefinition = (0, define_command_1.defineCommand)({
53
59
  },
54
60
  ],
55
61
  };
56
- }, (inputs) => {
62
+ }, async (inputs) => {
57
63
  const useDefaultConfigArgs = !inputs.filteredInputArgs.includes('--config');
58
64
  const configString = useDefaultConfigArgs
59
- ? `--config ${inputs.configFiles.mocharc.copyToPathRelativeToRepoDir} `
65
+ ? `--config '${inputs.configFiles.mochaConfig.copyToPathRelativeToRepoDir}'`
66
+ : '';
67
+ const useDefaultNycConfigPath = !inputs.filteredInputArgs.includes('--nycrc-path');
68
+ const nycConfigFlag = useDefaultNycConfigPath
69
+ ? `--nycrc-path '${inputs.configFiles.nycConfig.copyToPathRelativeToRepoDir}'`
60
70
  : '';
61
71
  return {
62
- mainCommand: (0, package_paths_1.getNpmBinPath)('mocha'),
72
+ mainCommand: await (0, package_paths_1.getNpmBinPath)('nyc'),
63
73
  args: [
74
+ // force colors in nyc
75
+ '--colors',
76
+ nycConfigFlag,
77
+ await (0, package_paths_1.getNpmBinPath)('mocha'),
64
78
  configString,
65
79
  ...inputs.filteredInputArgs,
66
80
  ],
@@ -6,6 +6,5 @@ export declare const virmatorConfigs: {
6
6
  vsCode: string;
7
7
  src: string;
8
8
  };
9
- export declare const virmatorNodeBin: string;
10
- export declare function getNpmBinPath(command: string): string;
9
+ export declare function getNpmBinPath(command: string): Promise<string>;
11
10
  export declare function relativeToVirmatorRoot(fullPath: string): string;
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.relativeToVirmatorRoot = exports.getNpmBinPath = exports.virmatorNodeBin = exports.virmatorConfigs = exports.virmatorConfigsDir = exports.virmatorPackageDir = void 0;
3
+ exports.relativeToVirmatorRoot = exports.getNpmBinPath = exports.virmatorConfigs = exports.virmatorConfigsDir = exports.virmatorPackageDir = void 0;
4
+ const augment_vir_1 = require("augment-vir");
4
5
  const node_only_1 = require("augment-vir/dist/cjs/node-only");
5
6
  const fs_1 = require("fs");
6
7
  const path_1 = require("path");
8
+ const fs_2 = require("../augments/fs");
7
9
  exports.virmatorPackageDir = (0, path_1.dirname)((0, path_1.dirname)(__dirname));
8
10
  exports.virmatorConfigsDir = (0, path_1.join)(exports.virmatorPackageDir, 'configs');
9
11
  exports.virmatorConfigs = {
@@ -12,16 +14,25 @@ exports.virmatorConfigs = {
12
14
  vsCode: (0, path_1.join)(exports.virmatorConfigsDir, '.vscode'),
13
15
  src: (0, path_1.join)(exports.virmatorConfigsDir, 'src'),
14
16
  };
15
- exports.virmatorNodeBin = (0, path_1.join)(exports.virmatorPackageDir, 'node_modules', '.bin');
16
- function getNpmBinPath(command) {
17
- const virmatorBinPath = (0, path_1.join)(exports.virmatorNodeBin, command);
18
- const actualBinPath = (0, fs_1.existsSync)(virmatorBinPath)
19
- ? virmatorBinPath
20
- : (0, path_1.join)(exports.virmatorPackageDir, '..', '.bin', command);
21
- if (!(0, fs_1.existsSync)(actualBinPath)) {
22
- throw new Error(`Could not find npm bin path for "${command}"`);
17
+ async function getNpmBinPath(command) {
18
+ const joinPath = (0, path_1.join)('node_modules', '.bin', command);
19
+ const startSearchDirPath = exports.virmatorPackageDir;
20
+ try {
21
+ const nodeModulesWithValidBin = await (0, fs_2.recursivelyUpwardsSearchForDir)(startSearchDirPath, (dirPath) => {
22
+ return (0, fs_1.existsSync)((0, path_1.join)(dirPath, joinPath));
23
+ });
24
+ if (!nodeModulesWithValidBin) {
25
+ throw new Error(`Search failed to find "${command}" bin path. Started in "${startSearchDirPath}".`);
26
+ }
27
+ const actualBinPath = (0, path_1.join)(nodeModulesWithValidBin, joinPath);
28
+ if (!(0, fs_1.existsSync)(actualBinPath)) {
29
+ throw new Error(`Discovered bin path for "${command}" does not actually exist: "${actualBinPath}". Started at "${startSearchDirPath}".`);
30
+ }
31
+ return (0, node_only_1.interpolationSafeWindowsPath)(actualBinPath);
32
+ }
33
+ catch (error) {
34
+ throw new Error(`Failed to find npm bin path for "${command}": ${(0, augment_vir_1.extractErrorMessage)(error)}. Started at "${startSearchDirPath}".`);
23
35
  }
24
- return (0, node_only_1.interpolationSafeWindowsPath)(actualBinPath);
25
36
  }
26
37
  exports.getNpmBinPath = getNpmBinPath;
27
38
  function relativeToVirmatorRoot(fullPath) {
package/dist/index.d.ts CHANGED
@@ -90,13 +90,18 @@ export declare const virmator: Readonly<{
90
90
  commandName: "test";
91
91
  subCommandDescriptions: {};
92
92
  configFiles: {
93
- readonly mocharc: {
93
+ readonly mochaConfig: {
94
+ readonly copyFromInternalPath: string;
95
+ readonly copyToPathRelativeToRepoDir: string;
96
+ readonly required: true;
97
+ };
98
+ readonly nycConfig: {
94
99
  readonly copyFromInternalPath: string;
95
100
  readonly copyToPathRelativeToRepoDir: string;
96
101
  readonly required: true;
97
102
  };
98
103
  };
99
- npmDeps: readonly ["@types/chai", "@types/mocha", "chai", "mocha-spec-reporter-with-file-names", "mocha", "ts-node"];
104
+ npmDeps: readonly ["@types/chai", "@types/mocha", "chai", "mocha-spec-reporter-with-file-names", "mocha", "ts-node", "nyc"];
100
105
  }> | import("./api/command/define-command").CommandDefinition<{
101
106
  commandName: "test-web";
102
107
  subCommandDescriptions: {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virmator",
3
- "version": "4.1.0",
3
+ "version": "4.2.1",
4
4
  "description": "Handle all the stuffs in one package.",
5
5
  "keywords": [
6
6
  "automation",
@@ -30,13 +30,13 @@
30
30
  "compile": "rm -rf dist && tsc",
31
31
  "format": "npm run format:base -- --write --list-different",
32
32
  "format:base": "prettier \"./**/*.+(ts|json|html|css|md|js)\"",
33
- "format:check": "npm run format:base -- --check",
34
33
  "prepublishOnly": "npm run test:all",
35
34
  "readme:check": "npm run compile && ts-node -r tsconfig-paths/register src/scripts/save-help-message.ts check && md-code --check README.md",
36
35
  "readme:update": "npm run compile && ts-node -r tsconfig-paths/register src/scripts/save-help-message.ts && md-code README.md",
37
36
  "spellcheck": "cspell \"{*,.*,**/{.*,*}/**/{.*,*}}\" --exclude \"test-files/spellcheck/invalid-spellcheck-repo/**/*\" --exclude \"extender-configs\"",
38
37
  "test": "bash src/scripts/run-tests.sh",
39
- "test:all": "npm run test && npm run spellcheck -- --no-progress && npm run format:check && npm run readme:check",
38
+ "test:all": "npm run test && npm run spellcheck -- --no-progress && npm run test:format && npm run readme:check",
39
+ "test:format": "npm run format:base -- --check",
40
40
  "test:help": "ts-node -r tsconfig-paths/register src/cli/cli.ts --help",
41
41
  "test:types": "tsc --noEmit"
42
42
  },
@@ -65,6 +65,7 @@
65
65
  "markdown-code-example-inserter": "0.1.11",
66
66
  "mocha": "10.0.0",
67
67
  "mocha-spec-reporter-with-file-names": "^0.0.0",
68
+ "nyc": "^15.1.0",
68
69
  "prettier": "2.7.1",
69
70
  "prettier-plugin-jsdoc": "0.4.2",
70
71
  "prettier-plugin-multiline-arrays": "1.1.1",