Skip to content

Commit abcd3cb

Browse files
committed
chore: __dirname is not valid in a ESM module scope
The recommended way of accessing the dirname is import.meta.dirname
1 parent 259f75e commit abcd3cb

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

packages/cli-repl/src/cli-repl.spec.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ describe('CliRepl', function () {
366366
context('loading JS files from disk', function () {
367367
it('allows loading a file from the disk', async function () {
368368
const filenameA = path.resolve(
369-
__dirname,
369+
import.meta.dirname,
370370
'..',
371371
'test',
372372
'fixtures',
@@ -383,7 +383,7 @@ describe('CliRepl', function () {
383383

384384
it('allows nested loading', async function () {
385385
const filenameB = path.resolve(
386-
__dirname,
386+
import.meta.dirname,
387387
'..',
388388
'test',
389389
'fixtures',
@@ -400,7 +400,7 @@ describe('CliRepl', function () {
400400

401401
it('allows async operations', async function () {
402402
const filenameC = path.resolve(
403-
__dirname,
403+
import.meta.dirname,
404404
'..',
405405
'test',
406406
'fixtures',
@@ -637,7 +637,7 @@ describe('CliRepl', function () {
637637
});
638638
it('load a file if it has been specified on the command line', async function () {
639639
const filename1 = path.resolve(
640-
__dirname,
640+
import.meta.dirname,
641641
'..',
642642
'test',
643643
'fixtures',
@@ -655,15 +655,15 @@ describe('CliRepl', function () {
655655

656656
it('load two files if it has been specified on the command line', async function () {
657657
const filename1 = path.resolve(
658-
__dirname,
658+
import.meta.dirname,
659659
'..',
660660
'test',
661661
'fixtures',
662662
'load',
663663
'hello1.js'
664664
);
665665
const filename2 = path.resolve(
666-
__dirname,
666+
import.meta.dirname,
667667
'..',
668668
'test',
669669
'fixtures',
@@ -683,7 +683,7 @@ describe('CliRepl', function () {
683683

684684
it('does not print filenames if --quiet is implied', async function () {
685685
const filename1 = path.resolve(
686-
__dirname,
686+
import.meta.dirname,
687687
'..',
688688
'test',
689689
'fixtures',
@@ -700,7 +700,7 @@ describe('CliRepl', function () {
700700

701701
it('forwards the error it if loading the file throws', async function () {
702702
const filename1 = path.resolve(
703-
__dirname,
703+
import.meta.dirname,
704704
'..',
705705
'test',
706706
'fixtures',
@@ -1633,7 +1633,7 @@ describe('CliRepl', function () {
16331633
it('posts analytics event for load() calls', async function () {
16341634
await cliRepl.start(await testServer.connectionString(), {});
16351635
const filenameB = path.resolve(
1636-
__dirname,
1636+
import.meta.dirname,
16371637
'..',
16381638
'test',
16391639
'fixtures',
@@ -1930,7 +1930,7 @@ describe('CliRepl', function () {
19301930
context('files loaded from command line', function () {
19311931
it('load a file if it has been specified on the command line', async function () {
19321932
const filename1 = path.resolve(
1933-
__dirname,
1933+
import.meta.dirname,
19341934
'..',
19351935
'test',
19361936
'fixtures',
@@ -1951,15 +1951,15 @@ describe('CliRepl', function () {
19511951

19521952
it('load two files if it has been specified on the command line', async function () {
19531953
const filename1 = path.resolve(
1954-
__dirname,
1954+
import.meta.dirname,
19551955
'..',
19561956
'test',
19571957
'fixtures',
19581958
'load',
19591959
'hello1.js'
19601960
);
19611961
const filename2 = path.resolve(
1962-
__dirname,
1962+
import.meta.dirname,
19631963
'..',
19641964
'test',
19651965
'fixtures',
@@ -1982,7 +1982,7 @@ describe('CliRepl', function () {
19821982

19831983
it('allows doing db ops', async function () {
19841984
const filename1 = path.resolve(
1985-
__dirname,
1985+
import.meta.dirname,
19861986
'..',
19871987
'test',
19881988
'fixtures',
@@ -2001,7 +2001,7 @@ describe('CliRepl', function () {
20012001

20022002
it('allows doing db ops (--eval variant)', async function () {
20032003
const filename1 = path.resolve(
2004-
__dirname,
2004+
import.meta.dirname,
20052005
'..',
20062006
'test',
20072007
'fixtures',
@@ -2022,7 +2022,7 @@ describe('CliRepl', function () {
20222022

20232023
it('drops into a shell if --shell is passed', async function () {
20242024
const filename1 = path.resolve(
2025-
__dirname,
2025+
import.meta.dirname,
20262026
'..',
20272027
'test',
20282028
'fixtures',
@@ -2054,7 +2054,7 @@ describe('CliRepl', function () {
20542054
'print("hi from mongoshrc")'
20552055
);
20562056
const filename1 = path.resolve(
2057-
__dirname,
2057+
import.meta.dirname,
20582058
'..',
20592059
'test',
20602060
'fixtures',
@@ -2079,7 +2079,7 @@ describe('CliRepl', function () {
20792079
'print("hi from mongoshrc")'
20802080
);
20812081
const filename1 = path.resolve(
2082-
__dirname,
2082+
import.meta.dirname,
20832083
'..',
20842084
'test',
20852085
'fixtures',
@@ -2102,7 +2102,7 @@ describe('CliRepl', function () {
21022102

21032103
it('isInteractive() is false for --eval without --shell', async function () {
21042104
const filename1 = path.resolve(
2105-
__dirname,
2105+
import.meta.dirname,
21062106
'..',
21072107
'test',
21082108
'fixtures',
@@ -2123,7 +2123,7 @@ describe('CliRepl', function () {
21232123

21242124
it('isInteractive() is true for --eval with --shell (eval)', async function () {
21252125
const filename1 = path.resolve(
2126-
__dirname,
2126+
import.meta.dirname,
21272127
'..',
21282128
'test',
21292129
'fixtures',
@@ -2146,7 +2146,7 @@ describe('CliRepl', function () {
21462146

21472147
it('isInteractive() is false for loaded file without --shell', async function () {
21482148
const filename1 = path.resolve(
2149-
__dirname,
2149+
import.meta.dirname,
21502150
'..',
21512151
'test',
21522152
'fixtures',
@@ -2165,7 +2165,7 @@ describe('CliRepl', function () {
21652165

21662166
it('isInteractive() is true for --eval with --shell (filenames)', async function () {
21672167
const filename1 = path.resolve(
2168-
__dirname,
2168+
import.meta.dirname,
21692169
'..',
21702170
'test',
21712171
'fixtures',

packages/cli-repl/src/config-directory.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('home directory management', function () {
2222

2323
beforeEach(function () {
2424
base = path.resolve(
25-
__dirname,
25+
import.meta.dirname,
2626
'..',
2727
'..',
2828
'..',

packages/cli-repl/src/run.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('CLI entry point', function () {
99
const pathToRun = [
1010
'-r',
1111
'ts-node/register',
12-
path.resolve(__dirname, 'run.ts'),
12+
path.resolve(import.meta.dirname, 'run.ts'),
1313
];
1414
async function run(
1515
args: string[],
@@ -39,7 +39,15 @@ describe('CLI entry point', function () {
3939

4040
it('runs Node.js scripts if MONGOSH_RUN_NODE_SCRIPT is passed', async function () {
4141
const { stdout } = await run(
42-
[path.resolve(__dirname, '..', 'test', 'fixtures', 'nodescript.js')],
42+
[
43+
path.resolve(
44+
import.meta.dirname,
45+
'..',
46+
'test',
47+
'fixtures',
48+
'nodescript.js'
49+
),
50+
],
4351
{ MONGOSH_RUN_NODE_SCRIPT: '1' }
4452
);
4553
expect(stdout).to.include('works!');

packages/cli-repl/src/smoke-tests.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('smoke tests', function () {
2323
process.execPath,
2424
'-r',
2525
'ts-node/register',
26-
path.resolve(__dirname, 'run.ts'),
26+
path.resolve(import.meta.dirname, 'run.ts'),
2727
'--cryptSharedLibPath',
2828
cryptLibrary,
2929
],

packages/cli-repl/src/tls-certificate-selector.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('arg-mapper.applyTlsCertificateSelector', function () {
88
let exportCertificateAndPrivateKey: sinon.SinonStub;
99
beforeEach(function () {
1010
process.env.TEST_OS_EXPORT_CERTIFICATE_AND_KEY_PATH = path.resolve(
11-
__dirname,
11+
import.meta.dirname,
1212
'..',
1313
'test',
1414
'fixtures',

0 commit comments

Comments
 (0)