Promact / md2

Angular2 based Material Design components, directives and services are Accordion, Autocomplete, Collapse, Colorpicker, Datepicker, Dialog(Modal), Menu, Multiselect, Select, Tabs, Tags(Chips), Toast and Tooltip.
http://code.promactinfo.com/md2/
MIT License
379 stars 111 forks source link

Not working with angular@5.1.2 #306

Open kluevandrew opened 6 years ago

kluevandrew commented 6 years ago

Bug, feature request, or proposal:

After upgrade and some breaking changes in @angular/compiler-cli library can't be build with rollup in AoT mode

What is the expected behavior?

Library works in AoT mode

What is the current behavior?

Errors like

[13:25:25] 'rollup' errored after 6.59 s
[13:25:25] Error: Could not resolve './calendar-body' from aot/tmp/node_modules/md2/datepicker/calendar-body.ngfactory.js
    at error (/home/andrew/www/riotgames/live/dashboard/node_modules/rollup/dist/rollup.js:185:14)
    at then.resolvedId (/home/andrew/www/riotgames/live/dashboard/node_modules/rollup/dist/rollup.js:18244:8)
    at <anonymous>

Because paths in compiled files like ./aot/tmp/node_modules/md2/datepicker/calendar-body.ngfactory.js are relative ex. import * as i3 from "./calendar-body";

My tsconfig.json is:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": ".",
    "target": "es5",
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es2015", "dom"],
    "removeComments": false,
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true,
    "allowSyntheticDefaultImports": true,
    "outDir": "./aot/tmp",
    "typeRoots": [
      "./node_modules/@types"
    ]
  },
  "include": [
    "./src/app/**/*",
    "./node_modules/@types/**/*"
  ],
  "files": [
    "./src/app/app.module.ts",
    "./src/app/boot.aot.ts",
    "./src/app/boot.development.ts"
  ],
  "exclude": [
    "src/**/*.spec.ts",
  ],
  "angularCompilerOptions": {
    "debug": true,
    "genDir": "./aot/tmp",
    "skipMetadataEmit" : true
  }
}

What are the steps to reproduce?

  1. Create any angular@5.1.2 app
  2. Compile it with ngc
  3. Try to rollup your app

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, MD2, OS, browsers are affected?

angular@5.1.2 md2@0.0.29 rollup@0.51.8

My workaround

  const fs = require('fs');
  const path = require('path');

  function ensureJsExt(fn) {
      return /\.js$/.test(fn) ? fn : fn + '.js';
  }

  function md2resolveId(importee, from) {
    if (from && (/^\.\/.*/.test(importee) || /^\.\.\/.*/.test(importee))) {
      var match = from.match(/^.*(node_modules\/md2\/.*$)/);
      if (match) {
        var dirTmp = path.dirname(from);
        var dirReal = path.dirname(match[1]);
        var pathTmp = ensureJsExt(dirTmp + '/' + importee);
        var pathReal = ensureJsExt('./' + dirReal + '/' + importee);

        return fs.realpathSync(fs.existsSync(pathTmp) ? pathTmp : pathReal);
      }
    }

    return false;
  }

 rollup({
  plugins: [
            ...
            {resolveId: resolveId}
           ...
  ]
})