@florianpat/lando-core 3.23.7-compose → 3.23.22-test1

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 (96) hide show
  1. package/CHANGELOG.md +101 -1
  2. package/bin/lando +2 -0
  3. package/bin/lando.cmd +3 -0
  4. package/builders/_lando.js +2 -1
  5. package/components/l337-v4.js +2 -2
  6. package/config.yml +3 -2
  7. package/hooks/lando-autostart-engine.js +4 -25
  8. package/hooks/lando-run-setup.js +58 -0
  9. package/hooks/lando-setup-build-engine-darwin.js +13 -12
  10. package/hooks/lando-setup-build-engine-linux.js +14 -4
  11. package/hooks/lando-setup-build-engine-win32.js +27 -20
  12. package/hooks/lando-setup-build-engine-wsl.js +210 -0
  13. package/hooks/lando-setup-check.js +19 -0
  14. package/hooks/lando-setup-create-ca-wsl.js +34 -0
  15. package/hooks/lando-setup-create-ca.js +22 -23
  16. package/hooks/lando-setup-install-ca-darwin.js +5 -1
  17. package/hooks/lando-setup-install-ca-linux.js +4 -1
  18. package/hooks/lando-setup-install-ca-win32.js +5 -1
  19. package/hooks/lando-setup-install-ca-wsl.js +145 -0
  20. package/hooks/lando-setup-orchestrator.js +4 -4
  21. package/index.js +18 -12
  22. package/lib/app.js +2 -2
  23. package/lib/art.js +20 -8
  24. package/lib/compose.js +0 -3
  25. package/lib/daemon.js +79 -76
  26. package/lib/docker.js +2 -2
  27. package/lib/engine.js +10 -3
  28. package/lib/lando.js +2 -2
  29. package/lib/metrics.js +5 -3
  30. package/lib/updates.js +12 -2
  31. package/node_modules/nanoid/.devcontainer.json +23 -0
  32. package/node_modules/nanoid/README.md +517 -2
  33. package/node_modules/nanoid/async/index.browser.cjs +37 -2
  34. package/node_modules/nanoid/async/index.browser.js +37 -2
  35. package/node_modules/nanoid/async/index.cjs +38 -2
  36. package/node_modules/nanoid/async/index.js +38 -2
  37. package/node_modules/nanoid/async/index.native.js +33 -2
  38. package/node_modules/nanoid/index.browser.cjs +39 -1
  39. package/node_modules/nanoid/index.browser.js +39 -1
  40. package/node_modules/nanoid/index.cjs +42 -2
  41. package/node_modules/nanoid/index.js +42 -2
  42. package/node_modules/nanoid/non-secure/index.cjs +15 -2
  43. package/node_modules/nanoid/non-secure/index.js +15 -2
  44. package/node_modules/nanoid/package.json +1 -1
  45. package/node_modules/nanoid/url-alphabet/index.cjs +4 -0
  46. package/node_modules/nanoid/url-alphabet/index.js +4 -0
  47. package/package.json +7 -7
  48. package/plugins/networking/app.js +4 -2
  49. package/plugins/networking/index.js +19 -6
  50. package/plugins/proxy/builders/_proxy.js +1 -2
  51. package/release-aliases/3-EDGE +1 -1
  52. package/release-aliases/3-STABLE +1 -1
  53. package/renderers/dc2.js +2 -1
  54. package/scripts/add-to-group.sh +72 -0
  55. package/scripts/docker-engine-start.sh +15 -1
  56. package/scripts/install-docker-desktop.ps1 +11 -12
  57. package/scripts/install-system-ca-win32.ps1 +14 -14
  58. package/scripts/run-elevated.ps1 +2 -2
  59. package/scripts/semcompare.sh +142 -0
  60. package/scripts/wait-for-user.sh +1 -2
  61. package/tasks/destroy.js +3 -0
  62. package/tasks/info.js +2 -1
  63. package/tasks/init.js +35 -30
  64. package/tasks/rebuild.js +2 -8
  65. package/tasks/restart.js +2 -8
  66. package/tasks/setup.js +2 -2
  67. package/tasks/shellenv.js +2 -2
  68. package/tasks/start.js +2 -8
  69. package/tasks/stop.js +3 -0
  70. package/utils/build-config.js +2 -0
  71. package/utils/build-tooling-runner.js +2 -1
  72. package/utils/get-app.js +1 -1
  73. package/utils/get-bin-paths.js +2 -2
  74. package/utils/get-compose-x.js +1 -1
  75. package/utils/get-config-defaults.js +12 -7
  76. package/utils/get-docker-bin-path.js +6 -2
  77. package/utils/get-docker-desktop-x.js +21 -0
  78. package/utils/get-docker-x.js +3 -2
  79. package/utils/get-shellenv.js +1 -2
  80. package/utils/get-system-cas.js +25 -6
  81. package/utils/get-win32-envvar-from-wsl.js +7 -0
  82. package/utils/is-admin-user.js +9 -8
  83. package/utils/is-group-member.js +14 -7
  84. package/utils/is-wsl-interop.js +17 -4
  85. package/utils/run-elevated.js +9 -0
  86. package/utils/run-powershell-script.js +31 -5
  87. package/utils/run-tasks.js +3 -2
  88. package/utils/setup-metrics.js +10 -1
  89. package/utils/shutdown-os.js +8 -3
  90. package/utils/spawn-sync-stringer.js +1 -0
  91. package/utils/update-shell-profile.js +8 -7
  92. package/utils/validate-ca.js +31 -0
  93. package/utils/winpath-2-wslpath.js +6 -0
  94. package/utils/wslpath-2-winpath.js +6 -0
  95. package/hooks/lando-dep-check.js +0 -26
  96. package/lib/checksums.txt +0 -0
