Skip to content

Commit 06ebd8d

Browse files
committed
Force use of unmanaged ajv-cli version as required
The ajv-cli command line tool is used for validating data files against their JSON schema. In general, it is preferable, and for some schemas even mandatory, to use the modern versions of ajv-cli. However, support for the "Draft 4" schema specification was dropped in ajv-cli version 4.0.0. So when working with JSON schemas that specify that draft, it is necessary to use ajv-cli 3.3.0, the last compatible version. This means that some projects may have dependencies on multiple versions of ajv-cli. This package is distributed via the npm registry. Unfortunately, npm does not have support for managing multiple versions of a binary dependency. npm's "alias" feature seems ideal: https://docs.npmjs.com/cli/v8/commands/npm-install > npm install <alias>@npm:<name>: > Install a package under a custom alias. Allows multiple versions of a same-name package side-by-side However, this is only suitable for code dependencies. There is no special handling of providing access via npx to the binary of the aliased package. So the only reasonable option is to manage only one of the two tool versions. This should be a simple matter of specifying the version of the package in the commands using the unmanaged tool: `npx [email protected]`: https://docs.npmjs.com/cli/v8/commands/npx#description > Package names with a specifier will only be considered a match if they have the exact same name and version as the > local dependency. Unfortunately, a bug in npm causes the version specifier to be ignored when the managed version is already installed. This bug is reportedly fixed, but the fix is not in a Node.js release yet, and even after that it may take us quite some time to upgrade to the version of Node.js which contains the fix. The workaround implemented here is to run the unmanaged tool command from outside the project folder.
1 parent dd2f46d commit 06ebd8d

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

Taskfile.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,18 @@ tasks:
119119
SCHEMA_PATH:
120120
sh: task utility:mktemp-file TEMPLATE="dependabot-schema-XXXXXXXXXX.json"
121121
DATA_PATH: "**/dependabot.yml"
122+
PROJECT_FOLDER:
123+
sh: pwd
124+
WORKING_FOLDER:
125+
sh: task utility:mktemp-folder TEMPLATE="dependabot-validate-XXXXXXXXXX"
122126
cmds:
123127
- wget --quiet --output-document="{{.SCHEMA_PATH}}" {{.SCHEMA_URL}}
124128
- |
129+
cd "{{.WORKING_FOLDER}}" # Workaround for https://github.com/npm/cli/issues/3210
125130
npx ajv-cli@{{.SCHEMA_DRAFT_4_AJV_CLI_VERSION}} validate \
126131
--all-errors \
127132
-s "{{.SCHEMA_PATH}}" \
128-
-d "{{.DATA_PATH}}"
133+
-d "{{.PROJECT_FOLDER}}/{{.DATA_PATH}}"
129134
130135
dependabot:sync:
131136
desc: Sync workflow duplicates for dependabot checks
@@ -373,6 +378,10 @@ tasks:
373378
STYLELINTRC_SCHEMA_PATH:
374379
sh: task utility:mktemp-file TEMPLATE="stylelintrc-schema-XXXXXXXXXX.json"
375380
INSTANCE_PATH: "**/package.json"
381+
PROJECT_FOLDER:
382+
sh: pwd
383+
WORKING_FOLDER:
384+
sh: task utility:mktemp-folder TEMPLATE="dependabot-validate-XXXXXXXXXX"
376385
cmds:
377386
- wget --quiet --output-document="{{.SCHEMA_PATH}}" {{.SCHEMA_URL}}
378387
- wget --quiet --output-document="{{.AVA_SCHEMA_PATH}}" {{.AVA_SCHEMA_URL}}
@@ -382,6 +391,7 @@ tasks:
382391
- wget --quiet --output-document="{{.SEMANTIC_RELEASE_SCHEMA_PATH}}" {{.SEMANTIC_RELEASE_SCHEMA_URL}}
383392
- wget --quiet --output-document="{{.STYLELINTRC_SCHEMA_PATH}}" {{.STYLELINTRC_SCHEMA_URL}}
384393
- |
394+
cd "{{.WORKING_FOLDER}}" # Workaround for https://github.com/npm/cli/issues/3210
385395
npx ajv-cli@{{.SCHEMA_DRAFT_4_AJV_CLI_VERSION}} validate \
386396
--all-errors \
387397
-s "{{.SCHEMA_PATH}}" \
@@ -391,7 +401,7 @@ tasks:
391401
-r "{{.PRETTIERRC_SCHEMA_PATH}}" \
392402
-r "{{.SEMANTIC_RELEASE_SCHEMA_PATH}}" \
393403
-r "{{.STYLELINTRC_SCHEMA_PATH}}" \
394-
-d "{{.INSTANCE_PATH}}"
404+
-d "{{.PROJECT_FOLDER}}/{{.INSTANCE_PATH}}"
395405
396406
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/poetry-task/Taskfile.yml
397407
poetry:install-deps:
@@ -514,6 +524,17 @@ tasks:
514524
vars:
515525
RAW_PATH: "{{.RAW_PATH}}"
516526

