如何在React Native中自动链接依赖项的依赖项?

时间:2019-11-21 17:21:11

标签: react-native cocoapods

我想与另一个应用程序共享组件,因此将它们移动到单独的NPM软件包中。该软件包的结构如下:

const updateRelations = async (relation) => {
  let x1 = await findX(x1);
  let y1 = await findAndUpdateY(y1, x1);
}
let relations = JSON.parse(data);
for (const relation of relations) {
  await updateRelations(relation);
}

某些组件使用其他第三方库,它们在- src --- components ----- component A ----- component B - package.json 中列出。

现在,当将该共享软件包安装到第二个项目时,这些第三方依赖关系不会自动链接。例如,呼叫package.json时未安装它们。

是否可以通过某种方式安装这些第三方依赖关系?

1 个答案:

答案 0 :(得分:1)

我们可以按如下所示在@ react-native-community / cli中修补函数findDependencies,以启用依赖关系的自动链接依赖

  Run npm install
  npm install
  npm run build --if-present
  npm run test --if-present
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"

> core-js@3.6.4 postinstall D:\a\SleepDiary\SleepDiary\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"


> @angular/cli@10.1.3 postinstall D:\a\SleepDiary\SleepDiary\node_modules\@angular\cli
> node ./bin/postinstall/script.js

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\webpack-dev-server\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules\watchpack-chokidar2\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 1494 packages from 1234 contributors and audited 1499 packages in 79.932s
found 0 vulnerabilities


> sleep-diary@0.0.0 build D:\a\SleepDiary\SleepDiary
> ng build

Compiling @angular/core : es2015 as esm2015
Compiling @angular/common : es2015 as esm2015
Compiling @angular/platform-browser : es2015 as esm2015
Compiling @angular/platform-browser-dynamic : es2015 as esm2015
Compiling @angular/router : es2015 as esm2015
Compiling @angular/cdk/clipboard : es2015 as esm2015
Compiling @angular/cdk/platform : es2015 as esm2015
Compiling @angular/cdk/bidi : es2015 as esm2015
Compiling @angular/cdk/collections : es2015 as esm2015
Compiling @angular/cdk/scrolling : es2015 as esm2015
Compiling @angular/cdk/drag-drop : es2015 as esm2015
Compiling @angular/cdk/keycodes : es2015 as esm2015
Compiling @angular/cdk/observers : es2015 as esm2015
Compiling @angular/cdk/a11y : es2015 as esm2015
Compiling @angular/animations : es2015 as esm2015
Compiling @angular/animations/browser : es2015 as esm2015
Compiling @angular/platform-browser/animations : es2015 as esm2015
Compiling @angular/forms : es2015 as esm2015
Compiling @angular/material/core : es2015 as esm2015
Compiling @angular/cdk/portal : es2015 as esm2015
Compiling @angular/cdk/overlay : es2015 as esm2015
Compiling @angular/material/form-field : es2015 as esm2015
Compiling @angular/material/autocomplete : es2015 as esm2015
Compiling @angular/material/badge : es2015 as esm2015
Compiling @angular/cdk/layout : es2015 as esm2015
Compiling @angular/material/bottom-sheet : es2015 as esm2015
Compiling @angular/material/button-toggle : es2015 as esm2015
Compiling @angular/material/card : es2015 as esm2015
Compiling @angular/material/checkbox : es2015 as esm2015
Compiling @angular/material/chips : es2015 as esm2015
Compiling @angular/cdk/stepper : es2015 as esm2015
Compiling @angular/material/button : es2015 as esm2015
Compiling @angular/common/http : es2015 as esm2015
Compiling @angular/material/icon : es2015 as esm2015
Compiling @angular/material/stepper : es2015 as esm2015
Compiling @angular/material/dialog : es2015 as esm2015
Compiling @angular/cdk/text-field : es2015 as esm2015
Compiling @angular/material/input : es2015 as esm2015
Compiling @angular/material/datepicker : es2015 as esm2015
Compiling @angular/cdk/accordion : es2015 as esm2015
Compiling @angular/material/expansion : es2015 as esm2015
Compiling @angular/material/grid-list : es2015 as esm2015
Compiling @angular/material/divider : es2015 as esm2015
Compiling @angular/material/list : es2015 as esm2015
Compiling @angular/material/menu : es2015 as esm2015
Compiling @angular/material/progress-bar : es2015 as esm2015
Compiling @angular/material/progress-spinner : es2015 as esm2015
Compiling @angular/material/radio : es2015 as esm2015
Compiling @angular/material/sidenav : es2015 as esm2015
Compiling @angular/material/slider : es2015 as esm2015
Compiling @angular/material/slide-toggle : es2015 as esm2015
Compiling @angular/material/snack-bar : es2015 as esm2015
Compiling @angular/cdk/table : es2015 as esm2015
Compiling @angular/material/select : es2015 as esm2015
Compiling @angular/material/tooltip : es2015 as esm2015
Compiling @angular/material/paginator : es2015 as esm2015
Compiling @angular/material/sort : es2015 as esm2015
Compiling @angular/material/table : es2015 as esm2015
Compiling @angular/material/tabs : es2015 as esm2015
Compiling @angular/material/toolbar : es2015 as esm2015
Compiling @angular/cdk/tree : es2015 as esm2015
Compiling @angular/material/tree : es2015 as esm2015

