Skip to content

Commit

Permalink
clean up todos
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Apr 25, 2024
1 parent 45479dc commit 81946a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
17 changes: 8 additions & 9 deletions packages/compat/src/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class Audit {
}
};

private load = async (id: string): Promise<Finding[] | { content: string | Buffer; type: ContentType }> => {
private load = async (id: string): Promise<{ content: string | Buffer; type: ContentType } | undefined> => {
let content: string | Buffer;
if (this.virtualModules.has(id)) {
content = this.virtualModules.get(id)!;
Expand Down Expand Up @@ -310,19 +310,18 @@ export class Audit {
return isNamespaceMarker(name) || target.isCJS || target.isAMD || target.exports.includes(name);
}

private handleJSON(filename: string, content: Buffer | string): { content: string; type: ContentType } | Finding[] {
private handleJSON(filename: string, content: Buffer | string): { content: string; type: ContentType } | undefined {
let js;
try {
let structure = JSON.parse(content.toString('utf8'));
js = `export default ${JSON.stringify(structure)}`;
} catch (err) {
return [
{
filename,
message: `failed to parse JSON`,
detail: err.toString().replace(filename, explicitRelative(this.originAppRoot, filename)),
},
];
this.findings.push({
filename,
message: `failed to parse JSON`,
detail: err.toString().replace(filename, explicitRelative(this.originAppRoot, filename)),
});
return;
}
return { content: js, type: 'javascript' };
}
Expand Down
15 changes: 6 additions & 9 deletions packages/compat/src/module-visitor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// TODO: split this so we have the import-analysis part as part of
// module-visitor and Audit adds its problem-detectoin stuff in the (optional)
// babel config
import { explicitRelative } from '@embroider/core';
import {
type CodeFrameStorage,
Expand All @@ -13,7 +10,6 @@ import fromPairs from 'lodash/fromPairs';
import assertNever from 'assert-never';
import { JSDOM } from 'jsdom';

// TODO: this is an audit concern
import type { Finding } from './audit';
import type { TransformOptions } from '@babel/core';

Expand Down Expand Up @@ -91,12 +87,10 @@ export interface Import {
interface VisitorParams {
base: string;
resolveId: (specifier: string, fromFile: string) => Promise<string | undefined>;
// TODO: remove Finding[] from this type
load: (id: string) => Promise<Finding[] | { content: string | Buffer; type: ContentType }>;
load: (id: string) => Promise<{ content: string | Buffer; type: ContentType } | undefined>;
entrypoints: string[];
debug?: boolean;

// TODO: remove below this point
findings: Finding[];
frames: CodeFrameStorage;
babelConfig: TransformOptions;
Expand All @@ -116,8 +110,7 @@ class ModuleVisitor {
private base: string;
private debugEnabled: boolean;
private resolveId: (specifier: string, fromFile: string) => Promise<string | undefined>;
// TODO: remove Finding[] from return type
private load: (id: string) => Promise<Finding[] | { content: string | Buffer; type: ContentType }>;
private load: (id: string) => Promise<{ content: string | Buffer; type: ContentType } | undefined>;
private entrypoints: string[];

constructor(private params: VisitorParams) {
Expand Down Expand Up @@ -149,6 +142,10 @@ class ModuleVisitor {
}
continue;
}
// if the load hook returned undefined we need to just skip it
if (loaded === undefined) {
continue;
}
let { content, type } = loaded;

let visitor = this.visitorFor(type);
Expand Down

0 comments on commit 81946a0

Please sign in to comment.