Initial commit

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
dinlo
2026-05-31 18:44:04 +08:00
commit 436a9631fc
8616 changed files with 1389957 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
import { SquirrelWindowsOptions } from './options';
export { SquirrelWindowsOptions } from './options';
export { SquirrelWindowsOptions as Options } from './options';
/**
* A utility function to convert SemVer version strings into NuGet-compatible
* version strings.
* @param version A SemVer version string
* @returns A NuGet-compatible version string
* @see {@link https://semver.org/ | Semantic Versioning specification}
* @see {@link https://learn.microsoft.com/en-us/nuget/concepts/package-versioning?tabs=semver20sort | NuGet versioning specification}
*/
export declare function convertVersion(version: string): string;
/**
* This package's main function, which creates a Squirrel.Windows executable
* installer and optionally code-signs the output.
*
* @param options Options for installer generation and signing
* @see {@link https://github.com/Squirrel/Squirrel.Windows | Squirrel.Windows}
*/
export declare function createWindowsInstaller(options: SquirrelWindowsOptions): Promise<void>;
+350
View File
@@ -0,0 +1,350 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createWindowsInstaller = exports.convertVersion = void 0;
var asar = __importStar(require("@electron/asar"));
var temp_utils_1 = require("./temp-utils");
var fs = __importStar(require("fs-extra"));
var path = __importStar(require("path"));
var os = __importStar(require("os"));
var child_process_1 = require("child_process");
var spawn_promise_1 = __importDefault(require("./spawn-promise"));
var lodash_1 = require("lodash");
var sign_1 = require("./sign");
var log = require('debug')('electron-windows-installer:main');
/**
* A utility function to convert SemVer version strings into NuGet-compatible
* version strings.
* @param version A SemVer version string
* @returns A NuGet-compatible version string
* @see {@link https://semver.org/ | Semantic Versioning specification}
* @see {@link https://learn.microsoft.com/en-us/nuget/concepts/package-versioning?tabs=semver20sort | NuGet versioning specification}
*/
function convertVersion(version) {
var parts = version.split('+')[0].split('-');
var mainVersion = parts.shift();
if (parts.length > 0) {
return [mainVersion, parts.join('-').replace(/\./g, '')].join('-');
}
else {
return mainVersion;
}
}
exports.convertVersion = convertVersion;
function checkIfCommandExists(command) {
var checkCommand = os.platform() === 'win32' ? 'where' : 'which';
return new Promise(function (resolve) {
(0, child_process_1.exec)("".concat(checkCommand, " ").concat(command), function (error) {
resolve(error ? false : true);
});
});
}
/**
* This package's main function, which creates a Squirrel.Windows executable
* installer and optionally code-signs the output.
*
* @param options Options for installer generation and signing
* @see {@link https://github.com/Squirrel/Squirrel.Windows | Squirrel.Windows}
*/
function createWindowsInstaller(options) {
return __awaiter(this, void 0, void 0, function () {
var useMono, monoExe, wineExe, _a, hasWine, hasMono, appDirectory, outputDirectory, loadingGif, vendorPath, vendorUpdate, appUpdate, cmd_1, args_1, defaultLoadingGif, certificateFile, certificatePassword, remoteReleases, signWithParams, remoteToken, windowsSign, metadata, appResources, asarFile, appMetadata, templatePath, templateData, _i, _b, f, nuspecContent, nugetOutput, targetNuspecPath, cmd, args, _c, nupkgPath, _d, _e, setupPath, unfixedSetupPath, msiPath, unfixedMsiPath;
return __generator(this, function (_f) {
switch (_f.label) {
case 0:
useMono = false;
monoExe = 'mono';
wineExe = ['arm64', 'x64'].includes(process.arch) ? 'wine64' : 'wine';
if (!(process.platform !== 'win32')) return [3 /*break*/, 2];
useMono = true;
return [4 /*yield*/, Promise.all([
checkIfCommandExists(wineExe),
checkIfCommandExists(monoExe)
])];
case 1:
_a = _f.sent(), hasWine = _a[0], hasMono = _a[1];
if (!hasWine || !hasMono) {
throw new Error('You must install both Mono and Wine on non-Windows');
}
log("Using Mono: '".concat(monoExe, "'"));
log("Using Wine: '".concat(wineExe, "'"));
_f.label = 2;
case 2:
appDirectory = options.appDirectory, outputDirectory = options.outputDirectory, loadingGif = options.loadingGif;
outputDirectory = path.resolve(outputDirectory || 'installer');
vendorPath = options.vendorDirectory || path.join(__dirname, '..', 'vendor');
vendorUpdate = path.join(vendorPath, 'Squirrel.exe');
appUpdate = path.join(appDirectory, 'Squirrel.exe');
return [4 /*yield*/, fs.copy(vendorUpdate, appUpdate)];
case 3:
_f.sent();
if (!(options.setupIcon && (options.skipUpdateIcon !== true))) return [3 /*break*/, 5];
cmd_1 = path.join(vendorPath, 'rcedit.exe');
args_1 = [
appUpdate,
'--set-icon', options.setupIcon
];
if (useMono) {
args_1.unshift(cmd_1);
cmd_1 = wineExe;
}
return [4 /*yield*/, (0, spawn_promise_1.default)(cmd_1, args_1)];
case 4:
_f.sent();
_f.label = 5;
case 5:
defaultLoadingGif = path.join(__dirname, '..', 'resources', 'install-spinner.gif');
loadingGif = loadingGif ? path.resolve(loadingGif) : defaultLoadingGif;
certificateFile = options.certificateFile, certificatePassword = options.certificatePassword, remoteReleases = options.remoteReleases, signWithParams = options.signWithParams, remoteToken = options.remoteToken, windowsSign = options.windowsSign;
metadata = {
description: '',
iconUrl: 'https://raw.githubusercontent.com/electron/electron/main/shell/browser/resources/win/electron.ico'
};
if (!(options.usePackageJson !== false)) return [3 /*break*/, 10];
appResources = path.join(appDirectory, 'resources');
asarFile = path.join(appResources, 'app.asar');
appMetadata = void 0;
return [4 /*yield*/, fs.pathExists(asarFile)];
case 6:
if (!_f.sent()) return [3 /*break*/, 7];
appMetadata = JSON.parse(asar.extractFile(asarFile, 'package.json').toString());
return [3 /*break*/, 9];
case 7: return [4 /*yield*/, fs.readJson(path.join(appResources, 'app', 'package.json'))];
case 8:
appMetadata = _f.sent();
_f.label = 9;
case 9:
Object.assign(metadata, {
exe: "".concat(appMetadata.name, ".exe"),
title: appMetadata.productName || appMetadata.name
}, appMetadata);
_f.label = 10;
case 10:
Object.assign(metadata, options);
if (!metadata.authors) {
if (typeof (metadata.author) === 'string') {
metadata.authors = metadata.author;
}
else {
metadata.authors = (metadata.author || {}).name || '';
}
}
metadata.owners = metadata.owners || metadata.authors;
metadata.version = convertVersion(metadata.version);
metadata.copyright = metadata.copyright ||
"Copyright \u00A9 ".concat(new Date().getFullYear(), " ").concat(metadata.authors || metadata.owners);
metadata.additionalFiles = metadata.additionalFiles || [];
return [4 /*yield*/, fs.pathExists(path.join(appDirectory, 'swiftshader'))];
case 11:
if (_f.sent()) {
metadata.additionalFiles.push({ src: 'swiftshader\\**', target: 'lib\\net45\\swiftshader' });
}
return [4 /*yield*/, fs.pathExists(path.join(appDirectory, 'vk_swiftshader_icd.json'))];
case 12:
if (_f.sent()) {
metadata.additionalFiles.push({ src: 'vk_swiftshader_icd.json', target: 'lib\\net45' });
}
templatePath = options.nuspecTemplate || path.join(__dirname, '..', 'template.nuspectemplate');
return [4 /*yield*/, fs.readFile(templatePath, 'utf8')];
case 13:
templateData = _f.sent();
if (path.sep === '/') {
templateData = templateData.replace(/\\/g, '/');
for (_i = 0, _b = metadata.additionalFiles; _i < _b.length; _i++) {
f = _b[_i];
f.src = f.src.replace(/\\/g, '/');
f.target = f.target.replace(/\\/g, '/');
}
}
nuspecContent = (0, lodash_1.template)(templateData)(metadata);
log("Created NuSpec file:\n".concat(nuspecContent));
return [4 /*yield*/, (0, temp_utils_1.createTempDir)('si-')];
case 14:
nugetOutput = _f.sent();
targetNuspecPath = path.join(nugetOutput, metadata.name + '.nuspec');
return [4 /*yield*/, fs.writeFile(targetNuspecPath, nuspecContent)];
case 15:
_f.sent();
cmd = path.join(vendorPath, 'nuget.exe');
args = [
'pack', targetNuspecPath,
'-BasePath', appDirectory,
'-OutputDirectory', nugetOutput,
'-NoDefaultExcludes'
];
if (useMono) {
args.unshift(cmd);
cmd = monoExe;
}
// Call NuGet to create our package
_c = log;
return [4 /*yield*/, (0, spawn_promise_1.default)(cmd, args)];
case 16:
// Call NuGet to create our package
_c.apply(void 0, [_f.sent()]);
nupkgPath = path.join(nugetOutput, "".concat(metadata.name, ".").concat(metadata.version, ".nupkg"));
if (!remoteReleases) return [3 /*break*/, 18];
cmd = path.join(vendorPath, 'SyncReleases.exe');
args = ['-u', remoteReleases, '-r', outputDirectory];
if (useMono) {
args.unshift(cmd);
cmd = monoExe;
}
if (remoteToken) {
args.push('-t', remoteToken);
}
_d = log;
return [4 /*yield*/, (0, spawn_promise_1.default)(cmd, args)];
case 17:
_d.apply(void 0, [_f.sent()]);
_f.label = 18;
case 18:
cmd = path.join(vendorPath, 'Squirrel.exe');
args = [
'--releasify', nupkgPath,
'--releaseDir', outputDirectory,
'--loadingGif', loadingGif
];
if (useMono) {
args.unshift(path.join(vendorPath, 'Squirrel-Mono.exe'));
cmd = monoExe;
}
// Legacy codesign options
return [4 /*yield*/, (0, sign_1.resetSignTool)()];
case 19:
// Legacy codesign options
_f.sent();
if (!signWithParams) return [3 /*break*/, 20];
args.push('--signWithParams');
if (!signWithParams.includes('/f') && !signWithParams.includes('/p') && certificateFile && certificatePassword) {
args.push("".concat(signWithParams, " /a /f \"").concat(path.resolve(certificateFile), "\" /p \"").concat(certificatePassword, "\""));
}
else {
args.push(signWithParams);
}
return [3 /*break*/, 23];
case 20:
if (!(certificateFile && certificatePassword)) return [3 /*break*/, 21];
args.push('--signWithParams');
args.push("/a /f \"".concat(path.resolve(certificateFile), "\" /p \"").concat(certificatePassword, "\""));
return [3 /*break*/, 23];
case 21:
if (!windowsSign) return [3 /*break*/, 23];
args.push('--signWithParams');
args.push('windows-sign');
return [4 /*yield*/, (0, sign_1.createSignTool)(options)];
case 22:
_f.sent();
_f.label = 23;
case 23:
if (options.setupIcon) {
args.push('--setupIcon');
args.push(path.resolve(options.setupIcon));
}
if (options.noMsi) {
args.push('--no-msi');
}
if (options.noDelta) {
args.push('--no-delta');
}
if (options.frameworkVersion) {
args.push('--framework-version');
args.push(options.frameworkVersion);
}
_e = log;
return [4 /*yield*/, (0, spawn_promise_1.default)(cmd, args)];
case 24:
_e.apply(void 0, [_f.sent()]);
if (!(options.fixUpPaths !== false)) return [3 /*break*/, 29];
log('Fixing up paths');
if (!(metadata.productName || options.setupExe)) return [3 /*break*/, 26];
setupPath = path.join(outputDirectory, options.setupExe || "".concat(metadata.productName, "Setup.exe"));
unfixedSetupPath = path.join(outputDirectory, 'Setup.exe');
log("Renaming ".concat(unfixedSetupPath, " => ").concat(setupPath));
return [4 /*yield*/, fs.rename(unfixedSetupPath, setupPath)];
case 25:
_f.sent();
_f.label = 26;
case 26:
if (!(metadata.productName || options.setupMsi)) return [3 /*break*/, 29];
msiPath = path.join(outputDirectory, options.setupMsi || "".concat(metadata.productName, "Setup.msi"));
unfixedMsiPath = path.join(outputDirectory, 'Setup.msi');
return [4 /*yield*/, fs.pathExists(unfixedMsiPath)];
case 27:
if (!_f.sent()) return [3 /*break*/, 29];
log("Renaming ".concat(unfixedMsiPath, " => ").concat(msiPath));
return [4 /*yield*/, fs.rename(unfixedMsiPath, msiPath)];
case 28:
_f.sent();
_f.label = 29;
case 29: return [4 /*yield*/, (0, sign_1.resetSignTool)()];
case 30:
_f.sent();
return [2 /*return*/];
}
});
});
}
exports.createWindowsInstaller = createWindowsInstaller;
//# sourceMappingURL=index.js.map
File diff suppressed because one or more lines are too long
+219
View File
@@ -0,0 +1,219 @@
import { SignToolOptions } from '@electron/windows-sign';
export interface SquirrelWindowsOptions {
/**
* The folder path of your Electron app
*/
appDirectory: string;
/**
* The folder path of Squirrel windows
*/
vendorDirectory?: string;
/**
* The folder path to create the .exe installer in.
*
* @defaultValue an `installer` folder at the project root.
*/
outputDirectory?: string;
/**
* The path to the .nuspectemplate file used by Squirrel.exe.
*
* @defaultValue the bundled {@link https://github.com/electron/windows-installer/blob/main/template.nuspectemplate | template.nuspectemplate}.
*/
nuspecTemplate?: string;
/**
* The local path to a `.gif` file to display during install.
*
* @defaultValue the bundled {@link https://github.com/electron/windows-installer/blob/main/resources/install-spinner.gif | install-spinner.gif}
*/
loadingGif?: string;
/**
* The `authors` value for the NuGet package metadata.
*
* @defaultValue the `author` field from your app's package.json file
* unless {@link SquirrelWindowsOptions.usePackageJson | usePackageJson} is false.
* @see {@link https://learn.microsoft.com/en-us/nuget/reference/nuspec | the Microsoft .nuspec reference}.
*/
authors?: string;
/**
* The `owners` value for the NuGet package metadata.
*
* @defaultValue the `authors` field from your app's package.json file
* unless {@link SquirrelWindowsOptions.usePackageJson | usePackageJson} is false.
* @see {@link https://learn.microsoft.com/en-us/nuget/reference/nuspec | the Microsoft .nuspec reference}.
*/
owners?: string;
/**
* The `copyright` value for the NuGet package metadata.
*
* @defaultValue a generated copyright with {@link SquirrelWindowsOptions.authors | authors}
* or {@link SquirrelWindowsOptions.owners | owners}.
* @see {@link https://learn.microsoft.com/en-us/nuget/reference/nuspec | the Microsoft .nuspec reference}.
*/
copyright?: string;
/**
* The name of your app's main `.exe` file.
*
* @defaultValue the `name` field in your app's package.json file with an added `.exe` extension
* unless {@link SquirrelWindowsOptions.usePackageJson | usePackageJson} is false.
*/
exe?: string;
/**
* The `description` value for the NuGet package metadata.
*
* @defaultValue the `description` field from your app's package.json file
* unless {@link SquirrelWindowsOptions.usePackageJson | usePackageJson} is false.
* @see {@link https://learn.microsoft.com/en-us/nuget/reference/nuspec | the Microsoft .nuspec reference}.
*/
description?: string;
/**
* The `version` value for the Nuget package metadata.
*
* @defaultValue the `version` field from your app's package.json file
* unless {@link SquirrelWindowsOptions.usePackageJson | usePackageJson} is false.
* @see {@link https://learn.microsoft.com/en-us/nuget/reference/nuspec | the Microsoft .nuspec reference}.
*/
version?: string;
/**
* The `title` value for the nuget package metadata.
*
* @defaultValue the `productName` field and then the `name` field from your app's package.json
* file unless {@link SquirrelWindowsOptions.usePackageJson | usePackageJson} is false.
* @see {@link https://learn.microsoft.com/en-us/nuget/reference/nuspec | the Microsoft .nuspec reference}.
*/
title?: string;
/**
* Windows Application Model ID (appId).
*
* @defaultValue the `name` field in your app's package.json file
* unless {@link SquirrelWindowsOptions.usePackageJson | usePackageJson} is false.
* @see {@link https://learn.microsoft.com/en-us/windows/win32/shell/appids | Microsoft's Application User Model IDs documentation}.
*/
name?: string;
/**
* The path to an Authenticode Code Signing Certificate.
*
* This is a legacy parameter provided for backwards compatibility.
* For more comprehensive support of various codesigning scenarios
* like EV certificates, see the
* {@link SquirrelWindowsOptions.windowsSign | windowsSign} parameter.
*/
certificateFile?: string;
/**
* The password to decrypt the certificate given in `certificateFile`
*
* This is a legacy parameter provided for backwards compatibility.
* For more comprehensive support of various codesigning scenarios
* like EV certificates, see the
* {@link SquirrelWindowsOptions.windowsSign | windowsSign} parameter.
*/
certificatePassword?: string;
/**
* Params to pass to signtool.
*
* Overrides {@link SquirrelWindowsOptions.certificateFile | certificateFile}
* and {@link SquirrelWindowsOptions.certificatePassword | certificatePassword}`.
*
* This is a legacy parameter provided for backwards compatibility.
* For more comprehensive support of various codesigning scenarios
* like EV certificates, see the
* {@link SquirrelWindowsOptions.windowsSign | windowsSign} parameter.
*/
signWithParams?: string;
/**
* A publicly accessible, fully qualified HTTP(S) URL to an ICO file, used as the application icon
* displayed in Control Panel ➡ Programs and Features. The icon is retrieved at install time.
* Example: http://example.com/favicon.ico
*
* Does not accept `file:` URLs.
*
* @defaultValue the Electron icon.
*/
iconUrl?: string;
/**
* The ICO file to use as the icon for the generated Setup.exe
*/
setupIcon?: string;
/**
* The name to use for the generated Setup.exe file
* @defaultValue the `productName` field from your app's package.json file
* unless {@link SquirrelWindowsOptions.usePackageJson | usePackageJson} is false.
*/
setupExe?: string;
/**
* The name to use for the generated Setup.msi file
* @defaultValue the `productName` field from your app's package.json file
* unless {@link SquirrelWindowsOptions.usePackageJson | usePackageJson} is false.
*/
setupMsi?: string;
/**
* Enable this flag to prevent Squirrel.Windows from creating an MSI installer.
* @defaultValue false
*/
noMsi?: boolean;
/**
* Enable this flag to prevent Squirrel.Windows from creating delta packages (disable only if necessary, they are a Good Thing).
* @defaultValue false
*/
noDelta?: boolean;
/**
* A URL to your existing updates. If given, these will be downloaded to create delta updates.
*/
remoteReleases?: string;
/**
* Authentication token for remote updates using {@link SquirrelWindowsOptions.remoteReleases | remoteReleases}
*/
remoteToken?: string;
/**
* Whether or not to infer metadata options from your app's package.json file.
* @defaultValue true
*/
usePackageJson?: boolean;
/**
* Set the required .NET framework version (e.g. `net461`).
*/
frameworkVersion?: string;
/**
* Attempt to create more descriptive installer names using metadata parameters.
* @defaultValue false
*/
fixUpPaths?: boolean;
/**
* Enable this flag to skip setting a custom icon for `Update.exe`
* @defaultValue false
*/
skipUpdateIcon?: boolean;
/**
* Requires Node.js 18 or newer.
*
* Sign your app with `@electron/windows-sign`, allowing for full customization
* of the code-signing process - and supports more complicated scenarios like
* cloud-hosted EV certificates, custom sign pipelines, and per-file overrides.
* It also supports all existing "simple" codesigning scenarios, including
* just passing a certificate file and password.
*
* @see {@link https://github.com/electron/windows-sign | @electron/windows-sign documentation}
* for all possible configuration options.
*/
windowsSign?: SignToolOptions;
}
export interface PersonMetadata {
name: string;
email?: string;
url?: string;
}
export interface AdditionalFile {
src: string;
target: string;
}
export interface Metadata {
name?: string;
productName?: string;
version?: string;
copyright?: string;
author?: string | PersonMetadata;
authors?: string | PersonMetadata[];
owners?: string | PersonMetadata[];
description?: string;
iconUrl?: string;
additionalFiles?: AdditionalFile[];
}
+6
View File
@@ -0,0 +1,6 @@
"use strict";
// Originally from @types/electron-winstaller@2.6.2
// Original definitions by: Brendan Forster <https://github.com/shiftkey>, Daniel Perez Alvarez <https://github.com/unindented>
// Original definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=options.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";AAAA,mDAAmD;AACnD,+HAA+H;AAC/H,2EAA2E"}
+15
View File
@@ -0,0 +1,15 @@
import { SquirrelWindowsOptions } from './options';
/**
* This method uses @electron/windows-sign to create a fake signtool.exe
* that can be called by Squirrel - but then just calls @electron/windows-sign
* to actually perform the signing.
*
* That's useful for users who need a high degree of customization of the signing
* process but still want to use @electron/windows-installer.
*/
export declare function createSignTool(options: SquirrelWindowsOptions): Promise<void>;
/**
* Ensure that signtool.exe is actually the "real" signtool.exe, not our
* fake substitute.
*/
export declare function resetSignTool(): Promise<void>;
+189
View File
@@ -0,0 +1,189 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.resetSignTool = exports.createSignTool = void 0;
var path_1 = __importDefault(require("path"));
var semver_1 = __importDefault(require("semver"));
var fs_extra_1 = __importDefault(require("fs-extra"));
var VENDOR_PATH;
var ORIGINAL_SIGN_TOOL_PATH;
var BACKUP_SIGN_TOOL_PATH;
var SIGN_LOG_PATH;
/**
* This method uses @electron/windows-sign to create a fake signtool.exe
* that can be called by Squirrel - but then just calls @electron/windows-sign
* to actually perform the signing.
*
* That's useful for users who need a high degree of customization of the signing
* process but still want to use @electron/windows-installer.
*/
function createSignTool(options) {
return __awaiter(this, void 0, void 0, function () {
var createSeaSignTool;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!options.windowsSign) {
throw new Error('Signtool should only be created if windowsSign options are set');
}
VENDOR_PATH = options.vendorDirectory || path_1.default.join(__dirname, '..', 'vendor');
ORIGINAL_SIGN_TOOL_PATH = path_1.default.join(VENDOR_PATH, 'signtool.exe');
BACKUP_SIGN_TOOL_PATH = path_1.default.join(VENDOR_PATH, 'signtool-original.exe');
SIGN_LOG_PATH = path_1.default.join(VENDOR_PATH, 'electron-windows-sign.log');
return [4 /*yield*/, getCreateSeaSignTool()];
case 1:
createSeaSignTool = _a.sent();
return [4 /*yield*/, resetSignTool()];
case 2:
_a.sent();
return [4 /*yield*/, fs_extra_1.default.remove(SIGN_LOG_PATH)];
case 3:
_a.sent();
// Make a backup of signtool.exe
return [4 /*yield*/, fs_extra_1.default.copy(ORIGINAL_SIGN_TOOL_PATH, BACKUP_SIGN_TOOL_PATH, { overwrite: true })];
case 4:
// Make a backup of signtool.exe
_a.sent();
// Create a new signtool.exe using @electron/windows-sign
return [4 /*yield*/, createSeaSignTool({
path: ORIGINAL_SIGN_TOOL_PATH,
windowsSign: options.windowsSign
})];
case 5:
// Create a new signtool.exe using @electron/windows-sign
_a.sent();
return [2 /*return*/];
}
});
});
}
exports.createSignTool = createSignTool;
/**
* Ensure that signtool.exe is actually the "real" signtool.exe, not our
* fake substitute.
*/
function resetSignTool() {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!fs_extra_1.default.existsSync(BACKUP_SIGN_TOOL_PATH)) return [3 /*break*/, 3];
// Reset the backup of signtool.exe
return [4 /*yield*/, fs_extra_1.default.copy(BACKUP_SIGN_TOOL_PATH, ORIGINAL_SIGN_TOOL_PATH, { overwrite: true })];
case 1:
// Reset the backup of signtool.exe
_a.sent();
return [4 /*yield*/, fs_extra_1.default.remove(BACKUP_SIGN_TOOL_PATH)];
case 2:
_a.sent();
_a.label = 3;
case 3: return [2 /*return*/];
}
});
});
}
exports.resetSignTool = resetSignTool;
/**
* @electron/windows-installer only requires Node.js >= 8.0.0.
* @electron/windows-sign requires Node.js >= 16.0.0.
* @electron/windows-sign's "fake signtool.exe" feature requires
* Node.js >= 20.0.0, the first version to contain the "single
* executable" feature with proper support.
*
* Since this is overall a very niche feature and only benefits
* consumers with rather advanced codesigning needs, we did not
* want to make Node.js v18 a hard requirement for @electron/windows-installer.
*
* Instead, @electron/windows-sign is an optional dependency - and
* if it didn't install, we'll throw a useful error here.
*
* @returns
*/
function getCreateSeaSignTool() {
return __awaiter(this, void 0, void 0, function () {
var createSeaSignTool, error_1, message;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('@electron/windows-sign')); })];
case 1:
createSeaSignTool = (_a.sent()).createSeaSignTool;
return [2 /*return*/, createSeaSignTool];
case 2:
error_1 = _a.sent();
message = 'In order to use windowsSign options, @electron/windows-sign must be installed as a dependency.';
if (semver_1.default.lte(process.version, '20.0.0')) {
message += " You are currently using Node.js ".concat(process.version, ". Please upgrade to Node.js 19 or later and reinstall all dependencies to ensure that @electron/windows-sign is available.");
}
else {
message += " ".concat(error_1);
}
throw new Error(message);
case 3: return [2 /*return*/];
}
});
});
}
//# sourceMappingURL=sign.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"sign.js","sourceRoot":"","sources":["../src/sign.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;GAGG;AACH,SAAsB,aAAa;;;;;yBAC7B,kBAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,EAApC,wBAAoC;oBACtC,mCAAmC;oBACnC,qBAAM,kBAAE,CAAC,IAAI,CAAC,qBAAqB,EAAE,uBAAuB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAA;;oBADlF,mCAAmC;oBACnC,SAAkF,CAAC;oBACnF,qBAAM,kBAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,EAAA;;oBAAtC,SAAsC,CAAC;;;;;;CAE1C;AAND,sCAMC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAe,oBAAoB;;;;;;;oBAED,sFAAa,wBAAwB,QAAC;;oBAA5D,iBAAiB,GAAK,CAAA,SAAsC,CAAA,kBAA3C;oBACzB,sBAAO,iBAAiB,EAAC;;;oBAErB,OAAO,GAAI,gGAAgG,CAAC;oBAEhH,IAAI,gBAAM,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE;wBACzC,OAAO,IAAI,2CAAoC,OAAO,CAAC,OAAO,+HAA4H,CAAC;qBAC5L;yBAAM;wBACL,OAAO,IAAI,WAAI,OAAK,CAAE,CAAC;qBACxB;oBAED,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;;;;;CAE5B"}
+3
View File
@@ -0,0 +1,3 @@
/// <reference types="node" />
import { SpawnOptionsWithoutStdio } from 'child_process';
export default function spawn(exe: string, params: string[], opts?: SpawnOptionsWithoutStdio): Promise<string>;
+54
View File
@@ -0,0 +1,54 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var child_process_1 = require("child_process");
var d = require('debug')('electron-windows-installer:spawn');
// Public: Maps a process's output into an {Observable}
//
// exe - The program to execute
// params - Arguments passed to the process
// opts - Options that will be passed to child_process.spawn
//
// Returns an {Observable} with a single value, that is the output of the
// spawned process
function spawn(exe, params, opts) {
return new Promise(function (resolve, reject) {
var proc = null;
d("Spawning ".concat(exe, " ").concat(params.join(' ')));
if (!opts) {
proc = (0, child_process_1.spawn)(exe, params);
}
else {
proc = (0, child_process_1.spawn)(exe, params, opts);
}
// We need to wait until all three events have happened:
// * stdout's pipe is closed
// * stderr's pipe is closed
// * We've got an exit code
var rejected = false;
var refCount = 3;
var stdout = '';
var release = function () {
if (--refCount <= 0 && !rejected)
resolve(stdout);
};
var bufHandler = function (chunk) {
stdout += chunk;
};
proc.stdout.setEncoding('utf8').on('data', bufHandler);
proc.stdout.once('close', release);
proc.stderr.setEncoding('utf8').on('data', bufHandler);
proc.stderr.once('close', release);
proc.on('error', function (e) { return reject(e); });
proc.on('close', function (code) {
if (code === 0) {
release();
}
else {
rejected = true;
reject(new Error("Failed with exit code: ".concat(code, "\nOutput:\n").concat(stdout)));
}
});
});
}
exports.default = spawn;
//# sourceMappingURL=spawn-promise.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"spawn-promise.js","sourceRoot":"","sources":["../src/spawn-promise.ts"],"names":[],"mappings":";;AAAA,+CAA2E;AAE3E,IAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,kCAAkC,CAAC,CAAC;AAE/D,uDAAuD;AACvD,EAAE;AACF,+BAA+B;AAC/B,2CAA2C;AAC3C,4DAA4D;AAC5D,EAAE;AACF,yEAAyE;AACzE,kBAAkB;AAClB,SAAwB,KAAK,CAAC,GAAW,EAAE,MAAgB,EAAE,IAA+B;IAC1F,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;QACjC,IAAI,IAAI,GAAG,IAAI,CAAC;QAEhB,CAAC,CAAC,mBAAY,GAAG,cAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAE,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,EAAE;YACT,IAAI,GAAG,IAAA,qBAAO,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;SAC7B;aAAM;YACL,IAAI,GAAG,IAAA,qBAAO,EAAC,GAAG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
View File
@@ -0,0 +1,3 @@
import * as temp from 'temp';
declare const createTempDir: (arg1: string | temp.AffixOptions | undefined) => Promise<string>;
export { createTempDir };
+32
View File
@@ -0,0 +1,32 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTempDir = void 0;
var temp = __importStar(require("temp"));
var util_1 = require("util");
temp.track();
var createTempDir = (0, util_1.promisify)(temp.mkdir);
exports.createTempDir = createTempDir;
//# sourceMappingURL=temp-utils.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"temp-utils.js","sourceRoot":"","sources":["../src/temp-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA6B;AAC7B,6BAAiC;AACjC,IAAI,CAAC,KAAK,EAAE,CAAC;AAEb,IAAM,aAAa,GAAG,IAAA,gBAAS,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAG1C,sCAAa"}