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

refactor: migrate to ESM #7331

Merged
merged 19 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
File renamed without changes.
28 changes: 15 additions & 13 deletions .webpack/webpack.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* global __dirname module */

/*
This is the OpenMCT common webpack file. It is imported by the other three webpack configurations:
- webpack.prod.js - the production configuration for OpenMCT (default)
Expand All @@ -8,27 +6,30 @@ This is the OpenMCT common webpack file. It is imported by the other three webpa
There are separate npm scripts to use these configurations, though simply running `npm install`
will use the default production configuration.
*/
const path = require('path');
const packageDefinition = require('../package.json');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
import path from 'node:path';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import webpack from 'webpack';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import fs from 'node:fs';
import { execSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';

const { VueLoaderPlugin } = require('vue-loader');
import { VueLoaderPlugin } from 'vue-loader';
let gitRevision = 'error-retrieving-revision';
let gitBranch = 'error-retrieving-branch';

const packageDefinition = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));

try {
gitRevision = require('child_process').execSync('git rev-parse HEAD').toString().trim();
gitBranch = require('child_process')
.execSync('git rev-parse --abbrev-ref HEAD')
gitRevision = execSync('git rev-parse HEAD').toString().trim();
gitBranch = execSync('git rev-parse --abbrev-ref HEAD')
.toString()
.trim();
} catch (err) {
console.warn(err);
}

const projectRootDir = path.resolve(__dirname, '..');
const projectRootDir = fileURLToPath(new URL('../', import.meta.url));

/** @type {import('webpack').Configuration} */
const config = {
Expand Down Expand Up @@ -56,6 +57,7 @@ const config = {
filename: '[name].js',
path: path.resolve(projectRootDir, 'dist'),
library: 'openmct',
libraryExport: 'default',
libraryTarget: 'umd',
publicPath: '',
hashFunction: 'xxhash64',
Expand Down Expand Up @@ -183,4 +185,4 @@ const config = {
}
};

module.exports = config;
export default config;
6 changes: 2 additions & 4 deletions .webpack/webpack.coverage.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/* global module */

/*
This file extends the webpack.dev.js config to add babel istanbul coverage.
OpenMCT Continuous Integration servers use this configuration to add code coverage
information to pull requests.
*/

const config = require('./webpack.dev');
import config from './webpack.dev.js';
// eslint-disable-next-line no-undef
const CI = process.env.CI === 'true';

Expand Down Expand Up @@ -34,4 +32,4 @@ config.module.rules.push({
}
});

module.exports = config;
export default config;
16 changes: 7 additions & 9 deletions .webpack/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
/* global __dirname module */

/*
This configuration should be used for development purposes. It contains full source map, a
devServer (which be invoked using by `npm start`), and a non-minified Vue.js distribution.
If OpenMCT is to be used for a production server, use webpack.prod.js instead.
*/
const path = require('path');
const webpack = require('webpack');
const { merge } = require('webpack-merge');
import path from 'path';
import webpack from 'webpack';
import { merge } from 'webpack-merge';
import { fileURLToPath } from 'node:url';

const common = require('./webpack.common');
const projectRootDir = path.resolve(__dirname, '..');
import common from './webpack.common.js';