chunk {main} main.js, main.js.map (main) 35.6 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 139 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 168 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 6.03 MB [initial] [rendered]
Date: 2020-09-29T06:44:33.715Z - Hash: d5c650f4ac85337a8e18 - Time: 17250ms

> sleep-diary@0.0.0 test D:\a\SleepDiary\SleepDiary
> ng test

Compiling @angular/core/testing : es2015 as esm2015
Compiling @angular/platform-browser/testing : es2015 as esm2015
Compiling @angular/compiler/testing : es2015 as esm2015
Compiling @angular/platform-browser-dynamic/testing : es2015 as esm2015
Compiling @angular/common/testing : es2015 as esm2015
Compiling @angular/router/testing : es2015 as esm2015
29 09 2020 06:44:54.035:WARN [karma]: No captured browser, open http://localhost:9876/
29 09 2020 06:44:54.041:INFO [karma-server]: Karma v5.2.3 server started at http://localhost:9876/
29 09 2020 06:44:54.042:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
29 09 2020 06:44:54.047:INFO [launcher]: Starting browser Chrome
29 09 2020 06:45:03.234:WARN [karma]: No captured browser, open http://localhost:9876/
29 09 2020 06:45:07.874:INFO [Chrome 85.0.4183.102 (Windows 10)]: Connected on socket zXnYWqIDSNfH7VtIAAAA with id 11289129
Chrome 85.0.4183.102 (Windows 10): Executed 0 of 7 SUCCESS (0 secs / 0 secs)
Chrome 85.0.4183.102 (Windows 10): Executed 1 of 7 SUCCESS (0 secs / 0.003 secs)
Chrome 85.0.4183.102 (Windows 10): Executed 2 of 7 SUCCESS (0 secs / 0.003 secs)
Chrome 85.0.4183.102 (Windows 10): Executed 3 of 7 SUCCESS (0 secs / 0.004 secs)
Chrome 85.0.4183.102 (Windows 10): Executed 4 of 7 SUCCESS (0 secs / 0.004 secs)
Chrome 85.0.4183.102 (Windows 10): Executed 5 of 7 SUCCESS (0 secs / 0.087 secs)
ERROR: ''mat-sidenav-container' is not a known element:
1. If 'mat-sidenav-container' is an Angular component, then verify that it is part of this module.
2. If 'mat-sidenav-container' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
Chrome 85.0.4183.102 (Windows 10): Executed 5 of 7 SUCCESS (0 secs / 0.087 secs)
ERROR: ''mat-sidenav-container' is not a known element:
1. If 'mat-sidenav-container' is an Angular component, then verify that it is part of this module.
2. If 'mat-sidenav-container' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
ERROR: ''mat-sidenav' is not a known element:
1. If 'mat-sidenav' is an Angular component, then verify that it is part of this module.
2. If 'mat-sidenav' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
Chrome 85.0.4183.102 (Windows 10): Executed 5 of 7 SUCCESS (0 secs / 0.087 secs)
ERROR: ''mat-sidenav' is not a known element:
1. If 'mat-sidenav' is an Angular component, then verify that it is part of this module.
2. If 'mat-sidenav' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
ERROR: ''mat-sidenav-content' is not a known element:
1. If 'mat-sidenav-content' is an Angular component, then verify that it is part of this module.
2. If 'mat-sidenav-content' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
Chrome 85.0.4183.102 (Windows 10): Executed 5 of 7 SUCCESS (0 secs / 0.087 secs)
ERROR: ''mat-sidenav-content' is not a known element:
1. If 'mat-sidenav-content' is an Angular component, then verify that it is part of this module.
2. If 'mat-sidenav-content' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
Chrome 85.0.4183.102 (Windows 10): Executed 6 of 7 SUCCESS (0 secs / 0.104 secs)
Chrome 85.0.4183.102 (Windows 10): Executed 7 of 7 SUCCESS (0 secs / 0.11 secs)
Chrome 85.0.4183.102 (Windows 10): Executed 7 of 7 SUCCESS (0.14 secs / 0.11 secs)
TOTAL: 7 SUCCESS
TOTAL: 7 SUCCESS