Skip to content

Commit 6d81596

Browse files
committed
feat: only use new flow on feature flag
1 parent eaf6043 commit 6d81596

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

lib/dep-graph-builders/npm-lock-v2/index.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ export const parseNpmLockV2Project = async (
2929
pkgLockContent: string,
3030
options: ProjectParseOptions,
3131
): Promise<DepGraph> => {
32-
const { includeDevDeps, strictOutOfSync, includeOptionalDeps } = options;
32+
const {
33+
includeDevDeps,
34+
strictOutOfSync,
35+
includeOptionalDeps,
36+
pruneNpmStrictOutOfSync,
37+
} = options;
3338

3439
const pkgJson: PackageJsonBase = parsePkgJson(pkgJsonContent);
3540
const pkgs = extractPkgsFromNpmLockV2(pkgLockContent);
@@ -38,6 +43,7 @@ export const parseNpmLockV2Project = async (
3843
includeDevDeps,
3944
includeOptionalDeps,
4045
strictOutOfSync,
46+
pruneNpmStrictOutOfSync,
4147
});
4248

4349
return depgraph;
@@ -48,8 +54,12 @@ export const buildDepGraphNpmLockV2 = async (
4854
pkgJson: PackageJsonBase,
4955
options: DepGraphBuildOptions,
5056
): Promise<DepGraph> => {
51-
const { includeDevDeps, strictOutOfSync, includeOptionalDeps } = options;
52-
57+
const {
58+
includeDevDeps,
59+
strictOutOfSync,
60+
includeOptionalDeps,
61+
pruneNpmStrictOutOfSync,
62+
} = options;
5363
const depGraphBuilder = new DepGraphBuilder(
5464
{ name: 'npm' },
5565
{ name: pkgJson.name as string, version: pkgJson.version },
@@ -101,6 +111,7 @@ export const buildDepGraphNpmLockV2 = async (
101111
[],
102112
pkgKeysByName,
103113
pkgJson.overrides,
114+
pruneNpmStrictOutOfSync,
104115
);
105116
return depGraphBuilder.build();
106117
};
@@ -123,6 +134,7 @@ const dfsVisit = async (
123134
ancestry: Ancestry[],
124135
pkgKeysByName: Map<string, string[]>,
125136
overrides: Overrides | undefined,
137+
pruneNpmStrictOutOfSync?: boolean,
126138
): Promise<void> => {
127139
visitedMap.add(node.id);
128140

@@ -149,6 +161,7 @@ const dfsVisit = async (
149161
],
150162
pkgKeysByName,
151163
overrides,
164+
pruneNpmStrictOutOfSync,
152165
);
153166

154167
if (!visitedMap.has(childNode.id)) {
@@ -189,6 +202,7 @@ const getChildNode = (
189202
ancestry: Ancestry[],
190203
pkgKeysByName: Map<string, string[]>,
191204
overrides?: Overrides,
205+
pruneNpmStrictOutOfSync?: boolean,
192206
) => {
193207
let version = depInfo.version;
194208

@@ -210,6 +224,7 @@ const getChildNode = (
210224
ancestry,
211225
pkgs,
212226
pkgKeysByName,
227+
pruneNpmStrictOutOfSync,
213228
);
214229

215230
if (!childNodeKey) {
@@ -292,6 +307,7 @@ export const getChildNodeKey = (
292307
ancestry: { name: string; key: string; inBundle: boolean }[],
293308
pkgs: Record<string, NpmLockPkg>,
294309
pkgKeysByName: Map<string, string[]>,
310+
pruneNpmStrictOutOfSync?: boolean,
295311
): string | undefined => {
296312
// This is a list of all our possible options for the childKey
297313
const candidateKeys = pkgKeysByName.get(name);
@@ -306,8 +322,10 @@ export const getChildNodeKey = (
306322
if (
307323
semver.validRange(version) &&
308324
pkgs[candidateKeys[0]].version &&
309-
!semver.satisfies(pkgs[candidateKeys[0]].version, version)
325+
!semver.satisfies(pkgs[candidateKeys[0]].version, version) &&
326+
pruneNpmStrictOutOfSync
310327
) {
328+
//TODO: Add some logs to monitor
311329
return undefined;
312330
}
313331
return candidateKeys[0];

lib/dep-graph-builders/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type DepGraphBuildOptions = {
3434
includeOptionalDeps: boolean;
3535
strictOutOfSync: boolean;
3636
includePeerDeps?: boolean;
37+
pruneNpmStrictOutOfSync?: boolean;
3738
};
3839

3940
export type LockFileParseOptions = {

test/jest/dep-graph-builders/npm-lock-v2.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ describe('dep-graph-builder npm-lock-v2', () => {
439439
).rejects.toThrow(new OutOfSyncError('[email protected]', LockfileType.npm));
440440
});
441441

442-
it('project: simple-out-of-sync -> throws OutOfSyncError', async () => {
442+
it('should throw error on out of sync with prune ff', async () => {
443443
const fixtureName = 'simple-out-of-sync';
444444
const pkgJsonContent = readFileSync(
445445
join(__dirname, `./fixtures/npm-lock-v2/${fixtureName}/package.json`),
@@ -458,6 +458,7 @@ describe('dep-graph-builder npm-lock-v2', () => {
458458
includeOptionalDeps: true,
459459
pruneCycles: true,
460460
strictOutOfSync: true,
461+
pruneNpmStrictOutOfSync: true,
461462
}),
462463
).rejects.toThrow(new OutOfSyncError('[email protected]', LockfileType.npm));
463464
});

0 commit comments

Comments
 (0)