@yao-pkg/pkg 6.5.1 → 6.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +112 -0
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -90,6 +90,14 @@ dashes, for example `node18-macos-x64` or `node14-linux-arm64`:
90
90
 
91
91
  (element) is unsupported, but you may try to compile yourself.
92
92
 
93
+ If your target is available in the assets of the latest [pkg-fetch release](https://github.com/yao-pkg/pkg-fetch/releases),
94
+ `pkg` downloads the pre-compiled Node.js binary from that project. Otherwise,
95
+ or if you specify the `--build` option, it will build the binary from source
96
+ (takes a very long time).
97
+ Pre-compiled Node.js binaries for some unsupported architectures and
98
+ instructions for using them are available in the [pkg-binaries](https://github.com/yao-pkg/pkg-binaries)
99
+ project.
100
+
93
101
  You may omit any element (and specify just `node14` for example).
94
102
  The omitted elements will be taken from current platform or
95
103
  system-wide Node.js installation (its version and arch).
@@ -193,6 +201,9 @@ like tests, documentation or build files that could have been included by a depe
193
201
  }
194
202
  ```
195
203
 
204
+ Note that both `**` and `*` would not match dotfiles e.g. `.git`,
205
+ the dotfile names must be in the glob explicitly to be matched.
206
+
196
207
  To see if you have unwanted files in your executable, read the [Exploring virtual file system embedded in debug mode](#exploring-virtual-file-system-embedded-in-debug-mode) section.
197
208
 
198
209
  ### Options
@@ -509,3 +520,104 @@ or
509
520
  C:\> output.exe
510
521
 
511
522
  Note: make sure not to use --debug flag in production.
523
+
524
+ ### Injecting Windows Executable Metadata After Packaging
525
+ Executables created with `pkg` are based on a Node.js binary and, by default,
526
+ inherit its embedded metadata – such as version number, product name, company
527
+ name, icon, and description. This can be misleading or unpolished in
528
+ distributed applications.
529
+
530
+ There are two ways to customize the metadata of the resulting `.exe`:
531
+ 1. **Use a custom Node.js binary** with your own metadata already embedded.
532
+ See: [Use Custom Node.js Binary](#use-custom-nodejs-binary)
533
+
534
+ 2. **Post-process the generated executable** using
535
+ [`resedit`](https://www.npmjs.com/package/resedit), a Node.js-compatible
536
+ tool for modifying Windows executable resources. This allows injecting
537
+ correct version info, icons, copyright,
538
+ and more.
539
+
540
+ This section focuses on the second approach: post-processing the packaged
541
+ binary using [`resedit`](https://www.npmjs.com/package/resedit).
542
+
543
+ > ⚠️ Other tools may corrupt the executable, resulting in runtime errors such as
544
+ > `Pkg: Error reading from file.` –
545
+ > [`resedit`](https://www.npmjs.com/package/resedit) has proven to work reliably
546
+ > with `pkg`-generated binaries.
547
+
548
+ Below is a working example for post-processing an `.exe` file using the Node.js API of [`resedit`](https://www.npmjs.com/package/resedit):
549
+
550
+ ```ts
551
+ import * as ResEdit from "resedit";
552
+ import * as fs from "fs";
553
+ import * as path from "path";
554
+
555
+ // Set your inputs:
556
+ const exePath = "dist/my-tool.exe"; // Path to the generated executable
557
+ const outputPath = exePath; // Overwrite or use a different path
558
+ const version = "1.2.3"; // Your application version
559
+
560
+ const lang = 1033; // en-US
561
+ const codepage = 1200; // Unicode
562
+
563
+ const exeData = fs.readFileSync(exePath);
564
+ const exe = ResEdit.NtExecutable.from(exeData);
565
+ const res = ResEdit.NtExecutableResource.from(exe);
566
+
567
+ const viList = ResEdit.Resource.VersionInfo.fromEntries(res.entries);
568
+ const vi = viList[0];
569
+
570
+ const [major, minor, patch] = version.split(".");
571
+ vi.setFileVersion(Number(major), Number(minor), Number(patch), 0, lang);
572
+ vi.setProductVersion(Number(major), Number(minor), Number(patch), 0, lang);
573
+
574
+ vi.setStringValues({ lang, codepage }, {
575
+ FileDescription: "ACME CLI Tool",
576
+ ProductName: "ACME Application",
577
+ CompanyName: "ACME Corporation",
578
+ ProductVersion: version,
579
+ FileVersion: version,
580
+ OriginalFilename: path.basename(exePath),
581
+ LegalCopyright: `© ${new Date().getFullYear()} ACME Corporation`
582
+ });
583
+
584
+ vi.outputToResourceEntries(res.entries);
585
+ res.outputResource(exe);
586
+ const newBinary = exe.generate();
587
+
588
+ fs.writeFileSync(outputPath, Buffer.from(newBinary));
589
+ ```
590
+
591
+ As an alternative to the Node.js API,
592
+ [`resedit`](https://www.npmjs.com/package/resedit) also supports command–line
593
+ usage. This can be convenient for simple use cases in build scripts.
594
+
595
+ The following command examples inject an icon and metadata into the executable
596
+ `dist/bin/app_with_metadata.exe`, based on the original built file
597
+ `dist/bin/app.exe`.
598
+
599
+ - **Example (PowerShell on Windows)**
600
+ ```powershell
601
+ npx resedit dist/bin/app.exe dist/bin/app_with_metadata.exe `
602
+ --icon 1,dist/favicon.ico `
603
+ --company-name "ACME Corporation" `
604
+ --file-description "ACME CLI Tool" `
605
+ --product-name "ACME Application" `
606
+ --file-version 1.2.3.4
607
+ ```
608
+
609
+ - **Example (bash on Linux/macOS)**
610
+ ```bash
611
+ npx resedit dist/bin/app.exe dist/bin/app_with_metadata.exe \
612
+ --icon 1,dist/favicon.ico \
613
+ --company-name "ACME Corporation" \
614
+ --file-description "ACME CLI Tool" \
615
+ --product-name "ACME Application" \
616
+ --file-version 1.2.3.4
617
+ ```
618
+ > 💡 This is especially useful when cross-compiling Windows executables from
619
+ > Linux or macOS using `pkg`.
620
+
621
+ > 📚 **More information:** See the
622
+ > [`resedit`](https://www.npmjs.com/package/resedit) package on npm for
623
+ > additional examples and full API documentation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yao-pkg/pkg",
3
- "version": "6.5.1",
3
+ "version": "6.7.0",
4
4
  "description": "Package your Node.js project into an executable",
5
5
  "main": "lib-es5/index.js",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  "@babel/generator": "^7.23.0",
26
26
  "@babel/parser": "^7.23.0",
27
27
  "@babel/types": "^7.23.0",
28
- "@yao-pkg/pkg-fetch": "3.5.23",
28
+ "@yao-pkg/pkg-fetch": "3.5.25",
29
29
  "into-stream": "^6.0.0",
30
30
  "minimist": "^1.2.6",
31
31
  "multistream": "^4.1.0",