Skip to content

Commit

Permalink
Back out "Back out "Finally enable es modules.""
Browse files Browse the repository at this point in the history
Original commit changeset: 0b29123
  • Loading branch information
Zemnmez committed Jan 22, 2024
1 parent 0b29123 commit 5538c1d
Show file tree
Hide file tree
Showing 136 changed files with 368 additions and 280 deletions.
4 changes: 2 additions & 2 deletions .swcrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
}
},
"module": {
"type": "commonjs"
"type": "es6"
}
}
}
6 changes: 5 additions & 1 deletion ci/bazel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import child_process from 'node:child_process';
import fs from 'node:fs/promises';

import { Command, FilePositionParams, Summarize } from 'ts/github/actions';
import {
Command,
FilePositionParams,
Summarize,
} from '#root/ts/github/actions/index.js';

/**
* Drink bytes from the Readable, returning each line.
Expand Down
2 changes: 1 addition & 1 deletion ci/bazel_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as bazel from 'ci/bazel';
import * as bazel from '#root/ci/bazel.js';

async function* text(s: string) {
for (const line of s.split('\n')) {
Expand Down
7 changes: 4 additions & 3 deletions ci/presubmit.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import child_process from 'node:child_process';

import { Command } from '@commander-js/extra-typings';
import * as Bazel from 'ci/bazel';
import { Command as WorkflowCommand } from 'ts/github/actions';
import deploy_to_staging from 'ts/pulumi/deploy_to_staging';

import * as Bazel from '#root/ci/bazel.js';
import { Command as WorkflowCommand } from '#root/ts/github/actions/index.js';
import deploy_to_staging from '#root/ts/pulumi/deploy_to_staging.js';

const Task =
(name: string) =>
Expand Down
4 changes: 2 additions & 2 deletions ci/submit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command, Summarize } from 'ts/github/actions';
import * as Stack from 'ts/pulumi/stack';
import { Command, Summarize } from '#root/ts/github/actions/index.js';
import * as Stack from '#root/ts/pulumi/stack.js';

async function main() {
const stack = await Stack.production();
Expand Down
10 changes: 9 additions & 1 deletion js/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# Nothing in here yet!
filegroup (
name = "mandatory_data",
data = [
# needed so that the ESM runtime can locate
# absolute imports.
"//:package_json"
],
visibility = [ "//:__subpackages__" ]
)
5 changes: 3 additions & 2 deletions js/api-extractor/config_gen/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import { Command } from '@commander-js/extra-typings';
import fs from 'fs/promises';
import paths from 'path';
import * as guard from 'ts/guard';

import * as guard from '#root/ts/guard.js';
// you may need to bazel build //ts/schemas/... to get type completion here... sorry!
import { APIExtractorConfiguration } from 'ts/schemas/microsoft/api-extractor/api-extractor';
import { APIExtractorConfiguration } from '#root/ts/schemas/microsoft/api-extractor/api-extractor.js';

new Command()
.name('gen_config')
Expand Down
2 changes: 1 addition & 1 deletion js/api-extractor/testing/import/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './something';
export * from '#root/js/api-extractor/testing/import/something.js';
7 changes: 5 additions & 2 deletions js/jest/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

load("@npm//:jest-cli/package_json.bzl", jest = "bin")

def jest_test(name, srcs = [], data = [], deps = [], jest_config = "//:jest.ts.config.js", **kwargs):
def jest_test(name, srcs = [], env = {}, data = [], deps = [], jest_config = "//:jest.ts.config.js", **kwargs):
"A macro around the autogenerated jest_test rule"
args = [
"--no-cache",
Expand All @@ -21,8 +21,11 @@ def jest_test(name, srcs = [], data = [], deps = [], jest_config = "//:jest.ts.c

jest.jest_test(
name = name,
data = data,
data = data + [ "//js:mandatory_data" ],
args = args,
env = dict({
"NODE_OPTIONS": "--experimental-vm-modules"
}, **env),
**kwargs
)

Expand Down
3 changes: 2 additions & 1 deletion js/npm/package_json/gen_pkgjson.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { JSONSchemaForNPMPackageJsonFiles as packageJson } from '@schemastore/package';
import { Command } from 'commander';
import fs from 'fs/promises';
import { githubIssuesPage } from 'ts/constants/constants';

import { githubIssuesPage } from '#root/ts/constants/constants.js';

const depTypes = {
skip: (v: string) => v === '@bazel/runfiles',
Expand Down
19 changes: 6 additions & 13 deletions js/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ load("@aspect_rules_js//npm:defs.bzl", _npm_link_package = "npm_link_package", _
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", _copy_to_bin = "copy_to_bin")
load("//js/copy_to_local:copy_to_local.bzl", _copy_to_local = "copy_to_local")

def _apply_env_defaults(d):
return d | {"NODE_PATH": "."}
def js_binary(name, data = [], **kwargs):
_js_binary(name = name, data = data + [ "//js:mandatory_data" ], **kwargs)

def js_binary(name, env = {}, **kwargs):
env = _apply_env_defaults(env)
_js_binary(name = name, env = env, **kwargs)

def js_test(name, env = {}, **kwargs):
env = _apply_env_defaults(env)
_js_test(name = name, env = env, **kwargs)
def js_test(name, data = [], **kwargs):
_js_test(name = name, data = data + [ "//js:mandatory_data" ], **kwargs)

def js_library(name, **kwargs):
_js_library(name = name, **kwargs)
Expand All @@ -23,10 +18,8 @@ def copy_to_bin(name, **kwargs):
def pkg_npm(name, **kwargs):
_pkg_npm(name = name, **kwargs)

def js_run_binary(name, env = {}, **kwargs):
env = _apply_env_defaults(env)

_js_run_binary(name = name, env = env, **kwargs)
def js_run_binary(name, srcs = [], **kwargs):
_js_run_binary(name = name, srcs = srcs + [ "//js:mandatory_data" ], **kwargs)

def npm_link_package(name, **kwargs):
_npm_link_package(name = name, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion js/testing/simple_binary_import/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { myString } from 'js/testing/simple_binary_import/lib';
import { myString } from '#root/js/testing/simple_binary_import/lib.js';

console.log(myString);
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,9 @@
"overrides": {
"resolve": "^2.0.0-next.5"
}
},
"type": "module",
"imports": {
"#root/*": "./*"
}
}
7 changes: 4 additions & 3 deletions project/cultist/action.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import immutable from 'immutable';
import * as state from 'project/cultist/state';
import * as cultist from 'project/cultist/types';
import * as iter from 'ts/iter';

import * as state from '#root/project/cultist/state/index.js';
import * as cultist from '#root/project/cultist/types.js';
import * as iter from '#root/ts/iter/index.js';

export enum Kind {
PassTime = 0,
Expand Down
7 changes: 4 additions & 3 deletions project/cultist/action_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import immutable from 'immutable';
import * as action from 'project/cultist/action';
import * as element from 'project/cultist/element';
import * as state from 'project/cultist/state';

import * as action from '#root/project/cultist/action.js';
import * as element from '#root/project/cultist/element.js';
import * as state from '#root/project/cultist/state/index.js';

const cultist = {
state,
Expand Down
2 changes: 1 addition & 1 deletion project/cultist/aspects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Aspects from 'project/cultist/types';
import * as Aspects from '#root/project/cultist/types.js';

function aspectsOf(item: Pick<Aspects.Element, 'id' | 'aspects'>) {
return Object.entries({ ...item.aspects, [item.id]: 1 });
Expand Down
4 changes: 2 additions & 2 deletions project/cultist/element.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as state from 'project/cultist/state';
import * as Iter from 'ts/iter';
import * as state from '#root/project/cultist/state/index.js';
import * as Iter from '#root/ts/iter/index.js';

export function count(id: string, elements: state.State['elementStacks']) {
return Iter.reduce(
Expand Down
2 changes: 1 addition & 1 deletion project/cultist/element_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import immutable from 'immutable';
import * as cultist from 'project/cultist';
import * as cultist from '#root/project/cultist.js';

describe('count', () => {
test('stacks', () => {
Expand Down
2 changes: 1 addition & 1 deletion project/cultist/history.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as cultist from 'project/cultist/types';
import * as cultist from '#root/project/cultist/types.js';

export enum Kind {
PassTime,
Expand Down
20 changes: 10 additions & 10 deletions project/cultist/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export * as action from 'project/cultist/action';
export { Action } from 'project/cultist/action';
export * as aspects from 'project/cultist/aspects';
export * as element from 'project/cultist/element';
export * as recipes from 'project/cultist/recipe';
export * as save from 'project/cultist/save';
export * as slots from 'project/cultist/slots';
export * as state from 'project/cultist/state';
export * from 'project/cultist/types';
export * as verb from 'project/cultist/verb';
export * as action from '#root/project/cultist/action.js';
export { Action } from '#root/project/cultist/action.js';
export * as aspects from '#root/project/cultist/aspects.js';
export * as element from '#root/project/cultist/element.js';
export * as recipes from '#root/project/cultist/recipe.js';
export * as save from '#root/project/cultist/save.js';
export * as slots from '#root/project/cultist/slots.js';
export * as state from '#root/project/cultist/state/index.js';
export * from '#root/project/cultist/types.js';
export * as verb from '#root/project/cultist/verb.js';
3 changes: 2 additions & 1 deletion project/cultist/multiplayer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Home from 'project/cultist/multiplayer/pages';
import React from 'react';
import { createRoot } from 'react-dom/client';

import Home from '#root/project/cultist/multiplayer/pages/index.js';

createRoot(document.querySelector('main')!).render(<Home />);
9 changes: 5 additions & 4 deletions project/cultist/multiplayer/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import exampleSave from 'project/cultist/example/savestate';
import * as Board from 'project/cultist/react/table';
import * as Save from 'project/cultist/save';
import * as State from 'project/cultist/state';
import React from 'react';

import exampleSave from '#root/project/cultist/example/savestate.js';
import * as Board from '#root/project/cultist/react/table.js';
import * as Save from '#root/project/cultist/save.js';
import * as State from '#root/project/cultist/state/index.js';

const Home = (): React.ReactElement => {
const [state, setState] = React.useState(
State.deserialize.state(Save.load(JSON.stringify(exampleSave)))
Expand Down
2 changes: 1 addition & 1 deletion project/cultist/react/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './table';
export * from '#root/project/cultist/react/table.js';
3 changes: 2 additions & 1 deletion project/cultist/react/table.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as State from 'project/cultist/state';
import React from 'react';

import * as State from '#root/project/cultist/state/index.js';
// stubbed out because IDK how to fix style issues right now.
//import style from './table.module.css';

Expand Down
6 changes: 3 additions & 3 deletions project/cultist/recipe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as aspects from 'project/cultist/aspects';
import * as cultist from 'project/cultist/types';
import * as Verb from 'project/cultist/verb';
import * as aspects from '#root/project/cultist/aspects.js';
import * as cultist from '#root/project/cultist/types.js';
import * as Verb from '#root/project/cultist/verb.js';

/**
* Given a set of verbs, recipes and elements, return an iterable subset
Expand Down
4 changes: 2 additions & 2 deletions project/cultist/save_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SaveStateExample from 'project/cultist/example/savestate';
import * as save from 'project/cultist/save';
import SaveStateExample from '#root/project/cultist/example/savestate.js';
import * as save from '#root/project/cultist/save.js';

test('savestate', () => {
const test: save.State = SaveStateExample;
Expand Down
4 changes: 2 additions & 2 deletions project/cultist/slots.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Aspects from 'project/cultist/aspects';
import * as cultist from 'project/cultist/types';
import * as Aspects from '#root/project/cultist/aspects.js';
import * as cultist from '#root/project/cultist/types.js';

export function* of(
i: Iterable<{ slot?: cultist.Slot } | { slots?: cultist.Slot[] }>
Expand Down
13 changes: 7 additions & 6 deletions project/cultist/solve/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as cultist from 'cultist';
import * as fs from 'fs';
import * as dot from 'solve/dot';
import { map } from 'ts/iter';
import { walk } from 'ts/tree';
import { must, perhaps, select } from 'ts/util';

import * as dot from '#root/project/cultist/solve/dot.js';
import { map } from '#root/ts/iter/index.js';
import { walk } from '#root/ts/tree.js';
import { must, perhaps, select } from '#root/ts/util.js';

import { quoteIfNotIdentifier } from './util';

Expand Down Expand Up @@ -55,7 +56,7 @@ export function caption(

export function prettyList(...l: (string | { toString(): string })[]) {
return `(${l.length}): ${l
.map((l, i, a) => `(${i + 1}/${a.length}) ${l?.toString() ?? l}`)
.map((l, i, a) => `(${i + 1}/${a.length}) ${l.toString() ?? l}`)
.sort()
.join(';\n ')}`;
}
Expand All @@ -71,7 +72,7 @@ function stateNodeCaption(
verb: (id: string) => cultist.Verb,
element: (id: string) => cultist.Element
) {
return s?.state ? shortBoardState(s.state, verb, element) : '(empty)';
return s.state ? shortBoardState(s.state, verb, element) : '(empty)';
}

function* SelectLegacy(
Expand Down
9 changes: 5 additions & 4 deletions project/cultist/state/deserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
*/

