Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(package.json): fix settings allowing developers to only use pnpm (
#673) We tried running the `npm i` command on this project. We found some problems, which we will fix. + Automatically inputs "y" into the stdin of the `npx only-allow pnpm` command The `npx` command prompts before installing a non-existent package. This prompt will continue if type "y". Thus, we have fixed it to automatically input "y". Note: The `--yes` option is not used. This is because the `npx` command included with npm v6 will not work with the `--yes` option. + Add incorrect `engines` field for npm and yarn In npm v7 and later, the `npm install` command executes the `preinstall` script after downloading the dependencies. Thus, after waiting for the dependencies to download, the developer learns that he/she/they should use pnpm instead of npm for this project. This is a waste of time. So we set an incorrect value in the `engines` field. npm will display a warning that the `engines` field is invalid while downloading dependencies. Thus, the developer can abort the dependency download. see https://zenn.dev/uttk/articles/create-pnpm-monorepo Note: If we set the `engine-strict` config flag, npm will automatically abort the dependency download. However, error messages reporting incorrect `engines` fields are never easy to read. The developer will have difficulty knowing why the `npm install` command is failing. Error messages displayed by the `npx only-allow pnpm` command are better. --- * chore(package.json): fix settings allowing developers to only use pnpm We tried running the `npm i` command on this project. We found some problems, which we will fix. + Add `--yes` option to `npx only-allow pnpm` command The npx command prompts before installing a non-existent package. To suppress this prompt, the `--yes` option must be added. + Add incorrect `engines` field for npm and yarn The `npm install` command executes the `preinstall` script after downloading the dependencies. Thus, after waiting for the dependencies to download, the developer learns that he/she/they should use pnpm instead of npm for this project. This is a waste of time. So we set an incorrect value in the `engines` field. npm will display a warning that the `engines` field is invalid while downloading dependencies. Thus, the developer can abort the dependency download. see https://zenn.dev/uttk/articles/create-pnpm-monorepo Note: If we set the `engine-strict` config flag, npm will automatically abort the dependency download. However, error messages reporting incorrect `engines` fields are never easy to read. The developer will have difficulty knowing why the `npm install` command is failing. Error messages displayed by the `npx --yes only-allow pnpm` command are better. * chore(package.json): shouldn't use the `--yes` option with the `npx` command The `npx` command included with npm v6 does not allow the `--yes` option. However, the `npx` command included with npm v7 and later will print a prompt if the `--yes` option is not added. To solve this problem, we decided to include `only-allow` in the dev dependencies for this project. This will ensure that `only-allow` is executed correctly in each version of the `npx` command: + If using npm v6, the `--yes` option is not necessary. npx will run `only-allow` without prompting. + If using npm v7 or later, the `npm install` command will install the dependencies before running the `preinstall` script. `only-allow` is included in the dependencies, so npx will not fetch `only-allow` from remote. Therefore, npx will not print a prompt. * revert(package.json): chore(package.json): shouldn't use the `--yes` option with the `npx` command With yarn, the `preinstall` script is run before the dependencies are installed. In this case, the npx command will print a prompt if npm v7 or later is installed in the development environment. This reverts commit fe4cb64. * chore(package.json): instead of using the `--yes` option, input "y" into stdin of the `npx` command The `npx` command included with npm v6 does not allow the `--yes` option. However, the `npx` command included with npm v7 and later will print a prompt if the `--yes` option is not added. To solve this problem, we decided to automatically input "y" into the stdin of the `npx` command. This is the same solution as using the `yes` command in Unix. However, the `yes` command is not available on Windows, so the `node` command is used to output "y" instead of it. Note: The `npx` command included with npm v7 and later seems not to print a prompt just the Unix pipeline is connected. see https://github.com/npm/cli/blob/libnpmexec-v5.0.11/workspaces/libnpmexec/lib/index.js#L245-L262 see https://github.com/npm/cli/blob/libnpmexec-v5.0.11/workspaces/libnpmexec/test/prompt.js#L167-L186 Thus, without outputting "y", this problem can be solved with the following simple command: `node -e "" | npx only-allow pnpm` However, this behavior may not be the same for future `npx` commands.