Skip to content

Commit

Permalink
Fix sku init on Windows (#833)
Browse files Browse the repository at this point in the history
Co-authored-by: Remus Mate <rmate@seek.com.au>
  • Loading branch information
askoufis and mrm007 committed Jun 9, 2023
1 parent 77fcf34 commit be929c0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-cobras-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sku': patch
---

Fix `sku init` on Windows
11 changes: 11 additions & 0 deletions packages/sku/lib/toPosixPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @ts-check
const path = require('path');

/**
* Replaces all win32 path separators (\) with posix path separators (/)
* @param {string} inputPath
*/
const toPosixPath = (inputPath) =>
inputPath.replaceAll(path.win32.sep, path.posix.sep);

module.exports = toPosixPath;
15 changes: 15 additions & 0 deletions packages/sku/lib/toPosixPath.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const toPosixPath = require('./toPosixPath');

describe('toPosixPath', () => {
it('should leave a posix path as-is', () => {
const inputPath = '/foo/bar/123';

expect(toPosixPath(inputPath)).toBe(inputPath);
});

it('should convert windows paths to posix paths', () => {
const inputPath = 'D:\\foo\\bar\\123';

expect(toPosixPath(inputPath)).toBe('D:/foo/bar/123');
});
});
5 changes: 3 additions & 2 deletions packages/sku/scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const chalk = require('chalk');
const fs = require('fs/promises');
const path = require('path');
const { posix: path } = require('path');
const emptyDir = require('empty-dir');
const validatePackageName = require('validate-npm-package-name');
const dedent = require('dedent');
Expand All @@ -13,6 +13,7 @@ const esLintFix = require('../lib/runESLint').fix;
const configure = require('../lib/configure');
const install = require('../lib/install');
const banner = require('../lib/banner');
const toPosixPath = require('../lib/toPosixPath');
const trace = require('debug')('sku:init');
const glob = require('fast-glob');
const ejs = require('ejs');
Expand Down Expand Up @@ -148,7 +149,7 @@ const getTemplateFileDestinationFromRoot =

const useYarn = detectYarn();

const templateDirectory = path.join(__dirname, '../template');
const templateDirectory = path.join(toPosixPath(__dirname), '../template');
const templateFiles = await glob(`${templateDirectory}/**/*`, {
onlyFiles: true,
});
Expand Down

0 comments on commit be929c0

Please sign in to comment.