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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"url": "git+https://github.com/e18e/cli.git"
},
"keywords": [
"e18e",
"attw",
"e18e",
"dependencies",
"dependency",
"publint"
Expand Down
31 changes: 5 additions & 26 deletions src/analyze/publint.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,25 @@
import {publint} from 'publint';
import {formatMessage} from 'publint/utils';
import type {ReportPluginResult, Options, AnalysisContext} from '../types.js';
import fs from 'node:fs/promises';
import path from 'node:path';
import type {ReportPluginResult, AnalysisContext} from '../types.js';

export async function runPublint(
context: AnalysisContext
): Promise<ReportPluginResult> {
const targetTarballs = context.options?.targetTarball;

if (targetTarballs && targetTarballs.length > 0) {
return runPublintWithTarballs(targetTarballs, context.options);
}

return {messages: []};
}

export async function runPublintWithTarballs(
targetTarballs: string[],
options?: Options
): Promise<ReportPluginResult> {
const result: ReportPluginResult = {
messages: []
};
const root = options?.root || process.cwd();

for (const targetTarball of targetTarballs) {
const targetTarballPath = path.resolve(root, targetTarball);
// TODO (jg): handle failed reads gracefully
const buffer = await fs.readFile(targetTarballPath);
const tarball = buffer.buffer.slice(
buffer.byteOffset,
buffer.byteOffset + buffer.byteLength
) as ArrayBuffer;
const publintResult = await publint({pack: {tarball}});
try {
const publintResult = await publint({pack: 'auto', pkgDir: context.root});
for (const problem of publintResult.messages) {
result.messages.push({
severity: problem.type,
score: 0,
message: formatMessage(problem, publintResult.pkg) ?? ''
});
}
} catch (error) {
console.error(`Failed to run publint: ${error}`);
}

return result;
Expand Down
12 changes: 0 additions & 12 deletions src/commands/analyze.meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@ export const meta = {
name: 'analyze',
description: 'Analyze the project for any warnings or errors',
args: {
'base-tarball': {
type: 'string',
multiple: true,
description:
'Path to base tarball file(s) (e.g. main) to analyze (globs supported)'
},
'target-tarball': {
type: 'string',
multiple: true,
description:
'Path to target tarball file(s) (e.g. PR branch) to analyze (globs supported)'
},
'log-level': {
type: 'enum',
choices: ['debug', 'info', 'warn', 'error'],
Expand Down
10 changes: 3 additions & 7 deletions src/commands/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ function formatBytes(bytes: number) {

export async function run(ctx: CommandContext<typeof meta.args>) {
const [_commandName, providedPath] = ctx.positionals;
const baseTarball = ctx.values['base-tarball'];
const targetTarball = ctx.values['target-tarball'];
const logLevel = ctx.values['log-level'];
let root: string | undefined = undefined;

Expand All @@ -33,7 +31,7 @@ export async function run(ctx: CommandContext<typeof meta.args>) {

prompts.intro('Analyzing...');

// Path can be a directory (analyze project) or a tarball file (analyze tarball)
// Path can be a directory (analyze project)
if (providedPath) {
let stat: Stats | null = null;
try {
Expand All @@ -50,14 +48,12 @@ export async function run(ctx: CommandContext<typeof meta.args>) {
root = providedPath;
}

// Then analyze the tarball
// Then read the manifest
const customManifests = ctx.values['manifest'];

const {stats, messages} = await report({
root,
manifest: customManifests,
baseTarball,
targetTarball
manifest: customManifests
});

prompts.log.info('Summary');
Expand Down
58 changes: 0 additions & 58 deletions src/tarball-file-system.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/test/analyze/__snapshots__/dependencies.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,3 @@ exports[`analyzeDependencies (local) > should handle symlinks 1`] = `
},
}
`;

exports[`analyzeDependencies (tarball) > should analyze a real tarball fixture 1`] = `
{
"messages": [],
"stats": {
"dependencyCount": {
"cjs": 0,
"development": 0,
"duplicate": 0,
"esm": 0,
"production": 0,
},
"installSize": 226,
"name": "test-package",
"version": "1.0.0",
},
}
`;
54 changes: 0 additions & 54 deletions src/test/analyze/dependencies.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
import {runDependencyAnalysis} from '../../analyze/dependencies.js';
import {TarballFileSystem} from '../../tarball-file-system.js';
import {LocalFileSystem} from '../../local-file-system.js';
import {
createTempDir,
Expand All @@ -12,59 +11,6 @@ import {
import type {AnalysisContext} from '../../types.js';
import fs from 'node:fs/promises';
import path from 'node:path';
import {fileURLToPath} from 'node:url';

const FIXTURE_DIR = path.join(
path.dirname(fileURLToPath(import.meta.url)),
'../../../test/fixtures'
);

// Integration test using a real tarball fixture

describe('analyzeDependencies (tarball)', () => {
it('should analyze a real tarball fixture', async () => {
const tarballPath = path.join(FIXTURE_DIR, 'test-package.tgz');
const tarballBuffer = await fs.readFile(tarballPath);
const fileSystem = new TarballFileSystem(
tarballBuffer.buffer as ArrayBuffer
);
const context: AnalysisContext = {
fs: fileSystem,
root: '.',
messages: [],
stats: {
name: 'unknown',
version: 'unknown',
dependencyCount: {
cjs: 0,
esm: 0,
duplicate: 0,
production: 0,
development: 0
},
extraStats: []
},
lockfile: {
type: 'npm',
packages: [],
root: {
name: 'test-package',
version: '1.0.0',
dependencies: [],
devDependencies: [],
optionalDependencies: [],
peerDependencies: []
}
},
packageFile: {
name: 'test-package',
version: '1.0.0'
}
};
const result = await runDependencyAnalysis(context);
expect(result).toMatchSnapshot();
});
});

describe('analyzeDependencies (local)', () => {
let tempDir: string;
Expand Down
86 changes: 0 additions & 86 deletions src/test/tarball-file-system.test.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,3 @@ export async function createTestPackageWithDependencies(
await createTestPackage(depDir, dep);
}
}

export function createMockTarball(files: Array<{name: string; content: any}>) {
return {
files: files.map((file) => ({
name: file.name,
data: new TextEncoder().encode(
typeof file.content === 'string'
? file.content
: JSON.stringify(file.content)
)
})),
rootDir: 'package'
};
}
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import type {ParsedLockFile} from 'lockparse';
export interface Options {
root?: string;
manifest?: string[];
baseTarball?: string[];
targetTarball?: string[];
}

export interface StatLike<T> {
Expand Down
Loading