Skip to content

Commit

Permalink
feat(version): move all version related methods under version package (
Browse files Browse the repository at this point in the history
…#456)

* feat(version): move all version related methods under version package
  • Loading branch information
ghiscoding committed Jan 24, 2023
1 parent 0b79e4d commit 2c0921a
Show file tree
Hide file tree
Showing 108 changed files with 302 additions and 330 deletions.
2 changes: 0 additions & 2 deletions helpers/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import execa from 'execa';
import fileUrl from 'file-url';
import tempy from 'tempy';
Expand Down
2 changes: 1 addition & 1 deletion helpers/git/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import execa from 'execa';
import os from 'os';
import { tempWrite } from '@lerna-lite/core';
import { tempWrite } from '../../packages/version/src/utils/temp-write';
import path from 'path';
import cp from 'child_process';
import loadJsonFile from 'load-json-file';
Expand Down
6 changes: 1 addition & 5 deletions helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@
"description": "Private test helpers for the lerna-lite monorepo",
"main": "index.js",
"private": true,
"license": "MIT",
"dependencies": {
"@lerna-lite/cli": "workspace:*",
"@lerna-lite/core": "workspace:*"
}
"license": "MIT"
}
23 changes: 0 additions & 23 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,58 +33,35 @@
},
"dependencies": {
"@npmcli/run-script": "^6.0.0",
"@octokit/plugin-enterprise-rest": "^6.0.1",
"@octokit/rest": "^19.0.5",
"chalk": "^4.1.2",
"clone-deep": "^4.0.1",
"config-chain": "^1.1.13",
"conventional-changelog-angular": "^5.0.13",
"conventional-changelog-core": "^4.2.4",
"conventional-changelog-writer": "^5.0.1",
"conventional-commits-parser": "^3.2.4",
"conventional-recommended-bump": "^6.1.0",
"cosmiconfig": "^8.0.0",
"dedent": "^0.7.0",
"execa": "^5.1.1",
"fs-extra": "^11.1.0",
"get-stream": "^6.0.1",
"git-url-parse": "^13.1.0",
"glob-parent": "^6.0.2",
"globby": "^11.1.0",
"graceful-fs": "^4.2.10",
"inquirer": "^8.2.4",
"is-ci": "^3.0.1",
"is-stream": "^2.0.1",
"load-json-file": "^6.2.0",
"make-dir": "^3.1.0",
"minimatch": "^5.1.6",
"node-fetch": "^2.6.7",
"npm-package-arg": "^10.1.0",
"npmlog": "^7.0.1",
"p-map": "^4.0.0",
"p-queue": "^6.6.2",
"path": "^0.12.7",
"pify": "^5.0.0",
"resolve-from": "^5.0.0",
"semver": "^7.3.8",
"slash": "^3.0.0",
"strong-log-transformer": "^2.1.0",
"temp-dir": "^1.0.0",
"uuid": "^9.0.0",
"write-file-atomic": "^5.0.0",
"write-json-file": "^4.3.0",
"write-pkg": "^4.0.0"
},
"devDependencies": {
"@types/clone-deep": "^4.0.1",
"@types/conventional-changelog-core": "^4.2.1",
"@types/conventional-changelog-writer": "^4.0.2",
"@types/conventional-commits-parser": "^3.0.3",
"@types/conventional-recommended-bump": "^6.1.0",
"@types/dedent": "^0.7.0",
"@types/execa": "^2.0.0",
"@types/fs-extra": "^11.0.1",
"@types/git-url-parse": "^9.0.1",
"@types/glob-parent": "^5.1.1",
"@types/inquirer": "^9.0.3",
"@types/load-json-file": "^5.1.0",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const EOL = '\n';
4 changes: 1 addition & 3 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// folders
export * from './conventional-commits';
export * from './git-clients';
export * from './models';
export * from './package-graph';
export * from './project';
export * from './utils';

// files
export * from './child-process';
export * from './constants';
export * from './command';
export * from './otplease';
export * from './package';
export * from './prompt';
export * from './validation-error';
1 change: 0 additions & 1 deletion packages/core/src/models/command-options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { boolean } from 'yargs';
import { RemoteClientType } from './interfaces';

export interface ChangedCommandOption {
Expand Down
106 changes: 2 additions & 104 deletions packages/core/src/models/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { GitRawCommitsOptions, ParserOptions } from 'conventional-changelog-core';
import { Options as WriterOptions } from 'conventional-changelog-writer';
import { Options as RecommendedBumpOptions } from 'conventional-recommended-bump';
import log from 'npmlog';
import npa from 'npm-package-arg';

Expand All @@ -12,25 +9,6 @@ export type JsonArray = JsonValue[];
export type JsonPrimitive = string | number | boolean | null;
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;

export type VersioningStrategy = 'fixed' | 'independent';
export type ChangelogType = 'fixed' | 'independent' | 'root';
export type ChangelogPresetConfig = string | { name: string; [key: string]: unknown };

export interface BaseChangelogOptions {
changelogPreset?: ChangelogPresetConfig;
rootPath?: string;
tagPrefix?: string;
}

export interface ChangelogConfig {
conventionalChangelog: { parserOpts: ParserOptions; writerOpts: WriterOptions };
gitRawCommitsOpts: GitRawCommitsOptions & { path: string };
key?: string;
parserOpts: ParserOptions;
recommendedBumpOpts: RecommendedBumpOptions;
writerOpts: WriterOptions;
}

export interface CommandOptions {
rollPublish?: boolean;
rollVersion?: boolean;
Expand Down Expand Up @@ -94,21 +72,6 @@ export interface Manifest {
version: string;
}

export interface UpdateChangelogOption {
changelogHeaderMessage?: string;
changelogVersionMessage?: string;
changelogPreset?: string;
changelogIncludeCommitsGitAuthor?: boolean | string;
changelogIncludeCommitsClientLogin?: boolean | string;
commitsSinceLastRelease?: RemoteCommit[];
rootPath?: string;
tagPrefix?: string;
version?: string;

/** @deprecated this option was renamed to `changelogIncludeCommitsGitAuthor` */
changelogIncludeCommitAuthorFullname?: boolean | string;
}

export interface FetchConfig {
fetchRetries: number;
log: log.Logger;
Expand Down Expand Up @@ -153,30 +116,6 @@ export interface TopologicalConfig extends QueryGraphConfig {
concurrency?: number;
}

export interface GitClientReleaseOption {
owner: string;
repo: string;
tag_name: string;
name: string;
body?: string;
draft?: boolean;
prerelease?: boolean;
}

export type GitCreateReleaseFn = (options: GitClientReleaseOption) => Promise<{
ok: boolean;
status: string;
statusText: string;
}>;

export interface GitClient {
createRelease: (opts: GitClientReleaseOption) => Promise<void>;
}

export interface GitCreateReleaseClientOutput {
repos: GitClient;
}

export type NpaResolveResult = (
| npa.FileResult
| npa.HostedGitResult
Expand All @@ -188,12 +127,6 @@ export type NpaResolveResult = (
workspaceSpec?: string;
};

/** Passed between concurrent executions */
export interface OneTimePasswordCache {
/* The one-time password, passed as an option or received via prompt */
otp?: string | number;
}

export interface LernaConfig {
command?: {
init?: InitCommandOption;
Expand Down Expand Up @@ -261,43 +194,6 @@ export interface RawManifest extends Package {
publishConfig?: Record<'directory' | 'registry' | 'tag', string>;
}

export interface ReleaseClient {
repos: {
createRelease: GitCreateReleaseFn;
};
}

export interface ReleaseCommandProps {
tags: string[];
releaseNotes: ReleaseNote[];
}

export interface ReleaseOptions {
gitRemote: string;
execOpts: ExecOpts;
}

export interface ReleaseNote {
name: string;
notes?: string;
}

export type RemoteClientType = 'gitlab' | 'github';

export type RemoteCommit = {
/** git commit author name */
authorName: string;

/** remote client login (ie github login) */
login: string;

/** commit message headling (50 chars maxlen) */
message: string;

/** short commit hash (7 chars long) */
shortHash: string;
};

export interface UpdateCollectorOptions {
/** The semver bump keyword (patch/minor/major) or explicit version used */
bump?: string;
Expand All @@ -324,3 +220,5 @@ export interface UpdateCollectorOptions {
conventionalGraduate?: boolean | string;
excludeDependents?: boolean;
}

export type RemoteClientType = 'gitlab' | 'github';
2 changes: 0 additions & 2 deletions packages/core/src/utils/__tests__/describe-ref.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

jest.mock('../../child-process');

import * as childProcess from '../../child-process';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import { Package } from '../../../package';

jest.mock('../../describe-ref');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// helpers
import buildGraph from '../__helpers__/build-graph';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import { Package } from '../../../package';

// helpers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// file under test
import { getPackagesForOption } from '../lib/get-packages-for-option';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

jest.mock('../../../child-process');

// mocked modules
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export * from './query-graph';
export * from './run-lifecycle';
export * from './run-topologically';
export * from './string-utils';
export * from './temp-write';
export * from './types';
export * from './warn-if-hanging';
export * from './write-log-file';
2 changes: 0 additions & 2 deletions packages/publish/src/__tests__/create-temp-licenses.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import fs from 'fs-extra';
import path from 'path';
import { Project } from '@lerna-lite/core';
Expand Down
2 changes: 0 additions & 2 deletions packages/publish/src/__tests__/get-current-sha.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import { getCurrentSHA } from '../lib/get-current-sha';
import { initFixtureFactory } from '@lerna-test/helpers';
const initFixture = initFixtureFactory(__dirname);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import { Project } from '@lerna-lite/core';
import { getPackagesWithoutLicense } from '../lib/get-packages-without-license';
import { initFixtureFactory } from '@lerna-test/helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

jest.mock('pacote');

// mocked module(s)
Expand Down
2 changes: 1 addition & 1 deletion packages/publish/src/__tests__/npm-publish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('npm-publish', () => {
const mockTarData = Buffer.from('MOCK');
const mockManifest = { _normalized: true };

(fs.readFile as jest.Mock).mockName('fs.readFile').mockResolvedValue(mockTarData);
(fs.readFile as any).mockName('fs.readFile').mockResolvedValue(mockTarData);
(publish as jest.Mock).mockName('libnpmpublish').mockResolvedValue(null);
(readJSON as jest.Mock).mockName('read-package-json').mockImplementation((file, cb) => cb(null, mockManifest));
(runLifecycle as jest.Mock).mockName('@lerna-lite/core').mockResolvedValue(null);
Expand Down
10 changes: 8 additions & 2 deletions packages/publish/src/__tests__/publish-command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ jest.mock('../../../version/dist/lib/remote-branch-exists', () =>
jest.requireActual('../../../version/src/lib/__mocks__/remote-branch-exists')
);

// mocked modules of @lerna-lite/version
jest.mock('@lerna-lite/version', () => ({
...jest.requireActual('@lerna-lite/version'), // return the other real methods, below we'll mock only 2 of the methods
getOneTimePassword: jest.fn(),
}));

// mocked modules of @lerna-lite/core
jest.mock('@lerna-lite/core', () => ({
...jest.requireActual('@lerna-lite/core'), // return the other real methods, below we'll mock only 2 of the methods
Command: jest.requireActual('../../../core/src/command').Command,
conf: jest.requireActual('../../../core/src/command').conf,
collectUpdates: jest.requireActual('../../../core/src/__mocks__/collect-updates').collectUpdates,
throwIfUncommitted: jest.requireActual('../../../core/src/__mocks__/check-working-tree').throwIfUncommitted,
getOneTimePassword: jest.fn(),
logOutput: jest.requireActual('../../../core/src/__mocks__/output').logOutput,
promptConfirmation: jest.requireActual('../../../core/src/__mocks__/prompt').promptConfirmation,
promptSelectOne: jest.requireActual('../../../core/src/__mocks__/prompt').promptSelectOne,
Expand Down Expand Up @@ -66,10 +71,11 @@ const lernaPublish = commandRunner(cliCommands);
import yargParser from 'yargs-parser';

// mocked or stubbed modules
import { collectUpdates } from '@lerna-lite/core';
import { getOneTimePassword } from '@lerna-lite/version';
import { npmPublish } from '../lib/npm-publish';
import { npmPublish as npmPublishMock } from '../lib/__mocks__/npm-publish';
import { promptConfirmation, PublishCommandOption } from '@lerna-lite/core';
import { getOneTimePassword, collectUpdates } from '@lerna-lite/core';
import { packDirectory } from '../lib/pack-directory';
import { getNpmUsername } from '../lib/get-npm-username';
import { verifyNpmPackageAccess } from '../lib/verify-npm-package-access';
Expand Down
2 changes: 0 additions & 2 deletions packages/publish/src/__tests__/publish-licenses.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// FIXME: better mock for version command
jest.mock('../../../version/dist/lib/git-push', () =>
jest.requireActual('../../../version/src/lib/__mocks__/git-push')
Expand Down
2 changes: 1 addition & 1 deletion packages/publish/src/lib/npm-dist-tag.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { OneTimePasswordCache, otplease } from '@lerna-lite/version';
import log from 'npmlog';
import npa from 'npm-package-arg';
import fetch from 'npm-registry-fetch';

import { OneTimePasswordCache, otplease } from '@lerna-lite/core';
import { DistTagOptions } from '../models';

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/publish/src/lib/npm-publish.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LifecycleConfig, Package, RawManifest, runLifecycle } from '@lerna-lite/core';
import { OneTimePasswordCache, otplease } from '@lerna-lite/version';
import fs from 'fs-extra';
import log from 'npmlog';
import npa from 'npm-package-arg';
Expand All @@ -6,7 +8,6 @@ import pify from 'pify';
import { publish } from 'libnpmpublish';
import readJSON from 'read-package-json';

import { LifecycleConfig, OneTimePasswordCache, otplease, Package, RawManifest, runLifecycle } from '@lerna-lite/core';
import { LibNpmPublishOptions, PackagePublishConfig } from '../models';

const readJSONAsync = pify(readJSON);
Expand Down

0 comments on commit 2c0921a

Please sign in to comment.