Skip to content

Commit ddfdfb8

Browse files
committed
import-is-undefined is debug in node_modules
1 parent 220141e commit ddfdfb8

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

internal/bundler_tests/bundler_css_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,16 @@ func TestUndefinedImportWarningCSS(t *testing.T) {
11371137
import * as empty_css from './empty.css'
11381138
import * as empty_global_css from './empty.global-css'
11391139
import * as empty_local_css from './empty.local-css'
1140+
1141+
import * as pkg_empty_js from 'pkg/empty.js'
1142+
import * as pkg_empty_esm_js from 'pkg/empty.esm.js'
1143+
import * as pkg_empty_json from 'pkg/empty.json'
1144+
import * as pkg_empty_css from 'pkg/empty.css'
1145+
import * as pkg_empty_global_css from 'pkg/empty.global-css'
1146+
import * as pkg_empty_local_css from 'pkg/empty.local-css'
1147+
1148+
import 'pkg'
1149+
11401150
console.log(
11411151
empty_js.foo,
11421152
empty_esm_js.foo,
@@ -1145,13 +1155,49 @@ func TestUndefinedImportWarningCSS(t *testing.T) {
11451155
empty_global_css.foo,
11461156
empty_local_css.foo,
11471157
)
1158+
1159+
console.log(
1160+
pkg_empty_js.foo,
1161+
pkg_empty_esm_js.foo,
1162+
pkg_empty_json.foo,
1163+
pkg_empty_css.foo,
1164+
pkg_empty_global_css.foo,
1165+
pkg_empty_local_css.foo,
1166+
)
11481167
`,
1168+
11491169
"/empty.js": ``,
11501170
"/empty.esm.js": `export {}`,
11511171
"/empty.json": `{}`,
11521172
"/empty.css": ``,
11531173
"/empty.global-css": ``,
11541174
"/empty.local-css": ``,
1175+
1176+
"/node_modules/pkg/empty.js": ``,
1177+
"/node_modules/pkg/empty.esm.js": `export {}`,
1178+
"/node_modules/pkg/empty.json": `{}`,
1179+
"/node_modules/pkg/empty.css": ``,
1180+
"/node_modules/pkg/empty.global-css": ``,
1181+
"/node_modules/pkg/empty.local-css": ``,
1182+
1183+
// Files inside of "node_modules" should not generate a warning
1184+
"/node_modules/pkg/index.js": `
1185+
import * as empty_js from './empty.js'
1186+
import * as empty_esm_js from './empty.esm.js'
1187+
import * as empty_json from './empty.json'
1188+
import * as empty_css from './empty.css'
1189+
import * as empty_global_css from './empty.global-css'
1190+
import * as empty_local_css from './empty.local-css'
1191+
1192+
console.log(
1193+
empty_js.foo,
1194+
empty_esm_js.foo,
1195+
empty_json.foo,
1196+
empty_css.foo,
1197+
empty_global_css.foo,
1198+
empty_local_css.foo,
1199+
)
1200+
`,
11551201
},
11561202
entryPaths: []string{"/entry.js"},
11571203
options: config.Options{
@@ -1171,6 +1217,12 @@ entry.js: WARNING: Import "foo" will always be undefined because there is no mat
11711217
entry.js: WARNING: Import "foo" will always be undefined because there is no matching export in "empty.css"
11721218
entry.js: WARNING: Import "foo" will always be undefined because there is no matching export in "empty.global-css"
11731219
entry.js: WARNING: Import "foo" will always be undefined because there is no matching export in "empty.local-css"
1220+
entry.js: WARNING: Import "foo" will always be undefined because the file "node_modules/pkg/empty.js" has no exports
1221+
entry.js: WARNING: Import "foo" will always be undefined because there is no matching export in "node_modules/pkg/empty.esm.js"
1222+
entry.js: WARNING: Import "foo" will always be undefined because there is no matching export in "node_modules/pkg/empty.json"
1223+
entry.js: WARNING: Import "foo" will always be undefined because there is no matching export in "node_modules/pkg/empty.css"
1224+
entry.js: WARNING: Import "foo" will always be undefined because there is no matching export in "node_modules/pkg/empty.global-css"
1225+
entry.js: WARNING: Import "foo" will always be undefined because there is no matching export in "node_modules/pkg/empty.local-css"
11741226
`,
11751227
})
11761228
}

