From 0a6324013ada0f32f86b09465ccaa74c6081900c Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Fri, 18 Dec 2015 20:22:01 -0500 Subject: [PATCH] Install Meteor packages into virtual node_modules/meteor/ directory. Previously Meteor packages were installed at /node_modules/. This commit wraps them in an additional directory called "meteor", which prevents their names from colliding with other installed npm package names, and also means Meteor package identifiers must now include the "meteor/" prefix: import Blaze from "meteor/blaze" This change will eventually enable Meteor packages to import npm packages installed in top-level node_modules directories of apps. That won't work just yet, though, because the app bundler doesn't yet know anything about external dependencies imported by packages. --- packages/accounts-base/accounts_url_tests.js | 2 +- tools/isobuild/import-scanner.js | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/accounts-base/accounts_url_tests.js b/packages/accounts-base/accounts_url_tests.js index bd7c33423a..3e9b4fd43c 100644 --- a/packages/accounts-base/accounts_url_tests.js +++ b/packages/accounts-base/accounts_url_tests.js @@ -1,4 +1,4 @@ -import {AccountsTest} from "accounts-base"; +import {AccountsTest} from "meteor/accounts-base"; Tinytest.add("accounts - parse urls for accounts-password", function (test) { diff --git a/tools/isobuild/import-scanner.js b/tools/isobuild/import-scanner.js index 9fd378dde2..403f184a7e 100644 --- a/tools/isobuild/import-scanner.js +++ b/tools/isobuild/import-scanner.js @@ -203,10 +203,7 @@ export default class ImportScanner { if (this.name) { // If we're bundling a package, prefix path with // node_modules//. - path = pathJoin("node_modules", this.name, path); - } else { - // If we're bundling an app, prefix path with app/. - path = pathJoin("app", path); + path = pathJoin("node_modules", "meteor", this.name, path); } return path; @@ -372,9 +369,10 @@ export default class ImportScanner { } _getMeteorPackageNameFromId(id) { - const possiblePackageName = id.split("/", 1)[0]; - if (has(this.usedPackageNames, possiblePackageName)) { - return possiblePackageName; + const [meteor, packageName] = id.split("/", 2); + if (meteor === "meteor" && + has(this.usedPackageNames, packageName)) { + return packageName; } } @@ -436,7 +434,7 @@ export default class ImportScanner { // directories, npm never takes advantage of this possibility, which // conveniently allows Meteor to install files there without conflict. _addMeteorPackageStubToOutput(packageName) { - const relPkgPath = pathJoin("node_modules", packageName + ".js"); + const relPkgPath = pathJoin("node_modules", "meteor", packageName + ".js"); const absPkgPath = pathJoin(this.sourceRoot, relPkgPath); // Note that this absPkgPath need not actually exist on disk!