Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

many fixes #27

Closed
wants to merge 1 commit into from
Closed

many fixes #27

wants to merge 1 commit into from

Conversation

pjordaan
Copy link
Contributor

fixes for packages that do define and calling the factory directly instead (for example zenscroll).

define(['dependencies'], factory()});

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.

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);
Copy link
Member

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));
Copy link
Member

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?

Copy link
Contributor Author

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....

Copy link
Contributor

@nicoschoenmaker nicoschoenmaker left a 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.

@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge mistake....

target: ts.ScriptTarget.ES5,
module: ts.ModuleKind.CommonJS,
moduleResolution: ts.ModuleResolutionKind.NodeJs,
emitDecoratorMetadata: true,
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -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 = []
Copy link
Contributor

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);
Copy link
Contributor

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
Copy link
Contributor

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?

@@ -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));
Copy link
Contributor

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())
Copy link
Contributor

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.

@pjordaan pjordaan force-pushed the master branch 2 times, most recently from 2f2501f to 40fd71c Compare November 1, 2017 12:42
@@ -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)
Copy link
Contributor

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.

Copy link
Contributor Author

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

*/
public function __construct(
string $config_file,
array $plugins = [],
bool $dev = false,
EventDispatcherInterface $dispatcher = null,
LoggerInterface $logger = null
LoggerInterface $logger = null,
array $non_static_options = []
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Member

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?

$plugin_api->getConfig()->getEventDispatcher()->addListener(
AssetEvents::FIND_SOURCE,
function (FindSourceEvent $ev) {
$file_path = preg_replace('/\.css$/', '.less', $ev->getFilepath());
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

true,
null,
null
);
Copy link
Member

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

@pjordaan pjordaan force-pushed the master branch 5 times, most recently from e794cd8 to de23183 Compare November 9, 2017 10:05

if ($file_path[0] === '.' && $owning_file->dir !== '.' && !empty($owning_file->dir)) {
$file_path = $owning_file->dir . '/' . $file_path;
if (substr($linked_file, 1, 0) === '/') {
Copy link
Contributor

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.

@nicoschoenmaker
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants