From da1d68ba1e2cf007c80c67edef13283b4d228796 Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Fri, 11 Jan 2019 20:22:25 +0100 Subject: [PATCH 1/5] warn with the importer in case of missing module --- ext/npm-extension.js | 9 +++++--- steal.production.js | 2 +- test/npm_nested_import_errors/dev.html | 24 ++++++++++++++++++++++ test/npm_nested_import_errors/main.js | 2 ++ test/npm_nested_import_errors/package.json | 8 ++++++++ test/test.js | 6 +++++- 6 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 test/npm_nested_import_errors/dev.html create mode 100644 test/npm_nested_import_errors/main.js create mode 100644 test/npm_nested_import_errors/package.json diff --git a/ext/npm-extension.js b/ext/npm-extension.js index 402612e82..fb180d0a2 100644 --- a/ext/npm-extension.js +++ b/ext/npm-extension.js @@ -393,11 +393,14 @@ exports.addExtension = function addNpmExtension(System){ if ((statusCode === 404 || statusCode === 0) && utils.moduleName.isBareIdentifier(load.name) && !utils.pkg.isRoot(loader, load.metadata.npmPackage)) { - var newError = new Error([ - "Could not load '" + load.name + "'", + var errorMsg = ["Could not load '" + load.name + "'", "Is this an npm module not saved in your package.json?" - ].join("\n")); + ].join("\n"); + var newError = new Error(); newError.statusCode = error.statusCode; + newError.stack = newError.stack + error.stack; + newError.message = errorMsg; + throw newError; } else { throw error; diff --git a/steal.production.js b/steal.production.js index 6c2b91bd7..4055a15e4 100644 --- a/steal.production.js +++ b/steal.production.js @@ -1,5 +1,5 @@ /* - * steal v2.1.12 + * steal v2.1.13 * * Copyright (c) 2019 Bitovi; Licensed MIT */ diff --git a/test/npm_nested_import_errors/dev.html b/test/npm_nested_import_errors/dev.html new file mode 100644 index 000000000..b46769968 --- /dev/null +++ b/test/npm_nested_import_errors/dev.html @@ -0,0 +1,24 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/test/npm_nested_import_errors/main.js b/test/npm_nested_import_errors/main.js new file mode 100644 index 000000000..f05e24d00 --- /dev/null +++ b/test/npm_nested_import_errors/main.js @@ -0,0 +1,2 @@ +//require("dep"); +console.log("Imported"); \ No newline at end of file diff --git a/test/npm_nested_import_errors/package.json b/test/npm_nested_import_errors/package.json new file mode 100644 index 000000000..f7e91e25d --- /dev/null +++ b/test/npm_nested_import_errors/package.json @@ -0,0 +1,8 @@ +{ + "name": "npm_nested_import_errors", + "main": "main.js", + "version": "1.0.0", + "dependencies": { + "dep": "1.0.0" + } +} diff --git a/test/test.js b/test/test.js index 57f7ccef0..19a79637e 100644 --- a/test/test.js +++ b/test/test.js @@ -2,7 +2,7 @@ var QUnit = require("steal-qunit"); QUnit.config.testTimeout = 30000; -require("src/cache-bust/test/"); +// require("src/cache-bust/test/"); require("src/env/test/"); require("src/json/test/"); require("src/trace/trace_test"); @@ -477,3 +477,7 @@ QUnit.test("dev bundle loads BEFORE configMain", function(assert) { QUnit.test("When the dev-bundle is missing we get a nice message", function(assert){ makeIframe("dev_bundle_err/dev.html", assert); }); + +QUnit.test("If a package is missing, warn which file imported it #1463", function(assert) { + makeIframe("npm_nested_import_errors/dev.html", assert); +}) \ No newline at end of file From eaf8a983b495e4af661379c243f1d9400ba417a5 Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Fri, 11 Jan 2019 20:35:47 +0100 Subject: [PATCH 2/5] remove comment --- test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index 19a79637e..9b885c598 100644 --- a/test/test.js +++ b/test/test.js @@ -2,7 +2,7 @@ var QUnit = require("steal-qunit"); QUnit.config.testTimeout = 30000; -// require("src/cache-bust/test/"); +require("src/cache-bust/test/"); require("src/env/test/"); require("src/json/test/"); require("src/trace/trace_test"); From 86a7944e1578550796f7003c0b9faffc408ec445 Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Fri, 11 Jan 2019 20:51:15 +0100 Subject: [PATCH 3/5] fix the stack message --- ext/npm-extension.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ext/npm-extension.js b/ext/npm-extension.js index fb180d0a2..9e0f0c5bb 100644 --- a/ext/npm-extension.js +++ b/ext/npm-extension.js @@ -393,14 +393,12 @@ exports.addExtension = function addNpmExtension(System){ if ((statusCode === 404 || statusCode === 0) && utils.moduleName.isBareIdentifier(load.name) && !utils.pkg.isRoot(loader, load.metadata.npmPackage)) { - var errorMsg = ["Could not load '" + load.name + "'", + var newError = new Error([ + "Could not load '" + load.name + "'", "Is this an npm module not saved in your package.json?" - ].join("\n"); - var newError = new Error(); + ].join("\n")); newError.statusCode = error.statusCode; newError.stack = newError.stack + error.stack; - newError.message = errorMsg; - throw newError; } else { throw error; From 15b8d991267594a7142ef48a0edecef54434b32a Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Tue, 15 Jan 2019 00:13:48 +0100 Subject: [PATCH 4/5] clean up tests --- test/npm_nested_import_errors/main.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/npm_nested_import_errors/main.js b/test/npm_nested_import_errors/main.js index f05e24d00..e69de29bb 100644 --- a/test/npm_nested_import_errors/main.js +++ b/test/npm_nested_import_errors/main.js @@ -1,2 +0,0 @@ -//require("dep"); -console.log("Imported"); \ No newline at end of file From 344bf2cf8688f3f6871f157613710d0922674c48 Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Tue, 15 Jan 2019 01:40:27 +0100 Subject: [PATCH 5/5] fix the test --- test/npm_nested_import_errors/dep.js | 2 ++ test/npm_nested_import_errors/dev.html | 18 ++++++++---------- test/npm_nested_import_errors/main.js | 3 +++ test/npm_nested_import_errors/package.json | 5 +---- 4 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 test/npm_nested_import_errors/dep.js diff --git a/test/npm_nested_import_errors/dep.js b/test/npm_nested_import_errors/dep.js new file mode 100644 index 000000000..30b71d8f9 --- /dev/null +++ b/test/npm_nested_import_errors/dep.js @@ -0,0 +1,2 @@ +module.exports = {}; +require("~/foo"); \ No newline at end of file diff --git a/test/npm_nested_import_errors/dev.html b/test/npm_nested_import_errors/dev.html index b46769968..81e624029 100644 --- a/test/npm_nested_import_errors/dev.html +++ b/test/npm_nested_import_errors/dev.html @@ -9,16 +9,14 @@ window.done = window.parent.done; window.assert = window.parent.assert; - \ No newline at end of file diff --git a/test/npm_nested_import_errors/main.js b/test/npm_nested_import_errors/main.js index e69de29bb..77c5ea022 100644 --- a/test/npm_nested_import_errors/main.js +++ b/test/npm_nested_import_errors/main.js @@ -0,0 +1,3 @@ +module.exports = {}; +require('~/dep'); + diff --git a/test/npm_nested_import_errors/package.json b/test/npm_nested_import_errors/package.json index f7e91e25d..42355456f 100644 --- a/test/npm_nested_import_errors/package.json +++ b/test/npm_nested_import_errors/package.json @@ -1,8 +1,5 @@ { "name": "npm_nested_import_errors", "main": "main.js", - "version": "1.0.0", - "dependencies": { - "dep": "1.0.0" - } + "version": "1.0.0" }