Skip to content

Commit

Permalink
#2846 Type error when importing docx in CJS file with TypeScript modu… (
Browse files Browse the repository at this point in the history
#2883)

* #2846 Type error when importing docx in CJS file with TypeScript moduleResolution set to node16

* Adhere to publint
  • Loading branch information
dolanmiu authored Dec 6, 2024
1 parent df99f96 commit e80a50d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ node_modules
.node_repl_history

# build
build
build-tests
dist

# Documentation
docs/api/
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import tsEslint from "typescript-eslint";

const config: Linter.Config<Linter.RulesRecord>[] = [
{
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,
Expand Down
20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
39 changes: 18 additions & 21 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand All @@ -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") {
Expand All @@ -53,7 +59,7 @@ export default defineConfig({
},
formats: ["iife", "es", "cjs", "umd"],
},
outDir: resolve(__dirname, "build"),
outDir: resolve(__dirname, "dist"),
commonjsOptions: {
include: [/node_modules/],
},
Expand All @@ -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/**"],
},
});

0 comments on commit e80a50d

Please sign in to comment.