Skip to content

Commit

Permalink
Package workspace packages
Browse files Browse the repository at this point in the history
  • Loading branch information
DBoroujerdi committed Dec 27, 2020
1 parent 82f184c commit 96f046d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
2 changes: 0 additions & 2 deletions sources/commands/packLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export default class PackageLambdaCommand extends Command<CommandContext> {
@Command.Boolean('--deps-only', {description: "Only package dependencies"})
depsOnly = false;

// @Command.Boolean('--ignore-mtime', {description: ""})

@Command.Boolean('--json', {description: `Format the output as an NDJSON stream`})
json: boolean = false;

Expand Down
66 changes: 49 additions & 17 deletions sources/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
npath
} from "@yarnpkg/fslib";
import mm from "micromatch";
import {UsageError} from "clipanion";

const ALWAYS_IGNORE = [
`/package.tgz`,
Expand Down Expand Up @@ -171,31 +172,62 @@ export async function addPackagesToZip(outputZip: ZipFS, workspace: Workspace, p

const fetchResult = await fetcher.fetch(pkg, fetcherOptions);

const pkgRoot = fetchResult.localPath || PortablePath.root;

const collected = await walkFs(fetchResult.packageFs, pkgRoot);
report.reportInfo(null, `${pkg.name}:${pkg.reference}`);
report.reportJson({dependency: pkg.name, ref: pkg.reference});

const pkgFileSystem = fetchResult.packageFs;
const pkgPath = await pkgFileSystem.getRealPath();

if (!(await pkgFileSystem.getRealPath()).endsWith(".zip")) {
// TODO handle non zip workspace packages
continue;
}
if (!pkgPath.endsWith(".zip")) {
const pkgWorkspace = project.workspaces.find(w => w.manifest.name.name === pkg.name);

report.reportInfo(null, `${pkg.name}:${pkg.reference}`);
report.reportJson({dependency: pkg.name, ref: pkg.reference});
if (!pkgWorkspace)
throw new UsageError(`${pkg.name} workspace not found, have you configured yarn workspaces correctly?`);

const rawManifest = pkgWorkspace.manifest.raw

if (!rawManifest.directories)
throw new UsageError(`"directories" not defined for workspace ${pkg.name}`);

for (const file of collected) {
const stat = await pkgFileSystem.lstatPromise(file);
if (!rawManifest.directories.lib)
throw new UsageError(`"directories.lib" not defined for workspace ${pkg.name}`);

if (stat.isDirectory()) {
await outputZip.mkdirpPromise(file);
} else {
const buffer = await pkgFileSystem.readFilePromise(file);
await outputZip.writeFilePromise(file, buffer);
const collected = await walkFs(fetchResult.packageFs, rawManifest.directories.lib);
const outputZipLibPath = ppath.join("node_modules" as PortablePath, pkg.name as PortablePath);

console.log("1")
await outputZip.mkdirpPromise(outputZipLibPath);
console.log("2")
for (const file of collected) {
const stat = await pkgFileSystem.lstatPromise(file);
const outFile = ppath.join(outputZipLibPath, file);

if (stat.isDirectory()) {
await outputZip.mkdirpPromise(outFile);
} else {
const buffer = await pkgFileSystem.readFilePromise(file);
await outputZip.writeFilePromise(outFile, buffer);
}

await outputZip.utimesPromise(outFile, stat.atime, stat.mtime);
}
} else {

await outputZip.utimesPromise(file, stat.atime, stat.mtime);
const pkgRoot = fetchResult.localPath || PortablePath.root;
const collected = await walkFs(fetchResult.packageFs, pkgRoot);

for (const file of collected) {
const stat = await pkgFileSystem.lstatPromise(file);

if (stat.isDirectory()) {
await outputZip.mkdirpPromise(file);
} else {
const buffer = await pkgFileSystem.readFilePromise(file);
await outputZip.writeFilePromise(file, buffer);
}

await outputZip.utimesPromise(file, stat.atime, stat.mtime);
}
}
}
}
Expand Down

0 comments on commit 96f046d

Please sign in to comment.