Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

chore: update build setup, fix #134 #127

Merged
merged 8 commits into from
Jun 21, 2024
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
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc && vite build",
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview"
},
"dependencies": {
Expand Down
1 change: 0 additions & 1 deletion demo/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { dereference, load } from '@scalar/openapi-parser'
import { fetchUrls } from '@scalar/openapi-parser/plugins/fetch-urls'
import { watchDebounced } from '@vueuse/core'
import { onMounted, ref, watch } from 'vue'
// @ts-expect-error Package doesn’t come with types
import JsonViewer from 'vue-json-viewer'

const value = ref(
Expand Down
42 changes: 22 additions & 20 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"target": "ES2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"module": "ESNext" /* Specify what module code is generated. */,
"moduleResolution": "Bundler",
// Required for isolated module compilation (ESBuild)
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
// Support proper ESM builds
"esModuleInterop": true,
// Ensure that casing is correct in imports.
"forceConsistentCasingInFileNames": true,
"strict": false,
"strictNullChecks": false,
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": ["src/**/*", "tests/**/*", "**/*.json", "**/*.yaml"],
"exclude": ["dist", "node_modules", "**/dist", "**/node_modules"],
// Required for path rewrites
"ts-node": {
"require": ["tsconfig-paths/register"]
},
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
// Required for path aliasing
"tsc-alias": {
"resolveFullPaths": true
}
}
11 changes: 0 additions & 11 deletions demo/tsconfig.node.json

This file was deleted.

19 changes: 11 additions & 8 deletions packages/openapi-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@
"type": "module",
"files": [
"dist",
"!dist/webpack-stats.json",
"CHANGELOG.md"
],
"main": "./dist/src/index.js",
"module": "./dist/src/index.js",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/src/index.js"
"import": "./dist/index.js"
},
"./plugins/fetch-urls": {
"import": "./dist/src/utils/load/plugins/fetchUrls.js"
"import": "./dist/utils/load/plugins/fetchUrls.js"
},
"./plugins/read-files": {
"import": "./dist/src/utils/load/plugins/readFiles.js"
"import": "./dist/utils/load/plugins/readFiles.js"
}
},
"sideEffects": false,
Expand All @@ -43,21 +44,23 @@
},
"scripts": {
"types:check": "tsc --noEmit --skipLibCheck",
"build": "pnpm types:check && rollup -c --configPlugin typescript",
"build": "pnpm types:check && rollup -c --configPlugin typescript && pnpm types:build",
"types:build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
"test": "vitest"
},
"devDependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^20.14.0",
"glob": "^10.4.1",
"just-diff": "^6.0.2",
"rollup": "^4.18.0",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-output-size": "^1.4.0",
"rollup-plugin-webpack-stats": "^0.2.6",
"tinybench": "^2.8.0",
"tsc-alias": "^1.8.10",
"tslib": "^2.6.2"
},
"dependencies": {
Expand Down
43 changes: 12 additions & 31 deletions packages/openapi-parser/rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import json from '@rollup/plugin-json'
import terser from '@rollup/plugin-terser'
import typescript from '@rollup/plugin-typescript'
import { rm } from 'node:fs/promises'
import { builtinModules } from 'node:module'
import type { RollupOptions } from 'rollup'
import type { Plugin } from 'rollup'
import dts from 'rollup-plugin-dts'
import type { Options as ESBuildOptions } from 'rollup-plugin-esbuild'
import esbuild from 'rollup-plugin-esbuild'
import outputSize from 'rollup-plugin-output-size'
import { webpackStats } from 'rollup-plugin-webpack-stats'

const input = [
'./src/index.ts',
'./src/utils/load/plugins/fetchUrls.ts',
'./src/utils/load/plugins/readFiles.ts',
]

const dir = 'dist'

/**
Expand All @@ -37,18 +38,6 @@ function cleanBeforeWrite(directory: string): Plugin {
}
}

/**
* Minimal ESBuild minifier.
*/
function esbuildMinifer(options: ESBuildOptions) {
const { renderChunk } = esbuild(options)

return {
name: 'esbuild-minifer',
renderChunk,
}
}

/**
* Rollup configuration
*/
Expand All @@ -59,20 +48,19 @@ const config: RollupOptions[] = [
output: [
// ESM
{
dir,
format: 'es',
sourcemap: false,
format: 'esm',
preserveModules: true,
preserveModulesRoot: 'src',
dir,
},
],
plugins: [
cleanBeforeWrite(dir),
typescript(),
json(),
esbuild({
exclude: /node_modules/,
}),
esbuildMinifer,
terser(),
webpackStats(),
outputSize(),
],
external: [
...builtinModules,
Expand All @@ -83,17 +71,10 @@ const config: RollupOptions[] = [
'yaml',
],
treeshake: {
moduleSideEffects: false,
propertyReadSideEffects: false,
tryCatchDeoptimization: false,
annotations: true,
preset: 'recommended',
},
},
// Types
{
input,
output: [{ dir, format: 'es', sourcemap: false, preserveModules: true }],
plugins: [dts()],
},
]

export default config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Swagger20 from '../schemas/v2.0/schema.json'
import OpenApi30 from '../schemas/v3.0/schema.json'
import OpenApi31 from '../schemas/v3.1/schema.json'
import Swagger20 from '../../schemas/v2.0/schema.json'
import OpenApi30 from '../../schemas/v3.0/schema.json'
import OpenApi31 from '../../schemas/v3.1/schema.json'

/**
* A list of the supported OpenAPI specifications
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-parser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './configuration'
export * from './lib'
export * from './types'
export * from './utils'
export * from './pipeline'
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
PatternValidationError,
RequiredValidationError,
UnevaluatedPropValidationError,
} from './validation-errors'
} from './validation-errors/index'

// eslint-disable-next-line unicorn/no-unsafe-regex
const JSON_POINTERS_REGEX = /\/[\w_-]+(\/\d+)?/g
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import { codeFrameColumns } from '@babel/code-frame';
// import chalk from 'chalk';
import { getMetaFromPath } from '../json'
import { getMetaFromPath } from '../json/index'

export default class BaseValidationError {
// eslint-disable-next-line default-param-last
Expand Down
1 change: 1 addition & 0 deletions packages/openapi-parser/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './isYaml'
export * from './load'
export * from './load/load'
export * from './normalize'
export * from './openapi'
export * from './resolveReferences'
export * from './toJson'
export * from './toYaml'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { join } from 'node:path'
import { describe, expect, it } from 'vitest'
import { stringify } from 'yaml'

import { openapi } from './pipeline'
import { readFiles } from './utils/load/plugins/readFiles'
import { readFiles } from './load/plugins/readFiles'
import { openapi } from './openapi'

const example = {
openapi: '3.1.0',
Expand All @@ -16,7 +16,7 @@ const example = {

const EXAMPLE_FILE = join(
new URL(import.meta.url).pathname,
'../utils/examples/openapi.yaml',
'../examples/openapi.yaml',
)

describe('pipeline', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ import type {
DetailsResult,
Filesystem,
ThrowOnErrorOption,
} from './types'
import {
dereference,
details,
filter,
getEntrypoint,
load,
toJson,
toYaml,
upgrade,
validate,
} from './utils'
import { type LoadPlugin } from './utils/load/load'
import { workThroughQueue } from './utils/workThroughQueue'
} from '../types'
import { dereference } from './dereference'
import { details } from './details'
import { filter } from './filter'
import { getEntrypoint } from './getEntrypoint'
import { type LoadPlugin, load } from './load'
import { toJson } from './toJson'
import { toYaml } from './toYaml'
import { upgrade } from './upgrade'
import { validate } from './validate'
import { workThroughQueue } from './workThroughQueue'

/**
* A queuable action for the pipeline
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-parser/src/utils/workThroughQueue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Queue } from '../pipeline'
import type {
DereferenceResult,
Filesystem,
Expand All @@ -7,6 +6,7 @@ import type {
UpgradeResult,
ValidateResult,
} from '../types'
import type { Queue } from './openapi'

type WorkThroughQueueResult = Partial<
LoadResult &
Expand Down
13 changes: 13 additions & 0 deletions packages/openapi-parser/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"exclude": ["node_modules", "dist", "test", "**/*.test.ts"],
"compilerOptions": {
"skipLibCheck": true,
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "dist/",
"rootDir": "src/"
}
}
34 changes: 20 additions & 14 deletions packages/openapi-parser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"target": "ES2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"module": "ESNext" /* Specify what module code is generated. */,
"moduleResolution": "Bundler",
"noEmitOnError": true,
"noUnusedParameters": true,
"pretty": true,
"resolveJsonModule": true,
"skipLibCheck": true,
// Required for isolated module compilation (ESBuild)
"isolatedModules": true,
// Support proper ESM builds
"esModuleInterop": true,
// Ensure that casing is correct in imports.
"forceConsistentCasingInFileNames": true,
"strict": false,
"target": "ES2022",
"useDefineForClassFields": false,
"paths": {
"rollup": ["./node_modules/rollup"]
}
"strictNullChecks": false,
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": [
"src/**/*",
Expand All @@ -23,5 +21,13 @@
"**/*.yaml",
"rollup.config.ts"
],
"exclude": ["dist", "node_modules"]
"exclude": ["dist", "node_modules", "**/dist", "**/node_modules"],
// Required for path rewrites
"ts-node": {
"require": ["tsconfig-paths/register"]
},
// Required for path aliasing
"tsc-alias": {
"resolveFullPaths": true
}
}
Loading