Skip to content

Generate CommonJS files too#327

Merged
arv merged 8 commits intorocicorp:mainfrom
arv:cjs-again
Mar 24, 2021
Merged

Generate CommonJS files too#327
arv merged 8 commits intorocicorp:mainfrom
arv:cjs-again

Conversation

@arv
Copy link
Contributor

@arv arv commented Mar 23, 2021

We now build

index.js
dev.js
cjs/index.js
cjs/dev.js

This is needed so that Next.js can skip using ES modules which it does
not fully support (no support for import.meta.url). In Next.js you need
to do:

require('replicache/cjs')

Sorry @aboodman, I could not make Next.js work with a bare module
specifier :'(

We now build

index.js
dev.js
cjs/index.js
cjs/dev.js

This is needed so that Next.js can skip using ES modules which it does
not fully support (no support for import.meta.url). In Next.js you need
to do:

```js
require('replicache/cjs')
```

Sorry @aboodman, I could not make Next.js work with a bare module
specifier :'(
@arv arv requested a review from aboodman March 23, 2021 19:18
@vercel
Copy link

vercel bot commented Mar 23, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

replicache-sdk-js – ./

🔍 Inspect: https://vercel.com/rocicorp/replicache-sdk-js/EFHkWW5fsrfaFBoP6qDTCZtu8ajm
✅ Preview: https://replicache-sdk-js-git-fork-arv-cjs-again-rocicorp.vercel.app

lithtml-todo-sample-ui – ./sample/lit-todo

🔍 Inspect: https://vercel.com/rocicorp/lithtml-todo-sample-ui/5mrEVBiDhNJCSFqeuK75pHyovpcg
✅ Preview: https://lithtml-todo-sample-ui-git-fork-arv-cjs-again-rocicorp.vercel.app

replicache-sdk-js-perf – ./dev/bench

🔍 Inspect: https://vercel.com/rocicorp/replicache-sdk-js-perf/EQfH1BCspM5gxrJ3cHaEoR8PcdDS
✅ Preview: https://replicache-sdk-js-perf-git-fork-arv-cjs-again-rocicorp.vercel.app

@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js March 23, 2021 19:18 Inactive
@vercel vercel bot temporarily deployed to Preview – lithtml-todo-sample-ui March 23, 2021 19:18 Inactive
@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js-perf March 23, 2021 19:18 Inactive
Copy link
Contributor

@aboodman aboodman left a comment

Choose a reason for hiding this comment

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

Excited to try this!

@vercel vercel bot temporarily deployed to Preview – lithtml-todo-sample-ui March 23, 2021 22:37 Inactive
@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js March 23, 2021 22:37 Inactive
@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js-perf March 23, 2021 22:37 Inactive
@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js March 23, 2021 23:00 Inactive
@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js-perf March 23, 2021 23:00 Inactive
@vercel vercel bot temporarily deployed to Preview – lithtml-todo-sample-ui March 23, 2021 23:00 Inactive
@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js March 23, 2021 23:09 Inactive
@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js-perf March 23, 2021 23:09 Inactive
node-version: 14.x
- uses: microsoft/playwright-github-action@v1
- run: npm ci
- run: npm run get-repc
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the get-repc from npm install flow since we already include the wasm files in the npm package.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why does github need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

github action runs from the git checkout. Not by installing the npm package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should use npm prepare. That gets called when doing npm install (but not when doing npm install foo) as well as when doing npm publish and npm pack

@aboodman
Copy link
Contributor

aboodman commented Mar 23, 2021 via email

package.json Outdated
"doc": "typedoc src/mod.ts",
"build": "rollup --config rollup.config.js",
"build-dev": "DEV=1 rollup --config rollup.config.js",
"build-all": "rollup --config rollup.config.js && DEV=1 rollup --config rollup.config.js && CJS=1 rollup --config rollup.config.js && CJS=1 DEV=1 rollup --config rollup.config.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

out of curiosity, why do we use rollup instead of letting tsc generate one module type or another?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tsc does not create a single file. It does not copy over the wasm/{debug,release}/replicache_client.js file

@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js March 24, 2021 19:19 Inactive
@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js-perf March 24, 2021 19:19 Inactive
We still include the ESM file in the npm package but we do not tell npm
about it. You can use it bey importing "replicache/out/replicache.mjs"
for now.
@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js March 24, 2021 21:41 Inactive
@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js-perf March 24, 2021 21:41 Inactive
@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js March 24, 2021 22:14 Inactive
@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js-perf March 24, 2021 22:14 Inactive
@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js-perf March 24, 2021 22:17 Inactive
@vercel vercel bot temporarily deployed to Preview – replicache-sdk-js March 24, 2021 22:18 Inactive
@arv arv merged commit ba88bd8 into rocicorp:main Mar 24, 2021
@arv arv deleted the cjs-again branch March 24, 2021 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants