Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: App builder bin 5.0 #8190

Merged
merged 44 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
43a499a
add dir into deps
Mar 13, 2024
3f46c23
add chmod
Mar 13, 2024
3d2a9ae
fix path
Mar 13, 2024
5575b5e
update app-buidler
Mar 13, 2024
cc8378b
update to 4.6
PayneFuRC Mar 14, 2024
af33a70
update to 4.6
Mar 14, 2024
e3ffafa
udpate 4.7
Mar 14, 2024
3cadd1a
update to 4.8
PayneFuRC Mar 16, 2024
b11bbde
update 4.9
PayneFuRC Mar 17, 2024
97cf700
update 4.9.1
PayneFuRC Mar 17, 2024
2469179
update 4.9.2
PayneFuRC Mar 17, 2024
432f784
add findLongestCommonDirectory
PayneFuRC Mar 17, 2024
bb59732
update snap
PayneFuRC Mar 17, 2024
4db6507
update 4.9.3
PayneFuRC Mar 17, 2024
e34edec
update 4.9.3
PayneFuRC Mar 17, 2024
9a216d1
update 4.9.4
PayneFuRC Mar 17, 2024
029d51e
add new dest
PayneFuRC Mar 19, 2024
4de03ee
update destination
PayneFuRC Mar 20, 2024
195f708
fix pnpm
PayneFuRC Mar 21, 2024
c582bfd
fix pnpm again
PayneFuRC Mar 21, 2024
713fa52
filter pnmp
PayneFuRC Mar 21, 2024
04c1201
fix pnpm
PayneFuRC Mar 22, 2024
1d3a0f5
update snap
PayneFuRC Mar 22, 2024
3880514
delete test log
PayneFuRC Mar 22, 2024
bd89bde
update all
Apr 6, 2024
c887ed5
udpate
Apr 6, 2024
1a30d36
udpate
Apr 6, 2024
7971db5
update version
Apr 7, 2024
0f059a2
update new
Apr 7, 2024
7281be5
udpate
Apr 7, 2024
274e898
fix ut
PayneFuRC Apr 8, 2024
b55b776
fix ut
PayneFuRC Apr 8, 2024
da185f6
update
PayneFuRC Apr 8, 2024
1cc7eec
fix ut
PayneFuRC Apr 8, 2024
e764b81
filter node_modules
PayneFuRC Apr 9, 2024
3c9084e
delete node-abi
PayneFuRC Apr 9, 2024
69eafbc
update
PayneFuRC Apr 9, 2024
243b7c7
update lf
PayneFuRC Apr 9, 2024
eea70a0
update
PayneFuRC Apr 9, 2024
4d8d803
update to v5.0.0-alpha.3
PayneFuRC May 1, 2024
b771930
Merge branch 'master' into app-builder-new
PayneFuRC May 7, 2024
e2fd9ee
Merge branch 'master' into app-builder-new
May 20, 2024
33ea866
Merge branch 'master' into app-builder-new
PayneFuRC May 22, 2024
2cd2b39
Create brave-rats-tap.md
mmaietta May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/brave-rats-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"app-builder-lib": minor
"builder-util": minor
---