import Immutable from 'immutable';
import * as Save from 'project/cultist/save';
import * as State from 'project/cultist/state/state';
import * as Iter from 'ts/iter';
import { maybe } from 'ts/util';

import * as Save from '#root/project/cultist/save.js';
import * as State from '#root/project/cultist/state/state.js';
import * as Iter from '#root/ts/iter/index.js';
import { maybe } from '#root/ts/util.js';

function intoMap<I, O>(
v: { [key: string]: I },
Expand Down
8 changes: 4 additions & 4 deletions project/cultist/state/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * as deserialize from 'project/cultist/state/deserialize';
export * from 'project/cultist/state/op';
export * as serialize from 'project/cultist/state/serialize';
export * from 'project/cultist/state/state';
export * as deserialize from '#root/project/cultist/state/deserialize.js';
export * from '#root/project/cultist/state/op.js';
export * as serialize from '#root/project/cultist/state/serialize.js';
export * from '#root/project/cultist/state/state.js';

// taken from a save from the game.

Expand Down
5 changes: 3 additions & 2 deletions project/cultist/state/op.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
*/

import Immutable from 'immutable';
import { v4 as v4uuid } from 'uuid';

import {
ElementInstance,
MutableElementInstance,
NewElementInstance,
} from 'project/cultist/state/state';
import { v4 as v4uuid } from 'uuid';
} from '#root/project/cultist/state/state.js';

