Skip to content

Commit

Permalink
fix(service-worker): fix npm package exports and types (#696)
Browse files Browse the repository at this point in the history
* fix(service-worker): fix npm package exports and types

* chore: add more code  owner users

* chore: update service worker docs
  • Loading branch information
bardisg authored Oct 21, 2022
1 parent 4ca3584 commit 1883367
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
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

0 comments on commit 1883367

Please sign in to comment.