cross-packer 0.1.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 (126) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +151 -0
  3. package/README.zh-CN.md +151 -0
  4. package/dist/archive/ar.d.ts +12 -0
  5. package/dist/archive/seven-za.d.ts +32 -0
  6. package/dist/archive/tar.d.ts +30 -0
  7. package/dist/archive/zip-reader.d.ts +17 -0
  8. package/dist/asar/dependency/collect.d.ts +2 -0
  9. package/dist/asar/dependency/detector.d.ts +8 -0
  10. package/dist/asar/dependency/hoister.d.ts +27 -0
  11. package/dist/asar/dependency/utils.d.ts +59 -0
  12. package/dist/asar/fileset/matcher.d.ts +12 -0
  13. package/dist/asar/fileset/platform-fileset.d.ts +36 -0
  14. package/dist/asar/fileset/transformer.d.ts +2 -0
  15. package/dist/asar/fileset/unpack-detector.d.ts +10 -0
  16. package/dist/asar/fileset/walker.d.ts +14 -0
  17. package/dist/asar/pack.d.ts +23 -0
  18. package/dist/asar/packer/app-collector.d.ts +2 -0
  19. package/dist/asar/packer/collector.d.ts +18 -0
  20. package/dist/asar/packer/concurrency.d.ts +1 -0
  21. package/dist/asar/packer/integrity.d.ts +8 -0
  22. package/dist/asar/packer/nm-collector.d.ts +7 -0
  23. package/dist/asar/packer/stream-builder.d.ts +18 -0
  24. package/dist/cli.d.ts +2 -0
  25. package/dist/config/index.d.ts +97 -0
  26. package/dist/electron/dist-zip.d.ts +18 -0
  27. package/dist/electron/download.d.ts +21 -0
  28. package/dist/index.d.ts +11 -0
  29. package/dist/packer/common/app-update-yml.d.ts +5 -0
  30. package/dist/packer/common/extra-resources.d.ts +39 -0
  31. package/dist/packer/common/staging.d.ts +3 -0
  32. package/dist/packer/common/template.d.ts +2 -0
  33. package/dist/packer/linux/linux.d.ts +2 -0
  34. package/dist/packer/mac/mac.d.ts +23 -0
  35. package/dist/packer/win/nsis.d.ts +24 -0
  36. package/dist/packer/win/resedit.d.ts +5 -0
  37. package/dist/packer/win/toolchain.d.ts +8 -0
  38. package/dist/packer/win/win.d.ts +12 -0
  39. package/dist/pipeline/pipeline.d.ts +41 -0
  40. package/dist/pipeline/targets.d.ts +28 -0
  41. package/dist/shared/hash.d.ts +2 -0
  42. package/dist/shared/logger.d.ts +39 -0
  43. package/dist/shared/platform.d.ts +26 -0
  44. package/dist/shared/types.d.ts +68 -0
  45. package/dist/update/blockmap.d.ts +13 -0
  46. package/dist/update/metadata.d.ts +20 -0
  47. package/dist/update/version.d.ts +7 -0
  48. package/package.json +71 -0
  49. package/src/archive/ar.ts +41 -0
  50. package/src/archive/seven-za.ts +160 -0
  51. package/src/archive/tar.ts +142 -0
  52. package/src/archive/zip-reader.ts +61 -0
  53. package/src/asar/dependency/collect.ts +437 -0
  54. package/src/asar/dependency/detector.ts +73 -0
  55. package/src/asar/dependency/hoister.ts +714 -0
  56. package/src/asar/dependency/utils.ts +225 -0
  57. package/src/asar/fileset/matcher.ts +101 -0
  58. package/src/asar/fileset/platform-fileset.ts +416 -0
  59. package/src/asar/fileset/transformer.ts +154 -0
  60. package/src/asar/fileset/unpack-detector.ts +38 -0
  61. package/src/asar/fileset/walker.ts +115 -0
  62. package/src/asar/pack.ts +186 -0
  63. package/src/asar/packer/app-collector.ts +74 -0
  64. package/src/asar/packer/collector.ts +134 -0
  65. package/src/asar/packer/concurrency.ts +24 -0
  66. package/src/asar/packer/integrity.ts +53 -0
  67. package/src/asar/packer/nm-collector.ts +194 -0
  68. package/src/asar/packer/stream-builder.ts +723 -0
  69. package/src/cli.ts +182 -0
  70. package/src/config/index.ts +365 -0
  71. package/src/electron/dist-zip.ts +65 -0
  72. package/src/electron/download.ts +121 -0
  73. package/src/index.ts +14 -0
  74. package/src/packer/common/app-update-yml.ts +21 -0
  75. package/src/packer/common/extra-resources.ts +83 -0
  76. package/src/packer/common/staging.ts +33 -0
  77. package/src/packer/common/template.ts +24 -0
  78. package/src/packer/linux/linux.ts +329 -0
  79. package/src/packer/mac/mac.ts +495 -0
  80. package/src/packer/win/nsis.ts +244 -0
  81. package/src/packer/win/resedit.ts +60 -0
  82. package/src/packer/win/toolchain.ts +63 -0
  83. package/src/packer/win/win.ts +421 -0
  84. package/src/pipeline/pipeline.ts +149 -0
  85. package/src/pipeline/targets.ts +67 -0
  86. package/src/shared/hash.ts +15 -0
  87. package/src/shared/logger.ts +91 -0
  88. package/src/shared/platform.ts +41 -0
  89. package/src/shared/types.ts +82 -0
  90. package/src/update/blockmap.ts +247 -0
  91. package/src/update/metadata.ts +97 -0
  92. package/src/update/version.ts +59 -0
  93. package/templates/linux/app.desktop +11 -0
  94. package/templates/linux/control +9 -0
  95. package/templates/linux/postinst +10 -0
  96. package/templates/linux/postrm +8 -0
  97. package/templates/linux/preinst +49 -0
  98. package/templates/linux/prerm +43 -0
  99. package/templates/mac/Info.plist +18 -0
  100. package/templates/mac/app-update.yml +4 -0
  101. package/templates/win/nsis/README.md +51 -0
  102. package/templates/win/nsis/THIRD-PARTY-NOTICES.md +20 -0
  103. package/templates/win/nsis/assistedInstaller.nsh +154 -0
  104. package/templates/win/nsis/assistedMessages.yml +368 -0
  105. package/templates/win/nsis/common.nsh +147 -0
  106. package/templates/win/nsis/empty-license.txt +1 -0
  107. package/templates/win/nsis/include/FileAssociation.nsh +123 -0
  108. package/templates/win/nsis/include/StdUtils.nsh +496 -0
  109. package/templates/win/nsis/include/StrContains.nsh +48 -0
  110. package/templates/win/nsis/include/UAC.nsh +299 -0
  111. package/templates/win/nsis/include/allowOnlyOneInstallerInstance.nsh +164 -0
  112. package/templates/win/nsis/include/extractAppPackage.nsh +138 -0
  113. package/templates/win/nsis/include/getProcessInfo.nsh +157 -0
  114. package/templates/win/nsis/include/installUtil.nsh +248 -0
  115. package/templates/win/nsis/include/installer.nsh +247 -0
  116. package/templates/win/nsis/include/nsProcess.nsh +28 -0
  117. package/templates/win/nsis/include/webPackage.nsh +64 -0
  118. package/templates/win/nsis/installSection.nsh +110 -0
  119. package/templates/win/nsis/installer.nsi +132 -0
  120. package/templates/win/nsis/messages.yml +240 -0
  121. package/templates/win/nsis/multiUser.nsh +134 -0
  122. package/templates/win/nsis/multiUserUi.nsh +230 -0
  123. package/templates/win/nsis/oneClick.nsh +19 -0
  124. package/templates/win/nsis/portable.nsi +91 -0
  125. package/templates/win/nsis/uninstaller.nsh +263 -0
  126. package/templates/win/nsis-header.nsh +57 -0
