Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add workspaceLockfiles and workspaceLockfileName options #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp.*
.pnp.*

.idea
55 changes: 55 additions & 0 deletions .yarn/releases/yarn-2.4.1.cjs

Large diffs are not rendered by default.

55 changes: 0 additions & 55 deletions .yarn/releases/yarn-berry.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
yarnPath: ".yarn/releases/yarn-berry.cjs"
yarnPath: .yarn/releases/yarn-2.4.1.cjs
21 changes: 19 additions & 2 deletions packages/plugin/bundles/@yarnpkg/plugin-workspace-lockfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,33 @@ const createLockfile = async (configuration, {
const green = text => `\x1b[32m${text}\x1b[0m`;

const plugin = {
configuration: {
workspaceLockfiles: {
description: 'List of the workspaces that need a specific lockfile',
type: _yarnpkg_core__WEBPACK_IMPORTED_MODULE_0__.SettingsType.STRING,
default: true,
isArray: true
},
workspaceLockfileName: {
description: 'Name of the workspaces specific lockfile',
type: _yarnpkg_core__WEBPACK_IMPORTED_MODULE_0__.SettingsType.STRING,
default: 'yarn.lock-workspace'
}
},
hooks: {
afterAllInstalled: async project => {
const configuration = await _yarnpkg_core__WEBPACK_IMPORTED_MODULE_0__.Configuration.find(project.cwd, (0,_yarnpkg_cli__WEBPACK_IMPORTED_MODULE_1__.getPluginConfiguration)());
const workspaceLockfiles = configuration.values.get('workspaceLockfiles');
const workspaceLockfileName = configuration.values.get('workspaceLockfileName');
await _yarnpkg_core__WEBPACK_IMPORTED_MODULE_0__.StreamReport.start({
configuration,
stdout: process.stdout,
includeLogs: true
}, async report => {
for (const workspace of project.workspaces) {
const lockPath = _yarnpkg_fslib__WEBPACK_IMPORTED_MODULE_2__.ppath.join(workspace.cwd, "yarn.lock-workspace");
const requiredWorkspaces = Array.isArray(workspaceLockfiles) ? new Set(workspaceLockfiles.map(name => project.getWorkspaceByIdent(_yarnpkg_core__WEBPACK_IMPORTED_MODULE_0__.structUtils.parseIdent(name)))) : new Set(project.workspaces);

for (const workspace of requiredWorkspaces) {
const lockPath = _yarnpkg_fslib__WEBPACK_IMPORTED_MODULE_2__.ppath.join(workspace.cwd, workspaceLockfileName);
await _yarnpkg_fslib__WEBPACK_IMPORTED_MODULE_2__.xfs.writeFilePromise(lockPath, await createLockfile(configuration, workspace));
report.reportInfo(null, `${green(`✓`)} Wrote ${lockPath}`);
}
Expand Down
12 changes: 6 additions & 6 deletions packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"name": "yarn-plugin-workspace-lockfile",
"main": "./sources/index.ts",
"dependencies": {
"@types/node": "^13.0.0",
"@yarnpkg/builder": "^2.1.2",
"@yarnpkg/cli": "^2.3.0",
"@yarnpkg/core": "^2.3.0",
"@yarnpkg/fslib": "^2.3.0",
"typescript": "^4.0.5"
"@types/node": "^14.14.37",
"@yarnpkg/builder": "^2.1.3",
"@yarnpkg/cli": "^2.4.1",
"@yarnpkg/core": "^2.4.0",
"@yarnpkg/fslib": "^2.4.0",
"typescript": "^4.2.4"
},
"scripts": {
"build:plugin": "builder build plugin --no-minify"
Expand Down
29 changes: 26 additions & 3 deletions packages/plugin/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
Workspace,
StreamReport,
ThrowReport,
} from "@yarnpkg/core";
SettingsType,
SettingsDefinition,
structUtils
} from '@yarnpkg/core';
import { getPluginConfiguration } from "@yarnpkg/cli";

import { xfs, ppath, Filename } from "@yarnpkg/fslib";
Expand Down Expand Up @@ -78,24 +81,44 @@ const createLockfile = async (
const green = (text: string) => `\x1b[32m${text}\x1b[0m`;

const plugin: Plugin<Hooks> = {
configuration: {
workspaceLockfiles: {
description: 'List of the workspaces that need a specific lockfile',
type: SettingsType.STRING,
default: true,
isArray: true
},
workspaceLockfileName: {
description: 'Name of the workspaces specific lockfile',
type: SettingsType.STRING,
default: 'yarn.lock-workspace'
}
} as {[settingName: string]: SettingsDefinition},
hooks: {
afterAllInstalled: async (project) => {
const configuration = await Configuration.find(
project.cwd,
getPluginConfiguration()
);

const workspaceLockfiles = configuration.values.get('workspaceLockfiles');
const workspaceLockfileName = configuration.values.get('workspaceLockfileName');

await StreamReport.start(
{
configuration,
stdout: process.stdout,
includeLogs: true,
},
async (report: StreamReport) => {
for (const workspace of project.workspaces) {
const requiredWorkspaces: Set<Workspace> = Array.isArray(workspaceLockfiles)
? new Set(workspaceLockfiles.map(name => project.getWorkspaceByIdent(structUtils.parseIdent(name))))
: new Set(project.workspaces);

for (const workspace of requiredWorkspaces) {
const lockPath = ppath.join(
workspace.cwd,
"yarn.lock-workspace" as Filename
workspaceLockfileName as Filename
);

await xfs.writeFilePromise(
Expand Down