Skip to content

Commit 39a6caa

Browse files
authored
fix: block lockfile behind flag until it's ready (#28)
1 parent 684b4b2 commit 39a6caa

File tree

5 files changed

+66
-24
lines changed

5 files changed

+66
-24
lines changed

libs/core/src/true-affected.spec.ts

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -241,33 +241,59 @@ describe('trueAffected', () => {
241241
expect(affected).toEqual(['angular-component']);
242242
});
243243

244-
it('should find fils that are related to changed modules from lockfile', async () => {
245-
jest.spyOn(git, 'getChangedFiles').mockReturnValue([
246-
{
247-
filePath: 'package-lock.json',
248-
changedLines: [2],
249-
},
250-
]);
251-
jest.spyOn(lockFiles, 'hasLockfileChanged').mockReturnValue(true);
252-
jest.spyOn(lockFiles, 'findAffectedFilesByLockfile').mockReturnValue([
253-
{
254-
filePath: 'proj1/index.ts',
255-
changedLines: [2],
256-
},
257-
]);
258-
259-
const affected = await trueAffected({
260-
cwd,
261-
base: 'main',
262-
projects: [
244+
describe('__experimentalLockfileCheck', () => {
245+
it('should find files that are related to changed modules from lockfile if flag is on', async () => {
246+
jest.spyOn(git, 'getChangedFiles').mockReturnValue([
263247
{
264-
name: 'proj1',
265-
sourceRoot: 'proj1/',
248+
filePath: 'package-lock.json',
249+
changedLines: [2],
266250
},
267-
],
251+
]);
252+
jest.spyOn(lockFiles, 'hasLockfileChanged').mockReturnValue(true);
253+
jest.spyOn(lockFiles, 'findAffectedFilesByLockfile').mockReturnValue([
254+
{
255+
filePath: 'proj1/index.ts',
256+
changedLines: [2],
257+
},
258+
]);
259+
260+
const affected = await trueAffected({
261+
cwd,
262+
base: 'main',
263+
__experimentalLockfileCheck: true,
264+
projects: [
265+
{
266+
name: 'proj1',
267+
sourceRoot: 'proj1/',
268+
},
269+
],
270+
});
271+
272+
expect(affected).toEqual(['proj1']);
268273
});
269274

270-
expect(affected).toEqual(['proj1']);
275+
it('should not find files that are related to changed modules from lockfile if flag is off', async () => {
276+
jest.spyOn(git, 'getChangedFiles').mockReturnValue([
277+
{
278+
filePath: 'package-lock.json',
279+
changedLines: [2],
280+
},
281+
]);
282+
283+
const affected = await trueAffected({
284+
cwd,
285+
base: 'main',
286+
__experimentalLockfileCheck: false,
287+
projects: [
288+
{
289+
name: 'proj1',
290+
sourceRoot: 'proj1/',
291+
},
292+
],
293+
});
294+
295+
expect(affected).toEqual([]);
296+
});
271297
});
272298

273299
it("should ignore files when can't find the changed line", async () => {

libs/core/src/true-affected.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const trueAffected = async ({
2727
base = 'origin/main',
2828
projects,
2929
include = [DEFAULT_INCLUDE_TEST_FILES],
30+
__experimentalLockfileCheck = false,
3031
}: TrueAffected) => {
3132
const project = new Project({
3233
compilerOptions: {
@@ -87,7 +88,7 @@ export const trueAffected = async ({
8788
);
8889

8990
let changedFilesByLockfile: ChangedFiles[] = [];
90-
if (hasLockfileChanged(changedFiles)) {
91+
if (__experimentalLockfileCheck && hasLockfileChanged(changedFiles)) {
9192
changedFilesByLockfile = findAffectedFilesByLockfile(
9293
cwd,
9394
base,

libs/core/src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ export interface TrueAffected {
1212
base?: string;
1313
projects: TrueAffectedProject[];
1414
include?: (string | RegExp)[];
15+
16+
// **experimental** - this is an experimental feature and may be removed or changed at any time
17+
__experimentalLockfileCheck?: boolean;
1518
}

libs/nx/src/cli.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe('cli', () => {
7272
restArgs: [],
7373
tsConfigFilePath: 'tsconfig.base.json',
7474
target: [],
75+
experimentalLockfileCheck: false,
7576
});
7677
});
7778

@@ -95,6 +96,7 @@ describe('cli', () => {
9596
restArgs: [],
9697
tsConfigFilePath: 'tsconfig.json',
9798
target: [],
99+
experimentalLockfileCheck: false,
98100
});
99101
});
100102
});

libs/nx/src/cli.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const affectedAction = async ({
2424
tsConfigFilePath,
2525
includeFiles,
2626
target,
27+
experimentalLockfileCheck,
2728
}: AffectedOptions) => {
2829
let projects = await getNxTrueAffectedProjects(cwd);
2930

@@ -44,6 +45,7 @@ export const affectedAction = async ({
4445
base,
4546
projects,
4647
include: [...includeFiles, DEFAULT_INCLUDE_TEST_FILES],
48+
__experimentalLockfileCheck: experimentalLockfileCheck,
4749
});
4850

4951
if (json) {
@@ -91,6 +93,7 @@ interface AffectedOptions {
9193
includeFiles: string[];
9294
restArgs: string[];
9395
target: string[];
96+
experimentalLockfileCheck?: boolean;
9497
}
9598

9699
const affectedCommand: CommandModule<unknown, AffectedOptions> = {
@@ -138,6 +141,11 @@ const affectedCommand: CommandModule<unknown, AffectedOptions> = {
138141
return array.flatMap((v) => v.split(',')).map((v) => v.trim());
139142
},
140143
},
144+
experimentalLockfileCheck: {
145+
desc: 'Experimental lockfile check',
146+
type: 'boolean',
147+
default: false,
148+
},
141149
},
142150
handler: async ({
143151
cwd,
@@ -148,6 +156,7 @@ const affectedCommand: CommandModule<unknown, AffectedOptions> = {
148156
json,
149157
includeFiles,
150158
target,
159+
experimentalLockfileCheck,
151160
// eslint-disable-next-line @typescript-eslint/no-unused-vars
152161
$0,
153162
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -163,6 +172,7 @@ const affectedCommand: CommandModule<unknown, AffectedOptions> = {
163172
json,
164173
includeFiles,
165174
target,
175+
experimentalLockfileCheck,
166176
restArgs: Object.entries(rest).map(
167177
/* istanbul ignore next */
168178
([key, value]) => `--${key}=${value}`

0 commit comments

Comments
 (0)