Skip to content
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

Resolve css after ts in node_modules #3352

Closed
wants to merge 1 commit into from
Closed
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
34 changes: 34 additions & 0 deletions internal/bundler_tests/bundler_ts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2719,6 +2719,40 @@ func TestTSPreferJSOverTSInsideNodeModules(t *testing.T) {
})
}

func TestTSPreferTSOverCssInsideNodeModules(t *testing.T) {
// We now prefer ".js" over ".ts" inside "node_modules"
ts_suite.expectBundled(t, bundled{
files: map[string]string{
"/Users/user/project/src/main.ts": `
// Implicit extensions
import './relative/path'
import 'package/path'

// Explicit extensions
import './relative2/path.css'
import 'package2/path.css'
`,

"/Users/user/project/src/relative/path.ts": `console.log('success')`,
"/Users/user/project/src/relative/path.css": `failure`,

"/Users/user/project/src/relative2/path.ts": `console.log('FAILURE')`,
"/Users/user/project/src/relative2/path.css": `html {}`,

"/Users/user/project/node_modules/package/path.ts": `console.log('success')`,
"/Users/user/project/node_modules/package/path.css": `failure`,

"/Users/user/project/node_modules/package2/path.ts": `console.log('FAILURE')`,
"/Users/user/project/node_modules/package2/path.css": `html {}`,
},
entryPaths: []string{"/Users/user/project/src/main.ts"},
options: config.Options{
Mode: config.ModeBundle,
AbsOutputDir: "/out",
},
})
}

func TestTSExperimentalDecoratorsManglePropsDefineSemantics(t *testing.T) {
ts_suite.expectBundled(t, bundled{
files: map[string]string{
Expand Down
22 changes: 20 additions & 2 deletions internal/bundler_tests/snapshots/snapshots_ts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1744,15 +1744,33 @@ TestTSPreferJSOverTSInsideNodeModules
// Users/user/project/src/relative/path.ts
console.log("success");

// Users/user/project/node_modules/package/path.js
console.log("success");
// Users/user/project/node_modules/package/path.ts
console.log("FAILURE");

// Users/user/project/src/relative2/path.js
console.log("success");

// Users/user/project/node_modules/package2/path.js
console.log("success");

================================================================================
TestTSPreferTSOverCssInsideNodeModules
---------- /out/main.js ----------
// Users/user/project/src/relative/path.ts
console.log("success");

// Users/user/project/node_modules/package/path.ts
console.log("success");

---------- /out/main.css ----------
/* Users/user/project/src/relative2/path.css */
html {
}

/* Users/user/project/node_modules/package2/path.css */
html {
}

================================================================================
TestTSSiblingEnum
---------- /out/number.js ----------
Expand Down
7 changes: 6 additions & 1 deletion internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func NewResolver(call config.APICall, fs fs.FS, log logger.Log, caches *cache.Ca
// for imports of files inside of "node_modules" directories
nodeModulesExtensionOrder := make([]string, 0, len(options.ExtensionOrder))
for _, ext := range options.ExtensionOrder {
if loader, ok := options.ExtensionToLoader[ext]; !ok || !loader.IsTypeScript() {
if loader, ok := options.ExtensionToLoader[ext]; !ok || !loader.IsTypeScript() || !loader.IsCSS() {
nodeModulesExtensionOrder = append(nodeModulesExtensionOrder, ext)
}
}
Expand All @@ -261,6 +261,11 @@ func NewResolver(call config.APICall, fs fs.FS, log logger.Log, caches *cache.Ca
nodeModulesExtensionOrder = append(nodeModulesExtensionOrder, ext)
}
}
for _, ext := range options.ExtensionOrder {
if loader, ok := options.ExtensionToLoader[ext]; ok && loader.IsCSS() {
nodeModulesExtensionOrder = append(nodeModulesExtensionOrder, ext)
}
}

// Generate the condition sets for interpreting the "exports" field
esmConditionsDefault := map[string]bool{"default": true}
Expand Down