From f60668aff1a199b444cea28c947b95c8984a5679 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 20 Aug 2022 15:56:26 -0700 Subject: [PATCH 1/2] fix: directly re-export is-path-inside --- package.json | 1 + pnpm-lock.yaml | 7 +++++++ src/is-path-inside.ts | 35 +---------------------------------- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index 3c9c6d3..1edb034 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,7 @@ "prettier": "prettier-config-atomic", "dependencies": { "escape-string-regexp": "^5.0.0", + "is-path-inside": "^4.0.0", "replace-ext": "^2.0.0" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 384529f..d70be07 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -19,6 +19,7 @@ importers: escape-string-regexp: ^5.0.0 eslint: ^8.21.0 eslint-config-atomic: ^1.18.1 + is-path-inside: ^4.0.0 jest: ^28.1.3 npm-check-updates: ^16.0.5 npm-run-all2: ^6.0.1 @@ -36,6 +37,7 @@ importers: typescript: ^4.7.4 dependencies: escape-string-regexp: 5.0.0 + is-path-inside: 4.0.0 replace-ext: 2.0.0 optionalDependencies: '@types/node': 18.6.3 @@ -5065,6 +5067,11 @@ packages: engines: {node: '>=8'} dev: true + /is-path-inside/4.0.0: + resolution: {integrity: sha512-lJJV/5dYS+RcL8uQdBDW9c9uWFLLBNRyFhnAKXw5tVqLlKZ4RMGZKv+YQ/IA3OhD+RpbJa1LLFM1FQPGyIXvOA==} + engines: {node: '>=12'} + dev: false + /is-plain-obj/2.1.0: resolution: {integrity: sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==} engines: {node: '>=8'} diff --git a/src/is-path-inside.ts b/src/is-path-inside.ts index 541104c..761e1a6 100644 --- a/src/is-path-inside.ts +++ b/src/is-path-inside.ts @@ -1,34 +1 @@ -import { relative, resolve, sep } from "path" - -/** - * Check if a path is inside another path. - * - * Note that relative paths are resolved against `process.cwd()` to make them absolute. - * - * This function does not check if the paths exist and it only works with strings. - * - * @example - * - * ```js - * import { isPathInside } from "patha" - * - * isPathInside("a/b/c", "a/b") - * //=> true - * - * isPathInside("a/b/c", "x/y") - * //=> false - * - * isPathInside("a/b/c", "a/b/c") - * //=> false - * - * isPathInside("/Users/some/dev/aa", "/Users/some") - * //=> true - * ``` - */ -export function isPathInside(childPath: string, parentPath: string): boolean { - // copied from is-path-inside because the package uses node:path that can't be bundled for the browser - - const relation = relative(parentPath, childPath) - - return Boolean(relation && relation !== ".." && !relation.startsWith(`..${sep}`) && relation !== resolve(childPath)) -} +export { default as isPathInside } from "is-path-inside" From dab3f8fd0f6cda4993375920ba2bb3217e7ac6cb Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 20 Aug 2022 16:43:54 -0700 Subject: [PATCH 2/2] fix: use esmodule even for the old browser bundle --- README.md | 32 ++++++++++++++++++++++++++++++++ package.json | 2 +- src/is-path-inside.ts | 31 ++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 561fefc..d6ee332 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ - [`normalizeTrim` (function)](#normalizetrim-function) - [`removeExt` (function)](#removeext-function) - [`replaceExt` (function)](#replaceext-function) + - [`isPathInside` (function)](#ispathinside-function) - [🤝 Contributing](#contributing) @@ -234,6 +235,37 @@ import { replaceExt } from "patha" replaceExt("path/to/file.md", ".html") // gives "path/to/file.html" ``` +### `isPathInside` (function) + +Check if a path is inside another path. + +Note that relative paths are resolved against `process.cwd()` to make them absolute. + +This function does not check if the paths exist and it only works with strings. + +**Parameters:** + +- childPath (`string`) +- parentPath (`string`) + +**returns:** boolean + +```js +import { isPathInside } from "patha" + +isPathInside("a/b/c", "a/b") +//=> true + +isPathInside("a/b/c", "x/y") +//=> false + +isPathInside("a/b/c", "a/b/c") +//=> false + +isPathInside("/Users/some/dev/aa", "/Users/some") +//=> true +``` + ## 🤝 Contributing diff --git a/package.json b/package.json index 1edb034..b1fef72 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ }, "optimize": true, "includeNodeModules": true, - "outputFormat": "global", + "outputFormat": "esmodule", "isLibrary": true }, "module.browser": { diff --git a/src/is-path-inside.ts b/src/is-path-inside.ts index 761e1a6..9980951 100644 --- a/src/is-path-inside.ts +++ b/src/is-path-inside.ts @@ -1 +1,30 @@ -export { default as isPathInside } from "is-path-inside" +import { default as isPathInsideOrig } from "is-path-inside" + +/** + * Check if a path is inside another path. + * + * Note that relative paths are resolved against `process.cwd()` to make them absolute. + * + * This function does not check if the paths exist and it only works with strings. + * + * @example + * + * ```js + * import { isPathInside } from "patha" + * + * isPathInside("a/b/c", "a/b") + * //=> true + * + * isPathInside("a/b/c", "x/y") + * //=> false + * + * isPathInside("a/b/c", "a/b/c") + * //=> false + * + * isPathInside("/Users/some/dev/aa", "/Users/some") + * //=> true + * ``` + */ +export function isPathInside(childPath: string, parentPath: string): boolean { + return isPathInsideOrig(childPath, parentPath) +}