Skip to content

Commit

Permalink
Merge pull request #463 from BarryThePenguin/fix/workspace-packages
Browse files Browse the repository at this point in the history
Handle additional `yarn` workspace definition formats
  • Loading branch information
rwjblue committed Mar 11, 2020
2 parents bff5859 + 8e31b46 commit aa4e3ff
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
16 changes: 11 additions & 5 deletions lib/dependency-manager-adapters/npm.js
Expand Up @@ -194,10 +194,13 @@ module.exports = CoreObject.extend({
let restoreTasks = [
copy(path.join(this.cwd, this.packageJSONBackupFileName),
path.join(this.cwd, this.packageJSON)),
copy(path.join(this.cwd, this.nodeModulesBackupLocation),
path.join(this.cwd, this.nodeModules), { clobber: true }),
];

if (fs.existsSync(path.join(this.cwd, this.nodeModulesBackupLocation))) {
restoreTasks.push(copy(path.join(this.cwd, this.nodeModulesBackupLocation),
path.join(this.cwd, this.nodeModules), { clobber: true }));
}

if (fs.existsSync(path.join(this.cwd, this.yarnLockBackupFileName))) {
restoreTasks.push(copy(path.join(this.cwd, this.yarnLockBackupFileName),
path.join(this.cwd, this.yarnLock)));
Expand All @@ -222,9 +225,12 @@ module.exports = CoreObject.extend({

let backupTasks = [
copy(path.join(this.cwd, this.packageJSON),
path.join(this.cwd, this.packageJSONBackupFileName)),
copy(path.join(this.cwd, this.nodeModules),
path.join(this.cwd, this.nodeModulesBackupLocation), { clobber: true })];
path.join(this.cwd, this.packageJSONBackupFileName))];

if (fs.existsSync(path.join(this.cwd, this.nodeModules))) {
backupTasks.push(copy(path.join(this.cwd, this.nodeModules),
path.join(this.cwd, this.nodeModulesBackupLocation), { clobber: true }));
}

if (fs.existsSync(path.join(this.cwd, this.yarnLock))) {
backupTasks.push(copy(path.join(this.cwd, this.yarnLock),
Expand Down
10 changes: 9 additions & 1 deletion lib/dependency-manager-adapters/workspace.js
Expand Up @@ -28,7 +28,15 @@ module.exports = CoreObject.extend({
}

let packageJSON = JSON.parse(fs.readFileSync(this.packageJSON));
let workspaceGlobs = packageJSON.workspaces;
let workspaceGlobs;

if (Array.isArray(packageJSON.workspaces)) {
workspaceGlobs = packageJSON.workspaces
}

if (packageJSON.workspaces && Array.isArray(packageJSON.workspaces.packages)) {
workspaceGlobs = packageJSON.workspaces.packages
}

if (!workspaceGlobs || !workspaceGlobs.length) {
throw new Error('you must define the `workspaces` property in package.json with at least one workspace to use workspaces with ember-try');
Expand Down
27 changes: 27 additions & 0 deletions test/dependency-manager-adapters/workspace-adapter-test.js
Expand Up @@ -44,6 +44,33 @@ describe('workspaceAdapter', () => {
});
});

it('with workspace packages', () => {
writeJSONFile('package.json', {
name: 'a-test-project-with-workspaces',
workspaces: {
packages: [
"packages/*"
],
nohoist: [
'@foo/example'
]
}
})

fs.ensureDirSync('packages/test/node_modules');

writeJSONFile('packages/test/package.json', { originalPackageJSON: true });
writeJSONFile('packages/test/node_modules/prove-it.json', { originalNodeModules: true });

return new WorkspaceAdapter({
cwd: tmpdir,
useYarnCommand: true,
}).setup().then(() => {
assertFileContainsJSON(path.join(tmpdir, 'packages/test/package.json.ember-try'), { originalPackageJSON: true });
assertFileContainsJSON(path.join(tmpdir, 'packages/test/.node_modules.ember-try/prove-it.json'), { originalNodeModules: true });
});
});

it('backs up the yarn.lock file, npm-shrinkwrap.json and package-lock.json if they exist', () => {
fs.ensureDirSync('packages/test/node_modules');

Expand Down

0 comments on commit aa4e3ff

Please sign in to comment.