-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5252 from Shopify/fd-fix-nx-dep
[Theme] Change how assets are resolved
- Loading branch information
Showing
2 changed files
with
13 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import {dirname, joinPath} from '@shopify/cli-kit/node/path' | ||
import {createRequire} from 'node:module' | ||
|
||
const require = createRequire(import.meta.url) | ||
import {findPathUp} from '@shopify/cli-kit/node/fs' | ||
import {joinPath, dirname} from '@shopify/cli-kit/node/path' | ||
import {fileURLToPath} from 'node:url' | ||
|
||
export async function resolveAssetPath(...subpaths: string[]) { | ||
if (process.env.SHOPIFY_UNIT_TEST) { | ||
return joinPath(__dirname, '..', '..', '..', ...subpaths) | ||
const rootPkgJon = await findPathUp('package.json', { | ||
cwd: fileURLToPath(import.meta.url), | ||
type: 'file', | ||
}) | ||
|
||
if (!rootPkgJon) { | ||
throw new Error('Failed to find CLI root path') | ||
} | ||
|
||
const cliRootPath = dirname(require.resolve('@shopify/cli/package.json')) | ||
return joinPath(cliRootPath, 'dist', 'assets', ...subpaths) | ||
return rootPkgJon.endsWith('/packages/theme/package.json') | ||
? joinPath(dirname(rootPkgJon), 'assets', ...subpaths) | ||
: joinPath(dirname(rootPkgJon), 'dist', 'assets', ...subpaths) | ||
} |