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.
- package/LICENSE +661 -0
- package/README.md +151 -0
- package/README.zh-CN.md +151 -0
- package/dist/archive/ar.d.ts +12 -0
- package/dist/archive/seven-za.d.ts +32 -0
- package/dist/archive/tar.d.ts +30 -0
- package/dist/archive/zip-reader.d.ts +17 -0
- package/dist/asar/dependency/collect.d.ts +2 -0
- package/dist/asar/dependency/detector.d.ts +8 -0
- package/dist/asar/dependency/hoister.d.ts +27 -0
- package/dist/asar/dependency/utils.d.ts +59 -0
- package/dist/asar/fileset/matcher.d.ts +12 -0
- package/dist/asar/fileset/platform-fileset.d.ts +36 -0
- package/dist/asar/fileset/transformer.d.ts +2 -0
- package/dist/asar/fileset/unpack-detector.d.ts +10 -0
- package/dist/asar/fileset/walker.d.ts +14 -0
- package/dist/asar/pack.d.ts +23 -0
- package/dist/asar/packer/app-collector.d.ts +2 -0
- package/dist/asar/packer/collector.d.ts +18 -0
- package/dist/asar/packer/concurrency.d.ts +1 -0
- package/dist/asar/packer/integrity.d.ts +8 -0
- package/dist/asar/packer/nm-collector.d.ts +7 -0
- package/dist/asar/packer/stream-builder.d.ts +18 -0
- package/dist/cli.d.ts +2 -0
- package/dist/config/index.d.ts +97 -0
- package/dist/electron/dist-zip.d.ts +18 -0
- package/dist/electron/download.d.ts +21 -0
- package/dist/index.d.ts +11 -0
- package/dist/packer/common/app-update-yml.d.ts +5 -0
- package/dist/packer/common/extra-resources.d.ts +39 -0
- package/dist/packer/common/staging.d.ts +3 -0
- package/dist/packer/common/template.d.ts +2 -0
- package/dist/packer/linux/linux.d.ts +2 -0
- package/dist/packer/mac/mac.d.ts +23 -0
- package/dist/packer/win/nsis.d.ts +24 -0
- package/dist/packer/win/resedit.d.ts +5 -0
- package/dist/packer/win/toolchain.d.ts +8 -0
- package/dist/packer/win/win.d.ts +12 -0
- package/dist/pipeline/pipeline.d.ts +41 -0
- package/dist/pipeline/targets.d.ts +28 -0
- package/dist/shared/hash.d.ts +2 -0
- package/dist/shared/logger.d.ts +39 -0
- package/dist/shared/platform.d.ts +26 -0
- package/dist/shared/types.d.ts +68 -0
- package/dist/update/blockmap.d.ts +13 -0
- package/dist/update/metadata.d.ts +20 -0
- package/dist/update/version.d.ts +7 -0
- package/package.json +71 -0
- package/src/archive/ar.ts +41 -0
- package/src/archive/seven-za.ts +160 -0
- package/src/archive/tar.ts +142 -0
- package/src/archive/zip-reader.ts +61 -0
- package/src/asar/dependency/collect.ts +437 -0
- package/src/asar/dependency/detector.ts +73 -0
- package/src/asar/dependency/hoister.ts +714 -0
- package/src/asar/dependency/utils.ts +225 -0
- package/src/asar/fileset/matcher.ts +101 -0
- package/src/asar/fileset/platform-fileset.ts +416 -0
- package/src/asar/fileset/transformer.ts +154 -0
- package/src/asar/fileset/unpack-detector.ts +38 -0
- package/src/asar/fileset/walker.ts +115 -0
- package/src/asar/pack.ts +186 -0
- package/src/asar/packer/app-collector.ts +74 -0
- package/src/asar/packer/collector.ts +134 -0
- package/src/asar/packer/concurrency.ts +24 -0
- package/src/asar/packer/integrity.ts +53 -0
- package/src/asar/packer/nm-collector.ts +194 -0
- package/src/asar/packer/stream-builder.ts +723 -0
- package/src/cli.ts +182 -0
- package/src/config/index.ts +365 -0
- package/src/electron/dist-zip.ts +65 -0
- package/src/electron/download.ts +121 -0
- package/src/index.ts +14 -0
- package/src/packer/common/app-update-yml.ts +21 -0
- package/src/packer/common/extra-resources.ts +83 -0
- package/src/packer/common/staging.ts +33 -0
- package/src/packer/common/template.ts +24 -0
- package/src/packer/linux/linux.ts +329 -0
- package/src/packer/mac/mac.ts +495 -0
- package/src/packer/win/nsis.ts +244 -0
- package/src/packer/win/resedit.ts +60 -0
- package/src/packer/win/toolchain.ts +63 -0
- package/src/packer/win/win.ts +421 -0
- package/src/pipeline/pipeline.ts +149 -0
- package/src/pipeline/targets.ts +67 -0
- package/src/shared/hash.ts +15 -0
- package/src/shared/logger.ts +91 -0
- package/src/shared/platform.ts +41 -0
- package/src/shared/types.ts +82 -0
- package/src/update/blockmap.ts +247 -0
- package/src/update/metadata.ts +97 -0
- package/src/update/version.ts +59 -0
- package/templates/linux/app.desktop +11 -0
- package/templates/linux/control +9 -0
- package/templates/linux/postinst +10 -0
- package/templates/linux/postrm +8 -0
- package/templates/linux/preinst +49 -0
- package/templates/linux/prerm +43 -0
- package/templates/mac/Info.plist +18 -0
- package/templates/mac/app-update.yml +4 -0
- package/templates/win/nsis/README.md +51 -0
- package/templates/win/nsis/THIRD-PARTY-NOTICES.md +20 -0
- package/templates/win/nsis/assistedInstaller.nsh +154 -0
- package/templates/win/nsis/assistedMessages.yml +368 -0
- package/templates/win/nsis/common.nsh +147 -0
- package/templates/win/nsis/empty-license.txt +1 -0
- package/templates/win/nsis/include/FileAssociation.nsh +123 -0
- package/templates/win/nsis/include/StdUtils.nsh +496 -0
- package/templates/win/nsis/include/StrContains.nsh +48 -0
- package/templates/win/nsis/include/UAC.nsh +299 -0
- package/templates/win/nsis/include/allowOnlyOneInstallerInstance.nsh +164 -0
- package/templates/win/nsis/include/extractAppPackage.nsh +138 -0
- package/templates/win/nsis/include/getProcessInfo.nsh +157 -0
- package/templates/win/nsis/include/installUtil.nsh +248 -0
- package/templates/win/nsis/include/installer.nsh +247 -0
- package/templates/win/nsis/include/nsProcess.nsh +28 -0
- package/templates/win/nsis/include/webPackage.nsh +64 -0
- package/templates/win/nsis/installSection.nsh +110 -0
- package/templates/win/nsis/installer.nsi +132 -0
- package/templates/win/nsis/messages.yml +240 -0
- package/templates/win/nsis/multiUser.nsh +134 -0
- package/templates/win/nsis/multiUserUi.nsh +230 -0
- package/templates/win/nsis/oneClick.nsh +19 -0
- package/templates/win/nsis/portable.nsi +91 -0
- package/templates/win/nsis/uninstaller.nsh +263 -0
- 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
|
+
}
|