Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions scripts/src/worker/pack.mts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ export const run: WorkerRunnerFunction = async ({ target }) => {
throw new Error('pack worker requires options.outputDir to be set in lage.config.js');
}

// Skip if this version is already published
const result = await $`npm view ${pkg.name}@${pkg.version} version`.nothrow().quiet();
if (result.exitCode === 0) {
console.log(`Skipping ${pkg.name}@${pkg.version} — already published`);
return;
}

// Resolve relative to cwd (lage runs from repo root, so this resolves correctly)
const stagingDir = resolve(outputDir);
await fs.mkdirp(stagingDir);
Expand Down
18 changes: 8 additions & 10 deletions scripts/src/worker/publish.mts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,15 @@ export const run: WorkerRunnerFunction = async ({ target }) => {

const dryRun = target.options?.dryRun ?? false;
const outputDir = target.options?.outputDir as string | undefined;

// If an outputDir is configured, look for a pre-packed tarball
const tarball = outputDir ? await findTarball(pkg, outputDir) : undefined;

if (tarball) {
// yarn npm publish doesn't support tarballs, so use npm directly
const args = ['publish', tarball, '--access', 'public', ...(dryRun ? ['--dry-run'] : [])];
await $({ cwd: target.cwd, verbose: true })`npm ${args}`;
} else {
// No tarball found — publish from source (local dev / dry-run)
const args = ['--tolerate-republish', ...(dryRun ? ['--dry-run'] : [])];
await $({ cwd: target.cwd, verbose: true })`yarn npm publish ${args}`;
if (!tarball) {
// No tarball means pack skipped this package (already published) — nothing to do
console.log(`Skipping ${pkg.name}@${pkg.version} — no tarball found`);
return;
}

// yarn npm publish doesn't support tarballs, so use npm directly
const args = ['publish', tarball, '--access', 'public', ...(dryRun ? ['--dry-run'] : [])];
await $({ cwd: target.cwd, verbose: true })`npm ${args}`;
};
Loading