Skip to content

Commit cde9845

Browse files
committed
feat: Support for sibling packages (lerna + yarn workspaces)
Close #2222
1 parent cfec5c6 commit cde9845

File tree

4 files changed

+69
-37
lines changed

4 files changed

+69
-37
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"docker-images": "docker/build.sh",
1616
"update-deps": "npm-check-updates -a -x gitbook-plugin-github,chalk && node ./scripts/update-deps.js",
1717
"set-versions": "node test/out/helpers/setVersions.js",
18-
"release": "yarn set-versions && yarn compile && sh ./__publish.sh && conventional-changelog -p angular -i CHANGELOG.md -s",
18+
"release": "BABEL_ENV=production yarn set-versions && yarn compile && sh ./__publish.sh && conventional-changelog -p angular -i CHANGELOG.md -s",
1919
"schema": "typescript-json-schema packages/electron-builder-lib/tsconfig.json Configuration --out packages/electron-builder-lib/scheme.json --noExtraProps --useTypeOfKeyword --strictNullChecks --titles --required",
2020
"jsdoc": "ts2jsdoc packages/builder-util-runtime packages/electron-updater packages/builder-util packages/electron-builder-lib packages/electron-builder packages/electron-publish",
2121
"jsdoc2md": "node scripts/jsdoc2md.js",
@@ -83,7 +83,7 @@
8383
"@types/semver": "^5.5.0",
8484
"@types/source-map-support": "^0.4.0",
8585
"@types/stat-mode": "^0.2.0",
86-
"babel-preset-ts-node6-bluebird": "^2.0.1",
86+
"babel-preset-ts-node6-bluebird": "^2.0.3",
8787
"convert-source-map": "^1.5.1",
8888
"decompress-zip": "^0.3.0",
8989
"depcheck": "^0.6.9",
@@ -100,7 +100,7 @@
100100
"jest-junit": "^3.6.0",
101101
"jsdoc-to-markdown": "^4.0.1",
102102
"path-sort": "^0.1.0",
103-
"ts-babel": "^5.0.1",
103+
"ts-babel": "^5.0.2",
104104
"ts-jsdoc": "^3.0.0",
105105
"tslint": "^5.9.1",
106106
"typescript": "2.7.2",

packages/electron-builder-lib/src/util/AppFileCopierHelper.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export async function computeFileSets(matchers: Array<FileMatcher>, transformer:
7979
return false
8080
}, CONCURRENCY)
8181

82-
fileSets.push({src: matcher.from, files, metadata, transformedFiles, destination: matcher.to})
82+
fileSets.push(validateFileSet({src: matcher.from, files, metadata, transformedFiles, destination: matcher.to}))
8383
}
8484

