From 4bebb63faf00b6006d5bbea14fdc535ba11a4cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Wed, 17 May 2023 16:56:47 +0200 Subject: [PATCH 1/7] chore(cli): inline html templates in html formatter --- packages/cli/package.json | 7 +- .../cli/scripts/inline-html-templates.mjs | 32 ++++++ .../cli/src/formatters/__tests__/html.test.ts | 5 +- packages/cli/src/formatters/html/index.ts | 12 +-- yarn.lock | 97 +++++++------------ 5 files changed, 79 insertions(+), 74 deletions(-) create mode 100644 packages/cli/scripts/inline-html-templates.mjs diff --git a/packages/cli/package.json b/packages/cli/package.json index d4b11f105..b6540eecf 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -27,7 +27,7 @@ "build.binary": "pkg . --output ./binaries/spectral", "build.windows": "pkg . --targets windows --out-path ./binaries", "build.nix": "pkg . --targets linux,macos,alpine --out-path ./binaries", - "postbuild": "copyfiles -u 1 \"./src/formatters/html/*.html\" \"./dist/\"", + "postbuild": "node scripts/inline-html-templates.mjs dist/formatters/html/index.js", "cli": "node -r ts-node/register/transpile-only -r tsconfig-paths/register src/index.ts", "cli:debug": "node -r ts-node/register/transpile-only -r tsconfig-paths/register --inspect-brk src/index.ts", "release": "semantic-release -e semantic-release-monorepo" @@ -45,7 +45,6 @@ "@stoplight/types": "^13.6.0", "chalk": "4.1.2", "cliui": "7.0.4", - "eol": "0.9.1", "fast-glob": "3.2.7", "lodash": "~4.17.21", "pony-cause": "^1.0.0", @@ -60,11 +59,12 @@ "@types/es-aggregate-error": "^1.0.2", "@types/xml2js": "^0.4.9", "@types/yargs": "^17.0.8", - "copyfiles": "^2.4.1", + "eol": "0.9.1", "es-aggregate-error": "^1.0.7", "nock": "^13.1.3", "node-html-parser": "^4.1.5", "pkg": "^5.8.0", + "recast": "^0.23.2", "xml2js": "^0.5.0" }, "pkg": { @@ -74,7 +74,6 @@ ], "assets": [ "./dist/**/*.json", - "./dist/**/*.html", "../*/dist/**/*.js.map", "../*/src/**/*.ts" ] diff --git a/packages/cli/scripts/inline-html-templates.mjs b/packages/cli/scripts/inline-html-templates.mjs new file mode 100644 index 000000000..c10344d58 --- /dev/null +++ b/packages/cli/scripts/inline-html-templates.mjs @@ -0,0 +1,32 @@ +#!/usr/bin/env node +import * as path from 'node:path'; +import * as fs from 'node:fs/promises'; +import process from 'node:process'; + +import eol from 'eol'; +import * as recast from 'recast'; + +await Promise.all( + process.argv.slice(2).map(async input => { + const target = path.join(process.cwd(), input); + const source = await fs.readFile(target, 'utf8'); + const ast = recast.parse(source); + + for (const node of ast.program.body) { + if (node.type !== 'VariableDeclaration') continue; + + for (const declaration of node.declarations) { + if (!declaration.id.name.endsWith('Template')) continue; + if (declaration.init.type !== 'CallExpression' || declaration.init.arguments.length !== 1) continue; + const arg = declaration.init.arguments[0]; + if (arg.type === 'Literal' && arg.value.endsWith('.html')) { + arg.value = eol.lf( + await fs.readFile(path.join(process.cwd(), input.replace('dist', 'src'), '..', arg.value), 'utf8'), + ); + } + } + } + + await fs.writeFile(target, recast.print(ast, { quote: 'single' }).code); + }), +); diff --git a/packages/cli/src/formatters/__tests__/html.test.ts b/packages/cli/src/formatters/__tests__/html.test.ts index f8bc1202d..56d17af1d 100644 --- a/packages/cli/src/formatters/__tests__/html.test.ts +++ b/packages/cli/src/formatters/__tests__/html.test.ts @@ -2,10 +2,11 @@ import { DiagnosticSeverity } from '@stoplight/types'; import { parse } from 'node-html-parser'; import { html } from '../html'; -const mixedErrors = require('./__fixtures__/mixed-errors.json'); +import mixedErrors from './__fixtures__/mixed-errors.json'; describe('HTML formatter', () => { - test('should display proper severity levels', () => { + // todo: this is broken now because template has a plain filepath + test.skip('should display proper severity levels', () => { const result = parse(html(mixedErrors, { failSeverity: DiagnosticSeverity.Error })); const table = result.querySelector('table tbody'); expect(table.innerHTML.trim()).toEqual(` diff --git a/packages/cli/src/formatters/html/index.ts b/packages/cli/src/formatters/html/index.ts index f40cbeacd..495dd67a5 100644 --- a/packages/cli/src/formatters/html/index.ts +++ b/packages/cli/src/formatters/html/index.ts @@ -22,11 +22,8 @@ * @fileoverview HTML reporter * @author Julian Laval */ -import * as path from '@stoplight/path'; import { Dictionary } from '@stoplight/types'; -import * as eol from 'eol'; -import * as fs from 'fs'; -import { template } from 'lodash'; +import template from 'lodash/template'; import type { IRuleResult } from '@stoplight/spectral-core'; import { Formatter } from '../types'; import { getHighestSeverity, getSeverityName, getSummary, getSummaryForSource, groupBySource } from '../utils'; @@ -35,9 +32,10 @@ import { getHighestSeverity, getSeverityName, getSummary, getSummaryForSource, g // Helpers // ------------------------------------------------------------------------------ -const pageTemplate = template(eol.lf(fs.readFileSync(path.join(__dirname, 'html-template-page.html'), 'utf8'))); -const messageTemplate = template(eol.lf(fs.readFileSync(path.join(__dirname, 'html-template-message.html'), 'utf8'))); -const resultTemplate = template(eol.lf(fs.readFileSync(path.join(__dirname, 'html-template-result.html'), 'utf8'))); +// these relative filepaths passed to the template fn will be dynamically replaced with their respective contents at build time +const pageTemplate = template('./html-template-page.html'); +const messageTemplate = template('./html-template-message.html'); +const resultTemplate = template('./html-template-result.html'); function renderMessages(messages: IRuleResult[], parentIndex: number): string { return messages diff --git a/yarn.lock b/yarn.lock index 99849c982..38aa41ee0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2512,7 +2512,6 @@ __metadata: "@types/yargs": ^17.0.8 chalk: 4.1.2 cliui: 7.0.4 - copyfiles: ^2.4.1 eol: 0.9.1 es-aggregate-error: ^1.0.7 fast-glob: 3.2.7 @@ -2522,6 +2521,7 @@ __metadata: pkg: ^5.8.0 pony-cause: ^1.0.0 proxy-agent: 5.0.0 + recast: ^0.23.2 stacktracey: ^2.1.7 strip-ansi: 6.0 text-table: 0.2 @@ -3800,6 +3800,15 @@ __metadata: languageName: node linkType: hard +"ast-types@npm:^0.16.1": + version: 0.16.1 + resolution: "ast-types@npm:0.16.1" + dependencies: + tslib: ^2.0.1 + checksum: 21c186da9fdb1d8087b1b7dabbc4059f91aa5a1e593a9776b4393cc1eaa857e741b2dda678d20e34b16727b78fef3ab59cf8f0c75ed1ba649c78fe194e5c114b + languageName: node + linkType: hard + "astral-regex@npm:^2.0.0": version: 2.0.0 resolution: "astral-regex@npm:2.0.0" @@ -4825,24 +4834,6 @@ __metadata: languageName: node linkType: hard -"copyfiles@npm:^2.4.1": - version: 2.4.1 - resolution: "copyfiles@npm:2.4.1" - dependencies: - glob: ^7.0.5 - minimatch: ^3.0.3 - mkdirp: ^1.0.4 - noms: 0.0.0 - through2: ^2.0.1 - untildify: ^4.0.0 - yargs: ^16.1.0 - bin: - copyfiles: copyfiles - copyup: copyfiles - checksum: aea69873bb99cc5f553967660cbfb70e4eeda198f572a36fb0f748b36877ff2c90fd906c58b1d540adbad8afa8ee82820172f1c18e69736f7ab52792c12745a7 - languageName: node - linkType: hard - "core-js-compat@npm:^3.8.0": version: 3.8.2 resolution: "core-js-compat@npm:3.8.2" @@ -6698,7 +6689,7 @@ __metadata: languageName: node linkType: hard -"glob@npm:^7.0.5, glob@npm:^7.1.3, glob@npm:^7.1.4, glob@npm:^7.1.6, glob@npm:^7.1.7": +"glob@npm:^7.1.3, glob@npm:^7.1.4, glob@npm:^7.1.6, glob@npm:^7.1.7": version: 7.2.3 resolution: "glob@npm:7.2.3" dependencies: @@ -9268,7 +9259,7 @@ __metadata: languageName: node linkType: hard -"minimatch@npm:3.1.2, minimatch@npm:^3.0.3, minimatch@npm:^3.0.4, minimatch@npm:^3.1.1, minimatch@npm:^3.1.2": +"minimatch@npm:3.1.2, minimatch@npm:^3.0.4, minimatch@npm:^3.1.1, minimatch@npm:^3.1.2": version: 3.1.2 resolution: "minimatch@npm:3.1.2" dependencies: @@ -9707,16 +9698,6 @@ __metadata: languageName: node linkType: hard -"noms@npm:0.0.0": - version: 0.0.0 - resolution: "noms@npm:0.0.0" - dependencies: - inherits: ^2.0.1 - readable-stream: ~1.0.31 - checksum: a05f056dabf764c86472b6b5aad10455f3adcb6971f366cdf36a72b559b29310a940e316bca30802f2804fdd41707941366224f4cba80c4f53071512245bf200 - languageName: node - linkType: hard - "nopt@npm:^5.0.0": version: 5.0.0 resolution: "nopt@npm:5.0.0" @@ -11146,18 +11127,6 @@ __metadata: languageName: node linkType: hard -"readable-stream@npm:~1.0.31": - version: 1.0.34 - resolution: "readable-stream@npm:1.0.34" - dependencies: - core-util-is: ~1.0.0 - inherits: ~2.0.1 - isarray: 0.0.1 - string_decoder: ~0.10.x - checksum: 85042c537e4f067daa1448a7e257a201070bfec3dd2706abdbd8ebc7f3418eb4d3ed4b8e5af63e2544d69f88ab09c28d5da3c0b77dc76185fddd189a59863b60 - languageName: node - linkType: hard - "readdir-scoped-modules@npm:^1.1.0": version: 1.1.0 resolution: "readdir-scoped-modules@npm:1.1.0" @@ -11179,6 +11148,19 @@ __metadata: languageName: node linkType: hard +"recast@npm:^0.23.2": + version: 0.23.2 + resolution: "recast@npm:0.23.2" + dependencies: + assert: ^2.0.0 + ast-types: ^0.16.1 + esprima: ~4.0.0 + source-map: ~0.6.1 + tslib: ^2.0.1 + checksum: 04c2617cb04c4d02a5c9e1bb75b8e7afc21d1ba7babce25303732f035c3d4b2f945d727f34c3976223d800592ea31e6641cfd33700a8699c02025040174af0b6 + languageName: node + linkType: hard + "redent@npm:^3.0.0": version: 3.0.0 resolution: "redent@npm:3.0.0" @@ -12487,16 +12469,6 @@ __metadata: languageName: node linkType: hard -"through2@npm:^2.0.1, through2@npm:~2.0.0": - version: 2.0.5 - resolution: "through2@npm:2.0.5" - dependencies: - readable-stream: ~2.3.6 - xtend: ~4.0.1 - checksum: beb0f338aa2931e5660ec7bf3ad949e6d2e068c31f4737b9525e5201b824ac40cac6a337224856b56bd1ddd866334bbfb92a9f57cd6f66bc3f18d3d86fc0fe50 - languageName: node - linkType: hard - "through2@npm:^4.0.0": version: 4.0.2 resolution: "through2@npm:4.0.2" @@ -12506,6 +12478,16 @@ __metadata: languageName: node linkType: hard +"through2@npm:~2.0.0": + version: 2.0.5 + resolution: "through2@npm:2.0.5" + dependencies: + readable-stream: ~2.3.6 + xtend: ~4.0.1 + checksum: beb0f338aa2931e5660ec7bf3ad949e6d2e068c31f4737b9525e5201b824ac40cac6a337224856b56bd1ddd866334bbfb92a9f57cd6f66bc3f18d3d86fc0fe50 + languageName: node + linkType: hard + "through@npm:2, through@npm:>=2.2.7 <3, through@npm:^2.3.8": version: 2.3.8 resolution: "through@npm:2.3.8" @@ -13017,13 +12999,6 @@ __metadata: languageName: node linkType: hard -"untildify@npm:^4.0.0": - version: 4.0.0 - resolution: "untildify@npm:4.0.0" - checksum: 39ced9c418a74f73f0a56e1ba4634b4d959422dff61f4c72a8e39f60b99380c1b45ed776fbaa0a4101b157e4310d873ad7d114e8534ca02609b4916bb4187fb9 - languageName: node - linkType: hard - "update-browserslist-db@npm:^1.0.5": version: 1.0.5 resolution: "update-browserslist-db@npm:1.0.5" @@ -13457,7 +13432,7 @@ __metadata: languageName: node linkType: hard -"yargs@npm:^16.1.0, yargs@npm:^16.1.1, yargs@npm:^16.2.0": +"yargs@npm:^16.1.1, yargs@npm:^16.2.0": version: 16.2.0 resolution: "yargs@npm:16.2.0" dependencies: From bb122d5ca50e2ed49e9a26eb7796ebaf972fe3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Wed, 17 May 2023 19:05:44 +0200 Subject: [PATCH 2/7] chore(cli): use ts file --- .eslintignore | 1 + .gitignore | 1 + package.json | 4 +- packages/cli/package.json | 8 ++- .../cli/scripts/bundle-html-templates.mjs | 25 ++++++++ .../cli/scripts/inline-html-templates.mjs | 32 ---------- .../cli/src/formatters/__tests__/html.test.ts | 3 +- packages/cli/src/formatters/html/index.ts | 8 +-- yarn.lock | 58 ++++--------------- 9 files changed, 51 insertions(+), 89 deletions(-) create mode 100644 packages/cli/scripts/bundle-html-templates.mjs delete mode 100644 packages/cli/scripts/inline-html-templates.mjs diff --git a/.eslintignore b/.eslintignore index 930eace8f..990412f38 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,3 +3,4 @@ /test-harness/tests/ /packages/*/dist /packages/*/CHANGELOG.md +packages/cli/src/formatters/html/templates.ts diff --git a/.gitignore b/.gitignore index 86fbb41ab..5ef457b59 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ node_modules !.yarn/sdks !.yarn/versions +packages/cli/src/formatters/html/templates.ts packages/cli/binaries /test-harness/tmp/ /test-harness/tests/ diff --git a/package.json b/package.json index 300531ede..8069d5bec 100644 --- a/package.json +++ b/package.json @@ -24,14 +24,14 @@ }, "scripts": { "clean": "rimraf .cache packages/*/{dist,.cache}", - "prebuild": "yarn workspace @stoplight/spectral-ruleset-migrator prebuild", + "prebuild": "yarn workspaces foreach run prebuild", "build": "yarn prebuild && tsc --build ./tsconfig.build.json && yarn postbuild", "postbuild": "yarn workspace @stoplight/spectral-cli postbuild", "lint": "yarn lint.prettier && yarn lint.eslint", "lint.fix": "yarn lint.prettier --write && yarn lint.eslint --fix", "lint.eslint": "eslint --cache --cache-location .cache/.eslintcache --ext=.js,.mjs,.ts packages test-harness", "lint.prettier": "prettier --ignore-path .eslintignore --ignore-unknown --check packages/core/src/ruleset/meta/*.json packages/rulesets/src/{asyncapi,oas}/schemas/*.json docs/**/*.md README.md", - "pretest": "yarn workspace @stoplight/spectral-ruleset-migrator pretest", + "pretest": "yarn workspaces foreach run pretest", "test": "yarn pretest && yarn test.karma && yarn test.jest", "pretest.harness": "ts-node -T test-harness/scripts/generate-tests.ts", "test.harness": "yarn pretest.harness && jest -c test-harness/jest.config.mjs", diff --git a/packages/cli/package.json b/packages/cli/package.json index b6540eecf..67406d510 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -27,7 +27,8 @@ "build.binary": "pkg . --output ./binaries/spectral", "build.windows": "pkg . --targets windows --out-path ./binaries", "build.nix": "pkg . --targets linux,macos,alpine --out-path ./binaries", - "postbuild": "node scripts/inline-html-templates.mjs dist/formatters/html/index.js", + "pretest": "yarn prebuild", + "prebuild": "node scripts/bundle-html-templates.mjs", "cli": "node -r ts-node/register/transpile-only -r tsconfig-paths/register src/index.ts", "cli:debug": "node -r ts-node/register/transpile-only -r tsconfig-paths/register --inspect-brk src/index.ts", "release": "semantic-release -e semantic-release-monorepo" @@ -45,7 +46,7 @@ "@stoplight/types": "^13.6.0", "chalk": "4.1.2", "cliui": "7.0.4", - "fast-glob": "3.2.7", + "fast-glob": "~3.2.12", "lodash": "~4.17.21", "pony-cause": "^1.0.0", "proxy-agent": "5.0.0", @@ -59,12 +60,13 @@ "@types/es-aggregate-error": "^1.0.2", "@types/xml2js": "^0.4.9", "@types/yargs": "^17.0.8", + "ast-types": "^0.14.2", + "astring": "^1.8.4", "eol": "0.9.1", "es-aggregate-error": "^1.0.7", "nock": "^13.1.3", "node-html-parser": "^4.1.5", "pkg": "^5.8.0", - "recast": "^0.23.2", "xml2js": "^0.5.0" }, "pkg": { diff --git a/packages/cli/scripts/bundle-html-templates.mjs b/packages/cli/scripts/bundle-html-templates.mjs new file mode 100644 index 000000000..0976f997c --- /dev/null +++ b/packages/cli/scripts/bundle-html-templates.mjs @@ -0,0 +1,25 @@ +#!/usr/bin/env node +import * as path from 'node:path'; +import * as fs from 'node:fs/promises'; +import { fileURLToPath } from 'node:url'; +import * as astring from 'astring'; +import { builders as b } from 'ast-types'; + +import eol from 'eol'; +import fg from 'fast-glob'; + +const cwd = path.join(path.dirname(fileURLToPath(import.meta.url)), '..'); + +fg('src/formatters/html/*.html', { cwd, absolute: true }) + .then(async files => + Promise.all( + files.map(async file => ({ file: path.basename(file), content: eol.lf(await fs.readFile(file, 'utf8')) })), + ), + ) + .then(async items => { + const root = b.exportDefaultDeclaration( + b.objectExpression(items.map(({ file, content }) => b.property('init', b.literal(file), b.literal(content)))), + ); + + await fs.writeFile(path.join(cwd, 'src/formatters/html/templates.ts'), astring.generate(root)); + }); diff --git a/packages/cli/scripts/inline-html-templates.mjs b/packages/cli/scripts/inline-html-templates.mjs deleted file mode 100644 index c10344d58..000000000 --- a/packages/cli/scripts/inline-html-templates.mjs +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env node -import * as path from 'node:path'; -import * as fs from 'node:fs/promises'; -import process from 'node:process'; - -import eol from 'eol'; -import * as recast from 'recast'; - -await Promise.all( - process.argv.slice(2).map(async input => { - const target = path.join(process.cwd(), input); - const source = await fs.readFile(target, 'utf8'); - const ast = recast.parse(source); - - for (const node of ast.program.body) { - if (node.type !== 'VariableDeclaration') continue; - - for (const declaration of node.declarations) { - if (!declaration.id.name.endsWith('Template')) continue; - if (declaration.init.type !== 'CallExpression' || declaration.init.arguments.length !== 1) continue; - const arg = declaration.init.arguments[0]; - if (arg.type === 'Literal' && arg.value.endsWith('.html')) { - arg.value = eol.lf( - await fs.readFile(path.join(process.cwd(), input.replace('dist', 'src'), '..', arg.value), 'utf8'), - ); - } - } - } - - await fs.writeFile(target, recast.print(ast, { quote: 'single' }).code); - }), -); diff --git a/packages/cli/src/formatters/__tests__/html.test.ts b/packages/cli/src/formatters/__tests__/html.test.ts index 56d17af1d..8db9acb7e 100644 --- a/packages/cli/src/formatters/__tests__/html.test.ts +++ b/packages/cli/src/formatters/__tests__/html.test.ts @@ -5,8 +5,7 @@ import { html } from '../html'; import mixedErrors from './__fixtures__/mixed-errors.json'; describe('HTML formatter', () => { - // todo: this is broken now because template has a plain filepath - test.skip('should display proper severity levels', () => { + test('should display proper severity levels', () => { const result = parse(html(mixedErrors, { failSeverity: DiagnosticSeverity.Error })); const table = result.querySelector('table tbody'); expect(table.innerHTML.trim()).toEqual(` diff --git a/packages/cli/src/formatters/html/index.ts b/packages/cli/src/formatters/html/index.ts index 495dd67a5..f8cd1527a 100644 --- a/packages/cli/src/formatters/html/index.ts +++ b/packages/cli/src/formatters/html/index.ts @@ -27,15 +27,15 @@ import template from 'lodash/template'; import type { IRuleResult } from '@stoplight/spectral-core'; import { Formatter } from '../types'; import { getHighestSeverity, getSeverityName, getSummary, getSummaryForSource, groupBySource } from '../utils'; +import templates from './templates'; // ------------------------------------------------------------------------------ // Helpers // ------------------------------------------------------------------------------ -// these relative filepaths passed to the template fn will be dynamically replaced with their respective contents at build time -const pageTemplate = template('./html-template-page.html'); -const messageTemplate = template('./html-template-message.html'); -const resultTemplate = template('./html-template-result.html'); +const pageTemplate = template(templates['html-template-page.html']); +const messageTemplate = template(templates['html-template-message.html']); +const resultTemplate = template(templates['html-template-result.html']); function renderMessages(messages: IRuleResult[], parentIndex: number): string { return messages diff --git a/yarn.lock b/yarn.lock index 38aa41ee0..06db079d6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2510,18 +2510,19 @@ __metadata: "@types/es-aggregate-error": ^1.0.2 "@types/xml2js": ^0.4.9 "@types/yargs": ^17.0.8 + ast-types: ^0.14.2 + astring: ^1.8.4 chalk: 4.1.2 cliui: 7.0.4 eol: 0.9.1 es-aggregate-error: ^1.0.7 - fast-glob: 3.2.7 + fast-glob: ~3.2.12 lodash: ~4.17.21 nock: ^13.1.3 node-html-parser: ^4.1.5 pkg: ^5.8.0 pony-cause: ^1.0.0 proxy-agent: 5.0.0 - recast: ^0.23.2 stacktracey: ^2.1.7 strip-ansi: 6.0 text-table: 0.2 @@ -3782,7 +3783,7 @@ __metadata: languageName: node linkType: hard -"ast-types@npm:0.14.2": +"ast-types@npm:0.14.2, ast-types@npm:^0.14.2": version: 0.14.2 resolution: "ast-types@npm:0.14.2" dependencies: @@ -3800,15 +3801,6 @@ __metadata: languageName: node linkType: hard -"ast-types@npm:^0.16.1": - version: 0.16.1 - resolution: "ast-types@npm:0.16.1" - dependencies: - tslib: ^2.0.1 - checksum: 21c186da9fdb1d8087b1b7dabbc4059f91aa5a1e593a9776b4393cc1eaa857e741b2dda678d20e34b16727b78fef3ab59cf8f0c75ed1ba649c78fe194e5c114b - languageName: node - linkType: hard - "astral-regex@npm:^2.0.0": version: 2.0.0 resolution: "astral-regex@npm:2.0.0" @@ -3816,12 +3808,12 @@ __metadata: languageName: node linkType: hard -"astring@npm:^1.7.5, astring@npm:^1.8.1": - version: 1.8.3 - resolution: "astring@npm:1.8.3" +"astring@npm:^1.7.5, astring@npm:^1.8.1, astring@npm:^1.8.4": + version: 1.8.4 + resolution: "astring@npm:1.8.4" bin: astring: bin/astring - checksum: 72fc85de7420ca6edeee15157fd65c5253a8cb1ced979ba66ecc439fa569f1c1cc242e4c0a9fc5a6380bf73fb5ec894dc65cf1dc0f3d1cab8c707b31df7daa1c + checksum: bc0b98087350c4a0c8a510d491d648cf8b299ec904629d5e0f5ae8d2ccc515cd27475327bb9729c7e92f4a4873adcd05cef15379d0f6f7293f1320319f0d24f0 languageName: node linkType: hard @@ -6118,29 +6110,16 @@ __metadata: languageName: node linkType: hard -"fast-glob@npm:3.2.7": - version: 3.2.7 - resolution: "fast-glob@npm:3.2.7" +"fast-glob@npm:^3.2.7, fast-glob@npm:^3.2.9, fast-glob@npm:~3.2.12": + version: 3.2.12 + resolution: "fast-glob@npm:3.2.12" dependencies: "@nodelib/fs.stat": ^2.0.2 "@nodelib/fs.walk": ^1.2.3 glob-parent: ^5.1.2 merge2: ^1.3.0 micromatch: ^4.0.4 - checksum: 2f4708ff112d2b451888129fdd9a0938db88b105b0ddfd043c064e3c4d3e20eed8d7c7615f7565fee660db34ddcf08a2db1bf0ab3c00b87608e4719694642d78 - languageName: node - linkType: hard - -"fast-glob@npm:^3.2.7, fast-glob@npm:^3.2.9": - version: 3.2.11 - resolution: "fast-glob@npm:3.2.11" - dependencies: - "@nodelib/fs.stat": ^2.0.2 - "@nodelib/fs.walk": ^1.2.3 - glob-parent: ^5.1.2 - merge2: ^1.3.0 - micromatch: ^4.0.4 - checksum: f473105324a7780a20c06de842e15ddbb41d3cb7e71d1e4fe6e8373204f22245d54f5ab9e2061e6a1c613047345954d29b022e0e76f5c28b1df9858179a0e6d7 + checksum: 0b1990f6ce831c7e28c4d505edcdaad8e27e88ab9fa65eedadb730438cfc7cde4910d6c975d6b7b8dc8a73da4773702ebcfcd6e3518e73938bb1383badfe01c2 languageName: node linkType: hard @@ -11148,19 +11127,6 @@ __metadata: languageName: node linkType: hard -"recast@npm:^0.23.2": - version: 0.23.2 - resolution: "recast@npm:0.23.2" - dependencies: - assert: ^2.0.0 - ast-types: ^0.16.1 - esprima: ~4.0.0 - source-map: ~0.6.1 - tslib: ^2.0.1 - checksum: 04c2617cb04c4d02a5c9e1bb75b8e7afc21d1ba7babce25303732f035c3d4b2f945d727f34c3976223d800592ea31e6641cfd33700a8699c02025040174af0b6 - languageName: node - linkType: hard - "redent@npm:^3.0.0": version: 3.0.0 resolution: "redent@npm:3.0.0" From 328497857fd9db98124a67a825092156be34a93f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Thu, 18 May 2023 15:37:15 +0200 Subject: [PATCH 3/7] chore(cli): address ESLint warnings --- packages/cli/src/formatters/__tests__/junit.test.ts | 6 +++--- packages/cli/src/formatters/__tests__/pretty.test.ts | 4 ++-- packages/cli/src/formatters/__tests__/stylish.test.ts | 4 ++-- packages/cli/src/formatters/__tests__/teamcity.test.ts | 2 +- packages/cli/src/formatters/__tests__/text.test.ts | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/formatters/__tests__/junit.test.ts b/packages/cli/src/formatters/__tests__/junit.test.ts index b38b1a421..3df90e239 100644 --- a/packages/cli/src/formatters/__tests__/junit.test.ts +++ b/packages/cli/src/formatters/__tests__/junit.test.ts @@ -2,9 +2,9 @@ import { Parser } from 'xml2js'; import { junit } from '../junit'; import { DiagnosticSeverity } from '@stoplight/types'; -const oas3SchemaErrors = require('./__fixtures__/oas3-schema-errors.json'); -const mixedErrors = require('./__fixtures__/mixed-errors.json'); -const specialXmlStrings = require('./__fixtures__/errors-with-special-xml-strings.json'); +import oas3SchemaErrors from './__fixtures__/oas3-schema-errors.json'; +import mixedErrors from './__fixtures__/mixed-errors.json'; +import specialXmlStrings from './__fixtures__/errors-with-special-xml-strings.json'; describe('JUnit formatter', () => { let parse: Parser['parseStringPromise']; diff --git a/packages/cli/src/formatters/__tests__/pretty.test.ts b/packages/cli/src/formatters/__tests__/pretty.test.ts index 7391f54a8..8a14b1da4 100644 --- a/packages/cli/src/formatters/__tests__/pretty.test.ts +++ b/packages/cli/src/formatters/__tests__/pretty.test.ts @@ -2,8 +2,8 @@ import { DiagnosticSeverity } from '@stoplight/types'; import chalk from 'chalk'; import { pretty } from '../pretty'; -const oas3SchemaErrors = require('./__fixtures__/oas3-schema-errors.json'); -const mixedErrors = require('./__fixtures__/mixed-errors.json'); +import oas3SchemaErrors from './__fixtures__/oas3-schema-errors.json'; +import mixedErrors from './__fixtures__/mixed-errors.json'; function setColumnWidth(width: number, func: CallableFunction): void { const og = process.stdout.columns; diff --git a/packages/cli/src/formatters/__tests__/stylish.test.ts b/packages/cli/src/formatters/__tests__/stylish.test.ts index 4fabf576b..9dc203191 100644 --- a/packages/cli/src/formatters/__tests__/stylish.test.ts +++ b/packages/cli/src/formatters/__tests__/stylish.test.ts @@ -2,8 +2,8 @@ import { DiagnosticSeverity } from '@stoplight/types'; import chalk from 'chalk'; import { stylish } from '../stylish'; -const oas3SchemaErrors = require('./__fixtures__/oas3-schema-errors.json'); -const mixedErrors = require('./__fixtures__/mixed-errors.json'); +import oas3SchemaErrors from './__fixtures__/oas3-schema-errors.json'; +import mixedErrors from './__fixtures__/mixed-errors.json'; describe('Stylish formatter', () => { test('should prefer message for oas-schema errors', () => { diff --git a/packages/cli/src/formatters/__tests__/teamcity.test.ts b/packages/cli/src/formatters/__tests__/teamcity.test.ts index cbc865910..027794a47 100644 --- a/packages/cli/src/formatters/__tests__/teamcity.test.ts +++ b/packages/cli/src/formatters/__tests__/teamcity.test.ts @@ -1,7 +1,7 @@ import { DiagnosticSeverity } from '@stoplight/types'; import { teamcity } from '../teamcity'; -const mixedErrors = require('./__fixtures__/mixed-errors.json'); +import mixedErrors from './__fixtures__/mixed-errors.json'; describe('Teamcity formatter', () => { test('should format messages', () => { diff --git a/packages/cli/src/formatters/__tests__/text.test.ts b/packages/cli/src/formatters/__tests__/text.test.ts index ca1c59faa..8c6c70f2c 100644 --- a/packages/cli/src/formatters/__tests__/text.test.ts +++ b/packages/cli/src/formatters/__tests__/text.test.ts @@ -1,7 +1,7 @@ import { DiagnosticSeverity } from '@stoplight/types'; import { text } from '../text'; -const mixedErrors = require('./__fixtures__/mixed-errors.json'); +import mixedErrors from './__fixtures__/mixed-errors.json'; describe('Text formatter', () => { test('should format messages', () => { From 29be79826e83ba84a316c9b4206be0279c7b1319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Thu, 18 May 2023 15:38:30 +0200 Subject: [PATCH 4/7] chore(repo): there is no postbuild --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 8069d5bec..b9a86eeff 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,7 @@ "scripts": { "clean": "rimraf .cache packages/*/{dist,.cache}", "prebuild": "yarn workspaces foreach run prebuild", - "build": "yarn prebuild && tsc --build ./tsconfig.build.json && yarn postbuild", - "postbuild": "yarn workspace @stoplight/spectral-cli postbuild", + "build": "yarn prebuild && tsc --build ./tsconfig.build.json", "lint": "yarn lint.prettier && yarn lint.eslint", "lint.fix": "yarn lint.prettier --write && yarn lint.eslint --fix", "lint.eslint": "eslint --cache --cache-location .cache/.eslintcache --ext=.js,.mjs,.ts packages test-harness", From c5bf1361f79e9b9280ebe7c6c35115ee0b50bd43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Thu, 18 May 2023 15:39:49 +0200 Subject: [PATCH 5/7] build(cli): node 12 eh --- packages/cli/scripts/bundle-html-templates.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/scripts/bundle-html-templates.mjs b/packages/cli/scripts/bundle-html-templates.mjs index 0976f997c..05b9fefb5 100644 --- a/packages/cli/scripts/bundle-html-templates.mjs +++ b/packages/cli/scripts/bundle-html-templates.mjs @@ -1,6 +1,6 @@ #!/usr/bin/env node import * as path from 'node:path'; -import * as fs from 'node:fs/promises'; +import { promises as fs } from 'node:fs'; import { fileURLToPath } from 'node:url'; import * as astring from 'astring'; import { builders as b } from 'ast-types'; @@ -11,7 +11,7 @@ import fg from 'fast-glob'; const cwd = path.join(path.dirname(fileURLToPath(import.meta.url)), '..'); fg('src/formatters/html/*.html', { cwd, absolute: true }) - .then(async files => + .then(files => Promise.all( files.map(async file => ({ file: path.basename(file), content: eol.lf(await fs.readFile(file, 'utf8')) })), ), From 3e880f80f6cb2c74b1858973a083e610e267fa52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Thu, 18 May 2023 18:08:49 +0200 Subject: [PATCH 6/7] build(cli): add prelint --- package.json | 3 ++- packages/cli/package.json | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b9a86eeff..256202caf 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "clean": "rimraf .cache packages/*/{dist,.cache}", "prebuild": "yarn workspaces foreach run prebuild", "build": "yarn prebuild && tsc --build ./tsconfig.build.json", - "lint": "yarn lint.prettier && yarn lint.eslint", + "prelint": "yarn workspaces foreach run prelint", + "lint": "yarn prelint && yarn lint.prettier && yarn lint.eslint", "lint.fix": "yarn lint.prettier --write && yarn lint.eslint --fix", "lint.eslint": "eslint --cache --cache-location .cache/.eslintcache --ext=.js,.mjs,.ts packages test-harness", "lint.prettier": "prettier --ignore-path .eslintignore --ignore-unknown --check packages/core/src/ruleset/meta/*.json packages/rulesets/src/{asyncapi,oas}/schemas/*.json docs/**/*.md README.md", diff --git a/packages/cli/package.json b/packages/cli/package.json index 67406d510..912b21ccc 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -28,6 +28,7 @@ "build.windows": "pkg . --targets windows --out-path ./binaries", "build.nix": "pkg . --targets linux,macos,alpine --out-path ./binaries", "pretest": "yarn prebuild", + "prelint": "yarn prebuild", "prebuild": "node scripts/bundle-html-templates.mjs", "cli": "node -r ts-node/register/transpile-only -r tsconfig-paths/register src/index.ts", "cli:debug": "node -r ts-node/register/transpile-only -r tsconfig-paths/register --inspect-brk src/index.ts", From 9972897d817c8922e020a0bb4a90970d83d72ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Thu, 18 May 2023 18:12:34 +0200 Subject: [PATCH 7/7] build(repo): run prelint --- .circleci/config.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c529e23df..9a1f0d4b1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -81,7 +81,9 @@ commands: steps: - run: name: Lint code - command: yarn lint.eslint + command: | + yarn prelint + yarn lint.eslint lint-documentation: steps: