Skip to content

Commit

Permalink
chore: Swap to main (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Jan 31, 2024
1 parent 661775d commit 6b0caff
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
1 change: 0 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- master

jobs:
check-package-version:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/library-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
push:
branches:
- master
- main

jobs:
unit:
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

- feat: safer rrweb events and regular full snapshots (#973)
- chore: update rollup (#974)
- chore: re-enable bundle checker now master and branches both use pnpm (#972)
- chore: re-enable bundle checker now main and branches both use pnpm (#972)

## 1.103.0 - 2024-01-26

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ Install Yalc to link a local version of `posthog-js` in another JS project: `npm

Just put a `bump patch/minor/major` label on your PR! Once the PR is merged, a new version with the appropriate version bump will be released, and the dependency will be updated in [posthog/PostHog](https://github.com/posthog/PostHog) – automatically.

If you want to release a new version without a PR (e.g. because you forgot to use the label), check out the `master` branch and run `npm version [major | minor | patch] && git push --tags` - this will trigger the automated release process just like the label.
If you want to release a new version without a PR (e.g. because you forgot to use the label), check out the `main` branch and run `npm version [major | minor | patch] && git push --tags` - this will trigger the automated release process just like the label.

### Prereleases

To release an alpha or beta version, you'll need to use the CLI locally:

1. Make sure you're a collaborator on `posthog-js` in npm ([check here](https://www.npmjs.com/package/posthog-js)).
2. Make sure you're logged into the npm CLI (`npm login`).
3. Check out your work-in-progress branch (do not release an alpha/beta from `master`).
3. Check out your work-in-progress branch (do not release an alpha/beta from `main`).
4. Run the following commands, using the same bump level (major/minor/patch) as your PR:
```bash
npm version [premajor | preminor | prepatch] --preid=beta
Expand Down
40 changes: 20 additions & 20 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ enum InitType {
let init_type: InitType

// TODO: the type of this is very loose. Sometimes it's also PostHogLib itself
let posthog_master: Record<string, PostHog> & {
let posthog_main: Record<string, PostHog> & {
init: (token: string, config: Partial<PostHogConfig>, name: string) => void
}

Expand Down Expand Up @@ -180,7 +180,7 @@ const create_phlib = function (
): PostHog {
let instance: PostHog
const target =
name === PRIMARY_INSTANCE_NAME || !posthog_master ? posthog_master : name ? posthog_master[name] : undefined
name === PRIMARY_INSTANCE_NAME || !posthog_main ? posthog_main : name ? posthog_main[name] : undefined
const callbacksHandled = {
initComplete: false,
syncCode: false,
Expand Down Expand Up @@ -376,10 +376,10 @@ export class PostHog {
}

const instance: PostHog = create_phlib(token, config, name, (instance: PostHog) => {
posthog_master[name] = instance
posthog_main[name] = instance
instance._loaded()
})
posthog_master[name] = instance
posthog_main[name] = instance

return instance
}
Expand Down Expand Up @@ -2116,31 +2116,31 @@ const extend_mp = function () {
// add all the sub posthog instances
_each(instances, function (instance, name) {
if (name !== PRIMARY_INSTANCE_NAME) {
posthog_master[name] = instance
posthog_main[name] = instance
}
})
}

const override_ph_init_func = function () {
// we override the snippets init function to handle the case where a
// user initializes the posthog library after the script loads & runs
posthog_master['init'] = function (token?: string, config?: Partial<PostHogConfig>, name?: string) {
posthog_main['init'] = function (token?: string, config?: Partial<PostHogConfig>, name?: string) {
if (name) {
// initialize a sub library
if (!posthog_master[name]) {
posthog_master[name] = instances[name] = create_phlib(
if (!posthog_main[name]) {
posthog_main[name] = instances[name] = create_phlib(
token || '',
config || {},
name,
(instance: PostHog) => {
posthog_master[name] = instances[name] = instance
posthog_main[name] = instances[name] = instance
instance._loaded()
}
)
}
return posthog_master[name]
return posthog_main[name]
} else {
let instance: PostHog = posthog_master as any as PostHog
let instance: PostHog = posthog_main as any as PostHog

if (instances[PRIMARY_INSTANCE_NAME]) {
// main posthog lib already initialized
Expand All @@ -2154,9 +2154,9 @@ const override_ph_init_func = function () {
instances[PRIMARY_INSTANCE_NAME] = instance
}

;(posthog_master as any) = instance
;(posthog_main as any) = instance
if (init_type === InitType.INIT_SNIPPET) {
assignableWindow[PRIMARY_INSTANCE_NAME] = posthog_master
assignableWindow[PRIMARY_INSTANCE_NAME] = posthog_main
}
extend_mp()
return instance
Expand Down Expand Up @@ -2203,23 +2203,23 @@ export function init_from_snippet(): void {
if (_isUndefined(assignableWindow.posthog)) {
assignableWindow.posthog = []
}
posthog_master = assignableWindow.posthog
posthog_main = assignableWindow.posthog

if (posthog_master['__loaded'] || (posthog_master['config'] && posthog_master['persistence'])) {
if (posthog_main['__loaded'] || (posthog_main['config'] && posthog_main['persistence'])) {
// lib has already been loaded at least once; we don't want to override the global object this time so bomb early
logger.critical('PostHog library has already been downloaded at least once.')
return
}

// Load instances of the PostHog Library
_each(posthog_master['_i'], function (item: [token: string, config: Partial<PostHogConfig>, name: string]) {
_each(posthog_main['_i'], function (item: [token: string, config: Partial<PostHogConfig>, name: string]) {
if (item && _isArray(item)) {
instances[item[2]] = create_phlib(...item)
}
})

override_ph_init_func()
;(posthog_master['init'] as any)()
;(posthog_main['init'] as any)()

// Fire loaded events after updating the window's posthog object
_each(instances, function (instance) {
Expand All @@ -2231,11 +2231,11 @@ export function init_from_snippet(): void {

export function init_as_module(): PostHog {
init_type = InitType.INIT_MODULE
;(posthog_master as any) = new PostHog()
;(posthog_main as any) = new PostHog()

override_ph_init_func()
;(posthog_master['init'] as any)()
;(posthog_main['init'] as any)()
add_dom_loaded_handler()

return posthog_master as any
return posthog_main as any
}

0 comments on commit 6b0caff

Please sign in to comment.