Skip to content

Commit 972e6e1

Browse files
authored
chore: yarn_pnp tests uses gatsby-dev-cli instead of portals (#35699)
1 parent e3d57c0 commit 972e6e1

File tree

6 files changed

+49
-18
lines changed

6 files changed

+49
-18
lines changed

.circleci/config.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,21 @@ jobs:
344344
- run: # Don't allow any fallback to root dependencies
345345
command: yarn config set pnpFallbackMode none
346346
working_directory: /tmp/e2e-tests/gatsby-pnp
347-
- run: # Forces to use the local packages
348-
command: yarn link --all --private ~/project
347+
- run: # Install before custom registry server is set
348+
command: yarn add start-server-and-test@^1.11.0
349349
working_directory: /tmp/e2e-tests/gatsby-pnp
350-
- run:
351-
command: yarn install
350+
- run: # Set the local registry to gatsby-dev-cli registry
351+
command: yarn config set npmRegistryServer http://localhost:4873
352352
working_directory: /tmp/e2e-tests/gatsby-pnp
353-
- run:
354-
command: yarn add start-server-and-test@^1.11.0
353+
- run: # Allow localhost registry
354+
command: |
355+
echo -e 'unsafeHttpWhitelist:\n - "localhost"' >> .yarnrc.yml
356+
working_directory: /tmp/e2e-tests/gatsby-pnp
357+
- run: # Set project dir
358+
command: node ~/project/packages/gatsby-dev-cli/dist/index.js --set-path-to-repo ~/project
359+
working_directory: /tmp/e2e-tests/gatsby-pnp
360+
- run: # Copy over packages
361+
command: node ~/project/packages/gatsby-dev-cli/dist/index.js --force-install --scan-once --external-registry
355362
working_directory: /tmp/e2e-tests/gatsby-pnp
356363
- run:
357364
command: yarn build

packages/gatsby-dev-cli/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,7 @@ Copy all modules/files in the gatsby source repo in packages/
7979
#### `--force-install`
8080

8181
Disable copying files into node_modules and force usage of local npm repository.
82+
83+
#### `--external-registry`
84+
85+
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.

packages/gatsby-dev-cli/src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ You typically only need to configure this once.`
2727
`force-install`,
2828
`Disables copying files into node_modules and forces usage of local npm repository.`
2929
)
30+
.nargs(`external-registry`, 0)
31+
.describe(
32+
`external-registry`,
33+
`Run 'yarn add' commands without the --registry flag.`
34+
)
3035
.alias(`C`, `copy-all`)
3136
.nargs(`C`, 0)
3237
.describe(
@@ -148,4 +153,5 @@ watch(gatsbyLocation, argv.packages, {
148153
forceInstall: argv.forceInstall,
149154
monoRepoPackages,
150155
packageNameToPath,
156+
externalRegistry: argv.externalRegistry,
151157
})

packages/gatsby-dev-cli/src/local-npm-registry/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ exports.publishPackagesLocallyAndInstall = async ({
4848
packageNameToPath,
4949
ignorePackageJSONChanges,
5050
yarnWorkspaceRoot,
51+
externalRegistry,
5152
}) => {
5253
await startServer()
5354

@@ -71,5 +72,6 @@ exports.publishPackagesLocallyAndInstall = async ({
7172
packagesToInstall,
7273
yarnWorkspaceRoot,
7374
newlyPublishedPackageVersions,
75+
externalRegistry,
7476
})
7577
}

packages/gatsby-dev-cli/src/local-npm-registry/install-packages.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const installPackages = async ({
88
packagesToInstall,
99
yarnWorkspaceRoot,
1010
newlyPublishedPackageVersions,
11+
externalRegistry,
1112
}) => {
1213
console.log(
1314
`Installing packages from local registry:\n${packagesToInstall
@@ -118,20 +119,28 @@ const installPackages = async ({
118119

119120
// package.json files are changed - so we just want to install
120121
// using verdaccio registry
121-
installCmd = [`yarn`, [`install`, `--registry=${registryUrl}`]]
122+
const yarnCommands = [`install`]
123+
124+
if (!externalRegistry) {
125+
yarnCommands.push(`--registry=${registryUrl}`)
126+
}
127+
128+
installCmd = [`yarn`, yarnCommands]
122129
} else {
123-
installCmd = [
124-
`yarn`,
125-
[
126-
`add`,
127-
...packagesToInstall.map(packageName => {
128-
const packageVersion = newlyPublishedPackageVersions[packageName]
129-
return `${packageName}@${packageVersion}`
130-
}),
131-
`--registry=${registryUrl}`,
132-
`--exact`,
133-
],
130+
const yarnCommands = [
131+
`add`,
132+
...packagesToInstall.map(packageName => {
133+
const packageVersion = newlyPublishedPackageVersions[packageName]
134+
return `${packageName}@${packageVersion}`
135+
}),
136+
`--exact`,
134137
]
138+
139+
if (!externalRegistry) {
140+
yarnCommands.push(`--registry=${registryUrl}`)
141+
}
142+
143+
installCmd = [`yarn`, yarnCommands]
135144
}
136145

137146
try {

packages/gatsby-dev-cli/src/watch.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ async function watch(
3737
monoRepoPackages,
3838
localPackages,
3939
packageNameToPath,
40+
externalRegistry,
4041
}
4142
) {
4243
setDefaultSpawnStdio(quiet ? `ignore` : `inherit`)
@@ -155,6 +156,7 @@ async function watch(
155156
localPackages,
156157
ignorePackageJSONChanges,
157158
yarnWorkspaceRoot,
159+
externalRegistry,
158160
})
159161
} else {
160162
// run `yarn`
@@ -339,6 +341,7 @@ async function watch(
339341
packageNameToPath,
340342
localPackages,
341343
ignorePackageJSONChanges,
344+
externalRegistry,
342345
})
343346
packagesToPublish.clear()
344347
isPublishing = false

0 commit comments

Comments
 (0)