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 all 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
20 changes: 8 additions & 12 deletions server/src/modes/template/tagProviders/externalTagProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,15 @@ 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)
);

try {
if (tagsPath && attrsPath) {
const tagsJson = JSON.parse(fs.readFileSync(tagsPath, 'utf-8'));
const attrsJson = JSON.parse(fs.readFileSync(attrsPath, 'utf-8'));
return getExternalTagProvider(depPkgJson.name, tagsJson, attrsJson);
}
return null;
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]
});

const tagsJson = JSON.parse(fs.readFileSync(tagsPath, 'utf-8'));
const attrsJson = JSON.parse(fs.readFileSync(attrsPath, 'utf-8'));
return getExternalTagProvider(depPkgJson.name, tagsJson, attrsJson);
} catch (err) {
return null;
}
Expand Down
7 changes: 4 additions & 3 deletions server/src/modes/template/tagProviders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ 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'));

if (!runtimePkgJsonPath) {
let runtimePkgJsonPath;
try {
runtimePkgJsonPath = require.resolve(join(dep, 'package.json'), { paths: [workspacePath] });
} catch {
continue;
}

Expand Down
6 changes: 2 additions & 4 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,9 +30,8 @@ export function inferVueVersion(workspacePath: string): VueVersion {
return floatVersionToEnum(sloppyVersion);
}

const nodeModulesVuePackagePath = findConfigFile(path.resolve(workspacePath, 'node_modules/vue'), 'package.json');
const nodeModulesVuePackageJSON =
nodeModulesVuePackagePath && JSON.parse(readFileSync(nodeModulesVuePackagePath, { encoding: 'utf-8' })!);
const nodeModulesVuePackagePath = require.resolve('vue/package.json', { paths: [workspacePath] });
const nodeModulesVuePackageJSON = JSON.parse(readFileSync(nodeModulesVuePackagePath, { encoding: 'utf-8' })!);
const nodeModulesVueVersion = parseFloat(nodeModulesVuePackageJSON.version.match(/\d+\.\d+/)[0]);

return floatVersionToEnum(nodeModulesVueVersion);
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 Yarn PnP support https://yarnpkg.com/features/pnp
if (!process.versions.pnp) {
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