-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-native/template): use verdaccio to publish local packages …
…before testing template app (#35444) Summary: Pull Request resolved: #35444 Changelog: [Internal][Changed] - now using Verdaccio to publish necessary packages for template app - Adds script `/scripts/template/install-dependencies.js`, which incapsulates the logic of installing dependencies of template app - The idea of the script is to run verdaccio and publish all necessary packages to node_modules, since these packages might not yet be present on npm - This should also potentially resolve some template app test failures on CircleCI related to package-ifying Animated, VirtualizedList, FlatList modules Reviewed By: cortinico Differential Revision: D41498086 fbshipit-source-id: 48fbbb1c9334e7a9e7657e6275b7b04f9ce290b5
- Loading branch information
Showing
6 changed files
with
163 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## Why? | ||
|
||
The main purpose of `install-dependencies.js` is to bootstrap [Verdaccio](https://verdaccio.org/docs/what-is-verdaccio). It will host all the local packages, which are not yet present on npm registry. In the near future this should help us in keep template tests green, because once we move to [monorepo structure](https://github.com/react-native-community/discussions-and-proposals/pull/480), template app may use some versions of dependencies that are not yet present on npm registry. | ||
|
||
## I have migrated some module to package, which is not yet published to npm, how to use it? | ||
|
||
First of all, you need to modify [Verdaccio config](https://github.com/facebook/react-native/tree/main/scripts/template/verdaccio.yml): | ||
```diff | ||
packages: | ||
+ '<my-migrated-package-name>': | ||
+ access: $all | ||
+ publish: $all | ||
'@*/*': | ||
access: $all | ||
publish: $authenticated | ||
proxy: npmjs | ||
'**': | ||
access: $all | ||
publish: $all | ||
proxy: npmjs | ||
``` | ||
|
||
After that, you should modify [install-dependencies script](https://github.com/facebook/react-native/tree/main/scripts/template/install-dependencies.js) to include your package for publishing | ||
|
||
```diff | ||
const PACKAGES_TO_PUBLISH_PATHS = [ | ||
... | ||
+ "packages/<your-package-folder-name>" | ||
]; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const yargs = require('yargs'); | ||
const {execSync, spawnSync} = require('child_process'); | ||
const setupVerdaccio = require('../setup-verdaccio'); | ||
|
||
const {argv} = yargs | ||
.option('r', { | ||
alias: 'reactNativeRootPath', | ||
describe: 'Path to root folder of react-native', | ||
required: true, | ||
}) | ||
.option('c', { | ||
alias: 'templatePath', | ||
describe: 'Path to template application folder', | ||
required: true, | ||
}) | ||
.strict(); | ||
|
||
const {reactNativeRootPath, templatePath} = argv; | ||
|
||
const VERDACCIO_CONFIG_PATH = `${reactNativeRootPath}/scripts/template/verdaccio.yml`; | ||
const VERDACCIO_STORAGE_PATH = `${templatePath}/node_modules`; | ||
|
||
const PACKAGES_TO_PUBLISH_PATHS = []; | ||
|
||
function install() { | ||
const VERDACCIO_PID = setupVerdaccio( | ||
reactNativeRootPath, | ||
VERDACCIO_CONFIG_PATH, | ||
VERDACCIO_STORAGE_PATH, | ||
); | ||
process.stdout.write('Bootstrapped Verdaccio \u2705\n'); | ||
|
||
// Publish all necessary packages... | ||
for (const packagePath of PACKAGES_TO_PUBLISH_PATHS) { | ||
execSync('npm publish --registry http://localhost:4873 --access public', { | ||
cwd: `${reactNativeRootPath}/${packagePath}`, | ||
stdio: [process.stdin, process.stdout, process.stderr], | ||
}); | ||
|
||
process.stdout.write(`Published /${packagePath} to proxy \u2705\n`); | ||
} | ||
|
||
spawnSync('yarn', ['install'], { | ||
cwd: templatePath, | ||
stdio: [process.stdin, process.stdout, process.stderr], | ||
}); | ||
process.stdout.write('Installed dependencies via Yarn \u2705\n'); | ||
|
||
process.stdout.write(`Killing verdaccio. PID — ${VERDACCIO_PID}...\n`); | ||
execSync(`kill -9 ${VERDACCIO_PID}`); | ||
process.stdout.write('Killed Verdaccio process \u2705\n'); | ||
|
||
process.exit(); | ||
} | ||
|
||
install(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
storage: ./storage | ||
auth: | ||
htpasswd: | ||
file: ./htpasswd | ||
uplinks: | ||
npmjs: | ||
url: https://registry.npmjs.org/ | ||
max_fails: 40 | ||
maxage: 30m | ||
timeout: 60s | ||
fail_timeout: 10m | ||
cache: false | ||
agent_options: | ||
keepAlive: true | ||
maxSockets: 40 | ||
maxFreeSockets: 10 | ||
packages: | ||
'@*/*': | ||
access: $all | ||
publish: $authenticated | ||
proxy: npmjs | ||
'**': | ||
access: $all | ||
publish: $all | ||
proxy: npmjs | ||
logs: | ||
- {type: file, path: verdaccio.log, format: json, level: warn} |