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

Upgrade TypeScript (and related) to 5.0, and start using package.json conditional exports #10

Merged
merged 9 commits into from
Apr 10, 2023
Merged
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/dist/build.js b/dist/build.js
index a669851a62851955a921cc070c4ee34fc7b07e4d..8c864827494011f3ebcbed952bd08bf6c81aa340 100644
index 29144bc5cdb118655229a1f8998c3168170ca257..ba0595bd0a2a9789aac96ba8e7c97b037da34536 100644
--- a/dist/build.js
+++ b/dist/build.js
@@ -20,10 +20,12 @@ function validateTargets(targets) {
Expand All @@ -13,7 +13,7 @@ index a669851a62851955a921cc070c4ee34fc7b07e4d..8c864827494011f3ebcbed952bd08bf6
+ // PATCHED by Splitgraph
+ // NOTE: duplicate extensions are okay as long as targets have different outDir and tsBuildInfoFile
+ // const existedIndex = extMap.get(ext);
+ // if (existedIndex != null && !targets[i].) {
+ // if (existedIndex != null) {
+ // throw new Error(`targets[${i}].extname is already used in targets[${existedIndex}].extname`);
+ // }
extMap.set(ext, i);
Expand Down
53 changes: 32 additions & 21 deletions build-examples-from-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,8 @@

REPO_ROOT="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"

WORKING_EXAMPLE="${1-notadirectory}"
shift

set -e

if [[ ! -d "$WORKING_EXAMPLE" ]] ; then
echo "error: first argument shuld be directory of example you're focusing on"
echo "e.g.: $0 examples/react-nextjs-seafowl"
exit 2
fi

if [[ "$REPO_ROOT" != "$(pwd)" ]] ; then
echo "error: script must be run in root directory"
echo "expected root directory: $REPO_ROOT"
Expand Down Expand Up @@ -71,15 +62,35 @@ VERDACCIO=http://localhost:4873 yarn install
echo "[+] Return to repo root"
cd "$REPO_ROOT"

# Install focused example
echo "[+] FOCUS: $WORKING_EXAMPLE"
cd "$WORKING_EXAMPLE"
if [[ -d ".next" ]] ; then
echo "[+] found .next, delete it"
rm -rf .next
fi
echo "[+] install example"
VERDACCIO=http://localhost:4873 yarn install
# Clean install examples
cd "$REPO_ROOT/examples"
# Get workspace names that are directories (except for the current one),
# and run yarn install in each of them. I'm not sure this is even necessary,
# but it doesn't hurt. And regardless, we do want to perform cleanup steps in
# each directory (e.g. deleting .next) anyway. (REMINDER: This script is a hack)
while read -r workspace_dir ; do
if ! test -d "$workspace_dir" ; then
echo "[+] WARNING: detected workspace that's not a directory: $workspace_dir"
continue
fi

echo "[+] $workspace_dir : start install"
set -x
cd "$workspace_dir"
set +x

if [[ -d ".next" ]] ; then
echo "[+] found .next, delete it"
rm -rf .next
fi
echo "[+] install example from Verdaccio"
VERDACCIO=http://localhost:4873 yarn install

echo "[+] $workspace_dir : done install"
echo "[+] cd back to examples"
cd "$REPO_ROOT/examples"
done < <(cd "$REPO_ROOT/examples" ; yarn workspaces list | awk '{print $3}' | grep -vE '^Done$|^\.$')

echo "[+] return to repo root"
cd "$REPO_ROOT"

Expand All @@ -103,8 +114,8 @@ set -x
ps aux | grep verdaccio
set +x

echo "[+] READY TO GO: $WORKING_EXAMPLE"
echo "[+] You can now cd into the example:"
echo "cd $WORKING_EXAMPLE"
echo "[+] READY TO GO: all examples installed"
echo "[+] You can now cd into a example, e.g.:"
echo "cd examples/react-nextjs-basic-hooks"
echo "[+] NOTE: When you are done, if you want to go back to regular development"
echo " outside of the examples repo, you will probably want to run 'yarn clean'"
15 changes: 6 additions & 9 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,20 @@ cleanup (keeping in mind it will kill any process on machine matching
`verdaccio` in its command line args).

```bash
# This example is for examples/react-nextjs-basic-hooks
# Modify the snippet accordingly depending on which example you're focused on

./build-examples.sh examples/react-nextjs-basic-hooks
./build-examples-from-local.sh
```

**WARNING**: After running this, if you are doing regular development (i.e. not
including examples), you will probably need to run `yarn clean` in the repo root
to make sure everything rebuilds properly (this especially applies to
`@madatdata/react`)

Note: this specific example also removes the `.next` directory in
`examples/react-nextjs-basic-hooks`. Other examples might have similar
directories that need to be deleted - by the nature of having realistic
examples, it can vary wildly and depends on the software being used.
Note: this specific example also removes the `.next` directory (if it exists) in
each workspace. Some examples might have similar directories that need to be
deleted - by the nature of having realistic examples, it can vary wildly and
depends on the software being used, and is currently hardcoded to only`.next`.

See `build-examples.sh` for exactly what is happening.
See `build-examples-from-local.sh` for exactly what is happening.

Note: Each test cycle will change `yarn.lock` (which is why we do `yarn install`
and not `yarn install --immutable` here), as the hash of each local package
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
"devDependencies": {
"@types/node": "18.7.13",
"@vitejs/plugin-react": "2.0.1",
"@vitest/coverage-c8": "0.22.1",
"@vitest/coverage-c8": "0.30.0",
"c8": "7.11.3",
"global-agent": "3.0.0",
"jsdom": "20.0.0",
"msw": "https://github.com/milesforks/msw/blob/released/patched/intercept-node-v18-native-fetch/unreleased-msw-1190f5560178babd232abbb9a96ce8ba4f1abfb1.tgz?raw=true",
"msw": "^1.2.1",
"prettier": "2.7.1",
"rimraf": "3.0.2",
"tsc-multi": "0.6.1",
"typescript": "4.9.5",
"tsc-multi": "1.0.0",
"typescript": "5.0.2",
"undici": "5.10.0",
"verdaccio": "5.13.1",
"vitest": "0.22.1",
"vitest": "0.30.0",
"wireit": "0.7.1"
},
"resolutions": {
"[email protected]": "patch:tsc-multi@npm:0.6.1#.yarn/patches/tsc-multi-npm-0.6.1-6c7411b6ff.patch",
"@madatdata/tiny-react-sandbox/react": "^18"
"@madatdata/tiny-react-sandbox/react": "^18",
"[email protected]": "patch:tsc-multi@npm:1.0.0#.yarn/patches/tsc-multi-npm-1.0.0-509fa4971c.patch"
},
"dependencies": {
"cross-fetch": "3.1.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/ast-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@types/node": "18.7.13"
},
"dependencies": {
"chalk": "5.0.1",
"chalk": "5.2.0",
"esno": "0.16.3",
"pgsql-ast-parser": "10.5.2"
}
Expand Down
2 changes: 2 additions & 0 deletions packages/base-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export { type Host, defaultHost, type Database, defaultDatabase };

export { type CredentialOptions, Credential };

export * from "./host";

export {
type AuthenticatedCredential,
type UnknownCredential,
Expand Down
17 changes: 17 additions & 0 deletions packages/base-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@
"build/*/**",
"package.json"
],
"exports": {
".": {
"dev": "./index.ts",
"require": {
"types": "./build/es2020-commonjs/index.d.ts",
"default": "./build/es2020-commonjs/index.cjs"
},
"import": {
"types": "./build/es2020/index.d.ts",
"default": "./build/es2020/index.mjs"
},
"default": {
"types": "./build/es2020/index.d.ts",
"default": "./build/es2020/index.mjs"
}
}
},
"scripts": {
"version": "yarn version",
"publish": "yarn npm publish"
Expand Down
8 changes: 4 additions & 4 deletions packages/base-db/base-db.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Plugin } from "./plugin-bindings";
import {
WithPluginRegistry,
type WithPluginRegistry,
PluginRegistry,
PluggableInterfaceShape,
PluginList,
ExtractPlugin,
type PluggableInterfaceShape,
type PluginList,
type ExtractPlugin,
} from "./plugin-registry";

import {
Expand Down
17 changes: 17 additions & 0 deletions packages/base-db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
"main": "./build/es2020-commonjs/index.cjs",
"module": "./build/es2020/index.mjs"
},
"exports": {
".": {
"dev": "./index.ts",
"require": {
"types": "./build/es2020-commonjs/index.d.ts",
"default": "./build/es2020-commonjs/index.cjs"
},
"import": {
"types": "./build/es2020/index.d.ts",
"default": "./build/es2020/index.mjs"
},
"default": {
"types": "./build/es2020/index.d.ts",
"default": "./build/es2020/index.mjs"
}
}
},
"files": [
"build/*/**",
"package.json"
Expand Down
4 changes: 2 additions & 2 deletions packages/base-db/plugin-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type {
NotEqual,
} from "@madatdata/test-helpers/type-test-utils";
import {
PluginList,
type PluginList,
PluginRegistry,
WithPluginRegistry,
type WithPluginRegistry,
} from "./plugin-registry";

type SomeKindOfChampionPlugin = {
Expand Down
4 changes: 2 additions & 2 deletions packages/client-http/client-http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { setupMswServerTestHooks } from "@madatdata/test-helpers/msw-server-hook
import { shouldSkipIntegrationTests } from "@madatdata/test-helpers/env-config";
import { rest } from "msw";

import { defaultHost } from "@madatdata/base-client/host";
import { defaultHost } from "@madatdata/base-client";

// NOTE: Previously, the default http-client was hardcoded for Splitgraph, which
// is why all the tests reflect its shape. But we don't want this package to
Expand Down Expand Up @@ -190,7 +190,7 @@ describe("client handles errors correctly because it", () => {

expect(error).toMatchInlineSnapshot(`
{
"name": "NetworkError",
"cause": [NetworkError: Some fake network error from MSW request handler],
"success": false,
"type": "network",
}
Expand Down
10 changes: 5 additions & 5 deletions packages/client-http/client-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
type Database,
type Host,
type UnknownCredential,
UnknownRowShape,
ExecutionResultWithObjectShapedRows,
ExecutionResultWithArrayShapedRows,
UnknownArrayShape,
UnknownObjectShape,
type UnknownRowShape,
type ExecutionResultWithObjectShapedRows,
type ExecutionResultWithArrayShapedRows,
type UnknownArrayShape,
type UnknownObjectShape,
} from "@madatdata/base-client";

export interface WebBridgeResponse<RowShape extends UnknownRowShape> {
Expand Down
17 changes: 17 additions & 0 deletions packages/client-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@
"main": "./build/es2020-commonjs/index.cjs",
"module": "./build/es2020/index.mjs"
},
"exports": {
".": {
"dev": "./index.ts",
"require": {
"types": "./build/es2020-commonjs/index.d.ts",
"default": "./build/es2020-commonjs/index.cjs"
},
"import": {
"types": "./build/es2020/index.d.ts",
"default": "./build/es2020/index.mjs"
},
"default": {
"types": "./build/es2020/index.d.ts",
"default": "./build/es2020/index.mjs"
}
}
},
"files": [
"build/*/**",
"package.json"
Expand Down
22 changes: 0 additions & 22 deletions packages/client-postgres/client-postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,3 @@ export const makeClient = (args: ClientOptions) => {
const client = new SplitgraphPostgresClient(args);
return client;
};

// TEMPORARY: add .values() to typings by copying unreleased bugfix from commit:
// https://github.com/porsager/postgres/commit/ac1bca41004c7923b877c26f2ffc3039b70b4432
declare module "postgres" {
type ValuesRowList<T extends readonly any[]> =
T[number][keyof T[number]][][] &
postgres.ResultQueryMeta<T["length"], keyof T[number]>;

interface PendingValuesQuery<TRow extends readonly postgres.MaybeRow[]>
extends Promise<ValuesRowList<TRow>>,
postgres.PendingQueryModifiers<TRow[number][keyof TRow[number]][][]> {
describe(): postgres.PendingDescribeQuery;
}

interface PendingQuery<TRow extends readonly postgres.MaybeRow[]>
extends Promise<postgres.RowList<TRow>>,
postgres.PendingQueryModifiers<TRow> {
describe(): postgres.PendingDescribeQuery;
values(): PendingValuesQuery<TRow>;
raw(): postgres.PendingRawQuery<TRow>;
}
}
19 changes: 18 additions & 1 deletion packages/client-postgres/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "./build/es2020/index.d.ts",
"devDependencies": {
"@types/node": "18.7.13",
"postgres": "3.2.4"
"postgres": "3.3.4"
},
"dependencies": {
"@madatdata/base-client": "workspace:*"
Expand All @@ -19,6 +19,23 @@
"main": "./build/es2020-commonjs/index.cjs",
"module": "./build/es2020/index.mjs"
},
"exports": {
".": {
"dev": "./index.ts",
"require": {
"types": "./build/es2020-commonjs/index.d.ts",
"default": "./build/es2020-commonjs/index.cjs"
},
"import": {
"types": "./build/es2020/index.d.ts",
"default": "./build/es2020/index.mjs"
},
"default": {
"types": "./build/es2020/index.d.ts",
"default": "./build/es2020/index.mjs"
}
}
},
"files": [
"build/*/**",
"package.json"
Expand Down
17 changes: 17 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@
"main": "./build/es2020-commonjs/index.cjs",
"module": "./build/es2020/index.mjs"
},
"exports": {
".": {
"dev": "./index.ts",
"require": {
"types": "./build/es2020-commonjs/index.d.ts",
"default": "./build/es2020-commonjs/index.cjs"
},
"import": {
"types": "./build/es2020/index.d.ts",
"default": "./build/es2020/index.mjs"
},
"default": {
"types": "./build/es2020/index.d.ts",
"default": "./build/es2020/index.mjs"
}
}
},
"files": [
"build/*/**",
"package.json"
Expand Down
Loading