diff --git a/.gitignore b/.gitignore index 2ec3d77b21..4233d23299 100644 --- a/.gitignore +++ b/.gitignore @@ -33,8 +33,7 @@ node_modules .node_repl_history # build -build -build-tests +dist # Documentation docs/api/ diff --git a/eslint.config.ts b/eslint.config.ts index 8733c814a1..03101357d0 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -10,7 +10,7 @@ import tsEslint from "typescript-eslint"; const config: Linter.Config[] = [ { - ignores: ["**/vite.config.ts", "**/build/**", "**/coverage/**", "**/*.js", "eslint.config.ts", "**/demo/**", "**/scripts/**"], + ignores: ["**/vite.config.ts", "**/dist/**", "**/coverage/**", "**/*.js", "eslint.config.ts", "**/demo/**", "**/scripts/**"], }, eslint.configs.recommended, importPlugin.flatConfigs.recommended, diff --git a/package.json b/package.json index 1e496e0fd7..5b413eb67c 100644 --- a/package.json +++ b/package.json @@ -3,19 +3,23 @@ "version": "9.1.0", "description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.", "type": "module", - "main": "build/index.umd.js", - "module": "./build/index.mjs", - "types": "./build/index.d.ts", + "main": "dist/index.umd.cjs", + "module": "./dist/index.mjs", + "types": "./dist/index.d.ts", "exports": { ".": { - "require": "./build/index.cjs", - "types": "./build/index.d.ts", - "import": "./build/index.mjs", - "default": "./build/index.mjs" + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.mjs" + }, + "require": { + "types": "./dist/index.d.cts", + "default": "./dist/index.cjs" + } } }, "files": [ - "build" + "dist" ], "scripts": { "build": "tsc && vite build", diff --git a/vite.config.ts b/vite.config.ts index f39fd8080f..b60c84a0d3 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,12 +3,18 @@ import dts from "vite-plugin-dts"; import { nodePolyfills } from "vite-plugin-node-polyfills"; import tsconfigPaths from "vite-tsconfig-paths"; import { configDefaults, defineConfig } from "vitest/config"; +import { copyFileSync } from "node:fs"; export default defineConfig({ plugins: [ tsconfigPaths(), dts({ - rollupTypes: true + rollupTypes: true, + afterBuild: () => { + // https://github.com/dolanmiu/docx/pull/2883 + // To pass publint - `npx publint@latest` + copyFileSync("dist/index.d.ts", "dist/index.d.cts"); + }, }), nodePolyfills({ exclude: [], @@ -34,7 +40,7 @@ export default defineConfig({ name: "docx", fileName: (d) => { if (d === "umd") { - return "index.umd.js"; + return "index.umd.cjs"; } if (d === "cjs") { @@ -53,7 +59,7 @@ export default defineConfig({ }, formats: ["iife", "es", "cjs", "umd"], }, - outDir: resolve(__dirname, "build"), + outDir: resolve(__dirname, "dist"), commonjsOptions: { include: [/node_modules/], }, @@ -71,25 +77,16 @@ export default defineConfig({ }, exclude: [ ...configDefaults.exclude, - '**/build/**', - '**/demo/**', - '**/docs/**', - '**/scripts/**', - '**/src/**/index.ts', - '**/src/**/types.ts', - '**/*.spec.ts', + "**/dist/**", + "**/demo/**", + "**/docs/**", + "**/scripts/**", + "**/src/**/index.ts", + "**/src/**/types.ts", + "**/*.spec.ts", ], }, - include: [ - '**/src/**/*.spec.ts', - '**/packages/**/*.spec.ts' - ], - exclude: [ - ...configDefaults.exclude, - '**/build/**', - '**/demo/**', - '**/docs/**', - '**/scripts/**' - ], + include: ["**/src/**/*.spec.ts", "**/packages/**/*.spec.ts"], + exclude: [...configDefaults.exclude, "**/build/**", "**/demo/**", "**/docs/**", "**/scripts/**"], }, });