From 18460f45e64cf4288b5aeec82257cd838b65e610 Mon Sep 17 00:00:00 2001 From: Adam Tkaczyk Date: Wed, 31 Jan 2024 00:45:18 +0100 Subject: [PATCH] build: :construction_worker: export only index and errors --- .eslintrc.cjs | 9 ++------- esbuild.mjs | 18 ++++++++++++++++++ src/index.ts | 4 ++++ tsconfig.json | 4 ++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 04dac93..33770cf 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -4,14 +4,15 @@ module.exports = { 'eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:sonarjs/recommended', - 'plugin:vitest/all', ], parser: '@typescript-eslint/parser', plugins: ['@typescript-eslint', 'sonarjs', 'vitest'], root: true, + ignorePatterns: ['dist'], overrides: [ { files: ['*.spec.ts'], + extends: ['plugin:vitest/all'], rules: { 'vitest/prefer-to-be-truthy': 'off', 'vitest/prefer-to-be-falsy': 'off', @@ -20,11 +21,5 @@ module.exports = { 'vitest/prefer-lowercase-title': 'off', }, }, - { - files: ['demo/**/*'], - rules: { - 'vitest/require-hook': 'off', - }, - }, ], } diff --git a/esbuild.mjs b/esbuild.mjs index e8f091a..525e263 100644 --- a/esbuild.mjs +++ b/esbuild.mjs @@ -1,4 +1,7 @@ import * as esbuild from 'esbuild' +import fs from 'fs' +import path from 'path' +import { fileURLToPath } from 'url' await esbuild.build({ entryPoints: ['src/index.ts'], @@ -7,3 +10,18 @@ await esbuild.build({ format: 'esm', minify: true, }) + +// TODO can we do it with esbuild/tsconfig.json? +// remove all files with .d.ts extension from dist folder except index.d.ts +const __filename = fileURLToPath(import.meta.url) +const __dirname = path.dirname(__filename) + +const distDir = path.join(__dirname, 'dist') +const files = fs.readdirSync(distDir) + +files.forEach((file) => { + if (file.endsWith('.d.ts') && file !== 'index.d.ts') { + fs.unlinkSync(path.join(distDir, file)) + } +}) + diff --git a/src/index.ts b/src/index.ts index 619cdfa..952ce10 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,10 @@ import { CelVisitor } from './visitor.js' import { CstNode } from 'chevrotain' import { CelParseError } from './errors/CelParseError.js' +export { CelParseError } from './errors/CelParseError.js' +export { CelEvaluationError } from './errors/CelEvaluationError.js' +export { CelTypeError } from './errors/CelTypeError.js' + const parserInstance = new CelParser() export type Success = { diff --git a/tsconfig.json b/tsconfig.json index ec0de88..40f9098 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,6 +15,6 @@ "*": ["*", "src/*"] } }, - "include": ["src/**/*", "src/tokens.ts"], - "exclude": ["node_modules", "lib", "**/*.spec.ts"] + "include": ["src/index.ts"], + "exclude": ["node_modules", "dist", "**/*.spec.ts"] }