internal/bundler_tests/snapshots/snapshots_css.txt

+32-1
Original file line numberDiff line numberDiff line change
@@ -1250,8 +1250,36 @@ var require_empty = __commonJS({
12501250
}
12511251
});
12521252

1253+
// node_modules/pkg/empty.js
1254+
var require_empty2 = __commonJS({
1255+
"node_modules/pkg/empty.js"() {
1256+
}
1257+
});
1258+
1259+
// entry.js
1260+
var empty_js2 = __toESM(require_empty());
1261+
var pkg_empty_js = __toESM(require_empty2());
1262+
1263+
// node_modules/pkg/index.js
1264+
var empty_js = __toESM(require_empty2());
1265+
console.log(
1266+
void 0,
1267+
void 0,
1268+
void 0,
1269+
void 0,
1270+
void 0,
1271+
void 0
1272+
);
1273+
12531274
// entry.js
1254-
var empty_js = __toESM(require_empty());
1275+
console.log(
1276+
void 0,
1277+
void 0,
1278+
void 0,
1279+
void 0,
1280+
void 0,
1281+
void 0
1282+
);
12551283
console.log(
12561284
void 0,
12571285
void 0,
@@ -1265,3 +1293,6 @@ console.log(
12651293
/* empty.css */
12661294
/* empty.global-css */
12671295
/* empty.local-css */
1296+
/* node_modules/pkg/empty.css */
1297+
/* node_modules/pkg/empty.global-css */
1298+
/* node_modules/pkg/empty.local-css */

internal/linker/linker.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -2471,7 +2471,11 @@ loop:
24712471
if status == importCommonJSWithoutExports {
24722472
symbol := c.graph.Symbols.Get(tracker.importRef)
24732473
symbol.ImportItemStatus = ast.ImportItemMissing
2474-
c.log.AddID(logger.MsgID_Bundler_ImportIsUndefined, logger.Warning,
2474+
kind := logger.Warning
2475+
if helpers.IsInsideNodeModules(trackerFile.InputFile.Source.KeyPath.Text) {
2476+
kind = logger.Debug
2477+
}
2478+
c.log.AddID(logger.MsgID_Bundler_ImportIsUndefined, kind,
24752479
trackerFile.LineColumnTracker(),
24762480
js_lexer.RangeOfIdentifier(trackerFile.InputFile.Source, namedImport.AliasLoc),
24772481
fmt.Sprintf("Import %q will always be undefined because the file %q has no exports",
@@ -2510,7 +2514,11 @@ loop:
25102514
// time, so we emit a debug message and rewrite the value to the literal
25112515
// "undefined" instead of emitting an error.
25122516
symbol.ImportItemStatus = ast.ImportItemMissing
2513-
c.log.AddID(logger.MsgID_Bundler_ImportIsUndefined, logger.Warning, trackerFile.LineColumnTracker(), r, fmt.Sprintf(
2517+
kind := logger.Warning
2518+
if helpers.IsInsideNodeModules(trackerFile.InputFile.Source.KeyPath.Text) {
2519+
kind = logger.Debug
2520+
}
2521+
c.log.AddID(logger.MsgID_Bundler_ImportIsUndefined, kind, trackerFile.LineColumnTracker(), r, fmt.Sprintf(
25142522
"Import %q will always be undefined because there is no matching export in %q",
25152523
namedImport.Alias, c.graph.Files[nextTracker.sourceIndex].InputFile.Source.PrettyPath))
25162524
} else {

0 commit comments

Comments
 (0)