Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(npm): startup time reduce #705

Merged
merged 7 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packaging/npm-bundled/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@evilmartians/lefthook",
"version": "1.6.10",
"description": "Simple git hooks manager",
"main": "index.js",
"main": "bin/index.js",
"bin": {
"lefthook": "./bin/index.js"
},
Expand Down
2 changes: 1 addition & 1 deletion packaging/npm-installer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@evilmartians/lefthook-installer",
"version": "1.6.10",
"description": "Simple git hooks manager",
"main": "index.js",
"main": "bin/index.js",
"bin": {
"lefthook": "./bin/index.js"
},
Expand Down
3 changes: 3 additions & 0 deletions packaging/npm/lefthook-darwin-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "lefthook-darwin-arm64",
"version": "1.6.10",
"description": "The macOS ARM 64-bit binary for lefthook, git hooks manager.",
"bin": {
"lefthook": "bin/lefthook"
},
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions packaging/npm/lefthook-darwin-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "lefthook-darwin-x64",
"version": "1.6.10",
"description": "The macOS 64-bit binary for lefthook, git hooks manager.",
"bin": {
"lefthook": "bin/lefthook"
},
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions packaging/npm/lefthook-freebsd-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "lefthook-freebsd-arm64",
"version": "1.6.10",
"description": "The FreeBSD ARM 64-bit binary for lefthook, git hooks manager.",
"bin": {
"lefthook": "bin/lefthook"
},
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions packaging/npm/lefthook-freebsd-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "lefthook-freebsd-x64",
"version": "1.6.10",
"description": "The FreeBSD 64-bit binary for lefthook, git hooks manager.",
"bin": {
"lefthook": "bin/lefthook"
},
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions packaging/npm/lefthook-linux-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "lefthook-linux-arm64",
"version": "1.6.10",
"description": "The Linux ARM 64-bit binary for lefthook, git hooks manager.",
"bin": {
"lefthook": "bin/lefthook"
},
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions packaging/npm/lefthook-linux-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "lefthook-linux-x64",
"version": "1.6.10",
"description": "The Linux 64-bit binary for lefthook, git hooks manager.",
"bin": {
"lefthook": "bin/lefthook"
},
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions packaging/npm/lefthook-windows-arm64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "lefthook-windows-arm64",
"version": "1.6.10",
"description": "The Windows ARM 64-bit binary for lefthook, git hooks manager.",
"bin": {
"lefthook": "bin/lefthook"
},
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions packaging/npm/lefthook-windows-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "lefthook-windows-x64",
"version": "1.6.10",
"description": "The Windows 64-bit binary for lefthook, git hooks manager.",
"bin": {
"lefthook": "bin/lefthook"
},
"preferUnplugged": false,
"repository": "https://github.com/evilmartians/lefthook",
"license": "MIT",
Expand Down
17 changes: 0 additions & 17 deletions packaging/npm/lefthook/bin/index.js

This file was deleted.

12 changes: 6 additions & 6 deletions packaging/npm/lefthook/get-exe.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const path = require("path")
const path = require("path");

function getExePath() {
// Detect OS
// https://nodejs.org/api/process.html#process_process_platform
let os = process.platform;
let extension = '';
if (['win32', 'cygwin'].includes(process.platform)) {
os = 'windows';
extension = '.exe';
let extension = "";
if (["win32", "cygwin"].includes(process.platform)) {
os = "windows";
extension = ".exe";
}

// Detect architecture
// https://nodejs.org/api/process.html#process_process_arch
let arch = process.arch;

return require.resolve(`lefthook-${os}-${arch}/bin/lefthook${extension}`)
return require.resolve(`lefthook-${os}-${arch}/bin/lefthook${extension}`);
}

exports.getExePath = getExePath;
4 changes: 0 additions & 4 deletions packaging/npm/lefthook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"name": "lefthook",
"version": "1.6.10",
"description": "Simple git hooks manager",
"main": "index.js",
"repository": "https://github.com/evilmartians/lefthook",
"bin": {
"lefthook": "bin/index.js"
},
"keywords": [
"git",
"hook",
Expand Down
16 changes: 9 additions & 7 deletions packaging/npm/lefthook/postinstall.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
const { spawnSync } = require("child_process")
const { getExePath } = require("./get-exe")
const { spawnSync } = require("child_process");
const { getExePath } = require("./get-exe");

function install() {
if (process.env.CI) {
return
return;
}

spawnSync(getExePath(), ["install", "-f"], {
cwd: process.env.INIT_CWD || process.cwd(),
stdio: "inherit",
})
});
}

try {
install()
} catch(e) {
console.warn("'lefthook install' command failed. Try running it manually.\n" + e)
install();
} catch (e) {
console.warn(
"'lefthook install' command failed. Try running it manually.\n" + e,
);
}