Skip to content

Commit

Permalink
chore(package.json): fix settings allowing developers to only use pnpm (
Browse files Browse the repository at this point in the history
#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.
sounisi5011 authored Feb 26, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 2265316 commit 96a311f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@
"fmt:ts:eslint": "eslint --cache --report-unused-disable-directives --fix --ext .ts,.cts,.mts ./",
"fmt:xs": "npm-run-all fmt:xs:eslint --parallel fmt:{ts,js}:dprint fmt:xs:eslint",
"fmt:xs:eslint": "run-s 'lint:eslint -- --fix'",
"preinstall": "npx only-allow pnpm",
"preinstall": "node -p \"'y\\n'\" | npx only-allow pnpm",
"lint": "run-p lint:*",
"lint:actions": "actionlint",
"lint:eslint": "eslint --cache --report-unused-disable-directives ./",
@@ -79,6 +79,8 @@
},
"engines": {
"node": "^12.17.x || 14.x || 15.x || 16.x || 17.x || >=18.x",
"pnpm": "6.x"
"npm": "use pnpm please!",
"pnpm": "6.x",
"yarn": "use pnpm please!"
}
}

0 comments on commit 96a311f

Please sign in to comment.