diff --git a/build-helpers/ensure-mac-dependency.js b/build-helpers/ensure-mac-dependency.js new file mode 100644 index 00000000..84109ed3 --- /dev/null +++ b/build-helpers/ensure-mac-dependency.js @@ -0,0 +1,46 @@ +const os = require('os'); +const fs = require('fs'); +const { execSync } = require('child_process'); +const path = require('path'); + +// Configuration: Array of packages to handle conditionally +const packages = [ + 'node-mac-permissions', + // Add more packages here if needed +]; + +const isMac = os.platform() === 'darwin'; + +packages.forEach((packageName) => { + const packagePath = path.join(__dirname, '..', 'node_modules', packageName); + + if (isMac) { + // On macOS, ensure that the package is installed + if (!fs.existsSync(packagePath)) { + console.log(`macOS detected and ${packageName} is not installed. Installing...`); + try { + execSync(`npm install ${packageName}`, { stdio: 'inherit' }); + console.log(`${packageName} installed successfully.`); + } catch (error) { + console.error(`Failed to install ${packageName} on macOS:`, error); + process.exit(1); + } + } else { + console.log(`macOS detected and ${packageName} is already installed. No action needed.`); + } + } else { + // On non-macOS platforms, ensure that the package is not present + if (fs.existsSync(packagePath)) { + console.log(`Non-macOS platform detected and ${packageName} is present. Removing...`); + try { + execSync(`npm uninstall ${packageName}`, { stdio: 'inherit' }); + console.log(`${packageName} removed successfully.`); + } catch (error) { + console.error(`Failed to uninstall ${packageName} on non-mac platform:`, error); + process.exit(1); + } + } else { + console.log(`Non-macOS platform detected and ${packageName} is not installed. No action needed.`); + } + } +}); diff --git a/package-lock.json b/package-lock.json index acac7c16..780f2462 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,7 +43,6 @@ "mobx-react-router": "3.1.2", "moment": "2.30.1", "ms": "2.1.1", - "node-mac-permissions": "2.4.0", "normalize-url": "^1.9.1", "npm": "6.14.8", "pretty-bytes": "^4.0.2", @@ -143,6 +142,9 @@ "webpack-cli": "3.2.1", "webpack-dev-server": "3.1.14", "webpack-node-externals": "1.7.2" + }, + "optionalDependencies": { + "node-mac-permissions": "2.4.0" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -7945,6 +7947,7 @@ "version": "1.5.0", "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "optional": true, "dependencies": { "file-uri-to-path": "1.0.0" } @@ -15016,7 +15019,8 @@ "node_modules/file-uri-to-path": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "optional": true }, "node_modules/filelist": { "version": "1.0.4", @@ -23871,7 +23875,8 @@ "node_modules/node-addon-api": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz", - "integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==" + "integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==", + "optional": true }, "node_modules/node-api-version": { "version": "0.1.4", @@ -24137,6 +24142,7 @@ "resolved": "https://registry.npmjs.org/node-mac-permissions/-/node-mac-permissions-2.4.0.tgz", "integrity": "sha512-X4jH4BCHXSIFonXlRmOh5vbEODR6bUoxaTZ7rHKDtObW2A6CVCYA92Y2p2s940ztvNiHBLfsFoBiejXMLx5vPA==", "hasInstallScript": true, + "optional": true, "os": [ "darwin" ], @@ -42993,6 +42999,7 @@ "version": "1.5.0", "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "optional": true, "requires": { "file-uri-to-path": "1.0.0" } @@ -48679,7 +48686,8 @@ "file-uri-to-path": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "optional": true }, "filelist": { "version": "1.0.4", @@ -55806,7 +55814,8 @@ "node-addon-api": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz", - "integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==" + "integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==", + "optional": true }, "node-api-version": { "version": "0.1.4", @@ -56035,6 +56044,7 @@ "version": "2.4.0", "resolved": "https://registry.npmjs.org/node-mac-permissions/-/node-mac-permissions-2.4.0.tgz", "integrity": "sha512-X4jH4BCHXSIFonXlRmOh5vbEODR6bUoxaTZ7rHKDtObW2A6CVCYA92Y2p2s940ztvNiHBLfsFoBiejXMLx5vPA==", + "optional": true, "requires": { "bindings": "^1.5.0", "node-addon-api": "^7.1.0" diff --git a/package.json b/package.json index e34edab6..5286ce0b 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "buildPackges": "npx lerna run build", "packages": "npx lerna publish --no-git-tag-version", "uidev": "cd uidev && webpack-dev-server", - "postinstall": "npx lerna run prepare" + "postinstall": "npx lerna run prepare && node ./build-helpers/ensure-mac-dependency.js" }, "keywords": [], "author": "Stefan Malzner ",