Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for pure ESM builds #31

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .build/replace.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// originally from: https://github.com/vitejs/vite/blob/51e9c83458e30e3ce70abead14e02a7b353322d9/src/node/build/buildPluginReplace.ts

// import type { Plugin, TransformResult } from "rollup";
import MagicString from "magic-string";
import { default as MagicString } from "magic-string";

/**
* @param {(id: string) => boolean} test
Expand Down
12 changes: 7 additions & 5 deletions .scripts/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import { format } from "prettier";
import chalk from "chalk";

export function TemplateCommand({ root }: StarbeamCommandOptions): Command {
const TEMPLATES = {
tsconfig: resolve(root, ".templates", "package", "tsconfig.json"),
};

return program
.createCommand("template")
.description("template a package")
Expand Down Expand Up @@ -49,7 +45,13 @@ function updatePackageJSON(root: string, pkg: Package) {

const json = JSON.parse(readFileSync(editingJSON, "utf-8"));

json.publishConfig = splice.publishConfig;
Object.assign(json, splice);

if (json.main) {
json.exports = {
default: `./${json.main}`,
};
}

writeFileSync(editingJSON, JSON.stringify(json, null, 2));
}
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"vitest.enable": true,
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.preferences.importModuleSpecifier": "project-relative",
"typescript.tsserver.experimental.enableProjectDiagnostics": true,
"typescript.tsserver.experimental.enableProjectDiagnostics": false,
"json.schemas": [
{
"fileMatch": ["manifest.json"],
Expand Down
2 changes: 1 addition & 1 deletion demos/react-query/src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "@shopify/polaris/build/esm/styles.css";

import axios from "axios";
import { default as axios } from "axios";
import { StrictMode } from "react";

import { type QueryResult, QUERY_CACHE } from "../lib/query.js";
Expand Down
2 changes: 1 addition & 1 deletion demos/react-query/src/components/style.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import styled, { keyframes } from "styled-components";
import { default as styled, keyframes } from "styled-components";

export const spinner = keyframes`
0% { transform: rotate(0deg); }
Expand Down
5 changes: 2 additions & 3 deletions demos/react-store/src/lib/people.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Query } from "@starbeamx/store";
import { Filter } from "@starbeamx/store/src/filter.js";
import type { TableRows } from "@starbeamx/store/src/flat.js";
import type { Query, TableRows } from "@starbeamx/store";
import { Filter } from "@starbeamx/store";

export interface Person {
name: string;
Expand Down
16 changes: 16 additions & 0 deletions framework/react/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# @starbeam/react

## 0.5.6

### Patch Changes

- Fix ESM package mistakes
- Updated dependencies
- @starbeam/use-strict-lifecycle@0.5.6
- @starbeam/core@0.5.6
- @starbeam/core-utils@0.5.6
- @starbeam/debug@0.5.6
- @starbeam/js@0.5.6
- @starbeam/modifier@0.5.6
- @starbeam/peer@1.0.6
- @starbeam/timeline@0.5.6
- @starbeam/verify@0.5.6

## 0.5.5

### Patch Changes
Expand Down
7 changes: 5 additions & 2 deletions framework/react/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@starbeam/react",
"type": "module",
"main": "index.ts",
"version": "0.5.5",
"version": "0.5.6",
"dependencies": {
"@starbeam/core": "workspace:^",
"@starbeam/debug": "workspace:^",
Expand Down Expand Up @@ -36,5 +36,8 @@
"default": "./dist/index.cjs"
}
}
},
"exports": {
"default": "./index.ts"
}
}
}
2 changes: 1 addition & 1 deletion framework/react/react/src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { Reactive } from "@starbeam/core";
import {
type Cell,
type CreateResource,
CompositeInternals,
Resource,
Setups,
} from "@starbeam/core";
import { CompositeInternals } from "@starbeam/core/src/storage/composite.js";
import type { Description } from "@starbeam/debug";
import { type DebugListener, callerStack } from "@starbeam/debug";
import {
Expand Down
6 changes: 4 additions & 2 deletions framework/react/react/src/use-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
import type { Description } from "@starbeam/debug";
import { callerStack, descriptionFrom } from "@starbeam/debug";
import { LIFETIME } from "@starbeam/timeline";
import { useLifecycle } from "@starbeam/use-strict-lifecycle";
import { unsafeTrackedElsewhere } from "@starbeam/use-strict-lifecycle/src/react.js";
import {
unsafeTrackedElsewhere,
useLifecycle,
} from "@starbeam/use-strict-lifecycle";
import { useState } from "react";

function createResource<T>(
Expand Down
7 changes: 5 additions & 2 deletions framework/react/react/src/use-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { PolledFormula, Reactive } from "@starbeam/core";
import { isObject } from "@starbeam/core-utils";
import { type Description, descriptionFrom, Message } from "@starbeam/debug";
import { isDebug, LIFETIME, TIMELINE } from "@starbeam/timeline";
import { isRendering, useLifecycle } from "@starbeam/use-strict-lifecycle";
import { unsafeTrackedElsewhere } from "@starbeam/use-strict-lifecycle/src/react.js";
import {
isRendering,
unsafeTrackedElsewhere,
useLifecycle,
} from "@starbeam/use-strict-lifecycle";
import { useState } from "react";

import { ReactiveElement } from "./element.js";
Expand Down
1 change: 1 addition & 0 deletions framework/react/react/tests/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"private": true,
"type": "module",
"name": "@starbeam-tests/react",
"dependencies": {
"@starbeam/react": "workspace:^",
Expand Down
4 changes: 3 additions & 1 deletion framework/react/test-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@starbeam-workspace/react-test-utils",
"private": true,
"type": "module",
"main": "index.ts",
"dependencies": {
"@starbeam-workspace/test-utils": "workspace:^",
Expand All @@ -14,7 +15,8 @@
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"vite": "^3.0.0"
},
"peerDependencies": {
"@starbeam/peer": "workspace:^",
Expand Down
1 change: 1 addition & 0 deletions framework/react/test-utils/src/act.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { act as reactAct } from "@testing-library/react";
export function act<T>(callback: () => T): T {
let value: T;

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
reactAct(() => {
value = callback();
});
Expand Down
6 changes: 6 additions & 0 deletions framework/react/use-strict-lifecycle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @starbeam/use-strict-lifecycle

## 0.5.6

### Patch Changes

- Fix ESM package mistakes

## 0.5.5

### Patch Changes
Expand Down
1 change: 1 addition & 0 deletions framework/react/use-strict-lifecycle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { isRestrictedRead as isRendering } from "./src/react.js";
export {
beginReadonly as maskRendering,
endReadonly as unmaskRendering,
unsafeTrackedElsewhere,
} from "./src/react.js";
export { useLifecycle } from "./src/resource.js";
export {
Expand Down
7 changes: 5 additions & 2 deletions framework/react/use-strict-lifecycle/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@starbeam/use-strict-lifecycle",
"description": "React hook to manage the lifecycle of a component correctly. It handles double-rendering in React 16.8+ strict mode and remounting in React 18+ strict mode. It does not circumvent those strict modes, but rather provides an ergonomic way to satisfy their requirements.",
"version": "0.5.5",
"version": "0.5.6",
"type": "module",
"main": "index.ts",
"scripts": {
Expand Down Expand Up @@ -41,5 +41,8 @@
"default": "./dist/index.cjs"
}
}
},
"exports": {
"default": "./index.ts"
}
}
}
4 changes: 0 additions & 4 deletions framework/react/use-strict-lifecycle/src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ export function unsafeTrackedElsewhere<T>(callback: () => T): T {
}
}

export function endUnsafeTrackedElsewhere(): void {
IS_RESTRICTED = true;
}

export function isRestrictedRead(): boolean {
if (IS_UNRESTRICTED) {
return false;
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"@import-meta-env/unplugin": "^0.1.8",
"@rollup/plugin-sucrase": "^4.0.4",
"@rollup/plugin-typescript": "^8.3.3",
"@swc/core": "^1.2.203",
"@swc/helpers": "^0.4.2",
"@swc/core": "^1.2.213",
"@swc/helpers": "^0.4.3",
"@types/jsdom": "^16.2.14",
"@types/node": "^17.0.40",
"@types/shelljs": "^0.8.11",
Expand Down Expand Up @@ -70,13 +70,13 @@
"shelljs": "^0.8.5",
"typescript": "next",
"unplugin-swc": "^1.3.2",
"vite": "^2.9.9",
"vitest": "^0.14.1",
"vite": "^3.0.0",
"vitest": "^0.18.0",
"watcher": "^1.2.0"
},
"pnpm": {
"overrides": {
"typescript": "latest",
"typescript": "next",
"vite": "^2.9.9",
"vitest": "^0.16.0",
"@vitest/ui": "^0.16.0",
Expand Down
14 changes: 14 additions & 0 deletions packages/bundle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# @starbeam-workspace/bundle

## 0.0.4

### Patch Changes

- Updated dependencies
- @starbeam/react@0.5.6
- @starbeam/core@0.5.6
- @starbeam/core-utils@0.5.6
- @starbeam/debug@0.5.6
- @starbeam/js@0.5.6
- @starbeam/peer@1.0.6
- @starbeam/timeline@0.5.6
- @starbeam/verify@0.5.6

## 0.0.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/bundle/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@starbeam-workspace/bundle",
"private": true,
"version": "0.0.3",
"version": "0.0.4",
"type": "module",
"main": "index.ts",
"types": "index.ts",
Expand Down
8 changes: 8 additions & 0 deletions packages/core-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @starbeam/core-utils

## 0.5.6

### Patch Changes

- Fix ESM package mistakes
- Updated dependencies
- @starbeam/peer@1.0.6

## 0.5.5

### Patch Changes
Expand Down
7 changes: 5 additions & 2 deletions packages/core-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@starbeam/core-utils",
"version": "0.5.5",
"version": "0.5.6",
"type": "module",
"main": "index.ts",
"dependencies": {
Expand All @@ -17,5 +17,8 @@
"default": "./dist/index.cjs"
}
}
},
"exports": {
"default": "./index.ts"
}
}
}
12 changes: 12 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @starbeam/core

## 0.5.6

### Patch Changes

- Fix ESM package mistakes
- Updated dependencies
- @starbeam/core-utils@0.5.6
- @starbeam/debug@0.5.6
- @starbeam/peer@1.0.6
- @starbeam/timeline@0.5.6
- @starbeam/verify@0.5.6

## 0.5.5

### Patch Changes
Expand Down
2 changes: 2 additions & 0 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ export { ResourceFn } from "./src/reactive-core/higher-level/mapped-resource.js"
export { ResourceList } from "./src/reactive-core/higher-level/resource-list.js";
export { Marker } from "./src/reactive-core/marker.js";
export { Renderable } from "./src/reactive-core/render.js";
export { CompositeInternals } from "./src/storage/composite.js";
export { StaticInternals } from "./src/storage/static.js";
export { LIFETIME, Pollable, REACTIVE, TIMELINE } from "@starbeam/timeline";
7 changes: 5 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"name": "@starbeam/core",
"version": "0.5.5",
"version": "0.5.6",
"type": "module",
"main": "index.ts",
"exports": {
"default": "./index.ts"
},
"publishConfig": {
"main": "dist/index.cjs",
"types": "dist/index.d.ts",
Expand All @@ -22,4 +25,4 @@
"@starbeam/core-utils": "workspace:^"
},
"devDependencies": {}
}
}
6 changes: 4 additions & 2 deletions packages/core/src/storage/composite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class CompositeInternalsImpl implements ReactiveProtocol {
static create(
children: InternalChildren,
description: Description
): CompositeInternalsImpl {
): CompositeInternals {
return new CompositeInternalsImpl(children, description);
}

Expand Down Expand Up @@ -61,7 +61,7 @@ export class CompositeInternalsImpl implements ReactiveProtocol {
export function CompositeInternals(
children: InternalChildren | readonly (ReactiveProtocol | undefined | null)[],
description: Description
): CompositeInternalsImpl {
): CompositeInternals {
if (isArray(children)) {
return CompositeInternalsImpl.create(
InternalChildren.from(children.filter(isPresent)),
Expand All @@ -71,3 +71,5 @@ export function CompositeInternals(
return CompositeInternalsImpl.create(children, description);
}
}

export type CompositeInternals = CompositeInternalsImpl;