+93
| #include <assert.h> | ||
| #include <bare.h> | ||
| #include <js.h> | ||
| #include <stddef.h> | ||
| #include <utf.h> | ||
| #include <uv.h> | ||
| static js_value_t * | ||
| bare_path_cwd(js_env_t *env, js_callback_info_t *info) { | ||
| int err; | ||
| size_t argc = 1; | ||
| js_value_t *argv[1]; | ||
| err = js_get_callback_info(env, info, &argc, argv, NULL, NULL); | ||
| assert(err == 0); | ||
| // An optional drive specifier, such as "C:", requests the current working | ||
| // directory of that specific drive rather than of the process. On Windows | ||
| // this is stored in the magic "=C:" environment variable. The variable name | ||
| // is constructed here from a validated drive letter so that only these | ||
| // per-drive current-directory variables can ever be read, never arbitrary | ||
| // environment variables. | ||
| if (argc >= 1) { | ||
| utf8_t device[8]; | ||
| size_t device_len; | ||
| err = js_get_value_string_utf8(env, argv[0], device, sizeof(device), &device_len); | ||
| if ( | ||
| err == 0 && | ||
| device_len == 2 && | ||
| device[1] == ':' && | ||
| ((device[0] >= 'A' && device[0] <= 'Z') || (device[0] >= 'a' && device[0] <= 'z')) | ||
| ) { | ||
| char name[4] = {'=', (char) device[0], ':', '\0'}; | ||
| char value[4096]; | ||
| size_t value_len = sizeof(value); | ||
| err = uv_os_getenv(name, value, &value_len); | ||
| // Fall through to the process working directory when the variable is | ||
| // unset or otherwise cannot be read. | ||
| if (err == 0) { | ||
| js_value_t *result; | ||
| err = js_create_string_utf8(env, (utf8_t *) value, value_len, &result); | ||
| assert(err == 0); | ||
| return result; | ||
| } | ||
| } | ||
| } | ||
| char cwd[4096]; | ||
| size_t cwd_len = sizeof(cwd); | ||
| err = uv_cwd(cwd, &cwd_len); | ||
| if (err < 0) { | ||
| err = js_throw_error(env, uv_err_name(err), uv_strerror(err)); | ||
| assert(err == 0); | ||
| return NULL; | ||
| } | ||
| js_value_t *result; | ||
| err = js_create_string_utf8(env, (utf8_t *) cwd, cwd_len, &result); | ||
| assert(err == 0); | ||
| return result; | ||
| } | ||
| static js_value_t * | ||
| bare_path_exports(js_env_t *env, js_value_t *exports) { | ||
| int err; | ||
| #define V(name, fn) \ | ||
| { \ | ||
| js_value_t *val; \ | ||
| err = js_create_function(env, name, -1, fn, NULL, &val); \ | ||
| assert(err == 0); \ | ||
| err = js_set_named_property(env, exports, name, val); \ | ||
| assert(err == 0); \ | ||
| } | ||
| V("cwd", bare_path_cwd) | ||
| #undef V | ||
| return exports; | ||
| } | ||
| BARE_MODULE(bare_path, bare_path_exports) |
| module.exports = require.addon() |
| cmake_minimum_required(VERSION 4.0) | ||
| find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare) | ||
| project(bare_path C) | ||
| add_bare_module(bare_path) | ||
| target_sources( | ||
| ${bare_path} | ||
| PRIVATE | ||
| binding.c | ||
| ) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
+2
-2
@@ -1,2 +0,2 @@ | ||
| const os = require('bare-os') | ||
| const binding = require('../binding') | ||
@@ -21,3 +21,3 @@ const { normalizeString } = require('./shared') | ||
| for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) { | ||
| const path = i >= 0 ? args[i] : os.cwd() | ||
| const path = i >= 0 ? args[i] : binding.cwd() | ||
@@ -24,0 +24,0 @@ if (path.length === 0) { |
+3
-3
@@ -1,2 +0,2 @@ | ||
| const os = require('bare-os') | ||
| const binding = require('../binding') | ||
@@ -45,5 +45,5 @@ const { normalizeString } = require('./shared') | ||
| } else if (resolvedDevice.length === 0) { | ||
| path = os.cwd() | ||
| path = binding.cwd() | ||
| } else { | ||
| path = os.getEnv(`=${resolvedDevice}`) || os.cwd() | ||
| path = binding.cwd(resolvedDevice) | ||
@@ -50,0 +50,0 @@ if ( |
+7
-4
| { | ||
| "name": "bare-path", | ||
| "version": "3.0.1", | ||
| "version": "3.1.0", | ||
| "description": "Path manipulation library for JavaScript", | ||
@@ -17,5 +17,10 @@ "exports": { | ||
| "index.d.ts", | ||
| "binding.c", | ||
| "binding.js", | ||
| "CMakeLists.txt", | ||
| "lib", | ||
| "prebuilds", | ||
| "NOTICE" | ||
| ], | ||
| "addon": true, | ||
| "scripts": { | ||
@@ -36,7 +41,5 @@ "format": "prettier --write . && lunte --fix", | ||
| "homepage": "https://github.com/holepunchto/bare-path#readme", | ||
| "dependencies": { | ||
| "bare-os": "^3.0.1" | ||
| }, | ||
| "devDependencies": { | ||
| "brittle": "^3.3.2", | ||
| "cmake-bare": "^1.1.6", | ||
| "lunte": "^1.8.0", | ||
@@ -43,0 +46,0 @@ "prettier": "^3.6.2", |
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Unidentified License
LicenseSomething that seems like a license was found, but its contents could not be matched with a known license.
Unidentified License
LicenseSomething that seems like a license was found, but its contents could not be matched with a known license.
505798
1285.44%0
-100%26
160%801
0.13%5
25%13
Infinity%- Removed
- Removed