Skip to content

Commit

Permalink
Fix compile package detection
Browse files Browse the repository at this point in the history
  • Loading branch information
askoufis committed Jun 27, 2023
1 parent 4c2da76 commit bb0bff1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-steaks-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sku': patch
---

Don't use `.git` folder to find root, only glob PNPM virtual store if PNPM is detected as the package manager
40 changes: 23 additions & 17 deletions packages/sku/context/defaultCompilePackages.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
const { posix: path } = require('path');
const chalk = require('chalk');
const glob = require('fast-glob');
const { execSync } = require('child_process');

const { cwd: skuCwd } = require('../lib/cwd');
const toPosixPath = require('../lib/toPosixPath');

const { findRootSync } = require('@manypkg/find-root');

/** @type {string[]} */
let detectedCompilePackages = [];

try {
const globs = ['node_modules/@seek/*/package.json'];
const cwd = skuCwd();
const gitRepoRoot = execSync('git rev-parse --show-toplevel', { cwd })
.toString()
.trim();

const pnpmVirtualStorePath = path.join(
toPosixPath(gitRepoRoot),
'node_modules/.pnpm',
);
const pnpmVirtualStoreRelativePath = path.relative('.', pnpmVirtualStorePath);
const pnpmVirtualStoreGlob = path.join(
pnpmVirtualStoreRelativePath,
'@seek*/node_modules/@seek/*/package.json',
);

const packageDependenciesGlob = 'node_modules/@seek/*/package.json';
const { rootDir, tool } = findRootSync(cwd);

if (tool === 'pnpm') {
const pnpmVirtualStorePath = path.join(
toPosixPath(rootDir),
'node_modules/.pnpm',
);
const pnpmVirtualStoreRelativePath = path.relative(
'.',
pnpmVirtualStorePath,
);
const pnpmVirtualStoreGlob = path.join(
pnpmVirtualStoreRelativePath,
'@seek*/node_modules/@seek/*/package.json',
);

globs.push(pnpmVirtualStoreGlob);
}

detectedCompilePackages = glob
.sync([pnpmVirtualStoreGlob, packageDependenciesGlob], {
.sync(globs, {
cwd,
})
.map((packagePath) => {
console.log({ packagePath });
const packageJson = require(path.join(cwd, packagePath));

return {
Expand All @@ -45,7 +52,6 @@ try {
console.log(
chalk.red`Warning: Failed to detect compile packages. Contact #sku-support.`,
);
console.error(e);
}

module.exports = [
Expand Down
1 change: 1 addition & 0 deletions packages/sku/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@loadable/component": "^5.14.1",
"@loadable/server": "^5.14.0",
"@loadable/webpack-plugin": "^5.14.0",
"@manypkg/find-root": "^2.2.0",
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
"@storybook/builder-webpack5": "^7.0.17",
"@storybook/cli": "^7.0.17",
Expand Down
32 changes: 27 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bb0bff1

Please sign in to comment.