Skip to content

Interpret leading slashes relative to package - #180

Merged
aomarks merged 13 commits into
mainfrom
glob-roots
May 4, 2022
Merged

Interpret leading slashes relative to package#180
aomarks merged 13 commits into
mainfrom
glob-roots

Conversation

@aomarks

@aomarks aomarks commented May 4, 2022

Copy link
Copy Markdown
Member

Previously, a glob pattern like /foo was resolved to foo in the root of the filesystem, which is the usual behavior for a file path.

However, that's a footgun because what a user almost certainly means by that is foo in the package directory.

So we now ignore the leading /. In the case of files, we still allow reaching out of the directory using e.g. ../foo.

This new behavior also matches the behavior of the npm files array (apart from the ../ support, which files simply ignores).

Also fixed a duplicate lint script in package.json.

Fixes #173

@aomarks aomarks changed the title Interpret leading slashes as relative to package Interpret leading slashes relative to package May 4, 2022
Comment thread src/util/glob.ts Outdated
Comment thread src/util/glob.ts Outdated
@aomarks
aomarks requested a review from AndrewJakubowicz May 4, 2022 18:50

@rictic rictic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One request

Comment thread src/test/glob.test.ts
patterns: ['\\{foo,bar\\}'],
expected: ['{foo,bar}'],
}));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No one should write this, but how do we interpret /./foo or /../bar? Probably worth a test to make sure what we do is sensible

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We remove the leading /, which I think is correct.

Added tests.

@AndrewJakubowicz AndrewJakubowicz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice!

@AndrewJakubowicz

Copy link
Copy Markdown

Failing Windows test - on Node 14

@aomarks

aomarks commented May 4, 2022

Copy link
Copy Markdown
Member Author

Failing Windows test - on Node 14

Fixed

@aomarks

aomarks commented May 4, 2022

Copy link
Copy Markdown
Member Author

Failing Windows test - on Node 14

Fixed

Actually not fixed, it's inconsistent on Windows between 14 and 16. But it's an inconsistency between foo and ./foo which are semantically the same, and my next PR (#182) just so happens to fix this by adding extra normalization. Temporarily disabled this one test.

@aomarks
aomarks enabled auto-merge (squash) May 4, 2022 21:55
@aomarks
aomarks merged commit 2bf9227 into main May 4, 2022
@aomarks
aomarks deleted the glob-roots branch May 4, 2022 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Globs should be forced relative to package directory

4 participants