Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adjust Typescript definition export #5583

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": "../tsconfig.json",
"exclude": [],
"include": ["./**/*.ts"],
"compilerOptions": {
"rootDir": "..",
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,27 @@
"require": "./dist/index.cjs"
},
"./dist/Components/*.js": {
"types": "./dist/components/*/index.d.ts",
"import": "./dist/Components/*.mjs",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be so happy to get rid of the uppercase path...

"require": "./dist/Components/*.cjs"
},
"./dist/Directives/*.js": {
"types": "./dist/directives/*/index.d.ts",
"import": "./dist/Directives/*.mjs",
"require": "./dist/Directives/*.cjs"
},
"./dist/Functions/*.js": {
"types": "./dist/functions/*/index.d.ts",
"import": "./dist/Functions/*.mjs",
"require": "./dist/Functions/*.cjs"
},
"./dist/Mixins/*.js": {
"types": "./dist/mixins/*/index.d.ts",
"import": "./dist/Mixins/*.mjs",
"require": "./dist/Mixins/*.cjs"
},
"./dist/Composables/*.js": {
"types": "./dist/composables/*/index.d.ts",
"import": "./dist/Composables/*.mjs",
"require": "./dist/Composables/*.cjs"
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/NcButton/NcButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ export default defineComponent({
},

ncPopoverTriggerAttrs() {
return this.getNcPopoverTriggerAttrs()
return (this.getNcPopoverTriggerAttrs as () => Record<string, string|undefined>)()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using Options API it is always infered as unknown only Composition API (setup) will provide correct type information without any need to cast it here.

},
},

Expand Down
2 changes: 1 addition & 1 deletion tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"compilerOptions": {
"rootDir": ".."
},
"include": ["./**/*.ts"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we only need to reset the excludes from the root config

"exclude": [],
}
12 changes: 6 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"extends": "@vue/tsconfig/tsconfig.json",
"include": ["./src/**/*.ts", "./src/**/*.vue", "**/*.ts"],
"exclude": ["./src/**/*.cy.ts"],
"include": ["./src/**/*.js","./src/**/*.ts", "./src/**/*.vue", "**/*.ts"],
"exclude": ["./src/**/*.cy.ts", "cypress", "tests"],
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "Bundler",
"target": "ESNext",
"module": "ESNext",
"declaration": true,
"strict": true,
"moduleResolution": "Bundler",
"noImplicitAny": false,
"outDir": "./dist",
"rootDir": "./src",
"rootDir": ".",
"strict": true,
"noEmit": true,
},

"vueCompilerOptions": {
Expand Down
13 changes: 11 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { defineConfig } from 'vite'

import md5 from 'md5'

import l10nPlugin from './build/l10n-plugin.mts'
import l10nPlugin from './build/l10n-plugin.mjs'

const appVersion = JSON.stringify(process.env.npm_package_version || 'nextcloud-vue')
const versionHash = md5(appVersion).slice(0, 7) as string
Expand Down Expand Up @@ -94,6 +94,15 @@ export default defineConfig((env) => {
const createConfig = createLibConfig(entryPoints, {
// Add our overrides to the config
config: overrides,
// Only create declarations for source files
DTSPluginOptions: {
include: ['src/**/*.ts', 'src/**/*.js', 'src/**/*.vue'],
compilerOptions: {
declaration: true,
rootDir: 'src',
noEmit: false,
},
},
// By default all dependencies are external, but no path imports
nodeExternalsOptions: {
// Packages with paths imports should be added here to mark them as external as well
Expand All @@ -104,7 +113,7 @@ export default defineConfig((env) => {
// For backwards compatibility we include the css within the js files
inlineCSS: true,
// Build CommonJS files for backwards compatibility
libraryFormats: ['es', 'cjs'],
libraryFormats: ['cjs', 'es'],
Comment on lines -107 to +116
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure Typescript definitions are emitted for ESM output (overwrites the CJS)

replace: {
PRODUCTION: JSON.stringify(env.mode === 'production'),
SCOPE_VERSION,
Expand Down
Loading