Skip to content

Commit 82a4aaa

Browse files
committed
Lint
1 parent c3a86aa commit 82a4aaa

7 files changed

Lines changed: 186 additions & 168 deletions

File tree

lib/internal/modules/esm/formats.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function getFormatOfExtensionlessFile(url) {
5656
return 'wasm';
5757
}
5858
} finally {
59-
if (fd) { closeSync(fd) };
59+
if (fd) { closeSync(fd); }
6060
}
6161

6262
return 'module';

lib/internal/modules/esm/get_format.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const {
2020
const experimentalNetworkImports =
2121
getOptionValue('--experimental-network-imports');
2222
const typeFlag = getOptionValue('--experimental-type');
23-
const defaultType = typeFlag === 'module' ? 'module' : 'commonjs'; // ! This is where we flip the default to ES modules someday
23+
// The next line is where we flip the default to ES modules someday.
24+
const defaultType = typeFlag === 'module' ? 'module' : 'commonjs';
2425
const { getPackageType, getPackageScopeConfig } = require('internal/modules/esm/resolve');
2526
const { fileURLToPath } = require('internal/url');
2627
const { ERR_UNKNOWN_FILE_EXTENSION } = require('internal/errors').codes;
@@ -73,7 +74,8 @@ function extname(url) {
7374

7475
/**
7576
* Determine whether the given file URL is under a `node_modules` folder.
76-
* This function assumes that the input has already been verified to be a `file:` URL, and is a file rather than a folder.
77+
* This function assumes that the input has already been verified to be a `file:` URL,
78+
* and is a file rather than a folder.
7779
* @param {URL} url
7880
*/
7981
function underNodeModules(url) {
@@ -110,13 +112,13 @@ function getFileProtocolModuleFormat(url, context, ignoreErrors) {
110112
return 'commonjs';
111113
}
112114
// If package type is `module`, fall through to the error case below
113-
} else { // defaultType === 'module'
115+
} else { // Else defaultType === 'module'
114116
if (underNodeModules(url)) { // Exception for package scopes under `node_modules`
115117
return 'commonjs';
116118
}
117119
if (packageType === 'none' || packageType === 'module') {
118120
return getFormatOfExtensionlessFile(url);
119-
} // else packageType === 'commonjs'
121+
} // Else packageType === 'commonjs'
120122
return 'commonjs';
121123
}
122124
}
@@ -133,10 +135,9 @@ function getFileProtocolModuleFormat(url, context, ignoreErrors) {
133135
const fileBasename = basename(filepath);
134136
const relativePath = StringPrototypeSlice(relative(config.pjsonPath, filepath), 1);
135137
suggestion = 'Loading extensionless files is not supported inside of "type":"module" package.json contexts ' +
136-
`without --experimental-type=module. The package.json file ${config.pjsonPath} caused this ` +
137-
`"type":"module" context. Try changing ${filepath} to have a file extension. Note the "bin" ` +
138-
'field of package.json can point to a file with an extension, for example ' +
139-
`{"type":"module","bin":{"${fileBasename}":"${relativePath}.js"}}`;
138+
`without --experimental-type=module. The package.json file ${config.pjsonPath} caused this "type":"module" ` +
139+
`context. Try changing ${filepath} to have a file extension. Note the "bin" field of package.json can point ` +
140+
`to a file with an extension, for example {"type":"module","bin":{"${fileBasename}":"${relativePath}.js"}}`;
140141
}
141142
throw new ERR_UNKNOWN_FILE_EXTENSION(ext, filepath, suggestion);
142143
}

lib/internal/modules/esm/resolve.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const preserveSymlinks = getOptionValue('--preserve-symlinks');
3535
const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main');
3636
const experimentalNetworkImports =
3737
getOptionValue('--experimental-network-imports');
38-
const typeFlag = getOptionValue('--experimental-type');
3938
const inputTypeFlag = getOptionValue('--input-type');
4039
const { URL, pathToFileURL, fileURLToPath, isURL } = require('internal/url');
4140
const { getCWDURL } = require('internal/util');

test/es-module/test-esm-type-flag-errors.mjs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,29 @@ import * as fixtures from '../common/fixtures.mjs';
33
import { describe, it } from 'node:test';
44
import { match, strictEqual } from 'node:assert';
55

6-
describe('--experimental-type=module should not affect the interpretation of files with unknown extensions', { concurrency: true }, () => {
7-
it('should error on an entry point with an unknown extension', async () => {
8-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
9-
'--experimental-type=module',
10-
fixtures.path('es-modules/package-type-module/extension.unknown'),
11-
]);
6+
describe('--experimental-type=module should not affect the interpretation of files with unknown extensions',
7+
{ concurrency: true }, () => {
8+
it('should error on an entry point with an unknown extension', async () => {
9+
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
10+
'--experimental-type=module',
11+
fixtures.path('es-modules/package-type-module/extension.unknown'),
12+
]);
1213

13-
match(stderr, /ERR_UNKNOWN_FILE_EXTENSION/);
14-
strictEqual(stdout, '');
15-
strictEqual(code, 1);
16-
strictEqual(signal, null);
17-
});
14+
match(stderr, /ERR_UNKNOWN_FILE_EXTENSION/);
15+
strictEqual(stdout, '');
16+
strictEqual(code, 1);
17+
strictEqual(signal, null);
18+
});
1819

19-
it('should error on an import with an unknown extension', async () => {
20-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
21-
'--experimental-type=module',
22-
fixtures.path('es-modules/package-type-module/imports-unknownext.mjs'),
23-
]);
20+
it('should error on an import with an unknown extension', async () => {
21+
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
22+
'--experimental-type=module',
23+
fixtures.path('es-modules/package-type-module/imports-unknownext.mjs'),
24+
]);
2425

