diff --git a/README.md b/README.md index e0581dc7bd..d7744111ce 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ You can install ApiDOM packages using [npm CLI](https://docs.npmjs.com/cli): ```sh $ npm install @swagger-api/apidom-ast + $ npm install @swagger-api/apidom-converter $ npm install @swagger-api/apidom-core $ npm install @swagger-api/apidom-error $ npm install @swagger-api/apidom-json-path diff --git a/package-lock.json b/package-lock.json index ecef0feaa5..f29e66d454 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8429,6 +8429,10 @@ "resolved": "packages/apidom-ast", "link": true }, + "node_modules/@swagger-api/apidom-converter": { + "resolved": "packages/apidom-converter", + "link": true + }, "node_modules/@swagger-api/apidom-core": { "resolved": "packages/apidom-core", "link": true @@ -37999,6 +38003,13 @@ "unraw": "^3.0.0" } }, + "packages/apidom-converter": { + "version": "0.92.0", + "license": "Apache-2.0", + "dependencies": { + "@babel/runtime-corejs3": "^7.20.7" + } + }, "packages/apidom-core": { "name": "@swagger-api/apidom-core", "version": "0.92.0", diff --git a/package.json b/package.json index 55e3c8d199..55f50e5c99 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "clean": "lerna run clean", "test": "lerna run test", "link": "npm link --workspaces", - "unlink": "npm unlink --global @swagger-api/apidom-ast @swagger-api/apidom-core @swagger-api/apidom-error @swagger-api/apidom-json-path @swagger-api/apidom-json-pointer @swagger-api/apidom-json-pointer-relative @swagger-api/apidom-parser-adapter-json @swagger-api/apidom-ns-api-design-systems @swagger-api/apidom-ns-asyncapi-2 @swagger-api/apidom-ns-json-schema-draft-4 @swagger-api/apidom-ns-json-schema-draft-6 @swagger-api/apidom-ns-json-schema-draft-7 @swagger-api/apidom-ns-openapi-2 @swagger-api/apidom-ns-openapi-3-0 @swagger-api/apidom-ns-openapi-3-1 @swagger-api/apidom-parser-adapter-yaml-1-2 @swagger-api/apidom-parser-adapter-asyncapi-yaml-2 @swagger-api/apidom-parser-adapter-openapi-yaml-2 @swagger-api/apidom-parser-adapter-openapi-yaml-3-0 @swagger-api/apidom-parser-adapter-openapi-yaml-3-1 @swagger-api/apidom-parser @swagger-api/apidom-parser-adapter-api-design-systems-json @swagger-api/apidom-parser-adapter-api-design-systems-yaml @swagger-api/apidom-parser-adapter-asyncapi-json-2 @swagger-api/apidom-ls @swagger-api/apidom-reference @swagger-api/apidom-parser-adapter-openapi-json-2 @swagger-api/apidom-parser-adapter-openapi-json-3-0 @swagger-api/apidom-parser-adapter-openapi-json-3-1 @swagger-api/apidom-parser-adapter-workflows-json-1 @swagger-api/apidom-parser-adapter-workflows-yaml-1 @swagger-api/apidom-playground", + "unlink": "npm unlink --global @swagger-api/apidom-ast @swagger-api/apidom-converter @swagger-api/apidom-core @swagger-api/apidom-error @swagger-api/apidom-json-path @swagger-api/apidom-json-pointer @swagger-api/apidom-json-pointer-relative @swagger-api/apidom-parser-adapter-json @swagger-api/apidom-ns-api-design-systems @swagger-api/apidom-ns-asyncapi-2 @swagger-api/apidom-ns-json-schema-draft-4 @swagger-api/apidom-ns-json-schema-draft-6 @swagger-api/apidom-ns-json-schema-draft-7 @swagger-api/apidom-ns-openapi-2 @swagger-api/apidom-ns-openapi-3-0 @swagger-api/apidom-ns-openapi-3-1 @swagger-api/apidom-parser-adapter-yaml-1-2 @swagger-api/apidom-parser-adapter-asyncapi-yaml-2 @swagger-api/apidom-parser-adapter-openapi-yaml-2 @swagger-api/apidom-parser-adapter-openapi-yaml-3-0 @swagger-api/apidom-parser-adapter-openapi-yaml-3-1 @swagger-api/apidom-parser @swagger-api/apidom-parser-adapter-api-design-systems-json @swagger-api/apidom-parser-adapter-api-design-systems-yaml @swagger-api/apidom-parser-adapter-asyncapi-json-2 @swagger-api/apidom-ls @swagger-api/apidom-reference @swagger-api/apidom-parser-adapter-openapi-json-2 @swagger-api/apidom-parser-adapter-openapi-json-3-0 @swagger-api/apidom-parser-adapter-openapi-json-3-1 @swagger-api/apidom-parser-adapter-workflows-json-1 @swagger-api/apidom-parser-adapter-workflows-yaml-1 @swagger-api/apidom-playground", "prepare": "chmod +x ./node_modules/husky/lib/bin.js && husky install" }, "repository": { diff --git a/packages/apidom-converter/.eslintignore b/packages/apidom-converter/.eslintignore new file mode 100644 index 0000000000..1e7dc31c49 --- /dev/null +++ b/packages/apidom-converter/.eslintignore @@ -0,0 +1,9 @@ +/dist +/es +/cjs +/types +/config +/.eslintrc.js +/.nyc_output +/node_modules +/**/*.js diff --git a/packages/apidom-converter/.gitignore b/packages/apidom-converter/.gitignore new file mode 100644 index 0000000000..c476245bb7 --- /dev/null +++ b/packages/apidom-converter/.gitignore @@ -0,0 +1,6 @@ +/dist +/es +/cjs +/types +/NOTICE +/swagger-api-apidom-converter-*.tgz diff --git a/packages/apidom-converter/.mocharc.json b/packages/apidom-converter/.mocharc.json new file mode 100644 index 0000000000..e923c24114 --- /dev/null +++ b/packages/apidom-converter/.mocharc.json @@ -0,0 +1,5 @@ +{ + "recursive": true, + "spec": "test/**/*.ts", + "file": ["test/mocha-bootstrap.cjs"] +} diff --git a/packages/apidom-converter/.npmrc b/packages/apidom-converter/.npmrc new file mode 100644 index 0000000000..4b82d2e7bb --- /dev/null +++ b/packages/apidom-converter/.npmrc @@ -0,0 +1,2 @@ +save-prefix="=" +save=false diff --git a/packages/apidom-converter/README.md b/packages/apidom-converter/README.md new file mode 100644 index 0000000000..e8d8cad5f9 --- /dev/null +++ b/packages/apidom-converter/README.md @@ -0,0 +1,11 @@ +# @swagger-api/apidom-converter + +`apidom-converter` is a package that facilitates conversion of API specifications. + +## Installation + +You can install this package via [npm CLI](https://docs.npmjs.com/cli) by running the following command: + +```sh + $ npm install @swagger-api/apidom-converter +``` diff --git a/packages/apidom-converter/config/rollup/types.dist.js b/packages/apidom-converter/config/rollup/types.dist.js new file mode 100644 index 0000000000..8fe05a1782 --- /dev/null +++ b/packages/apidom-converter/config/rollup/types.dist.js @@ -0,0 +1,12 @@ +import dts from 'rollup-plugin-dts'; + +const config = [ + { + input: './types/index.d.ts', + output: [{ file: 'types/dist.d.ts', format: 'es' }], + plugins: [dts()], + external: ['Function/Curry'], + }, +]; + +export default config; diff --git a/packages/apidom-converter/config/webpack/browser.config.js b/packages/apidom-converter/config/webpack/browser.config.js new file mode 100644 index 0000000000..49a83528dd --- /dev/null +++ b/packages/apidom-converter/config/webpack/browser.config.js @@ -0,0 +1,70 @@ +import path from 'node:path'; +import { nonMinimizeTrait, minimizeTrait } from './traits.config.js'; + +const browser = { + mode: 'production', + entry: ['./src/index.ts'], + target: 'web', + performance: { + maxEntrypointSize: 1100000, + maxAssetSize: 1100000, + }, + output: { + path: path.resolve('./dist'), + filename: 'apidom-converter.browser.js', + libraryTarget: 'umd', + library: 'apidomConverter', + }, + resolve: { + extensions: ['.ts', '.mjs', '.js', '.json'], + }, + module: { + rules: [ + { + test: /\.(ts|js)?$/, + exclude: /node_modules/, + use: { + loader: 'babel-loader', + options: { + babelrc: true, + rootMode: 'upward', + }, + }, + }, + ], + }, + ...nonMinimizeTrait, +}; + +const browserMin = { + mode: 'production', + entry: ['./src/index.ts'], + target: 'web', + output: { + path: path.resolve('./dist'), + filename: 'apidom-converter.browser.min.js', + libraryTarget: 'umd', + library: 'apidomConverter', + }, + resolve: { + extensions: ['.ts', '.mjs', '.js', '.json'], + }, + module: { + rules: [ + { + test: /\.(ts|js)?$/, + exclude: /node_modules/, + use: { + loader: 'babel-loader', + options: { + babelrc: true, + rootMode: 'upward', + }, + }, + }, + ], + }, + ...minimizeTrait, +}; + +export default [browser, browserMin]; diff --git a/packages/apidom-converter/config/webpack/traits.config.js b/packages/apidom-converter/config/webpack/traits.config.js new file mode 100644 index 0000000000..9043521175 --- /dev/null +++ b/packages/apidom-converter/config/webpack/traits.config.js @@ -0,0 +1,32 @@ +import webpack from 'webpack'; +import TerserPlugin from 'terser-webpack-plugin'; + +export const nonMinimizeTrait = { + optimization: { + minimize: false, + usedExports: false, + concatenateModules: false, + }, +}; + +export const minimizeTrait = { + plugins: [ + new webpack.LoaderOptionsPlugin({ + minimize: true, + }), + ], + optimization: { + minimizer: [ + new TerserPlugin({ + terserOptions: { + compress: { + warnings: false, + }, + output: { + comments: false, + }, + }, + }), + ], + }, +}; diff --git a/packages/apidom-converter/declaration.tsconfig.json b/packages/apidom-converter/declaration.tsconfig.json new file mode 100644 index 0000000000..5697fa3e89 --- /dev/null +++ b/packages/apidom-converter/declaration.tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", + "exclude": [ + "test/**/*" + ], + "compilerOptions": { + "declaration": true, + "declarationDir": "types", + "noEmit": false, + "emitDeclarationOnly": true + } +} diff --git a/packages/apidom-converter/package.json b/packages/apidom-converter/package.json new file mode 100644 index 0000000000..da9c5f014b --- /dev/null +++ b/packages/apidom-converter/package.json @@ -0,0 +1,54 @@ +{ + "name": "@swagger-api/apidom-converter", + "version": "0.92.0", + "description": "Tool for converting API specifications.", + "private": true, + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org" + }, + "type": "module", + "unpkg": "./dist/apidom-converter.browser.min.js", + "main": "./cjs/index.cjs", + "exports": { + "types": "./types/dist.d.ts", + "import": "./es/index.mjs", + "require": "./cjs/index.cjs" + }, + "types": "./types/dist.d.ts", + "scripts": { + "build": "npm run clean && run-p --max-parallel ${CPU_CORES:-2} typescript:declaration build:es build:cjs build:umd:browser", + "build:es": "cross-env BABEL_ENV=es babel src --out-dir es --extensions '.ts' --out-file-extension '.mjs' --root-mode 'upward'", + "build:cjs": "cross-env BABEL_ENV=cjs babel src --out-dir cjs --extensions '.ts' --out-file-extension '.cjs' --root-mode 'upward'", + "build:umd:browser": "cross-env BABEL_ENV=browser webpack --config config/webpack/browser.config.js --progress", + "lint": "eslint ./", + "lint:fix": "eslint ./ --fix", + "clean": "rimraf ./es ./cjs ./dist ./types", + "typescript:check-types": "tsc --noEmit", + "typescript:declaration": "copyfiles -u 1 'src/**/*.d.ts' ./types && tsc -p declaration.tsconfig.json && rollup -c config/rollup/types.dist.js", + "test": "cross-env NODE_ENV=test BABEL_ENV=cjs mocha", + "test:update-snapshots": "cross-env UPDATE_SNAPSHOT=1 BABEL_ENV=cjs mocha", + "prepack": "copyfiles -u 3 ../../LICENSES/* LICENSES && copyfiles -u 2 ../../NOTICE .", + "postpack": "rimraf NOTICE LICENSES" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/swagger-api/apidom.git" + }, + "author": "VladimĂ­r Gorej", + "license": "Apache-2.0", + "dependencies": { + "@babel/runtime-corejs3": "^7.20.7" + }, + "files": [ + "cjs/", + "dist/", + "es/", + "types/dist.d.ts", + "types/minim.d.ts", + "LICENSES", + "NOTICE", + "README.md", + "CHANGELOG.md" + ] +} diff --git a/packages/apidom-converter/src/index.ts b/packages/apidom-converter/src/index.ts new file mode 100644 index 0000000000..d850e7105f --- /dev/null +++ b/packages/apidom-converter/src/index.ts @@ -0,0 +1,3 @@ +const foo = Symbol('foo'); + +export default foo; diff --git a/packages/apidom-converter/test/.eslintrc b/packages/apidom-converter/test/.eslintrc new file mode 100644 index 0000000000..e4276f33c2 --- /dev/null +++ b/packages/apidom-converter/test/.eslintrc @@ -0,0 +1,40 @@ +{ + "env": { + "mocha": true + }, + "globals": { + "document": true + }, + "plugins": [ + "mocha" + ], + "rules": { + "no-void": 0, + "no-underscore-dangle": 0, + "func-names": 0, + "prefer-arrow-callback": 0, + "no-array-constructor": 0, + "prefer-rest-params": 0, + "no-new-wrappers": 0, + "mocha/no-skipped-tests": 2, + "mocha/handle-done-callback": 2, + "mocha/valid-suite-description": 2, + "mocha/no-mocha-arrows": 2, + "mocha/no-hooks-for-single-case": 2, + "mocha/no-sibling-hooks": 2, + "mocha/no-top-level-hooks": 2, + "mocha/no-identical-title": 2, + "mocha/no-nested-tests": 2, + "mocha/no-exclusive-tests": 2, + "max-classes-per-file": 0 + }, + "overrides": [{ + "files": ["mocha-bootstrap.cjs"], + "parserOptions": { + "sourceType": "script" + }, + "rules": { + "@typescript-eslint/no-var-requires": 0 + } + }] +} diff --git a/packages/apidom-converter/test/index.ts b/packages/apidom-converter/test/index.ts new file mode 100644 index 0000000000..a8eb8b8c58 --- /dev/null +++ b/packages/apidom-converter/test/index.ts @@ -0,0 +1,7 @@ +import { assert } from 'chai'; + +describe('apidom-converter', function () { + it('initial test', async function () { + assert.strictEqual(true, true); + }); +}); diff --git a/packages/apidom-converter/test/mocha-bootstrap.cjs b/packages/apidom-converter/test/mocha-bootstrap.cjs new file mode 100644 index 0000000000..d98d064514 --- /dev/null +++ b/packages/apidom-converter/test/mocha-bootstrap.cjs @@ -0,0 +1,11 @@ +require('@babel/register')({ extensions: ['.js', '.ts'], rootMode: 'upward' }); + +const chai = require('chai'); +const { jestSnapshotPlugin, addSerializer } = require('mocha-chai-jest-snapshot'); + +const jestApiDOMSerializer = require('../../../scripts/jest-serializer-apidom.cjs'); +const jestStringSerializer = require('../../../scripts/jest-serializer-string.cjs'); + +chai.use(jestSnapshotPlugin()); +addSerializer(jestApiDOMSerializer); +addSerializer(jestStringSerializer); diff --git a/packages/apidom-converter/tsconfig.json b/packages/apidom-converter/tsconfig.json new file mode 100644 index 0000000000..4081635a03 --- /dev/null +++ b/packages/apidom-converter/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "include": [ + "src/**/*", + "test/**/*" + ] +} diff --git a/ti-15770.log b/ti-15770.log deleted file mode 100644 index c147b0917b..0000000000 --- a/ti-15770.log +++ /dev/null @@ -1,44 +0,0 @@ -[10:44:32.248] Global cache location '/home/frantuma/.cache/typescript/5.3', safe file path '/dati/dev/progetti/swagger/projects/apidom/master/apidom/node_modules/typescript/lib/typingSafeList.json', types map path /dati/dev/progetti/swagger/projects/apidom/master/apidom/node_modules/typescript/lib/typesMap.json -[10:44:32.249] Processing cache location '/home/frantuma/.cache/typescript/5.3' -[10:44:32.249] Trying to find '/home/frantuma/.cache/typescript/5.3/package.json'... -[10:44:32.250] Loaded content of '/home/frantuma/.cache/typescript/5.3/package.json': - { - "private": true, - "dependencies": { - "types-registry": "^0.1.679" - } - } -[10:44:32.250] Loaded content of '/home/frantuma/.cache/typescript/5.3/package-lock.json': - { - "name": "5.3", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "dependencies": { - "types-registry": "^0.1.679" - } - }, - "node_modules/types-registry": { - "version": "0.1.679", - "resolved": "https://registry.npmjs.org/types-registry/-/types-registry-0.1.679.tgz", - "integrity": "sha512-XQ5kE50Pi7aiyJ45lJ2j2ZhF+1SP0luJ/8vDHnnB4fNKcoGd+VxylnfSW/NAXN2NvO5qUyGbPt/UdsDEyvzVkw==" - } - } - } -[10:44:32.250] Finished processing cache location '/home/frantuma/.cache/typescript/5.3' -[10:44:32.250] Process id: 15780 -[10:44:32.251] NPM location: /home/frantuma/.nvm/versions/node/v20.4.0/bin/npm (explicit '--npmLocation' not provided) -[10:44:32.251] validateDefaultNpmLocation: false -[10:44:32.251] Npm config file: /home/frantuma/.cache/typescript/5.3/package.json -[10:44:32.251] Updating types-registry npm package... -[10:44:32.251] Exec: /home/frantuma/.nvm/versions/node/v20.4.0/bin/npm install --ignore-scripts types-registry@latest -[10:44:33.744] Succeeded. stdout: - - up to date, audited 2 packages in 1s - -found 0 vulnerabilities - -[10:44:33.744] Updated types-registry npm package -[10:44:33.785] Closing file watchers for project '/home/frantuma/.local/share/JetBrains/Toolbox/apps/webstorm/plugins/javascript-impl/jsLanguageServicesImpl/typescript/tsconfig.json' -[10:44:33.785] No watchers are registered for project '/home/frantuma/.local/share/JetBrains/Toolbox/apps/webstorm/plugins/javascript-impl/jsLanguageServicesImpl/typescript/tsconfig.json'