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

fix: block lockfile behind flag until it's ready #28

Merged
merged 1 commit into from
Jan 2, 2024
Merged
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
72 changes: 49 additions & 23 deletions libs/core/src/true-affected.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,33 +241,59 @@ describe('trueAffected', () => {
expect(affected).toEqual(['angular-component']);
});

it('should find fils that are related to changed modules from lockfile', async () => {
jest.spyOn(git, 'getChangedFiles').mockReturnValue([
{
filePath: 'package-lock.json',
changedLines: [2],
},
]);
jest.spyOn(lockFiles, 'hasLockfileChanged').mockReturnValue(true);
jest.spyOn(lockFiles, 'findAffectedFilesByLockfile').mockReturnValue([
{
filePath: 'proj1/index.ts',
changedLines: [2],
},
]);

const affected = await trueAffected({
cwd,
base: 'main',
projects: [
describe('__experimentalLockfileCheck', () => {
it('should find files that are related to changed modules from lockfile if flag is on', async () => {
jest.spyOn(git, 'getChangedFiles').mockReturnValue([
{
name: 'proj1',
sourceRoot: 'proj1/',
filePath: 'package-lock.json',
changedLines: [2],
},
],
]);
jest.spyOn(lockFiles, 'hasLockfileChanged').mockReturnValue(true);
jest.spyOn(lockFiles, 'findAffectedFilesByLockfile').mockReturnValue([
{
filePath: 'proj1/index.ts',
changedLines: [2],
},
]);

const affected = await trueAffected({
cwd,
base: 'main',
__experimentalLockfileCheck: true,
projects: [
{
name: 'proj1',
sourceRoot: 'proj1/',
},
],
});

expect(affected).toEqual(['proj1']);
});

expect(affected).toEqual(['proj1']);
it('should not find files that are related to changed modules from lockfile if flag is off', async () => {
jest.spyOn(git, 'getChangedFiles').mockReturnValue([
{
filePath: 'package-lock.json',
changedLines: [2],
},
]);

const affected = await trueAffected({
cwd,
base: 'main',
__experimentalLockfileCheck: false,
projects: [
{
name: 'proj1',
sourceRoot: 'proj1/',
},
],
});

expect(affected).toEqual([]);
});
});

it("should ignore files when can't find the changed line", async () => {
Expand Down
3 changes: 2 additions & 1 deletion libs/core/src/true-affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const trueAffected = async ({
base = 'origin/main',
projects,
include = [DEFAULT_INCLUDE_TEST_FILES],
__experimentalLockfileCheck = false,
}: TrueAffected) => {
const project = new Project({
compilerOptions: {
Expand Down Expand Up @@ -87,7 +88,7 @@ export const trueAffected = async ({
);

let changedFilesByLockfile: ChangedFiles[] = [];
if (hasLockfileChanged(changedFiles)) {
if (__experimentalLockfileCheck && hasLockfileChanged(changedFiles)) {
changedFilesByLockfile = findAffectedFilesByLockfile(
cwd,
base,
Expand Down
3 changes: 3 additions & 0 deletions libs/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ export interface TrueAffected {
base?: string;
projects: TrueAffectedProject[];
include?: (string | RegExp)[];

// **experimental** - this is an experimental feature and may be removed or changed at any time
__experimentalLockfileCheck?: boolean;
}
2 changes: 2 additions & 0 deletions libs/nx/src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('cli', () => {
restArgs: [],
tsConfigFilePath: 'tsconfig.base.json',
target: [],
experimentalLockfileCheck: false,
});
});

Expand All @@ -95,6 +96,7 @@ describe('cli', () => {
restArgs: [],
tsConfigFilePath: 'tsconfig.json',
target: [],
experimentalLockfileCheck: false,
});
});
});
Expand Down
10 changes: 10 additions & 0 deletions libs/nx/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const affectedAction = async ({
tsConfigFilePath,
includeFiles,
target,
experimentalLockfileCheck,
}: AffectedOptions) => {
let projects = await getNxTrueAffectedProjects(cwd);

Expand All @@ -44,6 +45,7 @@ export const affectedAction = async ({
base,
projects,
include: [...includeFiles, DEFAULT_INCLUDE_TEST_FILES],
__experimentalLockfileCheck: experimentalLockfileCheck,
});

if (json) {
Expand Down Expand Up @@ -91,6 +93,7 @@ interface AffectedOptions {
includeFiles: string[];
restArgs: string[];
target: string[];
experimentalLockfileCheck?: boolean;
}

const affectedCommand: CommandModule<unknown, AffectedOptions> = {
Expand Down Expand Up @@ -138,6 +141,11 @@ const affectedCommand: CommandModule<unknown, AffectedOptions> = {
return array.flatMap((v) => v.split(',')).map((v) => v.trim());
},
},
experimentalLockfileCheck: {
desc: 'Experimental lockfile check',
type: 'boolean',
default: false,
},
},
handler: async ({
cwd,
Expand All @@ -148,6 +156,7 @@ const affectedCommand: CommandModule<unknown, AffectedOptions> = {
json,
includeFiles,
target,
experimentalLockfileCheck,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
$0,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -163,6 +172,7 @@ const affectedCommand: CommandModule<unknown, AffectedOptions> = {
json,
includeFiles,
target,
experimentalLockfileCheck,
restArgs: Object.entries(rest).map(
/* istanbul ignore next */
([key, value]) => `--${key}=${value}`
Expand Down