8585
if (isElectronCompile) {
@@ -92,11 +92,23 @@ export async function computeFileSets(matchers: Array<FileMatcher>, transformer:
9292
return fileSets
9393
}
9494

95+
function validateFileSet(fileSet: ResolvedFileSet): ResolvedFileSet {
96+
if (fileSet.src == null || fileSet.src.length === 0) {
97+
throw new Error("fileset src is empty")
98+
}
99+
return fileSet
100+
}
101+
95102
async function copyHoistedNodeModules(packager: Packager, mainMatcher: FileMatcher): Promise<Array<ResolvedFileSet>> {
96103
const productionDeps = await packager.productionDeps.value
97104
const rootPathToCopier = new Map<string, Array<Dependency>>()
98105
for (const dep of productionDeps) {
99-
const root = dep.path.substring(0, dep.path.indexOf(NODE_MODULES_PATTERN))
106+
const index = dep.path.indexOf(NODE_MODULES_PATTERN)
107+
if (index < 0) {
108+
throw new Error("cannot find node_modules in the path " + dep.path)
109+
}
110+
111+
const root = dep.path.substring(0, index)
100112
let list = rootPathToCopier.get(root)
101113
if (list == null) {
102114
list = []
@@ -111,7 +123,7 @@ async function copyHoistedNodeModules(packager: Packager, mainMatcher: FileMatch
111123
const matcher = new FileMatcher(source, mainMatcher.to, mainMatcher.macroExpander, mainMatcher.patterns)
112124
const copier = new NodeModuleCopyHelper(matcher, packager)
113125
const files = await copier.collectNodeModules(rootPathToCopier.get(source)!!)
114-
return {src: matcher.from, destination: matcher.to, files, metadata: copier.metadata}
126+
return validateFileSet({src: matcher.from, destination: matcher.to, files, metadata: copier.metadata})
115127
})
116128
}
117129

packages/electron-builder-lib/src/util/packageDependencies.ts

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ export function createLazyProductionDeps(projectDir: string) {
4242

4343
/** @internal */
4444
export async function getProductionDependencies(folder: string): Promise<Array<Dependency>> {
45-
const sorted: Array<Dependency> = []
46-
computeSortedPaths(await new Collector().collect(folder), sorted, false)
47-
return sorted
45+
const result: Array<Dependency> = []
46+
computeSortedPaths(await new Collector().collect(folder), result, false)
47+
return result
4848
}
4949

5050
const ignoredProperties = new Set(["description", "author", "bugs", "engines", "repository", "build", "main", "license", "homepage", "scripts", "maintainers", "contributors", "keywords", "devDependencies", "files", "typings", "types", "xo", "resolutions"])
@@ -78,13 +78,13 @@ class Collector {
7878
this.unmarkExtraneous(rootDependency)
7979

8080
if (this.unresolved.size > 0) {
81-
log.debug({unresolved: Array.from(this.unresolved.keys()).join(", ")}, "Unresolved dependencies after first round")
81+
log.debug({unresolved: Array.from(this.unresolved.keys()).join(", ")}, "unresolved dependencies after first round")
8282
await this.resolveUnresolvedHoisted(rootDependency, dir)
8383
}
8484
return rootDependency
8585
}
8686

87-
private async resolveUnresolvedHoisted(rootDependency: Dependency, dir: string) {
87+
private async resolveUnresolvedHoisted(rootDependency: Dependency, dir: string): Promise<void> {
8888
let nameToMetadata = rootDependency.dependencies
8989
if (nameToMetadata == null) {
9090
rootDependency.dependencies = new Map<string, Dependency>()
@@ -112,30 +112,50 @@ class Collector {
112112
const parentNodeModulesDir = parentDir + path.sep + "node_modules"
113113
const dirStat = await statOrNull(parentNodeModulesDir)
114114
if (dirStat == null || !dirStat.isDirectory()) {
115-
continue
115+
if (dirStat == null || !dirStat.isDirectory()) {
116+
continue
117+
}
116118
}
117119

118-
const unresolved = Array.from(this.unresolved.keys())
119-
this.unresolved.clear()
120-
121-
const resolved = await BluebirdPromise.map(unresolved, it => {
122-
return this.readChildPackage(it, parentNodeModulesDir, rootDependency)
123-
.catch(e => {
124-
if ((e as any).code === "ENOENT") {
125-
return null
126-
}
127-
else {
128-
throw e
129-
}
130-
})
131-
}, CONCURRENCY)
132-
for (const dep of resolved) {
133-
if (dep != null) {
134-
nameToMetadata.set(dep.realName, dep)
120+
// https://github.com/electron-userland/electron-builder/issues/2222#issuecomment-339060335
121+
// step 1: resolve current unresolved
122+
// step n: try to resolve new unresolved in the same parent dir until at least something is resolved in the dir
123+
while (true) {
124+
const unresolved = Array.from(this.unresolved.keys())
125+
this.unresolved.clear()
126+
127+
const resolved = await BluebirdPromise.map(unresolved, it => {
128+
return this.readChildPackage(it, parentNodeModulesDir, rootDependency)
129+
.catch(e => {
130+
if ((e as any).code === "ENOENT") {
131+
return null
132+
}
133+
else {
134+
throw e
135+
}
136+
})
137+
}, CONCURRENCY)
138+
139+
let hasResolved = false
140+
141+
for (const dep of resolved) {
142+
if (dep != null) {
143+
hasResolved = true
144+
this.unmarkExtraneous(dep)
145+
nameToMetadata.set(dep.realName, dep)
146+
}
135147
}
136-
}
137148

138-
this.unmarkExtraneous(rootDependency)
149+
if (!hasResolved) {
150+
break
151+
}
152+
153+
this.unmarkExtraneous(rootDependency)
154+
155+
if (this.unresolved.size === 0) {
156+
return
157+
}
158+
}
139159
}
140160
while (this.unresolved.size > 0)
141161
}

yarn.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -794,9 +794,9 @@ babel-preset-jest@^23.0.0-alpha.0:
794794
babel-plugin-jest-hoist "^23.0.0-alpha.0"
795795
babel-plugin-syntax-object-rest-spread "^6.13.0"
796796

797-
babel-preset-ts-node6-bluebird@^2.0.1:
798-
version "2.0.1"
799-
resolved "https://registry.yarnpkg.com/babel-preset-ts-node6-bluebird/-/babel-preset-ts-node6-bluebird-2.0.1.tgz#846f137112e0f8c0fca76dda696d8bd64e9be25e"
797+
babel-preset-ts-node6-bluebird@^2.0.3:
798+
version "2.0.3"
799+
resolved "https://registry.yarnpkg.com/babel-preset-ts-node6-bluebird/-/babel-preset-ts-node6-bluebird-2.0.3.tgz#d246288f9261f93ec0812e757aa217554ff020ae"
800800
dependencies:
801801
"@babel/helper-plugin-utils" "^7.0.0-beta.42"
802802
"@babel/plugin-transform-modules-commonjs" "^7.0.0-beta.42"
@@ -5615,9 +5615,9 @@ truncate-utf8-bytes@^1.0.0:
56155615
dependencies:
56165616
utf8-byte-length "^1.0.1"
56175617

5618-
ts-babel@^5.0.1:
5619-
version "5.0.1"
5620-
resolved "https://registry.yarnpkg.com/ts-babel/-/ts-babel-5.0.1.tgz#0b096306ff3180704441bdeecd61b51b37b8c434"
5618+
ts-babel@^5.0.2:
5619+
version "5.0.2"
5620+
resolved "https://registry.yarnpkg.com/ts-babel/-/ts-babel-5.0.2.tgz#fefeb9a26ca5e6195fde67961665a4e27d9cada0"
56215621
dependencies:
56225622
"@babel/core" "^7.0.0-beta.42"
56235623
bluebird-lst "^1.0.5"

0 commit comments

Comments
 (0)