Skip to content

Commit

Permalink
feat: publint (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aslemammad authored Nov 19, 2024
1 parent 361de61 commit 6efb0b9
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ const main = defineCommand({
},
},
run: async ({ args }) => {
const paths = args._.length > 0
? await glob(args._, {
expandDirectories: false,
onlyDirectories: true,
absolute: true,
})
: [process.cwd()];
const paths =
args._.length > 0
? await glob(args._, {
expandDirectories: false,
onlyDirectories: true,
absolute: true,
})
: [process.cwd()];

const templates = await glob(args.template ?? [], {
expandDirectories: false,
Expand Down Expand Up @@ -329,22 +330,21 @@ const main = defineCommand({
);

shasums[pJson.name] = shasum;
console.warn(`shasum for ${pJson.name}(${filename}): ${shasum}`);

const outputPkg = outputMetadata.packages.find(
(p) => p.name === pJson.name,
)!;
outputPkg.shasum = shasum;

const filePath = path.resolve(p, filename)
const filePath = path.resolve(p, filename);
const buffer = await fs.readFile(filePath);

const blob = new Blob([buffer], {
type: "application/octet-stream",
});
formData.append(`package:${pJson.name}`, blob, filename);

await fs.rm(filePath)
await fs.rm(filePath);
} finally {
await restoreMap.get(p)?.();
}
Expand Down Expand Up @@ -376,8 +376,11 @@ const main = defineCommand({
console.error(await createMultipartRes.text());
continue;
}
const { key: uploadKey, id: uploadId, ...data } =
await createMultipartRes.json();
const {
key: uploadKey,
id: uploadId,
...data
} = await createMultipartRes.json();

interface R2UploadedPart {
partNumber: number;
Expand Down Expand Up @@ -432,7 +435,9 @@ const main = defineCommand({
}

const packageManager = await detect();
const agent = packageManager.agent.includes('@') ? packageManager.agent.split('@')[0] : packageManager.agent;
const agent = packageManager.agent.includes("@")
? packageManager.agent.split("@")[0]
: packageManager.agent;
const res = await fetch(publishUrl, {
method: "POST",
headers: {
Expand All @@ -454,15 +459,22 @@ const main = defineCommand({
);

console.warn("\n");
console.warn(
`⚡️ Your npm packages are published.\n${[...formData.keys()]
.filter((k) => k.startsWith("package:"))
.map(
(name, i) =>
`${name.slice("package:".length)}: npm i ${laterRes.urls[i]}`,
)
.join("\n")}`,
);
console.warn("⚡️ Your npm packages are published.\n");

const packageLogs = [...formData.keys()]
.filter((k) => k.startsWith("package:"))
.map((name, i) => {
const packageName = name.slice("package:".length);
const url = new URL(laterRes.urls[i])
const publintUrl = new URL(`/pkg.pr.new${url.pathname}`, "https://publint.dev")
return `${packageName}:
- sha: ${shasums[packageName]}
- publint: ${publintUrl}
- npm: npm i ${url}`;
})
.join("\n\n");

console.warn(packageLogs);

const output = JSON.stringify(outputMetadata, null, 2);
if (printJson) {
Expand Down Expand Up @@ -542,7 +554,7 @@ function hijackDeps(
}

function getFormEntrySize(entry: FormDataEntryValue) {
if (typeof entry === 'string') {
if (typeof entry === "string") {
return entry.length;
}
return entry.size;
Expand Down

0 comments on commit 6efb0b9

Please sign in to comment.