mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-06 04:21:09 +00:00
fix: resolve plugins from npm packages correctly (#1749)
This commit is contained in:
committed by
GitHub
parent
67ea331257
commit
81ca339a16
6
.changeset/strange-starfishes-press.md
Normal file
6
.changeset/strange-starfishes-press.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@redocly/openapi-core": patch
|
||||||
|
"@redocly/cli": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixed an issue where the plugins in external NPM packages could not be resolved if the CLI package was installed globally.
|
||||||
92
.github/workflows/smoke-plugins.yaml
vendored
Normal file
92
.github/workflows/smoke-plugins.yaml
vendored
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
name: Plugins smoke tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
|
env:
|
||||||
|
CI: true
|
||||||
|
REDOCLY_TELEMETRY: off
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
prepare-smoke-plugins:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 18
|
||||||
|
cache: 'npm'
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Prepare Smoke
|
||||||
|
run: bash ./scripts/prepare-smoke-plugins.sh
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: __tests__/smoke-plugins/
|
||||||
|
key: cache-plugins-${{ github.run_id }}-${{ github.run_attempt }}
|
||||||
|
|
||||||
|
run-smoke-plugins--npm--node-22:
|
||||||
|
needs: prepare-smoke-plugins
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: __tests__/smoke-plugins/
|
||||||
|
key: cache-plugins-${{ github.run_id }}-${{ github.run_attempt }}
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 22
|
||||||
|
- run: bash ./__tests__/smoke-plugins/run-smoke.sh
|
||||||
|
|
||||||
|
run-smoke-plugins--npm--node-20:
|
||||||
|
needs: prepare-smoke-plugins
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: __tests__/smoke-plugins/
|
||||||
|
key: cache-plugins-${{ github.run_id }}-${{ github.run_attempt }}
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
|
- run: bash ./__tests__/smoke-plugins/run-smoke.sh
|
||||||
|
|
||||||
|
run-smoke-plugins--npm--node-18:
|
||||||
|
needs: prepare-smoke-plugins
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: __tests__/smoke-plugins/
|
||||||
|
key: cache-plugins-${{ github.run_id }}-${{ github.run_attempt }}
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 18
|
||||||
|
- run: bash ./__tests__/smoke-plugins/run-smoke.sh
|
||||||
|
|
||||||
|
run-smoke-plugins--npm--node-16:
|
||||||
|
needs: prepare-smoke-plugins
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: __tests__/smoke-plugins/
|
||||||
|
key: cache-plugins-${{ github.run_id }}-${{ github.run_attempt }}
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
- run: bash ./__tests__/smoke-plugins/run-smoke.sh
|
||||||
|
|
||||||
|
run-smoke-plugins--npm--node-14:
|
||||||
|
needs: prepare-smoke-plugins
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: __tests__/smoke-plugins/
|
||||||
|
key: cache-plugins-${{ github.run_id }}-${{ github.run_attempt }}
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 14
|
||||||
|
- run: bash ./__tests__/smoke-plugins/run-smoke.sh
|
||||||
52
.github/workflows/smoke.yaml
vendored
52
.github/workflows/smoke.yaml
vendored
@@ -26,6 +26,32 @@ jobs:
|
|||||||
path: __tests__/smoke/
|
path: __tests__/smoke/
|
||||||
key: cache-${{ github.run_id }}-${{ github.run_attempt }}
|
key: cache-${{ github.run_id }}-${{ github.run_attempt }}
|
||||||
|
|
||||||
|
run-smoke--npm--node-22:
|
||||||
|
needs: prepare-smoke
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: __tests__/smoke/
|
||||||
|
key: cache-${{ github.run_id }}-${{ github.run_attempt }}
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 22
|
||||||
|
- run: bash ./__tests__/smoke/run-smoke.sh "npm i redocly-cli.tgz" "npm run"
|
||||||
|
|
||||||
|
run-smoke--npm--node-22--redoc:
|
||||||
|
needs: prepare-smoke
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: __tests__/smoke/
|
||||||
|
key: cache-${{ github.run_id }}-${{ github.run_attempt }}
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 22
|
||||||
|
- run: bash ./__tests__/smoke/run-smoke.sh "npm i redoc redocly-cli.tgz" "npm run"
|
||||||
|
|
||||||
run-smoke--npm--node-20:
|
run-smoke--npm--node-20:
|
||||||
needs: prepare-smoke
|
needs: prepare-smoke
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -130,6 +156,32 @@ jobs:
|
|||||||
node-version: 14
|
node-version: 14
|
||||||
- run: bash ./__tests__/smoke/run-smoke.sh "npm i redoc redocly-cli.tgz" "npm run"
|
- run: bash ./__tests__/smoke/run-smoke.sh "npm i redoc redocly-cli.tgz" "npm run"
|
||||||
|
|
||||||
|
run-smoke--yarn--node-22:
|
||||||
|
needs: prepare-smoke
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: __tests__/smoke/
|
||||||
|
key: cache-${{ github.run_id }}-${{ github.run_attempt }}
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 22
|
||||||
|
- run: bash ./__tests__/smoke/run-smoke.sh "yarn add ./redocly-cli.tgz" "yarn"
|
||||||
|
|
||||||
|
run-smoke--yarn--node-22--redoc:
|
||||||
|
needs: prepare-smoke
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: __tests__/smoke/
|
||||||
|
key: cache-${{ github.run_id }}-${{ github.run_attempt }}
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 22
|
||||||
|
- run: bash ./__tests__/smoke/run-smoke.sh "yarn add redoc ./redocly-cli.tgz" "yarn"
|
||||||
|
|
||||||
run-smoke--yarn--node-20:
|
run-smoke--yarn--node-20:
|
||||||
needs: prepare-smoke
|
needs: prepare-smoke
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|||||||
3
__tests__/smoke-plugins/local-plugin.js
Normal file
3
__tests__/smoke-plugins/local-plugin.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = function localPlugin() {
|
||||||
|
return { id: 'local-plugin' };
|
||||||
|
};
|
||||||
4
__tests__/smoke-plugins/message-schema.yaml
Normal file
4
__tests__/smoke-plugins/message-schema.yaml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
19
__tests__/smoke-plugins/openapi.yaml
Normal file
19
__tests__/smoke-plugins/openapi.yaml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
openapi: 3.1.0
|
||||||
|
servers:
|
||||||
|
- url: http://redocly-example.com
|
||||||
|
info:
|
||||||
|
title: Sample API
|
||||||
|
version: 1.0.0
|
||||||
|
paths:
|
||||||
|
/hello:
|
||||||
|
get:
|
||||||
|
operationId: getMessage
|
||||||
|
security: []
|
||||||
|
summary: Get a greeting message
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: OK
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: ./message-schema.yaml
|
||||||
10
__tests__/smoke-plugins/package.json
Normal file
10
__tests__/smoke-plugins/package.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "test-project-smoke-plugins",
|
||||||
|
"scripts": {
|
||||||
|
"redocly-version": "redocly --version",
|
||||||
|
"redocly-lint": "redocly lint openapi.yaml"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@redocly/portal-plugin-async-api": "1.0.273"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
__tests__/smoke-plugins/redocly.yaml
Normal file
5
__tests__/smoke-plugins/redocly.yaml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
extends:
|
||||||
|
- recommended
|
||||||
|
plugins:
|
||||||
|
- '@redocly/portal-plugin-async-api'
|
||||||
|
- local-plugin.js
|
||||||
19
__tests__/smoke-plugins/run-smoke.sh
Normal file
19
__tests__/smoke-plugins/run-smoke.sh
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -eo pipefail # Fail on script errors
|
||||||
|
|
||||||
|
cd __tests__/smoke-plugins
|
||||||
|
echo
|
||||||
|
echo "Directory content:"
|
||||||
|
ls -a
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Install plugin package
|
||||||
|
npm i
|
||||||
|
|
||||||
|
# Install CLI globally
|
||||||
|
npm i redocly-cli.tgz -g
|
||||||
|
|
||||||
|
# Actual smoke test - executing the command provided as the second argument
|
||||||
|
npm run redocly-version
|
||||||
|
npm run redocly-lint
|
||||||
@@ -139,7 +139,7 @@ export async function resolvePlugins(
|
|||||||
const absolutePluginPath = existsSync(maybeAbsolutePluginPath)
|
const absolutePluginPath = existsSync(maybeAbsolutePluginPath)
|
||||||
? maybeAbsolutePluginPath
|
? maybeAbsolutePluginPath
|
||||||
: // For plugins imported from packages specifically
|
: // For plugins imported from packages specifically
|
||||||
require.resolve(plugin);
|
require.resolve(plugin, { paths: [configDir] });
|
||||||
|
|
||||||
if (!pluginsCache.has(absolutePluginPath)) {
|
if (!pluginsCache.has(absolutePluginPath)) {
|
||||||
let requiredPlugin: ImportedPlugin | undefined;
|
let requiredPlugin: ImportedPlugin | undefined;
|
||||||
|
|||||||
16
scripts/prepare-smoke-plugins.sh
Normal file
16
scripts/prepare-smoke-plugins.sh
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# For npm (Mutates packages/cli/package.json)
|
||||||
|
npm run pack:prepare
|
||||||
|
|
||||||
|
cp ./redocly-cli.tgz ./openapi-core.tgz ./__tests__/smoke-plugins
|
||||||
|
|
||||||
|
echo "Current directory:"
|
||||||
|
pwd
|
||||||
|
echo
|
||||||
|
echo "Current directory content:"
|
||||||
|
ls -a
|
||||||
|
echo
|
||||||
|
echo "Target directory content:"
|
||||||
|
ls -a __tests__/smoke-plugins/
|
||||||
|
echo
|
||||||
Reference in New Issue
Block a user