| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 435f3dd commit 24b8585
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1931,6 +1931,15 @@ Module._extensions['.js'] = function(module, filename) { | |||
| 1931 | 1931 | } else { | |
| 1932 | 1932 | format = 'typescript'; | |
| 1933 | 1933 | } | |
| 1934 | + } else if (path.extname(filename) === '') { | ||
| 1935 | + // Extensionless files skip the .js suffix check above. When type is explicit, | ||
| 1936 | + // follow it so ESM syntax surfaces as SyntaxError for commonjs instead of | ||
| 1937 | + // silently delegating to ESM. | ||
| 1938 | + pkg = packageJsonReader.getNearestParentPackageJSON(filename); | ||
| 1939 | + const typeFromPjson = pkg?.data?.type; | ||
| 1940 | + if (typeFromPjson === 'commonjs' || typeFromPjson === 'module') { | ||
| 1941 | + format = typeFromPjson; | ||
| 1942 | + } | ||
| 1934 | 1943 | } | |
| 1935 | 1944 | const { source, format: loadedFormat } = loadSource(module, filename, format); | |
| 1936 | 1945 | // Function require shouldn't be used in ES modules when require(esm) is disabled. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,19 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + const { spawnSyncAndAssert } = require('../common/child_process'); | ||
| 5 | + const fixtures = require('../common/fixtures'); | ||
| 6 | + | ||
| 7 | + spawnSyncAndAssert(process.execPath, [ | ||
| 8 | + fixtures.path('es-modules', 'extensionless-esm-commonjs', 'script'), | ||
| 9 | + ], { | ||
| 10 | + status: 1, | ||
| 11 | + stderr: /SyntaxError: Cannot use import statement outside a module/, | ||
| 12 | + }); | ||
| 13 | + | ||
| 14 | + spawnSyncAndAssert(process.execPath, [ | ||
| 15 | + fixtures.path('es-modules', 'extensionless-esm-module', 'script'), | ||
| 16 | + ], { | ||
| 17 | + stdout: /script STARTED[\s\S]*v\d+\./, | ||
| 18 | + trim: true, | ||
| 19 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + { | ||
| 2 | + "type": "commonjs" | ||
| 3 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + #!/usr/bin/env node | ||
| 2 | + console.log('script STARTED') | ||
| 3 | + import { version } from 'node:process' | ||
| 4 | + console.log(version) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + { | ||
| 2 | + "type": "module" | ||
| 3 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + #!/usr/bin/env node | ||
| 2 | + console.log('script STARTED') | ||
| 3 | + import { version } from 'node:process' | ||
| 4 | + console.log(version) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments