nan版本升级2.0 替换规则

在github看到一个nan版本升级规则替换规则,共享以便查阅

  #!/usr/bin/env bash

set -e
set -u

# Semi-automated upgrading of Native Abstractions for Node.js (NAN)
# usage, from v1.x.x to v2.x.x.
# https://github.com/nodejs/nan
#
# Based on Thorsten Lorenz' script `update_to_nan_v2.0.x.sh`
# https://github.com/thlorenz
# https://gist.github.com/thlorenz/7e9d8ad15566c99fd116
# See also NAN issue #376 io.js v3 preparation.
# https://github.com/nodejs/nan/issues/376
#
# Usage: nan-upgrade-v1-to-v2.sh *.h *.cpp

replacements=(
  "NanAsyncWorker/Nan::AsyncWorker"
  "NanAsyncQueueWorker/Nan::AsyncQueueWorker"
  "NanCallback/Nan::Callback"
  "NanSetInternalFieldPointer/Nan::SetInternalFieldPointer"
  "NanGetInternalFieldPointer/Nan::GetInternalFieldPointer"
  "NanNewBufferHandle\\(([^)]+)\\)/Nan::NewBuffer(\\1).ToLocalChecked()"
  "(NanNew(<(v8::)?String>)?\\(\"[^\"]*\"\\))/\\1.ToLocalChecked()"
  "(NanNew<(v8::)?String>\\([^\"][^)]*\\))/\\1.ToLocalChecked()"
  "NanNew/Nan::New"
  "NODE_SET_PROTOTYPE_METHOD/Nan::SetPrototypeMethod"
  "NODE_SET_METHOD/Nan::SetMethod"
  "_NAN_METHOD_ARGS_TYPE/Nan::NAN_METHOD_ARGS_TYPE"
  "(\\W)?args(\\W|\\.|\\[)/\\1info\\2"
  "(^|\\s)(v8::)?Persistent/\\1Nan::Persistent"
  "NanAssignPersistent(<\w+>)?\\(([^,]+),\\s*([^)]+)\\)/\\2.Reset(\\3)"
  "NanDisposePersistent\\(([^\\)]+)\\)/\\1.Reset()"
  "NanReturnValue/info.GetReturnValue().Set"
  "NanReturnNull\\(\\)/info.GetReturnValue().Set(Nan::Null())"
  "NanScope\\(\\)/Nan::HandleScope\ scope"
  "NanEscapableScope\\(\\)/Nan::EscapableHandleScope scope"
  "NanEscapeScope/scope.Escape"
  "NanReturnUndefined\\(\\);/return;"
  "NanUtf8String/Nan::Utf8String"
  "NanObjectWrapHandle\\(([^\\)]+)\\)/\\1->handle()"
  "(node::)?ObjectWrap/Nan::ObjectWrap"
  "NanMakeCallback/Nan::MakeCallback"
  "NanNull/Nan::Null"
  "NanUndefined/Nan::Undefined"
  "NanFalse/Nan::False"
  "NanTrue/Nan::True"
  "NanThrow(\w+)?Error/Nan::Throw\\1Error"
  "NanThrowTypeError/Nan::ThrowTypeError"
  "NanError/Nan::Error"
  "NanGetCurrentContext/Nan::GetCurrentContext"
  "([a-zA-Z0-9_]+)->SetAccessor\\(/Nan::SetAccessor(\\1, "
  "NanAdjustExternalMemory/Nan::AdjustExternalMemory"
  "NanSetTemplate/Nan::SetTemplate"
  "NanHasInstance\\(([^,]+),\\s*([^)]+)\\)/Nan::New(\\1)->HasInstance(\\2)"
  "NanReturnThis\\(\\)/info.GetReturnValue().Set(info.This())"
  "Handle<([^>]+)>/Local<\\1>"
  "Nan::Nan::/Nan::"
)
os=`uname`
if [ $os == 'Darwin' ];
then sed_flag='-E'
else sed_flag='-r'
fi

# NOTE: the below could possibly be peformed using `sed -i '.tmp~' -e 's/a/b/g -e 's/c/d/g' ...`.
for file in "$@"; do
  echo $file
  for replacement in "${replacements[@]}"; do
    cat $file | sed $sed_flag "s/${replacement}/g" > $file.$$ && mv $file.$$ $file
  done
done

参考:

脚本来更新Node.js插件来使用nan 2.0.x,因此使用iojs v3.x(在那里可以获得90%)

Semi-automated upgrading of Native Abstractions for Node.js (NAN)

io.js v3 preparation

你可能感兴趣的:(nan版本升级2.0 替换规则)