forked from eclipse-theia/theia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eclipse-theiaGH-934: Aligned the version of the third-party dependenc…
…ies. It is a must for the bundled electron application. Otherwise, these two dependencies won't be hoisted into the root `node_modules` folder. Instead, they will stay in `node_modules/@theia/core/node_modules`, and will not make into the bundled electron application. Added a `prepare` script to check the hoisted dependencies. Closes: eclipse-theia#934. Signed-off-by: Akos Kitta <[email protected]>
- Loading branch information
Showing
11 changed files
with
402 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
#!/usr/bin/env node | ||
/******************************************************************************** | ||
* Copyright (c) 2018 TypeFox and others | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
// @ts-check | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
/** | ||
* This scrip makes sure all the dependencies are hoisted into the root `node_modules` after running `yarn`. | ||
* - https://github.com/theia-ide/theia/pull/2994#issuecomment-425447650 | ||
* - https://github.com/theia-ide/theia/pull/2994#issuecomment-425649817 | ||
* | ||
* If you do not want to bail the execution, set the `THEIA_CHECK_HOISTING_NO_BAIL` environment variable to `true`. Use `cross-env`. | ||
* ```json | ||
* ... | ||
* "scripts": { | ||
* ..., | ||
* "prepare:hoisting": "cross-env THEIA_CHECK_HOISTING_NO_BAIL=true node scripts/check-hoisting", | ||
* ... | ||
* } | ||
* ... | ||
* ``` | ||
*/ | ||
|
||
(() => { | ||
|
||
function collectIssues() { | ||
|
||
console.log('🔍 Analyzing hoisted dependencies in the Theia extensions:'); | ||
const root = path.join(__dirname, '..'); | ||
const rootNodeModules = path.join(root, 'node_modules'); | ||
const packages = path.join(root, 'packages'); | ||
|
||
const issues = new Map(); | ||
for (const extension of fs.readdirSync(packages)) { | ||
console.log(` - Checking @theia/${extension}...`); | ||
const extensionPath = path.join(packages, extension); | ||
const nodeModulesPath = path.join(extensionPath, 'node_modules'); | ||
if (fs.existsSync(nodeModulesPath)) { | ||
for (const dependency of fs.readdirSync(nodeModulesPath).filter(name => name !== '.bin')) { | ||
const dependencyPath = path.join(nodeModulesPath, dependency); | ||
const version = versionOf(dependencyPath); | ||
let message = `Dependency '${dependency}' ${version ? `[${version}] ` : ''}was not hoisted to the root 'node_modules' folder.`; | ||
const existingDependency = path.join(rootNodeModules, dependency); | ||
if (fs.existsSync(existingDependency)) { | ||
const otherVersion = versionOf(existingDependency); | ||
if (otherVersion) { | ||
message += ` The same dependency already exists with version ${otherVersion} at '${existingDependency}'.`; | ||
} | ||
} | ||
error(issues, extension, message); | ||
} | ||
} else { | ||
warn(issues, extension, "Does not have 'node_modules' folder."); | ||
} | ||
} | ||
return issues; | ||
} | ||
|
||
function versionOf(npmPackagePath) { | ||
const packageJsonPath = path.join(npmPackagePath, 'package.json'); | ||
if (fs.existsSync(packageJsonPath)) { | ||
return require(packageJsonPath).version || ''; | ||
} | ||
return ''; | ||
} | ||
|
||
function warn(issues, extension, message) { | ||
return log(issues, extension, message, 'warn'); | ||
} | ||
|
||
function error(issues, extension, message) { | ||
return log(issues, extension, message, 'error'); | ||
} | ||
|
||
function log(issues, extension, message, type) { | ||
const key = `@theia/${extension}`; | ||
if (!issues.has(key)) { | ||
issues.set(key, []); | ||
} | ||
const severity = toSeverity(type); | ||
issues.get(key).push({ severity, message }); | ||
return issues; | ||
} | ||
|
||
function toSeverity(type) { | ||
switch (type) { | ||
case 'error': return 0; | ||
case 'warn': return 1; | ||
default: throw new Error(`Unexpected type: ${type}.`); | ||
} | ||
} | ||
|
||
function toType(severity) { | ||
switch (severity) { | ||
case 0: return 'error'; | ||
case 1: return 'warning'; | ||
default: throw new Error(`Unexpected severity: ${severity}.`); | ||
} | ||
} | ||
|
||
function assert(issues) { | ||
console.log('📖 Summary:'); | ||
let code = 0; | ||
if (issues && issues.length > 0) { | ||
for (const extension of issues.keys()) { | ||
const issuesPerExtension = issues.get(extension).sort((left, right) => left.severity - right.severity); | ||
if (issuesPerExtension) { | ||
console.log(`The following dependency issues were detected in '${extension}':`); | ||
for (const { severity, message } of issuesPerExtension) { | ||
const type = toType(severity); | ||
console.log(` - ${type}: ${message}`); | ||
if (type === 'error') { | ||
code = 1; | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
console.log('🎉 No dependency issues were detected.'); | ||
} | ||
if (code !== 0 && process.env.THEIA_CHECK_HOISTING_NO_BAIL === 'true') { | ||
console.log("⚠️ 'THEIA_CHECK_HOISTING_NO_BAIL' was 'true'. This is a kind reminder to fix the dependency issues."); | ||
process.exit(0); | ||
} | ||
process.exit(code); | ||
} | ||
|
||
assert(collectIssues()); | ||
|
||
})(); |
Oops, something went wrong.