Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Yarn PnP support #2478

Merged
merged 6 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ export function getDependencyTagProvider(workspacePath: string, depPkgJson: any)
return null;
}

const tagsPath = findConfigFile(workspacePath, path.join('node_modules/', depPkgJson.name, depPkgJson.vetur.tags));
const attrsPath = findConfigFile(
workspacePath,
path.join('node_modules/', depPkgJson.name, depPkgJson.vetur.attributes)
);
const tagsPath = require.resolve(path.join(depPkgJson.name, depPkgJson.vetur.tags), { paths: [workspacePath] });
const attrsPath = require.resolve(path.join(depPkgJson.name, depPkgJson.vetur.attributes), {
paths: [workspacePath]
});

try {
if (tagsPath && attrsPath) {
Expand Down
2 changes: 1 addition & 1 deletion server/src/modes/template/tagProviders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function getTagProviderSettings(workspacePath: string | null | undefined)
}

for (const dep of [...Object.keys(dependencies), ...Object.keys(devDependencies)]) {
const runtimePkgJsonPath = findConfigFile(workspacePath, join('node_modules', dep, 'package.json'));
const runtimePkgJsonPath = require.resolve(join(dep, 'package.json'), { paths: [workspacePath] });

if (!runtimePkgJsonPath) {
continue;
Expand Down
3 changes: 1 addition & 2 deletions server/src/services/typescriptService/vueVersion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { readFileSync } from 'fs';
import path from 'path';
import { findConfigFile } from '../../utils/workspace';

export enum VueVersion {
Expand Down Expand Up @@ -31,7 +30,7 @@ export function inferVueVersion(workspacePath: string): VueVersion {
return floatVersionToEnum(sloppyVersion);
}

const nodeModulesVuePackagePath = findConfigFile(path.resolve(workspacePath, 'node_modules/vue'), 'package.json');
const nodeModulesVuePackagePath = require.resolve('vue/package.json', { paths: [workspacePath] });
const nodeModulesVuePackageJSON =
nodeModulesVuePackagePath && JSON.parse(readFileSync(nodeModulesVuePackagePath, { encoding: 'utf-8' })!);
yoyo930021 marked this conversation as resolved.
Show resolved Hide resolved
const nodeModulesVueVersion = parseFloat(nodeModulesVuePackageJSON.version.match(/\d+\.\d+/)[0]);
Expand Down
10 changes: 10 additions & 0 deletions server/src/services/vls.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path';
import fs from 'fs';
import { getFileFsPath, normalizeFileNameToFsPath } from '../utils/paths';

import {
Expand Down Expand Up @@ -106,6 +107,15 @@ export class VLS {

this.workspacePath = normalizeFileNameToFsPath(workspacePath);

// Enable PnP API
if (this.workspacePath && !process.versions.pnp && config.vetur.useWorkspaceDependencies) {
yoyo930021 marked this conversation as resolved.
Show resolved Hide resolved
if (fs.existsSync(path.join(this.workspacePath, '.pnp.js'))) {
require(path.join(workspacePath, '.pnp.js')).setup();
} else if (fs.existsSync(path.join(this.workspacePath, '.pnp.cjs'))) {
require(path.join(workspacePath, '.pnp.cjs')).setup();
}
}

this.vueInfoService.init(this.languageModes);
await this.dependencyService.init(
this.workspacePath,
Expand Down