Files
meteor/tools/tests/apps/modules/packages/modules-test-package/common.js
Ben Newman bd9043db20 Prefer "main" field of package.json over "module" in legacy bundle.
https://github.com/meteor/meteor/issues/10658#issuecomment-550456095
https://github.com/meteor/meteor/issues/10658#issuecomment-551870115

As usual, changes to module resolution logic need to happen in parallel in
tools/isobuild/resolver.ts and in packages/modules-runtime. However,
thanks to the modern/legacy system, it's easy to make the modules-runtime
package behave exactly the way(s) we want in the server, modern client,
and legacy client bundles.
2019-11-08 11:15:23 -05:00

55 lines
1.4 KiB
JavaScript

import assert from "assert";
import "regenerator-runtime/runtime";
export const ModulesTestPackage = "loaded";
import { parse } from "acorn";
assert.strictEqual(typeof parse, "function");
// Test that an npm package with a "module" entry point in its package.json
// file can be imported.
import { Slot } from "@wry/context";
assert.strictEqual(typeof Slot, "function");
const idPrefix = "/node_modules/meteor/modules-test-package/node_modules/@wry/context/lib/";
assert.strictEqual(
require.resolve("@wry/context"),
idPrefix + (
Meteor.isClient && Meteor.isModern ? "context.esm.js" : "context.js"
),
);
import ganalytics from "ganalytics";
assert.strictEqual(typeof ganalytics, "function");
export function checkWhere(where) {
const { where: serverWhere } = require("./server/where.js");
const { where: clientWhere } = require("./client/where.js");
assert.strictEqual(serverWhere, where);
assert.strictEqual(clientWhere, where);
}
export function checkPackageVars() {
if (Meteor.isClient) {
assert.strictEqual(ClientPackageVar, "client");
try {
console.log(ServerPackageVar);
} catch (e) {
if (e instanceof ReferenceError) {
// ok
} else {
throw e;
}
}
} else {
assert.strictEqual(ServerPackageVar, "server");
try {
console.log(ClientPackageVar);
} catch (e) {
if (e instanceof ReferenceError) {
// ok
} else {
throw e;
}
}
}
}