@@ -1,7 +1,14 @@
1
1
  let crypto = require('crypto')
2
+
2
3
  let { urlAlphabet } = require('../url-alphabet/index.cjs')
4
+
5
+ // `crypto.randomFill()` is a little faster than `crypto.randomBytes()`,
6
+ // because it is possible to use in combination with `Buffer.allocUnsafe()`.
3
7
  let random = bytes =>
4
8
  new Promise((resolve, reject) => {
9
+ // `Buffer.allocUnsafe()` is faster because it doesn’t flush the memory.
10
+ // Memory flushing is unnecessary since the buffer allocation itself resets
11
+ // the memory with the new bytes.
5
12
  crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
6
13
  if (err) {
7
14
  reject(err)
@@ -10,26 +17,55 @@ let random = bytes =>
10
17
  }
11
18
  })
12
19
  })
20
+
13
21
  let customAlphabet = (alphabet, defaultSize = 21) => {
22
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
23
+ // values closer to the alphabet size. The bitmask calculates the closest
24
+ // `2^31 - 1` number, which exceeds the alphabet size.
25
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
14
26
  let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
27
+ // Though, the bitmask solution is not perfect since the bytes exceeding
28
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
29
+ // the random bytes redundancy has to be satisfied.
30
+
31
+ // Note: every hardware random generator call is performance expensive,
32
+ // because the system call for entropy collection takes a lot of time.
33
+ // So, to avoid additional system calls, extra bytes are requested in advance.
34
+
35
+ // Next, a step determines how many random bytes to generate.
36
+ // The number of random bytes gets decided upon the ID size, mask,
37
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
38
+ // according to benchmarks).
15
39
  let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
40
+
16
41
  let tick = (id, size = defaultSize) =>
17
42
  random(step).then(bytes => {
43
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
18
44
  let i = step
19
45
  while (i--) {
46
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
20
47
  id += alphabet[bytes[i] & mask] || ''
21
- if (id.length === size) return id
48
+ if (id.length >= size) return id
22
49
  }
23
50
  return tick(id, size)
24
51
  })
52
+
25
53
  return size => tick('', size)
26
54
  }
55
+
27
56
  let nanoid = (size = 21) =>
