@monoweave/publish 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +9 -0
- package/lib/commitPublishChanges.d.ts +14 -0
- package/lib/commitPublishChanges.js +101 -0
- package/lib/createReleaseGitTags.d.ts +7 -0
- package/lib/createReleaseGitTags.js +24 -0
- package/lib/determineGitTags.d.ts +6 -0
- package/lib/determineGitTags.js +24 -0
- package/lib/getPublishConfig.d.ts +7 -0
- package/lib/getPublishConfig.js +53 -0
- package/lib/getWorkspacesToPublish.d.ts +7 -0
- package/lib/getWorkspacesToPublish.js +22 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +84 -0
- package/lib/lifecycleExecutor.d.ts +9 -0
- package/lib/lifecycleExecutor.js +31 -0
- package/lib/pack.d.ts +11 -0
- package/lib/pack.js +79 -0
- package/package.json +62 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
<!-- MONOWEAVE:BELOW -->
|
|
4
|
+
|
|
5
|
+
## [0.0.2](https://github.com/monoweave/monoweave/compare/@monoweave/publish@0.0.1...@monoweave/publish@0.0.2) "@monoweave/publish" (2024-02-29)<a name="0.0.2"></a>
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* initial commit, forked from tophat/monodeploy under Apache 2.0 license (#1) ([2410d1c](https://github.com/monoweave/monoweave/commits/2410d1c))
|
|
10
|
+
|
|
11
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type MonoweaveConfiguration, type YarnContext } from '@monoweave/types';
|
|
2
|
+
export declare const createPublishCommit: ({ config, context, gitTags, }: {
|
|
3
|
+
config: MonoweaveConfiguration;
|
|
4
|
+
context: YarnContext;
|
|
5
|
+
gitTags?: Map<string, string> | undefined;
|
|
6
|
+
}) => Promise<{
|
|
7
|
+
headSha: string;
|
|
8
|
+
} | undefined>;
|
|
9
|
+
export declare const pushPublishCommit: ({ config, context, gitTags, dryRun, }: {
|
|
10
|
+
config: MonoweaveConfiguration;
|
|
11
|
+
context: YarnContext;
|
|
12
|
+
gitTags?: Map<string, string> | undefined;
|
|
13
|
+
dryRun?: boolean | undefined;
|
|
14
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pushPublishCommit = exports.createPublishCommit = void 0;
|
|
7
|
+
const git_1 = require("@monoweave/git");
|
|
8
|
+
const logging_1 = __importDefault(require("@monoweave/logging"));
|
|
9
|
+
const createReleaseGitTags_1 = __importDefault(require("./createReleaseGitTags"));
|
|
10
|
+
const createPublishCommit = async ({ config, context, gitTags, }) => {
|
|
11
|
+
if (config.dryRun) {
|
|
12
|
+
logging_1.default.info('[Publish] Creating publish commit', {
|
|
13
|
+
report: context?.report,
|
|
14
|
+
});
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
if (config.git.tag && gitTags?.size && !config.persistVersions) {
|
|
18
|
+
// If not using persistVersions, we'll attach the git tag to the commit
|
|
19
|
+
// that we're running monoweave against since this marks the commit as the
|
|
20
|
+
// "last one published". This informs later monoweave runs so that they don't republish
|
|
21
|
+
// the changes.
|
|
22
|
+
await (0, createReleaseGitTags_1.default)({
|
|
23
|
+
config,
|
|
24
|
+
context,
|
|
25
|
+
gitTags,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (config.autoCommit) {
|
|
29
|
+
const globs = [];
|
|
30
|
+
if (config.persistVersions) {
|
|
31
|
+
// Push package.json and related changes
|
|
32
|
+
globs.push('yarn.lock', 'package.json', '**/package.json', '.pnp.*');
|
|
33
|
+
}
|
|
34
|
+
if (config.changelogFilename) {
|
|
35
|
+
// Push changelog changes
|
|
36
|
+
globs.push(config.changelogFilename.replace('<packageDir>', '**'));
|
|
37
|
+
}
|
|
38
|
+
const files = globs.length ? await (0, git_1.gitGlob)(globs, { cwd: config.cwd, context }) : [];
|
|
39
|
+
if (files.length) {
|
|
40
|
+
await (0, git_1.gitAdd)(files, { cwd: config.cwd, context });
|
|
41
|
+
await (0, git_1.gitCommit)(config.autoCommitMessage, { cwd: config.cwd, context });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (config.git.push && config.autoCommit) {
|
|
45
|
+
await (0, git_1.gitPull)({
|
|
46
|
+
cwd: config.cwd,
|
|
47
|
+
remote: config.git.remote,
|
|
48
|
+
context,
|
|
49
|
+
autostash: true,
|
|
50
|
+
strategyOption: 'theirs',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (config.git.tag && gitTags?.size && config.persistVersions) {
|
|
54
|
+
// If using persistVersions, we attach the git tag to the commit with
|
|
55
|
+
// the modified package.json files and changelogs. This does mean that we are
|
|
56
|
+
// subject to a race condition where 2 changes going out at the same time might
|
|
57
|
+
// result in the latter change missing commits. This is an inherent flaw with using
|
|
58
|
+
// git tags to determine the last publish checkpoint.
|
|
59
|
+
await (0, createReleaseGitTags_1.default)({
|
|
60
|
+
config,
|
|
61
|
+
context,
|
|
62
|
+
gitTags,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return { headSha: await (0, git_1.gitResolveSha)('HEAD', { cwd: config.cwd, context }) };
|
|
66
|
+
};
|
|
67
|
+
exports.createPublishCommit = createPublishCommit;
|
|
68
|
+
const pushPublishCommit = async ({ config, context, gitTags, dryRun = config.dryRun, }) => {
|
|
69
|
+
if (!config.git.push) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (config.autoCommit) {
|
|
73
|
+
await (0, git_1.gitPush)({
|
|
74
|
+
cwd: config.cwd,
|
|
75
|
+
remote: config.git.remote,
|
|
76
|
+
context,
|
|
77
|
+
dryRun,
|
|
78
|
+
});
|
|
79
|
+
if (config.git.tag && gitTags?.size) {
|
|
80
|
+
await (0, git_1.gitPushTags)({
|
|
81
|
+
cwd: config.cwd,
|
|
82
|
+
remote: config.git.remote,
|
|
83
|
+
context,
|
|
84
|
+
dryRun,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
if (config.git.tag && gitTags?.size) {
|
|
90
|
+
// Push tags only outside of auto-commit mode, otherwise
|
|
91
|
+
// we'll push them after we push the commit
|
|
92
|
+
await (0, git_1.gitPushTags)({
|
|
93
|
+
cwd: config.cwd,
|
|
94
|
+
remote: config.git.remote,
|
|
95
|
+
context,
|
|
96
|
+
dryRun,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
exports.pushPublishCommit = pushPublishCommit;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MonoweaveConfiguration, YarnContext } from '@monoweave/types';
|
|
2
|
+
declare function createReleaseGitTags({ config, context, gitTags, }: {
|
|
3
|
+
config: MonoweaveConfiguration;
|
|
4
|
+
context: YarnContext;
|
|
5
|
+
gitTags: Map<string, string>;
|
|
6
|
+
}): Promise<void>;
|
|
7
|
+
export default createReleaseGitTags;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const git_1 = require("@monoweave/git");
|
|
7
|
+
const logging_1 = __importDefault(require("@monoweave/logging"));
|
|
8
|
+
async function createReleaseGitTags({ config, context, gitTags, }) {
|
|
9
|
+
// packages in a group share the same tag
|
|
10
|
+
const tags = new Set(gitTags.values());
|
|
11
|
+
for (const tag of tags) {
|
|
12
|
+
try {
|
|
13
|
+
if (!config.dryRun) {
|
|
14
|
+
await (0, git_1.gitTag)(tag, { cwd: config.cwd, context });
|
|
15
|
+
}
|
|
16
|
+
logging_1.default.info(`[Tag] ${tag}`, { report: context.report });
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
logging_1.default.error(`[Tag] Failed ${tag}`, { report: context.report });
|
|
20
|
+
logging_1.default.error(err, { report: context.report });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.default = createReleaseGitTags;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PackageVersionMap } from '@monoweave/types';
|
|
2
|
+
declare function determineGitTags({ versions, workspaceGroups, }: {
|
|
3
|
+
versions: PackageVersionMap;
|
|
4
|
+
workspaceGroups: Map<string, Set<string>>;
|
|
5
|
+
}): Promise<Map<string, string>>;
|
|
6
|
+
export default determineGitTags;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
async function determineGitTags({ versions, workspaceGroups, }) {
|
|
4
|
+
const groupByPackageName = new Map();
|
|
5
|
+
for (const [groupKey, group] of workspaceGroups.entries()) {
|
|
6
|
+
for (const packageName of group) {
|
|
7
|
+
groupByPackageName.set(packageName, groupKey);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const tags = [...versions.entries()].map((packageVersionEntry) => {
|
|
11
|
+
const [packageName, packageVersion] = packageVersionEntry;
|
|
12
|
+
const name = groupByPackageName.get(packageName) ?? packageName;
|
|
13
|
+
const tag = `${name}@${packageVersion}`;
|
|
14
|
+
return [packageName, tag];
|
|
15
|
+
});
|
|
16
|
+
const packageTags = new Map();
|
|
17
|
+
for (const tag of tags) {
|
|
18
|
+
if (!tag)
|
|
19
|
+
continue;
|
|
20
|
+
packageTags.set(tag[0], tag[1]);
|
|
21
|
+
}
|
|
22
|
+
return packageTags;
|
|
23
|
+
}
|
|
24
|
+
exports.default = determineGitTags;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type MonoweaveConfiguration, type YarnContext } from '@monoweave/types';
|
|
2
|
+
import { type Workspace } from '@yarnpkg/core';
|
|
3
|
+
export declare const getPublishRegistryUrl: ({ config, context, workspace, }: {
|
|
4
|
+
config: MonoweaveConfiguration;
|
|
5
|
+
context: YarnContext;
|
|
6
|
+
workspace: Workspace;
|
|
7
|
+
}) => Promise<string | null>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getPublishRegistryUrl = void 0;
|
|
27
|
+
const io_1 = require("@monoweave/io");
|
|
28
|
+
const types_1 = require("@monoweave/types");
|
|
29
|
+
const pluginNPM = __importStar(require("@yarnpkg/plugin-npm"));
|
|
30
|
+
const getPublishRegistryUrl = async ({ config, context, workspace, }) => {
|
|
31
|
+
const groupName = (0, io_1.resolveGroupName)({
|
|
32
|
+
context,
|
|
33
|
+
workspace,
|
|
34
|
+
packageGroupManifestField: config.packageGroupManifestField,
|
|
35
|
+
});
|
|
36
|
+
if (groupName) {
|
|
37
|
+
const registryMode = config.packageGroups?.[groupName]?.registryMode ?? config.registryMode;
|
|
38
|
+
if (registryMode === types_1.RegistryMode.Manifest) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (!groupName && config.registryMode === types_1.RegistryMode.Manifest) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const configRegistryUrl = config.registryUrl;
|
|
46
|
+
if (configRegistryUrl) {
|
|
47
|
+
return pluginNPM.npmConfigUtils.normalizeRegistry(configRegistryUrl);
|
|
48
|
+
}
|
|
49
|
+
return await pluginNPM.npmConfigUtils.getPublishRegistry(workspace.manifest, {
|
|
50
|
+
configuration: context.configuration,
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
exports.getPublishRegistryUrl = getPublishRegistryUrl;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ChangesetSchema, YarnContext } from '@monoweave/types';
|
|
2
|
+
import { type Workspace } from '@yarnpkg/core';
|
|
3
|
+
declare const getWorkspacesToPublish: ({ context, changeset, }: {
|
|
4
|
+
context: YarnContext;
|
|
5
|
+
changeset: ChangesetSchema;
|
|
6
|
+
}) => Promise<Set<Workspace>>;
|
|
7
|
+
export default getWorkspacesToPublish;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@yarnpkg/core");
|
|
4
|
+
const getWorkspacesToPublish = async ({ context, changeset, }) => {
|
|
5
|
+
const workspacesByIdent = context.project.workspaces.reduce((workspacesMap, current) => {
|
|
6
|
+
const manifestName = current.manifest.name;
|
|
7
|
+
if (manifestName) {
|
|
8
|
+
const ident = core_1.structUtils.stringifyIdent(manifestName);
|
|
9
|
+
workspacesMap.set(ident, current);
|
|
10
|
+
}
|
|
11
|
+
return workspacesMap;
|
|
12
|
+
}, new Map());
|
|
13
|
+
const workspacesToRelease = new Set();
|
|
14
|
+
for (const packageName of Object.keys(changeset)) {
|
|
15
|
+
const workspace = workspacesByIdent.get(packageName);
|
|
16
|
+
if (workspace && !workspace.manifest.private) {
|
|
17
|
+
workspacesToRelease.add(workspace);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return workspacesToRelease;
|
|
21
|
+
};
|
|
22
|
+
exports.default = getWorkspacesToPublish;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MonoweaveConfiguration, YarnContext } from '@monoweave/types';
|
|
2
|
+
import { type Workspace } from '@yarnpkg/core';
|
|
3
|
+
import determineGitTags from './determineGitTags';
|
|
4
|
+
import getWorkspacesToPublish from './getWorkspacesToPublish';
|
|
5
|
+
export { pushPublishCommit, createPublishCommit } from './commitPublishChanges';
|
|
6
|
+
export { determineGitTags, getWorkspacesToPublish };
|
|
7
|
+
export declare const publishPackages: ({ config, context, workspaces, publishCommitSha, }: {
|
|
8
|
+
config: MonoweaveConfiguration;
|
|
9
|
+
context: YarnContext;
|
|
10
|
+
workspaces: Set<Workspace>;
|
|
11
|
+
publishCommitSha?: string | undefined;
|
|
12
|
+
}) => Promise<void>;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.publishPackages = exports.getWorkspacesToPublish = exports.determineGitTags = exports.createPublishCommit = exports.pushPublishCommit = void 0;
|
|
7
|
+
const dependencies_1 = require("@monoweave/dependencies");
|
|
8
|
+
const p_limit_1 = __importDefault(require("p-limit"));
|
|
9
|
+
const determineGitTags_1 = __importDefault(require("./determineGitTags"));
|
|
10
|
+
exports.determineGitTags = determineGitTags_1.default;
|
|
11
|
+
const getWorkspacesToPublish_1 = __importDefault(require("./getWorkspacesToPublish"));
|
|
12
|
+
exports.getWorkspacesToPublish = getWorkspacesToPublish_1.default;
|
|
13
|
+
const lifecycleExecutor_1 = require("./lifecycleExecutor");
|
|
14
|
+
const pack_1 = require("./pack");
|
|
15
|
+
var commitPublishChanges_1 = require("./commitPublishChanges");
|
|
16
|
+
Object.defineProperty(exports, "pushPublishCommit", { enumerable: true, get: function () { return commitPublishChanges_1.pushPublishCommit; } });
|
|
17
|
+
Object.defineProperty(exports, "createPublishCommit", { enumerable: true, get: function () { return commitPublishChanges_1.createPublishCommit; } });
|
|
18
|
+
const publishPackages = async ({ config, context, workspaces, publishCommitSha, }) => {
|
|
19
|
+
const limitPublish = (0, p_limit_1.default)(config.maxConcurrentWrites || 1);
|
|
20
|
+
const publishTag = config.prerelease ? config.prereleaseNPMTag : 'latest';
|
|
21
|
+
const limit = (0, p_limit_1.default)(config.jobs || Infinity);
|
|
22
|
+
const groups = config.topological || config.topologicalDev
|
|
23
|
+
? await (0, dependencies_1.getTopologicalSort)(workspaces, {
|
|
24
|
+
dev: config.topologicalDev,
|
|
25
|
+
})
|
|
26
|
+
: [[...workspaces]];
|
|
27
|
+
const executeLifecycle = (0, lifecycleExecutor_1.createWorkspaceLifecycleExecutor)({ limit, groups, config, context });
|
|
28
|
+
/**
|
|
29
|
+
* Lifecycle: Prepublish
|
|
30
|
+
*
|
|
31
|
+
* Called before packing even starts. NPM will execute this lifecycle script
|
|
32
|
+
* on installs, so it's not recommended to place publish-only scripts here.
|
|
33
|
+
*
|
|
34
|
+
* This is deprecated by NPM in favour of prepublishOnly, however Yarn Modern does
|
|
35
|
+
* not implement prepublishOnly and only implements prepublish.
|
|
36
|
+
*/
|
|
37
|
+
await executeLifecycle('prepublish');
|
|
38
|
+
/**
|
|
39
|
+
* Lifecycle: Prepare
|
|
40
|
+
*
|
|
41
|
+
* This is not called by Yarn but called by NPM and by Lerna prior to packing.
|
|
42
|
+
* It is not recommended to use this lifecycle hook for compiling.
|
|
43
|
+
*/
|
|
44
|
+
await executeLifecycle('prepare');
|
|
45
|
+
/**
|
|
46
|
+
* Lifecycle: Prepublish Only
|
|
47
|
+
*
|
|
48
|
+
* This is not directly supported by Yarn Modern, however was introduced by NPM as
|
|
49
|
+
* a replacement for the deprecated "Prepublish".
|
|
50
|
+
*/
|
|
51
|
+
await executeLifecycle('prepublishOnly');
|
|
52
|
+
/**
|
|
53
|
+
* Lifecycle: Prepack
|
|
54
|
+
*
|
|
55
|
+
* The prepack script should be used to compile packages, e.g.
|
|
56
|
+
* transpiling TypeScript to JavaScript.
|
|
57
|
+
*/
|
|
58
|
+
await executeLifecycle('prepack');
|
|
59
|
+
try {
|
|
60
|
+
/**
|
|
61
|
+
* In "pack", we create the package archives and publish to the registry.
|
|
62
|
+
*/
|
|
63
|
+
await executeLifecycle((workspace) => (0, pack_1.pack)({ workspace, limitPublish, config, context, publishTag, publishCommitSha }));
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
try {
|
|
67
|
+
/**
|
|
68
|
+
* Lifecycle: Postpack
|
|
69
|
+
*
|
|
70
|
+
* Guaranteed to execute after packing the archive.
|
|
71
|
+
*/
|
|
72
|
+
await executeLifecycle('postpack');
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
/**
|
|
76
|
+
* Lifecycle: Postpublish
|
|
77
|
+
*
|
|
78
|
+
* Guaranteed to execute _after_ postpack.
|
|
79
|
+
*/
|
|
80
|
+
await executeLifecycle('postpublish');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
exports.publishPackages = publishPackages;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MonoweaveConfiguration, YarnContext } from '@monoweave/types';
|
|
2
|
+
import { type Workspace } from '@yarnpkg/core';
|
|
3
|
+
import type pLimit from 'p-limit';
|
|
4
|
+
export declare function createWorkspaceLifecycleExecutor({ limit, config, groups, context, }: {
|
|
5
|
+
limit: pLimit.Limit;
|
|
6
|
+
config: MonoweaveConfiguration;
|
|
7
|
+
context: YarnContext;
|
|
8
|
+
groups: Workspace[][];
|
|
9
|
+
}): (script: string | ((workspace: Workspace) => Promise<void>)) => Promise<void>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWorkspaceLifecycleExecutor = void 0;
|
|
4
|
+
const io_1 = require("@monoweave/io");
|
|
5
|
+
function createWorkspaceLifecycleExecutor({ limit, config, groups, context, }) {
|
|
6
|
+
async function executeInGroups(callback) {
|
|
7
|
+
await groups.reduce((chain, group) => chain.then(async () => {
|
|
8
|
+
// We'll wait for all promises to settle so we don't have runaway 'processes'
|
|
9
|
+
const results = await Promise.allSettled(group.map((workspace) => limit(() => callback(workspace))));
|
|
10
|
+
const rejections = results.filter((result) => result.status === 'rejected');
|
|
11
|
+
if (rejections.length) {
|
|
12
|
+
// We'll throw the first one for now.
|
|
13
|
+
// This can be improved in the future.
|
|
14
|
+
throw rejections[0].reason;
|
|
15
|
+
}
|
|
16
|
+
}), Promise.resolve());
|
|
17
|
+
}
|
|
18
|
+
async function executeLifecycle(script) {
|
|
19
|
+
await executeInGroups((workspace) => {
|
|
20
|
+
if (typeof script === 'function') {
|
|
21
|
+
return script(workspace);
|
|
22
|
+
}
|
|
23
|
+
return (0, io_1.maybeExecuteWorkspaceLifecycleScript)(context, workspace, script, {
|
|
24
|
+
cwd: workspace.cwd,
|
|
25
|
+
dryRun: config.dryRun,
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return executeLifecycle;
|
|
30
|
+
}
|
|
31
|
+
exports.createWorkspaceLifecycleExecutor = createWorkspaceLifecycleExecutor;
|
package/lib/pack.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MonoweaveConfiguration, YarnContext } from '@monoweave/types';
|
|
2
|
+
import { type Workspace } from '@yarnpkg/core';
|
|
3
|
+
import type pLimit from 'p-limit';
|
|
4
|
+
export declare const pack: ({ workspace, limitPublish, config, context, publishTag, publishCommitSha, }: {
|
|
5
|
+
workspace: Workspace;
|
|
6
|
+
limitPublish: pLimit.Limit;
|
|
7
|
+
publishTag: string;
|
|
8
|
+
config: MonoweaveConfiguration;
|
|
9
|
+
context: YarnContext;
|
|
10
|
+
publishCommitSha: string | undefined;
|
|
11
|
+
}) => Promise<void>;
|
package/lib/pack.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.pack = void 0;
|
|
27
|
+
const logging_1 = __importStar(require("@monoweave/logging"));
|
|
28
|
+
const core_1 = require("@yarnpkg/core");
|
|
29
|
+
const plugin_npm_1 = require("@yarnpkg/plugin-npm");
|
|
30
|
+
const plugin_pack_1 = require("@yarnpkg/plugin-pack");
|
|
31
|
+
const getPublishConfig_1 = require("./getPublishConfig");
|
|
32
|
+
const pack = async ({ workspace, limitPublish, config, context, publishTag, publishCommitSha, }) => {
|
|
33
|
+
const ident = workspace.manifest.name;
|
|
34
|
+
if (!ident)
|
|
35
|
+
return;
|
|
36
|
+
const pkgName = core_1.structUtils.stringifyIdent(ident);
|
|
37
|
+
const registryUrl = await (0, getPublishConfig_1.getPublishRegistryUrl)({
|
|
38
|
+
config,
|
|
39
|
+
context,
|
|
40
|
+
workspace,
|
|
41
|
+
});
|
|
42
|
+
if (!registryUrl) {
|
|
43
|
+
logging_1.default.info(`[Publish] '${pkgName}' (${publishTag}: ${workspace.manifest.version}, skipping registry)`, { report: context.report });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const globalAccess = config.access;
|
|
47
|
+
const access = globalAccess === 'infer' ? undefined : globalAccess;
|
|
48
|
+
logging_1.default.info(`[Publish] ${pkgName} (${publishTag}: ${workspace.manifest.version}, ${registryUrl}; ${access})`, { report: context.report });
|
|
49
|
+
const filesToPack = await plugin_pack_1.packUtils.genPackList(workspace);
|
|
50
|
+
const pack = await plugin_pack_1.packUtils.genPackStream(workspace, filesToPack);
|
|
51
|
+
const buffer = await core_1.miscUtils.bufferStream(pack);
|
|
52
|
+
const body = await plugin_npm_1.npmPublishUtils.makePublishBody(workspace, buffer, {
|
|
53
|
+
access,
|
|
54
|
+
tag: publishTag,
|
|
55
|
+
registry: registryUrl,
|
|
56
|
+
gitHead: publishCommitSha,
|
|
57
|
+
});
|
|
58
|
+
const identUrl = plugin_npm_1.npmHttpUtils.getIdentUrl(ident);
|
|
59
|
+
try {
|
|
60
|
+
if (!config.dryRun) {
|
|
61
|
+
(0, logging_1.assertProductionOrTest)();
|
|
62
|
+
await limitPublish(() => plugin_npm_1.npmHttpUtils.put(identUrl, body, {
|
|
63
|
+
authType: plugin_npm_1.npmHttpUtils.AuthType.ALWAYS_AUTH,
|
|
64
|
+
configuration: context.project.configuration,
|
|
65
|
+
ident,
|
|
66
|
+
registry: registryUrl,
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
logging_1.default.info(`[Publish] '${pkgName}' published.`, { report: context.report });
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
logging_1.default.error(err, {
|
|
73
|
+
report: context.report,
|
|
74
|
+
extras: `[Publish] Failed to publish '${pkgName}' to ${identUrl} (${publishTag}: ${body['dist-tags']?.[publishTag]}, ${registryUrl}; ${body.access})`,
|
|
75
|
+
});
|
|
76
|
+
throw err;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.pack = pack;
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@monoweave/publish",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/monoweave/monoweave.git",
|
|
7
|
+
"directory": "packages/publish"
|
|
8
|
+
},
|
|
9
|
+
"author": {
|
|
10
|
+
"name": "noahnu",
|
|
11
|
+
"url": "https://monoweave.github.io"
|
|
12
|
+
},
|
|
13
|
+
"license": "BSD-3",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"main": "./lib/index.js",
|
|
16
|
+
"registry": "https://registry.npmjs.org/",
|
|
17
|
+
"types": "./lib/index.d.ts",
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"group": "monoweave",
|
|
21
|
+
"files": [
|
|
22
|
+
"lib"
|
|
23
|
+
],
|
|
24
|
+
"main": "./lib/index.js",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"clean": "run workspace:clean \"$(pwd)\"",
|
|
27
|
+
"types:watch": "run workspace:types:watch \"$(pwd)\"",
|
|
28
|
+
"test:watch": "run workspace:test:watch \"$(pwd)\"",
|
|
29
|
+
"build:watch": "run workspace:build:watch \"$(pwd)\"",
|
|
30
|
+
"prepack": "run workspace:build \"$(pwd)\""
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"p-limit": "^3.1.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@monoweave/dependencies": "0.0.2",
|
|
37
|
+
"@monoweave/git": "0.0.2",
|
|
38
|
+
"@monoweave/io": "0.0.2",
|
|
39
|
+
"@monoweave/logging": "0.0.2",
|
|
40
|
+
"@monoweave/test-utils": "link:../../testUtils",
|
|
41
|
+
"@monoweave/types": "0.0.2",
|
|
42
|
+
"@types/jest": "^29.5.6",
|
|
43
|
+
"@yarnpkg/cli": "^4.1.0",
|
|
44
|
+
"@yarnpkg/core": "^4.0.3",
|
|
45
|
+
"@yarnpkg/fslib": "^3.0.2",
|
|
46
|
+
"@yarnpkg/plugin-npm": "^3.0.1",
|
|
47
|
+
"@yarnpkg/plugin-pack": "^4.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@monoweave/dependencies": "^0.0.2",
|
|
51
|
+
"@monoweave/git": "^0.0.2",
|
|
52
|
+
"@monoweave/io": "^0.0.2",
|
|
53
|
+
"@monoweave/logging": "^0.0.2",
|
|
54
|
+
"@monoweave/types": "^0.0.2",
|
|
55
|
+
"@yarnpkg/cli": "^4.1.0",
|
|
56
|
+
"@yarnpkg/core": "^4.0.3",
|
|
57
|
+
"@yarnpkg/fslib": "^3.0.2",
|
|
58
|
+
"@yarnpkg/plugin-npm": "^3.0.1",
|
|
59
|
+
"@yarnpkg/plugin-pack": "^4.0.0"
|
|
60
|
+
},
|
|
61
|
+
"types": "./lib/index.d.ts"
|
|
62
|
+
}
|