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

Commit 9c5aeed

Browse files
authored
chore: update build setup, fix #134 (#127)
* chore: update build setup * refactor: move files around * chore: remove src/ folder from dist/ folder structure * fix: can’t find test file * chore: show output size * chore: add terser to minify the build * chore: don’t publish the webpack stats output * chore: rebase
1 parent 8d8aa80 commit 9c5aeed

17 files changed

+351
-172
lines changed

demo/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
8-
"build": "vue-tsc && vite build",
8+
"build": "vue-tsc --noEmit && vite build",
99
"preview": "vite preview"
1010
},
1111
"dependencies": {

demo/src/App.vue

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { dereference, load } from '@scalar/openapi-parser'
33
import { fetchUrls } from '@scalar/openapi-parser/plugins/fetch-urls'
44
import { watchDebounced } from '@vueuse/core'
55
import { onMounted, ref, watch } from 'vue'
6-
// @ts-expect-error Package doesn’t come with types
76
import JsonViewer from 'vue-json-viewer'
87
98
const value = ref(

demo/tsconfig.json

+22-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2020",
4-
"useDefineForClassFields": true,
5-
"module": "ESNext",
6-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
7-
"skipLibCheck": true,
8-
9-
/* Bundler mode */
10-
"moduleResolution": "bundler",
11-
"allowImportingTsExtensions": true,
12-
"resolveJsonModule": true,
3+
"target": "ES2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
4+
"module": "ESNext" /* Specify what module code is generated. */,
5+
"moduleResolution": "Bundler",
6+
// Required for isolated module compilation (ESBuild)
137
"isolatedModules": true,
14-
"noEmit": true,
15-
"jsx": "preserve",
16-
17-
/* Linting */
18-
"strict": true,
19-
"noUnusedLocals": true,
20-
"noUnusedParameters": true,
21-
"noFallthroughCasesInSwitch": true
8+
// Support proper ESM builds
9+
"esModuleInterop": true,
10+
// Ensure that casing is correct in imports.
11+
"forceConsistentCasingInFileNames": true,
12+
"strict": false,
13+
"strictNullChecks": false,
14+
"resolveJsonModule": true,
15+
"skipLibCheck": true
16+
},
17+
"include": ["src/**/*", "tests/**/*", "**/*.json", "**/*.yaml"],
18+
"exclude": ["dist", "node_modules", "**/dist", "**/node_modules"],
19+
// Required for path rewrites
20+
"ts-node": {
21+
"require": ["tsconfig-paths/register"]
2222
},
23-
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
24-
"references": [{ "path": "./tsconfig.node.json" }]
23+
// Required for path aliasing
24+
"tsc-alias": {
25+
"resolveFullPaths": true
26+
}
2527
}

demo/tsconfig.node.json

-11
This file was deleted.

packages/openapi-parser/package.json