28
- random(size).then(bytes => {
57
+ random((size |= 0)).then(bytes => {
29
58
  let id = ''
59
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
30
60
  while (size--) {
61
+ // It is incorrect to use bytes exceeding the alphabet size.
62
+ // The following mask reduces the random byte in the 0-255 value
63
+ // range to the 0-63 value range. Therefore, adding hacks, such
64
+ // as empty string fallback or magic numbers, is unneccessary because
65
+ // the bitmask trims bytes down to the alphabet size.
31
66
  id += urlAlphabet[bytes[size] & 63]
32
67
  }
33
68
  return id
34
69
  })
70
+
35
71
  module.exports = { nanoid, customAlphabet, random }
@@ -1,7 +1,14 @@
1
1
  import crypto from 'crypto'
2
+
2
3
  import { urlAlphabet } from '../url-alphabet/index.js'
4
+
5
+ // `crypto.randomFill()` is a little faster than `crypto.randomBytes()`,
6
+ // because it is possible to use in combination with `Buffer.allocUnsafe()`.
3
7
  let random = bytes =>
4
8
  new Promise((resolve, reject) => {
9
+ // `Buffer.allocUnsafe()` is faster because it doesn’t flush the memory.
10
+ // Memory flushing is unnecessary since the buffer allocation itself resets
11
+ // the memory with the new bytes.
5
12
  crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
6
13
  if (err) {
7
14
  reject(err)
@@ -10,26 +17,55 @@ let random = bytes =>
10
17
  }
11
18
  })
12
19
  })
20
+
13
21
  let customAlphabet = (alphabet, defaultSize = 21) => {
22
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
23
+ // values closer to the alphabet size. The bitmask calculates the closest
24
+ // `2^31 - 1` number, which exceeds the alphabet size.
25
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
14
26
  let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
27
+ // Though, the bitmask solution is not perfect since the bytes exceeding
28
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
29
+ // the random bytes redundancy has to be satisfied.
30
+
31
+ // Note: every hardware random generator call is performance expensive,
32
+ // because the system call for entropy collection takes a lot of time.
33
+ // So, to avoid additional system calls, extra bytes are requested in advance.
34
+
35
+ // Next, a step determines how many random bytes to generate.
36
+ // The number of random bytes gets decided upon the ID size, mask,
37
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
38
+ // according to benchmarks).
15
39
  let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
40
+
16
41
  let tick = (id, size = defaultSize) =>
17
42
  random(step).then(bytes => {
43
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
18
44
  let i = step
19
45
  while (i--) {
46
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
20
47
  id += alphabet[bytes[i] & mask] || ''
21
- if (id.length === size) return id
48
+ if (id.length >= size) return id
22
49
  }
23
50
  return tick(id, size)
24
51
  })
52
+
25
53
  return size => tick('', size)
26
54
  }
55
+
27
56
  let nanoid = (size = 21) =>
