-
Notifications
You must be signed in to change notification settings - Fork 58
Compile node package as CommonJS module #532
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e48e843
Compile node package to CommonJS module
simolus3 fb1d37e
Formatting
simolus3 16babe8
Allow customizing worker loads
simolus3 82b0acb
Format
simolus3 30807bf
Fix checking for commonjs bundling
simolus3 34b2c1a
Fix logger imports
simolus3 4a41222
Format
simolus3 8c14e99
Add changeset
simolus3 abe8ec6
Allow compiling custom workers
simolus3 3d0f3eb
Review feedback
simolus3 d00f255
Merge remote-tracking branch 'origin/main' into node-commonjs
simolus3 3f8b8a6
Use OpenWorker type in test
simolus3 af51d87
OpenWorker -> WorkerOpener
simolus3 5054658
Remove unecessary as any
simolus3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@powersync/node': patch | ||
--- | ||
|
||
Include CommonJS distribution for this package. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const plugin = () => { | ||
return { | ||
name: 'mark-as-commonjs', | ||
resolveImportMeta: (property) => { | ||
if (property == 'isBundlingToCommonJs') { | ||
return 'true'; | ||
} | ||
|
||
return null; | ||
}, | ||
}; | ||
}; | ||
|
||
export default [ | ||
{ | ||
input: 'lib/index.js', | ||
plugins: [plugin()], | ||
output: { | ||
file: 'dist/bundle.cjs', | ||
format: 'cjs', | ||
sourcemap: true | ||
} | ||
}, | ||
{ | ||
input: 'lib/db/DefaultWorker.js', | ||
plugins: [plugin()], | ||
output: { | ||
file: 'dist/DefaultWorker.cjs', | ||
format: 'cjs', | ||
sourcemap: true | ||
} | ||
}, | ||
{ | ||
input: 'lib/worker.js', | ||
plugins: [plugin()], | ||
output: { | ||
file: 'dist/worker.cjs', | ||
format: 'cjs', | ||
sourcemap: true | ||
} | ||
} | ||
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { startPowerSyncWorker } from './SqliteWorker.js'; | ||
|
||
startPowerSyncWorker(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { type Worker } from 'node:worker_threads'; | ||
import { SQLOpenOptions } from '@powersync/common'; | ||
|
||
export type WorkerOpener = (...args: ConstructorParameters<typeof Worker>) => InstanceType<typeof Worker>; | ||
|
||
/** | ||
* The {@link SQLOpenOptions} available across all PowerSync SDKs for JavaScript extended with | ||
* Node.JS-specific options. | ||
*/ | ||
export interface NodeSQLOpenOptions extends SQLOpenOptions { | ||
/** | ||
* The Node.JS SDK will use one worker to run writing queries and additional workers to run reads. | ||
* This option controls how many workers to use for reads. | ||
*/ | ||
readWorkerCount?: number; | ||
/** | ||
* A callback to allow customizing how the Node.JS SDK loads workers. This can be customized to | ||
* use workers at different paths. | ||
* | ||
* @param args The arguments that would otherwise be passed to the {@link Worker} constructor. | ||
* @returns the resolved worker. | ||
*/ | ||
openWorker?: WorkerOpener; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
interface ImportMeta { | ||
isBundlingToCommonJs?: boolean; // This property is set by our rollup configuration | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './db/SqliteWorker.js'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.