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

chore: yarn_pnp tests uses gatsby-dev-cli instead of portals #35699

Merged
merged 11 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 13 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,21 @@ jobs:
- run: # Don't allow any fallback to root dependencies
command: yarn config set pnpFallbackMode none
working_directory: /tmp/e2e-tests/gatsby-pnp
- run: # Forces to use the local packages
command: yarn link --all --private ~/project
- run: # Install before custom registry server is set
command: yarn add start-server-and-test@^1.11.0
working_directory: /tmp/e2e-tests/gatsby-pnp
- run:
command: yarn install
- run: # Set the local registry to gatsby-dev-cli registry
command: yarn config set npmRegistryServer http://localhost:4873
working_directory: /tmp/e2e-tests/gatsby-pnp
- run:
command: yarn add start-server-and-test@^1.11.0
- run: # Allow localhost registry
command: |
echo -e 'unsafeHttpWhitelist:\n - "localhost"' >> .yarnrc.yml
working_directory: /tmp/e2e-tests/gatsby-pnp
- run: # Set project dir
command: node ~/project/packages/gatsby-dev-cli/dist/index.js --set-path-to-repo ~/project
working_directory: /tmp/e2e-tests/gatsby-pnp
- run: # Copy over packages
command: node ~/project/packages/gatsby-dev-cli/dist/index.js --force-install --scan-once --external-registry
working_directory: /tmp/e2e-tests/gatsby-pnp
- run:
command: yarn build
Expand Down
4 changes: 4 additions & 0 deletions packages/gatsby-dev-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ Copy all modules/files in the gatsby source repo in packages/
#### `--force-install`

Disable copying files into node_modules and force usage of local npm repository.

#### `--external-registry`

Run `yarn add` commands without the `--registry` flag. This is helpful when using yarn 2/3 and you need to use `yarn config set npmRegistryServer http://localhost:4873` for `gatsby-dev-cli` to work.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Run `yarn add` commands without the `--registry` flag. This is helpful when using yarn 2/3 and you need to use `yarn config set npmRegistryServer http://localhost:4873` for `gatsby-dev-cli` to work.
Run `yarn add` commands without the `--registry` flag. This is helpful when using yarn 2/3 and you need to use `yarn config set npmRegistryServer http://localhost:4873` and `echo -e 'unsafeHttpWhitelist:\n - "localhost"' >> .yarnrc.yml` before running `gatsby-dev-cli`.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be skipped from that PR for the sake of landing this faster

6 changes: 6 additions & 0 deletions packages/gatsby-dev-cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ You typically only need to configure this once.`
`force-install`,
`Disables copying files into node_modules and forces usage of local npm repository.`
)
.nargs(`external-registry`, 0)
.describe(
`external-registry`,
`Run 'yarn add' commands without the --registry flag.`
)
.alias(`C`, `copy-all`)
.nargs(`C`, 0)
.describe(
Expand Down Expand Up @@ -148,4 +153,5 @@ watch(gatsbyLocation, argv.packages, {
forceInstall: argv.forceInstall,
monoRepoPackages,
packageNameToPath,
externalRegistry: argv.externalRegistry,
})
2 changes: 2 additions & 0 deletions packages/gatsby-dev-cli/src/local-npm-registry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ exports.publishPackagesLocallyAndInstall = async ({
packageNameToPath,
ignorePackageJSONChanges,
yarnWorkspaceRoot,
externalRegistry,
}) => {
await startServer()

Expand All @@ -71,5 +72,6 @@ exports.publishPackagesLocallyAndInstall = async ({
packagesToInstall,
yarnWorkspaceRoot,
newlyPublishedPackageVersions,
externalRegistry,
})
}
33 changes: 21 additions & 12 deletions packages/gatsby-dev-cli/src/local-npm-registry/install-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const installPackages = async ({
packagesToInstall,
yarnWorkspaceRoot,
newlyPublishedPackageVersions,
externalRegistry,
}) => {
console.log(
`Installing packages from local registry:\n${packagesToInstall
Expand Down Expand Up @@ -118,20 +119,28 @@ const installPackages = async ({

// package.json files are changed - so we just want to install
// using verdaccio registry
installCmd = [`yarn`, [`install`, `--registry=${registryUrl}`]]
const yarnCommands = [`install`]

if (!externalRegistry) {
yarnCommands.push(`--registry=${registryUrl}`)
}

installCmd = [`yarn`, yarnCommands]
} else {
installCmd = [
`yarn`,
[
`add`,
...packagesToInstall.map(packageName => {
const packageVersion = newlyPublishedPackageVersions[packageName]
return `${packageName}@${packageVersion}`
}),
`--registry=${registryUrl}`,
`--exact`,
],
const yarnCommands = [
`add`,
...packagesToInstall.map(packageName => {
const packageVersion = newlyPublishedPackageVersions[packageName]
return `${packageName}@${packageVersion}`
}),
`--exact`,
]

if (!externalRegistry) {
yarnCommands.push(`--registry=${registryUrl}`)
}

installCmd = [`yarn`, yarnCommands]
}

try {
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby-dev-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async function watch(
monoRepoPackages,
localPackages,
packageNameToPath,
externalRegistry,
}
) {
setDefaultSpawnStdio(quiet ? `ignore` : `inherit`)
Expand Down Expand Up @@ -155,6 +156,7 @@ async function watch(
localPackages,
ignorePackageJSONChanges,
yarnWorkspaceRoot,
externalRegistry,
})
} else {
// run `yarn`
Expand Down Expand Up @@ -339,6 +341,7 @@ async function watch(
packageNameToPath,
localPackages,
ignorePackageJSONChanges,
externalRegistry,
})
packagesToPublish.clear()
isPublishing = false
Expand Down