const uuid = { v4: v4uuid };

Expand Down
8 changes: 4 additions & 4 deletions project/cultist/state/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @fileoverview like save state, but more sane.
*/

import * as Save from 'project/cultist/save';
import * as State from 'project/cultist/state/state';
import * as Iter from 'ts/iter';
import { maybe } from 'ts/util';
import * as Save from '#root/project/cultist/save.js';
import * as State from '#root/project/cultist/state/state.js';
import * as Iter from '#root/ts/iter/index.js';
import { maybe } from '#root/ts/util.js';

export function elements(
s: State.State['elementStacks'] | State.Situation['situationStoredElements']
Expand Down
8 changes: 4 additions & 4 deletions project/cultist/state/state_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Save from 'project/cultist/save';
import * as deserialize from 'project/cultist/state/deserialize';
import * as serialize from 'project/cultist/state/serialize';
import { maybe } from 'ts/util';
import * as Save from '#root/project/cultist/save.js';
import * as deserialize from '#root/project/cultist/state/deserialize.js';
import * as serialize from '#root/project/cultist/state/serialize.js';
import { maybe } from '#root/ts/util.js';

test('maybe', () => {
expect(maybe(serialize.number)(10)).toEqual('10');
Expand Down
Loading

0 comments on commit 5538c1d

Please sign in to comment.