Skip to content

Commit

Permalink
Merge branch 'split-build' into main
Browse files Browse the repository at this point in the history
This is a hacky implementation of:

- evanw/esbuild#207
- evanw/esbuild#492

If either of those are implemented, most of this should be obsolete.

For now, we will use this build in CI to enforce an import graph among
the `cubing/*` modules.
  • Loading branch information
lgarron committed Apr 12, 2021
2 parents 09bea32 + 6023a23 commit 0b8c4c0
Show file tree
Hide file tree
Showing 26 changed files with 283 additions and 48 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,21 @@
/coverage
/dist
/node_modules
/alg/index.js
/alg/**/index.js
/bluetooth/index.js
/bluetooth/**/*.js
/kpuzzle/index.js
/kpuzzle/**/*.js
/notation/index.js
/notation/**/*.js
/protocol/index.js
/protocol/**/*.js
/puzzle-geometry/index.js
/puzzle-geometry/**/*.js
/puzzles/index.js
/puzzles/**/*.js
/stream/index.js
/stream/**/*.js
/twisty/index.js
/twisty/**/*.js
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://github.com/lgarron/Makefile-scripts

# Note: the first command becomes the default `make` target.
NPM_COMMANDS = build build-esm build-cjs build-bundle-global build-types build-bin generate-js generate-js-parsers generate-js-svg dev clean test test-jest test-node-require test-node-import format setup lint prepack parcel-build-for-twizzle-net parcel-build-for-vr-cubing-net parcel-build-for-experiments-cubing-net parcel-build-for-twizzle-diaries
NPM_COMMANDS = build build-esm build-cjs build-bundle-global build-types build-bin build-experimental-splitting-build generate-js generate-js-parsers generate-js-svg dev clean test test-jest test-node-require test-node-import format setup lint prepack parcel-build-for-twizzle-net parcel-build-for-vr-cubing-net parcel-build-for-experiments-cubing-net parcel-build-for-twizzle-diaries