28
- random(size).then(bytes => {
57
+ random((size |= 0)).then(bytes => {
29
58
  let id = ''
59
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
30
60
  while (size--) {
61
+ // It is incorrect to use bytes exceeding the alphabet size.
62
+ // The following mask reduces the random byte in the 0-255 value
63
+ // range to the 0-63 value range. Therefore, adding hacks, such
64
+ // as empty string fallback or magic numbers, is unneccessary because
65
+ // the bitmask trims bytes down to the alphabet size.
31
66
  id += urlAlphabet[bytes[size] & 63]
32
67
  }
33
68
  return id
34
69
  })
70
+
35
71
  export { nanoid, customAlphabet, random }
@@ -1,26 +1,57 @@
1
1
  import { getRandomBytesAsync } from 'expo-random'
2
+
2
3
  import { urlAlphabet } from '../url-alphabet/index.js'
4
+
3
5
  let random = getRandomBytesAsync
6
+
4
7
  let customAlphabet = (alphabet, defaultSize = 21) => {
8
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
9
+ // values closer to the alphabet size. The bitmask calculates the closest
10
+ // `2^31 - 1` number, which exceeds the alphabet size.
11
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
5
12
  let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
13
+ // Though, the bitmask solution is not perfect since the bytes exceeding
14
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
15
+ // the random bytes redundancy has to be satisfied.
16
+
17
+ // Note: every hardware random generator call is performance expensive,
18
+ // because the system call for entropy collection takes a lot of time.
19
+ // So, to avoid additional system calls, extra bytes are requested in advance.
20
+
21
+ // Next, a step determines how many random bytes to generate.
22
+ // The number of random bytes gets decided upon the ID size, mask,
23
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
24
+ // according to benchmarks).
6
25
  let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
26
+
7
27
  let tick = (id, size = defaultSize) =>
8
28
  random(step).then(bytes => {
29
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
9
30
  let i = step
10
31
  while (i--) {
32
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
11
33
  id += alphabet[bytes[i] & mask] || ''
12
- if (id.length === size) return id
34
+ if (id.length >= size) return id
13
35
  }
14
36
  return tick(id, size)
15
37
  })
38
+
16
39
  return size => tick('', size)
17
40
  }
41
+
18
42
  let nanoid = (size = 21) =>
19
- random(size).then(bytes => {
43
+ random((size |= 0)).then(bytes => {
20
44
  let id = ''
45
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
21
46
  while (size--) {
47
+ // It is incorrect to use bytes exceeding the alphabet size.
48
+ // The following mask reduces the random byte in the 0-255 value
49
+ // range to the 0-63 value range. Therefore, adding hacks, such
50
+ // as empty string fallback or magic numbers, is unneccessary because
51
+ // the bitmask trims bytes down to the alphabet size.
22
52
  id += urlAlphabet[bytes[size] & 63]
23
53
  }
24
54
  return id
25
55
  })
56
+
26
57
  export { nanoid, customAlphabet, random }
@@ -1,28 +1,65 @@
1
+ // This file replaces `index.js` in bundlers like webpack or Rollup,
2
+ // according to `browser` config in `package.json`.
3
+
1
4
  let { urlAlphabet } = require('./url-alphabet/index.cjs')
5
+
2
6
  let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
7
+
3
8
  let customRandom = (alphabet, defaultSize, getRandom) => {
9
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
10
+ // values closer to the alphabet size. The bitmask calculates the closest
11
+ // `2^31 - 1` number, which exceeds the alphabet size.
12
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
13
+ // `Math.clz32` is not used, because it is not available in browsers.
4
14
  let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
15
+ // Though, the bitmask solution is not perfect since the bytes exceeding
16
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
17
+ // the random bytes redundancy has to be satisfied.
18
+
19
+ // Note: every hardware random generator call is performance expensive,
20
+ // because the system call for entropy collection takes a lot of time.
21
+ // So, to avoid additional system calls, extra bytes are requested in advance.
22
+
23
+ // Next, a step determines how many random bytes to generate.
24
+ // The number of random bytes gets decided upon the ID size, mask,
25
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
26
+ // according to benchmarks).
27
+
28
+ // `-~f => Math.ceil(f)` if f is a float
29
+ // `-~i => i + 1` if i is an integer
5
30
  let step = -~((1.6 * mask * defaultSize) / alphabet.length)
31
+
6
32
  return (size = defaultSize) => {
7
33
  let id = ''
8
34
  while (true) {
9
35
  let bytes = getRandom(step)
10
- let j = step
36
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
37
+ let j = step | 0
11
38
  while (j--) {
39
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
12
40
  id += alphabet[bytes[j] & mask] || ''
13
41
  if (id.length === size) return id
14
42
  }
15
43
  }
16
44
  }
17
45
  }
46
+
18
47
  let customAlphabet = (alphabet, size = 21) =>
19
48
  customRandom(alphabet, size, random)
49
+
20
50
  let nanoid = (size = 21) =>
21
51
  crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
52
+ // It is incorrect to use bytes exceeding the alphabet size.
53
+ // The following mask reduces the random byte in the 0-255 value
54
+ // range to the 0-63 value range. Therefore, adding hacks, such
55
+ // as empty string fallback or magic numbers, is unneccessary because
56
+ // the bitmask trims bytes down to the alphabet size.
22
57
  byte &= 63
23
58
  if (byte < 36) {
59
+ // `0-9a-z`
24
60
  id += byte.toString(36)
25
61
  } else if (byte < 62) {
62
+ // `A-Z`
26
63
  id += (byte - 26).toString(36).toUpperCase()
27
64
  } else if (byte > 62) {
28
65
  id += '-'
@@ -31,4 +68,5 @@ let nanoid = (size = 21) =>
31
68
  }
32
69
  return id
33
70
  }, '')
71
+
34
72
  module.exports = { nanoid, customAlphabet, customRandom, urlAlphabet, random }
@@ -1,28 +1,65 @@
1
+ // This file replaces `index.js` in bundlers like webpack or Rollup,
2
+ // according to `browser` config in `package.json`.
3
+
1
4
  import { urlAlphabet } from './url-alphabet/index.js'
5
+
2
6
  let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
7
+
3
8
  let customRandom = (alphabet, defaultSize, getRandom) => {
9
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
10
+ // values closer to the alphabet size. The bitmask calculates the closest
11
+ // `2^31 - 1` number, which exceeds the alphabet size.
12
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
13
+ // `Math.clz32` is not used, because it is not available in browsers.
4
14
  let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
15
+ // Though, the bitmask solution is not perfect since the bytes exceeding
16
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
17
+ // the random bytes redundancy has to be satisfied.
18
+
19
+ // Note: every hardware random generator call is performance expensive,
20
+ // because the system call for entropy collection takes a lot of time.
21
+ // So, to avoid additional system calls, extra bytes are requested in advance.
22
+
23
+ // Next, a step determines how many random bytes to generate.
24
+ // The number of random bytes gets decided upon the ID size, mask,
25
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
26
+ // according to benchmarks).
27
+
28
+ // `-~f => Math.ceil(f)` if f is a float
29
+ // `-~i => i + 1` if i is an integer
5
30
  let step = -~((1.6 * mask * defaultSize) / alphabet.length)
31
+
6
32
  return (size = defaultSize) => {
7
33
  let id = ''
8
34
  while (true) {
9
35
  let bytes = getRandom(step)
10
- let j = step
36
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
37
+ let j = step | 0
11
38
  while (j--) {
39
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
12
40
  id += alphabet[bytes[j] & mask] || ''
13
41
  if (id.length === size) return id
14
42
  }
15
43
  }
16
44
  }
17
45
  }
46
+
18
47
  let customAlphabet = (alphabet, size = 21) =>
19
48
  customRandom(alphabet, size, random)
49
+
20
50
  let nanoid = (size = 21) =>
21
51
  crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
52
+ // It is incorrect to use bytes exceeding the alphabet size.
53
+ // The following mask reduces the random byte in the 0-255 value
54
+ // range to the 0-63 value range. Therefore, adding hacks, such
55
+ // as empty string fallback or magic numbers, is unneccessary because
56
+ // the bitmask trims bytes down to the alphabet size.
22
57
  byte &= 63
23
58
  if (byte < 36) {
59
+ // `0-9a-z`
24
60
  id += byte.toString(36)
25
61
  } else if (byte < 62) {
62
+ // `A-Z`
26
63
  id += (byte - 26).toString(36).toUpperCase()
27
64
  } else if (byte > 62) {
28
65
  id += '-'
@@ -31,4 +68,5 @@ let nanoid = (size = 21) =>
31
68
  }
32
69
  return id
33
70
  }, '')
