Skip to content

Commit

Permalink
Debugging windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Jul 8, 2024
1 parent 616a3cf commit 232773c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"test:e2e:match": "playwright test -g",
"test:e2e:chrome": "playwright test",
"test:e2e:firefox": "playwright test --config playwright.firefox.config.js",
"test:node": "astro-scripts test \"test/**/*.test.js\""
"test:node": "astro-scripts test \"test/content-layer.test.js\" --timeout 30000 --only"
},
"dependencies": {
"@astrojs/compiler": "^2.8.1",
Expand Down Expand Up @@ -243,4 +243,4 @@
"publishConfig": {
"provenance": true
}
}
}
23 changes: 19 additions & 4 deletions packages/astro/src/content/loaders/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export function glob(globOptions: GlobOptions): Loader {
logger.warn(`No entry type found for ${entry}`);
return;
}
console.log({ entry, base });
const fileUrl = new URL(entry, base);
const { body, data } = await entryType.getEntryInfo({
contents: await fs.readFile(fileUrl, 'utf-8'),
Expand All @@ -81,7 +82,10 @@ export function glob(globOptions: GlobOptions): Loader {

const id = generateId({ entry, base, data });

console.log({ fileUrl });

const filePath = fileURLToPath(fileUrl);
console.log({ filePath });

const parsedData = await parseData({
id,
Expand Down Expand Up @@ -111,6 +115,9 @@ export function glob(globOptions: GlobOptions): Loader {
if (!baseDir.pathname.endsWith('/')) {
baseDir.pathname = `${baseDir.pathname}/`;
}
console.log('basedir', baseDir);
console.log('globOptions', globOptions.base);
console.log('settings', settings.config.root);

const files = await fastGlob(globOptions.pattern, {
cwd: fileURLToPath(baseDir),
Expand All @@ -131,11 +138,19 @@ export function glob(globOptions: GlobOptions): Loader {
files.map((entry) =>
limit(async () => {
const entryType = configForFile(entry);
await syncData(entry, baseDir, options, entryType);
try {
await syncData(entry, baseDir, options, entryType);
} catch (err) {
logger.error(`Failed to load ${entry}: ${err}`);
}
})
)
);

if (!watcher) {
return;
}

const matcher: RegExp = micromatch.makeRe(globOptions.pattern);

const matchesGlob = (entry: string) => !entry.startsWith('../') && matcher.test(entry);
Expand All @@ -152,11 +167,11 @@ export function glob(globOptions: GlobOptions): Loader {
await syncData(entry, baseUrl, options, entryType);
logger.info(`Reloaded data from ${green(entry)}`);
}
watcher?.on('change', onChange);
watcher.on('change', onChange);

watcher?.on('add', onChange);
watcher.on('add', onChange);

watcher?.on('unlink', async (deletedPath) => {
watcher.on('unlink', async (deletedPath) => {
const entry = relative(basePath, deletedPath);
if (!matchesGlob(entry)) {
return;
Expand Down
6 changes: 3 additions & 3 deletions packages/astro/test/content-layer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { loadFixture } from './test-utils.js';
import { sep } from 'node:path';
import { sep as posixSep } from 'node:path/posix';

describe('Content Layer', () => {
describe.only('Content Layer', () => {
/** @type {import("./test-utils.js").Fixture} */
let fixture;

before(async () => {
fixture = await loadFixture({ root: './fixtures/content-layer/' });
});

describe('Build', () => {
describe.only('Build', () => {
let json;
before(async () => {
fixture = await loadFixture({ root: './fixtures/content-layer/' });
Expand All @@ -21,7 +21,7 @@ describe('Content Layer', () => {
json = JSON.parse(rawJson);
});

it('Returns custom loader collection', async () => {
it.only('Returns custom loader collection', async () => {
assert.ok(json.hasOwnProperty('customLoader'));
assert.ok(Array.isArray(json.customLoader));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ const cats = defineCollection({
}),
});

console.log('import.meta.url', import.meta.url);
console.log('url', new URL('../../content-outside-src', import.meta.url).href );
console.log('fileURLToPath', fileURLToPath(new URL('../../content-outside-src', import.meta.url)));

// Absolute paths should also work
const absoluteRoot = fileURLToPath(new URL('../../content-outside-src', import.meta.url))
const absoluteRoot = fileURLToPath(new URL('../../content-outside-src', import.meta.url));
console.log('absoluteRoot', absoluteRoot);

const spacecraft = defineCollection({
type: 'experimental_data',
Expand Down
2 changes: 1 addition & 1 deletion scripts/cmd/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import arg from 'arg';
import glob from 'tiny-glob';

const isCI = !!process.env.CI;
const defaultTimeout = isCI ? 1400000 : 600000;
const defaultTimeout = 600000 //isCI ? 600000 : 600000;

export default async function test() {
const args = arg({
Expand Down

0 comments on commit 232773c

Please sign in to comment.