diff options
| author | Ed Slocomb <edslocomb@gmail.com> | 2023-11-05 12:08:58 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-05 12:08:58 -0800 |
| commit | 54a192c3454e82be9d5ad910d80796b27d58035f (patch) | |
| tree | a4769b1d43708709f37965837b705ec2fc30817b /test | |
| parent | 47547ea6941e605198369de9a7f3a63847765e5d (diff) | |
Add support for formatters locally installed via yarn 2+ pnp mode (#200)
This adds support for formatters installed locally in project
directories via yarn 2's "zero install" [pnp
mode](https://yarnpkg.com/features/pnp).
It's quite similar to the support for formatters installed locally in a
project's `node_modules` via npm, and leverages the `npx` symbol, so
existing formatter definitions should work without modification.
This checks for a `.pnp.cjs` file (expected in the project root for yarn
pnp projects), then looks for a yarn executable, and checks the version
of yarn to make sure it supports pnp. If that works, we just push
`"yarn"` onto the front of `command`.
I've only tested this with a locally installed `prettier.js`. It's very
much a works-for-me draft, I'm putting in a PR to make sure this is a
workable approach before going any further with it.
---------
Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
Diffstat (limited to 'test')
| -rwxr-xr-x | test/formatters/apheleia-ft.el | 16 | ||||
| -rwxr-xr-x | test/formatters/install-common.bash | 15 | ||||
| -rw-r--r-- | test/formatters/installers/prettier-ruby.bash | 17 | ||||
| -rw-r--r-- | test/formatters/installers/prettier-svelte.bash | 3 |
4 files changed, 25 insertions, 26 deletions
diff --git a/test/formatters/apheleia-ft.el b/test/formatters/apheleia-ft.el index 5396115..a8ac9d4 100755 --- a/test/formatters/apheleia-ft.el +++ b/test/formatters/apheleia-ft.el @@ -101,11 +101,12 @@ relative to repo root, as returned by git diff --name-only." ((string-match "^scripts/formatters/\\([^/]+\\)$" changed-file) (let ((script (match-string 1 changed-file))) - (map-keys - (map-filter - (lambda (fmt def) - (member script def)) - apheleia-formatters))))))) + (mapcar #'symbol-name + (map-keys + (map-filter + (lambda (fmt def) + (and (listp def) (member script def))) + apheleia-formatters)))))))) (defun apheleia-ft--get-formatters-for-pull-request () "Return list of formatter string names that were touched in this PR. @@ -133,7 +134,10 @@ main." "Print to stdout a comma-delimited list of formatters changed in this PR." (princ (concat (string-join - (apheleia-ft--get-formatters-for-pull-request) ",") + (cl-remove-duplicates + (apheleia-ft--get-formatters-for-pull-request) + :test 'string=) + ",") "\n"))) (defun apheleia-ft--read-file (filename) diff --git a/test/formatters/install-common.bash b/test/formatters/install-common.bash index 113e7ac..6b4489d 100755 --- a/test/formatters/install-common.bash +++ b/test/formatters/install-common.bash @@ -6,14 +6,10 @@ export DEBIAN_FRONTEND=noninteractive apt-get update apt-get install -y ca-certificates curl gnupg lsb-release software-properties-common -curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - - -ubuntu_name="$(lsb_release -cs)" -node_repo="$(curl -fsSL https://deb.nodesource.com/setup_current.x | grep NODEREPO= | grep -Eo 'node_[0-9]+\.x' | head -n1)" - -tee -a /etc/apt/sources.list.d/nodejs.list >/dev/null <<EOF -deb [arch=amd64] https://deb.nodesource.com/${node_repo} ${ubuntu_name} main -EOF +mkdir -p /etc/apt/keyrings +curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg +NODE_MAJOR=20 +echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list add-apt-repository -n ppa:longsleep/golang-backports @@ -30,9 +26,6 @@ nodejs sudo unzip wget -sudo -unzip -wget " diff --git a/test/formatters/installers/prettier-ruby.bash b/test/formatters/installers/prettier-ruby.bash index 611f5c6..9351a44 100644 --- a/test/formatters/installers/prettier-ruby.bash +++ b/test/formatters/installers/prettier-ruby.bash @@ -1,15 +1,16 @@ # Need ruby for gem, need gcc and ruby headers for native gem deps apt-get install -y ruby ruby-dev gcc -# Install the plugin -npm install -g prettier @prettier/plugin-ruby - -# Have to install from source because release not tagged yet -# https://github.com/ruby-syntax-tree/syntax_tree-rbs/pull/34 -# https://stackoverflow.com/a/11767563 -gem install specific_install -gem specific_install -l https://github.com/ruby-syntax-tree/syntax_tree-rbs.git +# Apparently rubygems does not know how to do dependency resolution. +# So we have to manually install an old version of this dependency to +# avoid the latest version getting installed and then failing to build +# because it does not support ruby 2.7 which is what we have. +gem install rbs -v 3.1.3 # These are required dependencies documented at # https://www.npmjs.com/package/@prettier/plugin-ruby gem install prettier_print syntax_tree syntax_tree-haml syntax_tree-rbs + +# Install the plugin +cd /tmp +npm install --save-dev prettier @prettier/plugin-ruby diff --git a/test/formatters/installers/prettier-svelte.bash b/test/formatters/installers/prettier-svelte.bash index 70fae61..1ab0809 100644 --- a/test/formatters/installers/prettier-svelte.bash +++ b/test/formatters/installers/prettier-svelte.bash @@ -1 +1,2 @@ -npm install -g prettier-plugin-svelte prettier +cd /tmp +npm install --save-dev prettier-plugin-svelte prettier |