71
+
34
72
  export { nanoid, customAlphabet, customRandom, urlAlphabet, random }
@@ -1,7 +1,15 @@
1
1
  let crypto = require('crypto')
2
+
2
3
  let { urlAlphabet } = require('./url-alphabet/index.cjs')
4
+
5
+ // It is best to make fewer, larger requests to the crypto module to
6
+ // avoid system call overhead. So, random numbers are generated in a
7
+ // pool. The pool is a Buffer that is larger than the initial random
8
+ // request size by this multiplier. The pool is enlarged if subsequent
9
+ // requests exceed the maximum buffer size.
3
10
  const POOL_SIZE_MULTIPLIER = 128
4
11
  let pool, poolOffset
12
+
5
13
  let fillPool = bytes => {
6
14
  if (!pool || pool.length < bytes) {
7
15
  pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER)
@@ -13,33 +21,65 @@ let fillPool = bytes => {
13
21
  }
14
22
  poolOffset += bytes
15
23
  }
24
+
16
25
  let random = bytes => {
17
- fillPool((bytes -= 0))
26
+ // `|=` convert `bytes` to number to prevent `valueOf` abusing and pool pollution
27
+ fillPool((bytes |= 0))
18
28
  return pool.subarray(poolOffset - bytes, poolOffset)
19
29
  }
