regressify 1.0.20 → 1.0.21

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.
package/helpers.ts CHANGED
@@ -1,27 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import fs from 'fs';
3
- import path, { dirname } from 'path';
4
2
  import { exec } from 'child_process';
5
- import { fileURLToPath, pathToFileURL } from 'url';
6
3
  import chalk from 'chalk';
7
4
 
8
- export function getLibraryPath() {
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = dirname(__filename);
11
-
12
- let currentDir = __dirname;
13
- while (!fs.existsSync(path.join(currentDir, 'package.json'))) {
14
- const parentDir = path.dirname(currentDir);
15
- if (parentDir === currentDir) {
16
- return null;
17
- }
18
- currentDir = parentDir;
19
- }
20
- const packageJsonPath = path.join(currentDir, 'package.json');
21
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
22
- return `node_modules/${packageJson.name}`;
23
- }
24
-
25
5
  export function runCommand(command) {
26
6
  const childProcess = exec(command, { env: { ...process.env, FORCE_COLOR: '1' } });
27
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "regressify",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "Visual regression tests support",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/helpers.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import fs from 'fs';
2
2
  import YAML from 'js-yaml';
3
- import path, { dirname } from 'path';
3
+ import { dirname } from 'path';
4
+ import slash from 'slash';
4
5
  import { fileURLToPath } from 'url';
6
+
5
7
  export const getStringArg = (key: string): string | undefined => {
6
8
  const index = process.argv.indexOf(key);
7
9
  return index >= 0 && index < process.argv.length - 1 && !process.argv[index + 1].startsWith('-') ? process.argv[index + 1] : undefined;
@@ -23,18 +25,6 @@ export const parseDataFromFile = (dataPath: string, type: 'yaml' | 'json' = 'yam
23
25
  };
24
26
 
25
27
  export function getLibraryPath() {
26
- const __filename = fileURLToPath(import.meta.url);
27
- const __dirname = dirname(__filename);
28
-
29
- let currentDir = __dirname;
30
- while (!fs.existsSync(path.join(currentDir, 'package.json'))) {
31
- const parentDir = path.dirname(currentDir);
32
- if (parentDir === currentDir) {
33
- return null;
34
- }
35
- currentDir = parentDir;
36
- }
37
- const packageJsonPath = path.join(currentDir, 'package.json');
38
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
39
- return `node_modules/${packageJson.name}`;
28
+ const fileName = fileURLToPath(import.meta.url);
29
+ return slash(dirname(dirname(fileName)));
40
30
  }
package/src/index.ts CHANGED
@@ -1,12 +1,9 @@
1
1
  import chalk from 'chalk';
2
2
  import backstop from 'backstopjs';
3
3
  import config from './config.js';
4
- import { getStringArg } from './helpers.js';
4
+ import { getLibraryPath, getStringArg } from './helpers.js';
5
5
  import path from 'path';
6
6
  import fs from 'fs';
7
- import { fileURLToPath } from 'url';
8
-
9
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
7
 
11
8
  const command = getStringArg('--command') as 'approve' | 'init' | 'reference' | 'test' | undefined;
12
9
  if (!command) {
@@ -28,8 +25,7 @@ ${PATCH_END}
28
25
  `;
29
26
 
30
27
  const packCompare = () => {
31
- const projectRootDir = process.cwd();
32
- const reportIndex = path.resolve(projectRootDir, 'node_modules/backstopjs/compare/output/index.html');
28
+ const reportIndex = path.resolve(getLibraryPath(), 'node_modules/backstopjs/compare/output/index.html');
33
29
  if (fs.existsSync(reportIndex)) {
34
30
  let html = fs.readFileSync(reportIndex, 'utf-8');
35
31
  const patchStartIndex = html.indexOf(PATCH_START);