Skip to content

An import ending in "/" is always an import of a directory.#10510

Merged
4 commits merged into
masterfrom
import_directory
Sep 14, 2016
Merged

An import ending in "/" is always an import of a directory.#10510
4 commits merged into
masterfrom
import_directory

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Aug 23, 2016

Fixes #9690

@weswigham
Copy link
Copy Markdown
Member

Couldn't a path ending in a slash just be a file with no name but an implied extension? Ie, foo/bar/ could be referencing /too/bar/.ts?

@ghost
Copy link
Copy Markdown
Author

ghost commented Aug 24, 2016

Node

foo/.js

module.exports = ".js"

a.js

console.log(require("./foo/"));

Result:

Error: Cannot find module './foo/'

SystemJS

SystemJS always requires an extension so there's no ambiguity there.

RequireJS

RequireJS seems to allow this:
(Basing my test on https://github.com/volojs/create-template)

main.js

requirejs(["helper/"], console.log);

helper/.js:

define(() => ".js");

Result: logs ".js"

Conclusion

We could always just take out the change here https://github.com/Microsoft/TypeScript/pull/10510/files#diff-08a3cc4f1f9a51dbb468c2810f5229d3R649 and all that would change would be traces. But then we would be allowing node users to import "foo/" matched by "foo/.ts", which would fail at runtime. On the other hand, the change makes the code more complicated and would forbid requirejs users from some valid imports.

@weswigham
Copy link
Copy Markdown
Member

If you configure syatemjs with the default extension option, does it behave
the same as requirejs?

Do browserify and webpack work exactly the same as Node?

On Wed, Aug 24, 2016, 9:41 AM Andy notifications@github.com wrote:

Node

foo/.js

module.exports = ".js"

a.js

console.log(require("./foo/"));

Result:

Error: Cannot find module './foo/'

SystemJS

SystemJS always requires an extension so there's no ambiguity there.
RequireJS

RequireJS seems to allow this:
(Basing my test on https://github.com/volojs/create-template)

main.js

requirejs(["helper/"], console.log);

helper/.js:

define(() => ".js");

Result: logs ".js"
Conclusion

We could always just take out the change here
https://github.com/Microsoft/TypeScript/pull/10510/files#diff-08a3cc4f1f9a51dbb468c2810f5229d3R649
and all that would change would be traces. But then we would be allowing
node users to import "foo/" matched by "foo/.ts", which would fail at
runtime. On the other hand, the change makes the code more complicated and
would forbid requirejs users from some valid imports.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#10510 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACzAMg5kTbYS4of6EzrwU-_rypCmzOG3ks5qjEnrgaJpZM4JrXRZ
.

@ghost ghost mentioned this pull request Aug 26, 2016
@ghost
Copy link
Copy Markdown
Author

ghost commented Aug 26, 2016

Filing a separate issue for that since it shouldn't block this: #10562

@@ -11,10 +11,10 @@ export default { aIndex: 0 };
import a from ".";
import aIndex from "./";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you add test for when the filename is not "/a/index.ts"? this seems to only work when your filename is "index.ts"

@ghost ghost assigned yuit Sep 2, 2016
@aluanhaddad
Copy link
Copy Markdown
Contributor

@weswigham Take a look at systemjs/systemjs#1069 and systemjs/systemjs#1308.

Comment thread src/compiler/core.ts Outdated
}

/** A path ending with '/' refers to a directory only, never a file. */
export function isPathToDirectory(path: string): boolean {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do not see why this is true.. can we make it more declarative and call it pathEndsWithDirectorySeparator to avoid ppl making wrong assumptions.

@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented Sep 14, 2016

👍

@ghost ghost merged commit 42515c7 into master Sep 14, 2016
@ghost ghost deleted the import_directory branch September 14, 2016 21:07
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This pull request was closed.
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.

5 participants