Skip to content

Commit e03fd38

Browse files
authored
fix: optimize deps errors in global installation mode (#1559)
1 parent 0191e06 commit e03fd38

File tree

10 files changed

+202
-100
lines changed

10 files changed

+202
-100
lines changed

.github/workflows/smoke.yml

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,55 @@ on:
1414
workflow_dispatch:
1515

1616
jobs:
17+
pack:
18+
timeout-minutes: 10
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Set git to use LF
22+
run: |
23+
git config --global core.autocrlf false
24+
git config --global core.eol lf
25+
26+
- uses: actions/checkout@v4
27+
28+
- name: Use Node.js 20.x
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: 20.x
32+
33+
- name: Setup
34+
run: npm i -g @antfu/ni
35+
36+
- name: Setup PNPM
37+
uses: pnpm/action-setup@v2
38+
39+
- name: Install
40+
run: nci
41+
env:
42+
CYPRESS_INSTALL_BINARY: 0
43+
44+
- name: Build
45+
run: nr build
46+
47+
- name: Pack
48+
run: node ./scripts/pack.mjs /tmp/slidev-pkgs
49+
50+
- name: Upload artifacts
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: slidev-packages
54+
path: /tmp/slidev-pkgs
55+
1756
test:
57+
needs: pack
1858
timeout-minutes: 10
1959
runs-on: ${{ matrix.os }}
2060

2161
strategy:
2262
matrix:
2363
node-version: [18.x]
2464
os: [ubuntu-latest, windows-latest]
25-
pm: [yarn, npm, pnpm]
65+
pm: [npm, pnpm] # yarn not working in this CI
2666
hoist: [true, false]
2767

2868
steps:
@@ -33,10 +73,10 @@ jobs:
3373
3474
- uses: actions/checkout@v4
3575

36-
- name: Use Node.js ${{ matrix.node-version }}
76+
- name: Use Node.js 20.x
3777
uses: actions/setup-node@v4
3878
with:
39-
node-version: ${{ matrix.node-version }}
79+
node-version: 20.x
4080

4181
- name: Setup
4282
run: npm i -g @antfu/ni
@@ -47,15 +87,15 @@ jobs:
4787
- name: Install
4888
run: nci
4989

50-
- name: Build
51-
run: nr build
52-
53-
- name: Pack
54-
run: node ./scripts/pack.mjs ../temp/slidev-pkgs
90+
- name: Download artifacts
91+
uses: actions/download-artifact@v4
92+
with:
93+
name: slidev-packages
94+
path: /tmp/slidev-pkgs
5595

5696
- name: Create new project
5797
run: |
58-
npm i -g ../temp/slidev-pkgs/create-app.tgz
98+
npm i -g /tmp/slidev-pkgs/create-app.tgz
5999
echo "N" | create-slidev ../temp/slidev-project
60100
61101
- name: Remove npmrc
@@ -68,12 +108,12 @@ jobs:
68108
working-directory: ../temp/slidev-project
69109

70110
- name: Install project (npm, pnpm)
71-
run: ${{ matrix.pm }} i ../slidev-pkgs/cli.tgz playwright-chromium
111+
run: ${{ matrix.pm }} i /tmp/slidev-pkgs/cli.tgz playwright-chromium
72112
working-directory: ../temp/slidev-project
73113
if: ${{ matrix.pm != 'yarn' }}
74114

75115
- name: Install project (yarn)
76-
run: yarn add ../slidev-pkgs/cli.tgz playwright-chromium
116+
run: yarn add /tmp/slidev-pkgs/cli.tgz playwright-chromium
77117
working-directory: ../temp/slidev-project
78118
if: ${{ matrix.pm == 'yarn' }}
79119

@@ -92,7 +132,7 @@ jobs:
92132

93133
- name: Install globally
94134
run: |
95-
${{ matrix.pm }} i -g ${{ github.workspace }}/../temp/slidev-pkgs/cli.tgz playwright-chromium
135+
${{ matrix.pm }} i -g /tmp/slidev-pkgs/cli.tgz playwright-chromium
96136
${{ matrix.pm }} i -g @slidev/theme-seriph
97137
if: ${{ matrix.pm != 'yarn' }}
98138

packages/client/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"typescript": "^5.4.5",
6060
"unocss": "^0.59.3",
6161
"vue": "^3.4.22",
62-
"vue-demi": "^0.14.7",
6362
"vue-router": "^4.3.0",
6463
"yaml": "^2.4.1"
6564
},

packages/client/uno.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
transformerVariantGroup,
1010
} from 'unocss'
1111
import { variantMatcher } from '@unocss/preset-mini/utils'
12+
import extractorMdc from '@unocss/extractor-mdc'
1213

