Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
use not foreign condition
  • Loading branch information
chargome committed Feb 24, 2026
commit 7530bd0c67c735385864b223be459e00cf6ca2b2
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export function generateValueInjectionRules({
rules.push({
matcher: '**/instrumentation-client.*',
rule: {
// Only run on user code, not node_modules or Next.js internals
condition: { not: 'foreign' },
loaders: [
{
loader: path.resolve(__dirname, '..', 'loaders', 'valueInjectionLoader.js'),
Comment thread
sentry[bot] marked this conversation as resolved.
Expand All @@ -72,6 +74,8 @@ export function generateValueInjectionRules({
rules.push({
matcher: '**/instrumentation.*',
rule: {
// Only run on user code, not node_modules or Next.js internals
condition: { not: 'foreign' },
Comment thread
chargome marked this conversation as resolved.
Outdated
loaders: [
{
loader: path.resolve(__dirname, '..', 'loaders', 'valueInjectionLoader.js'),
Expand Down
12 changes: 12 additions & 0 deletions packages/nextjs/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,17 @@ type TurbopackRuleCondition = {
path: string | RegExp;
};

// Condition used to filter when a loader rule applies.
// Supports built-in string conditions ('foreign', 'browser', 'development', 'production', 'node', 'edge-light')
// and boolean operators matching the Turbopack advanced condition syntax.
type TurbopackRuleConditionFilter =
| string
| { not: TurbopackRuleConditionFilter }
| { all: TurbopackRuleConditionFilter[] }
| { any: TurbopackRuleConditionFilter[] }
| { path: string | RegExp }
| { content: RegExp };

export type TurbopackRuleConfigItemOrShortcut = TurbopackLoaderItem[] | TurbopackRuleConfigItem;

export type TurbopackMatcherWithRule = {
Expand All @@ -859,6 +870,7 @@ export type TurbopackMatcherWithRule = {
type TurbopackRuleConfigItemOptions = {
loaders: TurbopackLoaderItem[];
as?: string;
condition?: TurbopackRuleConditionFilter;
Comment thread
chargome marked this conversation as resolved.
};

type TurbopackRuleConfigItem =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('constructTurbopackConfig', () => {
expect(result).toEqual({
rules: {
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand All @@ -66,6 +67,7 @@ describe('constructTurbopackConfig', () => {
expect(result).toEqual({
rules: {
'**/instrumentation-client.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand All @@ -78,6 +80,7 @@ describe('constructTurbopackConfig', () => {
],
},
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -164,6 +167,7 @@ describe('constructTurbopackConfig', () => {
rules: {
'*.test.js': ['jest-loader'],
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -203,6 +207,7 @@ describe('constructTurbopackConfig', () => {
rules: {
'*.test.js': ['jest-loader'],
'**/instrumentation-client.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand All @@ -215,6 +220,7 @@ describe('constructTurbopackConfig', () => {
],
},
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -256,6 +262,7 @@ describe('constructTurbopackConfig', () => {
expect(result).toEqual({
rules: {
'**/instrumentation-client.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -286,6 +293,7 @@ describe('constructTurbopackConfig', () => {
expect(result).toEqual({
rules: {
'**/instrumentation-client.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand All @@ -298,6 +306,7 @@ describe('constructTurbopackConfig', () => {
],
},
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -332,6 +341,7 @@ describe('constructTurbopackConfig', () => {
expect(result).toEqual({
rules: {
'**/instrumentation-client.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand All @@ -344,6 +354,7 @@ describe('constructTurbopackConfig', () => {
],
},
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -374,6 +385,7 @@ describe('constructTurbopackConfig', () => {
expect(result).toEqual({
rules: {
'**/instrumentation-client.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand All @@ -386,6 +398,7 @@ describe('constructTurbopackConfig', () => {
],
},
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -414,6 +427,7 @@ describe('constructTurbopackConfig', () => {
expect(result).toEqual({
rules: {
'**/instrumentation-client.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand All @@ -426,6 +440,7 @@ describe('constructTurbopackConfig', () => {
],
},
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -469,6 +484,7 @@ describe('constructTurbopackConfig', () => {
rules: {
'*.css': ['css-loader'],
'**/instrumentation-client.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand All @@ -482,6 +498,7 @@ describe('constructTurbopackConfig', () => {
],
},
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -513,6 +530,7 @@ describe('constructTurbopackConfig', () => {
expect(result).toEqual({
rules: {
'**/instrumentation-client.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand All @@ -525,6 +543,7 @@ describe('constructTurbopackConfig', () => {
],
},
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -579,6 +598,7 @@ describe('constructTurbopackConfig', () => {
expect(result).toEqual({
rules: {
'**/instrumentation-client.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand All @@ -591,6 +611,7 @@ describe('constructTurbopackConfig', () => {
],
},
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -620,6 +641,7 @@ describe('constructTurbopackConfig', () => {
expect(result).toEqual({
rules: {
'**/instrumentation-client.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand All @@ -633,6 +655,7 @@ describe('constructTurbopackConfig', () => {
],
},
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -674,6 +697,7 @@ describe('constructTurbopackConfig', () => {
rules: {
'*.test.js': ['jest-loader'],
'**/instrumentation-client.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand All @@ -686,6 +710,7 @@ describe('constructTurbopackConfig', () => {
],
},
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -733,6 +758,7 @@ describe('constructTurbopackConfig', () => {
expect(result).toEqual({
rules: {
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand All @@ -759,6 +785,7 @@ describe('constructTurbopackConfig', () => {
expect(result).toEqual({
rules: {
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -801,6 +828,7 @@ describe('constructTurbopackConfig', () => {
expect(result).toEqual({
rules: {
'**/instrumentation-client.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down Expand Up @@ -843,6 +871,7 @@ describe('constructTurbopackConfig', () => {
rules: {
'*.scss': ['sass-loader'],
'**/instrumentation-client.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand All @@ -856,6 +885,7 @@ describe('constructTurbopackConfig', () => {
],
},
'**/instrumentation.*': {
condition: { not: 'foreign' },
loaders: [
{
loader: '/mocked/path/to/valueInjectionLoader.js',
Expand Down
Loading