Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove slash package #7440

Merged
merged 8 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/early-students-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Remove `slash` package
5 changes: 5 additions & 0 deletions .changeset/rich-pumpkins-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/internal-helpers': patch
---

Add `slash` path utility
2 changes: 0 additions & 2 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions packages/astro/src/assets/utils/emitAsset.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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, '/');
}
7 changes: 3 additions & 4 deletions packages/astro/src/core/render/ssr-element.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/astro/src/core/routing/manifest/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions packages/astro/src/core/util.ts
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down Expand Up @@ -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/`;
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/vite-plugin-load-fallback/index.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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'),
};
Expand Down
1 change: 0 additions & 1 deletion packages/integrations/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
5 changes: 2 additions & 3 deletions packages/integrations/cloudflare/test/prerender.test.js
Original file line number Diff line number Diff line change
@@ -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} */
Expand All @@ -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/'];

Expand All @@ -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', '/'];

Expand Down
4 changes: 4 additions & 0 deletions packages/internal-helpers/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/');
}
25 changes: 0 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.