Allow client modules to be imported by server modules.

This commit is contained in:
Ben Newman
2016-02-05 18:37:45 -05:00
parent ecf4fdb7b4
commit 35a02864af
4 changed files with 19 additions and 2 deletions

View File

@@ -121,7 +121,8 @@ export default class ImportScanner {
}
getOutputFiles(options) {
return this.outputFiles;
// Return all installable output files.
return this.outputFiles.filter(file => !! file.installPath);
}
_findImportedModuleIdentifiers(file) {

View File

@@ -1316,6 +1316,16 @@ _.extend(PackageSource.prototype, {
const fileOptions = {};
const dirs = files.pathDirname(relPath).split(files.pathSep);
// If the file is restricted to the opposite architecture, make sure
// it is not evaluated eagerly.
if (arch === "os") {
if (dirs.indexOf("client") >= 0) {
fileOptions.lazy = true;
}
} else if (dirs.indexOf("server") >= 0) {
fileOptions.lazy = true;
}
if (dirs.indexOf("node_modules") >= 0) {
fileOptions.lazy = true;
fileOptions.transpile = false;
@@ -1373,7 +1383,6 @@ _.extend(PackageSource.prototype, {
const anyLevelExcludes = [
/^tests\/$/,
/^node_modules\/$/,
arch === "os" ? /^client\/$/ : /^server\/$/,
...sourceReadOptions.exclude
];

View File

@@ -0,0 +1 @@
export const name = module.id;

View File

@@ -5,6 +5,12 @@ import {Meteor as ImportedMeteor} from "meteor/meteor";
describe("app modules", () => {
it("can be imported using absolute identifiers", () => {
assert.strictEqual(require("/tests"), exports);
assert.strictEqual(
// Client modules should be importable by server modules, though not
// vice-versa.
require("/client/eager").name,
"/client/eager.js"
);
});
it("can have different file extensions", () => {