Skip to content

Commit

Permalink
Merge pull request #620 from peter-at-work/feature/fix-win32-codegen
Browse files Browse the repository at this point in the history
fix: Fix codegen'd import statements in Windows environments
  • Loading branch information
FlorianRappl authored Aug 23, 2023
2 parents 182342b + 00e9864 commit 6b585f2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/framework/piral-core/src/tools/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// this file is bundled, so the references here will not be at runtime (i.e., for a user)
import { getModulePath } from 'piral-cli/src/external/resolve';
import { readFileSync, existsSync } from 'fs';
import { resolve, relative, dirname } from 'path';
import { resolve, relative, dirname, sep, posix } from 'path';

function findPackagePath(moduleDir: string) {
const packageJson = 'package.json';
Expand Down Expand Up @@ -67,8 +67,10 @@ function getModulePathOrDefault(root: string, origin: string, name: string) {
try {
const absPath = getModulePath(root, name);
const relPath = relative(origin, absPath);
// fixes relative paths on Windows OS - should use forward slash
const path = relPath.split('\\').join('/');

// The relative path is to be used in an import statement,
// so it should be normalized back to use posix path separators.
const path = relPath.split(sep).join(posix.sep);
return path;
} catch {
return name;
Expand Down

0 comments on commit 6b585f2

Please sign in to comment.