@yao-pkg/pkg 5.12.1 → 5.14.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.
@@ -16,12 +16,28 @@ const log_1 = require("./log");
16
16
  const fabricator_1 = require("./fabricator");
17
17
  const types_1 = require("./types");
18
18
  const compress_type_1 = require("./compress_type");
19
- function discoverPlaceholder(binaryBuffer, searchString, padder) {
19
+ function discoverPlaceholder(binaryBuffer, searchString, padder, searchOffset = 0) {
20
20
  const placeholder = Buffer.from(searchString);
21
- const position = binaryBuffer.indexOf(placeholder);
21
+ const position = binaryBuffer.indexOf(placeholder, searchOffset);
22
22
  if (position === -1) {
23
23
  return { notFound: true };
24
24
  }
25
+ /**
26
+ * the PAYLOAD/PRELUDE placeholders can occur twice in the binaries:
27
+ * - in source text as a string literal
28
+ * - in bytecode as a raw string
29
+ * the ordering depends on the platform - we need to make sure that
30
+ * the bytecode string is replaced, not the source literal.
31
+ *
32
+ * this rejects the source code literal if it occurs first in the binary
33
+ * also see: https://github.com/yao-pkg/pkg/pull/86
34
+ */
35
+ if (binaryBuffer[position - 1] === 39 /* ascii for ' APOSTROPHE */) {
36
+ const nextPlaceholder = discoverPlaceholder(binaryBuffer, searchString, padder, position + placeholder.length);
37
+ if (!('notFound' in nextPlaceholder)) {
38
+ return nextPlaceholder;
39
+ }
40
+ }
25
41
  return { position, size: placeholder.length, padder };
26
42
  }
27
43
  function injectPlaceholder(fd, placeholder, value, cb) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yao-pkg/pkg",
3
- "version": "5.12.1",
3
+ "version": "5.14.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.9",
28
+ "@yao-pkg/pkg-fetch": "3.5.11",
29
29
  "chalk": "^4.1.2",
30
30
  "fs-extra": "^9.1.0",
31
31
  "globby": "^11.1.0",