From 150fbf5439a87547fd47ea7bcb9c0d3f37f3386d Mon Sep 17 00:00:00 2001 From: Kevin Hanna Date: Wed, 18 Oct 2023 09:32:28 +0100 Subject: [PATCH] remove build step for npm distribution we can expect anyone installing from npm is using a bundler, so bundling ourselves is redundant and causing build issues intermittently. --- build.js | 41 +++++++++-------------------------------- jest.config.js | 2 +- package.json | 13 +++++++------ tsconfig.build.json | 2 +- 4 files changed, 18 insertions(+), 40 deletions(-) diff --git a/build.js b/build.js index d7d04b39..c806528b 100644 --- a/build.js +++ b/build.js @@ -1,6 +1,6 @@ -import { build } from "esbuild"; -import { replace } from "esbuild-plugin-replace"; -import pkg from "./package.json" assert { type: "json" }; +const { build } = require("esbuild"); +const { replace } = require("esbuild-plugin-replace"); +const pkg = require("./package.json"); function makeCdnFilename() { const major = pkg.version.split(".")[0]; @@ -14,23 +14,16 @@ function makeCdnFilename() { return `v${major}${tag}.js`; } -/** - * we bundle jslib-media because webpack has issues resolving imports from it - * - * we bundle events because webpack tries to `require` it in the bundle which - * causes `Dynamic require of "events" is not supported` when jslib-media imports - * from mediasoup-client - * */ -const external = Object.keys(pkg.dependencies) - .concat(Object.keys(pkg.peerDependencies)) - .filter((dep) => !dep.match(/jslib-media|events/)); - -const sharedConfig = { +// embedded CDN +build({ bundle: true, - external, + entryPoints: ["src/lib/embed/index.ts"], + external: undefined, format: "esm", minify: process.env.NODE_ENV === "production", + outfile: `dist/${makeCdnFilename()}`, platform: "browser", + packages: undefined, plugins: [ replace({ __SDK_VERSION__: pkg.version, @@ -42,20 +35,4 @@ const sharedConfig = { ], target: ["es6"], treeShaking: process.env.NODE_ENV === "production", -}; - -// full package -build({ - ...sharedConfig, - entryPoints: ["src/lib/index.ts"], - outfile: "dist/index.esm.js", -}); - -// embed with dependencies -build({ - ...sharedConfig, - external: undefined, - packages: undefined, - entryPoints: ["src/lib/embed/index.ts"], - outfile: `dist/${makeCdnFilename()}`, }); diff --git a/jest.config.js b/jest.config.js index 4a940d1d..3b6d2a4c 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,4 @@ -export default { +module.exports = { preset: "ts-jest", testEnvironment: "jsdom", testMatch: ["/src/**/__tests__/**/*.[jt]s?(x)", "/src/**/?(*.)+(spec|test).[jt]s?(x)"], diff --git a/package.json b/package.json index feff3436..d4fd4276 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@whereby.com/browser-sdk", - "version": "2.0.0-alpha24", + "version": "2.0.0-alpha25", "description": "Modules for integration Whereby video in web apps", "author": "Whereby AS", "license": "MIT", @@ -10,23 +10,24 @@ }, "browserslist": "> 0.5%, last 2 versions, not dead", "source": "src/index.js", - "module": "dist/index.esm.js", + "main": "./dist/index.js", + "module": "./dist/index.js", + "types": "./dist/index.d.ts", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/index.esm.js" + "import": "./dist/index.js", + "require": "./dist/index.js" } }, - "type": "module", "files": [ "dist/**/*.js", "dist/**/*.d.ts" ], - "types": "dist/index.d.ts", "scripts": { "prebuild": "rimraf dist", "build": "node build.js", - "postbuild": "tsc --emitDeclarationOnly --declaration --project tsconfig.build.json", + "postbuild": "tsc --project tsconfig.build.json", "build:storybook": "build-storybook", "dev": "start-storybook -p 6006", "install:e2e-sample-app": "cd test/sample-app && yarn", diff --git a/tsconfig.build.json b/tsconfig.build.json index d84687be..0518b21d 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "emitDeclarationOnly": true, + "emitDeclarationOnly": false, "noEmit": false, "outDir": "dist", "removeComments": true