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 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions build/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
/**
* This file contains path definitions for build scripts.
*/
const path = require('path');
import path 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.

Use single quotes

const rootPath = path.resolve(__dirname, '..');

module.exports = {
srcDir: path.resolve(rootPath, 'src'),
testDir: path.resolve(rootPath, 'test'),
outputDir: path.resolve(rootPath, 'dist'),
testOutputDir: path.resolve(rootPath, 'test')
};
export const srcDir = path.resolve(rootPath, 'src');
export const testDir = path.resolve(rootPath, 'test');
export const outputDir = path.resolve(rootPath, 'dist');
export const testOutputDir = path.resolve(rootPath, 'test');
2 changes: 1 addition & 1 deletion build/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.js";
Copy link
Contributor

Choose a reason for hiding this comment

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

Use single quotes


const isDev = process.env.NODE_ENV === 'development';

Expand Down
46 changes: 23 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
"displayName": "TAO Core SDK",
"description": "Core libraries of TAO",
"homepage": "https://github.com/oat-sa/tao-core-sdk-fe#readme",
"type": "module",
"files": [
"dist/",
"src/"
],
"exports": {
"./core/*": "./src/core/*.js",
"./util/*": "./src/util/*.js"
},
"license": "GPL-2.0",
"scripts": {
"test": "npx qunit-testrunner",
Expand Down
23 changes: 11 additions & 12 deletions src/core/asyncProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2016-2019 (original work) Open Assessment Technologies SA ;
* Copyright (c) 2016-2024 (original work) Open Assessment Technologies SA ;
*/
/**
* @author Jean-Sébastien Conan <jean-sebastien.conan@vesperiagroup.com>
*/
import _ from 'lodash';
import Promise from 'core/promise';
import eventifier from 'core/eventifier';
import eventifier from './eventifier.js';

/**
* Defines a manager for async process with deferred steps.
Expand All @@ -34,15 +33,15 @@ import eventifier from 'core/eventifier';
* @trigger reject - When the process has finished on error
*/
function asyncProcessFactory() {
var running = false;
var steps = [];
let running = false;
let steps = [];

return eventifier({
/**
* Tells if a process is running
* @returns {Boolean}
*/
isRunning: function isRunning() {
isRunning() {
return running;
},

Expand All @@ -51,8 +50,8 @@ function asyncProcessFactory() {
* @param {Function} [cb] - The process to start
* @returns {boolean} - Returns true if the process can be started
*/
start: function start(cb) {
var started = false;
start(cb) {
let started = false;
if (!running) {
steps = [];
running = true;
Expand All @@ -75,7 +74,7 @@ function asyncProcessFactory() {
* @param {Promise} step
* @returns {asyncProcess}
*/
addStep: function addStep(step) {
addStep(step) {
steps.push(step);

/**
Expand All @@ -93,9 +92,9 @@ function asyncProcessFactory() {
* @param {Function} [cb] - A nodeback like function which will be called when all the deferred steps have finished or an error occurs
* @returns {Promise} - Returns the finish promise
*/
done: function done(cb) {
var self = this;
var finish = Promise.all(steps);
done(cb) {
const self = this;
const finish = Promise.all(steps);

finish
.then(function(data) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/cachedStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2016-2019 (original work) Open Assessment Technologies SA ;
* Copyright (c) 2016-2024 (original work) Open Assessment Technologies SA ;
*/
/**
* @author Jean-Sébastien Conan <jean-sebastien.conan@vesperiagroup.com>
*/
import store from 'core/store';
import store from './store.js';

/**
* The default name of the key storage indexing the persisted data
Expand Down
2 changes: 1 addition & 1 deletion src/core/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2016-2019 Open Assessment Technologies SA
* Copyright (c) 2016-2024 Open Assessment Technologies SA
Copy link
Contributor

Choose a reason for hiding this comment

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

rollback

*/

/**
Expand Down
13 changes: 6 additions & 7 deletions src/core/communicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2016-2019 (original work) Open Assessment Technologies SA ;
* Copyright (c) 2016-2024 (original work) Open Assessment Technologies SA ;
*/
/**
* @author Jean-Sébastien Conan <jean-sebastien.conan@vesperiagroup.com>
*/
import _ from 'lodash';
import Promise from 'core/promise';
import providerRegistry from 'core/providerRegistry';
import delegator from 'core/delegator';
import eventifier from 'core/eventifier';
import providerRegistry from './providerRegistry.js';
import delegator from './delegator.js';
import eventifier from './eventifier.js';

/**
* Some default config values
Expand Down Expand Up @@ -156,7 +155,7 @@ function communicatorFactory(providerName, config) {
},

/**
* Sends an messages through the communication implementation.
* Sends a messages through the communication implementation.
* @param {String} channel - The name of the communication channel to use
* @param {Object} message - The message to send
* @returns {Promise} The delegated provider's method must return a promise
Expand Down Expand Up @@ -227,7 +226,7 @@ function communicatorFactory(providerName, config) {
}
});

// all messages comes through a message event, then each is dispatched to the right channel
// all messages come through a message event, then each is dispatched to the right channel
communicator.on('message', function (channel, message) {
this.trigger(`channel-${channel}`, message);
});
Expand Down
9 changes: 4 additions & 5 deletions src/core/communicator/poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
*/

import _ from 'lodash';
import pollingFactory from 'core/polling';
import Promise from 'core/promise';
import coreRequest from 'core/request';
import pollingFactory from '../polling.js';
import coreRequest from '../request.js';

/**
* Some default config values
Expand Down Expand Up @@ -68,7 +67,7 @@ const defaults = {
*
* Business logic errors can be implemented using the `error` *channel*.
* Network errors are handled by the AJAX implementation, and are forwarded to the `error` *event*.
* Additional network error handling can be achieve by the rejected send promises.
* Additional network error handling can be achieved by the rejected send promises.
*
* Malformed messages will be issued through the `malformed` channel
*
Expand Down Expand Up @@ -258,7 +257,7 @@ const pollProvider = {
});
this.messagesQueue.push(pending);

// force a send in the next throttle period
// force send in the next throttle period
this.throttledSend();

return promise;
Expand Down
8 changes: 4 additions & 4 deletions src/core/communicator/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @author Bertrand Chevrier <bertrand@taotesting.com>
*/
import _ from 'lodash';
import pollProvider from 'core/communicator/poll';
import pollProvider from './poll.js';

/**
* 'request' provider for {@link core/communicator}
Expand Down Expand Up @@ -61,18 +61,18 @@ const requestProvider = _.defaults({
},

/**
* Sends an messages through the communication implementation
* Sends a messages through the communication implementation
* @param {String} channel - The name of the communication channel to use
* @param {Object} message - The message to send
* @returns {Promise}
*/
send: function send(channel, message) {
// queue the message, it will be sent soon
var pending = {
const pending = {
channel: channel,
message: message
};
var promise = new Promise(function(resolve, reject) {
const promise = new Promise(function (resolve, reject) {
pending.promise = {
resolve: resolve,
reject: reject
Expand Down
Loading
Loading