Skip to content

Commit

Permalink
Merge pull request #1275 from balena-io/date-dns-deep-imports
Browse files Browse the repository at this point in the history
Use deep imports for date-fns to improve tree-shaking
  • Loading branch information
bulldozer-balena[bot] committed Nov 4, 2022
2 parents 04ac82d + 7701562 commit 31778e5
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

import * as errors from 'balena-errors';
import * as memoizee from 'memoizee';
import memoizee from 'memoizee';
import type { InjectedDependenciesParam, InjectedOptionsParam } from '.';

const getAuth = function (
Expand Down
2 changes: 1 addition & 1 deletion lib/models/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import once = require('lodash/once');
import groupBy = require('lodash/groupBy');
import * as bSemver from 'balena-semver';
import * as errors from 'balena-errors';
import * as memoizee from 'memoizee';
import memoizee from 'memoizee';

import {
isId,
Expand Down
2 changes: 1 addition & 1 deletion lib/util/cache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as memoizee from 'memoizee';
import memoizee from 'memoizee';
import type { PubSub } from './pubsub';
const DEFAULT_CACHING_INTERVAL = 10 * 60 * 1000; // 10 minutes

Expand Down
4 changes: 2 additions & 2 deletions lib/util/date.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formatDistance } from 'date-fns';
import * as memoizee from 'memoizee';
import formatDistance from 'date-fns/formatDistance';
import memoizee from 'memoizee';

const now = memoizee(() => new Date(), { maxAge: 1000 });

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/api-key.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tslint:disable-next-line:import-blacklist
import * as _ from 'lodash';
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import {
balena,
givenAnApplication,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/application-membership.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tslint:disable-next-line:import-blacklist
import * as _ from 'lodash';
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import {
balena,
credentials,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/application.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tslint:disable-next-line:import-blacklist
import * as _ from 'lodash';
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import type * as BalenaSdk from '../../..';
import { toWritable } from '../../../lib/util/types';
import { timeSuite } from '../../util';
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/applicationInvite.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tslint:disable-next-line:import-blacklist
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import { balena, givenAnApplication, givenLoggedInUser } from '../setup';
import { timeSuite } from '../../util';
import type * as BalenaSdk from '../../..';
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tslint:disable-next-line:import-blacklist
import * as _ from 'lodash';
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import { balena } from '../setup';
import { timeSuite } from '../../util';
import type * as BalenaSdk from '../../..';
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/device-type.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import { balena, givenLoggedInUser } from '../setup';
import { timeSuite } from '../../util';
import type * as BalenaSdk from '../../..';
Expand Down
24 changes: 22 additions & 2 deletions tests/integration/models/device.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as _ from 'lodash';
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import * as superagent from 'superagent';

import {
Expand Down Expand Up @@ -2778,7 +2778,27 @@ describe('Device Model', function () {
});

describe('balena.models.device.setSupervisorRelease()', function () {
givenASupervisorRelease(before);
before(async function () {
const [oldSupervisorRelease] = await balena.pine.get({
resource: 'supervisor_release',
options: {
$select: 'id',
$filter: {
supervisor_version: 'v11.12.3',
is_for__device_type: this.application.is_for__device_type.__id,
},
},
});
// Set all devices to a supervisor release so that the service installs are already set.
// We shouldn't need to do this.
for (const d of this.devices) {
await balena.models.device.setSupervisorRelease(
d.id,
oldSupervisorRelease.id,
);
}
});
givenASupervisorRelease(before, 'v11.12.4');

it('should set the batch of devices to a specific supervisor release', async function () {
await balena.models.device.setSupervisorRelease(
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/keys.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tslint:disable-next-line:import-blacklist
import * as _ from 'lodash';
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import PUBLIC_KEY from '../../data/public-key';
import { balena, givenLoggedInUser } from '../setup';
import { timeSuite } from '../../util';
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/organization-membership.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tslint:disable-next-line:import-blacklist
import * as _ from 'lodash';
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import {
balena,
credentials,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/organization.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tslint:disable-next-line:import-blacklist
import * as _ from 'lodash';
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import { balena, credentials, givenLoggedInUser } from '../setup';
import { timeSuite } from '../../util';

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/organizationInvite.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tslint:disable-next-line:import-blacklist
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import { balena, givenInitialOrganization, givenLoggedInUser } from '../setup';
import { timeSuite } from '../../util';
import type * as BalenaSdk from '../../..';
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/os.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as bSemver from 'balena-semver';
// tslint:disable-next-line:import-blacklist
import * as _ from 'lodash';
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import {
balena,
credentials,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/release.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import * as _ from 'lodash';
import { delay, timeSuite } from '../../util';

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tslint:disable-next-line:import-blacklist
import * as _ from 'lodash';
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import {
balena,
givenAnApplication,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/models/tags.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// tslint:disable-next-line:import-blacklist
import * as _ from 'lodash';
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import type * as BalenaSdk from '../../..';

const getAllByResourcePropNameProvider = (resourceName: string) =>
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import * as _ from 'lodash';
import * as chai from 'chai';
import { expect } from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as memoize from 'memoizee';
import chaiAsPromised from 'chai-as-promised';
import chaiSamsam from 'chai-samsam';
import memoizee from 'memoizee';
import type * as BalenaSdk from '../../';
import type { Dictionary } from '../../typings/utils';
import { toWritable } from '../../lib/util/types';
import { getInitialOrganization } from './utils';
chai.use(chaiAsPromised);
// tslint:disable-next-line:no-var-requires
chai.use(require('chai-samsam'));
chai.use(chaiSamsam);

export const IS_BROWSER = typeof window !== 'undefined' && window !== null;

Expand Down Expand Up @@ -214,7 +214,7 @@ export function givenInitialOrganization(beforeFn: Mocha.HookFunction) {
});
}

const getDeviceType = memoize(
const getDeviceType = memoizee(
(deviceTypeId: number) =>
balena.pine.get({
resource: 'device_type',
Expand Down
2 changes: 1 addition & 1 deletion tests/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'chai-samsam';
import { expect } from 'chai';
import * as parallel from 'mocha.parallel';
import parallel from 'mocha.parallel';
import { balena } from './integration/setup';
import type * as BalenaSdk from '..';

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"noUnusedParameters": true,
"noUnusedLocals": true,
"moduleResolution": "node",
"esModuleInterop": true,
"allowJs": true,
"importHelpers": true
},
Expand Down
6 changes: 5 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"extends": "./node_modules/@balena/lint/config/tslint-prettier.json",
"rules": {
"import-blacklist": [true, "lodash"]
"import-blacklist": [
true,
"date-fns",
"lodash"
]
}
}

0 comments on commit 31778e5

Please sign in to comment.