Skip to content

Commit

Permalink
Add test + fixture for updated module resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Mar 28, 2024
1 parent 47ff3eb commit 478ab3f
Show file tree
Hide file tree
Showing 26 changed files with 136 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "@fixture/exports-in-file-shorthand",
"name": "@fixtures/exports-in-file-shorthand",
"version": "*"
}
2 changes: 1 addition & 1 deletion packages/knip/fixtures/plugins/typescript2/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@fixture/typescript2",
"name": "@fixtures/typescript2",
"workspaces": [
"packages/*"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"$schema": "http://json.schemastore.org/package",
"name": "@fixture/typescript2-lib"
"name": "@fixtures/typescript2-lib"
}
3 changes: 3 additions & 0 deletions packages/knip/fixtures/workspaces-dts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
.DS_Store
3 changes: 3 additions & 0 deletions packages/knip/fixtures/workspaces-dts/apps/app-a/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { usedFunction } from "@kp/shared";

console.log(usedFunction());
9 changes: 9 additions & 0 deletions packages/knip/fixtures/workspaces-dts/apps/app-a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@kp/app-a",
"version": "0.0.0",
"private": true,
"type": "module",
"dependencies": {
"@kp/shared": "*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["**/*.js"],
"exclude": []
}
3 changes: 3 additions & 0 deletions packages/knip/fixtures/workspaces-dts/apps/app-b/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { usedFunction } from "@kp/shared";

console.log(usedFunction());
9 changes: 9 additions & 0 deletions packages/knip/fixtures/workspaces-dts/apps/app-b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@kp/app-b",
"version": "0.0.0",
"private": true,
"type": "module",
"dependencies": {
"@kp/shared": "*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["**/*.js"],
"exclude": []
}
10 changes: 10 additions & 0 deletions packages/knip/fixtures/workspaces-dts/knip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('knip').KnipConfig} */
const config = {
workspaces: {
'packages/shared': {
includeEntryExports: true,
},
},
};

export default config;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions packages/knip/fixtures/workspaces-dts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@fixtures/workspaces-dts",
"version": "0.0.0",
"private": true,
"workspaces": [
"apps/*",
"packages/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { unusedFunction } from "./unused-function.js";
export { usedFunction } from "./used-function.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function unusedFunction(): string;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function usedFunction(): string;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@kp/shared",
"version": "0.0.0",
"private": true,
"main": "src/index.js",
"types": "build/index.d.ts",
"type": "module"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { unusedFunction } from "./unused-function.js";
export { usedFunction } from "./used-function.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const unusedFunction = () => "bar";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const usedFunction = () => "bar";
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"emitDeclarationOnly": true,
"outDir": "build"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.json",
"exclude": ["build"],
"include": ["**/*.js"]
}
18 changes: 18 additions & 0 deletions packages/knip/fixtures/workspaces-dts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"include": ["./**/*.js"],
"exclude": ["node_modules", "apps", "packages"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": true,
"checkJs": true,
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"skipLibCheck": true,
"esModuleInterop": true,
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"noPropertyAccessFromIndexSignature": true
}
}
24 changes: 24 additions & 0 deletions packages/knip/test/workspaces-dts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { main } from '../src/index.js';
import { resolve } from '../src/util/path.js';
import baseArguments from './helpers/baseArguments.js';
import baseCounters from './helpers/baseCounters.js';

const cwd = resolve('fixtures/workspaces-dts');

test('Find unused un-built exports across workspaces', async () => {
const { issues, counters } = await main({
...baseArguments,
cwd,
});

assert(issues.exports['packages/shared/src/index.js']['unusedFunction']);

assert.deepEqual(counters, {
...baseCounters,
exports: 1,
processed: 7,
total: 7,
});
});

0 comments on commit 478ab3f

Please sign in to comment.