Skip to content

Commit

Permalink
fix: type definitions for common js imports
Browse files Browse the repository at this point in the history
  • Loading branch information
schoero committed Nov 17, 2023
1 parent 098fbd2 commit cbe419a
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
},
{
"files": ["vite.config.ts", "vite.config.bundle.ts"],
"files": ["vite.config.ts", "vite.config.cjs.ts", "vite.config.bundle.ts"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
Expand Down
47 changes: 34 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,53 @@
"sideEffects": false,
"exports": {
"./bundle": {
"import": "./lib/bundle/index.js",
"require": "./lib/bundle/index.js"
"import": "./lib/esm/bundle/index.js",
"require": {
"require": "./lib/cjs/bundle/index.js",
"types": "./lib/cjs/bundle/index.d.ts"
}
},
"./errors": {
"import": "./lib/shared/errors.js",
"require": "./lib/shared/errors.cjs"
"import": "./lib/esm/shared/errors.js",
"require": {
"require": "./lib/cjs/shared/errors.cjs",
"types": "./lib/cjs/shared/errors.d.ts"
}
},
"./pdf": {
"import": "./lib/pdf/index.js",
"require": "./lib/pdf/index.cjs"
"import": "./lib/esm/pdf/index.js",
"require": {
"require": "./lib/cjs/pdf/index.cjs",
"types": "./lib/cjs/pdf/index.d.ts"
}
},
"./svg": {
"import": "./lib/svg/index.js",
"require": "./lib/svg/index.cjs"
"import": "./lib/esm/svg/index.js",
"require": {
"require": "./lib/cjs/svg/index.cjs",
"types": "./lib/cjs/svg/index.d.ts"
}
},
"./types": {
"import": "./lib/shared/types.js",
"require": "./lib/shared/types.cjs"
"import": "./lib/esm/shared/types.js",
"require": {
"require": "./lib/cjs/shared/types.cjs",
"types": "./lib/cjs/shared/types.d.ts"
}
},
"./utils": {
"import": "./lib/shared/utils.js",
"require": "./lib/shared/utils.cjs"
"import": "./lib/esm/shared/utils.js",
"require": {
"require": "./lib/cjs/shared/utils.cjs",
"types": "./lib/cjs/shared/utils.d.ts"
}
}
},
"scripts": {
"build": "rm -r ./lib || true && vite build --config vite.config.ts && vite build --config vite.config.bundle.ts",
"build": "npm run build:bundle && npm run build:cjs && npm run build:esm",
"build:bundle": "vite build --config vite.config.bundle.ts",
"build:cjs": "vite build --config vite.config.cjs.ts && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
"build:esm": "vite build --config vite.config.ts && echo '{ \"type\": \"module\" }' > lib/esm/package.json",
"docs": "npm run docs:pdf && npm run docs:svg && npm run docs:shared && npm run docs:bundle",
"docs:bundle": "unwritten src/bundle/index.ts -t tsconfig.docs.json -o docs/bundle/ ",
"docs:pdf": "unwritten src/pdf/index.ts src/shared/types.ts -t tsconfig.docs.json -o docs/pdf/",
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"declaration": false,
"declarationMap": false,
"lib": ["ESNext", "DOM"],
"module": "ESNext",
"moduleResolution": "Bundler",
"noImplicitAny": false,
"outDir": "lib",
"paths": {
Expand Down
7 changes: 0 additions & 7 deletions tsconfig.vite.json

This file was deleted.

5 changes: 3 additions & 2 deletions vite.config.bundle.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { config, defineConfig } from "@schoero/vite-config";

import type { UserConfig } from "vite";

/** @type {import('vitest/config').UserConfig} */
export default defineConfig({

export default defineConfig(<UserConfig>{
...config,
build: {
emptyOutDir: false,
Expand Down
32 changes: 32 additions & 0 deletions vite.config.cjs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { sync } from "glob";
import dts from "vite-plugin-dts";
import noBundlePlugin from "vite-plugin-no-bundle";

import { config, defineConfig } from "@schoero/vite-config";

import type { UserConfig } from "vite";


export default defineConfig(<UserConfig>{
...config,
build: {
emptyOutDir: true,
lib: {
entry: sync("src/**/*.ts", { ignore: ["src/**/*.test.ts", "test/**", "src/bundle/*"] }),
formats: ["cjs"]
},
minify: false,
outDir: "lib/cjs",
ssr: true,
target: "es6"
},
plugins: [
...config.plugins ?? [],
noBundlePlugin(),
dts({
entryRoot: "./src",
exclude: ["src/**/*.test.ts", "test/**", "src/bundle/*"],
pathsToAliases: true
})
]
});
11 changes: 6 additions & 5 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import noBundlePlugin from "vite-plugin-no-bundle";

import { config, defineConfig } from "@schoero/vite-config";

import type { UserConfig } from "vite";

/** @type {import('vitest/config').UserConfig} */
export default defineConfig({

export default defineConfig(<UserConfig>{
...config,
build: {
emptyOutDir: false,
emptyOutDir: true,
lib: {
entry: sync("src/**/*.ts", { ignore: ["src/**/*.test.ts", "test/**", "src/bundle/*"] }),
formats: ["es", "cjs"]
formats: ["es"]
},
minify: false,
outDir: "lib",
outDir: "lib/esm",
ssr: true,
target: "es6"
},
Expand Down

0 comments on commit cbe419a

Please sign in to comment.