Skip to content

Commit

Permalink
feat: simplifies sync paths (#11730)
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-lefebvre authored Aug 16, 2024
1 parent 423614e commit 2df49a6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-houses-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Simplifies path operations of `astro sync`
12 changes: 5 additions & 7 deletions packages/astro/src/core/sync/write-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import type fsMod from 'node:fs';
import { dirname, relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import { bold } from 'kleur/colors';
import { normalizePath } from 'vite';
import type { AstroSettings } from '../../@types/astro.js';
import { AstroError, AstroErrorData } from '../errors/index.js';
import type { Logger } from '../logger/core.js';
import { REFERENCE_FILE } from './constants.js';
import { normalizePath } from 'vite';

export async function writeFiles(settings: AstroSettings, fs: typeof fsMod, logger: Logger) {
try {
Expand All @@ -27,7 +27,7 @@ function writeInjectedTypes(settings: AstroSettings, fs: typeof fsMod) {
const references: Array<string> = [];

for (const { filename, content } of settings.injectedTypes) {
const filepath = normalizePath(fileURLToPath(new URL(filename, settings.dotAstroDir)));
const filepath = fileURLToPath(new URL(filename, settings.dotAstroDir));
fs.mkdirSync(dirname(filepath), { recursive: true });
fs.writeFileSync(filepath, content, 'utf-8');
references.push(normalizePath(relative(fileURLToPath(settings.dotAstroDir), filepath)));
Expand All @@ -38,17 +38,15 @@ function writeInjectedTypes(settings: AstroSettings, fs: typeof fsMod) {
fs.mkdirSync(settings.dotAstroDir, { recursive: true });
}
fs.writeFileSync(
normalizePath(fileURLToPath(new URL(REFERENCE_FILE, settings.dotAstroDir))),
fileURLToPath(new URL(REFERENCE_FILE, settings.dotAstroDir)),
astroDtsContent,
'utf-8',
);
}

async function setUpEnvTs(settings: AstroSettings, fs: typeof fsMod, logger: Logger) {
const envTsPath = normalizePath(fileURLToPath(new URL('env.d.ts', settings.config.srcDir)));
const envTsPathRelativetoRoot = normalizePath(
relative(fileURLToPath(settings.config.root), envTsPath),
);
const envTsPath = fileURLToPath(new URL('env.d.ts', settings.config.srcDir));
const envTsPathRelativetoRoot = relative(fileURLToPath(settings.config.root), envTsPath);
const relativePath = normalizePath(
relative(
fileURLToPath(settings.config.srcDir),
Expand Down
4 changes: 1 addition & 3 deletions packages/astro/test/astro-sync.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as fs from 'node:fs';
import { beforeEach, describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import ts from 'typescript';
import { normalizePath } from 'vite';
import { loadFixture } from './test-utils.js';

const createFixture = () => {
Expand All @@ -16,8 +15,7 @@ const createFixture = () => {
/**
* @param {string} path
*/
const getExpectedPath = (path) =>
normalizePath(fileURLToPath(new URL(path, astroFixture.config.root)));
const getExpectedPath = (path) => fileURLToPath(new URL(path, astroFixture.config.root));

return {
/** @param {string} root */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as assert from 'node:assert/strict';
import os from 'node:os';
import { describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import * as cheerio from 'cheerio';
Expand All @@ -9,8 +8,6 @@ import { createFsWithFallback, createRequestAndResponse, runInContainer } from '

const root = new URL('../../fixtures/content/', import.meta.url);

const _describe = os.platform() === 'win32' ? describe.skip : describe;

/** @type {typeof runInContainer} */
async function runInContainerWithContentListeners(params, callback) {
return await runInContainer(params, async (container) => {
Expand All @@ -19,7 +16,7 @@ async function runInContainerWithContentListeners(params, callback) {
});
}

_describe('Content Collections - render()', () => {
describe('Content Collections - render()', () => {
it('can be called in a page component', async () => {
const fs = createFsWithFallback(
{
Expand Down

0 comments on commit 2df49a6

Please sign in to comment.