module.exports = merge(common, {
export default merge(common, {
mode: 'development',
watchOptions: {
// Since we use require.context, webpack is watching the entire directory.
Expand Down Expand Up @@ -42,7 +40,7 @@ module.exports = merge(common, {
},
watchFiles: ['**/*.css'],
static: {
directory: path.join(__dirname, '..', '/dist'),
directory: fileURLToPath(new URL('../dist', import.meta.url)),
publicPath: '/dist',
watch: false
}
Expand Down
13 changes: 5 additions & 8 deletions .webpack/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
/* global __dirname module */

/*
This configuration should be used for production installs.
It is the default webpack configuration.
*/
const path = require('path');
const webpack = require('webpack');
const { merge } = require('webpack-merge');

const common = require('./webpack.common');
const projectRootDir = path.resolve(__dirname, '..');
import webpack from 'webpack';
import { merge } from 'webpack-merge';

import common from './webpack.common.js';

module.exports = merge(common, {
export default merge(common, {
mode: 'production',
plugins: [
new webpack.DefinePlugin({
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ The following contains a list of tips and tricks which don't exactly fit into a
It is possible to override the browser's clock in order to control time-based elements. Since this can cause unwanted behavior (i.e. Tree not rendering), only use this sparingly. To do this, use the `overrideClock` fixture as such:

```js
const { test, expect } = require('../../pluginFixtures.js');
import { test, expect } from '../../pluginFixtures.js';

test.describe('foo test suite', () => {

Expand Down
19 changes: 9 additions & 10 deletions e2e/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
* @property {import('../src/api/notifications/NotificationAPI').NotificationOptions} [notificationOptions] additional options
*/

const Buffer = require('buffer').Buffer;
const genUuid = require('uuid').v4;
const { expect } = require('@playwright/test');
import { expect } from '@playwright/test';
import { Buffer } from 'buffer';
import { v4 as genUuid } from 'uuid';

/**
* This common function creates a domain object with the default options. It is the preferred way of creating objects
Expand Down Expand Up @@ -644,25 +644,24 @@ async function renameObjectFromContextMenu(page, url, newName) {
await page.click('[aria-label="Save"]');
}

// eslint-disable-next-line no-undef
module.exports = {
export {
createDomainObjectWithDefaults,
createExampleTelemetryObject,
createNotification,
createPlanFromJSON,
expandEntireTree,
expandTreePaneItemByName,
getCanvasPixels,
getHashUrlToDomainObject,
getFocusedObjectUuid,
getHashUrlToDomainObject,
navigateToObjectWithFixedTimeBounds,
openObjectTreeContextMenu,
renameObjectFromContextMenu,
setEndOffset,
setFixedTimeMode,
setIndependentTimeConductorBounds,
setRealTimeMode,
setStartOffset,
setEndOffset,
setTimeConductorBounds,
setIndependentTimeConductorBounds,
waitForPlotsToRender,
renameObjectFromContextMenu
waitForPlotsToRender
};
16 changes: 8 additions & 8 deletions e2e/avpFixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
* existing ones.
*/

const fs = require('fs');
const path = require('path');
const { test, expect } = require('./pluginFixtures');
const AxeBuilder = require('@axe-core/playwright').default;
import AxeBuilder from '@axe-core/playwright';
import fs from 'fs';
import path from 'path';

import { expect, test } from './pluginFixtures.js';

// Constants for repeated values
const TEST_RESULTS_DIR = './test-results';
Expand All @@ -56,7 +57,7 @@ const TEST_RESULTS_DIR = './test-results';
* otherwise returns null.
*/
/* eslint-disable no-undef */
exports.scanForA11yViolations = async function (page, testCaseName, options = {}) {
export async function scanForA11yViolations(page, testCaseName, options = {}) {
const builder = new AxeBuilder({ page });
builder.withTags(['wcag2aa']);
// https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md
Expand Down Expand Up @@ -91,7 +92,6 @@ exports.scanForA11yViolations = async function (page, testCaseName, options = {}
console.log('No accessibility violations found, no report generated.');
return null;
}
};
}

exports.expect = expect;
exports.test = test;
export { expect, test };
20 changes: 9 additions & 11 deletions e2e/baseFixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
* GitHub issues.
*/

const base = require('@playwright/test');
const { expect, request } = base;
const fs = require('fs');
const path = require('path');
const { v4: uuid } = require('uuid');
const sinon = require('sinon');
import { expect, request, test } from '@playwright/test';
import fs from 'fs';
import path from 'path';
import sinon from 'sinon';
import { fileURLToPath } from 'url';
import { v4 as uuid } from 'uuid';

/**
* Takes a `ConsoleMessage` and returns a formatted string. Used to enable console log error detection.
Expand Down Expand Up @@ -68,7 +68,7 @@ function waitForAnimations(locator) {
*/
const istanbulCLIOutput = path.join(process.cwd(), '.nyc_output');

exports.test = base.test.extend({
const extendedTest = test.extend({
/**
* This allows the test to manipulate the browser clock. This is useful for Visual and Snapshot tests which need
* the Time Indicator Clock to be in a specific state.
Expand Down Expand Up @@ -97,7 +97,7 @@ exports.test = base.test.extend({
async ({ context, clockOptions }, use) => {
if (clockOptions !== undefined) {
await context.addInitScript({
path: path.join(__dirname, '../', './node_modules/sinon/pkg/sinon.js')
path: fileURLToPath(new URL('../node_modules/sinon/pkg/sinon.js', import.meta.url))
});
await context.addInitScript((options) => {
window.__clock = sinon.useFakeTimers(options);
Expand Down Expand Up @@ -201,6 +201,4 @@ exports.test = base.test.extend({
}
});

exports.expect = expect;
exports.request = request;
exports.waitForAnimations = waitForAnimations;
export { expect, request, extendedTest as test, waitForAnimations };
44 changes: 23 additions & 21 deletions e2e/helper/faultUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
/* global __dirname */
const path = require('path');
import { fileURLToPath } from 'url';

/**
* @param {import('@playwright/test').Page} page
*/
async function navigateToFaultManagementWithExample(page) {
await page.addInitScript({ path: path.join(__dirname, './', 'addInitExampleFaultProvider.js') });
await page.addInitScript({
path: fileURLToPath(new URL('./addInitExampleFaultProvider.js', import.meta.url))
});

await navigateToFaultItemInTree(page);
}
Expand All @@ -36,7 +37,7 @@ async function navigateToFaultManagementWithExample(page) {
*/
async function navigateToFaultManagementWithStaticExample(page) {
await page.addInitScript({
path: path.join(__dirname, './', 'addInitExampleFaultProviderStatic.js')
path: fileURLToPath(new URL('./addInitExampleFaultProviderStatic.js', import.meta.url))
});

await navigateToFaultItemInTree(page);
Expand All @@ -46,7 +47,9 @@ async function navigateToFaultManagementWithStaticExample(page) {
* @param {import('@playwright/test').Page} page
*/
async function navigateToFaultManagementWithoutExample(page) {
await page.addInitScript({ path: path.join(__dirname, './', 'addInitFaultManagementPlugin.js') });
await page.addInitScript({
path: fileURLToPath(new URL('./addInitFaultManagementPlugin.js', import.meta.url))
});

await navigateToFaultItemInTree(page);
}
Expand Down Expand Up @@ -265,29 +268,28 @@ async function openFaultRowMenu(page, rowNumber) {
.click();
}

// eslint-disable-next-line no-undef
module.exports = {
navigateToFaultManagementWithExample,
navigateToFaultManagementWithStaticExample,
navigateToFaultManagementWithoutExample,
navigateToFaultItemInTree,
export {
acknowledgeFault,
shelveMultipleFaults,
acknowledgeMultipleFaults,
shelveFault,
changeViewTo,
sortFaultsBy,
enterSearchTerm,
clearSearch,
selectFaultItem,
getHighestSeverity,
getLowestSeverity,
getFaultResultCount,
enterSearchTerm,
getFault,
getFaultByName,
getFaultName,
getFaultSeverity,
getFaultNamespace,
getFaultResultCount,
getFaultSeverity,
getFaultTriggerTime,
openFaultRowMenu
getHighestSeverity,
getLowestSeverity,
navigateToFaultItemInTree,
navigateToFaultManagementWithExample,
navigateToFaultManagementWithoutExample,
navigateToFaultManagementWithStaticExample,
openFaultRowMenu,
selectFaultItem,
shelveFault,
shelveMultipleFaults,
sortFaultsBy
};
19 changes: 10 additions & 9 deletions e2e/helper/notebookUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
* at runtime from the About dialog for additional information.
*****************************************************************************/

const { createDomainObjectWithDefaults } = require('../appActions');
import { createDomainObjectWithDefaults } from '../appActions.js';

const NOTEBOOK_DROP_AREA = '.c-notebook__drag-area';
const CUSTOM_NAME = 'CUSTOM_NAME';
const path = require('path');
import { fileURLToPath } from 'url';

/**
* @param {import('@playwright/test').Page} page
Expand Down Expand Up @@ -69,7 +69,9 @@ async function commitEntry(page) {
*/
async function startAndAddRestrictedNotebookObject(page) {
// eslint-disable-next-line no-undef
await page.addInitScript({ path: path.join(__dirname, 'addInitRestrictedNotebook.js') });
await page.addInitScript({
path: fileURLToPath(new URL('./addInitRestrictedNotebook.js', import.meta.url))
});
await page.goto('./', { waitUntil: 'domcontentloaded' });

return createDomainObjectWithDefaults(page, {
Expand Down Expand Up @@ -138,12 +140,11 @@ async function createNotebookEntryAndTags(page, iterations = 1) {
return notebook;
}

// eslint-disable-next-line no-undef
module.exports = {
enterTextEntry,
export {
createNotebookAndEntry,
createNotebookEntryAndTags,
dragAndDropEmbed,
startAndAddRestrictedNotebookObject,
enterTextEntry,
lockPage,
createNotebookEntryAndTags,
createNotebookAndEntry
startAndAddRestrictedNotebookObject
};
Loading