Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/chubby-apes-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nodesecure/tarball": patch
---

Properly implement metadata.relativePath across EFA and DependencyCollectableSet
2 changes: 1 addition & 1 deletion workspaces/rc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"ajv": "8.18.0"
},
"dependencies": {
"@nodesecure/js-x-ray": "14.1.0",
"@nodesecure/js-x-ray": "14.2.0",
"@nodesecure/npm-types": "^1.2.0",
"@nodesecure/vulnera": "3.0.0",
"@openally/config": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/scanner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@nodesecure/contact": "^3.0.0",
"@nodesecure/flags": "^3.0.3",
"@nodesecure/i18n": "^4.1.0",
"@nodesecure/js-x-ray": "14.1.0",
"@nodesecure/js-x-ray": "14.2.0",
"@nodesecure/mama": "^2.1.1",
"@nodesecure/npm-registry-sdk": "^4.4.0",
"@nodesecure/npm-types": "^1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion workspaces/tarball/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"dependencies": {
"@nodesecure/conformance": "^1.2.1",
"@nodesecure/fs-walk": "^2.0.0",
"@nodesecure/js-x-ray": "14.1.0",
"@nodesecure/js-x-ray": "14.2.0",
"@nodesecure/mama": "^2.1.1",
"@nodesecure/npm-types": "^1.2.0",
"@nodesecure/utils": "^2.3.0",
Expand Down
59 changes: 45 additions & 14 deletions workspaces/tarball/src/class/DependencyCollectableSet.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ const kExternalThirdPartyDeps = new Set([
]);
const kRelativeImportPath = new Set([".", "..", "./", "../"]);

type Metadata = Dependency & { relativeFile: string; };
export type DependencyCollectableSetMetadata = Dependency & {
relativeFile: string;
};

export class DependencyCollectableSet implements CollectableSet<Metadata> {
export class DependencyCollectableSet implements CollectableSet<DependencyCollectableSetMetadata> {
type = "dependency";
dependencies: Record<
string,
Expand All @@ -121,7 +123,9 @@ export class DependencyCollectableSet implements CollectableSet<Metadata> {
#mama: Pick<ManifestManager, "dependencies" | "devDependencies" | "nodejsImports">;
#hasExternalCapacity: boolean = false;

constructor(mama: Pick<ManifestManager, "dependencies" | "devDependencies" | "nodejsImports">) {
constructor(
mama: Pick<ManifestManager, "dependencies" | "devDependencies" | "nodejsImports">
) {
this.#mama = mama;
}

Expand Down Expand Up @@ -151,8 +155,15 @@ export class DependencyCollectableSet implements CollectableSet<Metadata> {
};
}

add(value: string, { metadata }: CollectableInfos<Metadata>) {
const relativeFile = metadata?.relativeFile!;
add(
value: string,
{ metadata }: CollectableInfos<DependencyCollectableSetMetadata>
) {
if (!metadata) {
return;
}

const relativeFile = metadata.relativeFile;
if (!(relativeFile in this.dependencies)) {
this.dependencies[relativeFile] = Object.create(null);
}
Expand All @@ -165,7 +176,10 @@ export class DependencyCollectableSet implements CollectableSet<Metadata> {
if (metadata?.inTry) {
this.#dependenciesInTryBlock.add(value);
}
const filtered = this.#filerDependencyByKind(value, relativeFile);
const filtered = this.#filerDependencyByKind(
value,
path.dirname(relativeFile)
);

if (filtered.file) {
this.#files.add(filtered.file);
Expand All @@ -178,7 +192,7 @@ export class DependencyCollectableSet implements CollectableSet<Metadata> {

#filerDependencyByKind(
dependency: string,
relativeFileLocation: string = ""
relativeFileLocation: string
) {
const firstChar = dependency.charAt(0);

Expand All @@ -202,13 +216,21 @@ export class DependencyCollectableSet implements CollectableSet<Metadata> {

return { package: dependency };
}
relativeFileLocation: string;

#analyzeDependency(sourceDependency: string, inTry: boolean) {
#analyzeDependency(
sourceDependency: string,
inTry: boolean
) {
if (this.#values.has(sourceDependency)) {
return;
}
const { dependencies, devDependencies, nodejsImports = {} } = this.#mama;

const {
dependencies,
devDependencies,
nodejsImports = {}
} = this.#mama;

let thirdPartyAliasedDependency: string | undefined;
// See: https://nodejs.org/api/packages.html#subpath-imports
if (this.#isAliasFileModule(sourceDependency) && sourceDependency in nodejsImports) {
Expand All @@ -233,7 +255,10 @@ export class DependencyCollectableSet implements CollectableSet<Metadata> {
this.#thirdPartyDependencies.add(name);
}

if (thirdPartyDependency && this.#isMissingDependency(thirdPartyDependency, thirdPartyAliasedDependency)) {
if (
thirdPartyDependency &&
this.#isMissingDependency(thirdPartyDependency, thirdPartyAliasedDependency)
) {
this.#missingDependencies.add(thirdPartyDependency);
}

Expand All @@ -254,7 +279,10 @@ export class DependencyCollectableSet implements CollectableSet<Metadata> {
}
}

#extractDependencyName(sourceDependency: string, dependencies: string[]) {
#extractDependencyName(
sourceDependency: string,
dependencies: string[]
) {
for (const dependency of dependencies) {
if (dependency === sourceDependency) {
return sourceDependency;
Expand All @@ -268,7 +296,10 @@ export class DependencyCollectableSet implements CollectableSet<Metadata> {
return parseNpmSpec(sourceDependency)?.name ?? sourceDependency;
}

#isMissingDependency(thirdPartyDependency: string, thirdPartyAliasedDependency: string | undefined) {
#isMissingDependency(
thirdPartyDependency: string,
thirdPartyAliasedDependency: string | undefined
) {
const { dependencies, nodejsImports = {} } = this.#mama;

return !dependencies.includes(thirdPartyDependency) &&
Expand Down Expand Up @@ -306,7 +337,7 @@ export class DependencyCollectableSet implements CollectableSet<Metadata> {
alias: string,
nodeImports: Record<string, string | NodeImport>
): [string, string] {
const importEntry = nodeImports[alias]!;
const importEntry = nodeImports[alias];

return typeof importEntry === "string" ?
[alias, importEntry] :
Expand Down
5 changes: 5 additions & 0 deletions workspaces/tarball/src/class/SourceCodeScanner.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ export class SourceCodeScanner<
for await (const fileReport of efa.analyse(absoluteEntryFiles, {
metadata: {
spec: this.manifest.spec
},
fileMetadata: (absoluteFile) => {
const relativeFile = path.relative(location, absoluteFile);

return { relativeFile };
}
})) {
report.push(fileReport);
Expand Down
Loading
Loading