Repository: Microsoft/node-uwp
Branch: master
Commit: cbb40f319374
Files: 11
Total size: 17.2 KB
Directory structure:
gitextract_m2z66kne/
├── .gitignore
├── LICENSE
├── README.md
├── SECURITY.md
├── binding.gyp
├── index.js
├── package.json
├── src/
│ ├── node-async.h
│ ├── uwp.cc
│ └── uwp.h
└── test/
└── index.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
build
node_modules
================================================
FILE: LICENSE
================================================
The MIT License (MIT)
Copyright (c) 2015 Microsoft
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
node-uwp
==========
Enables Universal Windows Platform (UWP) API access for Node.js (Chakra build)
on Windows 10.
Example
-------
```javascript
const uwp = require('uwp');
const Windows = uwp.projectNamespace('Windows');
Windows.Storage.KnownFolders.documentsLibrary.createFileAsync(
'sample.dat', Windows.Storage.CreationCollisionOption.replaceExisting)
.done(
function (file) {
console.log('ok');
uwp.close(); // all async operations are completed, release uwp
},
function (error) {
console.error('error', error);
uwp.close(); // all async operations are completed, release uwp
}
);
```
Installation
------------
### Prerequisites
* Windows 10 [1511 or above](http://windows.microsoft.com/en-us/windows-10/windows-update-faq)
* [Visual Studio](https://www.visualstudio.com/vs-2015-product-editions)
* [Node.js (Chakra)](http://aka.ms/node-chakra-installer)
Run under Node.js (Chakra) command prompt:
```sh
npm install uwp
```
APIs
----
This package exports 2 functions.
### projectNamespace(name)
Project a UWP namespace of given name.
* **Note**: This function will keep Node process alive so that your app can
continue to run and handle UWP async callbacks. You need to call
[close()](#close) when UWP usage is completed.
<a name="close"></a>
### close()
Close all UWP handles used by this package. Call this when all UWP usage is
completed.
---------------------------------------------------------------------------
Checkout our OSS effort with
[Node-ChakraCore](https://github.com/nodejs/node-chakracore). It supports the
most recent version of node.js and will also be useful if you are on Windows 7
or Windows 8.1. Note: <b>It does not support UWP.</b>
================================================
FILE: SECURITY.md
================================================
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.8 BLOCK -->
## Security
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.
## Reporting Security Issues
**Please do not report security vulnerabilities through public GitHub issues.**
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue
This information will help us triage your report more quickly.
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.
## Preferred Languages
We prefer all communications to be in English.
## Policy
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).
<!-- END MICROSOFT SECURITY.MD BLOCK -->
================================================
FILE: binding.gyp
================================================
{
'targets': [{
'target_name': 'uwp',
"include_dirs" : [
"<!(node -e \"require('nan')\")"
],
'sources': [
'binding.gyp',
'index.js',
'package.json',
'src/node-async.h',
'src/uwp.h',
'src/uwp.cc',
],
}]
}
================================================
FILE: index.js
================================================
// Copyright Microsoft. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and / or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
const uwp = module.exports = require('./build/release/uwp.node');
const nativeProjectNamespace = uwp.projectNamespace;
uwp.projectNamespace = function(namespace) {
nativeProjectNamespace.call(uwp, namespace);
return namespace.split('.').reduce(function(prev, name) {
return prev[name];
}, global);
};
================================================
FILE: package.json
================================================
{
"name": "uwp",
"version": "1.0.2",
"description": "Enables Universal Windows Platform (UWP) API access for Node.js (Chakra build) on Windows 10.",
"main": "index.js",
"scripts": {
"install": "node-gyp rebuild",
"test": "node test/index.js"
},
"repository": {
"type": "git",
"url": "git://github.com/Microsoft/node-uwp.git"
},
"keywords": [
"uwp",
"node",
"node-uwp",
"jsrt",
"chakra"
],
"author": "jianxu@microsoft.com",
"license": "MIT",
"gypfile": true,
"bugs": {
"url": "https://github.com/Microsoft/node-uwp/issues"
},
"homepage": "https://github.com/Microsoft/node-uwp#readme",
"dependencies": {
"nan": "^2.1.0"
}
}
================================================
FILE: src/node-async.h
================================================
// Copyright Microsoft. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and / or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
#pragma once
//
// This file is derived from https://github.com/saary/node-async-helper
//
#include "v8.h"
#include "nan.h"
#include <thread>
namespace NodeUtils {
extern std::thread::id g_mainThreadId;
class Async {
private:
class TokenData {
private:
std::function<void()> func;
friend Async;
public:
static uv_async_t* NewAsyncToken() {
uv_async_t* asyncHandle = new uv_async_t;
uv_async_init(uv_default_loop(), asyncHandle, AsyncCb);
asyncHandle->data = new TokenData();
return asyncHandle;
}
};
public:
static uv_async_t* GetAsyncToken() {
return TokenData::NewAsyncToken();
}
static void ReleaseAsyncToken(uv_async_t* handle) {
TokenData* tokenData = static_cast<TokenData*>(handle->data);
uv_close(reinterpret_cast<uv_handle_t*>(handle), AyncCloseCb);
delete tokenData;
}
static void RunOnMain(uv_async_t* async, std::function<void()> func) {
TokenData* tokenData = static_cast<TokenData*>(async->data);
tokenData->func = func;
uv_async_send(async);
}
static void RunOnMain(std::function<void()> func) {
if (std::this_thread::get_id() == g_mainThreadId) {
func();
} else {
uv_async_t *async = GetAsyncToken();
RunOnMain(async, func);
}
}
private:
// called after the async handle is closed in order to free it's memory
static void AyncCloseCb(uv_handle_t* handle) {
if (handle != nullptr) {
uv_async_t* async = reinterpret_cast<uv_async_t*>(handle);
delete async;
}
}
// Called by run on main in case we are not running on the main thread
static void AsyncCb(uv_async_t* handle) {
TokenData* tokenData = static_cast<TokenData*>(handle->data);
tokenData->func();
ReleaseAsyncToken(handle);
}
};
} // namespace NodeUtils
================================================
FILE: src/uwp.cc
================================================
// Copyright Microsoft. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and / or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
#include "uwp.h"
std::thread::id NodeUtils::g_mainThreadId;
UWPAddOn UWPAddOn::s_instance;
bool UWPAddOn::EnsureCoInitialized() {
if (!_coInitialized) {
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
_coInitialized = SUCCEEDED(hr);
if (!_coInitialized) {
Nan::ThrowError("CoInitializeEx failed");
}
}
return _coInitialized;
}
void UWPAddOn::EnsureCoUninitialized() {
if (_coInitialized) {
CoUninitialize();
_coInitialized = false;
}
}
bool UWPAddOn::EnsureKeepAlive() {
if (_keepAliveToken == nullptr) {
// Open an active async handler to keep Node alive
_keepAliveToken = Async::GetAsyncToken();
}
return _keepAliveToken != nullptr;
}
void UWPAddOn::ReleaseKeepAlive() {
if (_keepAliveToken != nullptr) {
auto token = _keepAliveToken;
_keepAliveToken = nullptr;
Async::ReleaseAsyncToken(token);
}
}
void UWPAddOn::Init(Handle<Object> target) {
Nan::HandleScope scope;
NodeUtils::g_mainThreadId =
std::this_thread::get_id(); // Capture entering thread id
if (!s_instance.EnsureCoInitialized()) {
return;
}
JsErrorCode err = JsSetProjectionEnqueueCallback(
[](JsProjectionCallback jsCallback,
JsProjectionCallbackContext jsContext, void *context) {
Async::RunOnMain([jsCallback, jsContext]() {
jsCallback(jsContext);
});
},
/*projectionEnqueueContext*/nullptr);
if (err != JsNoError) {
Nan::ThrowError("JsSetProjectionEnqueueCallback failed");
return;
}
Nan::SetMethod(target, "projectNamespace", ProjectNamespace);
Nan::SetMethod(target, "close", Close);
}
NAN_METHOD(UWPAddOn::ProjectNamespace) {
Nan::HandleScope scope;
if (!info[0]->IsString()) {
Nan::ThrowTypeError("Argument must be a string");
return;
}
if (!s_instance.EnsureCoInitialized()) {
return;
}
String::Value name(info[0]);
if (JsProjectWinRTNamespace(reinterpret_cast<wchar_t*>(*name)) != JsNoError) {
Nan::ThrowError("JsProjectWinRTNamespace failed");
return;
}
// Keep Node alive once successfully projected a UWP namespace
s_instance.EnsureKeepAlive();
return;
}
NAN_METHOD(UWPAddOn::Close) {
Nan::HandleScope scope;
s_instance.ReleaseKeepAlive();
s_instance.EnsureCoUninitialized();
return;
}
NODE_MODULE(uwp, UWPAddOn::Init);
================================================
FILE: src/uwp.h
================================================
// Copyright Microsoft. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and / or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
#pragma once
#include "node-async.h"
using namespace v8;
using NodeUtils::Async;
class UWPAddOn {
private:
bool _coInitialized;
uv_async_t* _keepAliveToken;
static UWPAddOn s_instance; // single instance
bool EnsureCoInitialized();
void EnsureCoUninitialized();
bool EnsureKeepAlive();
void ReleaseKeepAlive();
public:
UWPAddOn()
: _coInitialized(false), _keepAliveToken(nullptr) {
}
static void Init(Handle<Object> target);
static NAN_METHOD(ProjectNamespace);
static NAN_METHOD(Close);
};
================================================
FILE: test/index.js
================================================
// Copyright Microsoft. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and / or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
const uwp = require('../index.js');
const Windows = uwp.projectNamespace('Windows');
Windows.Storage.KnownFolders.documentsLibrary.createFileAsync(
'sample.dat', Windows.Storage.CreationCollisionOption.replaceExisting)
.done(
function (file) {
console.log('ok');
uwp.close(); // all async operations are completed, release uwp
},
function (error) {
console.error('error', error);
uwp.close(); // all async operations are completed, release uwp
}
);
gitextract_m2z66kne/
├── .gitignore
├── LICENSE
├── README.md
├── SECURITY.md
├── binding.gyp
├── index.js
├── package.json
├── src/
│ ├── node-async.h
│ ├── uwp.cc
│ └── uwp.h
└── test/
└── index.js
SYMBOL INDEX (4 symbols across 3 files)
FILE: src/node-async.h
function namespace (line 31) | namespace NodeUtils {
FILE: src/uwp.cc
function NAN_METHOD (line 91) | NAN_METHOD(UWPAddOn::ProjectNamespace) {
function NAN_METHOD (line 114) | NAN_METHOD(UWPAddOn::Close) {
FILE: src/uwp.h
function class (line 27) | class UWPAddOn {
Condensed preview — 11 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (19K chars).
[
{
"path": ".gitignore",
"chars": 19,
"preview": "build\nnode_modules\n"
},
{
"path": "LICENSE",
"chars": 1077,
"preview": "The MIT License (MIT)\n\nCopyright (c) 2015 Microsoft\n\nPermission is hereby granted, free of charge, to any person obtaini"
},
{
"path": "README.md",
"chars": 1730,
"preview": "node-uwp\n==========\n\nEnables Universal Windows Platform (UWP) API access for Node.js (Chakra build)\non Windows 10.\n\nExam"
},
{
"path": "SECURITY.md",
"chars": 2757,
"preview": "<!-- BEGIN MICROSOFT SECURITY.MD V0.0.8 BLOCK -->\n\n## Security\n\nMicrosoft takes the security of our software products an"
},
{
"path": "binding.gyp",
"chars": 270,
"preview": "{\n 'targets': [{\n 'target_name': 'uwp',\n \"include_dirs\" : [\n \"<!(node -e \\\"require('nan')\\\")\"\n ],\n 'so"
},
{
"path": "index.js",
"chars": 1434,
"preview": "// Copyright Microsoft. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining"
},
{
"path": "package.json",
"chars": 703,
"preview": "{\n \"name\": \"uwp\",\n \"version\": \"1.0.2\",\n \"description\": \"Enables Universal Windows Platform (UWP) API access for Node."
},
{
"path": "src/node-async.h",
"chars": 2934,
"preview": "// Copyright Microsoft. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining"
},
{
"path": "src/uwp.cc",
"chars": 3441,
"preview": "// Copyright Microsoft. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining"
},
{
"path": "src/uwp.h",
"chars": 1652,
"preview": "// Copyright Microsoft. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining"
},
{
"path": "test/index.js",
"chars": 1616,
"preview": "// Copyright Microsoft. All rights reserved.\n//\n// Permission is hereby granted, free of charge, to any person obtaining"
}
]
About this extraction
This page contains the full source code of the Microsoft/node-uwp GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 11 files (17.2 KB), approximately 4.3k tokens, and a symbol index with 4 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.