浏览代码

chore: update index.js

LongYinan 5 年之前
父节点
当前提交
1536e5041a
共有 1 个文件被更改,包括 9 次插入15 次删除
  1. 9 15
      index.js

+ 9 - 15
index.js

@@ -1,17 +1,11 @@
-const { platform } = require('os')
-
 const { loadBinding } = require('@node-rs/helper')
 const { loadBinding } = require('@node-rs/helper')
 
 
-try {
-  // __dirname means load native addon from current dir
-  // 'package-template' means native addon name is `package-template`
-  // the first arguments was decided by `build` script in `package.json`
-  // the second arguments was decided by `napi.name` field in `package.json`
-  module.exports = loadBinding(__dirname, 'package-template')
-} catch (e) {
-  try {
-    module.exports = require(`@napi-rs/package-template-${platform()}`)
-  } catch (e) {
-    throw new TypeError('Not compatible with your platform. Error message: ' + e.message)
-  }
-}
+/**
+ * __dirname means load native addon from current dir
+ * 'package-template' means native addon name is `package-template`
+ * the first arguments was decided by `napi.name` field in `package.json`
+ * the second arguments was decided by `name` field in `package.json`
+ * loadBinding helper will load `package-template.[PLATFORM].node` from `__dirname` first
+ * If failed to load addon, it will fallback to load from `@napi-rs/package-template-[PLATFORM]`
+ */
+module.exports = loadBinding(__dirname, 'package-template', '@napi-rs/package-template')