Skip to content

Commit b373fe9

Browse files
anmonteiroswannodette
authored andcommitted
CLJS-1920: cljs.build.api/node-inputs: package.json files are only added if module entries are top-level
1 parent 772e59a commit b373fe9

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

src/main/cljs/cljs/module_deps.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
var path = require('path');var mdeps = require('module-deps');var JSONStream = require('JSONStream');var md = mdeps();md.pipe(JSONStream.stringify()).pipe(process.stdout);md.end({file: path.resolve(path.join(__dirname, 'JS_FILE')) });
1+
var path = require('path');
2+
var mdeps = require('module-deps');
3+
4+
var md = mdeps({});
5+
var deps_files = [];
6+
7+
md.on('package', function (pkg) {
8+
// we don't want to include the package.json for users' projects
9+
if (/node_modules/.test(pkg.__dirname)) {
10+
deps_files.push({file: path.join(pkg.__dirname, 'package.json')});
11+
}
12+
});
13+
14+
md.on('file', function(file) {
15+
deps_files.push({file: file});
16+
});
17+
18+
md.on('end', function() {
19+
process.stdout.write(JSON.stringify(deps_files));
20+
});
21+
22+
md.end({
23+
file: path.resolve(path.join(__dirname, 'JS_FILE'))
24+
});
25+
26+
md.resume();

src/main/clojure/cljs/build/api.clj

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -219,25 +219,6 @@
219219
(binding [ana/*cljs-warning-handlers* (:warning-handlers opts ana/*cljs-warning-handlers*)]
220220
(closure/watch source opts compiler-env stop))))
221221

222-
(defn add-package-jsons
223-
"EXPERIMENTAL: see node-module-deps"
224-
[deps]
225-
(let [checked (atom #{})]
226-
(reduce
227-
(fn [ret {:keys [file] :as dep}]
228-
(let [f (.getParentFile (io/file file))
229-
path (.getAbsolutePath f)]
230-
(if-not (contains? @checked path)
231-
(let [f' (io/file f "package.json")]
232-
(swap! checked conj path)
233-
(if (.exists f')
234-
(conj ret dep
235-
{:file (.getAbsolutePath f')
236-
:module-type :commonjs})
237-
(conj ret dep)))
238-
(conj ret dep))))
239-
[] deps)))
240-
241222
(defn- alive? [proc]
242223
(try (.exitValue proc) false (catch IllegalThreadStateException _ true)))
243224

@@ -259,8 +240,7 @@
259240
(defn node-module-deps
260241
"EXPERIMENTAL: return the foreign libs entries as computed by running
261242
the module-deps package on the supplied JavaScript entry point. Assumes
262-
that the module-deps & JSONStream NPM packages are either locally or
263-
globally installed."
243+
that the module-deps NPM package is either locally or globally installed."
264244
[{:keys [file]}]
265245
(let [code (string/replace
266246
(slurp (io/resource "cljs/module_deps.js"))
@@ -285,7 +265,7 @@
285265
(into []
286266
(map (fn [{:strs [file]}] file
287267
{:file file :module-type :commonjs}))
288-
(butlast (json/read-str (str iw))))
268+
(next (json/read-str (str iw))))
289269
(do
290270
(when-not (.isAlive proc)
291271
(println (str ew)))
@@ -295,19 +275,16 @@
295275
(node-module-deps
296276
{:file (.getAbsolutePath (io/file "src/test/node/test.js"))})
297277

298-
(add-package-jsons
299-
(node-module-deps
300-
{:file (.getAbsolutePath (io/file "src/test/node/test.js"))}))
278+
(node-module-deps
279+
{:file (.getAbsolutePath (io/file "src/test/node/test.js"))})
301280
)
302281

303282
(defn node-inputs
304283
"EXPERIMENTAL: return the foreign libs entries as computed by running
305284
the module-deps package on the supplied JavaScript entry points. Assumes
306-
that the module-deps & JSONStream NPM packages are either locally or
307-
globally installed."
285+
that the module-deps NPM packages is either locally or globally installed."
308286
[entries]
309-
(add-package-jsons
310-
(vec (distinct (mapcat node-module-deps entries)))))
287+
(into [] (distinct (mapcat node-module-deps entries))))
311288

312289
(comment
313290
(node-inputs

0 commit comments

Comments
 (0)