1314
export default defineConfig({
1415
safelist: [
@@ -48,4 +49,7 @@ export default defineConfig({
4849
transformerDirectives({ enforce: 'pre' }),
4950
transformerVariantGroup(),
5051
],
52+
extractors: [
53+
extractorMdc(),
54+
],
5155
})

packages/parser/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"prepublishOnly": "npm run build"
4545
},
4646
"dependencies": {
47+
"@antfu/utils": "^0.7.7",
4748
"@slidev/types": "workspace:*",
4849
"yaml": "^2.4.1"
4950
}

packages/slidev/node/cli.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import yargs from 'yargs'
1111
import { blue, bold, cyan, dim, gray, green, underline, yellow } from 'kolorist'
1212
import type { LogLevel, ViteDevServer } from 'vite'
1313
import type { ResolvedSlidevOptions, SlidevConfig, SlidevData, SlidevPreparserExtension } from '@slidev/types'
14-
import isInstalledGlobally from 'is-installed-globally'
1514
import equal from 'fast-deep-equal'
1615
import { verifyConfig } from '@slidev/parser'
1716
import { injectPreparserExtensionLoader } from '@slidev/parser/fs'
@@ -23,7 +22,7 @@ import { resolveOptions } from './options'
2322
import { getThemeMeta, resolveTheme } from './integrations/themes'
2423
import { parser } from './parser'
2524
import { loadSetups } from './setups/load'
26-
import { getRoots, resolveEntry } from './resolver'
25+
import { getRoots, isInstalledGlobally, resolveEntry } from './resolver'
2726
import { resolveAddons } from './integrations/addons'
2827

2928
const CONFIG_RESTART_FIELDS: (keyof SlidevConfig)[] = [
@@ -623,7 +622,7 @@ function printInfo(
623622
console.log()
624623
console.log()
625624
console.log(` ${cyan('●') + blue('■') + yellow('▲')}`)
626-
console.log(`${bold(' Slidev')} ${blue(`v${version}`)} ${isInstalledGlobally ? yellow('(global)') : ''}`)
625+
console.log(`${bold(' Slidev')} ${blue(`v${version}`)} ${isInstalledGlobally.value ? yellow('(global)') : ''}`)
627626
console.log()
628627

629628
verifyConfig(options.data.config, options.data.themeMeta, v => console.warn(yellow(` ! ${v}`)))

packages/slidev/node/resolver.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { dirname, join, resolve } from 'node:path'
1+
import { dirname, join, relative, resolve } from 'node:path'
22
import * as fs from 'node:fs'
33
import process from 'node:process'
44
import { fileURLToPath } from 'node:url'
55
import { ensurePrefix, slash } from '@antfu/utils'
6-
import isInstalledGlobally from 'is-installed-globally'
76
import { resolveGlobal } from 'resolve-global'
8-
import { findDepPkgJsonPath } from 'vitefu'
7+
import { findClosestPkgJsonPath, findDepPkgJsonPath } from 'vitefu'
98
import { resolvePath } from 'mlly'
109
import globalDirs from 'global-directory'
1110
import prompts from 'prompts'
@@ -15,6 +14,8 @@ import type { RootsInfo } from '@slidev/types'
1514

1615
const cliRoot = fileURLToPath(new URL('..', import.meta.url))
1716

17+
export const isInstalledGlobally: { value?: boolean } = {}
18+
1819
/**
1920
* Resolve path for import url on Vite client side
2021
*/
@@ -39,7 +40,7 @@ export async function resolveImportPath(importName: string, ensure = false) {
3940
}
4041
catch { }
4142

42-
if (isInstalledGlobally) {
43+
if (isInstalledGlobally.value) {
4344
try {
4445
return resolveGlobal(importName)
4546
}
@@ -57,7 +58,7 @@ export async function findPkgRoot(dep: string, parent: string, ensure: true): Pr
5758
export async function findPkgRoot(dep: string, parent: string, ensure?: boolean): Promise<string | undefined>
5859
export async function findPkgRoot(dep: string, parent: string, ensure = false) {
5960
const pkgJsonPath = await findDepPkgJsonPath(dep, parent)
60-
const path = pkgJsonPath ? dirname(pkgJsonPath) : isInstalledGlobally ? await findGlobalPkgRoot(dep, false) : undefined
61+
const path = pkgJsonPath ? dirname(pkgJsonPath) : isInstalledGlobally.value ? await findGlobalPkgRoot(dep, false) : undefined
6162
if (ensure && !path)
6263
throw new Error(`Failed to resolve package "${dep}"`)
6364
return path
@@ -104,13 +105,13 @@ export function createResolver(type: 'theme' | 'addon', officials: Record<string
104105
name: 'confirm',
105106
initial: 'Y',
106107
type: 'confirm',
107-
message: `The ${type} "${pkgName}" was not found ${underline(isInstalledGlobally ? 'globally' : 'in your project')}, do you want to install it now?`,
108+
message: `The ${type} "${pkgName}" was not found ${underline(isInstalledGlobally.value ? 'globally' : 'in your project')}, do you want to install it now?`,
108109
})
109110

110111
if (!confirm)
111112
process.exit(1)
112113

113-
if (isInstalledGlobally)
114+
if (isInstalledGlobally.value)
114115
await run(parseNi, ['-g', pkgName])
115116
else
116117
await run(parseNi, [pkgName])
@@ -227,10 +228,14 @@ export async function getRoots(entry?: string): Promise<RootsInfo> {
227228
return rootsInfo
228229
if (!entry)
229230
throw new Error('[slidev] Cannot find roots without entry')
230-
const clientRoot = await findPkgRoot('@slidev/client', cliRoot, true)
231231
const userRoot = dirname(entry)
232-
const userPkgJson = getUserPkgJson(userRoot)
233-
const userWorkspaceRoot = searchForWorkspaceRoot(userRoot)
232+
isInstalledGlobally.value
233+
= !/^(\.\.\/)*node_modules\//i.test(slash(relative(userRoot, cliRoot)))
234+
|| (await import('is-installed-globally')).default
235+
const clientRoot = await findPkgRoot('@slidev/client', cliRoot, true)
236+
const closestPkgRoot = dirname(await findClosestPkgJsonPath(userRoot) || userRoot)
237+
const userPkgJson = getUserPkgJson(closestPkgRoot)
238+
const userWorkspaceRoot = searchForWorkspaceRoot(closestPkgRoot)
234239
rootsInfo = {
235240
cliRoot,
236241
clientRoot,

0 commit comments

Comments
 (0)