Skip to content
12 changes: 9 additions & 3 deletions .github/workflows/coverage-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ on:
- codecov.yml
- .nycrc

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
# concurrency:
# group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
# cancel-in-progress: true

env:
PYTHON_VERSION: '3.12'
Expand Down Expand Up @@ -74,3 +74,9 @@ jobs:
uses: codecov/codecov-action@015f24e6818733317a2da2edd6290ab26238649a # v5.0.7
with:
directory: ./coverage
- name: Change locale ja-JP for testing on SJIS environment
run: Set-WinSystemLocale -SystemLocale "ja-JP"
- name: Test on SJIS environment
run: ./vcbuild.bat nobuild noprojgen test-ci-js; node -e 'process.exit(0)'
env:
NODE_V8_COVERAGE: ./coverage/tmp
7 changes: 6 additions & 1 deletion lib/internal/child_process/serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ const advanced = {
*parseChannelMessages(channel, readData) {
if (readData.length === 0) return;

ArrayPrototypePush(channel[kMessageBuffer], readData);
if (channel[kMessageBufferSize] && channel[kMessageBuffer][0].length < 4) {
// Message length split into two buffers, so let's concatenate it.
channel[kMessageBuffer][0] = Buffer.concat([channel[kMessageBuffer][0], readData]);
} else {
ArrayPrototypePush(channel[kMessageBuffer], readData);
}
channel[kMessageBufferSize] += readData.length;

// Index 0 should always be present because we just pushed data into it.
Expand Down
19 changes: 12 additions & 7 deletions lib/punycode.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
'use strict';

process.emitWarning(
'The `punycode` module is deprecated. Please use a userland ' +
'alternative instead.',
'DeprecationWarning',
'DEP0040',
);
const {
isInsideNodeModules,
} = internalBinding('util');

if (!isInsideNodeModules(100, true)) {
process.emitWarning(
'The `punycode` module is deprecated. Please use a userland ' +
'alternative instead.',
'DeprecationWarning',
'DEP0040',
);
}

/** Highest positive signed 32-bit float value */
const maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
Expand Down
40 changes: 36 additions & 4 deletions src/node_modules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

#include "simdjson.h"

#ifdef _WIN32
#include <windows.h>
#endif

namespace node {
namespace modules {

Expand Down Expand Up @@ -326,6 +330,18 @@ const BindingData::PackageConfig* BindingData::TraverseParent(
return nullptr;
}

#ifdef _WIN32
std::wstring MaybeWCharTToWSTring(const std::string& input) {
bool is_unicode = IsTextUnicode(input.c_str(), input.size(), nullptr);
auto code_page = is_unicode ? CP_UTF8 : GetACP();
int length = MultiByteToWideChar(code_page, 0, input.c_str(), -1, nullptr, 0);

std::wstring wide_str(length, 0);
MultiByteToWideChar(code_page, 0, input.c_str(), -1, &wide_str[0], length);
return wide_str;
}
#endif

void BindingData::GetNearestParentPackageJSON(
const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK_GE(args.Length(), 1);
Expand All @@ -344,8 +360,16 @@ void BindingData::GetNearestParentPackageJSON(
path_value_str.push_back(kPathSeparator);
}

auto package_json =
TraverseParent(realm, std::filesystem::path(path_value_str));
std::filesystem::path path;

#ifdef _WIN32
std::wstring wide_path = MaybeWCharTToWSTring(path_value_str);
path = std::filesystem::path(wide_path);
#else
path = std::filesystem::path(path_value_str);
#endif

auto package_json = TraverseParent(realm, path);

if (package_json != nullptr) {
args.GetReturnValue().Set(package_json->Serialize(realm));
Expand All @@ -370,8 +394,16 @@ void BindingData::GetNearestParentPackageJSONType(
path_value_str.push_back(kPathSeparator);
}

auto package_json =
TraverseParent(realm, std::filesystem::path(path_value_str));
std::filesystem::path path;

#ifdef _WIN32
std::wstring wide_path = MaybeWCharTToWSTring(path_value_str);
path = std::filesystem::path(wide_path);
#else
path = std::filesystem::path(path_value_str);
#endif

auto package_json = TraverseParent(realm, path);

if (package_json == nullptr) {
return;
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/errors/core_line_numbers.snapshot
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
node:punycode:49
node:punycode:54
throw new RangeError(errors[type]);
^

RangeError: Invalid input
at error (node:punycode:49:8)
at Object.decode (node:punycode:242:5)
at error (node:punycode:54:8)
at Object.decode (node:punycode:247:5)
at Object.<anonymous> (*core_line_numbers.js:13:10)

Node.js *
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';
const common = require('../common');
const child_process = require('child_process');

// Regression test for https://github.com/nodejs/node/issues/55834
const msgLen = 65521;
let cnt = 10;

if (process.argv[2] === 'child') {
const msg = Buffer.allocUnsafe(msgLen);
(function send() {
if (cnt--) {
process.send(msg, send);
} else {
process.disconnect();
}
})();
} else {
const child = child_process.spawn(process.execPath, [__filename, 'child'], {
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
serialization: 'advanced'
});
child.on('message', common.mustCall(cnt));
}
15 changes: 15 additions & 0 deletions test/parallel/test-module-create-require-multibyte.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');

// This test ensures that the module can be resolved
// even if the path given to createRequire contains multibyte characters.

const { createRequire } = require('module');

const u = fixtures.fileURL('あ.js');

const reqToo = createRequire(u);
assert.deepStrictEqual(reqToo('./experimental'), { ofLife: 42 });
Loading