Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix codegen'd import statements in Windows environments #620

Merged
merged 5 commits into from
Aug 23, 2023
Merged
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
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
Loading