-
-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[js] allow to use remote js dependecies like https://unpkg.com/react.js in Project.xml #1670
base: develop
Are you sure you want to change the base?
Conversation
I like the idea, but I wonder if it's time to switch to regex. context.linkedLibraries = [];
//Matches strings that start with "http:https://" or "https://" and end with ".js".
var urlMatcher:EReg = ~/^https?:\/\/.+\.js$/i;
for (dependency in project.dependencies)
{
if (dependency.embed && !npm)
{
continue;
}
if (urlMatcher.match(dependency.name) || urlMatcher.match(dependency.path))
{
context.linkedLibraries.push(urlMatcher.matched(0));
}
else if (StringTools.endsWith(dependency.path, ".js") && FileSystem.exists(dependency.path))
{
var name = Path.withoutDirectory(dependency.path);
context.linkedLibraries.push("./" + dependencyPath + "/" + name);
System.copyIfNewer(dependency.path, Path.combine(destination, Path.combine(dependencyPath, name)));
}
} (My personal preference is to reduce nesting where possible, hence the The thing about this implementation is that |
Yes, in github a found enough examples where
So for backward compat There are basically two options:
|
Pretty sure the "name" and "path" attributes exist for the benefit of other targets. Perhaps for JS we could treat them as synonyms? context.linkedLibraries = [];
for (dependency in project.dependencies)
{
if (dependency.embed && !npm)
{
continue;
}
var path:String;
if (StringTools.endsWith(dependency.name, ".js"))
{
path = dependency.name;
}
else if (StringTools.endsWith(dependency.path, ".js"))
{
path = dependency.path;
}
else
{
continue;
}
if (FileSystem.exists(path))
{
var name = Path.withoutDirectory(path);
context.linkedLibraries.push("./" + dependencyPath + "/" + name);
System.copyIfNewer(dependency.path, Path.combine(destination, Path.combine(dependencyPath, name)));
}
else
{
context.linkedLibraries.push(path);
}
} |
What are the odds that someone put in a name (e.g., |
I guess the code before |
Yeah, and there are several other ways not to do that. I'm just trying to figure out the most appropriate option. If our only goal was to give the user the choice between "local file" and "resolvable url," we'd close this pull request and leave the code as-is. If our only goal was to reduce confusion stemming from attribute names, we'd make them synonyms. I personally prefer the latter, but Lime is pretty big on backwards compatibility, so I'm trying to decide exactly how backwards-compatible the "synonyms" option is. |
i believe this has desired compatibility: if (StringTools.endsWith(dependency.path, ".js") && FileSystem.exists(dependency.path))
{
var name = Path.withoutDirectory(dependency.path);
context.linkedLibraries.push("./" + dependencyPath + "/" + name);
System.copyIfNewer(dependency.path, Path.combine(destination, Path.combine(dependencyPath, name)));
}
else if (StringTools.endsWith(dependency.path, '.js'))
{
context.linkedLibraries.push(dependency.path);
}
else if (StringTools.endsWith(dependency.name, ".js"))
{
context.linkedLibraries.push(dependency.name);
} |
Yes, but then the attributes aren't synonymous. There are lots of perfect backwards-compatible options, but by definition, none of them make |
Why is that? They both do the same - user strings like |
Not if the file exists locally. To be synonyms, they have to be completely interchangeable in all cases. And the question is, do we want them to be completely interchangeable, or should there be a difference? Personally, I don't think this distinction makes sense. If you asked me to guess which of |
If that is the question then of course there is a difference.
|
Well that's a bit redundant. But there's no good way to stop people from writing redundant xml. Especially not now that they've already done it and published the code. We just have to keep supporting it until version 9.0.0 at the earliest.
Most targets can use the I can't see any good solutions here, but "add new behavior for |
This PR allows this syntax
to include the library in
index.html
.Without this PR, the same can be achieved using
name
attributebut I believe
path
attribute suits better.