create-wdio 8.3.4 → 8.4.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.
@@ -55,6 +55,18 @@ export const INSTALL_COMMAND = {
55
55
  yarn: 'add',
56
56
  bun: 'install'
57
57
  };
58
+ export const EXECUTER = {
59
+ npm: 'npx',
60
+ pnpm: 'pnpm',
61
+ yarn: 'yarn',
62
+ bun: 'bunx'
63
+ };
64
+ export const EXECUTE_COMMAND = {
65
+ npm: '',
66
+ pnpm: 'exec',
67
+ yarn: 'exec',
68
+ bun: ''
69
+ };
58
70
  export const DEV_FLAG = {
59
71
  npm: '--save-dev',
60
72
  pnpm: '--save-dev',
package/build/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
3
4
  import chalk from 'chalk';
4
5
  import semver from 'semver';
5
- import { detect } from 'detect-package-manager';
6
- import { readPackageUp } from 'read-pkg-up';
7
6
  import { Command } from 'commander';
7
+ import { resolve } from 'import-meta-resolve';
8
8
  import { runProgram, getPackageVersion } from './utils.js';
9
- import { ASCII_ROBOT, PROGRAM_TITLE, UNSUPPORTED_NODE_VERSION, DEFAULT_NPM_TAG, INSTALL_COMMAND, DEV_FLAG, PMs } from './constants.js';
9
+ import { ASCII_ROBOT, PROGRAM_TITLE, UNSUPPORTED_NODE_VERSION, DEFAULT_NPM_TAG, INSTALL_COMMAND, DEV_FLAG, PMs, EXECUTER, EXECUTE_COMMAND } from './constants.js';
10
+ import { execSync } from 'node:child_process';
10
11
  const WDIO_COMMAND = 'wdio';
11
12
  let projectDir;
12
13
  export async function run(operation = createWebdriverIO) {
@@ -42,46 +43,57 @@ export async function createWebdriverIO(opts) {
42
43
  const npmTag = opts.npmTag.startsWith('@') ? opts.npmTag : `@${opts.npmTag}`;
43
44
  const root = path.resolve(process.cwd(), projectDir || '');
44
45
  /**
45
- * check if a package.json exists and if not create one
46
+ * find package manager that was used to create project
46
47
  */
47
- const project = await readPackageUp({ cwd: root });
48
- if (!project) {
48
+ const pm = PMs.find((pm) => (
49
+ // for pnpm check "~/Library/pnpm/store/v3/..."
50
+ // for NPM check "~/.npm/npx/..."
51
+ // for Yarn check "~/.yarn/bin/create-wdio"
52
+ // for Bun check "~/.bun/bin/create-wdio"
53
+ process.argv[1].includes(`${path.sep}${pm}${path.sep}`) ||
54
+ process.argv[1].includes(`${path.sep}.${pm}${path.sep}`))) || 'npm';
55
+ const hasPackageJson = await fs.access(path.resolve(root, 'package.json')).then(() => true).catch(() => false);
56
+ if (!hasPackageJson) {
49
57
  await fs.mkdir(root, { recursive: true });
50
58
  await fs.writeFile(path.resolve(root, 'package.json'), JSON.stringify({
51
- name: 'my-new-project',
59
+ name: root.replace(/\/$/, '').split('/').pop(),
52
60
  type: 'module'
53
61
  }, null, 2));
54
- /**
55
- * find package manager that was used to create project
56
- */
57
- const pm = PMs.find((pm) => (
58
- // for pnpm check for "~/Library/pnpm/store/v3/..."
59
- process.argv[1].includes(`${path.sep}${pm}${path.sep}`) ||
60
- // for NPM and Yarn check for "~/.npm/npx/..." or "~/.yarn/bin/create-wdio"
61
- process.argv[1].includes(`${path.sep}.${pm}${path.sep}`))) || 'npm';
62
- /**
63
- * create a package-lock.json, yarn.lock or pnpm-lock.yaml so
64
- * that `detect-package-manager` doesn't mark it as a default
65
- * Yarn project
66
- * @see https://github.com/egoist/detect-package-manager/issues/11
67
- */
68
- await runProgram(pm, ['install'], { cwd: root, stdio: 'ignore' });
69
62
  }
70
- console.log(`\nInstalling ${chalk.bold('@wdio/cli')} to initialize project...`);
71
- const pm = await detect({ cwd: root });
72
- const args = [INSTALL_COMMAND[pm]];
73
- if (pm === 'yarn') {
74
- args.push('--exact', '--cwd', root);
63
+ const cliInstalled = await isCLIInstalled(root);
64
+ if (!cliInstalled) {
65
+ console.log(`\nInstalling ${chalk.bold('@wdio/cli')} to initialize project...`);
66
+ const args = [INSTALL_COMMAND[pm]];
67
+ if (pm === 'yarn') {
68
+ args.push('--exact', '--cwd', root);
69
+ }
70
+ if (opts.dev) {
71
+ args.push(DEV_FLAG[pm]);
72
+ }
73
+ args.push(`@wdio/cli${npmTag}`);
74
+ await runProgram(pm, args, { cwd: root, stdio: 'ignore' });
75
+ console.log(chalk.green.bold('✔ Success!'));
75
76
  }
76
- if (opts.dev) {
77
- args.push(DEV_FLAG[pm]);
78
- }
79
- args.push(`@wdio/cli${npmTag}`);
80
- await runProgram(pm, args, { cwd: root, stdio: 'ignore' });
81
- console.log(chalk.green.bold('✔ Success!'));
82
- return runProgram('npx', [
77
+ return runProgram(EXECUTER[pm], [
78
+ EXECUTE_COMMAND[pm],
83
79
  WDIO_COMMAND,
84
80
  'config',
85
81
  ...(opts.yes ? ['--yes'] : [])
86
- ], { cwd: root });
82
+ ].filter(i => !!i), { cwd: root });
83
+ }
84
+ async function isCLIInstalled(path) {
85
+ try {
86
+ // can be replaced with import.meta.resolve('@wdio/cli', new URL(`file:///${root}`).href) in the future
87
+ // check if the cli is installed in the project
88
+ resolve('@wdio/cli', pathToFileURL(path).href);
89
+ return true;
90
+ }
91
+ catch (error) {
92
+ // check of the cli is installed globally
93
+ const output = execSync('npm ls -g', { encoding: 'utf-8' });
94
+ if (output.includes('@wdio/cli')) {
95
+ return true;
96
+ }
97
+ return false;
98
+ }
87
99
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-wdio",
3
- "version": "8.3.4",
3
+ "version": "8.4.1",
4
4
  "description": "Install and setup a WebdriverIO project with all its dependencies in a single run",
5
5
  "author": "Christian Bromann <mail@bromann.dev>",
6
6
  "license": "MIT",
@@ -46,9 +46,9 @@
46
46
  "@vitest/coverage-v8": "^0.34.1",
47
47
  "eslint": "^8.45.0",
48
48
  "eslint-plugin-import": "^2.27.5",
49
- "eslint-plugin-unicorn": "^48.0.0",
49
+ "eslint-plugin-unicorn": "^49.0.0",
50
50
  "npm-run-all": "^4.1.5",
51
- "release-it": "^16.1.2",
51
+ "release-it": "^17.0.0",
52
52
  "typescript": "^5.1.6",
53
53
  "vitest": "^0.34.1"
54
54
  },
@@ -56,8 +56,7 @@
56
56
  "chalk": "^5.3.0",
57
57
  "commander": "^11.0.0",
58
58
  "cross-spawn": "^7.0.3",
59
- "detect-package-manager": "^3.0.1",
60
- "read-pkg-up": "^10.0.0",
59
+ "import-meta-resolve": "^4.0.0",
61
60
  "semver": "^7.5.4"
62
61
  }
63
62
  }