-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
module: development and production exports conditions #32869
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Flags: --experimental-wasm-modules | ||
import '../common/index.mjs'; | ||
import { path } from '../common/fixtures.mjs'; | ||
import { strictEqual } from 'assert'; | ||
import { spawnSync } from 'child_process'; | ||
|
||
{ | ||
const output = spawnSync(process.execPath, [path('/pkgexports-dev.mjs')], { | ||
env: Object.assign({}, process.env, { | ||
NODE_ENV: 'production' | ||
}) | ||
}); | ||
strictEqual(output.stdout.toString().trim(), 'production'); | ||
} | ||
|
||
{ | ||
const output = spawnSync(process.execPath, [path('/pkgexports-dev.mjs')], { | ||
}); | ||
strictEqual(output.stdout.toString().trim(), 'development'); | ||
} | ||
|
||
{ | ||
const output = spawnSync(process.execPath, [path('/pkgexports-dev.mjs')], { | ||
NODE_ENV: 'any' | ||
}); | ||
strictEqual(output.stdout.toString().trim(), 'development'); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { fileURLToPath } from 'url'; | ||
import { createRequire } from 'module'; | ||
import { strictEqual } from 'assert'; | ||
|
||
const require = createRequire(fileURLToPath(import.meta.url)); | ||
|
||
const production = process.env.NODE_ENV === 'production'; | ||
const expectValue = production ? 'production' : 'development'; | ||
|
||
strictEqual(require('pkgexports-dev'), expectValue); | ||
|
||
(async () => { | ||
const { default: value } = await import('pkgexports-dev'); | ||
strictEqual(value, expectValue); | ||
|
||
console.log(expectValue); | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not clear on how this works at all. is this production for "require" or for "import"? what about for "browser" or for "node"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just updated the example to a case where
production
andbrowser
are used together. These conditions are fully orthogonal if we are still allowed to use that word, so by default it applies for both require and import.