Skip to content

Aurelia adds /index to modules path after ModuleConcatenationPlugin #156

@homer0

Description

@homer0

I'm submitting a bug report

  • Library Version:
    3.0.0

Please tell us about your environment:

  • Operating System:
    OSX 10.13.6

  • Node Version:
    10.15.3

  • NPM Version:
    6.4.1

  • JSPM OR Webpack AND Version
    webpack 4.29.1

  • Browser:
    all

  • Language:
    ESNext

Current behavior:

When using .plugin(PLATFORM.moduleName('my/plugin/path')) on a production build, where ModuleConcatenationPlugin runs by default, the module ends up on the bundle with the key my/plugin/path/index, so the app fails to run as my/plugin/path doesn't exist.

Expected/desired behavior:

On the main configure of the app, use .plugin for a local folder index file that includes a component/service/valueConverter, basically anything that the ModuleConcatenationPlugin may want to optimize:

// main.js

export const configure = (aurelia) => {
  aurelia.use
  .plugin(PLATFORM.moduleName('modules/my-module'))
  .standardConfiguration();

  return aurelia.start().then(() => aurelia.setRoot(...));
};

// modules/my-module/index.js

import { MY_CONSTANT } = './my-constant.js';

export const configure = (aurelia) => {
  console.log(MY_CONSTANT);
};

// modules/my-module/my-constant.js

export const MY_CONSTANT = {
  someKey: 'someValue',
};

That's enough for ModuleConcatenationPlugin to try to put my-constant inside my-module/index.js and for the PreserveModuleNamePlugin to change modules/my-module to modules/my-module/index.

  • What is the expected behavior?

For PreserveModuleNamePlugin not to add the /index.

  • Possible solution

Not sure if this is the right way to do it, but if we add the following code before this line, it works:

if (id.endsWith('/index') && !realModule.rawRequest.endsWith('index')) {
  id = id.replace(/\/index$/, '');
  // or id = id.substr(0, id.length - 6);
}

I'm not that familiar with the module structure, so I'm not sure if we can "trust" in rawRequest

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions