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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃彈 Use timeago.js library #32809
馃彈 Use timeago.js library #32809
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice PR. So much cleaner!
* This file registers all necessary locales supported by amp-timeago. | ||
*/ | ||
|
||
import {format, register} from 'timeago.js/dist/timeago.full.min.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this to be included by the AMP build, I'm pretty sure the timeago
dependency will need to be added to this list:
amphtml/build-system/compile/sources.js
Lines 40 to 68 in 3d0c39b
'node_modules/dompurify/package.json', | |
'node_modules/dompurify/dist/purify.es.js', | |
'node_modules/intersection-observer/package.json', | |
'node_modules/intersection-observer/intersection-observer.install.js', | |
'node_modules/resize-observer-polyfill/package.json', | |
'node_modules/resize-observer-polyfill/ResizeObserver.install.js', | |
'node_modules/obj-str/package.json', | |
'node_modules/obj-str/dist/obj-str.mjs', | |
'node_modules/promise-pjs/package.json', | |
'node_modules/promise-pjs/promise.mjs', | |
'node_modules/rrule/dist/es5/rrule.js', | |
'node_modules/web-animations-js/package.json', | |
'node_modules/web-animations-js/web-animations.install.js', | |
'node_modules/web-activities/package.json', | |
'node_modules/web-activities/activity-ports.js', | |
'node_modules/@ampproject/animations/package.json', | |
'node_modules/@ampproject/animations/dist/animations.mjs', | |
'node_modules/@ampproject/toolbox-cache-url/package.json', | |
'node_modules/@ampproject/toolbox-cache-url/dist/amp-toolbox-cache-url.esm.js', | |
'node_modules/@ampproject/viewer-messaging/package.json', | |
'node_modules/@ampproject/viewer-messaging/messaging.js', | |
'node_modules/@ampproject/worker-dom/package.json', | |
'node_modules/@ampproject/worker-dom/dist/amp-production/main.mjs', | |
'node_modules/preact/package.json', | |
'node_modules/preact/dist/*.js', | |
'node_modules/preact/hooks/package.json', | |
'node_modules/preact/hooks/dist/*.js', | |
'node_modules/preact/compat/package.json', | |
'node_modules/preact/compat/dist/*.js', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question about the approach.
* @param {string} locale | ||
* @return {string} | ||
*/ | ||
export function getLocale(locale) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be doing this in JS or processing the locale information in a publishing step from the origin library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the latter, I believe we would need an I2D on the formats converted here and keep this as an intermediary step. Unless I am misunderstanding what you are suggesting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion was to remove the mapping here and generate the output from the library output as a build step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh got it, done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-opening this thread. After struggling with adding to sources.js
and chatting with @samouri, it seems as though the patch approach during build isn't compatible with importing the minified modules. He recommended in 3cd6067 to keep this in JS to most clearly get gulp dist
to build. Maybe we can open a TODO to see if it's possible to move over in a separate effort?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of things:
- It would be nontrivial to point closure compiler to either the
esm
orlib
folders of timeago and have it work correctly. depending on which folder you try to point to, something explodes. (e.g. expecting all the es5 imports to have.default
after their import etc). For that reason, using the files within the prebuilt dist folder is the only feasible option unless we move off Closure. - Since our locale format doesn't match up with timeago, we need to have the conversion somewhere. The absolutely ideal location is of course for only a single mapping layer to exist as Kris says, but to patch the minified file would be difficult (file is minified) and brittle (liable to break at any package update) with only a very small bytesize win
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to merge this for now. If folks have any recommended changes from this discussion happy to follow up!
5032f5a
to
9807ed9
Compare
Apologies to folks who may have been tagged in this PR by owners bot, I did that thing where I accidentally took other people's commits :) They have since been removed. |
9807ed9
to
370c147
Compare
f4926e7
to
3cd6067
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR:
amp-timeago
0.1
from using thetimeago
package inthird_party/
to the runtime dependency packagetimeago.js
being used byamp-timeago:0.1
from3.0.0
to4.0.2
Tasks that will follow up in subsequent PR:
amp-timeago
1.0
to do the same, at which point we canthird_party/timeagojs
entirely