Skip to content

Commit

Permalink
Fix init command in monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
frandiox committed Jul 8, 2024
1 parent 604040e commit d1aced4
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions packages/cli/src/lib/onboarding/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {readdir} from 'node:fs/promises';
import {readdir, symlink} from 'node:fs/promises';
import {
installNodeModules,
packageManagerFromUserAgent,
Expand Down Expand Up @@ -27,11 +27,13 @@ import {
fileExists,
isDirectory,
writeFile,
copyFile,
} from '@shopify/cli-kit/node/fs';
import {
outputDebug,
formatPackageManagerCommand,
} from '@shopify/cli-kit/node/output';
import {currentProcessIsGlobal} from '@shopify/cli-kit/node/is-global';
import colors from '@shopify/cli-kit/node/colors';
import {type AdminSession, login, renderLoginSuccess} from '../auth.js';
import {
Expand Down Expand Up @@ -59,7 +61,11 @@ import {
} from '../setups/routes/generate.js';
import {execAsync} from '../process.js';
import {getStorefronts} from '../graphql/admin/link-storefront.js';
import {currentProcessIsGlobal} from '@shopify/cli-kit/node/is-global';
import {
getRepoNodeModules,
getSkeletonSourceDir,
isHydrogenMonorepo,
} from '../build.js';

export type InitOptions = {
path?: string;
Expand Down Expand Up @@ -501,6 +507,23 @@ export async function handleDependencies(
}
}

if (isHydrogenMonorepo) {
// In Hydrogen monorepo, add `.npmrc` to bypass Shopify registry
// and symlink `node_modules` to monorepo's node_modules.

await copyFile(
joinPath(getSkeletonSourceDir(), '.npmrc'),
joinPath(projectDir, '.npmrc'),
).catch(() => {});

if (!shouldInstallDeps) {
await symlink(
await getRepoNodeModules(),
joinPath(projectDir, 'node_modules'),
).catch(() => {});
}
}

return {
packageManager: actualPackageManager,
shouldInstallDeps,
Expand Down

0 comments on commit d1aced4

Please sign in to comment.