Skip to content

Commit

Permalink
fix(plugin-workspaces-export): do not pack symlinks with absolute pat…
Browse files Browse the repository at this point in the history
…hs in tgz archives
  • Loading branch information
kherock committed Jun 20, 2021
1 parent ec1dc53 commit 3765403
Showing 1 changed file with 17 additions and 39 deletions.
56 changes: 17 additions & 39 deletions packages/plugin-workspaces-export/sources/exportUtils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {MultiFetcher} from '@yarnpkg/core/lib/MultiFetcher';
import {MultiResolver} from '@yarnpkg/core/lib/MultiResolver';
import {ProtocolResolver} from '@yarnpkg/core/lib/ProtocolResolver';
import {VirtualResolver} from '@yarnpkg/core/lib/VirtualResolver';
import {Project, VirtualFetcher, Workspace, tgzUtils} from '@yarnpkg/core';
import {FakeFS, Filename, JailFS, PortablePath, ppath, xfs, ZipCompression} from '@yarnpkg/fslib';
import {packUtils} from '@yarnpkg/plugin-pack';
import tar from 'tar-stream';
import {createGzip} from 'zlib';

import {WorkspacePackFetcher} from './WorkspacePackFetcher';
import {WorkspacePackResolver} from './WorkspacePackResolver';
import {MultiFetcher} from '@yarnpkg/core/lib/MultiFetcher';
import {MultiResolver} from '@yarnpkg/core/lib/MultiResolver';
import {ProtocolResolver} from '@yarnpkg/core/lib/ProtocolResolver';
import {VirtualResolver} from '@yarnpkg/core/lib/VirtualResolver';
import {Project, tgzUtils, VirtualFetcher, Workspace} from '@yarnpkg/core';
import {CwdFS, Filename, PortablePath, ppath, xfs, ZipCompression} from '@yarnpkg/fslib';
import {packUtils} from '@yarnpkg/plugin-pack';
import tar from 'tar-stream';
import {createGzip} from 'zlib';

import {WorkspacePackFetcher} from './WorkspacePackFetcher';
import {WorkspacePackResolver} from './WorkspacePackResolver';

/**
* Make a MultiFetcher that resolves workspaces using WorkspacePackFetcher
Expand Down Expand Up @@ -87,39 +87,17 @@ export const genPackZip = async (workspace: Workspace, opts: {
});
};

async function walk(cwdFs: FakeFS<PortablePath>) {
const list: Array<PortablePath> = [];

const cwdList: Array<PortablePath> = [PortablePath.root];

while (cwdList.length > 0) {
const cwd = cwdList.pop()!;
const stat = await cwdFs.lstatPromise(cwd);

if (stat.isDirectory()) {
const entries = await cwdFs.readdirPromise(cwd);

for (const entry of entries) {
cwdList.push(ppath.resolve(cwd, entry));
}
} else {
list.push(ppath.relative(PortablePath.root, cwd));
}
}

return list.sort();
}

export const makeGzipFromDirectory = async (directory: PortablePath) => {
const cwdFs = new JailFS(directory);
const files = await walk(cwdFs);
const cwdFs = new CwdFS(directory);
const files: Array<PortablePath> = [];
for await (const p of cwdFs.genTraversePromise(directory, {stableSort: true})) files.push(p);
const pack = tar.pack();

process.nextTick(async () => {
for (const fileRequest of files) {
const file = ppath.normalize(fileRequest);
const file = ppath.relative(directory, fileRequest);

const stat = await cwdFs.lstatPromise(file);
const stat = await cwdFs.lstatPromise(fileRequest);
const opts = {name: file, mtime: new Date(315532800000), mode: stat.mode};

let resolveFn: Function;
Expand Down

0 comments on commit 3765403

Please sign in to comment.