From 14b320768036cd3f328529ff5749883cf720703a Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Mon, 28 Jun 2021 16:37:02 +0200 Subject: [PATCH] Build: Add a commonjs bundle to dataverse --- .eslintrc.js | 6 ++++- packages/dataverse/.babelrc.js | 1 - packages/dataverse/devEnv/build.ts | 35 +++++++++++++++++++++++++ packages/dataverse/devEnv/tsconfig.json | 3 +++ packages/dataverse/package.json | 18 +++++++++++-- packages/dataverse/tsconfig.json | 2 +- theatre/core/package.json | 2 +- theatre/studio/package.json | 2 +- yarn.lock | 3 +++ 9 files changed, 65 insertions(+), 7 deletions(-) delete mode 100644 packages/dataverse/.babelrc.js create mode 100644 packages/dataverse/devEnv/build.ts create mode 100644 packages/dataverse/devEnv/tsconfig.json diff --git a/.eslintrc.js b/.eslintrc.js index 94ef2c1..8be6f8c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -23,7 +23,11 @@ module.exports = { parser: '@typescript-eslint/parser', plugins: ['@typescript-eslint'], parserOptions: { - project: ['./packages/**/tsconfig.json', './theatre/**/tsconfig.json'], + project: [ + './packages/*/tsconfig.json', + './packages/*/devEnv/tsconfig.json', + './theatre/*/tsconfig.json', + ], }, rules: { '@typescript-eslint/await-thenable': 'warn', diff --git a/packages/dataverse/.babelrc.js b/packages/dataverse/.babelrc.js deleted file mode 100644 index 4ba52ba..0000000 --- a/packages/dataverse/.babelrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = {} diff --git a/packages/dataverse/devEnv/build.ts b/packages/dataverse/devEnv/build.ts new file mode 100644 index 0000000..4348312 --- /dev/null +++ b/packages/dataverse/devEnv/build.ts @@ -0,0 +1,35 @@ +import path from 'path' +import {build} from 'esbuild' + +const definedGlobals = { + global: 'window', +} + +function createBundles(watch: boolean) { + const pathToPackage = path.join(__dirname, '../') + const esbuildConfig: Parameters[0] = { + entryPoints: [path.join(pathToPackage, 'src/index.ts')], + bundle: true, + sourcemap: true, + define: definedGlobals, + watch, + platform: 'neutral', + mainFields: ['browser', 'module', 'main'], + target: ['firefox57', 'chrome58'], + conditions: ['browser', 'node'], + } + + build({ + ...esbuildConfig, + outfile: path.join(pathToPackage, 'dist/index.cjs'), + format: 'cjs', + }) + + build({ + ...esbuildConfig, + outfile: path.join(pathToPackage, 'dist/index.mjs'), + format: 'esm', + }) +} + +createBundles(false) diff --git a/packages/dataverse/devEnv/tsconfig.json b/packages/dataverse/devEnv/tsconfig.json new file mode 100644 index 0000000..077404a --- /dev/null +++ b/packages/dataverse/devEnv/tsconfig.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/packages/dataverse/package.json b/packages/dataverse/package.json index 557168f..ca756b8 100644 --- a/packages/dataverse/package.json +++ b/packages/dataverse/package.json @@ -12,20 +12,34 @@ "url": "https://github.com/AriaMinaei/theatre", "directory": "packages/dataverse" }, - "main": "dist/index.js", + "main": "dist/index.cjs", "types": "dist/index.d.ts", + "module": "dist/index.mjs", + "exports": { + ".": { + "require": "./dist/index.cjs", + "import": "./dist/index.mjs", + "default": "./dist/index.cjs", + "node": "./dist/index.cjs" + } + }, "files": [ "dist/**/*" ], "scripts": { "prepack": "yarn run build", "typecheck": "yarn run build", - "build": "tsc --build ./tsconfig.json" + "build": "run-s build:ts build:js", + "build:ts": "tsc --build ./tsconfig.json", + "build:js": "node -r esbuild-register ./devEnv/build.ts" }, "devDependencies": { "@types/jest": "^26.0.23", "@types/lodash-es": "^4.17.4", "@types/node": "^15.6.2", + "esbuild": "^0.12.5", + "esbuild-register": "^2.5.0", + "npm-run-all": "^4.1.5", "typescript": "^4.3.2" }, "dependencies": { diff --git a/packages/dataverse/tsconfig.json b/packages/dataverse/tsconfig.json index d702371..0927cd1 100644 --- a/packages/dataverse/tsconfig.json +++ b/packages/dataverse/tsconfig.json @@ -5,7 +5,7 @@ "lib": ["ESNext", "DOM"], "rootDir": "src", "types": ["jest", "node"], - "emitDeclarationOnly": false, + "emitDeclarationOnly": true, "target": "es6", "composite": true }, diff --git a/theatre/core/package.json b/theatre/core/package.json index d431956..3e8f08e 100644 --- a/theatre/core/package.json +++ b/theatre/core/package.json @@ -42,4 +42,4 @@ "dependencies": { "@theatre/dataverse": "workspace:*" } -} \ No newline at end of file +} diff --git a/theatre/studio/package.json b/theatre/studio/package.json index d92eb97..2245c81 100644 --- a/theatre/studio/package.json +++ b/theatre/studio/package.json @@ -45,4 +45,4 @@ "peerDependencies": { "@theatre/core": "*" } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index 27dd446..8e92a68 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3760,7 +3760,10 @@ __metadata: "@types/jest": ^26.0.23 "@types/lodash-es": ^4.17.4 "@types/node": ^15.6.2 + esbuild: ^0.12.5 + esbuild-register: ^2.5.0 lodash-es: ^4.17.21 + npm-run-all: ^4.1.5 typescript: ^4.3.2 languageName: unknown linkType: soft