Skip to content

Commit

Permalink
fix: DTS generation (#51)
Browse files Browse the repository at this point in the history
* fix: DTS generation
* build: fix syntax error for build

---------

Co-authored-by: Richard Herman <[email protected]>
  • Loading branch information
GeekyEggo and GeekyEggo authored Sep 24, 2024
1 parent 1fcc034 commit 9e37a33
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 133 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"ignorePatterns": [
".github/",
"dist/",
"node_modules/"
"node_modules/",
"types/"
],
"parser": "@typescript-eslint/parser",
"plugins": [
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ node_modules/
coverage/

# Build output
dist/
dist/
types/
35 changes: 0 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"files": [
"./dist/*.js",
"./dist/*.d.ts"
"./dist/*.d.ts",
"./types/**/*d.ts"
],
"exports": {
".": {
Expand All @@ -24,8 +25,9 @@
}
},
"scripts": {
"build": "rm -rf ./dist && rollup --config rollup.config.ts --configPlugin typescript",
"watch": "rollup --config rollup.config.ts --configPlugin typescript --watch",
"build": "rm -rf ./dist && rollup --config rollup.config.mjs && npm run types",
"watch": "rollup --config rollup.config.mjs --watch --watch.onEnd=\"npm run types\"",
"types": "rm -rf ./types && mkdir types && cp -r ./dist/types ./",
"lint": "eslint . --ext .ts --max-warnings 0",
"lint:fix": "prettier --config .prettierrc src/**/*.ts --write",
"preversion": "npm run build && npm test && npm run lint",
Expand Down Expand Up @@ -76,7 +78,6 @@
"jest-websocket-mock": "^2.5.0",
"prettier": "^3.0.3",
"rollup": "^4.0.2",
"rollup-plugin-dts": "^6.1.0",
"typescript": "^5.2.2"
},
"dependencies": {
Expand Down
95 changes: 95 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import nodeResolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import { dirname, resolve } from "node:path";
import url from "node:url";

const isWatching = !!process.env.ROLLUP_WATCH;
const external = ["ws", "@elgato/schemas/streamdeck/plugins"];

const output = {
banner: `/**!
* @author Elgato
* @module elgato/streamdeck
* @license MIT
* @copyright Copyright (c) Corsair Memory Inc.
*/`,
sourcemap: isWatching,
sourcemapPathTransform: (relativeSourcePath, sourcemapPath) => {
return url.pathToFileURL(resolve(dirname(sourcemapPath), relativeSourcePath)).href;
}
};

/**
* Generates a wrapped DTS file.
* @param {string} index File path to the index.d.ts file.
* @returns The wrapped DTS file.
*/
function dts(index) {
return `import streamDeck from "${index}";
export * from "${index}";
export default streamDeck;`;
}

/**
* Rollup configuration.
*/
export default [
/**
* Main build.
*/
{
input: "src/plugin/index.ts",
output: {
...output,
file: `dist/index.js`
},
external,
plugins: [
typescript({
tsconfig: "src/plugin/tsconfig.build.json",
mapRoot: isWatching ? "./" : undefined
}),
nodeResolve(),
{
name: "emit-dts",
generateBundle() {
this.emitFile({
fileName: "index.d.ts",
source: dts("../types/plugin"),
type: "asset"
});
}
}
]
},

/**
* Browser build.
*/
{
input: "src/ui/index.ts",
output: {
...output,
file: `dist/browser.js`
},
external,
plugins: [
typescript({
tsconfig: "src/ui/tsconfig.build.json",
mapRoot: isWatching ? "./" : undefined
}),
nodeResolve(),
{
name: "emit-dts",
generateBundle() {
this.emitFile({
fileName: "browser.d.ts",
source: dts("../types/ui"),
type: "asset"
});
}
}
]
}
];
91 changes: 0 additions & 91 deletions rollup.config.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/plugin/tsconfig.json → src/plugin/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationDir": "../../dist/types"
},
"exclude": [
"../../tests",
"../ui/",
Expand Down
11 changes: 11 additions & 0 deletions src/ui/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationDir": "../../dist/types"
},
"exclude": [
"**/__mocks__/",
"**/__tests__/"
]
}
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
},
"include": [
"src/",
"rollup.config.ts",
"tests/"
],
"exclude": [
Expand Down

0 comments on commit 9e37a33

Please sign in to comment.