30
+
20
31
  let customRandom = (alphabet, defaultSize, getRandom) => {
32
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
33
+ // values closer to the alphabet size. The bitmask calculates the closest
34
+ // `2^31 - 1` number, which exceeds the alphabet size.
35
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
21
36
  let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
37
+ // Though, the bitmask solution is not perfect since the bytes exceeding
38
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
39
+ // the random bytes redundancy has to be satisfied.
40
+
41
+ // Note: every hardware random generator call is performance expensive,
42
+ // because the system call for entropy collection takes a lot of time.
43
+ // So, to avoid additional system calls, extra bytes are requested in advance.
44
+
45
+ // Next, a step determines how many random bytes to generate.
46
+ // The number of random bytes gets decided upon the ID size, mask,
47
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
48
+ // according to benchmarks).
22
49
  let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
50
+
23
51
  return (size = defaultSize) => {
24
52
  let id = ''
25
53
  while (true) {
26
54
  let bytes = getRandom(step)
55
+ // A compact alternative for `for (let i = 0; i < step; i++)`.
27
56
  let i = step
28
57
  while (i--) {
58
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
29
59
  id += alphabet[bytes[i] & mask] || ''
30
60
  if (id.length === size) return id
31
61
  }
32
62
  }
33
63
  }
34
64
  }
65
+
35
66
  let customAlphabet = (alphabet, size = 21) =>
36
67
  customRandom(alphabet, size, random)
68
+
37
69
  let nanoid = (size = 21) => {
38
- fillPool((size -= 0))
70
+ // `|=` convert `size` to number to prevent `valueOf` abusing and pool pollution
71
+ fillPool((size |= 0))
39
72
  let id = ''
73
+ // We are reading directly from the random pool to avoid creating new array
40
74
  for (let i = poolOffset - size; i < poolOffset; i++) {
75
+ // It is incorrect to use bytes exceeding the alphabet size.
76
+ // The following mask reduces the random byte in the 0-255 value
77
+ // range to the 0-63 value range. Therefore, adding hacks, such
78
+ // as empty string fallback or magic numbers, is unneccessary because
79
+ // the bitmask trims bytes down to the alphabet size.
41
80
  id += urlAlphabet[pool[i] & 63]
42
81
  }
43
82
  return id
44
83
  }
84
+
45
85
  module.exports = { nanoid, customAlphabet, customRandom, urlAlphabet, random }
@@ -1,7 +1,15 @@
1
1
  import crypto from 'crypto'
2
+
2
3
  import { urlAlphabet } from './url-alphabet/index.js'
4
+
5
+ // It is best to make fewer, larger requests to the crypto module to
6
+ // avoid system call overhead. So, random numbers are generated in a
7
+ // pool. The pool is a Buffer that is larger than the initial random
8
+ // request size by this multiplier. The pool is enlarged if subsequent
9
+ // requests exceed the maximum buffer size.
3
10
  const POOL_SIZE_MULTIPLIER = 128
4
11
  let pool, poolOffset
12
+
5
13
  let fillPool = bytes => {
6
14
  if (!pool || pool.length < bytes) {
7
15
  pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER)
@@ -13,33 +21,65 @@ let fillPool = bytes => {
13
21
  }
14
22
  poolOffset += bytes
15
23
  }
24
+
16
25
  let random = bytes => {
17
- fillPool((bytes -= 0))
26
+ // `|=` convert `bytes` to number to prevent `valueOf` abusing and pool pollution
27
+ fillPool((bytes |= 0))
18
28
  return pool.subarray(poolOffset - bytes, poolOffset)
19
29
  }
30
+
20
31
  let customRandom = (alphabet, defaultSize, getRandom) => {
32
+ // First, a bitmask is necessary to generate the ID. The bitmask makes bytes
33
+ // values closer to the alphabet size. The bitmask calculates the closest
34
+ // `2^31 - 1` number, which exceeds the alphabet size.
35
+ // For example, the bitmask for the alphabet size 30 is 31 (00011111).
21
36
  let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
37
+ // Though, the bitmask solution is not perfect since the bytes exceeding
38
+ // the alphabet size are refused. Therefore, to reliably generate the ID,
39
+ // the random bytes redundancy has to be satisfied.
40
+
41
+ // Note: every hardware random generator call is performance expensive,
42
+ // because the system call for entropy collection takes a lot of time.
43
+ // So, to avoid additional system calls, extra bytes are requested in advance.
44
+
45
+ // Next, a step determines how many random bytes to generate.
46
+ // The number of random bytes gets decided upon the ID size, mask,
47
+ // alphabet size, and magic number 1.6 (using 1.6 peaks at performance
48
+ // according to benchmarks).
22
49
  let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
50
+
23
51
  return (size = defaultSize) => {
24
52
  let id = ''
25
53
  while (true) {
26
54
  let bytes = getRandom(step)
55
+ // A compact alternative for `for (let i = 0; i < step; i++)`.
27
56
  let i = step
28
57
  while (i--) {
58
+ // Adding `|| ''` refuses a random byte that exceeds the alphabet size.
29
59
  id += alphabet[bytes[i] & mask] || ''
30
60
  if (id.length === size) return id
31
61
  }
32
62
  }
33
63
  }
34
64
  }