feat: update app-builder-bin to 5.0-alpha release
6 changes: 3 additions & 3 deletions packages/app-builder-lib/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ProtonFramework } from "./ProtonFramework"
import { computeArchToTargetNamesMap, createTargets, NoOpTarget } from "./targets/targetFactory"
import { computeDefaultAppDirectory, getConfig, validateConfiguration } from "./util/config"
import { expandMacro } from "./util/macroExpander"
import { createLazyProductionDeps, NodeModuleDirInfo } from "./util/packageDependencies"
import { createLazyProductionDeps, NodeModuleDirInfo, NodeModuleInfo } from "./util/packageDependencies"
import { checkMetadata, readPackageJson } from "./util/packageMetadata"
import { getRepositoryInfo } from "./util/repositoryInfo"
import { installOrRebuild, nodeGypRebuild } from "./util/yarn"
Expand Down Expand Up @@ -119,7 +119,7 @@ export class Packager {

private nodeDependencyInfo = new Map<string, Lazy<Array<any>>>()

getNodeDependencyInfo(platform: Platform | null): Lazy<Array<NodeModuleDirInfo>> {
getNodeDependencyInfo(platform: Platform | null): Lazy<Array<NodeModuleInfo | NodeModuleDirInfo>> {
let key = ""
let excludedDependencies: Array<string> | null = null
if (platform != null && this.framework.getExcludedDependencies != null) {
Expand Down Expand Up @@ -529,7 +529,7 @@ export class Packager {
frameworkInfo,
platform: platform.nodeName,
arch: Arch[arch],
productionDeps: this.getNodeDependencyInfo(null),
productionDeps: this.getNodeDependencyInfo(null) as Lazy<Array<NodeModuleDirInfo>>,
})
}
}
Expand Down
156 changes: 78 additions & 78 deletions packages/app-builder-lib/src/util/NodeModuleCopyHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { excludedNames, FileMatcher } from "../fileMatcher"
import { Packager } from "../packager"
import { resolveFunction } from "../platformPackager"
import { FileCopyHelper } from "./AppFileWalker"
import { NodeModuleInfo } from "./packageDependencies"

const excludedFiles = new Set(
[".DS_Store", "node_modules" /* already in the queue */, "CHANGELOG.md", "ChangeLog", "changelog.md", "Changelog.md", "Changelog", "binding.gyp", ".npmignore"].concat(
Expand Down Expand Up @@ -37,108 +38,107 @@ export class NodeModuleCopyHelper extends FileCopyHelper {
super(matcher, matcher.isEmpty() ? null : matcher.createFilter(), packager)
}

async collectNodeModules(baseDir: string, moduleNames: Iterable<string>, nodeModuleExcludedExts: Array<string>): Promise<Array<string>> {
async collectNodeModules(moduleInfo: NodeModuleInfo, nodeModuleExcludedExts: Array<string>): Promise<Array<string>> {
const filter = this.filter
const metadata = this.metadata

const onNodeModuleFile = await resolveFunction(this.packager.appInfo.type, this.packager.config.onNodeModuleFile, "onNodeModuleFile")

const result: Array<string> = []
const queue: Array<string> = []
for (const moduleName of moduleNames) {
const tmpPath = baseDir + path.sep + moduleName
queue.length = 1
// The path should be corrected in Windows that when the moduleName is Scoped packages named.
const depPath = path.normalize(tmpPath)
queue[0] = depPath

while (queue.length > 0) {
const dirPath = queue.pop()!

const childNames = await readdir(dirPath)
childNames.sort()

const isTopLevel = dirPath === depPath
const dirs: Array<string> = []
// our handler is async, but we should add sorted files, so, we add file to result not in the mapper, but after map
const sortedFilePaths = await BluebirdPromise.map(
childNames,
name => {
const filePath = dirPath + path.sep + name

const forceIncluded = onNodeModuleFile != null && !!onNodeModuleFile(filePath)

if (excludedFiles.has(name) || name.startsWith("._")) {
return null
}

if (!forceIncluded) {
for (const ext of nodeModuleExcludedExts) {
if (name.endsWith(ext)) {
return null
}
}
const tmpPath = moduleInfo.dir
const moduleName = moduleInfo.name
queue.length = 1
// The path should be corrected in Windows that when the moduleName is Scoped packages named.
const depPath = path.normalize(tmpPath)
queue[0] = depPath

while (queue.length > 0) {
const dirPath = queue.pop()!

const childNames = await readdir(dirPath)
childNames.sort()

const isTopLevel = dirPath === depPath
const dirs: Array<string> = []
// our handler is async, but we should add sorted files, so, we add file to result not in the mapper, but after map
const sortedFilePaths = await BluebirdPromise.map(
childNames,
name => {
const filePath = dirPath + path.sep + name

const forceIncluded = onNodeModuleFile != null && !!onNodeModuleFile(filePath)

if (excludedFiles.has(name) || name.startsWith("._")) {
return null
}

// noinspection SpellCheckingInspection
if (isTopLevel && (topLevelExcludedFiles.has(name) || (moduleName === "libui-node" && (name === "build" || name === "docs" || name === "src")))) {
if (!forceIncluded) {
for (const ext of nodeModuleExcludedExts) {
if (name.endsWith(ext)) {
return null
}
}

if (dirPath.endsWith("build")) {
if (name === "gyp-mac-tool" || name === "Makefile" || name.endsWith(".mk") || name.endsWith(".gypi") || name.endsWith(".Makefile")) {
return null
}
} else if (dirPath.endsWith("Release") && (name === ".deps" || name === "obj.target")) {
return null
} else if (name === "src" && (dirPath.endsWith("keytar") || dirPath.endsWith("keytar-prebuild"))) {
return null
} else if (dirPath.endsWith("lzma-native") && (name === "build" || name === "deps")) {
return null
}
// noinspection SpellCheckingInspection
if (isTopLevel && (topLevelExcludedFiles.has(name) || (moduleName === "libui-node" && (name === "build" || name === "docs" || name === "src")))) {
return null
}

return lstat(filePath).then(stat => {
if (filter != null && !filter(filePath, stat)) {
if (dirPath.endsWith("build")) {
if (name === "gyp-mac-tool" || name === "Makefile" || name.endsWith(".mk") || name.endsWith(".gypi") || name.endsWith(".Makefile")) {
return null
}
} else if (dirPath.endsWith("Release") && (name === ".deps" || name === "obj.target")) {
return null
} else if (name === "src" && (dirPath.endsWith("keytar") || dirPath.endsWith("keytar-prebuild"))) {
return null
} else if (dirPath.endsWith("lzma-native") && (name === "build" || name === "deps")) {
return null
}
}

if (!stat.isDirectory()) {
metadata.set(filePath, stat)
return lstat(filePath).then(stat => {
if (filter != null && !filter(filePath, stat)) {
return null
}

if (!stat.isDirectory()) {
metadata.set(filePath, stat)
}
const consumerResult = this.handleFile(filePath, dirPath, stat)
if (consumerResult == null) {
if (stat.isDirectory()) {
dirs.push(name)
return null
} else {
return filePath
}
const consumerResult = this.handleFile(filePath, dirPath, stat)
if (consumerResult == null) {
if (stat.isDirectory()) {
} else {
return consumerResult.then(it => {
// asarUtil can return modified stat (symlink handling)
if ((it == null ? stat : it).isDirectory()) {
dirs.push(name)
return null
} else {
return filePath
}
} else {
return consumerResult.then(it => {
// asarUtil can return modified stat (symlink handling)
if ((it == null ? stat : it).isDirectory()) {
dirs.push(name)
return null
} else {
return filePath
}
})
}
})
},
CONCURRENCY
)

for (const child of sortedFilePaths) {
if (child != null) {
result.push(child)
}
})
}
})
},
CONCURRENCY
)

for (const child of sortedFilePaths) {
if (child != null) {
result.push(child)
}
}

dirs.sort()
for (const child of dirs) {
queue.push(dirPath + path.sep + child)
}
dirs.sort()
for (const child of dirs) {
queue.push(dirPath + path.sep + child)
}
}
return result
Expand Down
68 changes: 49 additions & 19 deletions packages/app-builder-lib/src/util/appFileCopier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,37 @@ import { Packager } from "../packager"
import { PlatformPackager } from "../platformPackager"
import { AppFileWalker } from "./AppFileWalker"
import { NodeModuleCopyHelper } from "./NodeModuleCopyHelper"
import { NodeModuleInfo } from "./packageDependencies"

const BOWER_COMPONENTS_PATTERN = `${path.sep}bower_components${path.sep}`
/** @internal */
export const ELECTRON_COMPILE_SHIM_FILENAME = "__shim.js"

function extractPathAfterLastNodeModules(src: string, file: string) {
const srcComponents = src.split(path.sep)
const lastNodeModulesIndex = srcComponents.lastIndexOf("node_modules")

if (lastNodeModulesIndex === -1 || lastNodeModulesIndex === srcComponents.length - 1) {
return ""
}

const pathAfterNodeModules = srcComponents.slice(lastNodeModulesIndex + 1).join(path.sep)

const matchIndex = file.indexOf(pathAfterNodeModules)

if (matchIndex === -1) {
return ""
}

const remainingPathStartIndex = matchIndex + pathAfterNodeModules.length
if (remainingPathStartIndex >= file.length) {
return ""
}

const remainingPath = file.substring(remainingPathStartIndex).trim()
return remainingPath.startsWith(path.sep) ? remainingPath.substring(1) : remainingPath
}

export function getDestinationPath(file: string, fileSet: ResolvedFileSet) {
if (file === fileSet.src) {
return fileSet.destination
Expand All @@ -27,17 +53,8 @@ export function getDestinationPath(file: string, fileSet: ResolvedFileSet) {
if (file.length > src.length && file.startsWith(src) && file[src.length] === path.sep) {
return dest + file.substring(src.length)
} else {
// hoisted node_modules
// not lastIndexOf, to ensure that nested module (top-level module depends on) copied to parent node_modules, not to top-level directory
// project https://github.com/angexis/punchcontrol/commit/cf929aba55c40d0d8901c54df7945e1d001ce022
let index = file.indexOf(NODE_MODULES_PATTERN)
if (index < 0 && file.endsWith(`${path.sep}node_modules`)) {
index = file.length - 13
}
if (index < 0) {
throw new Error(`File "${file}" not under the source directory "${fileSet.src}"`)
}
return dest + file.substring(index)
const e = extractPathAfterLastNodeModules(src, file)
return path.join(dest, e)
}
}
}
Expand Down Expand Up @@ -191,25 +208,38 @@ function validateFileSet(fileSet: ResolvedFileSet): ResolvedFileSet {

/** @internal */
export async function computeNodeModuleFileSets(platformPackager: PlatformPackager<any>, mainMatcher: FileMatcher): Promise<Array<ResolvedFileSet>> {
const deps = await platformPackager.info.getNodeDependencyInfo(platformPackager.platform).value
const deps = (await platformPackager.info.getNodeDependencyInfo(platformPackager.platform).value) as Array<NodeModuleInfo>

const nodeModuleExcludedExts = getNodeModuleExcludedExts(platformPackager)
// serial execution because copyNodeModules is concurrent and so, no need to increase queue/pressure
const result = new Array<ResolvedFileSet>()
let index = 0
for (const info of deps) {
const source = info.dir
const source = platformPackager.info.appDir + path.sep + "node_modules" + path.sep + info.name
// const source = platformPackager.info.appDir
const destination = getDestinationPath(source, { src: mainMatcher.from, destination: mainMatcher.to, files: [], metadata: null as any })

// use main matcher patterns, so, user can exclude some files in such hoisted node modules
// source here includes node_modules, but pattern base should be without because users expect that pattern "!node_modules/loot-core/src{,/**/*}" will work
const matcher = new FileMatcher(path.dirname(source), destination, mainMatcher.macroExpander, mainMatcher.patterns)
const matcher = new FileMatcher(path.dirname(platformPackager.info.appDir + path.sep + "node_modules"), destination, mainMatcher.macroExpander, mainMatcher.patterns)
const copier = new NodeModuleCopyHelper(matcher, platformPackager.info)
const files = await copier.collectNodeModules(
source,
info.deps.map(it => it.name),
nodeModuleExcludedExts
)
const files = await copier.collectNodeModules(info, nodeModuleExcludedExts)
result[index++] = validateFileSet({ src: source, destination, files, metadata: copier.metadata })

if (info.conflictDependency) {
for (const dep of info.conflictDependency) {
const source = platformPackager.info.appDir + path.sep + "node_modules" + path.sep + info.name + path.sep + "node_modules" + path.sep + dep.name
const destination = getDestinationPath(source, { src: mainMatcher.from, destination: mainMatcher.to, files: [], metadata: null as any })
const matcher = new FileMatcher(
path.dirname(platformPackager.info.appDir + path.sep + "node_modules" + path.sep + info.name + path.sep + "node_modules"),
destination,
mainMatcher.macroExpander,
mainMatcher.patterns
)
const copier = new NodeModuleCopyHelper(matcher, platformPackager.info)
result[index++] = validateFileSet({ src: source, destination, files: await copier.collectNodeModules(dep, nodeModuleExcludedExts), metadata: copier.metadata })
}
}
}
return result
}
Expand Down
5 changes: 4 additions & 1 deletion packages/app-builder-lib/src/util/packageDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { executeAppBuilderAsJson } from "./appBuilder"

export function createLazyProductionDeps(projectDir: string, excludedDependencies: Array<string> | null) {
return new Lazy(async () => {
const args = ["node-dep-tree", "--dir", projectDir]
const args = ["node-dep-tree", "--flatten", "--dir", projectDir]
if (excludedDependencies != null) {
for (const name of excludedDependencies) {
args.push("--exclude-dep", name)
Expand All @@ -20,4 +20,7 @@ export interface NodeModuleDirInfo {

export interface NodeModuleInfo {
readonly name: string
readonly version: string
readonly dir: string
readonly conflictDependency: Array<NodeModuleInfo>
}
2 changes: 1 addition & 1 deletion packages/builder-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"7zip-bin": "~5.2.0",
"@types/debug": "^4.1.6",
"app-builder-bin": "4.0.0",
"app-builder-bin": "v5.0.0-alpha.3",
"bluebird-lst": "^1.0.9",
"builder-util-runtime": "workspace:*",
"chalk": "^4.1.2",
Expand Down
Loading
Loading