Skip to content
Permalink
Browse files

feat(plugin-auto-unpack-natives): add plugin/auto-unpack-natives for …

…automative native node module h
  • Loading branch information
MarshallOfSound committed May 17, 2018
1 parent d499d65 commit 0280d0fa0ef23c951ec32ae3b36045879d9c101d
@@ -0,0 +1,20 @@
{
"name": "@electron-forge/plugin-auto-unpack-natives",
"version": "6.0.0-beta.15",
"description": "Auto Unpack Natives plugin for Electron Forge, automatically adds native node modules to asar.unpacked",
"repository": "https://github.com/electron-userland/electron-forge",
"author": "Samuel Attard",
"license": "MIT",
"main": "dist/AutoUnpackNativesPlugin.js",
"typings": "dist/AutoUnpackNativesPlugin.d.ts",
"scripts": {
"test": "exit 0"
},
"engines": {
"node": ">= 6.0"
},
"dependencies": {
"@electron-forge/plugin-base": "6.0.0-beta.15",
"@electron-forge/shared-types": "6.0.0-beta.15"
}
}
@@ -0,0 +1,40 @@
import PluginBase from '@electron-forge/plugin-base';
import { ForgeConfig } from '@electron-forge/shared-types';

import { AutoUnpackNativesConfig } from './Config';

export default class AutoUnpackNativesPlugin extends PluginBase<AutoUnpackNativesConfig> {
private dir!: string;
private cachedGlob: Promise<string> | null = null;
name = 'auto-unpack-natives';

init(dir: string) {
this.dir = dir;
}

getHook(hookName: string) {
if (hookName === 'resolveForgeConfig') {
return this.resolveForgeConfig;
}
return null;
}

resolveForgeConfig = async (forgeConfig: ForgeConfig) => {
if (!forgeConfig.packagerConfig) {
forgeConfig.packagerConfig = {};
}
if (!forgeConfig.packagerConfig.asar) {
throw 'The AutoUnpackNatives plugin requires asar to be truthy or an object';
}
if (forgeConfig.packagerConfig.asar === true) {
forgeConfig.packagerConfig.asar = {};
}
const existingUnpack = forgeConfig.packagerConfig.asar.unpack;
const newUnpack = '**/*.node';
if (existingUnpack) {
forgeConfig.packagerConfig.asar.unpack = `{${existingUnpack},${newUnpack}}`;
} else {
forgeConfig.packagerConfig.asar.unpack = newUnpack;
}
}
}
@@ -0,0 +1,2 @@
export interface AutoUnpackNativesConfig {
}

0 comments on commit 0280d0f

Please sign in to comment.
You can’t perform that action at this time.