Skip to content

Commit

Permalink
Needed changes to be able to compile properly after adding '@metrica-…
Browse files Browse the repository at this point in the history
…sports' prefix to the package
  • Loading branch information
FranCarrascosaMS committed Oct 3, 2023
1 parent e1034c2 commit 0e18aa3
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 44 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
"postinstall": "npm run bootstrap",
"bootstrap": "lerna bootstrap --hoist",
"build": "lerna exec --ignore=troika-examples -- rollup -c \\$LERNA_ROOT_PATH/rollup.config.js",
"build-typr": "lerna exec --scope=troika-three-text -- npm run build-typr",
"build-unicode-font-resolver": "lerna exec --scope=troika-three-text -- npm run build-unicode-font-resolver",
"build-woff2otf": "lerna exec --scope=troika-three-text -- npm run build-woff2otf",
"build-typr": "lerna exec --scope=@metrica-sports/troika-three-text -- npm run build-typr",
"build-unicode-font-resolver": "lerna exec --scope=@metrica-sports/troika-three-text -- npm run build-unicode-font-resolver",
"build-woff2otf": "lerna exec --scope=@metrica-sports/troika-three-text -- npm run build-woff2otf",
"build-yoga": "npm run bootstrap && lerna exec --scope=troika-flex-layout -- npm run build-yoga",
"test": "jest",
"build-examples": "lerna exec --scope=troika-examples -- npm run build",
Expand Down
2 changes: 1 addition & 1 deletion packages/troika-2d/src/HitTestContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* whether an Object2DFacade is under the mouse cursor, by passing this as the context
* to its render() method.
*/
const canvas = typeof document === 'undefined' ? new OffscreenCanvas() : document.createElement('canvas')
const canvas = typeof document === 'undefined' ? new OffscreenCanvas(300, 150) : document.createElement('canvas')
const hitTestContext = canvas.getContext('2d')
hitTestContext.save()

