Skip to content

Commit 01b34f7

Browse files
authored
test: add test for exclusion of private package from report (#73)
* test: add test for exclusion of private package from report * docs: describe private package handling
1 parent f986bf6 commit 01b34f7

7 files changed

Lines changed: 36 additions & 2 deletions

File tree

docs/docs/docs/programmatic-usage.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ This tool (and in turn, the CLI and RN plugins) do not support `file:` specified
114114
If you would like to have support for this, please start a discussion on Github.
115115
:::
116116

117+
#### Private packages
118+
119+
All private packages (i.e., packages that have a `private: true` field in their `package.json`) are excluded from the scan. All their dependencies (all kinds of dependencies) also are **not included** in the scan / report. Therefore, all the tooling ignores private packages & their dependencies.
120+
121+
:::warning
122+
If you are using a private package that introduces dependencies to your bundle / program, remember it itself & its dependencies won't be included.
123+
:::
124+
117125
### Default `scanOptionsFactory` value
118126

119127
The default value for the optional `scanOptionsFactory` parameter in `scanPackage` & `scanDependencies` functions is set to the following:

examples/node-example/__tests__/report.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ import {
2121
optionalDependencies as optionalDependenciesObj,
2222
} from '../package.json';
2323

24-
const dependencies = dependencyMappingToCorrespondingKey(dependenciesObj);
24+
// do not expect the private test package to be in the assertions baseline, it shall be excluded
25+
const dependencies = dependencyMappingToCorrespondingKey(dependenciesObj).filter(
26+
(dep) => dep !== '@callstack/example-private-package@workspace:*',
27+
);
2528
const devDependencies = dependencyMappingToCorrespondingKey(devDependenciesObj);
2629
const optionalDependencies = dependencyMappingToCorrespondingKey(optionalDependenciesObj);
2730
const licenseKitDependencies = dependencyMappingToCorrespondingKey(licenseKitDependenciesObj);
@@ -80,6 +83,12 @@ describe('license-kit report', () => {
8083
);
8184
});
8285

86+
it("does not include private packages' licenses", async () => {
87+
const json = await runReportCommandForJsonOutput();
88+
89+
expect(Object.keys(json).toSorted()).not.toIncludeAllMembers(['@callstack/example-private-package']);
90+
});
91+
8392
it('with root-only dev deps and with transitive dependencies of workspace-specifier-only dependencies', async () => {
8493
const json = await runReportCommandForJsonOutput([
8594
'--dev-deps-mode',

examples/node-example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"test": "jest"
1010
},
1111
"dependencies": {
12+
"@callstack/example-private-package": "workspace:*",
1213
"dhtmlx-gantt": "9.0.11",
1314
"is-even": "1.0.0",
1415
"mariadb": "3.4.2",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @callstack/example-private-package
2+
3+
This is a test private package (`private: true`) for the needs of example tester projects in this monorepository to depend on, to test that the private package's license is not being included in the report.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "@callstack/example-private-package",
3+
"packageManager": "yarn@3.6.1",
4+
"private": true
5+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"packages": [
55
"packages/*",
66
"docs",
7-
"examples/*"
7+
"examples/*",
8+
"examples/packages/*"
89
]
910
},
1011
"scripts": {

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4177,6 +4177,12 @@ __metadata:
41774177
languageName: node
41784178
linkType: hard
41794179

4180+
"@callstack/example-private-package@workspace:*, @callstack/example-private-package@workspace:examples/packages/example-private-package":
4181+
version: 0.0.0-use.local
4182+
resolution: "@callstack/example-private-package@workspace:examples/packages/example-private-package"
4183+
languageName: unknown
4184+
linkType: soft
4185+
41804186
"@callstack/licenses@^0.2.1, @callstack/licenses@workspace:packages/licenses-api":
41814187
version: 0.0.0-use.local
41824188
resolution: "@callstack/licenses@workspace:packages/licenses-api"
@@ -15681,6 +15687,7 @@ __metadata:
1568115687
"@babel/core": 7.27.4
1568215688
"@babel/preset-env": 7.27.2
1568315689
"@babel/preset-typescript": 7.27.1
15690+
"@callstack/example-private-package": "workspace:*"
1568415691
"@types/jest": 29.5.5
1568515692
babel-jest: 29.7.0
1568615693
chartjs-plugin-dragdata: 2.3.1

0 commit comments

Comments
 (0)