Skip to content

use enableDevMode() or development condition instead of NODE_ENV #4464

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

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cspell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ words:
- deno
- denoland
- hashbang
- Rspack
- Rollup
- Rspack
- Rsbuild
- Turbopack

# Website tech
- Nextra
Expand Down
2 changes: 1 addition & 1 deletion integrationTests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The `conditions` subdirectory contains tests that verify the conditional exports

### Verifying Development Mode Tests

Each subdirectory represents a different environment/bundler demonstrating enabling development mode by setting the environment variable `NODE_ENV` to `development`.
Each subdirectory represents a different platform/bundler demonstrating enabling development mode by enabling the `development` condition or by calling `enableDevMode()`.

### Verifying Production Mode Tests

Expand Down
2 changes: 1 addition & 1 deletion integrationTests/dev-bun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"description": "graphql-js development mode should work with Bun",
"private": true,
"scripts": {
"test": "docker run --rm --volume \"$PWD\":/usr/src/app -w /usr/src/app oven/bun:\"$BUN_VERSION\"-slim bun test.js"
"test": "docker run --rm --volume \"$PWD\":/usr/src/app -w /usr/src/app oven/bun:\"$BUN_VERSION\"-slim bun --conditions=development test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
Expand Down
4 changes: 3 additions & 1 deletion integrationTests/dev-bun/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { isObjectType } from 'graphql';
import { enableDevMode, isObjectType } from 'graphql';

enableDevMode();

class GraphQLObjectType {
get [Symbol.toStringTag]() {
Expand Down
10 changes: 10 additions & 0 deletions integrationTests/dev-deno-condition-based/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "graphql-js condition-based development mode should work with Deno",
"private": true,
"scripts": {
"test": "docker run --rm --volume \"$PWD\":/usr/src/app -w /usr/src/app denoland/deno:latest deno run --conditions=development --allow-env=NODE_ENV test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GraphQLObjectType {
try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Deno implicit dev mode.',
'Expected isObjectType to throw an error in Deno condition-based development mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"description": "graphql-js development mode should work with Deno",
"description": "graphql-js explicit development mode should work with Deno",
"private": true,
"scripts": {
"test": "docker run --rm --volume \"$PWD\":/usr/src/app -w /usr/src/app denoland/deno:alpine-\"$DENO_VERSION\" deno run --allow-env=NODE_ENV test.js"
Expand Down
20 changes: 20 additions & 0 deletions integrationTests/dev-deno-explicit/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { enableDevMode, isObjectType } from 'graphql';

enableDevMode();

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Deno explicit development mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
2 changes: 1 addition & 1 deletion integrationTests/dev-esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"type": "module",
"scripts": {
"build": "esbuild index.js --bundle --outfile=dist/bundle.js --format=esm",
"build": "esbuild index.js --bundle --outfile=dist/bundle.js --format=esm --conditions=development",
"test": "npm run build && node dist/bundle.js"
},
"dependencies": {
Expand Down
22 changes: 22 additions & 0 deletions integrationTests/dev-jest/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const jestConfig = {
testEnvironment: 'node',

testEnvironmentOptions: {
customExportConditions: ['development'],
},

transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest'],
},

transformIgnorePatterns: [
// Allow 'graphql' to be transformed, ignore all other node_modules.
// This regex means: "match /node_modules/ unless it's followed by graphql/"
'/node_modules/(?!graphql/)',
// Keep Jest's default for .pnp.js files if using Yarn PnP
'\\.pnp\\.[^\\/]+$',
],
};

// eslint-disable-next-line no-restricted-exports, import/no-default-export
export default jestConfig;
6 changes: 4 additions & 2 deletions integrationTests/dev-jest/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"description": "graphql-js development mode should work with Jest",
"description": "graphql-js development mode should work with Jest and SWC",
"private": true,
"type": "module",
"scripts": {
Expand All @@ -9,6 +9,8 @@
"graphql": "file:../graphql.tgz"
},
"devDependencies": {
"jest": "^29.7.0"
"jest": "^29.7.0",
"@swc/core": "^1.6.0",
"@swc/jest": "^0.2.36"
}
}
11 changes: 11 additions & 0 deletions integrationTests/dev-node-condition-based/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"description": "graphql-js condition-based development mode should work with node",
"private": true,
"type": "module",
"scripts": {
"test": "node --conditions=development test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GraphQLObjectType {
try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Node.js implicit dev mode.',
'Expected isObjectType to throw an error in Node.js condition-based development mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"description": "graphql-js development mode should work with node",
"description": "graphql-js explicit development mode should work with node",
"private": true,
"type": "module",
"scripts": {
Expand Down
20 changes: 20 additions & 0 deletions integrationTests/dev-node-explicit/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { enableDevMode, isObjectType } from 'graphql';

enableDevMode();

class GraphQLObjectType {
get [Symbol.toStringTag]() {
return 'GraphQLObjectType';
}
}

try {
isObjectType(new GraphQLObjectType());
throw new Error(
'Expected isObjectType to throw an error in Node.js development mode.',
);
} catch (error) {
if (!error.message.includes('from another module or realm')) {
throw error;
}
}
3 changes: 2 additions & 1 deletion integrationTests/dev-rollup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"graphql": "file:../graphql.tgz",
"rollup": "^4.0.0"
"rollup": "^4.0.0",
"@rollup/plugin-node-resolve": "^15.0.0"
}
}
8 changes: 8 additions & 0 deletions integrationTests/dev-rollup/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
// eslint-disable-next-line n/no-missing-import
import resolve from '@rollup/plugin-node-resolve';

const rollupConfig = {
input: 'index.js',
output: {
file: 'dist/bundle.js',
format: 'es',
},
plugins: [
resolve({
exportConditions: ['development'],
}),
],
};

// eslint-disable-next-line no-restricted-exports, import/no-default-export
Expand Down
3 changes: 3 additions & 0 deletions integrationTests/dev-rspack/rspack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const rspack = {
},
mode: 'development',
target: 'node',
resolve: {
conditionNames: ['development'],
},
};

// eslint-disable-next-line no-restricted-exports, import/no-default-export
Expand Down
4 changes: 3 additions & 1 deletion integrationTests/dev-swc/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { isObjectType } from 'graphql';
import { enableDevMode, isObjectType } from 'graphql';

enableDevMode();

class GraphQLObjectType {
get [Symbol.toStringTag]() {
Expand Down
3 changes: 3 additions & 0 deletions integrationTests/dev-vitest/vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import { defineConfig } from 'vitest/config';

const vitestConfig = defineConfig({
resolve: {
conditions: ['development'],
},
test: {
include: ['**/*.test.js'],
},
Expand Down
3 changes: 3 additions & 0 deletions integrationTests/dev-webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const webpackConfig = {
},
mode: 'development',
target: 'node',
resolve: {
conditionNames: ['development'],
},
};

// eslint-disable-next-line no-restricted-exports, import/no-default-export
Expand Down
2 changes: 1 addition & 1 deletion integrationTests/prod-bun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"description": "graphql-js production mode should work with Bun",
"private": true,
"scripts": {
"test": "docker run --rm --volume \"$PWD\":/usr/src/app -w /usr/src/app oven/bun:\"$BUN_VERSION\"-slim bun --define process.env.NODE_ENV='\"production\"' test.js"
"test": "docker run --rm --volume \"$PWD\":/usr/src/app -w /usr/src/app oven/bun:\"$BUN_VERSION\"-slim bun test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
Expand Down
4 changes: 0 additions & 4 deletions integrationTests/prod-deno/env-shim.js

This file was deleted.

2 changes: 1 addition & 1 deletion integrationTests/prod-deno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"description": "graphql-js production mode should work with Deno",
"private": true,
"scripts": {
"test": "docker run --rm --volume \"$PWD\":/usr/src/app -w /usr/src/app denoland/deno:alpine-\"$DENO_VERSION\" deno run --allow-env --preload env-shim.js test.js"
"test": "docker run --rm --volume \"$PWD\":/usr/src/app -w /usr/src/app denoland/deno:alpine-\"$DENO_VERSION\" deno run test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
Expand Down
2 changes: 1 addition & 1 deletion integrationTests/prod-esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"type": "module",
"scripts": {
"build": "esbuild index.js --bundle --outfile=dist/bundle.js --format=esm --define:process.env.NODE_ENV='\"production\"'",
"build": "esbuild index.js --bundle --outfile=dist/bundle.js --format=esm",
"test": "npm run build && node dist/bundle.js"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion integrationTests/prod-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"type": "module",
"scripts": {
"test": "NODE_ENV=production node test.js"
"test": "node test.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz"
Expand Down
3 changes: 1 addition & 2 deletions integrationTests/prod-rollup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"dependencies": {
"graphql": "file:../graphql.tgz",
"rollup": "^4.0.0",
"@rollup/plugin-node-resolve": "^15.0.0",
"@rollup/plugin-replace": "^5.0.0"
"@rollup/plugin-node-resolve": "^15.0.0"
}
}
13 changes: 0 additions & 13 deletions integrationTests/prod-rollup/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
// eslint-disable-next-line n/no-missing-import
import resolve from '@rollup/plugin-node-resolve';
// eslint-disable-next-line n/no-missing-import
import replace from '@rollup/plugin-replace';

const rollupConfig = {
input: 'index.js',
output: {
file: 'dist/bundle.js',
format: 'es',
},
plugins: [
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify('production'),
include: ['node_modules/graphql/**'],
}),
resolve(),
],
};

// eslint-disable-next-line no-restricted-exports, import/no-default-export
Expand Down
2 changes: 1 addition & 1 deletion integrationTests/prod-swc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "module",
"scripts": {
"build": "swc index.js -d dist",
"test": "npm run build && NODE_ENV=production node dist/index.js"
"test": "npm run build && node dist/index.js"
},
"dependencies": {
"graphql": "file:../graphql.tgz",
Expand Down
Loading
Loading