-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add import.meta.resolve documentation (#1691)
Co-authored-by: Joan López de la Franca Beltran <[email protected]> Co-authored-by: Heitor Tashiro Sergent <[email protected]>
- Loading branch information
1 parent
dde3ddc
commit 706d47c
Showing
5 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: 'import.meta' | ||
description: 'Details about the ECMAScript import meta property.' | ||
weight: 20 | ||
--- | ||
|
||
## import.meta | ||
|
||
{{< docs/shared source="k6" lookup="javascript-api/import.meta.md" version="<K6_VERSION>" >}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
title: 'resolve( path )' | ||
description: 'Resolve the path to a URL string in the same way an import statement does.' | ||
--- | ||
|
||
# resolve( path ) | ||
|
||
Resolve a path to a URL string in the same way an import statement does.' | ||
|
||
This is useful if you want to provide a path relative to the current module to a function that uses `open` or another function that takes URLs. | ||
|
||
This is particularly useful as some functions within k6 are not relative to the same origin, which might lead to seemingly similar paths having different files being loaded from the filesystem. | ||
|
||
For more details, refer to this [issue](https://github.com/grafana/k6/issues/3857). | ||
|
||
| Parameter | Type | Description | | ||
| --------- | ------ | -------------------------- | | ||
| path | string | A file path. | | ||
|
||
### Example | ||
|
||
{{< code >}} | ||
|
||
```javascript | ||
const pdfFile = open(import.meta.resolve('./path/to/file.pdf'), 'b'); | ||
|
||
export default function () { | ||
// this is here to avoid an exception if run using k6 | ||
} | ||
``` | ||
{{< /code >}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: 'javascript-api/import.meta' | ||
--- | ||
|
||
`import.meta` is only available in ECMAScript modules, but not CommonJS ones. | ||
|
||
| Function | Description | | ||
| -------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | | ||
| [import.meta.resolve](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/import.meta/resolve) | resolve path to URL the same way that an ESM import would | |