Skip to content

Commit 7530bd0

Browse files
committed
use not foreign condition
1 parent 39d1ef7 commit 7530bd0

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

packages/nextjs/src/config/turbopack/generateValueInjectionRules.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export function generateValueInjectionRules({
5555
rules.push({
5656
matcher: '**/instrumentation-client.*',
5757
rule: {
58+
// Only run on user code, not node_modules or Next.js internals
59+
condition: { not: 'foreign' },
5860
loaders: [
5961
{
6062
loader: path.resolve(__dirname, '..', 'loaders', 'valueInjectionLoader.js'),
@@ -72,6 +74,8 @@ export function generateValueInjectionRules({
7274
rules.push({
7375
matcher: '**/instrumentation.*',
7476
rule: {
77+
// Only run on user code, not node_modules or Next.js internals
78+
condition: { not: 'foreign' },
7579
loaders: [
7680
{
7781
loader: path.resolve(__dirname, '..', 'loaders', 'valueInjectionLoader.js'),

packages/nextjs/src/config/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,17 @@ type TurbopackRuleCondition = {
849849
path: string | RegExp;
850850
};
851851

852+
// Condition used to filter when a loader rule applies.
853+
// Supports built-in string conditions ('foreign', 'browser', 'development', 'production', 'node', 'edge-light')
854+
// and boolean operators matching the Turbopack advanced condition syntax.
855+
type TurbopackRuleConditionFilter =
856+
| string
857+
| { not: TurbopackRuleConditionFilter }
858+
| { all: TurbopackRuleConditionFilter[] }
859+
| { any: TurbopackRuleConditionFilter[] }
860+
| { path: string | RegExp }
861+
| { content: RegExp };
862+
852863
export type TurbopackRuleConfigItemOrShortcut = TurbopackLoaderItem[] | TurbopackRuleConfigItem;
853864

854865
export type TurbopackMatcherWithRule = {
@@ -859,6 +870,7 @@ export type TurbopackMatcherWithRule = {
859870
type TurbopackRuleConfigItemOptions = {
860871
loaders: TurbopackLoaderItem[];
861872
as?: string;
873+
condition?: TurbopackRuleConditionFilter;
862874
};
863875

864876
type TurbopackRuleConfigItem =

packages/nextjs/test/config/turbopack/constructTurbopackConfig.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe('constructTurbopackConfig', () => {
4040
expect(result).toEqual({
4141
rules: {
4242
'**/instrumentation.*': {
43+
condition: { not: 'foreign' },
4344
loaders: [
4445
{
4546
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -66,6 +67,7 @@ describe('constructTurbopackConfig', () => {
6667
expect(result).toEqual({
6768
rules: {
6869
'**/instrumentation-client.*': {
70+
condition: { not: 'foreign' },
6971
loaders: [
7072
{
7173
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -78,6 +80,7 @@ describe('constructTurbopackConfig', () => {
7880
],
7981
},
8082
'**/instrumentation.*': {
83+
condition: { not: 'foreign' },
8184
loaders: [
8285
{
8386
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -164,6 +167,7 @@ describe('constructTurbopackConfig', () => {
164167
rules: {
165168
'*.test.js': ['jest-loader'],
166169
'**/instrumentation.*': {
170+
condition: { not: 'foreign' },
167171
loaders: [
168172
{
169173
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -203,6 +207,7 @@ describe('constructTurbopackConfig', () => {
203207
rules: {
204208
'*.test.js': ['jest-loader'],
205209
'**/instrumentation-client.*': {
210+
condition: { not: 'foreign' },
206211
loaders: [
207212
{
208213
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -215,6 +220,7 @@ describe('constructTurbopackConfig', () => {
215220
],
216221
},
217222
'**/instrumentation.*': {
223+
condition: { not: 'foreign' },
218224
loaders: [
219225
{
220226
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -256,6 +262,7 @@ describe('constructTurbopackConfig', () => {
256262
expect(result).toEqual({
257263
rules: {
258264
'**/instrumentation-client.*': {
265+
condition: { not: 'foreign' },
259266
loaders: [
260267
{
261268
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -286,6 +293,7 @@ describe('constructTurbopackConfig', () => {
286293
expect(result).toEqual({
287294
rules: {
288295
'**/instrumentation-client.*': {
296+
condition: { not: 'foreign' },
289297
loaders: [
290298
{
291299
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -298,6 +306,7 @@ describe('constructTurbopackConfig', () => {
298306
],
299307
},
300308
'**/instrumentation.*': {
309+
condition: { not: 'foreign' },
301310
loaders: [
302311
{
303312
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -332,6 +341,7 @@ describe('constructTurbopackConfig', () => {
332341
expect(result).toEqual({
333342
rules: {
334343
'**/instrumentation-client.*': {
344+
condition: { not: 'foreign' },
335345
loaders: [
336346
{
337347
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -344,6 +354,7 @@ describe('constructTurbopackConfig', () => {
344354
],
345355
},
346356
'**/instrumentation.*': {
357+
condition: { not: 'foreign' },
347358
loaders: [
348359
{
349360
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -374,6 +385,7 @@ describe('constructTurbopackConfig', () => {
374385
expect(result).toEqual({
375386
rules: {
376387
'**/instrumentation-client.*': {
388+
condition: { not: 'foreign' },
377389
loaders: [
378390
{
379391
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -386,6 +398,7 @@ describe('constructTurbopackConfig', () => {
386398
],
387399
},
388400
'**/instrumentation.*': {
401+
condition: { not: 'foreign' },
389402
loaders: [
390403
{
391404
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -414,6 +427,7 @@ describe('constructTurbopackConfig', () => {
414427
expect(result).toEqual({
415428
rules: {
416429
'**/instrumentation-client.*': {
430+
condition: { not: 'foreign' },
417431
loaders: [
418432
{
419433
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -426,6 +440,7 @@ describe('constructTurbopackConfig', () => {
426440
],
427441
},
428442
'**/instrumentation.*': {
443+
condition: { not: 'foreign' },
429444
loaders: [
430445
{
431446
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -469,6 +484,7 @@ describe('constructTurbopackConfig', () => {
469484
rules: {
470485
'*.css': ['css-loader'],
471486
'**/instrumentation-client.*': {
487+
condition: { not: 'foreign' },
472488
loaders: [
473489
{
474490
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -482,6 +498,7 @@ describe('constructTurbopackConfig', () => {
482498
],
483499
},
484500
'**/instrumentation.*': {
501+
condition: { not: 'foreign' },
485502
loaders: [
486503
{
487504
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -513,6 +530,7 @@ describe('constructTurbopackConfig', () => {
513530
expect(result).toEqual({
514531
rules: {
515532
'**/instrumentation-client.*': {
533+
condition: { not: 'foreign' },
516534
loaders: [
517535
{
518536
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -525,6 +543,7 @@ describe('constructTurbopackConfig', () => {
525543
],
526544
},
527545
'**/instrumentation.*': {
546+
condition: { not: 'foreign' },
528547
loaders: [
529548
{
530549
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -579,6 +598,7 @@ describe('constructTurbopackConfig', () => {
579598
expect(result).toEqual({
580599
rules: {
581600
'**/instrumentation-client.*': {
601+
condition: { not: 'foreign' },
582602
loaders: [
583603
{
584604
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -591,6 +611,7 @@ describe('constructTurbopackConfig', () => {
591611
],
592612
},
593613
'**/instrumentation.*': {
614+
condition: { not: 'foreign' },
594615
loaders: [
595616
{
596617
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -620,6 +641,7 @@ describe('constructTurbopackConfig', () => {
620641
expect(result).toEqual({
621642
rules: {
622643
'**/instrumentation-client.*': {
644+
condition: { not: 'foreign' },
623645
loaders: [
624646
{
625647
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -633,6 +655,7 @@ describe('constructTurbopackConfig', () => {
633655
],
634656
},
635657
'**/instrumentation.*': {
658+
condition: { not: 'foreign' },
636659
loaders: [
637660
{
638661
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -674,6 +697,7 @@ describe('constructTurbopackConfig', () => {
674697
rules: {
675698
'*.test.js': ['jest-loader'],
676699
'**/instrumentation-client.*': {
700+
condition: { not: 'foreign' },
677701
loaders: [
678702
{
679703
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -686,6 +710,7 @@ describe('constructTurbopackConfig', () => {
686710
],
687711
},
688712
'**/instrumentation.*': {
713+
condition: { not: 'foreign' },
689714
loaders: [
690715
{
691716
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -733,6 +758,7 @@ describe('constructTurbopackConfig', () => {
733758
expect(result).toEqual({
734759
rules: {
735760
'**/instrumentation.*': {
761+
condition: { not: 'foreign' },
736762
loaders: [
737763
{
738764
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -759,6 +785,7 @@ describe('constructTurbopackConfig', () => {
759785
expect(result).toEqual({
760786
rules: {
761787
'**/instrumentation.*': {
788+
condition: { not: 'foreign' },
762789
loaders: [
763790
{
764791
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -801,6 +828,7 @@ describe('constructTurbopackConfig', () => {
801828
expect(result).toEqual({
802829
rules: {
803830
'**/instrumentation-client.*': {
831+
condition: { not: 'foreign' },
804832
loaders: [
805833
{
806834
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -843,6 +871,7 @@ describe('constructTurbopackConfig', () => {
843871
rules: {
844872
'*.scss': ['sass-loader'],
845873
'**/instrumentation-client.*': {
874+
condition: { not: 'foreign' },
846875
loaders: [
847876
{
848877
loader: '/mocked/path/to/valueInjectionLoader.js',
@@ -856,6 +885,7 @@ describe('constructTurbopackConfig', () => {
856885
],
857886
},
858887
'**/instrumentation.*': {
888+
condition: { not: 'foreign' },
859889
loaders: [
860890
{
861891
loader: '/mocked/path/to/valueInjectionLoader.js',

0 commit comments

Comments
 (0)