Skip to content

Commit

Permalink
GH-934: Bumped up the version of yargs and ws.
Browse files Browse the repository at this point in the history
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: #934.

Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
Akos Kitta committed Oct 19, 2018
1 parent e619393 commit 33efe8f
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 44 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"chai": "^4.1.0",
"chai-string": "^1.4.0",
"concurrently": "^3.5.0",
"cross-env": "^5.2.0",
"electron-mocha": "~3.5.0",
"ignore-styles": "^5.0.1",
"istanbul": "^0.4.5",
Expand All @@ -48,6 +49,7 @@
"scripts": {
"prepare": "yarn prepare:travis && yarn rebuild:clean && yarn build:clean",
"prepare:travis": "node scripts/prepare-travis",
"prepare:hoisting": "cross-env THEIA_CHECK_HOISTING_NO_BAIL=true node scripts/check-hoisting",
"build": "run build",
"build:clean": "run prepare",
"docs": "run docs \"@theia/!(example-)*\"",
Expand Down
10 changes: 5 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"@types/react-dom": "^16.0.6",
"@types/react-virtualized": "^9.18.3",
"@types/route-parser": "^0.1.1",
"@types/ws": "^3.0.2",
"@types/yargs": "^8.0.2",
"@types/ws": "^5.1.2",
"@types/yargs": "^11.1.0",
"ajv": "^5.2.2",
"body-parser": "^1.17.2",
"electron": "1.8.2-beta.5",
Expand All @@ -40,8 +40,8 @@
"vscode-nsfw": "^1.0.17",
"vscode-uri": "^1.0.1",
"vscode-ws-jsonrpc": "^0.0.2-1",
"ws": "^3.0.0",
"yargs": "^9.0.1"
"ws": "^5.2.2",
"yargs": "^11.1.0"
},
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -86,4 +86,4 @@
"nyc": {
"extends": "../../configs/nyc.json"
}
}
}
139 changes: 139 additions & 0 deletions scripts/check-hoisting
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/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`.
* ```json
* ...
* "scripts": {
* ...,
* "prepare:hoisting": "cross-env THEIA_CHECK_HOISTING_NO_BAIL=true node scripts/check-hoisting",
* ...
* }
* ...
* ```
*/

(() => {

function collectIssues() {

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)) {
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 version = versionOf(dependency);
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) {
let code = 0;
if (issues) {
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;
}
}
}
}
}
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());

})();
58 changes: 19 additions & 39 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,16 @@
version "2.2.1"
resolved "https://registry.yarnpkg.com/@types/write-json-file/-/write-json-file-2.2.1.tgz#74155aaccbb0d532be21f9d66bebc4ea875a5a62"

"@types/ws@^3.0.2":
version "3.2.1"
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-3.2.1.tgz#b0c1579e58e686f83ce0a97bb9463d29705827fb"
"@types/ws@^5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-5.1.2.tgz#f02d3b1cd46db7686734f3ce83bdf46c49decd64"
dependencies:
"@types/events" "*"
"@types/node" "*"

"@types/yargs@^8.0.2":
version "8.0.3"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-8.0.3.tgz#6f0ad77792762fc69d209716dbab3201dcba56fb"
"@types/yargs@^11.1.0":
version "11.1.2"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-11.1.2.tgz#fd4b676846fe731a5de5c6d2e5ef6a377262fc30"

"@webassemblyjs/[email protected]":
version "1.5.13"
Expand Down Expand Up @@ -2723,6 +2724,14 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
safe-buffer "^5.0.1"
sha.js "^2.4.8"

cross-env@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.2.0.tgz#6ecd4c015d5773e614039ee529076669b9d126f2"
integrity sha512-jtdNFfFW1hB7sMhr/H6rW1Z45LFqyI431m3qU6bFXcQ3Eh7LtBuG3h74o7ohHZ3crrRkkqHlo4jYHFPcjroANg==
dependencies:
cross-spawn "^6.0.5"
is-windows "^1.0.0"

cross-spawn-async@^2.1.1:
version "2.2.5"
resolved "https://registry.yarnpkg.com/cross-spawn-async/-/cross-spawn-async-2.2.5.tgz#845ff0c0834a3ded9d160daca6d390906bb288cc"
Expand Down Expand Up @@ -5231,9 +5240,10 @@ is-utf8@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72"

is-windows@^1.0.1, is-windows@^1.0.2:
is-windows@^1.0.0, is-windows@^1.0.1, is-windows@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d"
integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==

[email protected]:
version "0.0.1"
Expand Down Expand Up @@ -9627,10 +9637,6 @@ uglifyjs-webpack-plugin@^1.2.4:
webpack-sources "^1.1.0"
worker-farm "^1.5.2"

ultron@~1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.1.1.tgz#9fe1536a10a664a65266a1e3ccf85fd36302bc9c"

umd-compat-loader@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/umd-compat-loader/-/umd-compat-loader-2.1.1.tgz#1a44674f57deeb429f4d1533668453a3cf322422"
Expand Down Expand Up @@ -10294,15 +10300,7 @@ write-pkg@^3.1.0:
sort-keys "^2.0.0"
write-json-file "^2.2.0"

ws@^3.0.0:
version "3.3.3"
resolved "https://registry.yarnpkg.com/ws/-/ws-3.3.3.tgz#f1cf84fe2d5e901ebce94efaece785f187a228f2"
dependencies:
async-limiter "~1.0.0"
safe-buffer "~5.1.0"
ultron "~1.1.0"

ws@^5.2.0:
ws@^5.2.0, ws@^5.2.2:
version "5.2.2"
resolved "https://registry.yarnpkg.com/ws/-/ws-5.2.2.tgz#dffef14866b8e8dc9133582514d1befaf96e980f"
dependencies:
Expand Down Expand Up @@ -10382,7 +10380,7 @@ yargs-parser@^9.0.2:
dependencies:
camelcase "^4.1.0"

[email protected], yargs@^11.0.0:
[email protected], yargs@^11.0.0, yargs@^11.1.0:
version "11.1.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-11.1.0.tgz#90b869934ed6e871115ea2ff58b03f4724ed2d77"
dependencies:
Expand Down Expand Up @@ -10452,24 +10450,6 @@ yargs@^8.0.2:
y18n "^3.2.1"
yargs-parser "^7.0.0"

yargs@^9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-9.0.1.tgz#52acc23feecac34042078ee78c0c007f5085db4c"
dependencies:
camelcase "^4.1.0"
cliui "^3.2.0"
decamelize "^1.1.1"
get-caller-file "^1.0.1"
os-locale "^2.0.0"
read-pkg-up "^2.0.0"
require-directory "^2.1.1"
require-main-filename "^1.0.1"
set-blocking "^2.0.0"
string-width "^2.0.0"
which-module "^2.0.0"
y18n "^3.2.1"
yargs-parser "^7.0.0"

yargs@~1.2.6:
version "1.2.6"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-1.2.6.tgz#9c7b4a82fd5d595b2bf17ab6dcc43135432fe34b"
Expand Down

0 comments on commit 33efe8f

Please sign in to comment.