Skip to content

Commit

Permalink
fix: ensure link-workspace-packages is true in npmrc (#764)
Browse files Browse the repository at this point in the history
fix #761
  • Loading branch information
agdimech authored Apr 17, 2024
1 parent 914d516 commit d143899
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions .npmrc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions packages/monorepo/src/components/nx-configurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SPDX-License-Identifier: Apache-2.0 */
import * as path from "path";
import {
Component,
IniFile,
JsonFile,
License,
Project,
Expand Down Expand Up @@ -485,6 +486,27 @@ export class NxConfigurator extends Component implements INxProjectCore {
},
}).synthesize();
}

if (
!ProjectUtils.isNamedInstanceOf(this.project, NodeProject) &&
!this.project.tryFindFile(".npmrc")
) {
new IniFile(this.project, ".npmrc", {
obj: {
"resolution-mode": "highest",
yes: "true",
"prefer-workspace-packages": "true",
"link-workspace-packages": "true",
},
}).synthesize();
} else if (
ProjectUtils.isNamedInstanceOf(this.project, NodeProject) &&
this.project.package.packageManager === NodePackageManager.PNPM
) {
this.project.npmrc.addConfig("prefer-workspace-packages", "true");
this.project.npmrc.addConfig("link-workspace-packages", "true");
this.project.npmrc.addConfig("yes", "true");
}
}

private _invokeInstallCITasks() {
Expand Down
16 changes: 16 additions & 0 deletions packages/monorepo/test/__snapshots__/monorepo.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions packages/type-safe-api/scripts/type-safe-api/common/.pnpmfile.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */

const readPackage = (pkg, context) => {
if (pkg.peerDependencies && pkg.peerDependencies.react) {
// fixes react error "Error: Invalid hook call."
// with multiple copy of react in the node_modules folder
context.log(`[${pkg.name}] Removing react as a peer dependency (https://bit.ly/3jmD8J6).`)
delete pkg.peerDependencies.react;
}
return pkg;
};

module.exports = {
hooks: {
readPackage
}
};
2 changes: 2 additions & 0 deletions packages/type-safe-api/scripts/type-safe-api/common/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ run_install_command() {
# installs the passed packages with the package manager in use
_install_packages() {
log "installing packages :: $@"
_script_dir="$( cd -- "$(dirname $([ -L "${BASH_SOURCE[0]:-$0}" ] && readlink -f "${BASH_SOURCE[0]:-$0}" || echo "${BASH_SOURCE[0]:-$0}"))" >/dev/null 2>&1 ; pwd -P )";
_install_packages_working_dir=`pwd`
_install_packages_pdk_base_dir="$HOME/.pdk/$AWS_PDK_VERSION/type-safe-api/$pkg_manager"

Expand Down Expand Up @@ -90,6 +91,7 @@ _install_packages() {
# Install if any packages are missing
if [ "$_install_packages_should_install" == "true" ]; then
npm init --yes
cp $_script_dir/.pnpmfile.cjs $_install_packages_pdk_dir
run_install_command "$@"
fi

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d143899

Please sign in to comment.