Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/smoke-plugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
with:
node-version: 20
- run: bash ./__tests__/smoke-plugins/run-smoke.sh

run-smoke-plugins--npm--node-20--windows:
needs: prepare-smoke-plugins
runs-on: windows-latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/smoke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ jobs:

# Check for broken styles when building docs (related issue: https://github.com/Redocly/redocly-cli/issues/1073)
echo "Checking docs for issues..."
diff pre-built/redoc.html redoc-static.html
diff pre-built/redoc.html redoc-static.html -u
echo "✅ Docs built correctly."

# Check for broken $refs (or other issues) in the split files, especially on Windows (it will fail on a difference)
echo "Checking split files for issues..."
diff -r pre-split output/split
diff -r pre-split output/split -u
echo "✅ Files split correctly."
2 changes: 1 addition & 1 deletion __tests__/smoke/pre-built/redoc.html
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
" class="sc-dZnbom sc-eStNqG sc-ecLbSZ ewwVxe jZPdSZ dcgeal"><p>OK</p>
</div></button></div><div><button class="sc-jZkJda iesDBN"><svg class="sc-cXrvCr cPuBeZ" version="1.1" viewBox="0 0 24 24" x="0" xmlns="http://www.w3.org/2000/svg" y="0" aria-hidden="true"><polygon points="17.3 8.3 12 13.6 6.7 8.3 5.3 9.7 12 16.4 18.7 9.7 "></polygon></svg><strong class="sc-dNrSaK eSFldv">400<!-- --> </strong><div html="&lt;p&gt;Bad request.&lt;/p&gt;
" class="sc-dZnbom sc-eStNqG sc-ecLbSZ ewwVxe jZPdSZ dcgeal"><p>Bad request.</p>
</div></button></div></div></div><div class="sc-jgmqJh sc-gIIpAQ egscYh brdjDi"><div class="sc-dTdpwD ePBxvF"><button class="sc-ligLZB bgPLGr"><span type="get" class="sc-eeA-dwE hMeoaw http-verb get">get</span><span class="sc-ieSqsC ioopTP">/hello</span><svg class="sc-cXrvCr dOdtJx" style="margin-right:-25px" version="1.1" viewBox="0 0 24 24" x="0" xmlns="http://www.w3.org/2000/svg" y="0" aria-hidden="true"><polygon points="17.3 8.3 12 13.6 6.7 8.3 5.3 9.7 12 16.4 18.7 9.7 "></polygon></svg></button><div aria-hidden="true" class="sc-dMGIQz kCxvuD"><div class="sc-hYvJMy sxQGy"><div html="" class="sc-dZnbom sc-eStNqG ewwVxe gxENBN"></div><div tabindex="0" role="button"><div class="sc-lbKftx iPVodL"><span>http://redocly-example.com</span>/hello</div></div></div></div></div><div><h3 class="sc-jOTjWM dhJZBt"> <!-- -->Response samples<!-- --> </h3><div class="sc-bwSFLc gTnidh" data-rttabs="true"><ul class="react-tabs__tab-list" role="tablist"><li class="tab-success react-tabs__tab--selected" role="tab" id="tab:R9pq:0" aria-selected="true" aria-disabled="false" aria-controls="panel:R9pq:0" tabindex="0" data-rttab="true">200</li><li class="tab-error" role="tab" id="tab:R9pq:1" aria-selected="false" aria-disabled="false" aria-controls="panel:R9pq:1" data-rttab="true">400</li></ul><div class="react-tabs__tab-panel react-tabs__tab-panel--selected" role="tabpanel" id="panel:R9pq:0" aria-labelledby="tab:R9pq:0"><div><div class="sc-brVvGI bVwklo"><span class="sc-fKfBHT gEDIwZ">Content type</span><div class="sc-buNqiq cnTPdi">application/json</div></div><div class="sc-eTAtz eQHTDF"><div class="sc-fowSIr gzsuAn"><div class="sc-ljIkKL jwxgAi"><button><div class="sc-fcNxSY kochun">Copy</div></button></div><div class="sc-dZnbom ewwVxe sc-gozoIq hnBcqa"><div class="redoc-json"><code><button class="collapser" aria-label="collapse"></button><span class="token punctuation">{</span><span class="ellipsis"></span><ul class="obj collapsible"><li><div class="hoverable "><span class="property token string">"message"</span>: <span class="token string">&quot;string&quot;</span></div></li></ul><span class="token punctuation">}</span></code></div></div></div></div></div></div><div class="react-tabs__tab-panel" role="tabpanel" id="panel:R9pq:1" aria-labelledby="tab:R9pq:1"></div></div></div></div></div></div></div><div class="sc-dJOOoR dKumiZ"></div></div></div>
</div></button></div></div></div><div class="sc-jgmqJh sc-gIIpAQ egscYh brdjDi"><div class="sc-dTdpwD ePBxvF"><button class="sc-ligLZB bgPLGr"><span type="get" class="sc-eeA-dwE hMeoaw http-verb get">get</span><span class="sc-ieSqsC ioopTP">/hello</span><svg class="sc-cXrvCr dOdtJx" style="margin-right:-25px" version="1.1" viewBox="0 0 24 24" x="0" xmlns="http://www.w3.org/2000/svg" y="0" aria-hidden="true"><polygon points="17.3 8.3 12 13.6 6.7 8.3 5.3 9.7 12 16.4 18.7 9.7 "></polygon></svg></button><div aria-hidden="true" class="sc-dMGIQz kCxvuD"><div class="sc-hYvJMy sxQGy"><div html="" class="sc-dZnbom sc-eStNqG ewwVxe gxENBN"></div><div tabindex="0" role="button"><div class="sc-lbKftx iPVodL"><span>http://redocly-example.com</span>/hello</div></div></div></div></div><div><h3 class="sc-jOTjWM dhJZBt"> <!-- -->Response samples<!-- --> </h3><div class="sc-bwSFLc gTnidh" data-rttabs="true"><ul class="react-tabs__tab-list" role="tablist"><li class="tab-success react-tabs__tab--selected" role="tab" id="tab«R9pq»0" aria-selected="true" aria-disabled="false" aria-controls="panel«R9pq»0" tabindex="0" data-rttab="true">200</li><li class="tab-error" role="tab" id="tab«R9pq»1" aria-selected="false" aria-disabled="false" aria-controls="panel«R9pq»1" data-rttab="true">400</li></ul><div class="react-tabs__tab-panel react-tabs__tab-panel--selected" role="tabpanel" id="panel«R9pq»0" aria-labelledby="tab«R9pq»0"><div><div class="sc-brVvGI bVwklo"><span class="sc-fKfBHT gEDIwZ">Content type</span><div class="sc-buNqiq cnTPdi">application/json</div></div><div class="sc-eTAtz eQHTDF"><div class="sc-fowSIr gzsuAn"><div class="sc-ljIkKL jwxgAi"><button><div class="sc-fcNxSY kochun">Copy</div></button></div><div class="sc-dZnbom ewwVxe sc-gozoIq hnBcqa"><div class="redoc-json"><code><button class="collapser" aria-label="collapse"></button><span class="token punctuation">{</span><span class="ellipsis"></span><ul class="obj collapsible"><li><div class="hoverable "><span class="property token string">"message"</span>: <span class="token string">&quot;string&quot;</span></div></li></ul><span class="token punctuation">}</span></code></div></div></div></div></div></div><div class="react-tabs__tab-panel" role="tabpanel" id="panel«R9pq»1" aria-labelledby="tab«R9pq»1"></div></div></div></div></div></div></div><div class="sc-dJOOoR dKumiZ"></div></div></div>
<script>
const __redoc_state = {"menu":{"activeItemIdx":-1},"spec":{"data":{"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":"#/components/schemas/message-schema"}}}},"400":{"$ref":"#/components/responses/BadRequest"}}}}},"components":{"schemas":{"message-schema":{"type":"object","properties":{"message":{"type":"string"}}},"Error":{"type":"object","properties":{"type":{"type":"string","example":"object"},"title":{"type":"string","example":"Validation failed"}}}},"responses":{"BadRequest":{"description":"Bad request.","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}},"searchIndex":{"store":["operation/getMessage"],"index":{"version":"2.3.9","fields":["title","description"],"fieldVectors":[["title/0",[0,0.288,1,0.288]],["description/0",[2,0.288]]],"invertedIndex":[["greet",{"_index":0,"title":{"0":{}},"description":{}}],["hello",{"_index":2,"title":{},"description":{"0":{}}}],["messag",{"_index":1,"title":{"0":{}},"description":{}}]],"pipeline":[]}},"options":{}};

Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/__tests__/commands/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ describe('handleLint', () => {
async (entrypoints) => entrypoints?.map((path: string) => ({ path })) ?? []
);

vi.mock('../../utils/update-version-notifier.js', () => ({
version: '1.0.0',
vi.mock('../../utils/package.js', () => ({
version: '2.0.0',
}));
});

Expand Down Expand Up @@ -137,7 +137,7 @@ describe('handleLint', () => {
format: 'stylish',
maxProblems: 2,
totals: { errors: 0 },
version: '1.0.0',
version: '2.0.0',
});
expect(getExecutionTime).toHaveBeenCalledWith(42);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/build-docs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import type { BuildDocsArgv } from './types.js';
import type { CommandArgs } from '../../wrapper.js';

const packageJson = createRequire(import.meta.url)('../../../package.json');
const packageJson = createRequire(import.meta.url ?? __dirname)('../../../package.json');

export const handlerBuildCommand = async ({
argv,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/build-docs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import type { Config } from '@redocly/openapi-core';
import type { BuildDocsOptions } from './types.js';

const __dirname = dirname(fileURLToPath(import.meta.url));
const __internalDirname = dirname(fileURLToPath(import.meta.url ?? __dirname));

export function getObjectOrJSON(
openapiOptions: string | Record<string, unknown>,
Expand Down Expand Up @@ -51,7 +51,7 @@
}

export async function getPageHTML(
api: any,

Check warning on line 54 in packages/cli/src/commands/build-docs/utils.ts

View workflow job for this annotation

GitHub Actions / code-style-check

Unexpected any. Specify a different type
pathToApi: string,
{
title,
Expand All @@ -77,7 +77,7 @@
? templateFileName
: redocOptions?.htmlTemplate
? resolve(configPath ? dirname(configPath) : '', redocOptions.htmlTemplate)
: join(__dirname, './template.hbs');
: join(__internalDirname, './template.hbs');
const template = handlebars.compile(readFileSync(templateFileName).toString());
return template({
redocHTML: `
Expand Down
7 changes: 2 additions & 5 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ import { handleLint } from './commands/lint.js';
import { handleBundle } from './commands/bundle.js';
import { handleLogin, handleLogout } from './commands/auth.js';
import { handlerBuildCommand } from './commands/build-docs/index.js';
import {
cacheLatestVersion,
notifyUpdateCliVersion,
version,
} from './utils/update-version-notifier.js';
import { cacheLatestVersion, notifyUpdateCliVersion } from './utils/update-version-notifier.js';
import { commandWrapper } from './wrapper.js';
import { previewProject } from './commands/preview-project/index.js';
import { handleTranslations } from './commands/translations.js';
import { handleEject } from './commands/eject.js';
import { PRODUCT_PLANS } from './commands/preview-project/constants.js';
import { version } from './utils/package.js';

import type { Arguments } from 'yargs';
import type { OutputFormat, RuleSeverity } from '@redocly/openapi-core';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/otel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Resource as OtelResource } from '@opentelemetry/resources';
import { NodeTracerProvider, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
import { version } from './utils/update-version-notifier.js';
import { version } from './utils/package.js';
import { DEFAULT_FETCH_TIMEOUT } from './utils/fetch-with-timeout.js';

import type { Analytics } from './utils/miscellaneous.js';
Expand Down
10 changes: 4 additions & 6 deletions packages/cli/src/utils/assert-node-version.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { createRequire } from 'node:module';
import * as process from 'node:process';
import * as semver from 'semver';
import { yellow } from 'colorette';
import { engines } from './package.js';

try {
const packageJson = createRequire(import.meta.url)('../../package.json');
const { engines } = packageJson;
const version = engines.node;
const range = engines?.node;

if (!semver.satisfies(process.version, version)) {
if (typeof range === 'string' && !semver.satisfies(process.version, range)) {
process.stderr.write(
yellow(
`\n⚠️ Warning: failed to satisfy expected node version. Expected: "${version}", Current "${process.version}"\n\n`
`\n⚠️ Warning: failed to satisfy expected node version. Expected: "${range}", Current "${process.version}"\n\n`
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '@redocly/openapi-core';
import { deprecatedRefDocsSchema } from '@redocly/config/lib/reference-docs-config-schema.js';
import { outputExtensions } from '../types.js';
import { version } from './update-version-notifier.js';
import { version } from './package.js';
import { getReuniteUrl } from '../reunite/api/index.js';

import type { Arguments } from 'yargs';
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/utils/package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createRequire } from 'node:module';

const packageJson = createRequire(import.meta.url ?? __dirname)('../../package.json');

export const { version, name, engines } = packageJson;
6 changes: 1 addition & 5 deletions packages/cli/src/utils/update-version-notifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { createRequire } from 'node:module';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import * as process from 'node:process';
Expand All @@ -7,10 +6,7 @@ import { compare } from 'semver';
import fetch, { DEFAULT_FETCH_TIMEOUT } from './fetch-with-timeout.js';
import { cyan, green, yellow } from 'colorette';
import { cleanColors } from './miscellaneous.js';

const packageJson = createRequire(import.meta.url)('../../package.json');

export const { version, name } = packageJson;
import { version, name } from './package.js';

const VERSION_CACHE_FILE = 'redocly-cli-version';
const SPACE_TO_BORDER = 4;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { detectSpec, doesYamlFileExist, isPlainObject } from '@redocly/openapi-core';
import { version } from './utils/update-version-notifier.js';
import { version } from './utils/package.js';
import { exitWithError, loadConfigAndHandleErrors, sendTelemetry } from './utils/miscellaneous.js';
import { lintConfigCallback } from './commands/lint.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { fileURLToPath } from 'node:url';

import type { StyleguideConfig } from '../../config/index.js';

const __dirname = dirname(fileURLToPath(import.meta.url));
const __internalDirname = dirname(fileURLToPath(import.meta.url ?? __dirname));

export const name = 'Validate with 50 top-level rules';
export const count = 10;
const rebillyDefinitionRef = pathResolve(pathJoin(__dirname, 'rebilly.yaml'));
const rebillyDefinitionRef = pathResolve(pathJoin(__internalDirname, 'rebilly.yaml'));
const rebillyDocument = parseYamlToDocument(
readFileSync(rebillyDefinitionRef, 'utf-8'),
rebillyDefinitionRef
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/config/config-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ export async function resolvePlugins(
const absolutePluginPath = existsSync(maybeAbsolutePluginPath)
? maybeAbsolutePluginPath
: // For plugins imported from packages specifically
createRequire(import.meta.url).resolve(plugin, {
createRequire(import.meta.url ?? __dirname).resolve(plugin, {
paths: [
// Plugins imported from the node_modules in the project directory
configDir,
// Plugins imported from the node_modules in the package install directory (for example, npx cache directory)
path.dirname(fileURLToPath(import.meta.url)),
path.dirname(fileURLToPath(import.meta.url ?? __dirname)),
],
});

Expand Down
7 changes: 1 addition & 6 deletions packages/core/src/format/format.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { createRequire } from 'node:module';
import * as path from 'node:path';
import { colorOptions, colorize, logger } from '../logger.js';
import { output } from '../output.js';
import { getCodeframe, getLineColLocation } from './codeframes.js';
import { env, isBrowser } from '../env.js';
import { isAbsoluteUrl } from '../ref-utils.js';

const packageJson = createRequire(import.meta.url)('../../package.json');

import type {
NormalizedProblem,
ProblemSeverity,
LineColLocationObject,
LocationObject,
} from '../walk.js';

const coreVersion = packageJson.version;

export type Totals = {
errors: number;
warnings: number;
Expand Down Expand Up @@ -101,7 +96,7 @@ export function formatProblems(
format = 'codeframe',
color = colorOptions.enabled,
totals = getTotals(problems),
version = coreVersion,
version = '2.0',
} = opts;

colorOptions.enabled = color; // force colors if specified
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ export {
bundleFromString,
} from './bundle.js';

export { type Assertions } from './rules/common/assertions/index.js';
export { type Assertions, type Assertion } from './rules/common/assertions/index.js';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import FormData from 'form-data';
import { type TestContext, type RequestBody } from '../../types.js';
import { fileURLToPath } from 'node:url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const __internalDirname = path.dirname(fileURLToPath(import.meta.url ?? __dirname));

const KNOWN_BINARY_CONTENT_TYPES_REGEX =
/^image\/(png|jpeg|gif|bmp|webp|svg\+xml)|application\/pdf$/;
Expand Down Expand Up @@ -79,7 +79,7 @@ const getRequestBodyMultipartFormData = async (

const getRequestBodyOctetStream = async (payload: RequestBody['payload']) => {
if (typeof payload === 'string' && payload.startsWith('$file(') && payload.endsWith(')')) {
const filePath = path.resolve(__dirname, '../', stripFileDecorator(payload));
const filePath = path.resolve(__internalDirname, '../', stripFileDecorator(payload));

await new Promise((resolve, reject) => {
access(filePath, constants.F_OK | constants.R_OK, (err) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { createRequire } from 'node:module';
import { bold, red } from 'colorette';
import { getTotals, formatProblems, lint, bundle, createConfig } from '@redocly/openapi-core';
import { type CollectFn } from '@redocly/openapi-core';
import * as path from 'node:path';
import { existsSync } from 'node:fs';
import { type TestDescription } from '../../types.js';
import { printConfigLintTotals } from '../../utils/cli-outputs.js';
import { isTestFile } from '../../utils/file.js';
import { readYaml } from '../../utils/yaml.js';

const packageJson = createRequire(import.meta.url)('../../../package.json');
const version = packageJson.version;
import { version } from '../../utils/package.js';

export async function bundleArazzo(filePath: string, collectSpecData?: CollectFn) {
const fileName = path.basename(filePath);
Expand Down Expand Up @@ -71,5 +67,5 @@ export async function bundleArazzo(filePath: string, collectSpecData?: CollectFn
throw new Error(`${red('Found errors in Arazzo description')} ${bold(fileName)}`);
}

return (bundledDocument.bundle.parsed || {}) as TestDescription;
return bundledDocument.bundle.parsed || {};
}
6 changes: 1 addition & 5 deletions packages/respect-core/src/utils/har-logs/create-har-log.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { createRequire } from 'node:module';

const packageJson = createRequire(import.meta.url)('../../../package.json');

const { name: packageName, version: packageVersion } = packageJson;
import { name as packageName, version as packageVersion } from '../package.js';

export function createHarLog(entries: any[] = [], pageInfo: any = {}): any {
return {
Expand Down
5 changes: 5 additions & 0 deletions packages/respect-core/src/utils/package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createRequire } from 'node:module';

const packageJson = createRequire(import.meta.url ?? __dirname)('../../package.json');

export const { version, name } = packageJson;
Loading