Buslowicz / twc

TypeScript based, boilerplate-less, Polymer toolbox friendly Polymer Modules
32 stars 1 forks source link

Running with wildcard breaks @template annotation #65

Closed tpluscode closed 7 years ago

tpluscode commented 7 years ago

In my project the structure of source and destination files is as follows (part relevant to a single element)

/augeas
├──src/
│  └── elements/
│      ├── ags-field.html
│      └── ags-field.ts
└── dist/
    └── elements/  
        ├── ags-field.html
        └── ags-field.d.ts

In ags-field.ts I use the @template decorator:

@template('ags-field.html')
export class AgsField {}

I want to process the entire src folder with twc using command twc src/**/*.ts --outDir dist but it throws an exception:

fs.js:584
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: ENOENT: no such file or directory, open '\augeas\src\ags-field.html'
    at Error (native)
    at Object.fs.openSync (fs.js:584:18)
    at Object.fs.readFileSync (fs.js:431:33)
    at \npm\node_modules\twc\src\PolymerModule.js:189:33
    at Module.toString (\npm\node_modules\twc\src\PolymerModule.js:195:11)
    at Module.toBuffer (\npm\node_modules\twc\src\PolymerModule.js:229:32)
    at DestroyableTransform._transform (\npm\node_modules\twc\src\index.js:57:22)
    at DestroyableTransform.Transform._read (\npm\node_modules\twc\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:159:10)
    at DestroyableTransform.Transform._write (\npm\node_modules\twc\node_modules\through2\node_modules\readable-stream\lib\_stream_transform.js:147:83)
    at doWrite (\npm\node_modules\twc\node_modules\through2\node_modules\readable-stream\lib\_stream_writable.js:347:64)

As you can see, the path is incorrectly calculated. Should be \augeas\src\elements\ags-field.html.

I tried with --rootDir src but the exact same error is thrown.

Buslowicz commented 7 years ago

Paths for templates (and styles) are relative to project dir atm. Would it be more intuitive if it was relative to the file itself?

tpluscode commented 7 years ago

Paths for templates (and styles) are relative to project dir atm.

AFAICT not always. Works fine when I run

twc src/elements/ags-field.ts --outDir dist/elements
tpluscode commented 7 years ago

Would it be more intuitive if it was relative to the file itself?

I think so. Parameter relative to current file just like <link> etc.

Buslowicz commented 7 years ago

Oh my bad, it's relative to base path. Base path is either provided with --rootDir (you tried with src, but your files are deeper) or calculated the same way tsc does it (longest common path). Nevertheless I will make it relative to the file itself, it should not rely on path that might change (didn't think of that before).

tpluscode commented 7 years ago

(didn't think of that before)

Hey, that's why you have a private beta-tester :)

Buslowicz commented 7 years ago

Haha true :D. Thanks for helping ;). TWC quality would be very bad without your help :).

Buslowicz commented 7 years ago

Fixed in #66.