.PHONY: $(NPM_COMMANDS)
$(NPM_COMMANDS):
Expand Down
1 change: 1 addition & 0 deletions notation/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "../dist/types/notation";
6 changes: 6 additions & 0 deletions notation/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "notation",
"type": "module",
"main": "./dist/esm/notation/index.js",
"types": "../dist/types/notation/index.d.ts"
}
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@
"build-bundle-global": "npx esbuild --target=es2015 --bundle --format=cjs --minify --outdir=dist/bundle-global src/cubing/cubing.bundle-global.ts",
"build-types": "npx tsc src/cubing/*.ts src/cubing/**/*.ts --declaration --emitDeclarationOnly --outDir dist/types --target es2015 --module es2020 --moduleResolution node --lib esnext,dom --resolveJsonModule --allowJs --allowSyntheticDefaultImports # TODO: unify with tsconfig.json",
"build-bin": "npx esbuild --target=es2015 --bundle --external:three --format=esm --outfile=dist/bin/puzzle-geometry-bin.js src/bin/puzzle-geometry-bin.ts",
"build-experimental-splitting-build": "node src/make/build.js",
"generate-js": "npm run generate-js-parsers && npm run generate-js-svg",
"generate-js-parsers": "npx pegjs src/cubing/alg/parser/parser-pegjs.pegjs && npx pegjs src/cubing/kpuzzle/parser/parser-pegjs.pegjs",
"generate-js-svg": "echo \"TODO: Generating JS for SVGs is not implemented yet.\"",
"dev": "npm run clean && npx parcel serve --no-autoinstall src/demo/index.html --port 3333 --open --dist-dir /tmp/cubing-js-parcel # cleaning is a workaround for one set of Parcel bugs, /tmp dir is a workaround dir for other Parcel bugs",
"clean": "rm -rf dist .cache .parcel-cache .rpt2_cache /tmp/cubing-js-parcel",
"test": "npm run test-jest && npm run lint",
"test": "npm run test-jest && npm run lint && npm run build-experimental-splitting-build",
"test-jest": "npx jest --collectCoverage",
"test-node-require": "node src/dist-test/require.cjs",
"test-node-import": "node src/dist-test/import.mjs",
Expand Down Expand Up @@ -138,7 +139,7 @@
"exports": {
".": {
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"import": "./index.js",
"types": "./types/types/index.d.ts"
},
"./alg": {
Expand All @@ -156,6 +157,11 @@
"import": "./dist/esm/kpuzzle/index.js",
"types": "./dist/types/kpuzzle/index.d.ts"
},
"./notation": {
"require": "./dist/cjs/notation/index.js",
"import": "./dist/esm/notation/index.js",
"types": "./dist/types/notation/index.d.ts"
},
"./protocol": {
"require": "./dist/cjs/protocol/index.js",
"import": "./dist/esm/protocol/index.js",
Expand Down
4 changes: 4 additions & 0 deletions src/cubing/alg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ export { keyToMove } from "./keyboard";
export * from "./units";

export { algCubingNetLink, AlgCubingNetOptions } from "./url";

export { experimentalAppendMove } from "./operation";
export { experimentalIs } from "./is";
export { directedGenerator as experimentalDirectedGenerator, direct as experimentalDirect, IterationDirection as ExperimentalIterationDirection } from "./iteration";
5 changes: 2 additions & 3 deletions src/cubing/bluetooth/smart-puzzle/gocube.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Quaternion } from "three";
import { Alg, Move } from "../../alg";
import { experimentalAppendMove } from "../../alg/operation";
import { BluetoothConfig, BluetoothPuzzle } from "./bluetooth-puzzle";
import { Alg, experimentalAppendMove, Move } from "../../alg";
import { debugLog } from "../debug";
import { BluetoothConfig, BluetoothPuzzle } from "./bluetooth-puzzle";

const UUIDs = {
goCubeService: "6e400001-b5a3-f393-e0a9-e50e24dcca9e",
Expand Down
2 changes: 2 additions & 0 deletions src/cubing/kpuzzle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ export { parseKPuzzleDefinition } from "./parser";
export { KPuzzleSVGWrapper } from "./svg";

export { experimentalIs3x3x3Solved } from "./puzzle-orientation";

export { transformationForQuantumMove as experimentalTransformationForQuantumMove } from "./kpuzzle";
4 changes: 2 additions & 2 deletions src/cubing/kpuzzle/puzzle-orientation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { normalizePuzzleOrientation as normalize3x3x3Orientation } from "../protocol/binary/puzzle-orientation";
import { experimentalNormalizePuzzleOrientation as normalize3x3x3Orientation } from "../protocol";
import { Transformation } from "./definition_types";
import { cube3x3x3KPuzzle as def } from "../puzzles/implementations/3x3x3/3x3x3.kpuzzle.json_";
import { experimentalCube3x3x3KPuzzle as def } from "../puzzles";
import {
areOrbitTransformationsEquivalent,
areTransformationsEquivalent,
Expand Down
2 changes: 1 addition & 1 deletion src/cubing/notation/CountMoves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Newline,
Pause,
TraversalUp,
} from "../alg/index";
} from "../alg";

/*
* For movecount, that understands puzzle rotations. This code
Expand Down
2 changes: 1 addition & 1 deletion src/cubing/protocol/binary/puzzle-orientation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Transformation,
} from "../../kpuzzle";
// TODO: Should we expose this directly in the `puzzles` package for sync uses?
import { cube3x3x3KPuzzle as def } from "../../puzzles/implementations/3x3x3/3x3x3.kpuzzle.json_";
import { experimentalCube3x3x3KPuzzle as def } from "../../puzzles";

export function puzzleOrientationIdx(state: Transformation): [number, number] {
const idxU = state["CENTERS"].permutation[0];
Expand Down
2 changes: 2 additions & 0 deletions src/cubing/protocol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export {
twizzleBinaryToReid3x3x3,
} from "./binary/binary3x3x3";
export { bufferToSpacedHex, spacedHexToBuffer } from "./binary/hex";

export {normalizePuzzleOrientation as experimentalNormalizePuzzleOrientation} from "./binary/puzzle-orientation"
2 changes: 1 addition & 1 deletion src/cubing/puzzles/PuzzleLoader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PuzzleGeometry } from "../puzzle-geometry";
import type { KPuzzleDefinition } from "../kpuzzle";
import { ExperimentalStickering } from "../twisty";
import type { ExperimentalStickering } from "../twisty";
import { PuzzleAppearance } from "./stickerings/appearance";

export interface PuzzleLoader {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// TODO: this would be a raw `.json` file, but Parcel runs into an error from

import { KPuzzleDefinition } from "../../../kpuzzle";
import type { KPuzzleDefinition } from "../../../kpuzzle";

// using that as both a sync and async import. Probably https://github.com/parcel-bundler/parcel/issues/2546
export const cube3x3x3KPuzzle: KPuzzleDefinition = {
Expand Down
2 changes: 1 addition & 1 deletion src/cubing/puzzles/implementations/fto/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExperimentalStickering } from "../../../twisty";
import type { ExperimentalStickering } from "../../../twisty";
import { genericPGPuzzleLoader } from "../../async/async-pg3d";
import { PuzzleAppearance } from "../../stickerings/appearance";
import {
Expand Down
6 changes: 6 additions & 0 deletions src/cubing/puzzles/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

export {cube3x3x3KPuzzle as experimentalCube3x3x3KPuzzle} from "./implementations/3x3x3/3x3x3.kpuzzle.json_";

import { cubePGPuzzleLoader, genericPGPuzzleLoader } from "./async/async-pg3d";
import { cube2x2x2 } from "./implementations/2x2x2";
import { cube3x3x3 } from "./implementations/3x3x3";
Expand Down Expand Up @@ -40,6 +43,9 @@ export const puzzles: Record<string, PuzzleLoader> = {

export { cube2x2x2, cube3x3x3 };

export {getFaceletAppearance as experimentalGetFaceletAppearance} from "./stickerings/appearance"
export type {FaceletMeshAppearance as ExperimentalFaceletMeshAppearance, PuzzleAppearance as ExperimentalPuzzleAppearance} from "./stickerings/appearance"

// // TODO: find a better way to share these defs.
// for (const puzzleName of [
// // "2x2x2",
Expand Down
2 changes: 1 addition & 1 deletion src/cubing/puzzles/stickerings/appearance.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TODO: figure out where to house this permanently.

import { Move } from "../../alg";
import { experimentalIs } from "../../alg/is";
import { experimentalIs } from "../../alg";
import { KPuzzleDefinition, transformationForMove } from "../../kpuzzle";

export type FaceletMeshAppearance =
Expand Down
26 changes: 13 additions & 13 deletions src/cubing/twisty/3D/puzzles/PG3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import {
KPuzzleDefinition,
Transformation,
} from "../../../kpuzzle";
import { transformationForQuantumMove } from "../../../kpuzzle/kpuzzle";
import { experimentalTransformationForQuantumMove } from "../../../kpuzzle";
import { StickerDat, StickerDatSticker } from "../../../puzzle-geometry";
import {
FaceletMeshAppearance,
getFaceletAppearance,
PuzzleAppearance,
} from "../../../puzzles/stickerings/appearance";
ExperimentalFaceletMeshAppearance,
experimentalGetFaceletAppearance,
ExperimentalPuzzleAppearance,
} from "../../../puzzles";
import { AlgCursor } from "../../animation/cursor/AlgCursor";
import { PuzzlePosition } from "../../animation/cursor/CursorTypes";
import { smootherStep } from "../../animation/easing";
Expand Down Expand Up @@ -139,7 +139,7 @@ class StickerDef {
stickerDat: StickerDatSticker,
hintStickers: boolean,
options?: {
appearance?: FaceletMeshAppearance;
appearance?: ExperimentalFaceletMeshAppearance;
},
) {
const sdColor = new Color(stickerDat.color).getHex();
Expand Down Expand Up @@ -209,7 +209,7 @@ class StickerDef {
);
}

public setAppearance(faceletMeshAppearance: FaceletMeshAppearance): void {
public setAppearance(faceletMeshAppearance: ExperimentalFaceletMeshAppearance): void {
switch (faceletMeshAppearance) {
case "regular":
this.origColorAppearance = this.origColor;
Expand Down Expand Up @@ -286,7 +286,7 @@ class AxisInfo {
}

export interface PG3DOptions {
appearance?: PuzzleAppearance;
appearance?: ExperimentalPuzzleAppearance;
}

const PG_SCALE = 0.5;
Expand Down Expand Up @@ -394,9 +394,9 @@ export class PG3D extends Object3D implements Twisty3DPuzzle {
if (!this.stickers[orbit][ori]) {
this.stickers[orbit][ori] = [];
}
const options: { appearance?: FaceletMeshAppearance } = {};
const options: { appearance?: ExperimentalFaceletMeshAppearance } = {};
if (params.appearance) {
options.appearance = getFaceletAppearance(
options.appearance = experimentalGetFaceletAppearance(
params.appearance,
orbit,
ord,
Expand Down Expand Up @@ -454,13 +454,13 @@ export class PG3D extends Object3D implements Twisty3DPuzzle {
return this.controlTargets;
}

experimentalSetAppearance(appearance: PuzzleAppearance): void {
experimentalSetAppearance(appearance: ExperimentalPuzzleAppearance): void {
this.params.appearance = appearance;
for (const orbitName in this.definition.orbits) {
const { numPieces, orientations } = this.definition.orbits[orbitName];
for (let pieceIdx = 0; pieceIdx < numPieces; pieceIdx++) {
for (let faceletIdx = 0; faceletIdx < orientations; faceletIdx++) {
const faceletAppearance = getFaceletAppearance(
const faceletAppearance = experimentalGetFaceletAppearance(
appearance,
orbitName,
pieceIdx,
Expand Down Expand Up @@ -525,7 +525,7 @@ export class PG3D extends Object3D implements Twisty3DPuzzle {
if (move === null) {
throw Error("Bad blockmove " + externalMove.family);
}
const quantumTransformation = transformationForQuantumMove(
const quantumTransformation = experimentalTransformationForQuantumMove(
this.definition,
externalMove.quantum,
);
Expand Down
2 changes: 1 addition & 1 deletion src/cubing/twisty/animation/indexer/SimpleAlgIndexer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Alg, Move, TraversalUp } from "../../../alg";
import { countAnimatedMoves } from "../../../notation/CountAnimatedMoves";
import { countAnimatedMoves } from "../../../notation";
import { PuzzleWrapper, State } from "../../3D/puzzles/KPuzzleWrapper";
import { Duration, Timestamp } from "../cursor/CursorTypes";
import { AlgDuration, defaultDurationForAmount } from "./AlgDuration";
Expand Down
2 changes: 1 addition & 1 deletion src/cubing/twisty/animation/indexer/tree/chunkAlgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TraversalUp,
Unit,
} from "../../../../alg";
import { AlgBuilder } from "../../../../alg/AlgBuilder";
import { AlgBuilder } from "../../../../alg";

const MIN_CHUNKING_THRESHOLD = 16;

Expand Down
10 changes: 5 additions & 5 deletions src/cubing/twisty/animation/indexer/tree/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
Unit,
} from "../../../../alg";
import {
directedGenerator,
IterationDirection,
} from "../../../../alg/iteration";
experimentalDirectedGenerator,
ExperimentalIterationDirection,
} from "../../../../alg";
import { PuzzleWrapper, State } from "../../../3D/puzzles/KPuzzleWrapper";
import { Duration } from "../../cursor/CursorTypes";
import { AlgDuration, defaultDurationForAmount } from "../AlgDuration";
Expand Down Expand Up @@ -250,9 +250,9 @@ export class AlgWalker<P extends PuzzleWrapper> extends TraversalDownUp<
return false;
}
let i = wd.back ? alg.experimentalNumUnits() - 1 : 0;
for (const unit of directedGenerator(
for (const unit of experimentalDirectedGenerator(
alg.units(),
wd.back ? IterationDirection.Backwards : IterationDirection.Forwards,
wd.back ? ExperimentalIterationDirection.Backwards : ExperimentalIterationDirection.Forwards,
)) {
if (
this.traverseUnit(unit, new WalkerDown(wd.apd.children[i], wd.back))
Expand Down
26 changes: 13 additions & 13 deletions src/cubing/twisty/dom/TwistyAlgViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Pause,
TraversalDownUp,
} from "../../alg";
import { direct, IterationDirection } from "../../alg/iteration";
import { experimentalDirect, ExperimentalIterationDirection } from "../../alg";
import { TwistyPlayer } from "../../twisty";
import { TimeRange } from "../animation/cursor/AlgCursor";
import { MillisecondTimestamp } from "../animation/cursor/CursorTypes";
Expand All @@ -21,7 +21,7 @@ import {
class DataDown {
earliestMoveIndex: number;
twistyAlgViewer: ExperimentalTwistyAlgViewer;
direction: IterationDirection;
direction: ExperimentalIterationDirection;
}

class DataUp {
Expand Down Expand Up @@ -65,7 +65,7 @@ class TwistyAlgWrapperElem extends HTMLElementShim {
}

flushQueue(
direction: IterationDirection = IterationDirection.Forwards,
direction: ExperimentalIterationDirection = ExperimentalIterationDirection.Forwards,
): void {
for (const node of maybeReverseList(this.queue, direction)) {
this.append(node);
Expand All @@ -80,21 +80,21 @@ class TwistyAlgWrapperElem extends HTMLElementShim {

customElementsShim.define("twisty-alg-wrapper-elem", TwistyAlgWrapperElem);

function oppositeDirection(direction: IterationDirection): IterationDirection {
return direction === IterationDirection.Forwards
? IterationDirection.Backwards
: IterationDirection.Forwards;
function oppositeDirection(direction: ExperimentalIterationDirection): ExperimentalIterationDirection {
return direction === ExperimentalIterationDirection.Forwards
? ExperimentalIterationDirection.Backwards
: ExperimentalIterationDirection.Forwards;
}

function updateDirectionByAmount(
currentDirection: IterationDirection,
currentDirection: ExperimentalIterationDirection,
amount: number,
): IterationDirection {
): ExperimentalIterationDirection {
return amount < 0 ? oppositeDirection(currentDirection) : currentDirection;
}

function maybeReverseList<T>(l: T[], direction: IterationDirection): T[] {
if (direction === IterationDirection.Forwards) {
function maybeReverseList<T>(l: T[], direction: ExperimentalIterationDirection): T[] {
if (direction === ExperimentalIterationDirection.Forwards) {
return l;
}
// console.log("rev", Array.from(l).reverse());
Expand All @@ -109,7 +109,7 @@ class AlgToDOMTree extends TraversalDownUp<DataDown, DataUp, DataUp> {
let moveCount = 0;
const element = new TwistyAlgWrapperElem("twisty-alg-sequence");
let first = true;
for (const unit of direct(alg.units(), dataDown.direction)) {
for (const unit of experimentalDirect(alg.units(), dataDown.direction)) {
if (!first) {
element.addString(" ");
}
Expand Down Expand Up @@ -289,7 +289,7 @@ export class ExperimentalTwistyAlgViewer extends HTMLElementShim {
this.#domTree = algToDOMTree(alg, {
earliestMoveIndex: 0,
twistyAlgViewer: this,
direction: IterationDirection.Forwards,
direction: ExperimentalIterationDirection.Forwards,
}).element;
this.textContent = "";
this.appendChild(this.#domTree);
Expand Down
2 changes: 1 addition & 1 deletion src/cubing/twisty/dom/TwistyPlayer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Vector3 } from "three";
import { Alg, Move } from "../../alg";
import { experimentalAppendMove } from "../../alg/operation";
import { experimentalAppendMove } from "../../alg";
import { KPuzzleDefinition, Transformation } from "../../kpuzzle";
import type { StickerDat } from "../../puzzle-geometry";
import { puzzles } from "../../puzzles";
Expand Down

0 comments on commit 0b8c4c0

Please sign in to comment.