Expand Down
2 changes: 1 addition & 1 deletion packages/troika-3d/src/facade/WorldTextureProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function makeWorldTextureProvider(WrappedFacadeClass) {
}
if (newWorldConfig) {
this.worldTexture.dispose()
const canvas = typeof document === 'undefined' ? new OffscreenCanvas() : document.createElement('canvas')
const canvas = typeof document === 'undefined' ? new OffscreenCanvas(300, 150) : document.createElement('canvas')
canvas.width = newWorldConfig.width
canvas.height = newWorldConfig.height
this.worldTexture = new CanvasTexture(canvas)
Expand Down
2 changes: 1 addition & 1 deletion packages/troika-animation/src/Interpolators.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const colorValueToNumber = (function() {

// 2D canvas for evaluating string values
if (!colorCanvas) {
colorCanvas = typeof document === 'undefined' ? new OffscreenCanvas() : document.createElement('canvas')
colorCanvas = typeof document === 'undefined' ? new OffscreenCanvas(300, 150) : document.createElement('canvas')
colorCanvasCtx = colorCanvas.getContext('2d')
}

Expand Down
2 changes: 1 addition & 1 deletion packages/troika-three-text/libs/woff2otf.factory.js

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

2 changes: 1 addition & 1 deletion packages/troika-three-text/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "troika-three-text",
"name": "@metrica-sports/troika-three-text",
"description": "SDF-based text rendering for Three.js",
"version": "1.0.0",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/troika-three-text/src/TextBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function getTextRenderInfo(args, callback) {
const glyphsPerRow = (textureWidth / sdfGlyphSize * 4)
let atlas = atlases[sdfGlyphSize]
if (!atlas) {
const canvas = typeof document === 'undefined' ? new OffscreenCanvas() : document.createElement('canvas')
const canvas = typeof document === 'undefined' ? new OffscreenCanvas(300, 150) : document.createElement('canvas')
canvas.width = textureWidth
canvas.height = sdfGlyphSize * 256 / glyphsPerRow // start tall enough to fit 256 glyphs
atlas = atlases[sdfGlyphSize] = {
Expand Down
62 changes: 27 additions & 35 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import buble from 'rollup-plugin-buble'
import closureCompiler from '@ampproject/rollup-plugin-closure-compiler'
import fs from 'fs'


/*
This is the primary shared Rollup configuration used for building most of Troika's
Expand All @@ -12,40 +11,39 @@ subpackages. To build all packages, make sure you're in the repository root and
*/


const { LERNA_PACKAGE_NAME, LERNA_ROOT_PATH } = process.env
if (!LERNA_PACKAGE_NAME || !LERNA_ROOT_PATH) {
throw new Error("The build must be run by Lerna; please use `npm run build` from the repository root.")
throw new Error(
'The build must be run by Lerna; please use `npm run build` from the repository root.'
)
}



// Names of all the packages
// These will be treated as externals when referenced as cross-package dependencies
const SIBLING_PACKAGES = fs.readdirSync(`${LERNA_ROOT_PATH}/packages`)


// Mapping of external package names to their globals for UMD build
const EXTERNAL_GLOBALS = SIBLING_PACKAGES.reduce((out, sib) => {
out[sib] = sib.replace(/-/g, '_')
return out
},{
react: 'React',
three: 'THREE',
'bidi-js': 'bidi_js',
'webgl-sdf-generator': 'webgl_sdf_generator',
'three/examples/jsm/loaders/GLTFLoader.js': 'THREE.GLTFLoader',
'prop-types': 'PropTypes',
'object-path': 'objectPath'
})
const EXTERNAL_GLOBALS = SIBLING_PACKAGES.reduce(
(out, sib) => {
out[sib] = sib.replace(/-/g, '_')
return out
},
{
react: 'React',
three: 'THREE',
'bidi-js': 'bidi_js',
'webgl-sdf-generator': 'webgl_sdf_generator',
'three/examples/jsm/loaders/GLTFLoader.js': 'THREE.GLTFLoader',
'prop-types': 'PropTypes',
'object-path': 'objectPath',
'@metrica-sports/troika-three-text': 'troika_three_text'
}
)

// Some packages (e.g. those with worker code) we want to transpile in the ESM
// in addition to the UMD:
// TODO make this more fine-grained than the whole package
const TRANSPILE_PACKAGES = [
'troika-worker-utils'
]

const TRANSPILE_PACKAGES = ['troika-worker-utils']

const onwarn = (warning, warn) => {
// Quiet the 'Use of eval is strongly discouraged' warnings from Yoga lib
Expand All @@ -57,7 +55,6 @@ const onwarn = (warning, warn) => {
warn(warning)
}


// Allow an individual package to define custom entry point(s) and output, via a
// json file in its root. If not present, uses a default.
let entries
Expand All @@ -70,22 +67,20 @@ if (fs.existsSync(entriesPath)) {
}
}


const builds = []
for (let entry of Object.keys(entries)) {
const outFilePrefix = entries[entry]
const outFilePrefix = entries[entry].replace('@metrica-sports/', '')
const outputName = EXTERNAL_GLOBALS[LERNA_PACKAGE_NAME] || outFilePrefix
builds.push(
// ES module file
{
input: entry,
output: {
format: 'esm',
file: `dist/${outFilePrefix}.esm.js`
file: `dist/${outFilePrefix}.esm.js`,
},
external: Object.keys(EXTERNAL_GLOBALS),
plugins: [
TRANSPILE_PACKAGES.includes(LERNA_PACKAGE_NAME) ? buble() : null
],
plugins: [TRANSPILE_PACKAGES.includes(LERNA_PACKAGE_NAME) ? buble() : null],
onwarn
},
// UMD file
Expand All @@ -94,13 +89,11 @@ for (let entry of Object.keys(entries)) {
output: {
format: 'umd',
file: `dist/${outFilePrefix}.umd.js`,
name: EXTERNAL_GLOBALS[LERNA_PACKAGE_NAME],
name: outputName,
globals: EXTERNAL_GLOBALS
},
external: Object.keys(EXTERNAL_GLOBALS),
plugins: [
TRANSPILE_PACKAGES.includes(LERNA_PACKAGE_NAME) ? buble() : null
],
plugins: [TRANSPILE_PACKAGES.includes(LERNA_PACKAGE_NAME) ? buble() : null],
onwarn
},
// UMD file, minified
Expand All @@ -109,7 +102,7 @@ for (let entry of Object.keys(entries)) {
output: {
format: 'umd',
file: `dist/${outFilePrefix}.umd.min.js`,
name: EXTERNAL_GLOBALS[LERNA_PACKAGE_NAME],
name: outputName,
globals: EXTERNAL_GLOBALS
},
external: Object.keys(EXTERNAL_GLOBALS),
Expand All @@ -122,5 +115,4 @@ for (let entry of Object.keys(entries)) {
)
}


export default builds

0 comments on commit 0e18aa3

Please sign in to comment.