Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: build types and add suport to ESM entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossantos74 committed Mar 19, 2024
1 parent 301b156 commit 0558eef
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 7 deletions.
18 changes: 17 additions & 1 deletion .esbuild/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@ const config = Object.assign({}, baseConfig, {
});

require('esbuild')
.build(config)
.build({
...config,
platform: 'node', // for CJS
outfile: 'lib/index.js',
})
.catch((error) => {
console.error(error);
process.exit(1);
});

require('esbuild')
.build({
...config,
platform: 'neutral', // for ESM
format: 'esm',
outfile: 'lib/index.esm.js',
})
.catch((error) => {
console.error(error);
process.exit(1);
Expand Down
3 changes: 2 additions & 1 deletion .esbuild/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require('dotenv').config();
const { style } = require('./plugins/style-loader');
const { dependencies } = require('../package.json');

const entries = Object.entries(process.env).filter((key) => key[0].startsWith('SDK_'));
const env = Object.fromEntries(entries);
Expand All @@ -18,7 +19,7 @@ module.exports = {
bundle: true,
target: 'es6',
format: 'esm',
outdir: 'lib',
external: Object.keys(dependencies),
define: {
'process.env': JSON.stringify(env),
},
Expand Down
19 changes: 17 additions & 2 deletions .esbuild/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@ const baseConfig = require('./config');

const config = Object.assign({}, baseConfig, {
watch: true,
outdir: 'dist',
});

require('esbuild')
.build(config)
.build({
...config,
platform: 'node', // for CJS
outfile: 'dist/index.js',
})
.catch((error) => {
console.error(error);
process.exit(1);
});

require('esbuild')
.build({
...config,
platform: 'neutral', // for ESM
format: 'esm',
outfile: 'dist/index.esm.js',
})
.catch((error) => {
console.error(error);
process.exit(1);
Expand Down
4 changes: 4 additions & 0 deletions .remote-config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export namespace remoteConfig {
let apiUrl: string;
let conferenceLayerUrl: string;
}
1 change: 1 addition & 0 deletions .version.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const version: "lab";
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
"version": "0.0.0-development",
"description": "SuperViz SDK",
"main": "./lib/index.js",
"module": "./lib/index.esm.js",
"types": "./lib/index.d.ts",
"files": [
"lib"
],
"scripts": {
"prepare": "husky install",
"build": "node ./.esbuild/build.js",
"postbuild": "./node_modules/typescript/bin/tsc --emitDeclarationOnly --declaration",
"postbuild": "./node_modules/typescript/bin/tsc",
"watch": "concurrently -n code,types \"yarn watch:code\" \"yarn watch:types\"",
"watch:code": "node ./.esbuild/watch.js",
"watch:types": "./node_modules/typescript/bin/tsc --watch --out ./dist/index.d.ts",
"watch:types": "./node_modules/typescript/bin/tsc --watch --outDir ./dist",
"test:unit": "jest",
"test:unit:watch": "jest --watch",
"test:unit:coverage": "jest --coverage",
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"compilerOptions": {
"rootDir": "./src",
"target": "ES2020",
"module": "ES2020",
"outFile": "./lib/index.d.ts",
"outDir": "./lib",
"lib": ["ES2020", "DOM"],
"preserveWatchOutput": true,
"emitDeclarationOnly": true,
Expand Down

0 comments on commit 0558eef

Please sign in to comment.