forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
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 Summary: 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](facebook#35263) Differential Revision: D41498086 fbshipit-source-id: 1b185857c21f4cf4996fb1fa4faca5f9e77f534f
- Loading branch information
1 parent
c5a8425
commit 08141a7
Showing
6 changed files
with
163 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,22 +9,41 @@ | |
|
||
'use strict'; | ||
|
||
const {exec} = require('shelljs'); | ||
const spawn = require('child_process').spawn; | ||
|
||
function setupVerdaccio() { | ||
const verdaccioProcess = spawn('npx', [ | ||
'[email protected]', | ||
'--config', | ||
'.circleci/verdaccio.yml', | ||
]); | ||
const {execSync, spawn} = require('child_process'); | ||
|
||
function setupVerdaccio( | ||
reactNativeRootPath, // Path to React Native root folder | ||
verdaccioConfigPath, // Path to Verdaccio config file, which you want to use for bootstrapping Verdaccio | ||
verdaccioStoragePath, // Path to Verdaccio storage, where it should keep packages. Optional. Default value will be decided by your Verdaccio config | ||
) { | ||
if (!reactNativeRootPath) { | ||
throw new Error( | ||
'Path to React Native repo root is not specified. You should provide it as a first argument', | ||
); | ||
} | ||
|
||
if (!verdaccioConfigPath) { | ||
throw new Error( | ||
'Path to Verdaccio config is not specified. You should provide it as a second argument', | ||
); | ||
} | ||
|
||
const verdaccioProcess = spawn( | ||
'npx', | ||
['[email protected]', '--config', pathToConfig], | ||
{env: {...process.env, VERDACCIO_STORAGE_PATH: verdaccioStoragePath}}, | ||
); | ||
|
||
const VERDACCIO_PID = verdaccioProcess.pid; | ||
exec('npx [email protected] http://localhost:4873'); | ||
exec('npm set registry http://localhost:4873'); | ||
exec('echo "//localhost:4873/:_authToken=secretToken" > .npmrc'); | ||
|
||
execSync('npx [email protected] http://localhost:4873'); | ||
|
||
execSync('npm set registry http://localhost:4873'); | ||
execSync('echo "//localhost:4873/:_authToken=secretToken" > .npmrc', { | ||
cwd: pathToRoot, | ||
}); | ||
|
||
return VERDACCIO_PID; | ||
} | ||
|
||
module.exports = { | ||
setupVerdaccio: setupVerdaccio, | ||
}; | ||
module.exports = setupVerdaccio; |
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,38 @@ | ||
## 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: | ||
+ '@react-native/<my-migrated-package>': | ||
+ 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 publish your package | ||
|
||
```diff | ||
// Publish all necessary packages... | ||
|
||
+execSync('npm publish --registry http://localhost:4873 --access public', { | ||
+ cwd: `${reactNativeRootPath}/packages/<path-to-package>`, | ||
+ stdio: [process.stdin, process.stdout, process.stderr], | ||
+}); | ||
+process.stdout.write('Published <migrated-package-name> to proxy \u2705\n'); | ||
|
||
spawnSync('yarn', ['install'], { | ||
cwd: PATH_TO_TEMPLATE, | ||
stdio: [process.stdin, process.stdout, process.stderr], | ||
}); | ||
``` |
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,56 @@ | ||
/** | ||
* 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 {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 = './verdaccio.yml'; | ||
const VERDACCIO_STORAGE_PATH = `${templatePath}/node_modules`; | ||
|
||
function install() { | ||
const VERDACCIO_PID = setupVerdaccio( | ||
reactNativeRootPath, | ||
VERDACCIO_CONFIG_PATH, | ||
VERDACCIO_STORAGE_PATH, | ||
); | ||
process.stdout.write('Bootstrapped Verdaccio \u2705\n'); | ||
|
||
// Publish all necessary packages... | ||
|
||
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} |