Skip to content

Commit

Permalink
[BUGFIX] sync-dev-dependency should not hoist @ember-data/-test-infra (
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav0 authored and runspired committed Sep 11, 2019
1 parent bc2a074 commit dbec1dd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
23 changes: 20 additions & 3 deletions bin/sync-dev-dependency
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,22 @@ function execWithLog(command) {
return shellSync(command, { stdio: [0, 1, 2] });
}

// Remove this ponyfill once fromEntries is supported in min version of node.js
if (!Object.fromEntries) {
Object.fromEntries = require('fromentries');
}

// gather deps not yet in root
let rootPackage = require(rootJson);
const rootUpdates = {};
let rootUpdates = {};
const packageJsons = {};

// Write a json object to file
// Add \n to end of file in accordance with .editorconfig
function writeJsonToFile(path, json) {
return fs.writeFileSync(path, JSON.stringify(json, null, 2) + '\n');
}

// hoist anything needed to root
packages.forEach(localName => {
const pkgDir = path.join(packagesDir, localName);
Expand Down Expand Up @@ -81,9 +92,15 @@ if (Object.keys(rootUpdates).length > 0) {
// grab latest in case we wrote in the previous step
delete require.cache[rootJson];
rootPackage = require(rootJson);

// Do not hoist devDependencies in @ember-data namespace
// This is a single pass, so should be faster than spread operator or filter/reduce,
// especially if fromEntries is supported natiely
rootUpdates = Object.fromEntries(Object.entries(rootUpdates).filter(([key]) => !key.startsWith('@ember-data/')));

debug(`Adding staged devDependencies to root: ${JSON.stringify(rootUpdates, null, 2)}`);
Object.assign(rootPackage.devDependencies, rootUpdates);
fs.writeFileSync(rootJson, JSON.stringify(rootPackage, null, 2));
writeJsonToFile(rootJson, rootPackage);
}

// assign root versions to sub-packages and write
Expand All @@ -96,7 +113,7 @@ Object.keys(packageJsons).forEach(key => {
}
});

fs.writeFileSync(key, JSON.stringify(pkg, null, 2));
writeJsonToFile(key, pkg);
});

execWithLog(`yarn install`);
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-qunit": "^4.0.0",
"execa": "^1.0.0",
"fromentries": "^1.2.0",
"git-repo-info": "^2.0.0",
"github": "^1.1.1",
"glob": "^7.1.4",
Expand All @@ -115,7 +116,12 @@
"rsvp": "^4.8.5",
"semver": "^6.2.0",
"silent-error": "^1.1.1",
"typescript": "~3.6.3"
"typescript": "~3.6.3",
"babel-plugin-debug-macros": "^0.3.3",
"babel-plugin-feature-flags": "^0.3.1",
"babel-plugin-filter-imports": "^3.0.0",
"babel6-plugin-strip-class-callcheck": "^6.0.0",
"broccoli-file-creator": "^2.1.1"
},
"bin": {
"test-partner-project": "./bin/test-external-partner-project.js",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6230,6 +6230,11 @@ from2@^2.1.0, from2@^2.1.1:
inherits "^2.0.1"
readable-stream "^2.0.0"

fromentries@^1.2.0:
version "1.2.0"
resolved "https://registry.npmjs.org/fromentries/-/fromentries-1.2.0.tgz#e6aa06f240d6267f913cea422075ef88b63e7897"
integrity sha512-33X7H/wdfO99GdRLLgkjUrD4geAFdq/Uv0kl3HD4da6HDixd2GUg8Mw7dahLCV9r/EARkmtYBB6Tch4EEokFTQ==

fs-extra@^0.24.0:
version "0.24.0"
resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-0.24.0.tgz#d4e4342a96675cb7846633a6099249332b539952"
Expand Down

0 comments on commit dbec1dd

Please sign in to comment.