Skip to content

Commit 694a623

Browse files
anmonteiroswannodette
authored andcommitted
CLJS-2326: Indexing node_modules can't find main when it doesn't have an extension
1 parent befb367 commit 694a623

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

src/main/cljs/cljs/module_deps.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,16 @@ md.on('file', function (file) {
175175
md.on('end', function () {
176176
for (let i = 0; i < pkgJsons.length; i++) {
177177
let pkgJson = pkgJsons[i];
178+
const candidates = /\.js(on)?$/.test(pkgJson.mainEntry)
179+
? [pkgJson.mainEntry]
180+
: [pkgJson.mainEntry, pkgJson.mainEntry + '.js', pkgJson.mainEntry + '.json'];
178181

179-
if (deps_files[pkgJson.mainEntry] != null && pkgJson.provides != null) {
180-
deps_files[pkgJson.mainEntry].provides = pkgJson.provides;
182+
for (let j = 0; j < candidates.length; j++) {
183+
const candidate = candidates[j];
184+
185+
if (deps_files[candidate] != null && pkgJson.provides != null) {
186+
deps_files[candidate].provides = pkgJson.provides;
187+
}
181188
}
182189

183190
for (let j = 0; j < aliasFields.length; j++) {

src/main/clojure/cljs/closure.clj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,8 +2259,12 @@
22592259
(string/replace #"\\" "/")
22602260
(string/replace #"package\.json$" "")
22612261
(str main))]
2262-
(when (= main-path (string/replace path #"\\" "/"))
2263-
name))))
2262+
(some (fn [candidate]
2263+
(when (= candidate (string/replace path #"\\" "/"))
2264+
name))
2265+
(cond-> [main-path]
2266+
(nil? (re-find #"\.js(on)?$" main-path))
2267+
(into [(str main-path ".js") (str main-path ".json")]))))))
22642268
pkg-jsons)]
22652269
{:provides (let [module-rel-name (-> (subs path (.lastIndexOf path "node_modules"))
22662270
(string/replace #"\\" "/")

src/test/clojure/cljs/closure_tests.clj

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@
275275
"tslib/tslib.es6.js"
276276
"tslib/tslib.es6"]}))
277277
(closure/index-node-modules ["tslib"] opts))))
278+
(.delete (io/file "package.json"))
278279
(test/delete-node-modules)
279280
(test/delete-out-files out)))
280281

@@ -339,3 +340,32 @@
339340
(.delete (io/file "package.json"))
340341
(test/delete-node-modules)
341342
(test/delete-out-files out)))
343+
344+
(deftest test-cljs-2326
345+
(spit (io/file "package.json") "{}")
346+
(let [opts {:npm-deps {:bootstrap "4.0.0-beta"}}
347+
out (util/output-directory opts)]
348+
(test/delete-node-modules)
349+
(test/delete-out-files out)
350+
(closure/maybe-install-node-deps! opts)
351+
(is (true? (some (fn [module]
352+
(= module {:module-type :es6
353+
:file (.getAbsolutePath (io/file "node_modules/bootstrap/dist/js/bootstrap.js"))
354+
:provides ["bootstrap"
355+
"bootstrap/dist/js/bootstrap.js"
356+
"bootstrap/dist/js/bootstrap"]}))
357+
(closure/index-node-modules ["bootstrap"] opts))))
358+
(test/delete-node-modules)
359+
(spit (io/file "package.json") "{}")
360+
(test/delete-out-files out))
361+
(closure/maybe-install-node-deps! {:npm-deps {:bootstrap "4.0.0-beta"}})
362+
(let [modules (closure/index-node-modules-dir)]
363+
(is (true? (some (fn [module]
364+
(= module {:module-type :es6
365+
:file (.getAbsolutePath (io/file "node_modules/bootstrap/dist/js/bootstrap.js"))
366+
:provides ["bootstrap/dist/js/bootstrap.js"
367+
"bootstrap/dist/js/bootstrap"
368+
"bootstrap"]}))
369+
modules))))
370+
(.delete (io/file "package.json"))
371+
(test/delete-node-modules))

0 commit comments

Comments
 (0)