Search code examples
javascriptnpmstealjs

How to Repath CommonJS modules in StealJS


I'm probably doing something wrong, so feel free to question all things. I'm using an npm package xrm-mock for a MS CRM mocking framework. I've setup my config as such

steal.config({
    meta: {
        "dependencyModule": {
            deps: [
                /***********************************
                 *  List of Spec Files goes here!  *
                 ***********************************/
                "spec/po_/commonSpec"
                ,"spec/xrmMockGeneratorSpec"
            ]
        },
        "jasmine": {
            "exports":  "jasmineRequire"
        },
        "jasmine-html": {
            deps: ["jasmine"]
        },
        "jasmine-boot": {
            deps: ["jasmine", "jasmine-html"]
        },
        "xrm-mock-generator": {
            deps: ["xrm-mock"]
        }
    },
    bundlesPath: "../WebResources",
    loadBundles: true,
    paths: {
        "jasmine": "../node_modules/jasmine-core/lib/jasmine-core/jasmine.js",
        "jasmine-html": "../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js",
        "jasmine-boot": "../node_modules/jasmine-core/lib/jasmine-core/boot.js",
        "sourcemapped-stacktrace": "../node_modules/sourcemapped-stacktrace/dist/sourcemapped-stacktrace.js",
        "xrm-mock": "../node_modules/xrm-mock/index.js",
        "xrm-mock-generator": "../node_modules/xrm-mock-generator/dist/xrm-mock-generator.js"
    },
    map: {},
    main: "./testRunner"
});

but xrm-mock/index.js looks like this:

"use strict";
exports.__esModule = true;
var formselector_mock_1 = require("./dist/page/formselector/formselector.mock");
exports.FormSelectorMock = formselector_mock_1.FormSelectorMock;
var formitem_mock_1 = require("./dist/page/formitem/formitem.mock");
exports.FormItemMock = formitem_mock_1.FormItemMock;
   ... 80 more lines...

and I get 404s for each require: "http://localhost:62576/test/dist/page/formselector/formselector.mock.js" which should be "http://localhost:62576/node_modules/xrm-mock/dist/page/formselector/formselector.mock.js"

I'm guessing I could add each and every module file as a module with a path, but that's 40 some modules I'd have to define. Is there an easier way?


Solution

  • Most devs use the npm plugin nowadays, do you know about it? Removes the need for this manual (and difficult) configuration To answer your question though, I think what you want to do is remove the xrm-mock path and instead have something like

    "xrm-mock/*": "../node_modules/xrm-mock/*.js"
    

    and then a map for the main module:

    "map": {
      "xrm-mock": "xrm-mock/index"
    }