-
Notifications
You must be signed in to change notification settings - Fork 11
Conversation
if (false !== ($i = strrpos($module_name, '.'))) { | ||
$module_name = substr($module_name, 0, $i); | ||
if (preg_match('/\.ts$/i', $module_name)) { | ||
$module_name = preg_replace('/\.ts$/i', '', $module_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you not always replace it? because preg_replace
does not do anything if it does not match anything.
@@ -51,7 +51,7 @@ public function onPostTranspile(AssetEvent $event): void | |||
$content = preg_replace_callback( | |||
'/templateUrl\s*:(\s*[\'"`](.*?)[\'"`]\s*)/m', | |||
function ($match) use ($file, $reader) { | |||
return 'template: ' . json_encode($this->getCompiledAssetFor($match[2], $file, $reader)); | |||
return 'template: ' . json_encode($this->getCompiledAssetFor('./' . $match[2], $file, $reader)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if these are absolute paths? Or is that not possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically it's possible, but in general it doesn't happen, but I can add it if you want....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of adjustments that still need unit-tests. Otherwise these fixes might break in the future.
src/Config/ConfigInterface.php
Outdated
@@ -61,7 +61,6 @@ public function getPlugins(): array; | |||
/** | |||
* Return the output folder in which to dump the compiled assets. | |||
* | |||
* @param bool $include_public_folder Whether to include the web/ directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this doc is removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge mistake....
src/Bundler/Runner/js/tsc.js
Outdated
target: ts.ScriptTarget.ES5, | ||
module: ts.ModuleKind.CommonJS, | ||
moduleResolution: ts.ModuleResolutionKind.NodeJs, | ||
emitDecoratorMetadata: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we enable this?
The docs of typescript point to this issue: microsoft/TypeScript#2577
But that does not tell me anything about why this is (or isn't) a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Angular require this to be turned on.
src/Config/FileConfig.php
Outdated
@@ -40,10 +40,14 @@ public function __construct( | |||
array $plugins = [], | |||
bool $dev = false, | |||
EventDispatcherInterface $dispatcher = null, | |||
LoggerInterface $logger = null | |||
LoggerInterface $logger = null, | |||
array $non_static_options = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This added argument is not documented in the docblock.
if ($file_path[0] === '.' && $owning_file->dir !== '.' && !empty($owning_file->dir)) { | ||
$file_path = $owning_file->dir . '/' . $file_path; | ||
} | ||
$file_path = preg_replace('/\.css$/', '.less', $owning_file->dir . '/' . $file_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is called for both style and for the template, so hardcoding anything with .css
or .less
doesn't feel right.
} | ||
|
||
_modules[name] = { | ||
_initializer: initializer, | ||
_module: null | ||
_module: null, | ||
_stack: (new TypeError).stack |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the impact on this for client side performance? I understand it's nice for debugging, but wouldn't this mean creating >100 objects for a javascript intensive app?
test/Config/FileConfigTest.php
Outdated
@@ -28,7 +28,6 @@ public function testMinimal() | |||
self::assertSame([], $config->getEntryPoints()); | |||
self::assertSame([], $config->getAssetFiles()); | |||
self::assertSame(self::EXPECTED_OUTPUT, $config->getOutputFolder()); | |||
self::assertSame('dev', $config->getOutputFolder(false)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these test-cases removed?
@@ -94,7 +94,7 @@ public function push(array $dependencies, ReaderInterface $file_reader, File $ta | |||
$module_name = $file->getName(); | |||
|
|||
if (!empty($this->config->getSourceRoot()) | |||
&& false !== strpos($module_name, $this->config->getSourceRoot()) | |||
&& 0 === strpos($module_name, $this->config->getSourceRoot()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fix for probably a bug that exists for which no unit-test has been added.
2f2501f
to
40fd71c
Compare
@@ -26,7 +26,9 @@ public function peek(string $cwd, ContentState $state): void | |||
|
|||
public function transpile(string $cwd, ContentItem $item): void | |||
{ | |||
$js = "register('" . $item->module_name . "', function (define, require, module, exports) {\n"; | |||
$js = "register(" | |||
. json_encode($item->module_name, JSON_UNESCAPED_SLASHES) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fix for probably a bug that exists for which no unit-test has been added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just a common XSS fix
src/Config/FileConfig.php
Outdated
*/ | ||
public function __construct( | ||
string $config_file, | ||
array $plugins = [], | ||
bool $dev = false, | ||
EventDispatcherInterface $dispatcher = null, | ||
LoggerInterface $logger = null | ||
LoggerInterface $logger = null, | ||
array $non_static_options = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use case for these non static options? Especially the docblock type mixed
scares me.
Maybe we should remove the FileConfig
and move the ArrayConfig
from the bundle here instead. Or make the FileConfig
class a wrapper around the ArrayConfig
class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the issue I have one setting which is not statically determined. I can generate a json file and use this class or indeed make a wrapper class for just one setting or I could just add this argument to keep it simple
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems to be only used in the test? There is an interface, just mock it?
src/Plugin/LessPlugin.php
Outdated
$plugin_api->getConfig()->getEventDispatcher()->addListener( | ||
AssetEvents::FIND_SOURCE, | ||
function (FindSourceEvent $ev) { | ||
$file_path = preg_replace('/\.css$/', '.less', $ev->getFilepath()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wouldn't the Angular component refer to the .less
file immediately? That would also help the IDE to find the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if Angular Ahead of Time would be used, using .less inmediately would load the less file in as css.
|
||
/** | ||
* Angular asset resolver. | ||
*/ | ||
final class AngularImportCollector implements ImportCollectorInterface | ||
{ | ||
private $plugin_api; | ||
|
||
public function __construct(PluginApi $plugin_api) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to only need the EventDispatcher
.
test/Config/FileConfigTest.php
Outdated
true, | ||
null, | ||
null | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this change still needed? I think those extra arguments are defaults
e794cd8
to
de23183
Compare
|
||
if ($file_path[0] === '.' && $owning_file->dir !== '.' && !empty($owning_file->dir)) { | ||
$file_path = $owning_file->dir . '/' . $file_path; | ||
if (substr($linked_file, 1, 0) === '/') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
php -r "var_dump(substr('ABC', 1, 0));"
string(0) ""
Based on that, this if can not become true. There should probably be a unit-test for this case.
Can we tear this pull request in 10 pieces or so? This appears to fix a lot of issues at the same time, it's hard to see how these are related now. Or whether all the unit-tests are complete, etc. |
fixes for packages that do define and calling the factory directly instead (for example zenscroll).
wrong module name for external modules with 'src' somewhere in the path. (for example angular2-swiper/src/ks-swiper.module)
Possible XSS on module name.
Do not automatically remove . from a module name, it's not always '.ts'
Enable ts-helpers to reuse ts transpile helper functions.
Enable emitting deocrator metadata for Angular DI.
Added optional config for FileConfig to provide non-static options.
Ignore comments with require() statements.
Make angular templates always relative and let the import provide the full path instead.
Parse less to css for angular templates possiblity.
Ignore .d.ts entirely. This is because some imports fail because end up at the definition file, while a source file is available too. For example @angular/platform-browser/animations resolved to node_modules/@angular/platform-browser/animations/index.d.ts, while it should resolve to node_modules/@angular/platform-browser/bundles/platform-browser-animations.umd.js by reading the package.json.