Skip to content

Commit fc5dd2c

Browse files
committed
fix bugs with use as module (cli, file resolution)
1 parent 66def43 commit fc5dd2c

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

cli/index

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
#!/bin/bash
22

3-
if [[ "$*" == *"--node"* ]]; then
4-
/usr/bin/env node cli/main.js -- "$@"
5-
elif command /usr/bin/env bun &>/dev/null; then
6-
/usr/bin/env bun cli/main.js -- "$@"
7-
elif command /usr/bin/env node &>/dev/null; then
8-
/usr/bin/env node cli/main.js -- "$@"
3+
CC_MAIN_SCRIPT_PARTIAL="cherry-cola/cli/main.js"
4+
DIRNAME=$(dirname "$0")
5+
6+
if [[ $DIRNAME == *node_modules/.bin ]]; then
7+
CC_MAIN_SCRIPT="${DIRNAME//.bin/$CC_MAIN_SCRIPT_PARTIAL}"
8+
else
9+
CC_MAIN_SCRIPT="${DIRNAME}/main.js"
910
fi
11+
12+
/usr/bin/env bun "$CC_MAIN_SCRIPT" -- "$@"
13+
14+
#if [[ "$*" == *"--node"* ]]; then
15+
# /usr/bin/env node "$CC_MAIN_SCRIPT" -- "$@"
16+
#elif command /usr/bin/env bun &>/dev/null; then
17+
# /usr/bin/env bun "$CC_MAIN_SCRIPT" -- "$@"
18+
#elif command /usr/bin/env node &>/dev/null; then
19+
# /usr/bin/env node "$CC_MAIN_SCRIPT" -- "$@"
20+
#fi

example/cherry-cola-template/App.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@media (prefers-color-scheme: dark) {
1212
.App {
13-
background: #211e1e;
13+
background: #222;
1414
color: #fff;
1515
}
1616
}

example/counter/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ body {
1212

1313
@media (prefers-color-scheme: dark) {
1414
body {
15-
background: #211e1e;
15+
background: #222;
1616
color: #fff;
1717
}
1818
}

src/compiler/helpers/resolve-import-file-specifier.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import resolveFile from './resolve-file'
22
import projectRoot, {resolve as resolveProjectRoot} from '../../utils/project-root'
3+
import moduleRoot, {resolve as resolveModuleRoot} from '../../utils/module-root'
34
import {printWarning, messages as warningMessages} from '../../messages/warnings'
45

5-
const packageJson = await (Bun.file(resolveProjectRoot('package.json')) as File & { json: () => object }).json()
6+
const projectPackageJson = await (Bun.file(resolveProjectRoot('package.json')) as File & { json: () => object }).json()
7+
const modulePackageJson = await (Bun.file(resolveModuleRoot('package.json')) as File & { json: () => object }).json()
68

79
export default function resolveImportFileSpecifier(base: string, fileSpecifier: string) {
810
if (fileSpecifier.startsWith('#')) {
9-
if ('imports' in packageJson)
10-
fileSpecifier = resolveProjectRoot(packageJson.imports[fileSpecifier])
11+
if ('imports' in projectPackageJson)
12+
fileSpecifier = resolveProjectRoot(projectPackageJson.imports[fileSpecifier])
13+
else if ('imports' in modulePackageJson)
14+
fileSpecifier = resolveModuleRoot(modulePackageJson.imports[fileSpecifier])
1115
else
1216
printWarning(warningMessages.resolve.noImports, [fileSpecifier])
1317
} else {

src/utils/module-root.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ process.env.APP_MODULE_PATH = findDirWith('package.json')
55
export default process.env.APP_MODULE_PATH
66

77
export function resolve(...filePath) {
8-
return path.join(process.env.PROJECT_ROOT_PATH, ...filePath)
8+
return path.join(process.env.APP_MODULE_PATH, ...filePath)
99
}

0 commit comments

Comments
 (0)