Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix init command in monorepo #2305

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading