diff --git a/.changeset/tender-cobras-provide.md b/.changeset/tender-cobras-provide.md new file mode 100644 index 000000000..539e28b72 --- /dev/null +++ b/.changeset/tender-cobras-provide.md @@ -0,0 +1,5 @@ +--- +'sku': patch +--- + +Fix `sku init` on Windows diff --git a/packages/sku/lib/toPosixPath.js b/packages/sku/lib/toPosixPath.js new file mode 100644 index 000000000..1fabe3b5f --- /dev/null +++ b/packages/sku/lib/toPosixPath.js @@ -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; diff --git a/packages/sku/lib/toPosixPath.test.js b/packages/sku/lib/toPosixPath.test.js new file mode 100644 index 000000000..2806304d6 --- /dev/null +++ b/packages/sku/lib/toPosixPath.test.js @@ -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'); + }); +}); diff --git a/packages/sku/scripts/init.js b/packages/sku/scripts/init.js index 6a6c2bfee..dd6bf03c5 100644 --- a/packages/sku/scripts/init.js +++ b/packages/sku/scripts/init.js @@ -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'); @@ -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'); @@ -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, });