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

Replace "rollup" bundling with TypeScript project references #6492

Merged
merged 49 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
6e88c2d
Adding a "build" script to SDK using TS project references
kraenhansen Feb 13, 2024
29bd876
Removed "realm:bundle" in favour of "realm:build"
kraenhansen Feb 13, 2024
27c977d
Downgrading "module" of shared code to es2015
kraenhansen Feb 15, 2024
89d60b9
Fixing up unit tests
kraenhansen Feb 15, 2024
f7a1e68
Exporting "bare" types from @realm/fetch
kraenhansen Feb 15, 2024
34f67f0
Building only commonjs for now
kraenhansen Feb 15, 2024
a896a42
WIP
kraenhansen Feb 16, 2024
37665ed
No named exports only cjs
kraenhansen Feb 16, 2024
6ed76e1
Moving public types into dist
kraenhansen Feb 16, 2024
abae54d
Marking toFetchArgs as @internal
kraenhansen Feb 16, 2024
a842394
Minor changes to platforms
kraenhansen Feb 16, 2024
3f8591a
Stop generating TS via Cmake
kraenhansen Feb 19, 2024
1e9db90
Seperating "node-wrapper" bindgen into two separate templates reusing…
kraenhansen Feb 19, 2024
e7ae6ea
Injecting binding instead of importing "realm/binding"
kraenhansen Feb 19, 2024
d64d7a5
Adding a script to clean the SDK package
kraenhansen Feb 19, 2024
61f96bd
No need to emit the native.d.ts in the platform directories anymore
kraenhansen Feb 19, 2024
a5ebaeb
Moved patching of binding to a function called after injection
kraenhansen Feb 19, 2024
ceedf35
Fixed relative paths in tsconfig.json
kraenhansen Feb 19, 2024
282ba72
Adding documentation on applyPatch
kraenhansen Feb 19, 2024
297982a
Emitting source-maps
kraenhansen Feb 19, 2024
2e7d5c7
Renaming "build" script to "build:typescript"
kraenhansen Feb 19, 2024
03feb47
Moved deprecated global Realm into its own file
kraenhansen Feb 20, 2024
3190aa3
Refactored namespace API
kraenhansen Feb 20, 2024
bfeb902
Renamed "build" to "build:typescript" across depending packages
kraenhansen Feb 20, 2024
af2f46e
Expose Auth on the namespace
kraenhansen Feb 20, 2024
a29fb4c
Renamed "realm:build:typescript" to "realm:build:ts"
kraenhansen Feb 20, 2024
c03de59
Waypoint
kraenhansen Feb 21, 2024
0f14343
Adding a "check-types" script
kraenhansen Feb 21, 2024
b59d4f5
Adding @internal tags
kraenhansen Feb 21, 2024
f5016c4
Exposing Realm on the Realm namespace to help ease ESM transition
kraenhansen Feb 21, 2024
008f1e0
Adding a comment
kraenhansen Feb 21, 2024
1b69b8f
Removed the tsconfig.base.json
kraenhansen Feb 21, 2024
ee6d53e
Removed an extraneous internal tag
kraenhansen Feb 21, 2024
26f5586
Adding transpilation as a dep of "test"
kraenhansen Feb 21, 2024
a0a6971
Fixed running tests and building from scratch
kraenhansen Feb 21, 2024
769b0a0
Fixed tests (again)
kraenhansen Feb 21, 2024
429c64f
Fixed missing import in @realm/react
kraenhansen Feb 21, 2024
6c84b75
Exporting the namespace deprecated-global.ts
kraenhansen Feb 21, 2024
5574984
Fixed test coverage
kraenhansen Feb 22, 2024
4cd729c
Removed the build:ts:instrumented script again
kraenhansen Feb 22, 2024
0f012aa
Adding binding sourcecode to the dist artifact upload
kraenhansen Feb 22, 2024
7b16a04
Fixing namespace errors
kraenhansen Feb 22, 2024
6309190
Fixed lint error
kraenhansen Feb 22, 2024
09aa48d
Adding a Jest wrapper for the RN entrypoint
kraenhansen Feb 23, 2024
08dc7a7
Attempt at fixing coverage
kraenhansen Feb 23, 2024
d02a472
Incorporating feedback
kraenhansen Feb 23, 2024
dc6a89b
Fixed tsconfigs
kraenhansen Feb 23, 2024
e6818c5
Adding binding files to package files
kraenhansen Feb 23, 2024
5d830f0
Fixed output of bindgen:generate:typescript
kraenhansen Feb 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ coverage/
# Generated artifacts
/packages/realm/bindgen/vendor/bindgen-lib/generated/
/packages/realm/generated/
/packages/realm/binding/generated

