@docusaurus/utils
Advanced tools
Comparing version 2.0.0-alpha.1db0277d3 to 2.0.0-alpha.1e1860681
@@ -39,2 +39,3 @@ /** | ||
export declare function posixPath(str: string): string; | ||
export declare function toMessageRelativeFilePath(filePath: string): string; | ||
/** | ||
@@ -71,2 +72,3 @@ * Generate unique chunk name given a module path. | ||
export declare function addTrailingSlash(str: string): string; | ||
export declare function addTrailingPathSeparator(str: string): string; | ||
export declare function removeTrailingSlash(str: string): string; | ||
@@ -73,0 +75,0 @@ export declare function removeSuffix(str: string, suffix: string): string; |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.updateTranslationFileMessages = exports.getSwizzledComponent = exports.mergeTranslations = exports.reportMessage = exports.getFolderContainingFile = exports.findFolderContainingFile = exports.findAsyncSequential = exports.mapAsyncSequencial = exports.getPluginI18nPath = exports.getElementsAround = exports.getFilePathForRoutePath = exports.removePrefix = exports.removeSuffix = exports.removeTrailingSlash = exports.addTrailingSlash = exports.addLeadingSlash = exports.resolvePathname = exports.isValidPathname = exports.getEditUrl = exports.aliasedSitePath = exports.normalizeUrl = exports.parseMarkdownFile = exports.parseMarkdownString = exports.createExcerpt = exports.getSubFolder = exports.idx = exports.genChunkName = exports.posixPath = exports.genComponentName = exports.upperFirst = exports.docuHash = exports.simpleHash = exports.encodePath = exports.fileToPath = exports.objectWithKeySorted = exports.generate = void 0; | ||
exports.updateTranslationFileMessages = exports.getSwizzledComponent = exports.mergeTranslations = exports.reportMessage = exports.getFolderContainingFile = exports.findFolderContainingFile = exports.findAsyncSequential = exports.mapAsyncSequencial = exports.getPluginI18nPath = exports.getElementsAround = exports.getFilePathForRoutePath = exports.removePrefix = exports.removeSuffix = exports.removeTrailingSlash = exports.addTrailingPathSeparator = exports.addTrailingSlash = exports.addLeadingSlash = exports.resolvePathname = exports.isValidPathname = exports.getEditUrl = exports.aliasedSitePath = exports.normalizeUrl = exports.parseMarkdownFile = exports.parseMarkdownString = exports.createExcerpt = exports.getSubFolder = exports.idx = exports.genChunkName = exports.toMessageRelativeFilePath = exports.posixPath = exports.genComponentName = exports.upperFirst = exports.docuHash = exports.simpleHash = exports.encodePath = exports.fileToPath = exports.objectWithKeySorted = exports.generate = void 0; | ||
const chalk_1 = __importDefault(require("chalk")); | ||
@@ -130,2 +130,13 @@ const path_1 = __importDefault(require("path")); | ||
exports.posixPath = posixPath; | ||
// When you want to display a path in a message/warning/error, | ||
// it's more convenient to: | ||
// - make it relative to cwd() | ||
// - convert to posix (ie not using windows \ path separator) | ||
// This way, Jest tests can run more reliably on any computer/CI | ||
// on both Unix/Windows | ||
// For Windows users this is not perfect (as they see / instead of \) but it's probably good enough | ||
function toMessageRelativeFilePath(filePath) { | ||
return posixPath(path_1.default.relative(process.cwd(), filePath)); | ||
} | ||
exports.toMessageRelativeFilePath = toMessageRelativeFilePath; | ||
const chunkNameCache = new Map(); | ||
@@ -185,3 +196,3 @@ /** | ||
// Skip import/export declaration. | ||
if (/^.*import\s.*from.*;?|export\s.*{.*};?/.test(fileLine)) { | ||
if (/^\s*?import\s.*(from.*)?;?|export\s.*{.*};?/.test(fileLine)) { | ||
continue; | ||
@@ -312,3 +323,3 @@ } | ||
function aliasedSitePath(filePath, siteDir) { | ||
const relativePath = path_1.default.relative(siteDir, filePath); | ||
const relativePath = posixPath(path_1.default.relative(siteDir, filePath)); | ||
// Cannot use path.join() as it resolves '../' and removes | ||
@@ -352,2 +363,6 @@ // the '@site'. Let webpack loader resolve it. | ||
exports.addTrailingSlash = addTrailingSlash; | ||
function addTrailingPathSeparator(str) { | ||
return str.endsWith(path_1.default.sep) ? str : `${str}${path_1.default.sep}`; | ||
} | ||
exports.addTrailingPathSeparator = addTrailingPathSeparator; | ||
function removeTrailingSlash(str) { | ||
@@ -354,0 +369,0 @@ return removeSuffix(str, '/'); |
{ | ||
"name": "@docusaurus/utils", | ||
"version": "2.0.0-alpha.1db0277d3", | ||
"version": "2.0.0-alpha.1e1860681", | ||
"description": "Node utility functions for Docusaurus packages", | ||
@@ -21,3 +21,3 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@docusaurus/types": "2.0.0-alpha.1db0277d3", | ||
"@docusaurus/types": "2.0.0-alpha.1e1860681", | ||
"chalk": "^3.0.0", | ||
@@ -35,3 +35,3 @@ "escape-string-regexp": "^2.0.0", | ||
}, | ||
"gitHead": "3c3f0a9eb7a8861bb8dd9f42d7c9d8abd1e448ee" | ||
"gitHead": "5107f3b05bbc4e99e6e52c089e1a1b61b3463f16" | ||
} |
@@ -48,3 +48,5 @@ /** | ||
Object.keys(asserts).forEach((file) => { | ||
expect(aliasedSitePath(file, 'user/website')).toBe(asserts[file]); | ||
expect(posixPath(aliasedSitePath(file, 'user/website'))).toBe( | ||
asserts[file], | ||
); | ||
}); | ||
@@ -390,2 +392,3 @@ }); | ||
import Component from '@site/src/components/Component' | ||
import './styles.css'; | ||
@@ -525,6 +528,6 @@ export function ItemCol(props) { return <Item {...props} className={'col col--6 margin-bottom--lg'}/> } | ||
test('works for /', () => { | ||
expect(getFilePathForRoutePath('/')).toEqual('/index.html'); | ||
expect(posixPath(getFilePathForRoutePath('/'))).toEqual('/index.html'); | ||
}); | ||
test('works for /somePath', () => { | ||
expect(getFilePathForRoutePath('/somePath')).toEqual( | ||
expect(posixPath(getFilePathForRoutePath('/somePath'))).toEqual( | ||
'/somePath/index.html', | ||
@@ -534,3 +537,3 @@ ); | ||
test('works for /somePath/', () => { | ||
expect(getFilePathForRoutePath('/somePath/')).toEqual( | ||
expect(posixPath(getFilePathForRoutePath('/somePath/'))).toEqual( | ||
'/somePath/index.html', | ||
@@ -537,0 +540,0 @@ ); |
@@ -143,2 +143,13 @@ /** | ||
// When you want to display a path in a message/warning/error, | ||
// it's more convenient to: | ||
// - make it relative to cwd() | ||
// - convert to posix (ie not using windows \ path separator) | ||
// This way, Jest tests can run more reliably on any computer/CI | ||
// on both Unix/Windows | ||
// For Windows users this is not perfect (as they see / instead of \) but it's probably good enough | ||
export function toMessageRelativeFilePath(filePath: string) { | ||
return posixPath(path.relative(process.cwd(), filePath)); | ||
} | ||
const chunkNameCache = new Map(); | ||
@@ -208,3 +219,3 @@ /** | ||
// Skip import/export declaration. | ||
if (/^.*import\s.*from.*;?|export\s.*{.*};?/.test(fileLine)) { | ||
if (/^\s*?import\s.*(from.*)?;?|export\s.*{.*};?/.test(fileLine)) { | ||
continue; | ||
@@ -370,3 +381,3 @@ } | ||
export function aliasedSitePath(filePath: string, siteDir: string): string { | ||
const relativePath = path.relative(siteDir, filePath); | ||
const relativePath = posixPath(path.relative(siteDir, filePath)); | ||
// Cannot use path.join() as it resolves '../' and removes | ||
@@ -409,2 +420,5 @@ // the '@site'. Let webpack loader resolve it. | ||
} | ||
export function addTrailingPathSeparator(str: string): string { | ||
return str.endsWith(path.sep) ? str : `${str}${path.sep}`; | ||
} | ||
@@ -411,0 +425,0 @@ export function removeTrailingSlash(str: string): string { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
520380
1788
+ Added@docusaurus/types@2.0.0-alpha.1e1860681(transitive)
- Removed@docusaurus/types@2.0.0-alpha.1db0277d3(transitive)