Skip to content

Commit

Permalink
feat(plugin-workspaces-export): upgrade workspaces export plugin with…
Browse files Browse the repository at this point in the history
… Yarn 3 support
  • Loading branch information
kherock committed Jun 20, 2021
1 parent f178b84 commit fd0c808
Show file tree
Hide file tree
Showing 25 changed files with 184 additions and 61 deletions.
50 changes: 49 additions & 1 deletion .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
13 changes: 13 additions & 0 deletions .yarn/patches/@yarnpkg-builder-npm-3.0.0-rc.5-eca8edb975
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/lib/commands/build/plugin.js b/lib/commands/build/plugin.js
index f9dab43edb5549fedd9723a265aa381a61a5678b..3c5c4e309274fe3a7b41c3aa7b13fecb502ab061 100644
--- a/lib/commands/build/plugin.js
+++ b/lib/commands/build/plugin.js
@@ -55,7 +55,7 @@ class BuildPluginCommand extends clipanion_1.Command {
if (dependencyNameMatch === null)
return undefined;
const [, dependencyName] = dependencyNameMatch;
- if (dependencyName === name || !isDynamicLib_1.isDynamicLib(dependencyName))
+ if (dependencyName === name || !isDynamicLib_1.isDynamicLib(args.path))
return undefined;
return {
path: args.path,
2 changes: 2 additions & 0 deletions .yarn/versions/3b708e6c.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
releases:
"@kherock/yarn-plugin-workspaces-export": major
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ plugins:
spec: "@yarnpkg/plugin-workspace-tools"
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
# - path: packages/plugin-workspaces-export/bundles/@yarnpkg/plugin-workspaces-export.js

yarnPath: .yarn/releases/yarn-sources.cjs
2 changes: 1 addition & 1 deletion examples/phrases/in-hac/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import consectetur from "@example/consectetur";
import elit from "@example/elit";
import elit from "@example/elit";

export default `In hac habitasse platea ${consectetur}. Maecenas et blandit nisl ${elit}.`;
18 changes: 9 additions & 9 deletions examples/phrases/lorem-ipsum/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import adipiscing from "@example/adipiscing";
import amet from "@example/amet";
import adipiscing from "@example/adipiscing";
import amet from "@example/amet";
import consectetur from "@example/consectetur";
import dolor from "@example/dolor";
import elit from "@example/elit";
import ipsum from "@example/ipsum";
import lorem from "@example/lorem";
import inHac from "@example/phrase-in-hac";
import nullam from "@example/phrase-nullam-risus";
import sit from "@example/sit";
import dolor from "@example/dolor";
import elit from "@example/elit";
import ipsum from "@example/ipsum";
import lorem from "@example/lorem";
import inHac from "@example/phrase-in-hac";
import nullam from "@example/phrase-nullam-risus";
import sit from "@example/sit";

export default `${lorem} ${ipsum} ${dolor} ${sit} ${amet}, ${consectetur}` +
` ${adipiscing} ${elit}. Nunc id faucibus metus, ac maximus lectus. ` +
Expand Down
2 changes: 1 addition & 1 deletion examples/phrases/nullam-risus/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import adipiscing from "@example/adipiscing";
import dolor from "@example/dolor";
import dolor from "@example/dolor";

export default `Class aptent ${adipiscing} sociosqu ad litora torquent per conubia nostra ${dolor}.`;
2 changes: 1 addition & 1 deletion examples/words/adipiscing/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default "adipiscing";
export default `adipiscing`;
2 changes: 1 addition & 1 deletion examples/words/amet/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default "amet";
export default `amet`;
2 changes: 1 addition & 1 deletion examples/words/consectetur/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default "consectetur";
export default `consectetur`;
2 changes: 1 addition & 1 deletion examples/words/dolor/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default "dolor";
export default `dolor`;
2 changes: 1 addition & 1 deletion examples/words/elit/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default "elit";
export default `elit`;
2 changes: 1 addition & 1 deletion examples/words/ipsum/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default "ipsum";
export default `ipsum`;
2 changes: 1 addition & 1 deletion examples/words/lorem/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default "lorem";
export default `lorem`;
2 changes: 1 addition & 1 deletion examples/words/sit/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default "sit";
export default `sit`;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@
},
"engines": {
"node": ">=12.13.0"
},
"resolutions": {
"@yarnpkg/builder@3.0.0-rc.5": "patch:@yarnpkg/builder@npm:3.0.0-rc.5#.yarn/patches/@yarnpkg-builder-npm-3.0.0-rc.5-eca8edb975"
}
}
4 changes: 2 additions & 2 deletions packages/plugin-workspaces-export/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `@yarnpkg/plugin-workspaces-export`

