-
Notifications
You must be signed in to change notification settings - Fork 0
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TR-6197] Moving from AMD to ESM #190
base: develop
Are you sure you want to change the base?
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.
Code changes look alright.
I'm pretty sure the reason tests are failing is due to async
version upgrade. I checked out develop versions of package.json and package-lock, installed them (tests passed), then installed async@3
(tests failed).
I guess it is related to the following dependency chain, but I can't explain the precise error:
npm ls async
@oat-sa/tao-core-sdk@3.2.1
├── async@3.2.6
└─┬ handlebars@1.3.0
└─┬ uglify-js@2.3.6
└── async@0.2.10
package.json
Outdated
@@ -47,11 +52,11 @@ | |||
"@oat-sa/eslint-config-tao": "^2.0.0", | |||
"@oat-sa/prettier-config": "^0.1.1", | |||
"@oat-sa/tao-qunit-testrunner": "^2.0.0", | |||
"async": "^0.2.10", | |||
"async": "^3.2.6", |
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.
I believe there was a specific reason we kept the async 0.x
version for so long.
If the 3.x version is 100% equivalent, that's great, but we must be absolutely sure of it.
I'm not even sure where it is used in this library - need to check history books and see if another part of the TAO ecosystem breaks...
package.json
Outdated
"eslint": "^8.39.0", | ||
"fetch-mock": "^9.11.0", | ||
"glob": "^8.1.0", | ||
"handlebars": "1.3.0", | ||
"handlebars": "4.7.7", |
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 handlebars I don't think we can upgrade this easily. It requires a big effort to synchronise across all TAO 3.x repos, see https://oat-sa.atlassian.net/wiki/spaces/FOUN/pages/144081031/Upgrade+Handlebars (a task which ended up blocked the last 2 times).
src/core/polling.js
Outdated
@@ -115,8 +115,8 @@ | |||
*/ | |||
|
|||
import _ from 'lodash'; | |||
import Promise from 'core/promise'; | |||
import eventifier from 'core/eventifier'; | |||
import Promise from './promise'; |
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.
Can Promise
be removed here too?
src/core/store/indexeddb.js
Outdated
@@ -22,9 +22,9 @@ | |||
* @author Bertrand Chevrier <bertrand@taotesting.com> | |||
*/ | |||
import _ from 'lodash'; | |||
import Promise from 'core/promise'; | |||
import Promise from '../promise'; |
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.
Can we remove it?
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.
Added a few comments. Mainly my concern is regarding the replacement of URI with relative paths.
I'm not sure it will work fine with TAO Terre, which still uses AMD. Moreover, if you want a proper handling of ESM, every import should have the file extension. Here again, I'm not sure about the impact on the AMD consumers.
update: Ok, this is required by the ticket, actually. While it is worth checking with the Terre consumers, we should also add the file extension to each import as this is recommended by the standard and required by Vite.
I see you did convert some files to ES6, which is nice, but then why is it half way?
src/core/asyncProcess.js
Outdated
import Promise from './promise'; | ||
import eventifier from './eventifier'; |
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.
issue: I don't think the URI can be changed. Remember, the consumer still needs to access AMD-compatible URIs. Renaming the routes may create issues. I'm curious to know why such a change is necessary.
update: Ok, this is required by the ticket, actually. While it is worth checking with the Terre consumers, we should also add the file extension to each import as this is recommended by the standard and required by Vite.
src/core/asyncProcess.js
Outdated
@@ -52,7 +52,7 @@ function asyncProcessFactory() { | |||
* @returns {boolean} - Returns true if the process can be started | |||
*/ | |||
start: function start(cb) { |
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.
quibble: Converting the code to use let
and const
instead of var
is good, but why not continue and also use the shorthand?
start: function start(cb) { | |
start(cb) { |
var Filters = { | ||
register: function(name, filter) { | ||
const Filters = { | ||
register: function (name, filter) { |
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.
register: function (name, filter) { | |
register(name, filter) { |
@@ -53,8 +52,8 @@ var allowedEvents = [ | |||
* @param {*} eventOptions | |||
* @returns {Event} | |||
*/ | |||
var createEvent = function createEvent(eventName, eventOptions) { | |||
var event; | |||
const createEvent = function createEvent(eventName, eventOptions) { |
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.
quibble: Converting the code to use let
and const
instead of var
is good, but why not continue and also the correct pattern for functions?
Usually, when you see var something = function() { ... }
, this is either a developer's taste (which is IMO debatable), or because the function needs to be redefined later on. If the function is immutable, then the best practice is to use a named function instead of const something = function() { ... }
. Why? because function
hoists, while const
is lexically scoped. This also removes redundant and cumbersome naming.
suggestion:
const createEvent = function createEvent(eventName, eventOptions) { | |
function createEvent(eventName, eventOptions) { |
build/rollup.config.js
Outdated
@@ -25,7 +25,7 @@ import commonJS from 'rollup-plugin-commonjs'; | |||
import babel from 'rollup-plugin-babel'; | |||
import istanbul from 'rollup-plugin-istanbul'; | |||
|
|||
const { srcDir, outputDir } = require('./path'); | |||
import { srcDir, outputDir } from "./path"; |
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.
import { srcDir, outputDir } from "./path"; | |
import { srcDir, outputDir } from "./path.js"; |
src/core/asyncProcess.js
Outdated
import Promise from './promise'; | ||
import eventifier from './eventifier'; |
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: to properly follow the requirements, we also need to add the file extension
import Promise from './promise'; | |
import eventifier from './eventifier'; | |
import Promise from './promise.js'; | |
import eventifier from './eventifier.js'; |
src/core/asyncProcess.js
Outdated
*/ | ||
/** | ||
* @author Jean-Sébastien Conan <jean-sebastien.conan@vesperiagroup.com> | ||
*/ | ||
import _ from 'lodash'; | ||
import Promise from 'core/promise'; | ||
import eventifier from 'core/eventifier'; | ||
import Promise from './promise'; |
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: Is this still needed? Promise
was polyfilled, but it has been natively supported since ages.
Version
There are 0 BREAKING CHANGE, 0 feature, 0 fix |
Ticket: TR-6197