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

Migrate from Webpack to Vite #879

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1abf1d6
fix: Default-import Moment to make Vite happy
hyperupcall May 19, 2023
05c7673
fix: Export Redux store from a separate file
hyperupcall May 19, 2023
fd64495
fix: Use static plotly.js imports to make Vite happy
hyperupcall May 19, 2023
86c1ad1
feat: Remove Webpack and add Vite
hyperupcall May 19, 2023
f9d328c
chore: Add YAML to `.editorconfig`
hyperupcall May 19, 2023
e35768e
chore: Convert to tabs in `package{,-lock}.json` and config
hyperupcall May 19, 2023
a4e0244
chore: Format files
hyperupcall May 19, 2023
a9226d5
chore: Add previous formatting commit to new file `.git-blame-ignore-…
hyperupcall May 19, 2023
b16d091
chore: Update dependencies
hyperupcall May 19, 2023
1343091
fix: Miscellaneous fixes
hyperupcall May 19, 2023
5ce9935
fix: `peerDependency` resolutions
hyperupcall May 19, 2023
758d915
fix: Remove `core-js@2`
hyperupcall May 19, 2023
72efd58
fix: Make `TimeInterval.mjs` work
hyperupcall May 19, 2023
cde54ed
Various fixes and updates
hyperupcall May 19, 2023
f1f1457
fix: Expected a class/function as component Error
hyperupcall May 19, 2023
6a16512
fix: Import lodash with default imported
hyperupcall May 19, 2023
d0375a3
fix: Manually chunk dependencies for improved load times
hyperupcall May 19, 2023
547113e
chore: Update to Vite 4.3
hyperupcall May 19, 2023
413d58e
chore: Add missing license headers
hyperupcall May 19, 2023
78ed31e
Fix TypeScript error from `@formatjs/ecma402-abstract`
hyperupcall May 19, 2023
9455185
fix: Convert `TimeInterval.js` back to CommonJS
hyperupcall May 19, 2023
eb0f709
fix: Vite now listens on port `9229` in container
hyperupcall May 19, 2023
e38e99b
Merge branch 'development' into improve-build
hyperupcall Oct 16, 2023
3340c9b
fix: Remove vestiges
hyperupcall Oct 16, 2023
a4816a1
fix: Override transitive dependency resolutions
hyperupcall Oct 16, 2023
984ebd1
Fix typecheck and remove unused HTML file
hyperupcall Oct 16, 2023
6476534
fix: Do not race on `npm ci` in `docker-compose`
hyperupcall Oct 17, 2023
4773564
chore: Fix editorconfig
hyperupcall Oct 17, 2023
db186a3
Remove more Webpack things
hyperupcall Oct 22, 2023
347b1a4
Comment tweaks
hyperupcall Oct 30, 2023
8164663
Merge branch 'development' into improve-build
hyperupcall Oct 30, 2023
ef241f6
Set default for Vite dev server to `8085`
hyperupcall Oct 31, 2023
37e5aa6
style(webpack): Format code
hyperupcall Dec 4, 2023
32e497f
Merge branch 'development' into improve-build
hyperupcall Dec 4, 2023
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
6 changes: 2 additions & 4 deletions src/common/TimeInterval.js → src/common/TimeInterval.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

const moment = require('moment')
Copy link
Contributor Author

@hyperupcall hyperupcall May 19, 2023

Choose a reason for hiding this comment

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

Should probably note that this commit doesn't fix anything server-side. NodeJS only allows importing ESM through dynamic imports. But, I didn't properly await the imports, so there were errors since the imports had a value of Promise<Module> rather than Module. I didn't see the errors until later.

I later fixed this in 9455185 (one of the last commits in this series) by converting things back to CommonJS. Luckily, I didn't get the previous errors I was getting with Vite because I updated Vite to a later version by then.

import moment from 'moment'

class TimeInterval {
export class TimeInterval {
constructor(startTimestamp, endTimestamp) {
// utc keeps the moments from changing timezone.
this.startTimestamp = startTimestamp && moment.utc(startTimestamp);
Expand Down Expand Up @@ -103,5 +103,3 @@ class TimeInterval {
return new TimeInterval(startTimestamp, endTimestamp);
}
}

exports.TimeInterval = TimeInterval
2 changes: 1 addition & 1 deletion src/server/models/Baseline.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
const database = require('./database');
const { TimeInterval } = require('../../common/TimeInterval');
const { TimeInterval } = import('../../common/TimeInterval.mjs');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To elaborate a bit more from the extended commit message: Because TimeInterval.mjs uses ESModules, we can only import things from the file using ESModule-style imports (not CommonJS).

const sqlFile = database.sqlFile;
class Baseline {
constructor(meterID, applyStart, applyEnd, calcStart, calcEnd, note = null, baselineValue = null) {
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/readings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const _ = require('lodash');
const moment = require('moment');
const Meter = require('../models/Meter');
const Reading = require('../models/Reading');
const TimeInterval = require('../../common/TimeInterval').TimeInterval;
const { TimeInterval } = import('../../common/TimeInterval.mjs');
const { log } = require('../log');
const validate = require('jsonschema').validate;
const { getConnection } = require('../db');
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/unitReadings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const _ = require('lodash');

const { getConnection } = require('../db');
const Reading = require('../models/Reading');
const { TimeInterval } = require('../../common/TimeInterval');
const { TimeInterval } = import('../../common/TimeInterval.mjs');

function validateMeterLineReadingsParams(params) {
const validParams = {
Expand Down
2 changes: 1 addition & 1 deletion src/server/test/routes/unitReadingsRouteTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const { meterLineReadings,
validateBarReadingsQueryParams
} = require('../../routes/unitReadings');

const { TimeInterval } = require('../../../common/TimeInterval');
const { TimeInterval } = import('../../../common/TimeInterval.mjs');

function mockResponse() {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/server/test/timeIntervalTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const expect = chai.expect;
const { TimeInterval } = require('../../common/TimeInterval');
const { TimeInterval } = import('../../common/TimeInterval.mjs');


mocha.describe('Time Intervals', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/server/test/web/readings.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

const { chai, mocha, expect, app, testDB } = require('../common');
const { TimeInterval } = require('../../../common/TimeInterval');
const { TimeInterval } = import('../../../common/TimeInterval.mjs');
const { insertUnits, insertConversions, insertMeters, insertGroups } = require('../../util/insertData');
const Unit = require('../../models/Unit');
const { redoCik } = require('../../services/graph/redoCik');
Expand Down Expand Up @@ -926,4 +926,4 @@ mocha.describe('readings API', () => {
});
});
});
});
});