Skip to content

Commit a034d6f

Browse files
authored
Add version number to meta tag (#52)
1 parent 81abc90 commit a034d6f

File tree

9 files changed

+68
-23
lines changed

9 files changed

+68
-23
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Added version number to `<meta name="react-scroll-to-bottom:version">` for diagnostic purpose, in PR [#51](https://github.com/compulim/react-scroll-to-bottom/pull/51)
12+
913
### Changed
1014

11-
- Bump dependencies, in PR [#XXX](https://github.com/compulim/react-scroll-to-bottom/pull/XXX)
15+
- Bump dependencies, in PR [#50](https://github.com/compulim/react-scroll-to-bottom/pull/50)
1216
- [`@babel/cli@7.10.3`](https://www.npmjs.com/package/@babel/cli)
1317
- [`@babel/core@7.10.3`](https://www.npmjs.com/package/@babel/core)
1418
- [`@babel/plugin-proposal-object-rest-spread@7.10.3`](https://www.npmjs.com/package/@babel/plugin-proposal-object-rest-spread)

packages/component/babel.config.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
{
22
"plugins": [
3-
"@babel/plugin-proposal-object-rest-spread"
3+
"@babel/plugin-proposal-object-rest-spread",
4+
[
5+
"babel-plugin-transform-inline-environment-variables",
6+
{
7+
"include": [
8+
"npm_package_version"
9+
]
10+
}
11+
]
412
],
513
"presets": [
614
[

packages/component/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/component/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@babel/plugin-proposal-object-rest-spread": "^7.10.3",
4545
"@babel/preset-env": "^7.10.3",
4646
"@babel/preset-react": "^7.10.1",
47+
"babel-plugin-transform-inline-environment-variables": "^0.4.3",
4748
"eslint": "^7.3.0",
4849
"eslint-plugin-prettier": "^3.1.4",
4950
"eslint-plugin-react": "^7.20.0",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* global global:readonly, process:readonly */
2+
/* eslint no-empty: ["error", { "allowEmptyCatch": true }] */
3+
4+
function setMetaTag(name, content) {
5+
try {
6+
const { document } = global;
7+
8+
if (typeof document !== 'undefined' && document.createElement && document.head && document.head.appendChild) {
9+
const meta = document.querySelector(`html meta[name="${encodeURI(name)}"]`) || document.createElement('meta');
10+
11+
meta.setAttribute('name', name);
12+
meta.setAttribute('content', content);
13+
14+
document.head.appendChild(meta);
15+
}
16+
} catch (err) {}
17+
}
18+
19+
export default function addVersionToMetaTag() {
20+
setMetaTag('react-scroll-to-bottom:version', process.env.npm_package_version);
21+
}

packages/component/src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import addVersionToMetaTag from './addVersionToMetaTag';
2+
13
import AutoHideFollowButton from './ScrollToBottom/AutoHideFollowButton';
24
import BasicScrollToBottom from './BasicScrollToBottom';
35
import Composer from './ScrollToBottom/Composer';
@@ -39,3 +41,5 @@ export {
3941
useScrollToTop,
4042
useSticky
4143
};
44+
45+
addVersionToMetaTag();

packages/playground/.prettierrc.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
arrowParens: avoid
2+
bracketSpacing: true
3+
endOfLine: auto
4+
jsxBracketSameLine: false
5+
printWidth: 120
6+
proseWrap: preserve
7+
quoteProps: as-needed
8+
semi: true
9+
singleQuote: true
10+
tabWidth: 2
11+
trailingComma: none

packages/playground/src/App.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ const ROOT_CSS = css({
3434
'& > *:not(:last-child)': {
3535
marginRight: 10
3636
}
37+
},
38+
39+
'& > .version': {
40+
bottom: 10,
41+
position: 'absolute'
3742
}
3843
});
3944

@@ -77,6 +82,9 @@ const App = () => {
7782
const [intervalEnabled, setIntervalEnabled] = useState(false);
7883
const [paragraphs, setParagraphs] = useState(createParagraphs(10));
7984
const [commandBarVisible, setCommandBarVisible] = useState(false);
85+
const [loadedVersion] = useState(() =>
86+
document.querySelector('head meta[name="react-scroll-to-bottom:version"]').getAttribute('content')
87+
);
8088

8189
const handleAdd = useCallback(count => setParagraphs([...paragraphs, ...createParagraphs(count)]), [
8290
paragraphs,
@@ -225,6 +233,9 @@ const App = () => {
225233
{commandBarVisible && <CommandBar />}
226234
</ScrollToEnd>
227235
</div>
236+
<div className="version">
237+
<code>react-scroll-to-bottom@{loadedVersion}</code> has loaded.
238+
</div>
228239
{intervalEnabled && <Interval callback={handleAdd1} enabled={true} timeout={1000} />}
229240
</div>
230241
);

scripts/lerna_publish

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

0 commit comments

Comments
 (0)