25-
match(stderr, /ERR_UNKNOWN_FILE_EXTENSION/);
26-
strictEqual(stdout, '');
27-
strictEqual(code, 1);
28-
strictEqual(signal, null);
29-
});
30-
});
26+
match(stderr, /ERR_UNKNOWN_FILE_EXTENSION/);
27+
strictEqual(stdout, '');
28+
strictEqual(code, 1);
29+
strictEqual(signal, null);
30+
});
31+
});

test/es-module/test-esm-type-flag-loose-files.mjs

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,70 +4,72 @@ import * as fixtures from '../common/fixtures.mjs';
44
import { describe, it } from 'node:test';
55
import { strictEqual } from 'node:assert';
66

7-
describe('the type flag should change the interpretation of certain files outside of any package scope', { concurrency: true }, () => {
8-
it('should run as ESM a .js file that is outside of any package scope', async () => {
9-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
10-
'--experimental-type=module',
11-
fixtures.path('es-modules/loose.js'),
12-
]);
7+
describe('the type flag should change the interpretation of certain files outside of any package scope',
8+
{ concurrency: true }, () => {
9+
it('should run as ESM a .js file that is outside of any package scope', async () => {
10+
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
11+
'--experimental-type=module',
12+
fixtures.path('es-modules/loose.js'),
13+
]);
1314

14-
strictEqual(stderr, '');
15-
strictEqual(stdout, 'executed\n');
16-
strictEqual(code, 0);
17-
strictEqual(signal, null);
18-
});
15+
strictEqual(stderr, '');
16+
strictEqual(stdout, 'executed\n');
17+
strictEqual(code, 0);
18+
strictEqual(signal, null);
19+
});
1920

20-
it('should run as ESM an extensionless JavaScript file that is outside of any package scope', async () => {
21-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
22-
'--experimental-type=module',
23-
fixtures.path('es-modules/noext-esm'),
24-
]);
21+
it('should run as ESM an extensionless JavaScript file that is outside of any package scope', async () => {
22+
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
23+
'--experimental-type=module',
24+
fixtures.path('es-modules/noext-esm'),
25+
]);
2526

26-
strictEqual(stderr, '');
27-
strictEqual(stdout, 'executed\n');
28-
strictEqual(code, 0);
29-
strictEqual(signal, null);
30-
});
27+
strictEqual(stderr, '');
28+
strictEqual(stdout, 'executed\n');
29+
strictEqual(code, 0);
30+
strictEqual(signal, null);
31+
});
3132

32-
it('should run as Wasm an extensionless Wasm file that is outside of any package scope', async () => {
33-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
34-
'--experimental-type=module',
35-
'--experimental-wasm-modules',
36-
'--no-warnings',
37-
fixtures.path('es-modules/noext-wasm'),
38-
]);
33+
it('should run as Wasm an extensionless Wasm file that is outside of any package scope', async () => {
34+
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
35+
'--experimental-type=module',
36+
'--experimental-wasm-modules',
37+
'--no-warnings',
38+
fixtures.path('es-modules/noext-wasm'),
39+
]);
3940

40-
strictEqual(stderr, '');
41-
strictEqual(stdout, '');
42-
strictEqual(code, 0);
43-
strictEqual(signal, null);
44-
});
41+
strictEqual(stderr, '');
42+
strictEqual(stdout, '');
43+
strictEqual(code, 0);
44+
strictEqual(signal, null);
45+
});
4546

46-
it('should import as ESM a .js file that is outside of any package scope', async () => {
47-
const { default: defaultExport } = await import(fixtures.fileURL('es-modules/loose.js'));
48-
strictEqual(defaultExport, 'module');
49-
});
47+
it('should import as ESM a .js file that is outside of any package scope', async () => {
48+
const { default: defaultExport } = await import(fixtures.fileURL('es-modules/loose.js'));
49+
strictEqual(defaultExport, 'module');
50+
});
5051

51-
it('should import as ESM an extensionless JavaScript file that is outside of any package scope', async () => {
52-
const { default: defaultExport } = await import(fixtures.fileURL('es-modules/noext-esm'));
53-
strictEqual(defaultExport, 'module');
54-
});
52+
it('should import as ESM an extensionless JavaScript file that is outside of any package scope',
53+
async () => {
54+
const { default: defaultExport } = await import(fixtures.fileURL('es-modules/noext-esm'));
55+
strictEqual(defaultExport, 'module');
56+
});
5557

56-
it('should import as Wasm an extensionless Wasm file that is outside of any package scope', async () => {
57-
const { add } = await import(fixtures.fileURL('es-modules/noext-wasm'));
58-
strictEqual(add(1, 2), 3);
59-
});
58+
it('should import as Wasm an extensionless Wasm file that is outside of any package scope', async () => {
59+
const { add } = await import(fixtures.fileURL('es-modules/noext-wasm'));
60+
strictEqual(add(1, 2), 3);
61+
});
6062

61-
it('should check as ESM input passed via --check', async () => {
62-
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
63-
'--experimental-type=module',
64-
'--check',
65-
fixtures.path('es-modules/loose.js'),
66-
]);
63+
it('should check as ESM input passed via --check', async () => {
64+
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [
65+
'--experimental-type=module',
66+
'--check',
67+
fixtures.path('es-modules/loose.js'),
68+
]);
6769

68-
strictEqual(stderr, '');
69-
strictEqual(stdout, '');
70-
strictEqual(code, 0);
71-
strictEqual(signal, null);
72-
});
73-
});
70+
strictEqual(stderr, '');
71+
strictEqual(stdout, '');
72+
strictEqual(code, 0);
73+
strictEqual(signal, null);
74+
});
75+
});

0 commit comments

Comments
 (0)