-
-
Notifications
You must be signed in to change notification settings - Fork 33k
esm: fix emit deprecation on legacy main resolve #48664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b5a1eb0
esm: fix emit deprecation on legacy main resolve
aduh95 ac15b0b
add tests
aduh95 94a5ce4
simplify condition
aduh95 c905e5e
add test for falsy `"main"`
aduh95 b9cada0
jsdoc
aduh95 ee13bbc
fixup! jsdoc
aduh95 ee89104
missing `await`s
aduh95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
test/es-module/test-esm-extension-lookup-deprecation.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { spawnPromisified } from '../common/index.mjs'; | ||
import * as tmpdir from '../common/tmpdir.js'; | ||
|
||
import assert from 'node:assert'; | ||
import { mkdir, writeFile } from 'node:fs/promises'; | ||
import * as path from 'node:path'; | ||
import { execPath } from 'node:process'; | ||
import { describe, it, before } from 'node:test'; | ||
|
||
describe('ESM in main field', { concurrency: true }, () => { | ||
before(() => tmpdir.refresh()); | ||
|
||
it('should handle fully-specified relative path without any warning', async () => { | ||
const cwd = path.join(tmpdir.path, Math.random().toString()); | ||
const pkgPath = path.join(cwd, './node_modules/pkg/'); | ||
await mkdir(pkgPath, { recursive: true }); | ||
await writeFile(path.join(pkgPath, './index.js'), 'console.log("Hello World!")'); | ||
await writeFile(path.join(pkgPath, './package.json'), JSON.stringify({ | ||
main: './index.js', | ||
type: 'module', | ||
})); | ||
const { code, stdout, stderr } = await spawnPromisified(execPath, [ | ||
'--input-type=module', | ||
'--eval', 'import "pkg"', | ||
], { cwd }); | ||
|
||
assert.strictEqual(stderr, ''); | ||
assert.match(stdout, /^Hello World!\r?\n$/); | ||
assert.strictEqual(code, 0); | ||
}); | ||
it('should handle fully-specified absolute path without any warning', async () => { | ||
const cwd = path.join(tmpdir.path, Math.random().toString()); | ||
const pkgPath = path.join(cwd, './node_modules/pkg/'); | ||
await mkdir(pkgPath, { recursive: true }); | ||
await writeFile(path.join(pkgPath, './index.js'), 'console.log("Hello World!")'); | ||
await writeFile(path.join(pkgPath, './package.json'), JSON.stringify({ | ||
main: path.join(pkgPath, './index.js'), | ||
type: 'module', | ||
})); | ||
const { code, stdout, stderr } = await spawnPromisified(execPath, [ | ||
'--input-type=module', | ||
'--eval', 'import "pkg"', | ||
], { cwd }); | ||
|
||
assert.strictEqual(stderr, ''); | ||
assert.match(stdout, /^Hello World!\r?\n$/); | ||
assert.strictEqual(code, 0); | ||
}); | ||
|
||
it('should emit warning when "main" and "exports" are missing', async () => { | ||
const cwd = path.join(tmpdir.path, Math.random().toString()); | ||
const pkgPath = path.join(cwd, './node_modules/pkg/'); | ||
await mkdir(pkgPath, { recursive: true }); | ||
await writeFile(path.join(pkgPath, './index.js'), 'console.log("Hello World!")'); | ||
await writeFile(path.join(pkgPath, './package.json'), JSON.stringify({ | ||
type: 'module', | ||
})); | ||
const { code, stdout, stderr } = await spawnPromisified(execPath, [ | ||
'--input-type=module', | ||
'--eval', 'import "pkg"', | ||
], { cwd }); | ||
|
||
assert.match(stderr, /\[DEP0151\]/); | ||
assert.match(stdout, /^Hello World!\r?\n$/); | ||
assert.strictEqual(code, 0); | ||
}); | ||
it('should emit warning when "main" is falsy', async () => { | ||
const cwd = path.join(tmpdir.path, Math.random().toString()); | ||
const pkgPath = path.join(cwd, './node_modules/pkg/'); | ||
await mkdir(pkgPath, { recursive: true }); | ||
await writeFile(path.join(pkgPath, './index.js'), 'console.log("Hello World!")'); | ||
await writeFile(path.join(pkgPath, './package.json'), JSON.stringify({ | ||
type: 'module', | ||
main: '', | ||
})); | ||
const { code, stdout, stderr } = await spawnPromisified(execPath, [ | ||
'--input-type=module', | ||
'--eval', 'import "pkg"', | ||
], { cwd }); | ||
|
||
assert.match(stderr, /\[DEP0151\]/); | ||
assert.match(stdout, /^Hello World!\r?\n$/); | ||
assert.strictEqual(code, 0); | ||
}); | ||
it('should emit warning when "main" is a relative path without extension', async () => { | ||
const cwd = path.join(tmpdir.path, Math.random().toString()); | ||
const pkgPath = path.join(cwd, './node_modules/pkg/'); | ||
await mkdir(pkgPath, { recursive: true }); | ||
await writeFile(path.join(pkgPath, './index.js'), 'console.log("Hello World!")'); | ||
await writeFile(path.join(pkgPath, './package.json'), JSON.stringify({ | ||
main: 'index', | ||
type: 'module', | ||
})); | ||
const { code, stdout, stderr } = await spawnPromisified(execPath, [ | ||
'--input-type=module', | ||
'--eval', 'import "pkg"', | ||
], { cwd }); | ||
|
||
assert.match(stderr, /\[DEP0151\]/); | ||
assert.match(stdout, /^Hello World!\r?\n$/); | ||
assert.strictEqual(code, 0); | ||
}); | ||
it('should emit warning when "main" is an absolute path without extension', async () => { | ||
const cwd = path.join(tmpdir.path, Math.random().toString()); | ||
const pkgPath = path.join(cwd, './node_modules/pkg/'); | ||
await mkdir(pkgPath, { recursive: true }); | ||
await writeFile(path.join(pkgPath, './index.js'), 'console.log("Hello World!")'); | ||
await writeFile(path.join(pkgPath, './package.json'), JSON.stringify({ | ||
main: pkgPath + 'index', | ||
type: 'module', | ||
})); | ||
const { code, stdout, stderr } = await spawnPromisified(execPath, [ | ||
'--input-type=module', | ||
'--eval', 'import "pkg"', | ||
], { cwd }); | ||
|
||
assert.match(stderr, /\[DEP0151\]/); | ||
assert.match(stdout, /^Hello World!\r?\n$/); | ||
assert.strictEqual(code, 0); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.