Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit d1074f5

Browse files
committed
Revert "Drop @segment/canonical. Also uprade some libs (#213)"
This reverts commit d4d70e3.
1 parent 11856ca commit d1074f5

9 files changed

+54
-97
lines changed

HISTORY.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
# 4.1.5 / 2020-09-20
1010

1111
- Remove `@segment/canonical` in favor of `document.querySelector`
12-
13-
# 4.1.5 / 2020-09-17
14-
1512
- Replace @ndhoule/defaults with merging via ES6 spread syntax
1613

1714
# 4.1.4 / 2020-09-16

karma.conf.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ module.exports = function(config) {
4444
module: "commonjs",
4545
target: "ES5",
4646
allowJs: false,
47-
esModuleInterop: true
4847
},
4948
include: ['test'],
5049
exclude: ['node_modules', 'lib', 'test-e2e/*.ts']

lib/analytics.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ import {
88
SegmentIntegration,
99
PageDefaults
1010
} from './types';
11-
12-
import { pageDefaults } from './pageDefaults';
13-
14-
import cloneDeep from 'lodash.clonedeep';
15-
import pick from 'lodash.pick';
1611
var url = require('component-url');
1712

13+
import cloneDeep from 'lodash.clonedeep'
14+
import pick from 'lodash.pick'
15+
1816
var _analytics = global.analytics;
1917

2018
/*
@@ -45,6 +43,7 @@ var memory = require('./memory');
4543
var nextTick = require('next-tick');
4644
var normalize = require('./normalize');
4745
var on = require('component-event').bind;
46+
var pageDefaults = require('./pageDefaults');
4847
var prevent = require('@segment/prevent-default');
4948
var store = require('./store');
5049
var user = require('./user');

lib/pageDefaults.ts

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
import { PageDefaults } from './types';
22
import includes from 'lodash.includes'
3+
import canonical from '@segment/canonical'
34
import url from 'component-url'
45

6+
/**
7+
* Return a default `options.context.page` object.
8+
*
9+
* https://segment.com/docs/spec/page/#properties
10+
*/
11+
12+
function pageDefaults(): PageDefaults {
13+
return {
14+
path: canonicalPath(),
15+
referrer: document.referrer,
16+
search: location.search,
17+
title: document.title,
18+
url: canonicalUrl(location.search)
19+
};
20+
}
21+
522
/**
623
* Return the canonical path for the page.
724
*/
825

9-
const canonicalPath = (): string => {
10-
const canon = document.querySelector("link[rel='canonical']")
26+
function canonicalPath(): string {
27+
const canon = canonical();
1128
if (!canon) return window.location.pathname;
12-
const href = canon.getAttribute("href")
13-
14-
const parsed = url.parse(href);
29+
const parsed = url.parse(canon);
1530
return parsed.pathname;
1631
}
1732

@@ -20,35 +35,16 @@ const canonicalPath = (): string => {
2035
* and strip the hash.
2136
*/
2237

23-
const canonicalUrl = (search: string): string => {
24-
const canon = document.querySelector("link[rel='canonical']")
25-
if (canon) {
26-
const href = canon.getAttribute("href")
27-
return includes(href, '?') ? href : href + search;
28-
}
29-
38+
function canonicalUrl(search: string): string {
39+
const canon = canonical();
40+
if (canon) return includes(canon, '?') ? canon : canon + search;
3041
const url = window.location.href;
3142
const i = url.indexOf('#');
3243
return i === -1 ? url : url.slice(0, i);
3344
}
3445

35-
/**
36-
* Return a default `options.context.page` object.
37-
*
38-
* https://segment.com/docs/spec/page/#properties
46+
/*
47+
* Exports.
3948
*/
4049

41-
export const pageDefaults = (): PageDefaults => {
42-
const path = canonicalPath()
43-
const { referrer, title } = document
44-
const { search } = location
45-
const url = canonicalUrl(search)
46-
47-
return {
48-
path,
49-
referrer,
50-
search,
51-
title,
52-
url
53-
};
54-
}
50+
module.exports = pageDefaults;

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@segment/analytics.js-core",
33
"author": "Segment <[email protected]>",
4-
"version": "4.1.7",
4+
"version": "4.1.5",
55
"description": "The hassle-free way to integrate analytics into any web application.",
66
"types": "lib/index.d.ts",
77
"keywords": [
@@ -30,6 +30,7 @@
3030
},
3131
"homepage": "https://github.com/segmentio/analytics.js-core#readme",
3232
"dependencies": {
33+
"@segment/canonical": "^1.0.0",
3334
"@segment/cookie": "^1.1.5",
3435
"@segment/is-meta": "^1.0.0",
3536
"@segment/isodate": "^1.0.2",
@@ -71,8 +72,6 @@
7172
"@types/mocha": "^7.0.2",
7273
"@types/node": "^14.0.6",
7374
"@types/node-fetch": "^2.5.7",
74-
"@types/proclaim": "^3.6.1",
75-
"@types/sinon": "^9.0.5",
7675
"@typescript-eslint/eslint-plugin": "^4.1.0",
7776
"@typescript-eslint/parser": "^4.1.0",
7877
"assert": "1.5.0",
@@ -109,7 +108,7 @@
109108
"prettier-eslint-cli": "5.0.0",
110109
"proclaim": "^3.5.1",
111110
"puppeteer": "^5.3.0",
112-
"sinon": "^1.17.7",
111+
"sinon": "^1.7.3",
113112
"snyk": "^1.393.0",
114113
"ts-node": "^8.10.2",
115114
"typescript": "^4.0.2",

test/analytics.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import assignIn from 'lodash.assignin'
2-
import { pageDefaults} from '../build/pageDefaults';
3-
import assert from 'proclaim'
42

53
var Analytics = require('../build').constructor;
64
var Facade = require('segmentio-facade');
75
var analytics = require('../build');
6+
var assert = require('proclaim');
87
var bind = require('component-event').bind;
98
var createIntegration = require('@segment/analytics.js-integration');
109
var type = require('component-type');
10+
var pageDefaults = require('../build/pageDefaults');
1111
var sinon = require('sinon');
1212
var tick = require('next-tick');
1313
var trigger = require('compat-trigger-event');

test/pageDefaults.test.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"module": "commonjs",
55
"target": "ES5",
66
"allowJs": true,
7-
"outDir": "build",
8-
"lib": ["dom"]
7+
"outDir": "build"
98
},
109
"include": ["lib"],
1110
"exclude": ["node_modules", "*.md", "Makefile", "karma.*", "test", "test-e2e"]

yarn.lock

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,10 @@
474474
dependencies:
475475
utf8-encode "1"
476476

477+
"@segment/canonical@^1.0.0":
478+
version "1.0.0"
479+
resolved "https://registry.yarnpkg.com/@segment/canonical/-/canonical-1.0.0.tgz#9adb1a731d29ab975493bf17a4ce4952985c4920"
480+
477481
"@segment/cookie@^1.1.5":
478482
version "1.2.0"
479483
resolved "https://registry.yarnpkg.com/@segment/cookie/-/cookie-1.2.0.tgz#17ee237c90dbf2c03643b06c53ccb49cbd7d9980"
@@ -1029,11 +1033,14 @@
10291033
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
10301034
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==
10311035

1036+
<<<<<<< HEAD
10321037
"@types/proclaim@^3.6.1":
10331038
version "3.6.2"
10341039
resolved "https://registry.yarnpkg.com/@types/proclaim/-/proclaim-3.6.2.tgz#8d3ba03f5cf370d518c719bd0223203f10e97998"
10351040
integrity sha512-A3yo/rvft8rQjxjmXsWAY2b/AWcV2GK5Lc03Iis9niiZV7HnFqys8ngy7mDAoUk9XCW1n4tnHRUFIFQuAFb77A==
10361041

1042+
=======
1043+
>>>>>>> parent of d4d70e3... Drop @segment/canonical. Also uprade some libs (#213)
10371044
"@types/qs@*":
10381045
version "6.9.6"
10391046
resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.6.tgz#df9c3c8b31a247ec315e6996566be3171df4b3b1"
@@ -1074,6 +1081,7 @@
10741081
"@types/mime" "^1"
10751082
"@types/node" "*"
10761083

1084+
<<<<<<< HEAD
10771085
"@types/sinon@^9.0.5":
10781086
version "9.0.11"
10791087
resolved "https://registry.yarnpkg.com/@types/sinon/-/sinon-9.0.11.tgz#7af202dda5253a847b511c929d8b6dda170562eb"
@@ -1086,6 +1094,8 @@
10861094
resolved "https://registry.yarnpkg.com/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-6.0.2.tgz#3a84cf5ec3249439015e14049bd3161419bf9eae"
10871095
integrity sha512-dIPoZ3g5gcx9zZEszaxLSVTvMReD3xxyyDnQUjA6IYDG9Ba2AV0otMPs+77sG9ojB4Qr2N2Vk5RnKeuA0X/0bg==
10881096

1097+
=======
1098+
>>>>>>> parent of d4d70e3... Drop @segment/canonical. Also uprade some libs (#213)
10891099
"@types/sizzle@*":
10901100
version "2.3.2"
10911101
resolved "https://registry.yarnpkg.com/@types/sizzle/-/sizzle-2.3.2.tgz#a811b8c18e2babab7d542b3365887ae2e4d9de47"
@@ -4367,7 +4377,6 @@ form-data@~2.3.2:
43674377
43684378
version "1.1.1"
43694379
resolved "https://registry.yarnpkg.com/formatio/-/formatio-1.1.1.tgz#5ed3ccd636551097383465d996199100e86161e9"
4370-
integrity sha1-XtPM1jZVEJc4NGXZlhmRAOhhYek=
43714380
dependencies:
43724381
samsam "~1.1"
43734382

@@ -6692,7 +6701,6 @@ loglevel@^1.4.1, loglevel@^1.6.0:
66926701
66936702
version "1.3.2"
66946703
resolved "https://registry.yarnpkg.com/lolex/-/lolex-1.3.2.tgz#7c3da62ffcb30f0f5a80a2566ca24e45d8a01f31"
6695-
integrity sha1-fD2mL/yzDw9agKJWbKJORdigHzE=
66966704

66976705
longest@^1.0.1:
66986706
version "1.0.1"
@@ -8759,12 +8767,10 @@ safe-regex@^1.1.0:
87598767
87608768
version "1.1.2"
87618769
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.1.2.tgz#bec11fdc83a9fda063401210e40176c3024d1567"
8762-
integrity sha1-vsEf3IOp/aBjQBIQ5AF2wwJNFWc=
87638770

87648771
samsam@~1.1:
87658772
version "1.1.3"
87668773
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.1.3.tgz#9f5087419b4d091f232571e7fa52e90b0f552621"
8767-
integrity sha1-n1CHQZtNCR8jJXHn+lLpCw9VJiE=
87688774

87698775
sauce-connect-launcher@^1.2.2:
87708776
version "1.3.2"
@@ -8994,10 +9000,9 @@ simple-concat@^1.0.0:
89949000
resolved "https://registry.yarnpkg.com/simple-concat/-/simple-concat-1.0.1.tgz#f46976082ba35c2263f1c8ab5edfe26c41c9552f"
89959001
integrity sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==
89969002

8997-
sinon@^1.17.7:
9003+
sinon@^1.7.3:
89989004
version "1.17.7"
89999005
resolved "https://registry.yarnpkg.com/sinon/-/sinon-1.17.7.tgz#4542a4f49ba0c45c05eb2e9dd9d203e2b8efe0bf"
9000-
integrity sha1-RUKk9JugxFwF6y6d2dID4rjv4L8=
90019006
dependencies:
90029007
formatio "1.1.1"
90039008
lolex "1.3.2"
@@ -10531,7 +10536,13 @@ [email protected]:
1053110536
dependencies:
1053210537
inherits "2.0.1"
1053310538

10534-
"util@>=0.10.3 <1", util@^0.12.1:
10539+
"util@>=0.10.3 <1":
10540+
version "0.11.0"
10541+
resolved "https://registry.yarnpkg.com/util/-/util-0.11.0.tgz#c5f391beb244103d799b21077a926fef8769e1fb"
10542+
dependencies:
10543+
inherits "2.0.3"
10544+
10545+
util@^0.12.1:
1053510546
version "0.12.3"
1053610547
resolved "https://registry.yarnpkg.com/util/-/util-0.12.3.tgz#971bb0292d2cc0c892dab7c6a5d37c2bec707888"
1053710548
integrity sha512-I8XkoQwE+fPQEhy9v012V+TSdH2kp9ts29i20TaaDUXsg7x/onePbhFJUExBfv/2ay1ZOp/Vsm3nDlmnFGSAog==

0 commit comments

Comments
 (0)