Skip to content

Commit

Permalink
Fix site creation on Windows (#653)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding authored Sep 6, 2024
1 parent 58a9b85 commit 4964f00
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/create-site/bin/mosaic-create-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function readMosaicConfig(mosaicConfigPath) {
await init({ silent: true });
}
try {
const nodeModulesPathRegexp = /(.*\/node_modules\/)/;
const nodeModulesPathRegexp = /(.*[/\\]node_modules[/\\])/;
const nodeModulesPathMatches = __filename.match(nodeModulesPathRegexp);
process.env.NODE_PATH = `${process.env.NODE_PATH}${path.delimiter}${nodeModulesPathMatches[1]}`;
require('module').Module._initPaths();
Expand Down
2 changes: 0 additions & 2 deletions packages/create-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
"@types/inquirer": "^8.2.4",
"@types/node": "^18.7.19",
"commander": "^9.4.0",
"resolve": "^1.22.1",
"resolve-global": "^1.0.0",
"node-plop": "^0.31.0"
}
}
17 changes: 4 additions & 13 deletions packages/create-site/src/create.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { spawn } from 'child_process';
import nodePlop from 'node-plop';
import resolve from 'resolve';
import resolveGlobal from 'resolve-global';
import { createRequire } from 'node:module';

const { default: inquirer } = await import('inquirer');

const nodeRequire = createRequire(import.meta.url);

async function promptForGenerator(plop, allGeneratorsConfig) {
const allGenerators = plop.getGeneratorList();
const { generator } = await inquirer.prompt([
Expand Down Expand Up @@ -42,16 +43,6 @@ type CreateMosaicAppEnv = {
outputPath: string;
};

const resolvePath = filePath => {
let resolvedPath;
try {
resolvedPath = resolve.sync(filePath);
} catch {
resolvedPath = resolveGlobal(filePath);
}
return resolvedPath;
};

export default async function createMosaicApp(env: CreateMosaicAppEnv): Promise<void> {
const { generators = [], interactive = false } = env;
const generatorConfig = {};
Expand All @@ -60,7 +51,7 @@ export default async function createMosaicApp(env: CreateMosaicAppEnv): Promise<
await Promise.all(
generators.map(async generator => {
const { generatorName, ...generatorRest } = generator[1];
const generatorPath = resolvePath(generator[0]);
const generatorPath = nodeRequire.resolve(generator[0]);
generatorConfig[generatorName] = {
plopFile: generatorPath,
config: generatorRest
Expand Down
18 changes: 2 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7186,13 +7186,6 @@ glob@^7.0.0, glob@^7.1.3:
once "^1.3.0"
path-is-absolute "^1.0.0"

global-dirs@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-0.1.1.tgz#b319c0dd4607f353f3be9cca4c72fc148c49f445"
integrity sha512-NknMLn7F2J7aflwFOlGdNIuCDpN3VGoSoB+aap3KABFWbHVn1TCgFC+np23J8W2BiZbjfEw3BFBycSMv1AFblg==
dependencies:
ini "^1.3.4"

globals@^11.1.0:
version "11.12.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
Expand Down Expand Up @@ -7677,7 +7670,7 @@ inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4:
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha1-D6LGT5MpF8NDOg3tVTY6rjdBa3w=

ini@^1.3.4, ini@~1.3.0:
ini@~1.3.0:
version "1.3.8"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==
Expand Down Expand Up @@ -11331,13 +11324,6 @@ resolve-from@^5.0.0:
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69"
integrity sha1-w1IlhD3493bfIcV1V7wIfp39/Gk=

resolve-global@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/resolve-global/-/resolve-global-1.0.0.tgz#a2a79df4af2ca3f49bf77ef9ddacd322dad19255"
integrity sha512-zFa12V4OLtT5XUX/Q4VLvTfBf+Ok0SPc1FNGM/z9ctUdiU618qwKpWnd0CHs3+RqROfyEg/DhuHbMWYqcgljEw==
dependencies:
global-dirs "^0.1.1"

resolve-pkg-maps@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz#616b3dc2c57056b5588c31cdf4b3d64db133720f"
Expand All @@ -11361,7 +11347,7 @@ resolve@^1.10.0, resolve@^1.20.0:
path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0"

resolve@^1.22.0, resolve@^1.22.1:
resolve@^1.22.0:
version "1.22.1"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.1.tgz#27cb2ebb53f91abb49470a928bba7558066ac177"
integrity sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==
Expand Down

0 comments on commit 4964f00

Please sign in to comment.