Skip to content

Commit

Permalink
fix: improve package linking
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Apr 15, 2020
1 parent 76085c4 commit 4773995
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/project-utils/packages/linkPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ async function symlink(src, dest) {
}
}

module.exports.linkPackages = async () => {
const defaults = { whitelist: ["packages"] };

module.exports.linkPackages = async ({ whitelist } = defaults) => {
console.log(`Linking repo packages...`);

whitelist = whitelist.map(p => path.resolve(p));

// Filter packages to only those in the whitelisted folders
const whitelist = [path.resolve("components"), path.resolve("packages")];
const packages = require("get-yarn-workspaces")()
.map(pkg => pkg.replace(/\//g, path.sep))
.reduce((acc, pkg) => {
Expand All @@ -67,14 +70,14 @@ module.exports.linkPackages = async () => {
continue;
}

const package = require(packageJson);
const pkg = require(packageJson);

let targetDirectory = get(package, "publishConfig.directory");
let targetDirectory = get(pkg, "publishConfig.directory");
if (!targetDirectory && lerna) {
targetDirectory = get(lerna, "command.publish.contents");
}

const link = path.resolve("node_modules", package.name);
const link = path.resolve("node_modules", pkg.name);
const target = path.resolve(packages[i], targetDirectory || ".");

if (!fs.existsSync(target)) {
Expand All @@ -85,7 +88,7 @@ module.exports.linkPackages = async () => {
await fs.mkdirp(path.dirname(link));
await symlink(target, link);
} catch (err) {
console.log(`Failed ${package.name}: ${err.message}`);
console.log(`Failed ${pkg.name}: ${err.message}`);
}
}
};

0 comments on commit 4773995

Please sign in to comment.