-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
emit ".node" binaries that are required
- Loading branch information
1 parent
2ade601
commit 1239e0a
Showing
12 changed files
with
122 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# About this directory | ||
|
||
This directory will contain: | ||
|
||
- `node-loader.js` the ncc loader for supporting Node binary requires | ||
- `relocate-loader.js` the ncc loader for handling CommonJS asset and reference relocations | ||
|
||
These are generated by the `build` step defined in `../../../package.json`. | ||
|
||
These files are published to npm. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const { getOptions } = require('loader-utils'); | ||
const getUniqueAssetName = require('../utils/dedupe-names'); | ||
|
||
module.exports = function (content) { | ||
if (this.cacheable) | ||
this.cacheable(); | ||
|
||
const id = this.resourcePath; | ||
const options = getOptions(this); | ||
|
||
const name = getUniqueAssetName(id, options.assetNames); | ||
this.emitFile(name, content); | ||
|
||
return 'module.exports = __non_webpack_require__("./' + name + '")'; | ||
}; | ||
module.exports.raw = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const path = require("path"); | ||
|
||
module.exports = function (assetPath, assetNames) { | ||
const basename = path.basename(assetPath); | ||
const ext = path.extname(basename); | ||
let name = basename, i = 0; | ||
while (name in assetNames && assetNames[name] !== assetPath) | ||
name = basename.substr(0, basename.length - ext.length) + ++i + ext; | ||
assetNames[name] = assetPath; | ||
return name; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"targets": [ | ||
{ | ||
"target_name": "hello", | ||
"sources": [ "hello.cc" ], | ||
"include_dirs": [ | ||
"<!(node -e \"require('nan')\")" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// hello.cc | ||
#include <node.h> | ||
|
||
namespace demo { | ||
|
||
using v8::FunctionCallbackInfo; | ||
using v8::Isolate; | ||
using v8::Local; | ||
using v8::NewStringType; | ||
using v8::Object; | ||
using v8::String; | ||
using v8::Value; | ||
|
||
void Method(const FunctionCallbackInfo<Value>& args) { | ||
Isolate* isolate = args.GetIsolate(); | ||
args.GetReturnValue().Set(String::NewFromUtf8( | ||
isolate, "world", NewStringType::kNormal).ToLocalChecked()); | ||
} | ||
|
||
void Initialize(Local<Object> exports) { | ||
NODE_SET_METHOD(exports, "hello", Method); | ||
} | ||
|
||
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize) | ||
|
||
} // namespace demo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const binary = require('./hello.node'); | ||
const assert = require('assert'); | ||
|
||
module.exports = () => { | ||
assert.equal(binary.hello(), 'world'); | ||
}; |