# Build artifacts
/packages/realm/dist/
/packages/realm/binding/dist/
/packages/realm/binding/build/
/packages/realm/prebuilds/
/packages/realm/react-native/android/src/main/java/io/realm/react/Version.java
/packages/realm/react-native/android/src/main/jniLibs/
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/environments/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
"test:main": {
"command": "mocha-remote --reporter @realm/mocha-reporter --id main tsx runner.ts main",
"dependencies": [
"../../../packages/realm:bundle",
"../../../packages/realm:build:ts",
"../../../packages/realm:build:node",
"../../../packages/mocha-reporter:bundle"
]
},
"test:renderer": {
"command": "mocha-remote --reporter @realm/mocha-reporter --id renderer tsx runner.ts renderer",
"dependencies": [
"../../../packages/realm:bundle",
"../../../packages/realm:build:ts",
"../../../packages/realm:build:node",
"../../../packages/mocha-reporter:bundle"
]
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/environments/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
"test": {
"command": "mocha-remote --reporter @realm/mocha-reporter tsx index.mjs",
"dependencies": [
"../../../packages/realm:bundle",
"../../../packages/realm:build:ts",
"../../../packages/realm:build:node",
"../../../packages/mocha-reporter:bundle"
]
},
"test:commonjs": {
"command": "mocha-remote --reporter @realm/mocha-reporter tsx index.cjs",
"dependencies": [
"../../../packages/realm:bundle",
"../../../packages/realm:build:ts",
"../../../packages/realm:build:node",
"../../../packages/mocha-reporter:bundle"
]
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/environments/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"command": "npm run common",
"dependencies": [
"../../../packages/realm:build:android",
"../../../packages/realm:bundle",
"../../../packages/realm:build:ts",
"../../../packages/mocha-reporter:bundle"
],
"env": {
Expand All @@ -116,7 +116,7 @@
"command": "npm run common",
"dependencies": [
"pod-install:simulator",
"../../../packages/realm:bundle",
"../../../packages/realm:build:ts",
"../../../packages/mocha-reporter:bundle"
],
"env": {
Expand All @@ -128,7 +128,7 @@
"command": "npm run common",
"dependencies": [
"pod-install:catalyst",
"../../../packages/realm:bundle",
"../../../packages/realm:build:ts",
"../../../packages/mocha-reporter:bundle"
],
"env": {
Expand All @@ -155,7 +155,7 @@
"command": "npm run common",
"dependencies": [
"../../../packages/realm:build:android",
"../../../packages/realm:bundle",
"../../../packages/realm:build:ts",
"../../../packages/mocha-reporter:bundle"
],
"env": {
Expand All @@ -168,7 +168,7 @@
"dependencies": [
"pod-install:simulator",
"../../../packages/realm:build:ios:debug:simulator",
"../../../packages/realm:bundle",
"../../../packages/realm:build:ts",
"../../../packages/mocha-reporter:bundle"
],
"env": {
Expand All @@ -181,7 +181,7 @@
"dependencies": [
"pod-install:catalyst",
"../../../packages/realm:build:ios:debug:catalyst",
"../../../packages/realm:bundle",
"../../../packages/realm:build:ts",
"../../../packages/mocha-reporter:bundle"
],
"env": {
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@
"lint": {
"command": "eslint --ext .js,.ts . && tsc --noEmit",
"dependencies": [
"../../packages/realm:bundle"
"../../packages/realm:build:ts"
]
},
"build": {
"command": "tsc",
"dependencies": [
"../../packages/realm:bundle",
"../../packages/realm:build:ts",
"build-dependencies"
]
},
"start": {
"command": "mocha --watch",
"dependencies": [
"../../packages/realm:bundle",
"../../packages/realm:build:ts",
"build-dependencies"
]
},
"test": {
"command": "mocha --exit",
"dependencies": [
"../../packages/realm:bundle",
"../../packages/realm:build:ts",
"build-dependencies"
]
},
Expand Down
16 changes: 11 additions & 5 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"build": {
"dependencies": [
"bundle",
"./packages/realm:build"
"./packages/realm:build:ts"
]
},
"bundle": {
"dependencies": [
"./packages/realm:bundle",
"./packages/realm:build:ts",
"./packages/babel-plugin:bundle",
"./packages/mocha-reporter:bundle",
"./packages/realm-react:bundle",
Expand Down Expand Up @@ -78,6 +78,7 @@
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-typescript": "^11.1.6",
"@tsconfig/node-lts": "^20.1.1",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"clang-format": "^1.8.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"test": {
"command": "jest",
"dependencies": [
"../realm:bundle"
"../realm:build:ts",
"../realm:bindgen:build:typescript"
]
}
},
Expand Down
4 changes: 2 additions & 2 deletions packages/fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
}
},
"exports": {
"types": "./dist/types/types.d.ts",
"node": {
"import": "./dist/node-esm/node.js",
"require": "./dist/node-cjs/node.js"
},
"react-native": "./dist/react-native/react-native.js",
"browser": "./dist/browser/browser.js",
"types": "./dist/types/types.d.ts"
"browser": "./dist/browser/browser.js"
},
"react-native": "./dist/react-native/react-native.js",
"types": "./dist/types/types.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion packages/fetch/tsconfig.node.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"@tsconfig/node18/tsconfig.json",
],
"files": [
"src/node.ts"
"src/node.ts",
"src/types.ts"
]
}
3 changes: 2 additions & 1 deletion packages/fetch/tsconfig.node.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "./tsconfig.node.base.json",
"compilerOptions": {
"outDir": "./dist/node-cjs",
"module": "CommonJS"
"module": "Node16",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs, it should be node16.

"moduleResolution": "Node16"
},
"references": [
{ "path": "tsconfig.types.json" }
Expand Down
3 changes: 2 additions & 1 deletion packages/fetch/tsconfig.node.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "./tsconfig.node.base.json",
"compilerOptions": {
"outDir": "./dist/node-esm",
"module": "ES2022"
"module": "es2022",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you want to prepare for top-level awaits?

"moduleResolution": "Bundler"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs, it should be bundler

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either is fine, this was suggested by VSCode - it seems this property isn't case-sensitive.

},
"references": [
{ "path": "tsconfig.types.json" }
Expand Down
4 changes: 2 additions & 2 deletions packages/realm-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"bundle": {
"command": "rollup --config && tsc -p tsconfig.types.json",
"dependencies": [
"../realm:bundle",
"../realm:build:ts",
"../realm-common:bundle"
],
"files": [
Expand All @@ -33,7 +33,7 @@
"test": {
"command": "jest --forceExit",
"dependencies": [
"../realm:bundle",
"../realm:build:ts",
"../realm:build:node",
"../realm-common:bundle",
"../realm-app-importer:type-check"
Expand Down
1 change: 1 addition & 0 deletions packages/realm-react/src/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
////////////////////////////////////////////////////////////////////////////

import React, { createContext, useContext, useEffect, useState } from "react";
import Realm from "realm";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be able to only import the type here.

Suggested change
import Realm from "realm";
import type Realm from "realm";


import { useApp } from "./AppProvider";

Expand Down
2 changes: 1 addition & 1 deletion packages/realm-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"build": {
"command": "tsc -p tsconfig.build.json",
"dependencies": [
"../realm:bundle"
"../realm:build:ts"
],
"files": [
"tsconfig.build.json",
Expand Down
3 changes: 3 additions & 0 deletions packages/realm/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ dist/
docs/
bindgen/vendor/realm-core/
src/tests/realms/

# Files transpiled by babel from generated files
binding/generated/*.cjs
30 changes: 1 addition & 29 deletions packages/realm/bindgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,35 +137,7 @@ list(FILTER SDK_TS_FILES EXCLUDE REGEX "templates/[^/]*\.ts$")

set(JS_SPEC_FILE ${SDK_DIR}/bindgen/js_spec.yml)
set(JS_OPT_IN_FILE ${SDK_DIR}/bindgen/js_opt_in_spec.yml)
set(TYPESCRIPT_OUTPUT_DIR ${SDK_DIR}/generated/ts)

set(GENERATED_TS_FILES
${TYPESCRIPT_OUTPUT_DIR}/native.d.mts
${TYPESCRIPT_OUTPUT_DIR}/core.ts
)
bindgen(
TEMPLATE ${SDK_DIR}/bindgen/src/templates/typescript.ts
OUTPUTS ${GENERATED_TS_FILES}
OUTDIR ${TYPESCRIPT_OUTPUT_DIR}
SPECS ${JS_SPEC_FILE}
OPTIN ${JS_OPT_IN_FILE}
SOURCES ${SDK_TS_FILES}
)

set(GENERATED_JS_FILES
${TYPESCRIPT_OUTPUT_DIR}/native-node.mjs
${TYPESCRIPT_OUTPUT_DIR}/native-react-native.mjs
)
bindgen(
TEMPLATE ${SDK_DIR}/bindgen/src/templates/node-wrapper.ts
OUTPUTS ${GENERATED_JS_FILES}
OUTDIR ${TYPESCRIPT_OUTPUT_DIR}
SPECS ${JS_SPEC_FILE}
OPTIN ${JS_OPT_IN_FILE}
SOURCES ${SDK_TS_FILES}
)

add_custom_target(TypeScript ALL DEPENDS ${GENERATED_TS_FILES} ${GENERATED_JS_FILES})
Comment on lines -140 to -168
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest driving this entirely from Wireit, to have a single point of configuration that doesn't diverge.

set(NODE_OUTPUT_DIR ${SDK_DIR}/binding/build)

if(DEFINED CMAKE_JS_VERSION)
include(node.cmake)
Expand Down
4 changes: 2 additions & 2 deletions packages/realm/bindgen/node.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ set_target_properties(realm-js-node PROPERTIES

set_target_properties(realm-js-node PROPERTIES
# Need a dummy generator expression to avoid adding in the config name
LIBRARY_OUTPUT_DIRECTORY "${TYPESCRIPT_OUTPUT_DIR}/$<0:dummy_genex>"
RUNTIME_OUTPUT_DIRECTORY "${TYPESCRIPT_OUTPUT_DIR}/$<0:dummy_genex>"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got renamed since Cmake is no longer generating TypeScript files.

LIBRARY_OUTPUT_DIRECTORY "${NODE_OUTPUT_DIR}/$<0:dummy_genex>"
RUNTIME_OUTPUT_DIRECTORY "${NODE_OUTPUT_DIR}/$<0:dummy_genex>"
)

if(WIN32)
Expand Down
7 changes: 2 additions & 5 deletions packages/realm/bindgen/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"name": "@realm/js-binding",
"name": "@realm/js-bindgen",
Copy link
Member Author

@kraenhansen kraenhansen Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the binding, but the JS specific tool / package used to generate it.

"private": true,
"type": "module",
"workspaces": [
"packages/realm/bindgen/vendor/realm-core/"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was pointing nowhere. I know Mathias wanted to keep it around as an example on how to integrate this in another SDK, but that will probably be the least of their worries 🙂

]
"type": "module"
}
Loading
Loading