| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1864175 commit 044402c
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -123,7 +123,7 @@ void ProcessRunner::SetEnvironmentVariables() { | |||
| 123 | 123 | // Add NODE_RUN_PACKAGE_JSON_PATH environment variable to the environment to | |
| 124 | 124 | // indicate which package.json is being processed. | |
| 125 | 125 | env_vars_.push_back("NODE_RUN_PACKAGE_JSON_PATH=" + | |
| 126 | - package_json_path_.string()); | ||
| 126 | + ConvertPathToUTF8(package_json_path_)); | ||
| 127 | 127 | ||
| 128 | 128 | env_ = std::unique_ptr<char*[]>(new char*[env_vars_.size() + 1]); | |
| 129 | 129 | options_.env = env_.get(); | |
@@ -206,7 +206,7 @@ void ProcessRunner::OnExit(int64_t exit_status, int term_signal) { | |||
| 206 | 206 | ||
| 207 | 207 | void ProcessRunner::Run() { | |
| 208 | 208 | // keeps the string alive until destructor | |
| 209 | - cwd_ = package_json_path_.parent_path().string(); | ||
| 209 | + cwd_ = ConvertPathToUTF8(package_json_path_.parent_path()); | ||
| 210 | 210 | options_.cwd = cwd_.c_str(); | |
| 211 | 211 | if (int r = uv_spawn(loop_, &process_, &options_)) { | |
| 212 | 212 | fprintf(stderr, "Error: %s\n", uv_strerror(r)); | |
@@ -228,14 +228,14 @@ FindPackageJson(const std::filesystem::path& cwd) { | |||
| 228 | 228 | // Append "path/node_modules/.bin" to the env var, if it is a directory. | |
| 229 | 229 | auto node_modules_bin = directory_path / "node_modules" / ".bin"; | |
| 230 | 230 | if (std::filesystem::is_directory(node_modules_bin)) { | |
| 231 | - path_env_var += node_modules_bin.string() + env_var_separator; | ||
| 231 | + path_env_var += ConvertPathToUTF8(node_modules_bin) + env_var_separator; | ||
| 232 | 232 | } | |
| 233 | 233 | ||
| 234 | 234 | if (raw_content.empty()) { | |
| 235 | 235 | package_json_path = directory_path / "package.json"; | |
| 236 | 236 | // This is required for Windows because std::filesystem::path::c_str() | |
| 237 | 237 | // returns wchar_t* on Windows, and char* on other platforms. | |
| 238 | - std::string contents = package_json_path.string(); | ||
| 238 | + std::string contents = ConvertPathToUTF8(package_json_path); | ||
| 239 | 239 | USE(ReadFileSync(&raw_content, contents.c_str()) > 0); | |
| 240 | 240 | } | |
| 241 | 241 | } | |
@@ -258,7 +258,7 @@ void RunTask(const std::shared_ptr<InitializationResultImpl>& result, | |||
| 258 | 258 | if (!package_json.has_value()) { | |
| 259 | 259 | fprintf(stderr, | |
| 260 | 260 | "Can't find package.json for directory %s\n", | |
| 261 | - cwd.string().c_str()); | ||
| 261 | + ConvertPathToUTF8(cwd).c_str()); | ||
| 262 | 262 | result->exit_code_ = ExitCode::kGenericUserError; | |
| 263 | 263 | return; | |
| 264 | 264 | } | |
@@ -274,7 +274,7 @@ void RunTask(const std::shared_ptr<InitializationResultImpl>& result, | |||
| 274 | 274 | simdjson::ondemand::object main_object; | |
| 275 | 275 | ||
| 276 | 276 | if (json_parser.iterate(raw_json).get(document)) { | |
| 277 | - fprintf(stderr, "Can't parse %s\n", path.string().c_str()); | ||
| 277 | + fprintf(stderr, "Can't parse %s\n", ConvertPathToUTF8(path).c_str()); | ||
| 278 | 278 | result->exit_code_ = ExitCode::kGenericUserError; | |
| 279 | 279 | return; | |
| 280 | 280 | } | |
@@ -283,9 +283,9 @@ void RunTask(const std::shared_ptr<InitializationResultImpl>& result, | |||
| 283 | 283 | if (root_error == simdjson::error_code::INCORRECT_TYPE) { | |
| 284 | 284 | fprintf(stderr, | |
| 285 | 285 | "Root value unexpected not an object for %s\n\n", | |
| 286 | - path.string().c_str()); | ||
| 286 | + ConvertPathToUTF8(path).c_str()); | ||
| 287 | 287 | } else { | |
| 288 | - fprintf(stderr, "Can't parse %s\n", path.string().c_str()); | ||
| 288 | + fprintf(stderr, "Can't parse %s\n", ConvertPathToUTF8(path).c_str()); | ||
| 289 | 289 | } | |
| 290 | 290 | result->exit_code_ = ExitCode::kGenericUserError; | |
| 291 | 291 | return; | |
@@ -294,8 +294,9 @@ void RunTask(const std::shared_ptr<InitializationResultImpl>& result, | |||
| 294 | 294 | // If package_json object doesn't have "scripts" field, throw an error. | |
| 295 | 295 | simdjson::ondemand::object scripts_object; | |
| 296 | 296 | if (main_object["scripts"].get_object().get(scripts_object)) { | |
| 297 | - fprintf( | ||
| 298 | - stderr, "Can't find \"scripts\" field in %s\n", path.string().c_str()); | ||
| 297 | + fprintf(stderr, | ||
| 298 | + "Can't find \"scripts\" field in %s\n", | ||
| 299 | + ConvertPathToUTF8(path).c_str()); | ||
| 299 | 300 | result->exit_code_ = ExitCode::kGenericUserError; | |
| 300 | 301 | return; | |
| 301 | 302 | } | |
@@ -309,13 +310,13 @@ void RunTask(const std::shared_ptr<InitializationResultImpl>& result, | |||
| 309 | 310 | "Script \"%.*s\" is unexpectedly not a string for %s\n\n", | |
| 310 | 311 | static_cast<int>(command_id.size()), | |
| 311 | 312 | command_id.data(), | |
| 312 | - path.string().c_str()); | ||
| 313 | + ConvertPathToUTF8(path).c_str()); | ||
| 313 | 314 | } else { | |
| 314 | 315 | fprintf(stderr, | |
| 315 | 316 | "Missing script: \"%.*s\" for %s\n\n", | |
| 316 | 317 | static_cast<int>(command_id.size()), | |
| 317 | 318 | command_id.data(), | |
| 318 | - path.string().c_str()); | ||
| 319 | + ConvertPathToUTF8(path).c_str()); | ||
| 319 | 320 | fprintf(stderr, "Available scripts are:\n"); | |
| 320 | 321 | ||
| 321 | 322 | // Reset the object to iterate over it again | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,8 +5,11 @@ common.requireNoPackageJSONAbove(); | |||
| 5 | 5 | ||
| 6 | 6 | const { it, describe } = require('node:test'); | |
| 7 | 7 | const assert = require('node:assert'); | |
| 8 | + const fs = require('node:fs'); | ||
| 9 | + const path = require('node:path'); | ||
| 8 | 10 | ||
| 9 | 11 | const fixtures = require('../common/fixtures'); | |
| 12 | + const tmpdir = require('../common/tmpdir'); | ||
| 10 | 13 | const envSuffix = common.isWindows ? '-windows' : ''; | |
| 11 | 14 | ||
| 12 | 15 | describe('node --run [command]', () => { | |
@@ -201,6 +204,45 @@ describe('node --run [command]', () => { | |||
| 201 | 204 | assert.strictEqual(child.code, 0); | |
| 202 | 205 | }); | |
| 203 | 206 | ||
| 207 | + it('handles package paths outside the active Windows code page', | ||
| 208 | + { skip: !common.isWindows }, async () => { | ||
| 209 | + tmpdir.refresh(); | ||
| 210 | + | ||
| 211 | + const projectDir = path.join(tmpdir.path, 'node-run-\u{20BB7}'); | ||
| 212 | + const packageJsonPath = path.join(projectDir, 'package.json'); | ||
| 213 | + const nodeModulesBin = path.join(projectDir, 'node_modules', '.bin'); | ||
| 214 | + const checkScript = path.join(projectDir, 'check.js'); | ||
| 215 | + | ||
| 216 | + fs.mkdirSync(nodeModulesBin, { recursive: true }); | ||
| 217 | + fs.writeFileSync(packageJsonPath, JSON.stringify({ | ||
| 218 | + scripts: { | ||
| 219 | + unicode: `"${process.execPath}" check.js`, | ||
| 220 | + }, | ||
| 221 | + })); | ||
| 222 | + fs.writeFileSync(checkScript, ` | ||
| 223 | + 'use strict'; | ||
| 224 | + console.log(JSON.stringify({ | ||
| 225 | + cwd: process.cwd(), | ||
| 226 | + packageJsonPath: process.env.NODE_RUN_PACKAGE_JSON_PATH, | ||
| 227 | + path: process.env.PATH, | ||
| 228 | + })); | ||
| 229 | + `); | ||
| 230 | + | ||
| 231 | + const child = await common.spawnPromisified( | ||
| 232 | + process.execPath, | ||
| 233 | + [ '--run', 'unicode'], | ||
| 234 | + { cwd: projectDir }, | ||
| 235 | + ); | ||
| 236 | + | ||
| 237 | + assert.strictEqual(child.stderr, ''); | ||
| 238 | + assert.strictEqual(child.code, 0); | ||
| 239 | + | ||
| 240 | + const output = JSON.parse(child.stdout); | ||
| 241 | + assert.strictEqual(output.cwd, projectDir); | ||
| 242 | + assert.strictEqual(output.packageJsonPath, packageJsonPath); | ||
| 243 | + assert.strictEqual(output.path.split(path.delimiter)[0], nodeModulesBin); | ||
| 244 | + }); | ||
| 245 | + | ||
| 204 | 246 | it('returns error on unparsable file', async () => { | |
| 205 | 247 | const child = await common.spawnPromisified( | |
| 206 | 248 | process.execPath, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments