Skip to content

Commit

Permalink
perf(npm): startup time reduce (#705)
Browse files Browse the repository at this point in the history
* perf(`npm/lefthook`): use `optionalDependencies` `bin` field

* perf(`npm/@evilmartians/lefthook`): update `binary` at postinstall

* perf(`@evilmartians/lefthook-installer`): use `postinstall` binary

* fix(`@evilmartians/lefthook`): typo fix

* fix(`@evilmartians/lefthook-installer`): typo fix

* revert(`@npm-*`): restore old behavior and fix `pkg` `main` field

* chore(`npm-bundled`): add missing `bin` removed on prev commit
  • Loading branch information
dalisoft committed Jul 8, 2024
1 parent c15e15c commit ae05d1f
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 36 deletions.
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.18",
"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.18",
"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.18",
"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.18",
"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.18",
"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.18",
"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.18",
"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.18",
"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.18",
"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.18",
"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.18",
"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,
);
}

0 comments on commit ae05d1f

Please sign in to comment.