Skip to content
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
10 changes: 10 additions & 0 deletions .changeset/fair-eels-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@halfdomelabs/baseplate-plugin-storage': patch
'@halfdomelabs/project-builder-server': patch
'@halfdomelabs/project-builder-test': patch
'@halfdomelabs/project-builder-lib': patch
'@halfdomelabs/core-generators': patch
'@halfdomelabs/sync': patch
---

Support generation on Windows platforms
10 changes: 8 additions & 2 deletions packages/core-generators/src/generators/node/prettier/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import fs from 'fs-extra';
import _ from 'lodash';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { packageUp } from 'package-up';
import prettier from 'prettier';
import prettierPluginPackageJson from 'prettier-plugin-packagejson';
Expand Down Expand Up @@ -175,7 +176,10 @@ const PrettierGenerator = createGeneratorWithChildren({
if (result.version === prettier.version) {
return prettier;
}
const rawImport = (await import(result.modulePath)) as {
const rawImport = (await import(
// use file:// to support Windows
pathToFileURL(result.modulePath).href
)) as {
default: PrettierModule;
};
return rawImport.default;
Expand All @@ -202,7 +206,9 @@ const PrettierGenerator = createGeneratorWithChildren({

return plugin.version === resolvedModule.version
? plugin.default
: (import(resolvedModule.modulePath) as Plugin);
: (import(
pathToFileURL(resolvedModule.modulePath).href
) as Plugin);
}),
);

Expand Down
11 changes: 8 additions & 3 deletions packages/core-generators/src/utils/path.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import path from 'node:path';

/**
* Builds out the full path so it can be used for imports/writing to file
* @param path Path to the file with file extension
*/
export function makeImportAndFilePath(path: string): [string, string] {
const importPath = `@/${path.replace(/\.(ts|tsx)$/, '.js')}`;
return [importPath, path];
export function makeImportAndFilePath(filePath: string): [string, string] {
const importPath = `@/${filePath
.replace(/\.(ts|tsx)$/, '.js')
// normalize path separators for Windows to POSIX for imports
.replaceAll(path.sep, path.posix.sep)}`;
return [importPath, filePath];
}
4 changes: 3 additions & 1 deletion packages/core-generators/src/writers/typescript/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export function resolveModule(
// figure out relative directory
const absolutePath = moduleSpecifier.slice(2);
const relativePathImport = (() => {
const relativePath = path.relative(directory, absolutePath);
const relativePath = path
.relative(directory, absolutePath)
.replaceAll(path.sep, path.posix.sep);

return relativePath.startsWith('./') ||
relativePath.startsWith('../') ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ function getWebEntrypointImport(
entrypointPath: string,
): string {
const pathWithoutExtension = entrypointPath.replace(/\.[jt]sx?$/, '');
const relativeEntrypoint = path.relative(
pluginDirectory,
pathWithoutExtension,
);
const relativeEntrypoint = path
.relative(pluginDirectory, pathWithoutExtension)
.replace(/\\/g, '/');
return `${pluginName}/${relativeEntrypoint}`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
modelTransformerCompilerSpec,
} from '@halfdomelabs/project-builder-lib';
import path from 'node:path';
import { pathToFileURL } from 'node:url';

import { discoverPlugins } from './plugin-discovery.js';

Expand All @@ -29,7 +30,7 @@ export async function createNodePluginStore(
metadata: plugin,
modules: await Promise.all(
plugin.nodeModulePaths.map(async (modulePath) => {
const mod = (await import(modulePath)) as
const mod = (await import(pathToFileURL(modulePath).href)) as
| { default: PluginPlatformModule }
| PluginPlatformModule;
const unwrappedModule = 'default' in mod ? mod.default : mod;
Expand Down
5 changes: 4 additions & 1 deletion packages/project-builder-test/src/runner/discover-tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { globby } from 'globby';
import path from 'node:path';
import { pathToFileURL } from 'node:url';

import type { ProjectBuilderTest } from '@src/types.js';

Expand All @@ -22,7 +23,9 @@ export async function discoverTests(

return Promise.all(
matchingTestFiles.map(async (testFile) => {
const file = (await import(path.join(testDirectory, testFile))) as {
const file = (await import(
pathToFileURL(path.join(testDirectory, testFile)).href
)) as {
default?: ProjectBuilderTest;
};
if (!file.default || typeof file.default !== 'object') {
Expand Down
12 changes: 9 additions & 3 deletions packages/sync/src/core/generator-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,15 @@ export class OutputBuilder implements GeneratorOutputBuilder {
}

resolvePath(relativePath: string): string {
return this.baseDirectory
? path.join(this.baseDirectory, relativePath)
: relativePath;
return (
(
this.baseDirectory
? path.join(this.baseDirectory, relativePath)
: relativePath
)
// normalize all paths to POSIX style / paths
.replaceAll(path.sep, path.posix.sep)
);
}

setBaseDirectory(baseDirectory: string): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/sync/src/core/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function loadGeneratorsForModule(
`Generator function lacks a parseDescriptor function: ${generatorFolder}`,
);
}
const name = `${moduleName.replace(/-generators$/, '')}/${folder}`;
const name = `${moduleName.replace(/-generators$/, '')}/${folder.replaceAll(path.sep, path.posix.sep)}`;

return {
[name]: {
Expand Down
6 changes: 5 additions & 1 deletion packages/sync/src/utils/require.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import path from 'node:path';
import { pathToFileURL } from 'node:url';

/**
* Simple function to load a module dynamically
*
* @param module Name of module to load
*/
export async function getModuleDefault<T>(module: string): Promise<T | null> {
const importedModule = (await import(path.join(module, 'index.js'))) as {
const fileUrl = module.startsWith('file://')
? module
: pathToFileURL(module).href;
const importedModule = (await import(path.join(fileUrl, 'index.js'))) as {
default: T;
};
return importedModule.default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const StorageModuleGenerator = createGeneratorWithTasks({
pothosSetup.getTypeReferences().addInputType({
typeName: 'FileUploadInput',
exportName: 'fileUploadInputInputType',
moduleName: `@/${path.join(
moduleName: `@/${path.posix.join(
moduleFolder,
'schema/file-upload.input-type.js',
)}`,
Expand Down
Loading