packaging native dependencies separately

pull/1541/head
antelle 2020-06-02 13:58:25 +02:00
parent 2b24d716a9
commit 461a45dc51
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
6 changed files with 56 additions and 23 deletions

View File

@ -187,6 +187,31 @@ module.exports = function (grunt) {
dest: `dist/desktop/KeeWeb-${pkg.version}.win.arm64.exe`,
nonull: true
},
'native-modules-darwin': {
src: 'node_modules/@keeweb/keeweb-native-modules/*-darwin-x64.node',
dest: 'tmp/desktop/KeeWeb-darwin-x64/KeeWeb.app/Contents/Resources/',
nonull: true
},
'native-modules-win32-x64': {
src: 'node_modules/@keeweb/keeweb-native-modules/*-win32-x64.node',
dest: 'tmp/desktop/KeeWeb-win32-x64/resources/',
nonull: true
},
'native-modules-win32-ia32': {
src: 'node_modules/@keeweb/keeweb-native-modules/*-win32-ia32.node',
dest: 'tmp/desktop/KeeWeb-win32-ia32/resources/',
nonull: true
},
'native-modules-win32-arm64': {
src: 'node_modules/@keeweb/keeweb-native-modules/*-win32-arm64.node',
dest: 'tmp/desktop/KeeWeb-win32-arm64/resources/',
nonull: true
},
'native-modules-linux-x64': {
src: 'node_modules/@keeweb/keeweb-native-modules/*-linux-x64.node',
dest: 'tmp/desktop/keeweb-linux-x64/resources/',
nonull: true
},
'electron-builder-dist-linux-rpm': {
src: `tmp/desktop/electron-builder/KeeWeb-${pkg.version}.x86_64.rpm`,
dest: `dist/desktop/KeeWeb-${pkg.version}.linux.x86_64.rpm`,
@ -330,8 +355,7 @@ module.exports = function (grunt) {
name: 'keeweb',
platform: 'linux',
arch: ['x64'],
icon: 'graphics/icon.ico',
ignore: [/(darwin|win32)-\w+\.node$/]
icon: 'graphics/icon.ico'
}
},
darwin: {
@ -341,8 +365,7 @@ module.exports = function (grunt) {
icon: 'graphics/icon.icns',
appBundleId: 'net.antelle.keeweb',
appCategoryType: 'public.app-category.productivity',
extendInfo: 'package/osx/extend.plist',
ignore: [/(linux|win32)-\w+\.node$/]
extendInfo: 'package/osx/extend.plist'
}
},
'win32-x64': {
@ -351,7 +374,6 @@ module.exports = function (grunt) {
arch: 'x64',
icon: 'graphics/icon.ico',
buildVersion: pkg.version,
ignore: [/(linux|darwin)-\w+\.node$/, /(ia32|arm64)\.node/],
'version-string': windowsAppVersionString
}
},
@ -361,7 +383,6 @@ module.exports = function (grunt) {
arch: 'ia32',
icon: 'graphics/icon.ico',
buildVersion: pkg.version,
ignore: [/(linux|darwin)-\w+\.node$/, /(x64|arm64)\.node/],
'version-string': windowsAppVersionString
}
},
@ -371,7 +392,6 @@ module.exports = function (grunt) {
arch: 'arm64',
icon: 'graphics/icon.ico',
buildVersion: pkg.version,
ignore: [/(linux|darwin)-\w+\.node$/, /(ia32|x64)\.node/],
'version-string': windowsAppVersionString
}
}

View File

@ -731,13 +731,23 @@ function reportStartProfile() {
function reqNative(mod) {
const fileName = `${mod}-${process.platform}-${process.arch}.node`;
const mainAsarPath = process.mainModule.path;
const latestAsarPath = __dirname;
const pathInsideAsar = `node_modules/@keeweb/keeweb-native-modules/${fileName}`;
const modulePath = `../node_modules/@keeweb/keeweb-native-modules/${fileName}`;
let fullPath;
let fullPath = path.join(latestAsarPath, pathInsideAsar);
if (!fs.existsSync(fullPath)) {
fullPath = path.join(mainAsarPath, pathInsideAsar);
if (isDev) {
fullPath = path.join(__dirname, modulePath);
} else {
const mainAsarPath = process.mainModule.path;
fullPath = path.join(mainAsarPath, modulePath);
// Currently native modules can't be updated
// const latestAsarPath = __dirname;
//
// fullPath = path.join(latestAsarPath, modulePath);
//
// if (!fs.existsSync(fullPath)) {
// fullPath = path.join(mainAsarPath, modulePath);
// }
}
const binding = require(fullPath);

View File

@ -4,10 +4,6 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@keeweb/keeweb-native-modules": {
"version": "https://github.com/keeweb/keeweb-native-modules/releases/download/0.3.6/keeweb-native-modules.tgz",
"integrity": "sha512-1nCgKTU/esky1rFexCSs7U87A/sCEC6T/RNF5FO89dwzKMU9yVM/U7OuBspLuWnwxjCoaicTZr/WuYeoM1UATQ=="
},
"node-stream-zip": {
"version": "1.4.2",
"resolved": "https://registry.npmjs.org/node-stream-zip/-/node-stream-zip-1.4.2.tgz",

View File

@ -16,7 +16,6 @@
"license": "MIT",
"readme": "../README.md",
"dependencies": {
"@keeweb/keeweb-native-modules": "https://github.com/keeweb/keeweb-native-modules/releases/download/0.3.6/keeweb-native-modules.tgz",
"node-stream-zip": "^1.4.2"
},
"devDependencies": {}

View File

@ -56,21 +56,24 @@ module.exports = function(grunt) {
'build-desktop-app-content',
'electron:darwin',
'copy:desktop-darwin-helper',
'copy:desktop-darwin-installer-helper'
'copy:desktop-darwin-installer-helper',
'copy:native-modules-darwin'
]);
grunt.registerTask('dev-desktop-win32', 'Build a Windows app in dev environment', [
'default',
'build-desktop-app-content',
'electron:win32-x64',
'copy:desktop-windows-helper-x64'
'copy:desktop-windows-helper-x64',
'copy:native-modules-win32-x64'
]);
grunt.registerTask('dev-desktop-linux', 'Build a Linux app in dev environment', [
'default',
'build-desktop-app-content',
'electron:linux',
'chmod:linux-desktop-x64'
'chmod:linux-desktop-x64',
'copy:native-modules-linux-x64'
]);
grunt.registerTask('cordova', 'Build cordova app', [

View File

@ -36,13 +36,15 @@ module.exports = function (grunt) {
grunt.registerTask('build-desktop-executables-linux', [
'electron:linux',
'chmod:linux-desktop-x64'
'chmod:linux-desktop-x64',
'copy:native-modules-linux-x64'
]);
grunt.registerTask('build-desktop-executables-darwin', [
'electron:darwin',
'copy:desktop-darwin-helper',
'copy:desktop-darwin-installer-helper',
'copy:native-modules-darwin',
'osx-sign:desktop',
'notarize:desktop'
]);
@ -56,7 +58,10 @@ module.exports = function (grunt) {
'sign-exe:win32-build-arm64',
'copy:desktop-windows-helper-x64',
'copy:desktop-windows-helper-ia32',
'copy:desktop-windows-helper-arm64'
'copy:desktop-windows-helper-arm64',
'copy:native-modules-win32-x64',
'copy:native-modules-win32-ia32',
'copy:native-modules-win32-arm64'
]);
grunt.registerTask('build-desktop-executables', [