From f4f33dcd8d5c863c5ab29dad67615b308a724526 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Sat, 7 Aug 2021 23:24:37 +0200 Subject: [PATCH] Still trying to get cra to play nice with theatre --- packages/dataverse-react/devEnv/build.ts | 34 +++++++++++++++----- packages/dataverse-react/src/index.ts | 2 +- packages/dataverse/devEnv/build.ts | 33 ++++++++++++++----- packages/dataverse/src/PointerProxy.ts | 6 ++-- packages/plugin-r3f/devEnv/build.ts | 17 +++++----- theatre/core/package.json | 9 +----- theatre/devEnv/buildUtils.ts | 40 ++++++++++++------------ theatre/studio/package.json | 9 +----- 8 files changed, 88 insertions(+), 62 deletions(-) diff --git a/packages/dataverse-react/devEnv/build.ts b/packages/dataverse-react/devEnv/build.ts index 4348312..599d720 100644 --- a/packages/dataverse-react/devEnv/build.ts +++ b/packages/dataverse-react/devEnv/build.ts @@ -1,5 +1,24 @@ -import path from 'path' +import * as path from 'path' import {build} from 'esbuild' +import type {Plugin} from 'esbuild' + +const externalPlugin = (patterns: RegExp[]): Plugin => { + return { + name: `external`, + + setup(build) { + build.onResolve({filter: /.*/}, (args) => { + const external = patterns.some((p) => { + return p.test(args.path) + }) + + if (external) { + return {path: args.path, external} + } + }) + }, + } +} const definedGlobals = { global: 'window', @@ -17,19 +36,20 @@ function createBundles(watch: boolean) { mainFields: ['browser', 'module', 'main'], target: ['firefox57', 'chrome58'], conditions: ['browser', 'node'], + plugins: [externalPlugin([/^[\@a-zA-Z]+/])], } build({ ...esbuildConfig, - outfile: path.join(pathToPackage, 'dist/index.cjs'), + outfile: path.join(pathToPackage, 'dist/index.js'), format: 'cjs', }) - build({ - ...esbuildConfig, - outfile: path.join(pathToPackage, 'dist/index.mjs'), - format: 'esm', - }) + // build({ + // ...esbuildConfig, + // outfile: path.join(pathToPackage, 'dist/index.mjs'), + // format: 'esm', + // }) } createBundles(false) diff --git a/packages/dataverse-react/src/index.ts b/packages/dataverse-react/src/index.ts index e03e733..d23384f 100644 --- a/packages/dataverse-react/src/index.ts +++ b/packages/dataverse-react/src/index.ts @@ -56,7 +56,7 @@ export function usePrism( return useDerivation(derivation, debugLabel) } -export const useVal: typeof val = (p, debugLabel?: string) => { +export const useVal: typeof val = (p: $IntentionalAny, debugLabel?: string) => { return usePrism(() => val(p), [p], debugLabel) } diff --git a/packages/dataverse/devEnv/build.ts b/packages/dataverse/devEnv/build.ts index 4348312..b647b06 100644 --- a/packages/dataverse/devEnv/build.ts +++ b/packages/dataverse/devEnv/build.ts @@ -1,6 +1,24 @@ -import path from 'path' +import * as path from 'path' import {build} from 'esbuild' +import type {Plugin} from 'esbuild' +const externalPlugin = (patterns: RegExp[]): Plugin => { + return { + name: `external`, + + setup(build) { + build.onResolve({filter: /.*/}, (args) => { + const external = patterns.some((p) => { + return p.test(args.path) + }) + + if (external) { + return {path: args.path, external} + } + }) + }, + } +} const definedGlobals = { global: 'window', } @@ -17,19 +35,20 @@ function createBundles(watch: boolean) { mainFields: ['browser', 'module', 'main'], target: ['firefox57', 'chrome58'], conditions: ['browser', 'node'], + plugins: [externalPlugin([/^[\@a-zA-Z]+/])], } build({ ...esbuildConfig, - outfile: path.join(pathToPackage, 'dist/index.cjs'), + outfile: path.join(pathToPackage, 'dist/index.js'), format: 'cjs', }) - build({ - ...esbuildConfig, - outfile: path.join(pathToPackage, 'dist/index.mjs'), - format: 'esm', - }) + // build({ + // ...esbuildConfig, + // outfile: path.join(pathToPackage, 'dist/index.mjs'), + // format: 'esm', + // }) } createBundles(false) diff --git a/packages/dataverse/src/PointerProxy.ts b/packages/dataverse/src/PointerProxy.ts index d809337..f1c7ee7 100644 --- a/packages/dataverse/src/PointerProxy.ts +++ b/packages/dataverse/src/PointerProxy.ts @@ -1,10 +1,10 @@ import type {IdentityDerivationProvider} from './Atom' -import type {Pointer} from './pointer'; +import type {Pointer} from './pointer' import pointer from './pointer' -import type {IBox} from './Box'; +import type {IBox} from './Box' import Box from './Box' import type {$FixMe, $IntentionalAny} from './types' -import {valueDerivation} from '@theatre/dataverse' +import {valueDerivation} from './Atom' export default class PointerProxy implements IdentityDerivationProvider diff --git a/packages/plugin-r3f/devEnv/build.ts b/packages/plugin-r3f/devEnv/build.ts index 6e58fe8..ac8aa36 100644 --- a/packages/plugin-r3f/devEnv/build.ts +++ b/packages/plugin-r3f/devEnv/build.ts @@ -1,7 +1,7 @@ -import path from 'path' +import * as path from 'path' import {build} from 'esbuild' import type {Plugin} from 'esbuild' -import {writeFileSync} from 'fs' +import {mkdirSync, writeFileSync} from 'fs' const externalPlugin = (patterns: RegExp[]): Plugin => { return { @@ -46,7 +46,6 @@ function createBundles(watch: boolean) { define: {...definedGlobals, 'process.env.NODE_ENV': '"production"'}, outfile: path.join(pathToPackage, 'dist/index.production.js'), format: 'cjs', - treeShaking: true, }) build({ @@ -56,6 +55,8 @@ function createBundles(watch: boolean) { format: 'cjs', }) + mkdirSync(path.join(pathToPackage, 'dist')) + writeFileSync( path.join(pathToPackage, 'dist/index.js'), `module.exports = @@ -65,11 +66,11 @@ function createBundles(watch: boolean) { {encoding: 'utf-8'}, ) - build({ - ...esbuildConfig, - outfile: path.join(pathToPackage, 'dist/index.mjs'), - format: 'esm', - }) + // build({ + // ...esbuildConfig, + // outfile: path.join(pathToPackage, 'dist/index.mjs'), + // format: 'esm', + // }) } createBundles(false) diff --git a/theatre/core/package.json b/theatre/core/package.json index 799ad54..1be3b98 100644 --- a/theatre/core/package.json +++ b/theatre/core/package.json @@ -17,14 +17,7 @@ "types": "dist/index.d.ts", "type": "commonjs", "files": [ - "dist/index.cjs", - "dist/index.cjs.map", - "dist/index.mjs", - "dist/index.mjs.map", - "dist/index.min.js", - "dist/index.min.js.map", - "dist/index.min.js.LEGAL.txt", - "dist/index.d.ts" + "dist/*" ], "scripts": { "prepublish": "node ../../devEnv/ensurePublishing.js" diff --git a/theatre/devEnv/buildUtils.ts b/theatre/devEnv/buildUtils.ts index 39ec16b..f463980 100644 --- a/theatre/devEnv/buildUtils.ts +++ b/theatre/devEnv/buildUtils.ts @@ -31,29 +31,29 @@ export function createBundles(watch: boolean) { build({ ...esbuildConfig, - outfile: path.join(pathToPackage, 'dist/index.cjs'), + outfile: path.join(pathToPackage, 'dist/index.js'), format: 'cjs', }) - build({ - ...esbuildConfig, - outfile: path.join(pathToPackage, 'dist/index.mjs'), - format: 'esm', - }) + // build({ + // ...esbuildConfig, + // outfile: path.join(pathToPackage, 'dist/index.mjs'), + // format: 'esm', + // }) - build({ - ...esbuildConfig, - outfile: path.join(pathToPackage, 'dist/index.min.js'), - format: 'iife', - external: [], - minify: true, - globalName: `Theatre.${which}`, - legalComments: 'external', - platform: 'browser', - define: { - ...definedGlobals, - 'process.env.NODE_ENV': JSON.stringify('production'), - }, - }) + // build({ + // ...esbuildConfig, + // outfile: path.join(pathToPackage, 'dist/index.min.js'), + // format: 'iife', + // external: [], + // minify: true, + // globalName: `Theatre.${which}`, + // legalComments: 'external', + // platform: 'browser', + // define: { + // ...definedGlobals, + // 'process.env.NODE_ENV': JSON.stringify('production'), + // }, + // }) } } diff --git a/theatre/studio/package.json b/theatre/studio/package.json index d9adc5b..4eb7683 100644 --- a/theatre/studio/package.json +++ b/theatre/studio/package.json @@ -16,14 +16,7 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ - "dist/index.cjs", - "dist/index.cjs.map", - "dist/index.mjs", - "dist/index.mjs.map", - "dist/index.min.js", - "dist/index.min.js.map", - "dist/index.min.js.LEGAL.txt", - "dist/index.d.ts" + "dist/*" ], "scripts": { "prepublish": "node ../../devEnv/ensurePublishing.js"