Skip to content

Commit e5a47ce

Browse files
feat: removing tarball code (#134)
* Initial commit for removing tarball code * Add package directory to publint * remove attw keyword
1 parent a859f62 commit e5a47ce

File tree

10 files changed

+9
-279
lines changed

10 files changed

+9
-279
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
"url": "git+https://github.com/e18e/cli.git"
3535
},
3636
"keywords": [
37-
"e18e",
38-
"attw",
37+
"e18e",
3938
"dependencies",
4039
"dependency",
4140
"publint"

src/analyze/publint.ts

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,25 @@
11
import {publint} from 'publint';
22
import {formatMessage} from 'publint/utils';
3-
import type {ReportPluginResult, Options, AnalysisContext} from '../types.js';
4-
import fs from 'node:fs/promises';
5-
import path from 'node:path';
3+
import type {ReportPluginResult, AnalysisContext} from '../types.js';
64

75
export async function runPublint(
86
context: AnalysisContext
9-
): Promise<ReportPluginResult> {
10-
const targetTarballs = context.options?.targetTarball;
11-
12-
if (targetTarballs && targetTarballs.length > 0) {
13-
return runPublintWithTarballs(targetTarballs, context.options);
14-
}
15-
16-
return {messages: []};
17-
}
18-
19-
export async function runPublintWithTarballs(
20-
targetTarballs: string[],
21-
options?: Options
227
): Promise<ReportPluginResult> {
238
const result: ReportPluginResult = {
249
messages: []
2510
};
26-
const root = options?.root || process.cwd();
2711

28-
for (const targetTarball of targetTarballs) {
29-
const targetTarballPath = path.resolve(root, targetTarball);
30-
// TODO (jg): handle failed reads gracefully
31-
const buffer = await fs.readFile(targetTarballPath);
32-
const tarball = buffer.buffer.slice(
33-
buffer.byteOffset,
34-
buffer.byteOffset + buffer.byteLength
35-
) as ArrayBuffer;
36-
const publintResult = await publint({pack: {tarball}});
12+
try {
13+
const publintResult = await publint({pack: 'auto', pkgDir: context.root});
3714
for (const problem of publintResult.messages) {
3815
result.messages.push({
3916
severity: problem.type,
4017
score: 0,
4118
message: formatMessage(problem, publintResult.pkg) ?? ''
4219
});
4320
}
21+
} catch (error) {
22+
console.error(`Failed to run publint: ${error}`);
4423
}
4524

4625
return result;

src/commands/analyze.meta.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@ export const meta = {
22
name: 'analyze',
33
description: 'Analyze the project for any warnings or errors',
44
args: {
5-
'base-tarball': {
6-
type: 'string',
7-
multiple: true,
8-
description:
9-
'Path to base tarball file(s) (e.g. main) to analyze (globs supported)'
10-
},
11-
'target-tarball': {
12-
type: 'string',
13-
multiple: true,
14-
description:
15-
'Path to target tarball file(s) (e.g. PR branch) to analyze (globs supported)'
16-
},
175
'log-level': {
186
type: 'enum',
197
choices: ['debug', 'info', 'warn', 'error'],

src/commands/analyze.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ function formatBytes(bytes: number) {
2121

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

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

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

36-
// Path can be a directory (analyze project) or a tarball file (analyze tarball)
34+
// Path can be a directory (analyze project)
3735
if (providedPath) {
3836
let stat: Stats | null = null;
3937
try {
@@ -50,14 +48,12 @@ export async function run(ctx: CommandContext<typeof meta>) {
5048
root = providedPath;
5149
}
5250

53-
// Then analyze the tarball
51+
// Then read the manifest
5452
const customManifests = ctx.values['manifest'];
5553

5654
const {stats, messages} = await report({
5755
root,
58-
manifest: customManifests,
59-
baseTarball,
60-
targetTarball
56+
manifest: customManifests
6157
});
6258

6359
prompts.log.info('Summary');

src/tarball-file-system.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/test/analyze/__snapshots__/dependencies.test.ts.snap

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,3 @@ exports[`analyzeDependencies (local) > should handle symlinks 1`] = `
7171
},
7272
}
7373
`;
74-
75-
exports[`analyzeDependencies (tarball) > should analyze a real tarball fixture 1`] = `
76-
{
77-
"messages": [],
78-
"stats": {
79-
"dependencyCount": {
80-
"cjs": 0,
81-
"development": 0,
82-
"duplicate": 0,
83-
"esm": 0,
84-
"production": 0,
85-
},
86-
"installSize": 226,
87-
"name": "test-package",
88-
"version": "1.0.0",
89-
},
90-
}
91-
`;

src/test/analyze/dependencies.test.ts

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {describe, it, expect, beforeEach, afterEach} from 'vitest';
22
import {runDependencyAnalysis} from '../../analyze/dependencies.js';
3-
import {TarballFileSystem} from '../../tarball-file-system.js';
43
import {LocalFileSystem} from '../../local-file-system.js';
54
import {
65
createTempDir,
@@ -12,59 +11,6 @@ import {
1211
import type {AnalysisContext} from '../../types.js';
1312
import fs from 'node:fs/promises';
1413
import path from 'node:path';
15-
import {fileURLToPath} from 'node:url';
16-
17-
const FIXTURE_DIR = path.join(
18-
path.dirname(fileURLToPath(import.meta.url)),
19-
'../../../test/fixtures'
20-
);
21-
22-
// Integration test using a real tarball fixture
23-
24-
describe('analyzeDependencies (tarball)', () => {
25-
it('should analyze a real tarball fixture', async () => {
26-
const tarballPath = path.join(FIXTURE_DIR, 'test-package.tgz');
27-
const tarballBuffer = await fs.readFile(tarballPath);
28-
const fileSystem = new TarballFileSystem(
29-
tarballBuffer.buffer as ArrayBuffer
30-
);
31-
const context: AnalysisContext = {
32-
fs: fileSystem,
33-
root: '.',
34-
messages: [],
35-
stats: {
36-
name: 'unknown',
37-
version: 'unknown',
38-
dependencyCount: {
39-
cjs: 0,
40-
esm: 0,
41-
duplicate: 0,
42-
production: 0,
43-
development: 0
44-
},
45-
extraStats: []
46-
},
47-
lockfile: {
48-
type: 'npm',
49-
packages: [],
50-
root: {
51-
name: 'test-package',
52-
version: '1.0.0',
53-
dependencies: [],
54-
devDependencies: [],
55-
optionalDependencies: [],
56-
peerDependencies: []
57-
}
58-
},
59-
packageFile: {
60-
name: 'test-package',
61-
version: '1.0.0'
62-
}
63-
};
64-
const result = await runDependencyAnalysis(context);
65-
expect(result).toMatchSnapshot();
66-
});
67-
});
6814

6915
describe('analyzeDependencies (local)', () => {
7016
let tempDir: string;

src/test/tarball-file-system.test.ts

Lines changed: 0 additions & 86 deletions
This file was deleted.

src/test/utils.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,3 @@ export async function createTestPackageWithDependencies(
9797
await createTestPackage(depDir, dep);
9898
}
9999
}
100-
101-
export function createMockTarball(files: Array<{name: string; content: any}>) {
102-
return {
103-
files: files.map((file) => ({
104-
name: file.name,
105-
data: new TextEncoder().encode(
106-
typeof file.content === 'string'
107-
? file.content
108-
: JSON.stringify(file.content)
109-
)
110-
})),
111-
rootDir: 'package'
112-
};
113-
}

src/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import type {ParsedLockFile} from 'lockparse';
55
export interface Options {
66
root?: string;
77
manifest?: string[];
8-
baseTarball?: string[];
9-
targetTarball?: string[];
108
}
119

1210
export interface StatLike<T> {

0 commit comments

Comments
 (0)