65
+
35
66
  let customAlphabet = (alphabet, size = 21) =>
36
67
  customRandom(alphabet, size, random)
68
+
37
69
  let nanoid = (size = 21) => {
38
- fillPool((size -= 0))
70
+ // `|=` convert `size` to number to prevent `valueOf` abusing and pool pollution
71
+ fillPool((size |= 0))
39
72
  let id = ''
73
+ // We are reading directly from the random pool to avoid creating new array
40
74
  for (let i = poolOffset - size; i < poolOffset; i++) {
75
+ // It is incorrect to use bytes exceeding the alphabet size.
76
+ // The following mask reduces the random byte in the 0-255 value
77
+ // range to the 0-63 value range. Therefore, adding hacks, such
78
+ // as empty string fallback or magic numbers, is unneccessary because
79
+ // the bitmask trims bytes down to the alphabet size.
41
80
  id += urlAlphabet[pool[i] & 63]
42
81
  }
43
82
  return id
44
83
  }
84
+
45
85
  export { nanoid, customAlphabet, customRandom, urlAlphabet, random }
@@ -1,21 +1,34 @@
1
+ // This alphabet uses `A-Za-z0-9_-` symbols.
2
+ // The order of characters is optimized for better gzip and brotli compression.
3
+ // References to the same file (works both for gzip and brotli):
4
+ // `'use`, `andom`, and `rict'`
5
+ // References to the brotli default dictionary:
6
+ // `-26T`, `1983`, `40px`, `75px`, `bush`, `jack`, `mind`, `very`, and `wolf`
1
7
  let urlAlphabet =
2
8
  'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
9
+
3
10
  let customAlphabet = (alphabet, defaultSize = 21) => {
4
11
  return (size = defaultSize) => {
5
12
  let id = ''
6
- let i = size
13
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
14
+ let i = size | 0
7
15
  while (i--) {
16
+ // `| 0` is more compact and faster than `Math.floor()`.
8
17
  id += alphabet[(Math.random() * alphabet.length) | 0]
9
18
  }
10
19
  return id
11
20
  }
12
21
  }
22
+
13
23
  let nanoid = (size = 21) => {
14
24
  let id = ''
15
- let i = size
25
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
26
+ let i = size | 0
16
27
  while (i--) {
28
+ // `| 0` is more compact and faster than `Math.floor()`.
17
29
  id += urlAlphabet[(Math.random() * 64) | 0]
18
30
  }
19
31
  return id
20
32
  }
33
+
21
34
  module.exports = { nanoid, customAlphabet }
@@ -1,21 +1,34 @@
1
+ // This alphabet uses `A-Za-z0-9_-` symbols.
2
+ // The order of characters is optimized for better gzip and brotli compression.
3
+ // References to the same file (works both for gzip and brotli):
4
+ // `'use`, `andom`, and `rict'`
5
+ // References to the brotli default dictionary:
6
+ // `-26T`, `1983`, `40px`, `75px`, `bush`, `jack`, `mind`, `very`, and `wolf`
1
7
  let urlAlphabet =
2
8
  'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
9
+
3
10
  let customAlphabet = (alphabet, defaultSize = 21) => {
4
11
  return (size = defaultSize) => {
5
12
  let id = ''
6
- let i = size
13
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
14
+ let i = size | 0
7
15
  while (i--) {
16
+ // `| 0` is more compact and faster than `Math.floor()`.
8
17
  id += alphabet[(Math.random() * alphabet.length) | 0]
9
18
  }
10
19
  return id
11
20
  }
12
21
  }
