Skip to content

Commit

Permalink
feat: Support for sibling packages (lerna + yarn workspaces)
Browse files Browse the repository at this point in the history
Close #2222
  • Loading branch information
develar committed Mar 17, 2018
1 parent cfec5c6 commit cde9845
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 37 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"docker-images": "docker/build.sh",
"update-deps": "npm-check-updates -a -x gitbook-plugin-github,chalk && node ./scripts/update-deps.js",
"set-versions": "node test/out/helpers/setVersions.js",
"release": "yarn set-versions && yarn compile && sh ./__publish.sh && conventional-changelog -p angular -i CHANGELOG.md -s",
"release": "BABEL_ENV=production yarn set-versions && yarn compile && sh ./__publish.sh && conventional-changelog -p angular -i CHANGELOG.md -s",
"schema": "typescript-json-schema packages/electron-builder-lib/tsconfig.json Configuration --out packages/electron-builder-lib/scheme.json --noExtraProps --useTypeOfKeyword --strictNullChecks --titles --required",
"jsdoc": "ts2jsdoc packages/builder-util-runtime packages/electron-updater packages/builder-util packages/electron-builder-lib packages/electron-builder packages/electron-publish",
"jsdoc2md": "node scripts/jsdoc2md.js",
Expand Down Expand Up @@ -83,7 +83,7 @@
"@types/semver": "^5.5.0",
"@types/source-map-support": "^0.4.0",
"@types/stat-mode": "^0.2.0",
"babel-preset-ts-node6-bluebird": "^2.0.1",
"babel-preset-ts-node6-bluebird": "^2.0.3",
"convert-source-map": "^1.5.1",
"decompress-zip": "^0.3.0",
"depcheck": "^0.6.9",
Expand All @@ -100,7 +100,7 @@
"jest-junit": "^3.6.0",
"jsdoc-to-markdown": "^4.0.1",
"path-sort": "^0.1.0",
"ts-babel": "^5.0.1",
"ts-babel": "^5.0.2",
"ts-jsdoc": "^3.0.0",
"tslint": "^5.9.1",
"typescript": "2.7.2",
Expand Down
18 changes: 15 additions & 3 deletions packages/electron-builder-lib/src/util/AppFileCopierHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function computeFileSets(matchers: Array<FileMatcher>, transformer:
return false
}, CONCURRENCY)

fileSets.push({src: matcher.from, files, metadata, transformedFiles, destination: matcher.to})
fileSets.push(validateFileSet({src: matcher.from, files, metadata, transformedFiles, destination: matcher.to}))
}

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

function validateFileSet(fileSet: ResolvedFileSet): ResolvedFileSet {
if (fileSet.src == null || fileSet.src.length === 0) {
throw new Error("fileset src is empty")
}
return fileSet
}

