@wdio/utils 8.0.7 → 8.0.9

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.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAW,MAAM,aAAa,CAAA;AAQpD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,gBAAgB,EAAE;IAAE,sBAAsB,CAAC,EAAE;QAAE,KAAK,EAAE,GAAG,CAAA;KAAE,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,QAsCzH;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,UA+BrE;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAE,MAAM,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE;;;EAapF;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAE,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,WA8B/D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAE,GAAG,EAAE,GAAG,wGAExC;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,aAAa,GAAG,IAAI,CAAC,CA8DtF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAE,EAAE,EAAE,QAAQ,WAE5C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAE,IAAI,EAAE,GAAG,EAAE,SAE1C;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,WAanC;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,UAAW,MAAM,YAWtC,CAAA;AAED;;;GAGG;AAC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'node:fs';
2
2
  import path from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
- import { createRequire } from 'node:module';
5
- const require = createRequire(import.meta.url);
4
+ import { resolve } from 'import-meta-resolve';
6
5
  const SCREENSHOT_REPLACEMENT = '"<Screenshot[base64]>"';
7
6
  const SCRIPT_PLACEHOLDER = '"<Script[base64]>"';
8
7
  const REGEX_SCRIPT_NAME = /return \(function (\w+)/;
@@ -149,44 +148,42 @@ export function getArgumentType(arg) {
149
148
  * @return {object} package content
150
149
  */
151
150
  export async function safeImport(name) {
152
- let requirePath = name;
151
+ let importPath = name;
153
152
  try {
154
153
  /**
155
- * Check if cli command was called from local directory, if not require
156
- * the plugin from the place where the command is called. This avoids
157
- * issues where user have the @wdio/cli package installed globally
158
- * but run on a project where wdio packages are installed locally. It
159
- * also allows to link the package to a random place and have plugins
160
- * imported correctly (for dev purposes).
154
+ * Initially we will search for the package by using the standard package
155
+ * resolution starting from the path given by 'import.meta.url' (which
156
+ * returns the path to this file). The default mechanism will then search
157
+ * upwards through the hierarchy in the file system in node_modules directories
158
+ * until it finds the package or reaches the root of the file system.
159
+ *
160
+ * In the case where a user has installed the @wdio/cli package globally,
161
+ * then clearly the search will be performed in the global area and not
162
+ * in the project specific area. Consequently, if the package we are
163
+ * looking for is installed within the project it will not be found and
164
+ * then we also need to search in the project, we do that by defining
165
+ * 'localNodeModules' and searching from that also.
166
+ *
167
+ * Note that import-meta-resolve will resolve to CJS no ESM export is found
161
168
  */
162
169
  const localNodeModules = path.join(process.cwd(), 'node_modules');
163
- /* istanbul ignore if */
164
- if (!require.resolve.paths(name)?.includes(localNodeModules)) {
165
- const resolveLocation = [
166
- ...(require.resolve.paths(name) || []),
167
- localNodeModules
168
- ];
169
- /**
170
- * don't set requireOpts when running unit tests as it
171
- * confuses Jest require magic
172
- */
173
- const requireOpts = process.env.VITEST_WORKER_ID
174
- ? {}
175
- : { paths: resolveLocation };
176
- requirePath = require.resolve(name, requireOpts);
177
- }
178
- else {
179
- requirePath = require.resolve(name);
170
+ try {
171
+ importPath = await resolve(name, import.meta.url);
180
172
  }
181
- if (!requirePath.startsWith('file://')) {
182
- requirePath = pathToFileURL(requirePath).href;
173
+ catch (err) {
174
+ try {
175
+ importPath = await resolve(name, pathToFileURL(localNodeModules).toString());
176
+ }
177
+ catch (err) {
178
+ return null;
179
+ }
183
180
  }
184
181
  }
185
182
  catch (err) {
186
183
  return null;
187
184
  }
188
185
  try {
189
- const pkg = await import(requirePath);
186
+ const pkg = await import(importPath);
190
187
  /**
191
188
  * CJS packages build with TS imported through an ESM context can end up being this:
192
189
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/utils",
3
- "version": "8.0.7",
3
+ "version": "8.0.9",
4
4
  "description": "A WDIO helper utility to provide several utility functions used across the project.",
5
5
  "author": "Christian Bromann <mail@bromann.dev>",
6
6
  "homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-utils",
@@ -28,11 +28,12 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@wdio/logger": "8.0.0",
31
- "@wdio/types": "8.0.7",
31
+ "@wdio/types": "8.0.8",
32
+ "import-meta-resolve": "^2.2.0",
32
33
  "p-iteration": "^1.1.8"
33
34
  },
34
35
  "publishConfig": {
35
36
  "access": "public"
36
37
  },
37
- "gitHead": "a874a82a727634d1323fff05c17455ba0907a020"
38
+ "gitHead": "f92405a6bab7d0409d3b2777e8d65aaa493a4899"
38
39
  }