+11-8
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,21 @@
1919
"type": "module",
2020
"files": [
2121
"dist",
22+
"!dist/webpack-stats.json",
2223
"CHANGELOG.md"
2324
],
24-
"main": "./dist/src/index.js",
25-
"module": "./dist/src/index.js",
25+
"main": "./dist/index.js",
26+
"module": "./dist/index.js",
2627
"types": "./dist/index.d.ts",
2728
"exports": {
2829
".": {
29-
"import": "./dist/src/index.js"
30+
"import": "./dist/index.js"
3031
},
3132
"./plugins/fetch-urls": {
32-
"import": "./dist/src/utils/load/plugins/fetchUrls.js"
33+
"import": "./dist/utils/load/plugins/fetchUrls.js"
3334
},
3435
"./plugins/read-files": {
35-
"import": "./dist/src/utils/load/plugins/readFiles.js"
36+
"import": "./dist/utils/load/plugins/readFiles.js"
3637
}
3738
},
3839
"sideEffects": false,
@@ -43,21 +44,23 @@
4344
},
4445
"scripts": {
4546
"types:check": "tsc --noEmit --skipLibCheck",
46-
"build": "pnpm types:check && rollup -c --configPlugin typescript",
47+
"build": "pnpm types:check && rollup -c --configPlugin typescript && pnpm types:build",
48+
"types:build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
4749
"test": "vitest"
4850
},
4951
"devDependencies": {
5052
"@apidevtools/swagger-parser": "^10.1.0",
5153
"@rollup/plugin-json": "^6.1.0",
54+
"@rollup/plugin-terser": "^0.4.4",
5255
"@rollup/plugin-typescript": "^11.1.6",
5356
"@types/node": "^20.14.0",
5457
"glob": "^10.4.1",
5558
"just-diff": "^6.0.2",
5659
"rollup": "^4.18.0",
57-
"rollup-plugin-dts": "^6.1.1",
58-
"rollup-plugin-esbuild": "^6.1.1",
60+
"rollup-plugin-output-size": "^1.4.0",
5961
"rollup-plugin-webpack-stats": "^0.2.6",
6062
"tinybench": "^2.8.0",
63+
"tsc-alias": "^1.8.10",
6164
"tslib": "^2.6.2"
6265
},
6366
"dependencies": {
+12-31
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import json from '@rollup/plugin-json'
2+
import terser from '@rollup/plugin-terser'
3+
import typescript from '@rollup/plugin-typescript'
24
import { rm } from 'node:fs/promises'
35
import { builtinModules } from 'node:module'
46
import type { RollupOptions } from 'rollup'
57
import type { Plugin } from 'rollup'
6-
import dts from 'rollup-plugin-dts'
7-
import type { Options as ESBuildOptions } from 'rollup-plugin-esbuild'
8-
import esbuild from 'rollup-plugin-esbuild'
8+
import outputSize from 'rollup-plugin-output-size'
99
import { webpackStats } from 'rollup-plugin-webpack-stats'
1010

1111
const input = [
1212
'./src/index.ts',
1313
'./src/utils/load/plugins/fetchUrls.ts',
1414
'./src/utils/load/plugins/readFiles.ts',
1515
]
16+
1617
const dir = 'dist'
1718

1819
/**
@@ -37,18 +38,6 @@ function cleanBeforeWrite(directory: string): Plugin {
3738
}
3839
}
3940

40-
/**
41-
* Minimal ESBuild minifier.
42-
*/
43-
function esbuildMinifer(options: ESBuildOptions) {
44-
const { renderChunk } = esbuild(options)
45-
46-
return {
47-
name: 'esbuild-minifer',
48-
renderChunk,
49-
}
50-
}
51-
5241
/**
5342
* Rollup configuration
5443
*/
@@ -59,20 +48,19 @@ const config: RollupOptions[] = [
5948
output: [
6049
// ESM
6150
{
62-
dir,
63-
format: 'es',
64-
sourcemap: false,
51+
format: 'esm',
6552
preserveModules: true,
53+
preserveModulesRoot: 'src',
54+
dir,
6655
},
6756
],
6857
plugins: [
6958
cleanBeforeWrite(dir),
59+
typescript(),
7060
json(),
71-
esbuild({
72-
exclude: /node_modules/,
73-
}),
74-
esbuildMinifer,
61+
terser(),
7562
webpackStats(),
63+
outputSize(),
7664
],
7765
external: [
7866
...builtinModules,
@@ -83,17 +71,10 @@ const config: RollupOptions[] = [
8371
'yaml',
8472
],
8573
treeshake: {
86-
moduleSideEffects: false,
87-
propertyReadSideEffects: false,
88-
tryCatchDeoptimization: false,
74+
annotations: true,
75+
preset: 'recommended',
8976
},
9077
},
91-
// Types
92-
{
93-
input,
94-
output: [{ dir, format: 'es', sourcemap: false, preserveModules: true }],
95-
plugins: [dts()],
96-
},
9778
]
9879

9980
export default config

packages/openapi-parser/src/configuration.ts packages/openapi-parser/src/configuration/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import Swagger20 from '../schemas/v2.0/schema.json'
2-
import OpenApi30 from '../schemas/v3.0/schema.json'
3-
import OpenApi31 from '../schemas/v3.1/schema.json'
1+
import Swagger20 from '../../schemas/v2.0/schema.json'
2+
import OpenApi30 from '../../schemas/v3.0/schema.json'
3+
import OpenApi31 from '../../schemas/v3.1/schema.json'
44

55
/**
66
* A list of the supported OpenAPI specifications

packages/openapi-parser/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1+
export * from './configuration'
12
export * from './lib'
23
export * from './types'
34
export * from './utils'
4-
export * from './pipeline'

packages/openapi-parser/src/utils/betterAjvErrors/helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
PatternValidationError,
1717
RequiredValidationError,
1818
UnevaluatedPropValidationError,
19-
} from './validation-errors'
19+
} from './validation-errors/index'
2020

2121
// eslint-disable-next-line unicorn/no-unsafe-regex
2222
const JSON_POINTERS_REGEX = /\/[\w_-]+(\/\d+)?/g

packages/openapi-parser/src/utils/betterAjvErrors/validation-errors/base.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// import { codeFrameColumns } from '@babel/code-frame';
22
// import chalk from 'chalk';
3-
import { getMetaFromPath } from '../json'
3+
import { getMetaFromPath } from '../json/index'
44

55
export default class BaseValidationError {
66
// eslint-disable-next-line default-param-last

packages/openapi-parser/src/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export * from './isYaml'
1212
export * from './load'
1313
export * from './load/load'
1414
export * from './normalize'
15+
export * from './openapi'
1516
export * from './resolveReferences'
1617
export * from './toJson'
1718
export * from './toYaml'

packages/openapi-parser/src/pipeline.test.ts packages/openapi-parser/src/utils/openapi.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { join } from 'node:path'
22
import { describe, expect, it } from 'vitest'
33
import { stringify } from 'yaml'
44

5-
import { openapi } from './pipeline'
6-
import { readFiles } from './utils/load/plugins/readFiles'
5+
import { readFiles } from './load/plugins/readFiles'
6+
import { openapi } from './openapi'
77

88
const example = {
99
openapi: '3.1.0',
@@ -16,7 +16,7 @@ const example = {
1616

1717
const EXAMPLE_FILE = join(
1818
new URL(import.meta.url).pathname,
19-
'../utils/examples/openapi.yaml',
19+
'../examples/openapi.yaml',
2020
)
2121

2222
describe('pipeline', () => {

packages/openapi-parser/src/pipeline.ts packages/openapi-parser/src/utils/openapi.ts

+11-14
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ import type {
33
DetailsResult,
44
Filesystem,
55
ThrowOnErrorOption,
6-
} from './types'
7-
import {
8-
dereference,
9-
details,
10-
filter,
11-
getEntrypoint,
12-
load,
13-
toJson,
14-
toYaml,
15-
upgrade,
16-
validate,
17-
} from './utils'
18-
import { type LoadPlugin } from './utils/load/load'
19-
import { workThroughQueue } from './utils/workThroughQueue'
6+
} from '../types'
7+
import { dereference } from './dereference'
8+
import { details } from './details'
9+
import { filter } from './filter'
10+
import { getEntrypoint } from './getEntrypoint'
11+
import { type LoadPlugin, load } from './load'
12+
import { toJson } from './toJson'
13+
import { toYaml } from './toYaml'
14+
import { upgrade } from './upgrade'
15+
import { validate } from './validate'
16+
import { workThroughQueue } from './workThroughQueue'
2017

2118
/**
2219
* A queuable action for the pipeline

packages/openapi-parser/src/utils/workThroughQueue.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { Queue } from '../pipeline'
21
import type {
32
DereferenceResult,
43
Filesystem,
@@ -7,6 +6,7 @@ import type {
76
UpgradeResult,
87
ValidateResult,
98
} from '../types'
9+
import type { Queue } from './openapi'
1010

1111
type WorkThroughQueueResult = Partial<
1212
LoadResult &
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["src"],
4+
"exclude": ["node_modules", "dist", "test", "**/*.test.ts"],
5+
"compilerOptions": {
6+
"skipLibCheck": true,
7+
"declaration": true,
8+
"declarationMap": true,
9+
"emitDeclarationOnly": true,
10+
"outDir": "dist/",
11+
"rootDir": "src/"
12+
}
13+
}