22
+
13
23
  let nanoid = (size = 21) => {
14
24
  let id = ''
15
- let i = size
25
+ // A compact alternative for `for (var i = 0; i < step; i++)`.
26
+ let i = size | 0
16
27
  while (i--) {
28
+ // `| 0` is more compact and faster than `Math.floor()`.
17
29
  id += urlAlphabet[(Math.random() * 64) | 0]
18
30
  }
19
31
  return id
20
32
  }
33
+
21
34
  export { nanoid, customAlphabet }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanoid",
3
- "version": "3.3.7",
3
+ "version": "3.3.8",
4
4
  "description": "A tiny (116 bytes), secure URL-friendly unique string ID generator",
5
5
  "keywords": [
6
6
  "uuid",
@@ -1,3 +1,7 @@
1
+ // This alphabet uses `A-Za-z0-9_-` symbols.
2
+ // The order of characters is optimized for better gzip and brotli compression.
3
+ // Same as in non-secure/index.js
1
4
  let urlAlphabet =
2
5
  'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
6
+
3
7
  module.exports = { urlAlphabet }
@@ -1,3 +1,7 @@
1
+ // This alphabet uses `A-Za-z0-9_-` symbols.
2
+ // The order of characters is optimized for better gzip and brotli compression.
3
+ // Same as in non-secure/index.js
1
4
  let urlAlphabet =
2
5
  'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
6
+
3
7
  export { urlAlphabet }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@florianpat/lando-core",
3
3
  "description": "The libraries that power all of Lando. Fork by flo for compose integration",
4
- "version": "3.23.7-compose",
4
+ "version": "3.23.22-test1",
5
5
  "author": "Florian Patruck @florianPat",
6
6
  "license": "GPL-3.0",
7
7
  "repository": "florianPat/lando-core",
@@ -46,7 +46,7 @@
46
46
  "docs:preview": "vitepress preview docs",
47
47
  "docs:rename-sitemap": "node docs/.vitepress/rename-sitemap.js",
48
48
  "lint": "eslint . --ext .js --ext .mjs ",
49
- "pkg": "pkg --config package.json --targets node20 --options 'dns-result-order=ipv4first' bin/lando",
49
+ "pkg": "pkg --config package.json --output dist/lando ---targets node20 --options 'dns-result-order=ipv4first' bin/lando",
50
50
  "test:unit": "nyc --reporter=html --reporter=text mocha --timeout 5000 test/**/*.spec.js",
51
51
  "test:leia": "leia \"examples/**/README.md\" -c 'Destroy tests' --stdin",
52
52
  "test": "npm run lint && npm run test:unit"
@@ -168,7 +168,7 @@
168
168
  "devDependencies": {
169
169
  "@babel/eslint-parser": "^7.16.0",
170
170
  "@lando/leia": "^1.0.0-beta.4",
171
- "@lando/vitepress-theme-default-plus": "^1.1.0-beta.23",
171
+ "@lando/vitepress-theme-default-plus": "github:lando/vitepress-theme-default-plus#main",
172
172
  "@yao-pkg/pkg": "^5.16.1",
173
173
  "chai": "^4.3.4",
174
174
  "chai-as-promised": "^7.1.1",
@@ -247,9 +247,9 @@
247
247
  "yargs-parser"
248
248
  ],
249
249
  "dist": {
250
- "integrity": "sha512-6Xq72IhD1/1DBzarI6IEybpTykDn0k4Msia/Uwovg7sXRH+ML1DOnrPG8YvZyQVmPh2KBrsCVGkyfT57zJu80g==",
251
- "shasum": "66e479f5ab1a093a4d4e0a7709ac28a4c2b2b910",
252
- "filename": "florianpat-lando-core-3.23.7-compose.tgz",
253
- "unpackedSize": 60880860
250
+ "integrity": "sha512-h72uRffHk6XuEegs2pNU8qc1+jL8m0KE2jre+r8SEe7nCZH4ThEfay5XTj60VwrsAqen4YuqZaMgHXbY6kF3nw==",
251
+ "shasum": "9007ee7ef574b78df997a031740b1685f0420ec6",
252
+ "filename": "florianpat-lando-core-3.23.22-test1.tgz",
253
+ "unpackedSize": 60947194
254
254
  }
255
255
  }