Skip to content

Commit

Permalink
Merge pull request #150 from ext/bugfix/types-node-maxbuffer
Browse files Browse the repository at this point in the history
fix: ignore @types/node when verifying transitive engine constraints
  • Loading branch information
ext committed Jan 15, 2023
2 parents 547a9a9 + d9fed79 commit d8239f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/rules/verify-engine-constraint.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import PackageJson from "../types/package-json";
import * as npmInfoModule from "../utils/npm-info";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { npmInfoMockClear, npmInfoMockAdd } from "../utils/npm-info";
Expand Down Expand Up @@ -104,3 +105,16 @@ it("should not return error if all dependencies have matching constraints", asyn
npmInfoMockAdd("bar@1.0.0", { name: "bar", version: "1.0.0", engines: { node: ">= 12" } });
expect(await verifyEngineConstraint(pkg)).toEqual([]);
});

it("should ignore @types/node", async () => {
expect.assertions(1);
const pkg: PackageJson = {
name: "my-app",
version: "1.0.0",
dependencies: { "@types/node": "*" },
engines: { node: ">= 10" },
};
const npmInfo = jest.spyOn(npmInfoModule, "npmInfo");
await verifyEngineConstraint(pkg);
expect(npmInfo).not.toHaveBeenCalled();
});
8 changes: 8 additions & 0 deletions src/rules/verify-engine-constraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ const ruleId = "invalid-engine-constraint";
async function* getDeepDependencies(pkg: PackageJson, dependency?: string): AsyncGenerator<string> {
const pkgData = dependency ? await npmInfo(dependency) : pkg;
for (const [key, value] of Object.entries(pkgData.dependencies ?? {})) {
/* ignore this as this package is sometimes is present as version "*" which
* just yields way to many versions to handle causing MaxBuffer errors and
* there is another rule to make sure the outermost @types/node package
* matches the configured engines */
if (key === "@types/node") {
continue;
}

const deep = `${key}@${value}`;
yield deep;
yield* await getDeepDependencies(pkg, deep);
Expand Down

0 comments on commit d8239f3

Please sign in to comment.