packages/openapi-parser/tsconfig.json

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
{
22
"compilerOptions": {
3-
"allowSyntheticDefaultImports": true,
4-
"forceConsistentCasingInFileNames": true,
5-
"module": "ESNext",
3+
"target": "ES2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
4+
"module": "ESNext" /* Specify what module code is generated. */,
65
"moduleResolution": "Bundler",
7-
"noEmitOnError": true,
8-
"noUnusedParameters": true,
9-
"pretty": true,
10-
"resolveJsonModule": true,
11-
"skipLibCheck": true,
6+
// Required for isolated module compilation (ESBuild)
7+
"isolatedModules": true,
8+
// Support proper ESM builds
9+
"esModuleInterop": true,
10+
// Ensure that casing is correct in imports.
11+
"forceConsistentCasingInFileNames": true,
1212
"strict": false,
13-
"target": "ES2022",
14-
"useDefineForClassFields": false,
15-
"paths": {
16-
"rollup": ["./node_modules/rollup"]
17-
}
13+
"strictNullChecks": false,
14+
"resolveJsonModule": true,
15+
"skipLibCheck": true
1816
},
1917
"include": [
2018
"src/**/*",
@@ -23,5 +21,13 @@
2321
"**/*.yaml",
2422
"rollup.config.ts"
2523
],
26-
"exclude": ["dist", "node_modules"]
24+
"exclude": ["dist", "node_modules", "**/dist", "**/node_modules"],
25+
// Required for path rewrites
26+
"ts-node": {
27+
"require": ["tsconfig-paths/register"]
28+
},
29+
// Required for path aliasing
30+
"tsc-alias": {
31+
"resolveFullPaths": true
32+
}
2733
}

0 commit comments

Comments
 (0)