This plugin adds support exporting workspaces into a deployable archive with a
PnP runtime.
This plugin adds support for exporting workspaces into a deployable archive with
a PnP runtime.

## Install

Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-workspaces-export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
"@yarnpkg/libzip": "^2.2.2-rc.3",
"@yarnpkg/plugin-pack": "^3.0.0-rc.5",
"clipanion": "^3.0.0-rc.12",
"semver": "^7.3.5",
"tar-stream": "^2.2.0",
"tslib": "^2.3.0"
},
"devDependencies": {
"@types/semver": "^7.3.6",
"@types/tar-stream": "^2.2.0",
"@yarnpkg/builder": "^3.0.0-rc.5",
"@yarnpkg/builder": "3.0.0-rc.5",
"@yarnpkg/plugin-pnp": "^3.0.0-rc.5",
"typescript": "~4.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-workspaces-export/sources/ExportCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class ExportCache extends Cache {
const baseFs = new NodeFS();

const loadWorkspaceThroughMutex = async () => {
const cachePath = ppath.resolve(this.cwd, `../workspaces` as PortablePath, structUtils.requirableIdent(locator) as PortablePath);
const cachePath = ppath.resolve(this.cwd, `../workspaces` as PortablePath, structUtils.stringifyIdent(locator) as PortablePath);

const mutexedLoad = async () => {
const cacheExists = await baseFs.existsPromise(cachePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {WorkspaceFetcher} from '@yarnpkg/core/lib/WorkspaceFetcher';
import {PortablePath} from '@yarnpkg/fslib';

import {genPackZip} from './exportUtils';

import {
Locator,
Fetcher,
FetchOptions,
FetchResult,
MinimalFetchOptions,
WorkspaceResolver,
structUtils,
Project,
FetchResult,
WorkspaceResolver,
} from '@yarnpkg/core';
import {PortablePath} from '@yarnpkg/fslib';

import {genPackZip} from './exportUtils';

/**
* Fetcher that packs workspaces as cacheable packages
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {PortablePath} from '@yarnpkg/fslib';

import {
Descriptor,
LinkType,
Locator,
MinimalResolveOptions,
Project,
Resolver,
ResolveOptions,
WorkspaceResolver,
Descriptor,
MinimalResolveOptions,
} from '@yarnpkg/core';
import {PortablePath} from '@yarnpkg/fslib';

/**
* Resolver that resolves workspace packages with a hard link reference and without
Expand Down
65 changes: 39 additions & 26 deletions packages/plugin-workspaces-export/sources/commands/export.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/// <reference types="@yarnpkg/plugin-pnp" />
import {BaseCommand, WorkspaceRequiredError} from "@yarnpkg/cli";
import {BaseCommand, WorkspaceRequiredError} from "@yarnpkg/cli";
import {getLibzipPromise} from '@yarnpkg/libzip';
import {packUtils} from "@yarnpkg/plugin-pack";
import {Command, Usage, Option} from "clipanion";

import {ExportCache} from '../ExportCache';
import {genPackTgz, makeExportDir, makeFetcher, makeGzipFromDirectory, makeResolver} from '../exportUtils';

import {
DEFAULT_LOCK_FILENAME,
Cache,
Expand All @@ -23,38 +30,43 @@ import {
ppath,
xfs,
} from "@yarnpkg/fslib";
import {getLibzipPromise} from '@yarnpkg/libzip';
import {packUtils} from "@yarnpkg/plugin-pack";
import {Command, Usage} from "clipanion";

import {ExportCache} from '../ExportCache';
import {genPackTgz, makeExportDir, makeFetcher, makeGzipFromDirectory, makeResolver} from '../exportUtils';

// eslint-disable-next-line arca/no-default-export
export default class WorkspacesExportCommand extends BaseCommand {
@Command.Rest()
workspaces: Array<string> = [];
workspaces: Array<string> = Option.Rest();

@Command.Boolean(`--json`, {description: `Format the output as an NDJSON stream`})
json: boolean = false;
json: boolean = Option.Boolean(`--json`, false, {description: `Format the output as an NDJSON stream`});

@Command.Boolean(`--production`, {description: `Only install regular dependencies by omitting dev dependencies`})
production: boolean = false;
production: boolean = Option.Boolean(
`--production`,
false,
{description: `Only install regular dependencies by omitting dev dependencies`}
);

@Command.Boolean(`--no-cache`, {description: `Do not cache archive contents in the configured \`exportCacheFolder\``})
noCache: boolean = false;
noCache: boolean = Option.Boolean(
`--no-cache`,
false,
{description: `Do not cache archive contents in the configured \`exportCacheFolder\``}
);

@Command.Boolean(`--install-if-needed`, {description: `Run a preliminary \`yarn install\` if a package contains build scripts`})
installIfNeeded: boolean = false;
installIfNeeded: boolean = Option.Boolean(
`--install-if-needed`,
false,
{description: `Run a preliminary \`yarn install\` if a package contains build scripts`}
);

@Command.Boolean(`--skip-pack-lifecycle`, {description: `Skip running \`yarn pack\` lifecycle scripts`})
skipPackLifecycle: boolean = false;
skipPackLifecycle: boolean = Option.Boolean(
`--skip-pack-lifecycle`,
false,
{description: `Skip running \`yarn pack\` lifecycle scripts`}
);

@Command.String(`--node-linker`, {description: `Override the project's nodeLinker option in the exported archive`})
nodeLinker?: string;
nodeLinker?: string = Option.String(
`--node-linker`,
{description: `Override the project's nodeLinker option in the exported archive`}
);

@Command.String(`-o,--out`, {description: `Create the archive at the specified path`})
out?: string;
out?: string = Option.String(`-o,--out`, {description: `Create the archive at the specified path`});

static usage: Usage = Command.Usage({
category: `Workspace-related commands`,
Expand Down Expand Up @@ -84,7 +96,8 @@ export default class WorkspacesExportCommand extends BaseCommand {
],
});

@Command.Path(`workspaces`, `export`)
static paths = [[`workspaces`, `export`]];

async execute() {
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
const {project, workspace} = await Project.find(configuration, this.context.cwd);
Expand Down Expand Up @@ -116,7 +129,7 @@ export default class WorkspacesExportCommand extends BaseCommand {
requiredWorkspaces.add(matchingWorkspace);
}
}
if (!await packUtils.hasPackScripts(workspace)) {
if (!(await packUtils.hasPackScripts(workspace))) {
requiredWorkspaces.delete(workspace);
}
}
Expand Down Expand Up @@ -196,7 +209,7 @@ export default class WorkspacesExportCommand extends BaseCommand {
persistProject: false,
});
await baseFs.removePromise(DEFAULT_LOCK_FILENAME);
await baseFs.removePromise(tmpConfiguration.get(`bstatePath`));
await baseFs.removePromise(tmpConfiguration.get(`installStatePath`));

if (target.endsWith(`.zip`)) {
report.reportJson({output: target, format: `zip`});
Expand Down
Loading

0 comments on commit fd0c808

Please sign in to comment.