Skip to content
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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

KirylHatalski
Copy link

@KirylHatalski KirylHatalski commented Oct 14, 2024

Ticket: TR-6197

Copy link
Contributor

@oatymart oatymart left a 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",
Copy link
Contributor

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",
Copy link
Contributor

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).

@@ -115,8 +115,8 @@
*/

import _ from 'lodash';
import Promise from 'core/promise';
import eventifier from 'core/eventifier';
import Promise from './promise';
Copy link
Contributor

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?

@@ -22,9 +22,9 @@
* @author Bertrand Chevrier <bertrand@taotesting.com>
*/
import _ from 'lodash';
import Promise from 'core/promise';
import Promise from '../promise';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove it?

Copy link
Contributor

@jsconan jsconan left a 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?

Comment on lines 22 to 23
import Promise from './promise';
import eventifier from './eventifier';
Copy link
Contributor

@jsconan jsconan Oct 15, 2024

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.

@@ -52,7 +52,7 @@ function asyncProcessFactory() {
* @returns {boolean} - Returns true if the process can be started
*/
start: function start(cb) {
Copy link
Contributor

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?

Suggested change
start: function start(cb) {
start(cb) {

var Filters = {
register: function(name, filter) {
const Filters = {
register: function (name, filter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) {
Copy link
Contributor

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:

Suggested change
const createEvent = function createEvent(eventName, eventOptions) {
function createEvent(eventName, eventOptions) {

@@ -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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { srcDir, outputDir } from "./path";
import { srcDir, outputDir } from "./path.js";

Comment on lines 22 to 23
import Promise from './promise';
import eventifier from './eventifier';
Copy link
Contributor

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

Suggested change
import Promise from './promise';
import eventifier from './eventifier';
import Promise from './promise.js';
import eventifier from './eventifier.js';

*/
/**
* @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';
Copy link
Contributor

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.

Copy link

Version

Target Version 3.2.2
Last version 3.2.1

There are 0 BREAKING CHANGE, 0 feature, 0 fix

@KirylHatalski KirylHatalski marked this pull request as ready for review October 21, 2024 14:25
@KirylHatalski KirylHatalski changed the title [WIP] moving from AMD to ESM [TR-6197] Moving from AMD to ESM Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants