From 4964f002f31ebea8cce578eee82e083fb874c4ab Mon Sep 17 00:00:00 2001 From: Josh Wooding <12938082+joshwooding@users.noreply.github.com> Date: Fri, 6 Sep 2024 09:30:35 +0100 Subject: [PATCH] Fix site creation on Windows (#653) --- packages/create-site/bin/mosaic-create-site.js | 2 +- packages/create-site/package.json | 2 -- packages/create-site/src/create.ts | 17 ++++------------- yarn.lock | 18 ++---------------- 4 files changed, 7 insertions(+), 32 deletions(-) diff --git a/packages/create-site/bin/mosaic-create-site.js b/packages/create-site/bin/mosaic-create-site.js index 138fbc16..6e3e4499 100755 --- a/packages/create-site/bin/mosaic-create-site.js +++ b/packages/create-site/bin/mosaic-create-site.js @@ -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(); diff --git a/packages/create-site/package.json b/packages/create-site/package.json index e9d342d4..3ca1ec4a 100644 --- a/packages/create-site/package.json +++ b/packages/create-site/package.json @@ -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" } } diff --git a/packages/create-site/src/create.ts b/packages/create-site/src/create.ts index 08aaa94f..cee90b16 100755 --- a/packages/create-site/src/create.ts +++ b/packages/create-site/src/create.ts @@ -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([ @@ -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 { const { generators = [], interactive = false } = env; const generatorConfig = {}; @@ -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 diff --git a/yarn.lock b/yarn.lock index 387610cd..84932ae2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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== @@ -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" @@ -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==