summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Drew Powers <1369770+drwpow@users.noreply.github.com> 2021-04-14 13:21:25 -0600
committerGravatar GitHub <noreply@github.com> 2021-04-14 13:21:25 -0600
commit034674c88c5eab59d1cf8883951daa60693fb95c (patch)
tree603f2e7e6e1e825f303c36ca1b72cccd3caba43d /src
parentec75312a153424a47e05d72d41f4c3152cc7ad09 (diff)
downloadastro-034674c88c5eab59d1cf8883951daa60693fb95c.tar.gz
astro-034674c88c5eab59d1cf8883951daa60693fb95c.tar.zst
astro-034674c88c5eab59d1cf8883951daa60693fb95c.zip
Add Windows Support (#93)
* Add Windows to test suite * Try implicit URL
Diffstat (limited to 'src')
-rw-r--r--src/build.ts7
-rw-r--r--src/build/bundle.ts5
-rw-r--r--src/compiler/transform/styles.ts3
-rw-r--r--src/runtime.ts11
-rw-r--r--src/search.ts8
5 files changed, 20 insertions, 14 deletions
diff --git a/src/build.ts b/src/build.ts
index 37ef560d6..51cdc6e56 100644
--- a/src/build.ts
+++ b/src/build.ts
@@ -4,6 +4,7 @@ import type { LoadResult } from './runtime';
import { existsSync, promises as fsPromises } from 'fs';
import { relative as pathRelative } from 'path';
+import { fileURLToPath } from 'url';
import { fdir } from 'fdir';
import { defaultLogDestination, error } from './logger.js';
import { createRuntime } from './runtime.js';
@@ -22,7 +23,7 @@ async function allPages(root: URL) {
const api = new fdir()
.filter((p) => /\.(astro|md)$/.test(p))
.withFullPaths()
- .crawl(root.pathname);
+ .crawl(fileURLToPath(root));
const files = await api.withPromise();
return files as string[];
}
@@ -47,7 +48,7 @@ async function writeResult(result: LoadResult, outPath: URL, encoding: null | 'u
if (result.statusCode === 500 || result.statusCode === 404) {
error(logging, 'build', result.error || result.statusCode);
} else if (result.statusCode !== 200) {
- error(logging, 'build', `Unexpected load result (${result.statusCode}) for ${outPath.pathname}`);
+ error(logging, 'build', `Unexpected load result (${result.statusCode}) for ${fileURLToPath(outPath)}`);
} else {
const bytes = result.contents;
await writeFilep(outPath, bytes, encoding);
@@ -119,7 +120,7 @@ export async function build(astroConfig: AstroConfig): Promise<0 | 1> {
if (existsSync(astroConfig.public)) {
const pub = astroConfig.public;
- const publicFiles = (await new fdir().withFullPaths().crawl(pub.pathname).withPromise()) as string[];
+ const publicFiles = (await new fdir().withFullPaths().crawl(fileURLToPath(pub)).withPromise()) as string[];
for (const filepath of publicFiles) {
const fileUrl = new URL(`file://${filepath}`);
const rel = pathRelative(pub.pathname, fileUrl.pathname);
diff --git a/src/build/bundle.ts b/src/build/bundle.ts
index a0f61289e..0a5961986 100644
--- a/src/build/bundle.ts
+++ b/src/build/bundle.ts
@@ -6,6 +6,7 @@ import type { LogOptions } from '../logger';
import esbuild from 'esbuild';
import { promises as fsPromises } from 'fs';
+import { fileURLToPath } from 'url';
import { parse } from '../parser/index.js';
import { transform } from '../compiler/transform/index.js';
import { convertMdToAstroSource } from '../compiler/index.js';
@@ -93,7 +94,7 @@ export async function collectDynamicImports(filename: URL, { astroConfig, loggin
}
await transform(ast, {
- filename: filename.pathname,
+ filename: fileURLToPath(filename),
fileID: '',
compileOptions: {
astroConfig,
@@ -281,7 +282,7 @@ export async function bundle(imports: Set<string>, { runtime, dist }: BundleOpti
const build = await rollup(inputOptions);
const outputOptions: OutputOptions = {
- dir: dist.pathname,
+ dir: fileURLToPath(dist),
format: 'esm',
exports: 'named',
entryFileNames(chunk) {
diff --git a/src/compiler/transform/styles.ts b/src/compiler/transform/styles.ts
index bb07f3267..77eedfa89 100644
--- a/src/compiler/transform/styles.ts
+++ b/src/compiler/transform/styles.ts
@@ -2,6 +2,7 @@ import crypto from 'crypto';
import fs from 'fs';
import { createRequire } from 'module';
import path from 'path';
+import { fileURLToPath } from 'url';
import autoprefixer from 'autoprefixer';
import postcss, { Plugin } from 'postcss';
import postcssKeyframes from 'postcss-icss-keyframes';
@@ -165,7 +166,7 @@ export default function transformStyles({ compileOptions, filename, fileID }: Tr
if (miniCache.tailwindEnabled === undefined) {
const tailwindNames = ['tailwind.config.js', 'tailwind.config.mjs'];
for (const loc of tailwindNames) {
- const tailwindLoc = path.join(compileOptions.astroConfig.projectRoot.pathname, loc);
+ const tailwindLoc = path.join(fileURLToPath(compileOptions.astroConfig.projectRoot), loc);
if (fs.existsSync(tailwindLoc)) {
miniCache.tailwindEnabled = true; // Success! We have a Tailwind config file.
debug(compileOptions.logging, 'tailwind', 'Found config. Enabling.');
diff --git a/src/runtime.ts b/src/runtime.ts
index 583fb97b5..24e186e1c 100644
--- a/src/runtime.ts
+++ b/src/runtime.ts
@@ -1,3 +1,4 @@
+import { fileURLToPath } from 'url';
import type { SnowpackDevServer, ServerRuntime as SnowpackServerRuntime, SnowpackConfig } from 'snowpack';
import type { AstroConfig, CollectionResult, CreateCollection, Params, RuntimeMode } from './@types/astro';
import type { LogOptions } from './logger';
@@ -223,19 +224,19 @@ async function createSnowpack(astroConfig: AstroConfig, env: Record<string, any>
};
const mountOptions = {
- [astroRoot.pathname]: '/_astro',
- [internalPath.pathname]: '/_astro_internal',
+ [fileURLToPath(astroRoot)]: '/_astro',
+ [fileURLToPath(internalPath)]: '/_astro_internal',
};
if (existsSync(astroConfig.public)) {
- mountOptions[astroConfig.public.pathname] = '/';
+ mountOptions[fileURLToPath(astroConfig.public)] = '/';
}
const snowpackConfig = await loadConfiguration({
- root: projectRoot.pathname,
+ root: fileURLToPath(projectRoot),
mount: mountOptions,
plugins: [
- [new URL('../snowpack-plugin.cjs', import.meta.url).pathname, astroPlugOptions],
+ [fileURLToPath(new URL('../snowpack-plugin.cjs', import.meta.url)), astroPlugOptions],
require.resolve('@snowpack/plugin-sass'),
require.resolve('@snowpack/plugin-svelte'),
require.resolve('@snowpack/plugin-vue'),
diff --git a/src/search.ts b/src/search.ts
index 64a9c4782..d4ed73f96 100644
--- a/src/search.ts
+++ b/src/search.ts
@@ -1,5 +1,6 @@
import { existsSync } from 'fs';
import path from 'path';
+import { fileURLToPath } from 'url';
import { fdir, PathsOutput } from 'fdir';
interface PageLocation {
@@ -99,9 +100,10 @@ const crawler = new fdir();
/** load a collection route */
function loadCollection(url: string, astroRoot: URL): { currentPage?: number; location: PageLocation } | undefined {
- const pages = (crawler.glob('**/*').crawl(path.join(astroRoot.pathname, 'pages')).sync() as PathsOutput).filter(
- (filepath) => filepath.startsWith('$') || filepath.includes('/$')
- );
+ const pages = (crawler
+ .glob('**/*')
+ .crawl(path.join(fileURLToPath(astroRoot), 'pages'))
+ .sync() as PathsOutput).filter((filepath) => filepath.startsWith('$') || filepath.includes('/$'));
for (const pageURL of pages) {
const reqURL = new RegExp('^/' + pageURL.replace(/\$([^/]+)\.astro/, '$1') + '/?(.*)');
const match = url.match(reqURL);