Skip to content
Closed
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 @@ -18,5 +18,8 @@ module.exports = withDefaults({
output: {
filename: 'cssServerMain.js',
path: path.join(__dirname, 'dist')
}
},
externals: {
'requireresolveproxy': 'commonjs requireresolveproxy',
},
});
1 change: 1 addition & 0 deletions extensions/css-language-features/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"main": "./out/cssServerMain",
"dependencies": {
"requireresolveproxy": "0.0.1",
"vscode-css-languageservice": "^4.0.3-next.3",
"vscode-languageserver": "^5.3.0-next.8"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import { endsWith, startsWith } from '../utils/strings';
import * as url from 'url';
import { WorkspaceFolder } from 'vscode-languageserver';
import URI from 'vscode-uri';
import { join, dirname } from 'path';
import { existsSync } from 'fs';

const resolve = require('requireresolveproxy');
Copy link
Contributor Author

@penx penx Aug 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is using require rather than import due to not having .ts typings for requireresolveproxy - happy to resolve in another way if someone can suggest how


function getModuleNameFromPath(path: string) {
// If a scoped module (starts with @) then get up until second instance of '/', otherwise get until first isntance of '/'
if (path[0] === '@') {
Expand All @@ -19,10 +20,19 @@ function getModuleNameFromPath(path: string) {
return path.substring(0, path.indexOf('/'));
}

function resolvePathToModule(_moduleName: string, _relativeTo: string): string | undefined {
// resolve the module relative to the document. We can't use `require` here as the code is webpacked.
const documentFolder = dirname(URI.parse(_relativeTo).fsPath);
const packPath = join(documentFolder, 'node_modules', _moduleName, 'package.json');
function resolvePathToModule(moduleName: string, relativeTo: string): string | undefined {
let resolved;
try {
// We can't use `require` here directly as the code is webpacked, see #78894.
// If we require.resolve('my-module') then it will follow the main property in the linked package.json
// but we want the root of the module so resolve to the package.json and then trim
resolved = resolve(`${moduleName}/package.json`, { paths: [relativeTo] });
}
catch (ex) {
return undefined;
}
// remove trailing `package.json`, which is just used to ensure we resolve to the root directory, as above
const packPath = resolved.slice(0, -12);
if (existsSync(packPath)) {
return URI.file(packPath).toString();
}
Expand Down
5 changes: 5 additions & 0 deletions extensions/css-language-features/server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ require-main-filename@^2.0.0:
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b"
integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==

[email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/requireresolveproxy/-/requireresolveproxy-0.0.1.tgz#c65ba54a3557ae778025212a5572ddce779f9607"
integrity sha512-0JGjCjOKyJJAMlWhLR+Kx6qW7+KjI7HZUipgZMQtHDg4n57r/pX17Dlke4+lwJzfkMM25I/eQ0+cHCfA5bFgPA==

semver@^5.5.0, semver@^5.7.0:
version "5.7.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.0.tgz#790a7cf6fea5459bac96110b29b60412dc8ff96b"
Expand Down