Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't include devDependencies in analysis (resolves #43) #51

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/khaki-moons-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@open-pioneer/vite-plugin-pioneer": major
---

**Breaking Change:** A trails package's `devDependencies` are no longer included in the build (fixes #43).
For normal dependencies, service classes are automatically picked up and compiled into the application.

This behavior is surprising for `devDependencies`: license scanners and cve scanner sometimes chose to exclude
`devDependencies`; which would have been invalid prior to this change (as the code was compiled in anyway).

If your package depends on another trails package at runtime, configure an entry in `peerDependencies` instead.
6 changes: 4 additions & 2 deletions packages/vite-plugin/src/codegenPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ describe("codegen support", function () {
});

/*
* Normal deps, Dev deps, required peer dependencies and installed optional dependencies
* Normal deps,required peer dependencies and installed optional dependencies
* are discovered. Non-existing optional peer dependencies and non existing
* optional dependencies are not an error.
*
* Code from dev dependencies not is not automatically included.
*/
const testAppJs = readFileSync(join(outDir, "test-app.js"), "utf-8");
assert.include(testAppJs, `console.log("from normal dep");`);
assert.include(testAppJs, `console.log("from dev dep");`);
assert.notInclude(testAppJs, `console.log("from dev dep");`);
assert.include(testAppJs, `console.log("from peer dep");`);
assert.include(testAppJs, `console.log("from optional dep");`);
});
Expand Down
17 changes: 2 additions & 15 deletions packages/vite-plugin/src/metadata/loadPackageMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class PackageMetadataReader {
version: packageVersion,
dependencies,
frameworkMetadata
} = await parsePackageJson(packageJsonPath, mode);
} = await parsePackageJson(packageJsonPath);

// The package config is read either from the package's build.config.mjs (for source packages)
// or from a package's serialized metadata in its package.json (for published packages).
Expand Down Expand Up @@ -288,7 +288,7 @@ class PackageMetadataReader {
}
}

async function parsePackageJson(packageJsonPath: string, mode: "local" | "external") {
async function parsePackageJson(packageJsonPath: string) {
if (!(await fileExists(packageJsonPath))) {
throw new ReportableError(`Expected a 'package.json' file at ${packageJsonPath}`);
}
Expand Down Expand Up @@ -330,13 +330,6 @@ async function parsePackageJson(packageJsonPath: string, mode: "local" | "extern
);
}

const devDependencies = packageJsonContent.devDependencies ?? {};
if (typeof devDependencies !== "object") {
throw new ReportableError(
`Expected a valid 'devDependencies' object in ${packageJsonPath}`
);
}

const deps = new Map<string, PackageDependency>();
const addDep = (packageName: string, optional: boolean) => {
let dep = deps.get(packageName);
Expand All @@ -363,12 +356,6 @@ async function parsePackageJson(packageJsonPath: string, mode: "local" | "extern
addDep(depName, true);
}

if (mode === "local") {
for (const depName of Object.keys(devDependencies)) {
addDep(depName, false);
}
}

const frameworkMetadata = packageJsonContent[PackageMetadataV1.PACKAGE_JSON_KEY] ?? undefined;
return {
name: packageName,
Expand Down