Skip to content

Commit 7e12998

Browse files
authored
Convert @redux-devtools/cli to ESM (#1316)
* stash * Updates * Fix lint * Create lovely-boats-happen.md * Update package.json * Update lovely-boats-happen.md
1 parent 78eed2d commit 7e12998

File tree

16 files changed

+108
-51
lines changed

16 files changed

+108
-51
lines changed

.changeset/lovely-boats-happen.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@redux-devtools/cli': major
3+
---
4+
5+
Convert @redux-devtools/cli to ESM. Please [read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) for more info about ESM.
6+
Update supported Node versions from `>=14.15.0` to `^14.13.1 || ^16.13.0 || >=18.12.0`.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#! /usr/bin/env node
22

3-
require('../dist/bin/redux-devtools.js');
3+
import '../dist/bin/redux-devtools.js';

packages/redux-devtools-cli/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
preset: 'ts-jest',
33
transform: {
44
'^.+\\.tsx?$': ['ts-jest', { tsconfig: 'tsconfig.test.json' }],

packages/redux-devtools-cli/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"index.js",
1717
"defaultDbOptions.json"
1818
],
19+
"type": "module",
1920
"main": "dist/index.js",
2021
"types": "dist/index.d.ts",
2122
"bin": {
@@ -37,22 +38,22 @@
3738
"prepublish": "pnpm run type-check && pnpm run lint && pnpm run test"
3839
},
3940
"engines": {
40-
"node": ">=14.15.0"
41+
"node": "^14.13.1 || ^16.13.0 || >= 18.12.0"
4142
},
4243
"dependencies": {
4344
"@apollo/server": "^4.3.0",
4445
"@redux-devtools/app": "^2.1.3",
4546
"@types/react": "^18.0.26",
4647
"body-parser": "^1.20.1",
47-
"chalk": "^4.1.2",
48+
"chalk": "^5.2.0",
4849
"cors": "^2.8.5",
4950
"cross-spawn": "^7.0.3",
5051
"electron": "^22.0.0",
5152
"express": "^4.18.2",
52-
"get-port": "^5.1.1",
53+
"get-port": "^6.1.2",
5354
"graphql": "^16.6.0",
5455
"knex": "^2.3.0",
55-
"lodash": "^4.17.21",
56+
"lodash-es": "^4.17.21",
5657
"minimist": "^1.2.7",
5758
"morgan": "^1.10.0",
5859
"open": "^8.4.0",
@@ -71,7 +72,7 @@
7172
"@types/cross-spawn": "^6.0.2",
7273
"@types/express": "^4.17.15",
7374
"@types/jest": "^29.2.4",
74-
"@types/lodash": "^4.14.191",
75+
"@types/lodash-es": "^4.17.6",
7576
"@types/minimist": "^1.2.2",
7677
"@types/morgan": "^1.9.3",
7778
"@types/node": "^18.11.17",

packages/redux-devtools-cli/src/api/schema.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import fs from 'fs';
2-
import { Store } from '../store';
2+
import type { Store } from '../store.js';
33

4-
export const schema = fs
5-
.readFileSync(require.resolve('./schema_def.graphql'))
6-
.toString();
4+
export const schema = fs.readFileSync(
5+
new URL('./schema_def.graphql', import.meta.url),
6+
'utf8'
7+
);
78

89
export const resolvers = {
910
Query: {

packages/redux-devtools-cli/src/bin/injectServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
33
import semver from 'semver';
4-
import { Options } from '../options';
4+
import type { Options } from '../options.js';
55

66
const name = '@redux-devtools/cli';
77
const startFlag = '/* ' + name + ' start */';

packages/redux-devtools-cli/src/bin/openApp.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
import open from 'open';
22
import path from 'path';
3+
import { fileURLToPath } from 'url';
4+
import { createRequire } from 'module';
35
import spawn from 'cross-spawn';
4-
import { Options } from '../options';
6+
import type { Options } from '../options.js';
7+
8+
const require = createRequire(import.meta.url);
59

610
export default async function openApp(app: true | string, options: Options) {
711
if (app === true || app === 'electron') {
812
try {
913
const port = options.port ? `--port=${options.port}` : '';
1014
// eslint-disable-next-line @typescript-eslint/no-var-requires
1115
spawn.sync(require('electron') as string, [
12-
path.join(__dirname, '..', '..', 'app'),
16+
path.join(
17+
path.dirname(fileURLToPath(import.meta.url)),
18+
'..',
19+
'..',
20+
'app'
21+
),
1322
port,
1423
]);
1524
} catch (error) {

packages/redux-devtools-cli/src/bin/redux-devtools.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import fs from 'fs';
33
import path from 'path';
44
import parseArgs from 'minimist';
55
import chalk from 'chalk';
6-
import * as injectServer from './injectServer';
7-
import getOptions from '../options';
8-
import server from '../index';
9-
import openApp from './openApp';
6+
import * as injectServer from './injectServer.js';
7+
import getOptions from '../options.js';
8+
import server from '../index.js';
9+
import openApp from './openApp.js';
1010

1111
const argv = parseArgs(process.argv.slice(2));
1212

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
import path from 'path';
2-
import knexModule, { Knex } from 'knex';
2+
import { fileURLToPath } from 'url';
3+
import knex from 'knex';
4+
import type { Knex } from 'knex';
35
import { AGServer } from 'socketcluster-server';
46

7+
// eslint-disable-next-line @typescript-eslint/ban-types
8+
type KnexFunction = <TRecord extends {} = any, TResult = unknown[]>(
9+
config: Knex.Config | string
10+
) => Knex<TRecord, TResult>;
11+
512
export default function connector(options: AGServer.AGServerOptions) {
613
const dbOptions = options.dbOptions as Knex.Config;
714
dbOptions.useNullAsDefault = true;
815
if (!(dbOptions as any).migrate) {
9-
return knexModule(dbOptions);
16+
return (knex as unknown as KnexFunction)(dbOptions);
1017
}
1118

12-
dbOptions.migrations = { directory: path.resolve(__dirname, 'migrations') };
13-
dbOptions.seeds = { directory: path.resolve(__dirname, 'seeds') };
14-
const knex = knexModule(dbOptions);
19+
dbOptions.migrations = {
20+
directory: path.join(
21+
path.dirname(fileURLToPath(import.meta.url)),
22+
'migrations'
23+
),
24+
};
25+
dbOptions.seeds = {
26+
directory: path.join(path.dirname(fileURLToPath(import.meta.url)), 'seeds'),
27+
};
28+
const knexInstance = (knex as unknown as KnexFunction)(dbOptions);
1529

1630
/* eslint-disable no-console */
17-
knex.migrate
31+
knexInstance.migrate
1832
.latest({ loadExtensions: ['.js'] })
1933
.then(function () {
20-
return knex.seed.run({ loadExtensions: ['.js'] });
34+
return knexInstance.seed.run({ loadExtensions: ['.js'] });
2135
})
2236
.then(function () {
2337
console.log(' \x1b[0;32m[Done]\x1b[0m Migrations are finished\n');
@@ -27,5 +41,5 @@ export default function connector(options: AGServer.AGServerOptions) {
2741
});
2842
/* eslint-enable no-console */
2943

30-
return knex;
44+
return knexInstance;
3145
}

0 commit comments

Comments
 (0)