527+
# Make a temporary folder named according to the passed TEMPLATE variable and print the path passed to stdout
528+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
529+
utility:mktemp-folder:
530+
vars:
531+
RAW_PATH:
532+
sh: mktemp --directory --tmpdir "{{.TEMPLATE}}"
533+
cmds:
534+
- task: utility:normalize-path
535+
vars:
536+
RAW_PATH: "{{.RAW_PATH}}"
537+
517538
# Print a normalized version of the path passed via the RAW_PATH variable to stdout
518539
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
519540
utility:normalize-path:

workflow-templates/assets/check-npm-task/Taskfile.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ tasks:
3939
STYLELINTRC_SCHEMA_PATH:
4040
sh: task utility:mktemp-file TEMPLATE="stylelintrc-schema-XXXXXXXXXX.json"
4141
INSTANCE_PATH: "**/package.json"
42+
PROJECT_FOLDER:
43+
sh: pwd
44+
WORKING_FOLDER:
45+
sh: task utility:mktemp-folder TEMPLATE="dependabot-validate-XXXXXXXXXX"
4246
cmds:
4347
- wget --quiet --output-document="{{.SCHEMA_PATH}}" {{.SCHEMA_URL}}
4448
- wget --quiet --output-document="{{.AVA_SCHEMA_PATH}}" {{.AVA_SCHEMA_URL}}
@@ -48,6 +52,7 @@ tasks:
4852
- wget --quiet --output-document="{{.SEMANTIC_RELEASE_SCHEMA_PATH}}" {{.SEMANTIC_RELEASE_SCHEMA_URL}}
4953
- wget --quiet --output-document="{{.STYLELINTRC_SCHEMA_PATH}}" {{.STYLELINTRC_SCHEMA_URL}}
5054
- |
55+
cd "{{.WORKING_FOLDER}}" # Workaround for https://github.com/npm/cli/issues/3210
5156
npx ajv-cli@{{.SCHEMA_DRAFT_4_AJV_CLI_VERSION}} validate \
5257
--all-errors \
5358
-s "{{.SCHEMA_PATH}}" \
@@ -57,4 +62,4 @@ tasks:
5762
-r "{{.PRETTIERRC_SCHEMA_PATH}}" \
5863
-r "{{.SEMANTIC_RELEASE_SCHEMA_PATH}}" \
5964
-r "{{.STYLELINTRC_SCHEMA_PATH}}" \
60-
-d "{{.INSTANCE_PATH}}"
65+
-d "{{.PROJECT_FOLDER}}/{{.INSTANCE_PATH}}"

workflow-templates/assets/windows-task/Taskfile.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ tasks:
1313
vars:
1414
RAW_PATH: "{{.RAW_PATH}}"
1515

16+
# Make a temporary folder named according to the passed TEMPLATE variable and print the path passed to stdout
17+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
18+
utility:mktemp-folder:
19+
vars:
20+
RAW_PATH:
21+
sh: mktemp --directory --tmpdir "{{.TEMPLATE}}"
22+
cmds:
23+
- task: utility:normalize-path
24+
vars:
25+
RAW_PATH: "{{.RAW_PATH}}"
26+
1627
# Print a normalized version of the path passed via the RAW_PATH variable to stdout
1728
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
1829
utility:normalize-path:

0 commit comments

Comments
 (0)