Skip to content

Conversation

simolus3
Copy link
Contributor

@simolus3 simolus3 commented Mar 13, 2025

In the @powersync/node package, this adds rollup to bundle the ESM modules emitted by tsc modules into a CommonJS module. Two places in the package are using import.meta.url which I had to replace since the CJS bundle is at a different path. We use a custom entry in import.meta (also set by rollup) to detect when the package has been compiled to a CJS module.
As a fallback (e.g. when users are applying their own bundler that might not set the import.meta entry), I've also added options to customize how the worker is loaded.

I've used this file to test this:

// demos/example-node/src/test.cjs
const { PowerSyncDatabase, Schema, Table, column } = require('@powersync/node');

const lists = new Table({
    created_at: column.text,
    name: column.text,
    owner_id: column.text
  });

const main = async () => {
  const db = new PowerSyncDatabase({
    schema: new Schema({lists}),
    database: {
      dbFilename: 'test.db'
    }
  });

  console.log(await db.get('SELECT powersync_rs_version();'));
  await db.close();
};

main();

@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2025

🦋 Changeset detected

Latest commit: 5054658

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@powersync/node Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@simolus3 simolus3 marked this pull request as ready for review March 17, 2025 10:27
@simolus3 simolus3 requested a review from stevensJourney March 17, 2025 10:27
stevensJourney
stevensJourney previously approved these changes Mar 18, 2025
Copy link
Collaborator

@stevensJourney stevensJourney left a comment

Choose a reason for hiding this comment

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

Happy with these changes :)

@simolus3 simolus3 merged commit 53335c7 into main Mar 19, 2025
6 checks passed
@simolus3 simolus3 deleted the node-commonjs branch March 19, 2025 19:49
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