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

fix(service-worker): fix npm package exports and types (#696) #700

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* @saikumarrs @MoumitaM
* @saikumarrs @MoumitaM @bardisg
/integrations/ @utsabc @ItsSudip @shrouti1507
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ You can start adding integrations of your choice for sending the data through th
RudderStack JS SDK can be used in Chrome Extensions with manifest v3, both as a content script or as a background script
service worker.

For examples and specific details look into [Chrome Extensions Usage](https://github.com/rudderlabs/rudder-sdk-js/blob/master/tests/chrome-extension/USAGE.md)
For examples and specific details look into [Chrome Extensions Usage](https://github.com/rudderlabs/rudder-sdk-js/blob/production/tests/chrome-extension/USAGE.md)

## Contribute

Expand Down
12 changes: 9 additions & 3 deletions dist/rudder-sdk-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
"main": "index.js",
"module": "index.es.js",
"exports": {
".": {
"service-worker": "./service-worker/index.es.js"
".": "./index.js",
"./service-worker": "./service-worker/index.js",
"./service-worker/index.es": "./service-worker/index.es.js"
},
"typesVersions": {
"*": {
".": ["index.d.ts"],
"service-worker": ["service-worker/index.d.ts"],
"service-worker/index.es": ["service-worker/index.d.ts"]
}
},
"types": "index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
5 changes: 4 additions & 1 deletion service-worker/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default Analytics;
export {
Analytics
};

/**
* Represents a generic object in the APIs
Expand All @@ -11,6 +13,7 @@ export interface apiObject {
| boolean
| undefined
| apiObject
| unknown
| (string | number | boolean | apiObject)[];
}

Expand Down
12 changes: 10 additions & 2 deletions tests/chrome-extension/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ You can react to events that are available in background scripts via the [Chrome

Here is an example to track url changes.

Sample background script:
Sample background script imports:

# file copied from node_modules/rudder-sdk-js/service-worker/index.es.js
# In case file is copied from node_modules/rudder-sdk-js/service-worker/index.es.js in extension resources folder
import { Analytics } from "./rudderAnalytics.js";

# In case the package is imported directly as umd and then bundled in the background script
import { Analytics } from "rudder-sdk-js/service-worker";

# In case the package is imported directly as es-module and then bundled in the background script
import { Analytics } from "rudder-sdk-js/service-worker/index.es";

Sample background script:

const rudderClient = new Analytics("<writeKey>","<dataPlaneURL>/v1/batch");

Expand Down