Remove slash package (#7440)

This commit is contained in:
Bjorn Lu 2023-06-23 16:48:05 +08:00 committed by GitHub
parent 8642912120
commit 2b75399520
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 29 additions and 48 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Remove `slash` package

View file

@ -0,0 +1,5 @@
---
'@astrojs/internal-helpers': patch
---
Add `slash` path utility

View file

@ -158,10 +158,8 @@
"semver": "^7.5.2",
"server-destroy": "^1.0.1",
"shiki": "^0.14.1",
"slash": "^4.0.0",
"string-width": "^5.1.2",
"strip-ansi": "^7.1.0",
"supports-esm": "^1.0.0",
"tsconfig-resolver": "^3.0.1",
"typescript": "*",
"unist-util-visit": "^4.1.2",

View file

@ -1,8 +1,7 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import slash from 'slash';
import { prependForwardSlash } from '../../core/path.js';
import { prependForwardSlash, slash } from '../../core/path.js';
import { imageMetadata, type Metadata } from './metadata.js';
export async function emitESMImage(
@ -46,7 +45,6 @@ export async function emitESMImage(
}
function fileURLToNormalizedPath(filePath: URL): string {
// Uses `slash` package instead of Vite's `normalizePath`
// to avoid CJS bundling issues.
// Uses `slash` instead of Vite's `normalizePath` to avoid CJS bundling issues.
return slash(fileURLToPath(filePath) + filePath.search).replace(/\\/g, '/');
}

View file

@ -1,13 +1,12 @@
import slashify from 'slash';
import type { SSRElement } from '../../@types/astro';
import { joinPaths, prependForwardSlash } from '../../core/path.js';
import { joinPaths, prependForwardSlash, slash } from '../../core/path.js';
import type { StylesheetAsset } from '../app/types';
export function createAssetLink(href: string, base?: string, assetsPrefix?: string): string {
if (assetsPrefix) {
return joinPaths(assetsPrefix, slashify(href));
return joinPaths(assetsPrefix, slash(href));
} else if (base) {
return prependForwardSlash(joinPaths(base, slashify(href)));
return prependForwardSlash(joinPaths(base, slash(href)));
} else {
return href;
}

View file

@ -11,12 +11,11 @@ import type { LogOptions } from '../../logger/core';
import nodeFs from 'fs';
import { createRequire } from 'module';
import path from 'path';
import slash from 'slash';
import { fileURLToPath } from 'url';
import { getPrerenderDefault } from '../../../prerender/utils.js';
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from '../../constants.js';
import { warn } from '../../logger/core.js';
import { removeLeadingForwardSlash } from '../../path.js';
import { removeLeadingForwardSlash, slash } from '../../path.js';
import { resolvePages } from '../../util.js';
import { getRouteGenerator } from './generator.js';
const require = createRequire(import.meta.url);

View file

@ -1,13 +1,12 @@
import fs from 'fs';
import path from 'path';
import slash from 'slash';
import { fileURLToPath } from 'url';
import { normalizePath } from 'vite';
import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro';
import { isServerLikeOutput } from '../prerender/utils.js';
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './constants.js';
import type { ModuleLoader } from './module-loader';
import { prependForwardSlash, removeTrailingForwardSlash } from './path.js';
import { prependForwardSlash, removeTrailingForwardSlash, slash } from './path.js';
/** Returns true if argument is an object of any prototype/class (but not null). */
export function isObject(value: unknown): value is Record<string, any> {
@ -90,7 +89,7 @@ export function parseNpmName(
* Windows: C:/Users/astro/code/my-project/src/pages/index.astro
*/
export function viteID(filePath: URL): string {
return slash(fileURLToPath(filePath) + filePath.search).replace(/\\/g, '/');
return slash(fileURLToPath(filePath) + filePath.search);
}
export const VALID_ID_PREFIX = `/@id/`;

View file

@ -1,7 +1,7 @@
import nodeFs from 'fs';
import npath from 'path';
import slashify from 'slash';
import type * as vite from 'vite';
import { slash } from '../core/path.js';
type NodeFileSystemModule = typeof nodeFs;
@ -47,7 +47,7 @@ export default function loadFallbackPlugin({
async resolveId(id, parent) {
// See if this can be loaded from our fs
if (parent) {
const candidateId = npath.posix.join(npath.posix.dirname(slashify(parent)), id);
const candidateId = npath.posix.join(npath.posix.dirname(slash(parent)), id);
try {
// Check to see if this file exists and is not a directory.
const stats = await fs.promises.stat(candidateId);

View file

@ -1,7 +1,6 @@
import { fileURLToPath } from 'node:url';
import nodeFS from 'node:fs';
import path from 'node:path';
import slash from 'slash';
import { runInContainer } from '../../../dist/core/dev/index.js';
import { attachContentServerListeners } from '../../../dist/content/index.js';
@ -11,7 +10,9 @@ const root = new URL('../../fixtures/alias/', import.meta.url);
function getTypesDts() {
const typesdtsURL = new URL('../../../content-types.template.d.ts', import.meta.url);
const relpath = slash(path.relative(fileURLToPath(root), fileURLToPath(typesdtsURL)));
const relpath = path
.relative(fileURLToPath(root), fileURLToPath(typesdtsURL))
.replace(/\\/g, '/');
return {
[relpath]: nodeFS.readFileSync(typesdtsURL, 'utf-8'),
};

View file

@ -52,7 +52,6 @@
"chai": "^4.3.7",
"cheerio": "1.0.0-rc.12",
"mocha": "^9.2.2",
"slash": "^4.0.0",
"wrangler": "^2.0.23"
}
}

View file

@ -1,6 +1,5 @@
import { loadFixture } from './test-utils.js';
import { expect } from 'chai';
import slash from 'slash';
describe('Prerendering', () => {
/** @type {import('./test-utils').Fixture} */
@ -21,7 +20,7 @@ describe('Prerendering', () => {
it('includes prerendered routes in the routes.json config', async () => {
const foundRoutes = JSON.parse(await fixture.readFile('/_routes.json')).exclude.map((r) =>
slash(r)
r.replace(/\\/g, '/')
);
const expectedExcludedRoutes = ['/_worker.js', '/one/index.html', '/one/'];
@ -48,7 +47,7 @@ describe('Hybrid rendering', () => {
it('includes prerendered routes in the routes.json config', async () => {
const foundRoutes = JSON.parse(await fixture.readFile('/_routes.json')).exclude.map((r) =>
slash(r)
r.replace(/\\/g, '/')
);
const expectedExcludedRoutes = ['/_worker.js', '/index.html', '/'];

View file

@ -84,3 +84,7 @@ export function removeQueryString(path: string) {
export function isRemotePath(src: string) {
return /^(http|ftp|https|ws):?\/\//.test(src) || src.startsWith('data:');
}
export function slash(path: string) {
return path.replace(/\\/g, '/');
}

View file

@ -619,18 +619,12 @@ importers:
shiki:
specifier: ^0.14.1
version: 0.14.1
slash:
specifier: ^4.0.0
version: 4.0.0
string-width:
specifier: ^5.1.2
version: 5.1.2
strip-ansi:
specifier: ^7.1.0
version: 7.1.0
supports-esm:
specifier: ^1.0.0
version: 1.0.0
tsconfig-resolver:
specifier: ^3.0.1
version: 3.0.1
@ -3638,9 +3632,6 @@ importers:
mocha:
specifier: ^9.2.2
version: 9.2.2
slash:
specifier: ^4.0.0
version: 4.0.0
wrangler:
specifier: ^2.0.23
version: 2.0.23
@ -7719,10 +7710,6 @@ packages:
dependencies:
'@lit-labs/ssr-dom-shim': 1.1.1
/@ljharb/has-package-exports-patterns@0.0.2:
resolution: {integrity: sha512-4/RWEeXDO6bocPONheFe6gX/oQdP/bEpv0oL4HqjPP5DCenBSt0mHgahppY49N0CpsaqffdwPq+TlX9CYOq2Dw==}
dev: false
/@manypkg/find-root@1.1.0:
resolution: {integrity: sha512-mki5uBvhHzO8kYYix/WRy2WX8S3B5wdVSc9D6KcU5lQNglP2yt58/VfLuAK49glRXChosY8ap2oJ1qgma3GUVA==}
dependencies:
@ -12093,12 +12080,6 @@ packages:
resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==}
engines: {node: '>=8'}
/has-package-exports@1.3.0:
resolution: {integrity: sha512-e9OeXPQnmPhYoJ63lXC4wWe34TxEGZDZ3OQX9XRqp2VwsfLl3bQBy7VehLnd34g3ef8CmYlBLGqEMKXuz8YazQ==}
dependencies:
'@ljharb/has-package-exports-patterns': 0.0.2
dev: false
/has-property-descriptors@1.0.0:
resolution: {integrity: sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==}
dependencies:
@ -16461,12 +16442,6 @@ packages:
dependencies:
has-flag: 4.0.0
/supports-esm@1.0.0:
resolution: {integrity: sha512-96Am8CDqUaC0I2+C/swJ0yEvM8ZnGn4unoers/LSdE4umhX7mELzqyLzx3HnZAluq5PXIsGMKqa7NkqaeHMPcg==}
dependencies:
has-package-exports: 1.3.0
dev: false
/supports-preserve-symlinks-flag@1.0.0:
resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==}
engines: {node: '>= 0.4'}