Add prettier

This commit is contained in:
Caelan Sayler
2024-08-26 09:08:29 +01:00
committed by Caelan
parent bb3f3d96fc
commit 2012b9be7e
12 changed files with 332 additions and 269 deletions

View File

@@ -1,10 +1,5 @@
installing ts tool: cargo install --git https://github.com/Aleph-Alpha/ts-rs.git --branch cli cargo-ts
# veloz
This project was bootstrapped by [create-neon](https://www.npmjs.com/package/create-neon).
@@ -88,19 +83,19 @@ veloz/
└── target/
```
| Entry | Purpose |
|----------------|------------------------------------------------------------------------------------------------------------------------------------------|
| `Cargo.toml` | The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command. |
| `README.md` | This file. |
| `lib/` | The directory containing the generated output from [tsc](https://typescriptlang.org). |
| `src/` | The directory containing the TypeScript source files. |
| `index.mts` | Entry point for when this library is loaded via [ESM `import`](https://nodejs.org/api/esm.html#modules-ecmascript-modules) syntax. |
| `index.cts` | Entry point for when this library is loaded via [CJS `require`](https://nodejs.org/api/modules.html#requireid). |
| `crates/` | The directory tree containing the Rust source code for the project. |
| `lib.rs` | Entry point for the Rust source code. |
| `platforms/` | The directory containing distributions of the binary addon backend for each platform supported by this library. |
| `package.json` | The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command. |
| `target/` | Binary artifacts generated by the Rust build. |
| Entry | Purpose |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `Cargo.toml` | The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command. |
| `README.md` | This file. |
| `lib/` | The directory containing the generated output from [tsc](https://typescriptlang.org). |
| `src/` | The directory containing the TypeScript source files. |
| `index.mts` | Entry point for when this library is loaded via [ESM `import`](https://nodejs.org/api/esm.html#modules-ecmascript-modules) syntax. |
| `index.cts` | Entry point for when this library is loaded via [CJS `require`](https://nodejs.org/api/modules.html#requireid). |
| `crates/` | The directory tree containing the Rust source code for the project. |
| `lib.rs` | Entry point for the Rust source code. |
| `platforms/` | The directory containing distributions of the binary addon backend for each platform supported by this library. |
| `package.json` | The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command. |
| `target/` | Binary artifacts generated by the Rust build. |
## Learn More

View File

@@ -2,6 +2,6 @@
module.exports = {
testEnvironment: "node",
transform: {
"^.+.ts$": ["ts-jest",{}],
"^.+.ts$": ["ts-jest", {}],
},
};
};

View File

@@ -19,6 +19,7 @@
"cross-env": "^7.0.3",
"del-cli": "^5.1.0",
"jest": "^29.7.0",
"prettier": "3.3.3",
"ts-jest": "^29.2.5",
"typescript": "^5.3.3"
},
@@ -5420,6 +5421,21 @@
"node": ">=8"
}
},
"node_modules/prettier": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz",
"integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==",
"dev": true,
"bin": {
"prettier": "bin/prettier.cjs"
},
"engines": {
"node": ">=14"
},
"funding": {
"url": "https://github.com/prettier/prettier?sponsor=1"
}
},
"node_modules/pretty-format": {
"version": "29.7.0",
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz",

View File

@@ -5,9 +5,10 @@
"main": "./lib/index.cjs",
"scripts": {
"test": "npm run debug && cross-env VELOPACK_RESTART=true VELOPACK_DEBUG=true jest --silent=false",
"debug": "tsc -p tsconfig.build.json && cargo build && neon dist -f ../../target/debug/velopack_nodeffi.dll",
"debug": "tsc -p tsconfig.build.json && cargo build && neon dist -f ../../target/debug/velopack_nodeffi.dll && npm run lint",
"build": "tsc -p tsconfig.build.json && cargo build --release && neon dist -f ../../target/release/velopack_nodeffi.dll",
"clean": "cargo clean && del-cli platforms/**/index.node index.node lib"
"clean": "cargo clean && del-cli platforms/**/index.node index.node lib",
"lint": "prettier . --write"
},
"author": "Velopack Ltd, Caelan Sayler",
"license": "MIT",
@@ -41,6 +42,7 @@
"cross-env": "^7.0.3",
"del-cli": "^5.1.0",
"jest": "^29.7.0",
"prettier": "3.3.3",
"ts-jest": "^29.2.5",
"typescript": "^5.3.3"
},

View File

@@ -4,14 +4,15 @@ import type { VelopackAsset } from "./VelopackAsset";
/**
* Holds information about the current version and pending updates, such as how many there are, and access to release notes.
*/
export type UpdateInfo = {
/**
* The available version that we are updating to.
*/
TargetFullRelease: VelopackAsset,
/**
* True if the update is a version downgrade or lateral move (such as when switching channels to the same version number).
* In this case, only full updates are allowed, and any local packages on disk newer than the downloaded version will be
* deleted.
*/
IsDowngrade: boolean, };
export type UpdateInfo = {
/**
* The available version that we are updating to.
*/
TargetFullRelease: VelopackAsset;
/**
* True if the update is a version downgrade or lateral move (such as when switching channels to the same version number).
* In this case, only full updates are allowed, and any local packages on disk newer than the downloaded version will be
* deleted.
*/
IsDowngrade: boolean;
};

View File

@@ -3,21 +3,22 @@
/**
* Options to customise the behaviour of UpdateManager.
*/
export type UpdateOptions = {
/**
* Allows UpdateManager to update to a version that's lower than the current version (i.e. downgrading).
* This could happen if a release has bugs and was retracted from the release feed, or if you're using
* ExplicitChannel to switch channels to another channel where the latest version on that
* channel is lower than the current version.
*/
AllowVersionDowngrade: boolean,
/**
* **This option should usually be left None**. <br/>
* Overrides the default channel used to fetch updates.
* The default channel will be whatever channel was specified on the command line when building this release.
* For example, if the current release was packaged with '--channel beta', then the default channel will be 'beta'.
* This allows users to automatically receive updates from the same channel they installed from. This options
* allows you to explicitly switch channels, for example if the user wished to switch back to the 'stable' channel
* without having to reinstall the application.
*/
ExplicitChannel: string | null, };
export type UpdateOptions = {
/**
* Allows UpdateManager to update to a version that's lower than the current version (i.e. downgrading).
* This could happen if a release has bugs and was retracted from the release feed, or if you're using
* ExplicitChannel to switch channels to another channel where the latest version on that
* channel is lower than the current version.
*/
AllowVersionDowngrade: boolean;
/**
* **This option should usually be left None**. <br/>
* Overrides the default channel used to fetch updates.
* The default channel will be whatever channel was specified on the command line when building this release.
* For example, if the current release was packaged with '--channel beta', then the default channel will be 'beta'.
* This allows users to automatically receive updates from the same channel they installed from. This options
* allows you to explicitly switch channels, for example if the user wished to switch back to the 'stable' channel
* without having to reinstall the application.
*/
ExplicitChannel: string | null;
};

View File

@@ -3,40 +3,41 @@
/**
* An individual Velopack asset, could refer to an asset on-disk or in a remote package feed.
*/
export type VelopackAsset = {
/**
* The name or Id of the package containing this release.
*/
PackageId: string,
/**
* The version of this release.
*/
Version: string,
/**
* The type of asset (eg. "Full" or "Delta").
*/
Type: string,
/**
* The filename of the update package containing this release.
*/
FileName: string,
/**
* The SHA1 checksum of the update package containing this release.
*/
SHA1: string,
/**
* The SHA256 checksum of the update package containing this release.
*/
SHA256: string,
/**
* The size in bytes of the update package containing this release.
*/
Size: bigint,
/**
* The release notes in markdown format, as passed to Velopack when packaging the release. This may be an empty string.
*/
NotesMarkdown: string,
/**
* The release notes in HTML format, transformed from Markdown when packaging the release. This may be an empty string.
*/
NotesHtml: string, };
export type VelopackAsset = {
/**
* The name or Id of the package containing this release.
*/
PackageId: string;
/**
* The version of this release.
*/
Version: string;
/**
* The type of asset (eg. "Full" or "Delta").
*/
Type: string;
/**
* The filename of the update package containing this release.
*/
FileName: string;
/**
* The SHA1 checksum of the update package containing this release.
*/
SHA1: string;
/**
* The SHA256 checksum of the update package containing this release.
*/
SHA256: string;
/**
* The size in bytes of the update package containing this release.
*/
Size: bigint;
/**
* The release notes in markdown format, as passed to Velopack when packaging the release. This may be an empty string.
*/
NotesMarkdown: string;
/**
* The release notes in HTML format, transformed from Markdown when packaging the release. This may be an empty string.
*/
NotesHtml: string;
};

View File

@@ -1,102 +1,126 @@
import * as addon from './load';
import type { UpdateInfo } from './bindings/UpdateInfo';
import type { UpdateOptions } from './bindings/UpdateOptions';
import * as addon from "./load";
import type { UpdateInfo } from "./bindings/UpdateInfo";
import type { UpdateOptions } from "./bindings/UpdateOptions";
export { UpdateInfo, UpdateOptions };
type UpdateManagerOpaque = {};
declare module "./load" {
function js_new_update_manager(urlOrPath: string, options?: string): UpdateManagerOpaque;
function js_new_update_manager(
urlOrPath: string,
options?: string,
): UpdateManagerOpaque;
function js_get_current_version(um: UpdateManagerOpaque): string;
// function js_get_app_id(um: UpdateManagerOpaque): string;
// function js_is_portable(um: UpdateManagerOpaque): boolean;
// function js_is_installed(um: UpdateManagerOpaque): boolean;
// function js_is_update_pending_restart(um: UpdateManagerOpaque): boolean;
function js_check_for_updates_async(um: UpdateManagerOpaque): Promise<string | null>;
function js_download_update_async(um: UpdateManagerOpaque, update: string, progress: (perc: number) => void): Promise<void>;
function js_wait_exit_then_apply_update(um: UpdateManagerOpaque, update: string, silent?: boolean, restart?: boolean, restartArgs?: string[]): void;
function js_appbuilder_run(cb: (hook_name: string, current_version: string) => void, customArgs: string[] | null): void;
function js_check_for_updates_async(
um: UpdateManagerOpaque,
): Promise<string | null>;
function js_download_update_async(
um: UpdateManagerOpaque,
update: string,
progress: (perc: number) => void,
): Promise<void>;
function js_wait_exit_then_apply_update(
um: UpdateManagerOpaque,
update: string,
silent?: boolean,
restart?: boolean,
restartArgs?: string[],
): void;
function js_appbuilder_run(
cb: (hook_name: string, current_version: string) => void,
customArgs: string[] | null,
): void;
}
type VelopackHookType = "after-install" | "before-uninstall" | "before-update" | "after-update" | "restarted" | "first-run";
type VelopackHookType =
| "after-install"
| "before-uninstall"
| "before-update"
| "after-update"
| "restarted"
| "first-run";
type VelopackHook = (version: string) => void;
class VelopackAppBuilder {
private _hooks = new Map<VelopackHookType, VelopackHook>();
private _customArgs: string[] | null = null;
/**
WARNING: FastCallback hooks are run during critical stages of Velopack operations.
Your code will be run and then the process will exit.
If your code has not completed within 30 seconds, it will be terminated.
Only supported on windows; On other operating systems, this will never be called.
*/
/**
* WARNING: FastCallback hooks are run during critical stages of Velopack operations.
* Your code will be run and then the process will exit.
* If your code has not completed within 30 seconds, it will be terminated.
* Only supported on windows; On other operating systems, this will never be called.
*/
onAfterInstallFastCallback(callback: VelopackHook): VelopackAppBuilder {
this._hooks.set("after-install", callback);
return this;
}
/**
WARNING: FastCallback hooks are run during critical stages of Velopack operations.
Your code will be run and then the process will exit.
If your code has not completed within 30 seconds, it will be terminated.
Only supported on windows; On other operating systems, this will never be called.
*/
/**
* WARNING: FastCallback hooks are run during critical stages of Velopack operations.
* Your code will be run and then the process will exit.
* If your code has not completed within 30 seconds, it will be terminated.
* Only supported on windows; On other operating systems, this will never be called.
*/
onBeforeUninstallFastCallback(callback: VelopackHook): VelopackAppBuilder {
this._hooks.set("before-uninstall", callback);
return this;
}
/**
WARNING: FastCallback hooks are run during critical stages of Velopack operations.
Your code will be run and then the process will exit.
If your code has not completed within 15 seconds, it will be terminated.
Only supported on windows; On other operating systems, this will never be called.
*/
/**
* WARNING: FastCallback hooks are run during critical stages of Velopack operations.
* Your code will be run and then the process will exit.
* If your code has not completed within 15 seconds, it will be terminated.
* Only supported on windows; On other operating systems, this will never be called.
*/
onBeforeUpdateFastCallback(callback: VelopackHook): VelopackAppBuilder {
this._hooks.set("before-update", callback);
return this;
}
/**
WARNING: FastCallback hooks are run during critical stages of Velopack operations.
Your code will be run and then the process will exit.
If your code has not completed within 15 seconds, it will be terminated.
Only supported on windows; On other operating systems, this will never be called.
*/
/**
* WARNING: FastCallback hooks are run during critical stages of Velopack operations.
* Your code will be run and then the process will exit.
* If your code has not completed within 15 seconds, it will be terminated.
* Only supported on windows; On other operating systems, this will never be called.
*/
onAfterUpdateFastCallback(callback: VelopackHook): VelopackAppBuilder {
this._hooks.set("after-update", callback);
return this;
}
/**
This hook is triggered when the application is restarted by Velopack after installing updates.
*/
/**
* This hook is triggered when the application is restarted by Velopack after installing updates.
*/
onRestarted(callback: VelopackHook): VelopackAppBuilder {
this._hooks.set("restarted", callback);
return this;
}
/**
This hook is triggered when the application is started for the first time after installation.
*/
/**
* This hook is triggered when the application is started for the first time after installation.
*/
onFirstRun(callback: VelopackHook): VelopackAppBuilder {
this._hooks.set("first-run", callback);
return this;
}
/**
Override the command line arguments used by VelopackApp. (by default this is env::args().skip(1))
*/
* Override the command line arguments used by VelopackApp. (by default this is env::args().skip(1))
*/
setArgs(args: string[]): VelopackAppBuilder {
this._customArgs = args;
return this;
}
/**
Runs the Velopack startup logic. This should be the first thing to run in your app.
In some circumstances it may terminate/restart the process to perform tasks.
*/
/**
* Runs the Velopack startup logic. This should be the first thing to run in your app.
* In some circumstances it may terminate/restart the process to perform tasks.
*/
run(): void {
addon.js_appbuilder_run((hook_name: string, current_version: string) => {
let hook = this._hooks.get(hook_name as VelopackHookType);
@@ -110,14 +134,17 @@ class VelopackAppBuilder {
export const VelopackApp = {
build: () => {
return new VelopackAppBuilder();
}
}
},
};
export class UpdateManager {
private opaque: UpdateManagerOpaque;
constructor(urlOrPath: string, options?: UpdateOptions) {
this.opaque = addon.js_new_update_manager(urlOrPath, options ? JSON.stringify(options) : "");
this.opaque = addon.js_new_update_manager(
urlOrPath,
options ? JSON.stringify(options) : "",
);
}
getCurrentVersion(): string {
@@ -141,11 +168,13 @@ export class UpdateManager {
// }
/**
Checks for updates, returning None if there are none available. If there are updates available, this method will return an
UpdateInfo object containing the latest available release, and any delta updates that can be applied if they are available.
*/
* Checks for updates, returning None if there are none available. If there are updates available, this method will return an
* UpdateInfo object containing the latest available release, and any delta updates that can be applied if they are available.
*/
checkForUpdatesAsync(): Promise<UpdateInfo | null> {
let json: Promise<string | null> = addon.js_check_for_updates_async(this.opaque);
let json: Promise<string | null> = addon.js_check_for_updates_async(
this.opaque,
);
return json.then((json) => {
if (json && json.length > 0) {
return JSON.parse(json);
@@ -155,29 +184,47 @@ export class UpdateManager {
}
/**
Downloads the specified updates to the local app packages directory. Progress is reported back to the caller via an optional Sender.
This function will acquire a global update lock so may fail if there is already another update operation in progress.
- If the update contains delta packages and the delta feature is enabled
this method will attempt to unpack and prepare them.
- If there is no delta update available, or there is an error preparing delta
packages, this method will fall back to downloading the full version of the update.
*/
downloadUpdateAsync(update: UpdateInfo, progress: (perc: number) => void): Promise<void> {
* Downloads the specified updates to the local app packages directory. Progress is reported back to the caller via an optional Sender.
* This function will acquire a global update lock so may fail if there is already another update operation in progress.
* - If the update contains delta packages and the delta feature is enabled
* this method will attempt to unpack and prepare them.
* - If there is no delta update available, or there is an error preparing delta
* packages, this method will fall back to downloading the full version of the update.
*/
downloadUpdateAsync(
update: UpdateInfo,
progress: (perc: number) => void,
): Promise<void> {
if (!update) {
throw new Error("update is required");
}
return addon.js_download_update_async(this.opaque, JSON.stringify(update), progress ?? (() => { }));
return addon.js_download_update_async(
this.opaque,
JSON.stringify(update),
progress ?? (() => {}),
);
}
/**
This will launch the Velopack updater and tell it to wait for this program to exit gracefully.
You should then clean up any state and exit your app. The updater will apply updates and then
optionally restart your app. The updater will only wait for 60 seconds before giving up.
*/
waitExitThenApplyUpdate(update: UpdateInfo, silent: boolean = false, restart: boolean = true, restartArgs: string[] = []): void {
* This will launch the Velopack updater and tell it to wait for this program to exit gracefully.
* You should then clean up any state and exit your app. The updater will apply updates and then
* optionally restart your app. The updater will only wait for 60 seconds before giving up.
*/
waitExitThenApplyUpdate(
update: UpdateInfo,
silent: boolean = false,
restart: boolean = true,
restartArgs: string[] = [],
): void {
if (!update) {
throw new Error("update is required");
}
addon.js_wait_exit_then_apply_update(this.opaque, JSON.stringify(update), silent, restart, restartArgs);
addon.js_wait_exit_then_apply_update(
this.opaque,
JSON.stringify(update),
silent,
restart,
restartArgs,
);
}
}
}

View File

@@ -9,10 +9,10 @@ import { proxy } from "@neon-rs/load";
module.exports = proxy({
platforms: {
'win32-x64-msvc': () => require('@velopack/win32-x64-msvc'),
'darwin-x64': () => require('@velopack/darwin-x64'),
'darwin-arm64': () => require('@velopack/darwin-arm64'),
'linux-x64-gnu': () => require('@velopack/linux-x64-gnu')
"win32-x64-msvc": () => require("@velopack/win32-x64-msvc"),
"darwin-x64": () => require("@velopack/darwin-x64"),
"darwin-arm64": () => require("@velopack/darwin-arm64"),
"linux-x64-gnu": () => require("@velopack/linux-x64-gnu"),
},
debug: () => require('../index.node'),
debug: () => require("../index.node"),
});

View File

@@ -1,130 +1,130 @@
import { VelopackApp } from "../src/index";
test("VelopackApp should handle restarted event", () => {
let afterInstall = false;
let beforeUninstall = false;
let beforeUpdate = false;
let afterUpdate = false;
let restarted = false;
let firstRun = false;
let afterInstall = false;
let beforeUninstall = false;
let beforeUpdate = false;
let afterUpdate = false;
let restarted = false;
let firstRun = false;
VelopackApp.build()
.onAfterInstallFastCallback(() => afterInstall = true)
.onBeforeUninstallFastCallback(() => beforeUninstall = true)
.onBeforeUpdateFastCallback(() => beforeUpdate = true)
.onAfterUpdateFastCallback(() => afterUpdate = true)
.onRestarted(() => restarted = true)
.onFirstRun(() => firstRun = true)
.run();
VelopackApp.build()
.onAfterInstallFastCallback(() => (afterInstall = true))
.onBeforeUninstallFastCallback(() => (beforeUninstall = true))
.onBeforeUpdateFastCallback(() => (beforeUpdate = true))
.onAfterUpdateFastCallback(() => (afterUpdate = true))
.onRestarted(() => (restarted = true))
.onFirstRun(() => (firstRun = true))
.run();
expect(afterInstall).toBe(false);
expect(beforeUninstall).toBe(false);
expect(beforeUpdate).toBe(false);
expect(afterUpdate).toBe(false);
expect(restarted).toBe(true);
expect(firstRun).toBe(false);
expect(afterInstall).toBe(false);
expect(beforeUninstall).toBe(false);
expect(beforeUpdate).toBe(false);
expect(afterUpdate).toBe(false);
expect(restarted).toBe(true);
expect(firstRun).toBe(false);
});
test("VelopackApp should handle after-install hook", () => {
let afterInstall = false;
let beforeUninstall = false;
let beforeUpdate = false;
let afterUpdate = false;
let restarted = false;
let firstRun = false;
let afterInstall = false;
let beforeUninstall = false;
let beforeUpdate = false;
let afterUpdate = false;
let restarted = false;
let firstRun = false;
VelopackApp.build()
.onAfterInstallFastCallback(() => afterInstall = true)
.onBeforeUninstallFastCallback(() => beforeUninstall = true)
.onBeforeUpdateFastCallback(() => beforeUpdate = true)
.onAfterUpdateFastCallback(() => afterUpdate = true)
.onRestarted(() => restarted = true)
.onFirstRun(() => firstRun = true)
.setArgs(["--veloapp-install", "1.2.3-test.4"])
.run();
VelopackApp.build()
.onAfterInstallFastCallback(() => (afterInstall = true))
.onBeforeUninstallFastCallback(() => (beforeUninstall = true))
.onBeforeUpdateFastCallback(() => (beforeUpdate = true))
.onAfterUpdateFastCallback(() => (afterUpdate = true))
.onRestarted(() => (restarted = true))
.onFirstRun(() => (firstRun = true))
.setArgs(["--veloapp-install", "1.2.3-test.4"])
.run();
expect(afterInstall).toBe(true);
expect(beforeUninstall).toBe(false);
expect(beforeUpdate).toBe(false);
expect(afterUpdate).toBe(false);
expect(restarted).toBe(false);
expect(firstRun).toBe(false);
expect(afterInstall).toBe(true);
expect(beforeUninstall).toBe(false);
expect(beforeUpdate).toBe(false);
expect(afterUpdate).toBe(false);
expect(restarted).toBe(false);
expect(firstRun).toBe(false);
});
test("VelopackApp should handle before-uninstall hook", () => {
let afterInstall = false;
let beforeUninstall = false;
let beforeUpdate = false;
let afterUpdate = false;
let restarted = false;
let firstRun = false;
let afterInstall = false;
let beforeUninstall = false;
let beforeUpdate = false;
let afterUpdate = false;
let restarted = false;
let firstRun = false;
VelopackApp.build()
.onAfterInstallFastCallback(() => afterInstall = true)
.onBeforeUninstallFastCallback(() => beforeUninstall = true)
.onBeforeUpdateFastCallback(() => beforeUpdate = true)
.onAfterUpdateFastCallback(() => afterUpdate = true)
.onRestarted(() => restarted = true)
.onFirstRun(() => firstRun = true)
.setArgs(["--veloapp-uninstall", "1.2.3-test"])
.run();
VelopackApp.build()
.onAfterInstallFastCallback(() => (afterInstall = true))
.onBeforeUninstallFastCallback(() => (beforeUninstall = true))
.onBeforeUpdateFastCallback(() => (beforeUpdate = true))
.onAfterUpdateFastCallback(() => (afterUpdate = true))
.onRestarted(() => (restarted = true))
.onFirstRun(() => (firstRun = true))
.setArgs(["--veloapp-uninstall", "1.2.3-test"])
.run();
expect(afterInstall).toBe(false);
expect(beforeUninstall).toBe(true);
expect(beforeUpdate).toBe(false);
expect(afterUpdate).toBe(false);
expect(restarted).toBe(false);
expect(firstRun).toBe(false);
expect(afterInstall).toBe(false);
expect(beforeUninstall).toBe(true);
expect(beforeUpdate).toBe(false);
expect(afterUpdate).toBe(false);
expect(restarted).toBe(false);
expect(firstRun).toBe(false);
});
test("VelopackApp should handle after-update hook", () => {
let afterInstall = false;
let beforeUninstall = false;
let beforeUpdate = false;
let afterUpdate = false;
let restarted = false;
let firstRun = false;
let afterInstall = false;
let beforeUninstall = false;
let beforeUpdate = false;
let afterUpdate = false;
let restarted = false;
let firstRun = false;
VelopackApp.build()
.onAfterInstallFastCallback(() => afterInstall = true)
.onBeforeUninstallFastCallback(() => beforeUninstall = true)
.onBeforeUpdateFastCallback(() => beforeUpdate = true)
.onAfterUpdateFastCallback(() => afterUpdate = true)
.onRestarted(() => restarted = true)
.onFirstRun(() => firstRun = true)
.setArgs(["--veloapp-updated", "1.2.3"])
.run();
VelopackApp.build()
.onAfterInstallFastCallback(() => (afterInstall = true))
.onBeforeUninstallFastCallback(() => (beforeUninstall = true))
.onBeforeUpdateFastCallback(() => (beforeUpdate = true))
.onAfterUpdateFastCallback(() => (afterUpdate = true))
.onRestarted(() => (restarted = true))
.onFirstRun(() => (firstRun = true))
.setArgs(["--veloapp-updated", "1.2.3"])
.run();
expect(afterInstall).toBe(false);
expect(beforeUninstall).toBe(false);
expect(beforeUpdate).toBe(false);
expect(afterUpdate).toBe(true);
expect(restarted).toBe(false);
expect(firstRun).toBe(false);
expect(afterInstall).toBe(false);
expect(beforeUninstall).toBe(false);
expect(beforeUpdate).toBe(false);
expect(afterUpdate).toBe(true);
expect(restarted).toBe(false);
expect(firstRun).toBe(false);
});
test("VelopackApp should handle before-update hook", () => {
let afterInstall = false;
let beforeUninstall = false;
let beforeUpdate = false;
let afterUpdate = false;
let restarted = false;
let firstRun = false;
let afterInstall = false;
let beforeUninstall = false;
let beforeUpdate = false;
let afterUpdate = false;
let restarted = false;
let firstRun = false;
VelopackApp.build()
.onAfterInstallFastCallback(() => afterInstall = true)
.onBeforeUninstallFastCallback(() => beforeUninstall = true)
.onBeforeUpdateFastCallback(() => beforeUpdate = true)
.onAfterUpdateFastCallback(() => afterUpdate = true)
.onRestarted(() => restarted = true)
.onFirstRun(() => firstRun = true)
.setArgs(["--veloapp-obsolete", "1.2.3-test.4"])
.run();
VelopackApp.build()
.onAfterInstallFastCallback(() => (afterInstall = true))
.onBeforeUninstallFastCallback(() => (beforeUninstall = true))
.onBeforeUpdateFastCallback(() => (beforeUpdate = true))
.onAfterUpdateFastCallback(() => (afterUpdate = true))
.onRestarted(() => (restarted = true))
.onFirstRun(() => (firstRun = true))
.setArgs(["--veloapp-obsolete", "1.2.3-test.4"])
.run();
expect(afterInstall).toBe(false);
expect(beforeUninstall).toBe(false);
expect(beforeUpdate).toBe(true);
expect(afterUpdate).toBe(false);
expect(restarted).toBe(false);
expect(firstRun).toBe(false);
});
expect(afterInstall).toBe(false);
expect(beforeUninstall).toBe(false);
expect(beforeUpdate).toBe(true);
expect(afterUpdate).toBe(false);
expect(restarted).toBe(false);
expect(firstRun).toBe(false);
});

View File

@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["lib", "test"],
}
"exclude": ["lib", "test"]
}

View File

@@ -3,7 +3,7 @@
"compilerOptions": {
"module": "node16",
"declaration": true,
"outDir": "lib",
"outDir": "lib"
},
"exclude": ["lib"]
}