async function copyHoistedNodeModules(packager: Packager, mainMatcher: FileMatcher): Promise<Array<ResolvedFileSet>> {
const productionDeps = await packager.productionDeps.value
const rootPathToCopier = new Map<string, Array<Dependency>>()
for (const dep of productionDeps) {
const root = dep.path.substring(0, dep.path.indexOf(NODE_MODULES_PATTERN))
const index = dep.path.indexOf(NODE_MODULES_PATTERN)
if (index < 0) {
throw new Error("cannot find node_modules in the path " + dep.path)
}

const root = dep.path.substring(0, index)
let list = rootPathToCopier.get(root)
if (list == null) {
list = []
Expand All @@ -111,7 +123,7 @@ async function copyHoistedNodeModules(packager: Packager, mainMatcher: FileMatch
const matcher = new FileMatcher(source, mainMatcher.to, mainMatcher.macroExpander, mainMatcher.patterns)
const copier = new NodeModuleCopyHelper(matcher, packager)
const files = await copier.collectNodeModules(rootPathToCopier.get(source)!!)
return {src: matcher.from, destination: matcher.to, files, metadata: copier.metadata}
return validateFileSet({src: matcher.from, destination: matcher.to, files, metadata: copier.metadata})
})
}

Expand Down
70 changes: 45 additions & 25 deletions packages/electron-builder-lib/src/util/packageDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export function createLazyProductionDeps(projectDir: string) {

/** @internal */
export async function getProductionDependencies(folder: string): Promise<Array<Dependency>> {
const sorted: Array<Dependency> = []
computeSortedPaths(await new Collector().collect(folder), sorted, false)
return sorted
const result: Array<Dependency> = []
computeSortedPaths(await new Collector().collect(folder), result, false)
return result
}

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

if (this.unresolved.size > 0) {
log.debug({unresolved: Array.from(this.unresolved.keys()).join(", ")}, "Unresolved dependencies after first round")
log.debug({unresolved: Array.from(this.unresolved.keys()).join(", ")}, "unresolved dependencies after first round")
await this.resolveUnresolvedHoisted(rootDependency, dir)
}
return rootDependency
}

private async resolveUnresolvedHoisted(rootDependency: Dependency, dir: string) {
private async resolveUnresolvedHoisted(rootDependency: Dependency, dir: string): Promise<void> {
let nameToMetadata = rootDependency.dependencies
if (nameToMetadata == null) {
rootDependency.dependencies = new Map<string, Dependency>()
Expand Down Expand Up @@ -112,30 +112,50 @@ class Collector {
const parentNodeModulesDir = parentDir + path.sep + "node_modules"
const dirStat = await statOrNull(parentNodeModulesDir)
if (dirStat == null || !dirStat.isDirectory()) {
continue
if (dirStat == null || !dirStat.isDirectory()) {
continue
}
}

const unresolved = Array.from(this.unresolved.keys())
this.unresolved.clear()

const resolved = await BluebirdPromise.map(unresolved, it => {
return this.readChildPackage(it, parentNodeModulesDir, rootDependency)
.catch(e => {
if ((e as any).code === "ENOENT") {
return null
}
else {
throw e
}
})
}, CONCURRENCY)
for (const dep of resolved) {
if (dep != null) {
nameToMetadata.set(dep.realName, dep)
// https://github.com/electron-userland/electron-builder/issues/2222#issuecomment-339060335
// step 1: resolve current unresolved
// step n: try to resolve new unresolved in the same parent dir until at least something is resolved in the dir
while (true) {
const unresolved = Array.from(this.unresolved.keys())
this.unresolved.clear()

const resolved = await BluebirdPromise.map(unresolved, it => {
return this.readChildPackage(it, parentNodeModulesDir, rootDependency)
.catch(e => {
if ((e as any).code === "ENOENT") {
return null
}
else {
throw e
}
})
}, CONCURRENCY)

let hasResolved = false

for (const dep of resolved) {
if (dep != null) {
hasResolved = true
this.unmarkExtraneous(dep)
nameToMetadata.set(dep.realName, dep)
}
}
}

this.unmarkExtraneous(rootDependency)
if (!hasResolved) {
break
}

this.unmarkExtraneous(rootDependency)

if (this.unresolved.size === 0) {
return
}
}
}
while (this.unresolved.size > 0)
}
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,9 @@ babel-preset-jest@^23.0.0-alpha.0:
babel-plugin-jest-hoist "^23.0.0-alpha.0"
babel-plugin-syntax-object-rest-spread "^6.13.0"

babel-preset-ts-node6-bluebird@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/babel-preset-ts-node6-bluebird/-/babel-preset-ts-node6-bluebird-2.0.1.tgz#846f137112e0f8c0fca76dda696d8bd64e9be25e"
babel-preset-ts-node6-bluebird@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/babel-preset-ts-node6-bluebird/-/babel-preset-ts-node6-bluebird-2.0.3.tgz#d246288f9261f93ec0812e757aa217554ff020ae"
dependencies:
"@babel/helper-plugin-utils" "^7.0.0-beta.42"
"@babel/plugin-transform-modules-commonjs" "^7.0.0-beta.42"
Expand Down Expand Up @@ -5615,9 +5615,9 @@ truncate-utf8-bytes@^1.0.0:
dependencies:
utf8-byte-length "^1.0.1"

ts-babel@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/ts-babel/-/ts-babel-5.0.1.tgz#0b096306ff3180704441bdeecd61b51b37b8c434"
ts-babel@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/ts-babel/-/ts-babel-5.0.2.tgz#fefeb9a26ca5e6195fde67961665a4e27d9cada0"
dependencies:
"@babel/core" "^7.0.0-beta.42"
bluebird-lst "^1.0.5"
Expand Down

0 comments on commit cde9845

Please sign in to comment.