@@ -0,0 +1,194 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import fsExtra from 'fs-extra'
4
+ import { NodePlatform } from '../../shared/platform.ts'
5
+ import {
6
+ EntryKind,
7
+ entryKind,
8
+ type FileFilter,
9
+ type FileStat,
10
+ type FileVisitor,
11
+ } from '../../shared/types.ts'
12
+ import { excludedExts, excludedFiles, topLevelExcludedFiles } from '../fileset/matcher.ts'
13
+
14
+ export function getNodeModuleExcludedExts(platform: NodePlatform, includePdb: boolean): string[] {
15
+ const result = ['.o', '.obj'].concat(excludedExts.split(',').map((it) => `.${it}`))
16
+ if (includePdb !== true) {
17
+ result.push('.pdb')
18
+ }
19
+ if (platform !== NodePlatform.WIN32) {
20
+ result.push('.dll')
21
+ result.push('.exe')
22
+ }
23
+ return result
24
+ }
25
+
26
+ export async function collectNodeModuleFiles(
27
+ moduleDir: string,
28
+ moduleName: string,
29
+ moduleRootPath: string,
30
+ platform: NodePlatform,
31
+ includePdb: boolean,
32
+ disableDefaultIgnoredFiles: boolean,
33
+ filter: FileFilter | undefined = undefined,
34
+ onNodeModuleFile: FileVisitor | undefined = undefined,
35
+ ): Promise<{ files: string[]; metadata: Map<string, FileStat> }> {
36
+ const nodeModuleExcludedExts = getNodeModuleExcludedExts(platform, includePdb)
37
+ const metadata = new Map<string, FileStat>()
38
+ const result: (string | undefined)[] = []
39
+ const queue: string[] = []
40
+ const emptyDirs = new Set<string>()
41
+ const symlinkFiles = new Map<string, number>()
42
+ const depPath = path.normalize(moduleDir)
43
+ queue.push(depPath)
44
+
45
+ while (queue.length > 0) {
46
+ const dirPath = queue.pop()
47
+ if (dirPath === undefined) continue
48
+ let childNames: string[]
49
+ try {
50
+ childNames = await fsExtra.readdir(dirPath)
51
+ } catch {
52
+ continue
53
+ }
54
+ childNames.sort()
55
+ const isTopLevel = dirPath === depPath
56
+ const dirs: string[] = []
57
+ let isEmpty = true
58
+
59
+ for (const name of childNames) {
60
+ const filePath = path.join(dirPath, name)
61
+ const forceIncluded = onNodeModuleFile != null && !!onNodeModuleFile(filePath)
62
+ if (excludedFiles.has(name) || name.startsWith('._')) {
63
+ if (!forceIncluded) continue
64
+ }
65
+ const dirStat = await fsExtra.lstat(dirPath).catch(() => null)
66
+ const dirKind = dirStat != null ? entryKind(dirStat) : null
67
+ const fileMatched =
68
+ filter != null && dirStat != null && dirKind !== null
69
+ ? filter(dirPath, { type: dirKind, size: dirStat.size, mode: dirStat.mode })
70
+ : false
71
+ if (!fileMatched || !forceIncluded || disableDefaultIgnoredFiles) {
72
+ let excluded = false
73
+ for (const ext of nodeModuleExcludedExts) {
74
+ if (name.endsWith(ext)) {
75
+ excluded = true
76
+ break
77
+ }
78
+ }
79
+ if (excluded) continue
80
+ if (
81
+ isTopLevel &&
82
+ (topLevelExcludedFiles.has(name) ||
83
+ (moduleName === 'libui-node' &&
84
+ (name === 'build' || name === 'docs' || name === 'src')))
85
+ ) {
86
+ continue
87
+ }
88
+ if (dirPath.endsWith('build')) {
89
+ if (
90
+ name === 'gyp-mac-tool' ||
91
+ name === 'Makefile' ||
92
+ name.endsWith('.mk') ||
93
+ name.endsWith('.gypi') ||
94
+ name.endsWith('.Makefile')
95
+ ) {
96
+ continue
97
+ }
98
+ } else if (dirPath.endsWith('Release') && (name === '.deps' || name === 'obj.target')) {
99
+ continue
100
+ } else if (
101
+ name === 'src' &&
102
+ (dirPath.endsWith('keytar') || dirPath.endsWith('keytar-prebuild'))
103
+ ) {
104
+ continue
105
+ } else if (dirPath.endsWith('lzma-native') && (name === 'build' || name === 'deps')) {
106
+ continue
107
+ }
108
+ }
109
+
110
+ let lstat: fs.Stats
111
+ try {
112
+ lstat = await fsExtra.lstat(filePath)
113
+ } catch {
114
+ continue
115
+ }
116
+ const type = entryKind(lstat)
117
+ if (type === null) continue
118
+ const stat: FileStat = {
119
+ type,
120
+ size: lstat.size,
121
+ mode: lstat.mode,
122
+ moduleName,
123
+ moduleRootPath,
124
+ moduleFullFilePath: path.join(moduleRootPath, path.relative(depPath, filePath)),
125
+ }
126
+
127
+ if (filter != null && stat.type !== 'directory' && !filter(filePath, stat)) {
128
+ continue
129
+ }
130
+
131
+ if (stat.type === EntryKind.LINK) {
132
+ let linkTarget: string
133
+ try {
134
+ linkTarget = await fsExtra.readlink(filePath)
135
+ } catch {
136
+ continue
137
+ }
138
+ const resolvedLinkTarget = path.resolve(dirPath, linkTarget)
139
+ const link = path.relative(depPath, resolvedLinkTarget)
140
+ if (link.startsWith('..')) {
141
+ try {
142
+ const targetStat = await fsExtra.stat(resolvedLinkTarget)
143
+ const targetType = entryKind(targetStat)
144
+ if (targetType !== null) {
145
+ metadata.set(filePath, {
146
+ type: targetType,
147
+ size: targetStat.size,
148
+ mode: targetStat.mode,
149
+ })
150
+ result.push(filePath)
151
+ isEmpty = false
152
+ }
153
+ } catch {
154
+ // Skip broken external symlinks.
155
+ }
156
+ } else {
157
+ stat.relativeLink = link
158
+ stat.linkRelativeToFile = path.relative(dirPath, resolvedLinkTarget)
159
+ result.push(filePath)
160
+ symlinkFiles.set(filePath, result.length - 1)
161
+ isEmpty = false
162
+ }
163
+ } else if (stat.type === EntryKind.DIRECTORY) {
164
+ metadata.set(filePath, stat)
165
+ dirs.push(name)
166
+ isEmpty = false
167
+ } else {
168
+ metadata.set(filePath, stat)
169
+ result.push(filePath)
170
+ isEmpty = false
171
+ }
172
+ }
173
+ if (isEmpty) {
174
+ emptyDirs.add(dirPath)
175
+ }
176
+ dirs.sort()
177
+ for (const child of dirs) {
178
+ queue.push(dirPath + path.sep + child)
179
+ }
180
+ }
181
+
182
+ for (const [file, index] of symlinkFiles) {
183
+ let resolvedPath: string
184
+ try {
185
+ resolvedPath = fs.realpathSync(file)
186
+ } catch {
187
+ continue
188
+ }
189
+ if (emptyDirs.has(resolvedPath)) {
190
+ result[index] = undefined
191
+ }
192
+ }
193
+ return { files: result.filter((it): it is string => it !== undefined), metadata }
194
+ }