Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,17 @@
#include <node.h>
#include <uv.h>
#include <v8.h>
static void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(
v8::String::NewFromUtf8(isolate, "world").ToLocalChecked());
}
static void InitModule(v8::Local<v8::Object> exports,
v8::Local<v8::Value> module,
v8::Local<v8::Context> context) {
NODE_SET_METHOD(exports, "hello", Method);
}
NODE_MODULE_CONTEXT_AWARE(Binding, InitModule)

View File

@ -0,0 +1,30 @@
{
'variables': {
'source_dir': '<!("<(python)" -c "import os; print(os.getcwd())")',
},
'targets': [
{
'target_name': 'binding',
'sources': [ 'binding.cc' ],
'includes': ['../common.gypi'],
},
{
'target_name': 'node_modules',
'type': 'none',
'dependencies': [
'binding',
],
# The `exports` in package.json can not reference files outside the package
# directory. Copy the `binding.node` into the package directory so that
# it can be exported with the conditional exports.
'copies': [
{
'files': [
'<(PRODUCT_DIR)/binding.node'
],
'destination': '<(source_dir)/node_modules/esm-package/build',
},
],
}
]
}

View File

@ -0,0 +1,8 @@
{
"name": "esm-package",
"exports": {
"./binding": {
"node-addons": "./build/binding.node"
}
}
}

View File

@ -0,0 +1,34 @@
/**
* This file is supposed to be loaded by `test-import.js` and `test-require.js`
* to verify that `import('*.node')` is working properly either been loaded with
* the ESM loader or the CJS loader.
*/
import { buildType } from '../../common/index.mjs';
import assert from 'node:assert';
import { createRequire } from 'node:module';
import { pathToFileURL } from 'node:url';
const require = createRequire(import.meta.url);
export async function run() {
// binding.node
{
const bindingPath = require.resolve(`./build/${buildType}/binding.node`);
// Test with order of import+require
const { default: binding, 'module.exports': exports } = await import(pathToFileURL(bindingPath));
assert.strictEqual(binding, exports);
assert.strictEqual(binding.hello(), 'world');
const bindingRequire = require(bindingPath);
assert.strictEqual(binding, bindingRequire);
assert.strictEqual(binding.hello, bindingRequire.hello);
// Test multiple loading of the same addon.
// ESM cache can not be removed.
delete require.cache[bindingPath];
const { default: rebinding } = await import(pathToFileURL(bindingPath));
assert.strictEqual(rebinding.hello(), 'world');
assert.strictEqual(binding.hello, rebinding.hello);
}
}

View File

@ -0,0 +1,15 @@
// Flags: --experimental-addon-modules
'use strict';
const common = require('../../common');
const assert = require('node:assert');
/**
* Test that the export condition `node-addons` can be used
* with `*.node` files with the ESM loader.
*/
import('esm-package/binding')
.then((mod) => {
assert.strictEqual(mod.default.hello(), 'world');
})
.then(common.mustCall());

View File

@ -0,0 +1,7 @@
// Flags: --experimental-addon-modules
'use strict';
const common = require('../../common');
import('./test-esm.mjs')
.then((mod) => mod.run())
.then(common.mustCall());

View File

@ -0,0 +1,12 @@
// Flags: --experimental-addon-modules
'use strict';
require('../../common');
const assert = require('node:assert');
/**
* Test that the export condition `node-addons` can be used
* with `*.node` files with the CJS loader.
*/
const mod = require('esm-package/binding');
assert.strictEqual(mod.hello(), 'world');

View File

@ -0,0 +1,6 @@
// Flags: --experimental-addon-modules
'use strict';
const common = require('../../common');
require('./test-esm.mjs')
.run().then(common.mustCall());