Skip to content

Commit

Permalink
fix(run): Nx correctly detect if target dependencies default are set
Browse files Browse the repository at this point in the history
- follows Lerna's PR [3182](lerna/lerna#3182)
  • Loading branch information
ghiscoding committed Jun 19, 2022
1 parent 881a2ee commit 4720351
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
21 changes: 14 additions & 7 deletions packages/core/src/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
InitCommandOption,
PublishCommandOption,
RunCommandOption,
VersionCommandOption
VersionCommandOption,
} from './command-options';

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

export interface BaseChangelogOptions {
changelogPreset?: ChangelogPresetConfig;
Expand Down Expand Up @@ -148,10 +148,16 @@ export interface GitClient {
createRelease: (opts: GitClientRelease) => Promise<void>;
}

export type NpaResolveResult = (npa.FileResult | npa.HostedGitResult | npa.URLResult | npa.AliasResult | npa.RegistryResult) & {
export type NpaResolveResult = (
| npa.FileResult
| npa.HostedGitResult
| npa.URLResult
| npa.AliasResult
| npa.RegistryResult
) & {
explicitWorkspace?: boolean;
workspaceTarget?: string;
}
};

/** Passed between concurrent executions */
export interface OneTimePasswordCache {
Expand All @@ -167,10 +173,10 @@ export interface LernaConfig {
run?: RunCommandOption;
};
packages?: string[];
loglevel?: 'silent', 'error', 'warn', 'notice', 'http', 'timing', 'info', 'verbose', 'silly',
loglevel?: 'silent' | 'error' | 'warn' | 'notice' | 'http' | 'timing' | 'info' | 'verbose' | 'silly';

/** executable used to install dependencies (npm, yarn, pnpm, ...) */
npmClient?: 'npm' | 'pnpm' | 'yarn',
npmClient?: 'npm' | 'pnpm' | 'yarn';

/** enables integration with Yarn or other package manager that use `workspaces` property in `package.json` */
useWorkspaces?: boolean;
Expand All @@ -187,6 +193,7 @@ export interface ProjectConfig extends LernaConfig, QueryGraphConfig {
since?: string;
sort?: any;
stream?: boolean;
useNx?: boolean;
onRejected?: (result: any) => void;
onResolved?: (result: any) => void;
}
Expand All @@ -199,7 +206,7 @@ export interface RawManifest extends Package {
export interface ReleaseClient {
repos: {
createRelease: GitCreateReleaseFn;
}
};
}

export interface ReleaseCommandProps {
Expand Down
17 changes: 11 additions & 6 deletions packages/init/src/__tests__/init-command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import tempy from 'tempy';
const initFixture = require('@lerna-test/init-fixture')(__dirname);

// file under test
const lernaInit = require('@lerna-test/command-runner')(require('../../../cli/src/cli-commands/cli-init-commands'));
const lernaInit = require('@lerna-test/command-runner')(
require('../../../cli/src/cli-commands/cli-init-commands')
);
import { InitCommand } from '../index';
import { factory } from '../init-command';

Expand All @@ -25,7 +27,7 @@ const createArgv = (cwd: string, ...args: string[]) => {
};

describe('Init Command', () => {
const lernaVersion = "__TEST_VERSION__";
const lernaVersion = '__TEST_VERSION__';

it('should execute methods when initializing the command via its class', async () => {
const testDir = await initFixture('empty');
Expand Down Expand Up @@ -115,8 +117,8 @@ describe('Init Command', () => {
const [lernaJson, pkgJson, packagesDirExists, gitDirExists] = await Promise.all([
fs.readJSON(path.join(testDir, 'lerna.json')),
fs.readJSON(path.join(testDir, 'package.json')),
fs.exists(path.join(testDir, 'packages'), null),
fs.exists(path.join(testDir, '.git'), null),
fs.exists(path.join(testDir, 'packages'), null as any),
fs.exists(path.join(testDir, '.git'), null as any),
]);

expect(lernaJson).toMatchObject({
Expand Down Expand Up @@ -198,6 +200,7 @@ describe('Init Command', () => {
hoist: true,
},
},
useNx: false,
version: '1.2.3',
});
});
Expand All @@ -215,7 +218,7 @@ describe('Init Command', () => {
const [lernaJson, pkgJson, packagesDirExists] = await Promise.all([
fs.readJSON(path.join(testDir, 'lerna.json')),
fs.readJSON(path.join(testDir, 'package.json')),
fs.exists(path.join(testDir, 'packages'), null),
fs.exists(path.join(testDir, 'packages'), null as any),
]);

expect(lernaJson).toMatchObject({
Expand Down Expand Up @@ -319,6 +322,7 @@ describe('Init Command', () => {

expect(await fs.readJSON(lernaJsonPath)).toEqual({
packages: ['packages/*'],
useNx: false,
version: '1.2.3',
});
});
Expand Down Expand Up @@ -370,8 +374,9 @@ describe('Init Command', () => {
},
},
packages: ['packages/*'],
useNx: false,
version: '1.2.3',
});
});
});
});
});
4 changes: 2 additions & 2 deletions packages/init/src/init-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class InitCommand extends Command<InitCommandOption> {
version = '0.0.0';
}

const logMessage = (!projectVersion) ? 'Creating lerna.json' : 'Updating lerna.json';
const logMessage = !projectVersion ? 'Creating lerna.json' : 'Updating lerna.json';
this.logger.info('', logMessage);

delete config[LERNA_CLI_PKG_NAME]; // no longer relevant
Expand All @@ -115,7 +115,7 @@ export class InitCommand extends Command<InitCommandOption> {
initConfig.exact = true;
}

const lernaConfig: Partial<ProjectConfig> = { version };
const lernaConfig: Partial<ProjectConfig> = { useNx: false, version };
if (!this.options.useWorkspaces) {
lernaConfig.packages = ['packages/*'];
}
Expand Down
6 changes: 4 additions & 2 deletions packages/run/src/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ export class RunCommand extends Command<RunCommandOption & FilterOptions> {

async prepNxOptions() {
const { readNxJson } = await import('nx/src/config/configuration');
const targetDependenciesAreDefined = Object.keys(readNxJson().targetDependencies || {}).length > 0;
const nxJson = readNxJson();
const targetDependenciesAreDefined =
Object.keys(nxJson.targetDependencies || nxJson.targetDefaults || {}).length > 0;
const targetDependencies =
// prettier-ignore
this.toposort && !targetDependenciesAreDefined
Expand All @@ -277,7 +279,7 @@ export class RunCommand extends Command<RunCommandOption & FilterOptions> {
nxBail: this.bail,
nxIgnoreCycles: !this.options.rejectCycles,
skipNxCache: this.options.skipNxCache,
_: this.args,
_: this.args.map((t) => t.toString()),
};

return { targetDependencies, options };
Expand Down

0 comments on commit 4720351

Please sign in to comment.