Skip to content

Commit

Permalink
fix: can't find prettier module bugfix (#105)
Browse files Browse the repository at this point in the history
* fix: can't find prettier module bugfix

* [skip ci]: add missing changlog
  • Loading branch information
iChenLei committed Aug 31, 2021
1 parent 2cab1dd commit 21a1989
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
6 changes: 4 additions & 2 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.github/**
.vscode/**
.vscode-test/**
dist/test/**
Expand All @@ -10,5 +11,6 @@ src/**
tsconfig.json
vsc-extension-quickstart.md
vendor/**
node_modules/**
!node_modules/prettier/

node_modules/
!node_modules/prettier
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
2.3.2 / 2021-08-30
2.3.3 / 2021-08-31
==================

* 参考vscode-eslint处理webpack打包时`require`语句失效的问题

2.3.2 / 2021-08-31
==================

* 将prettier打包进vsix文件,修复#103
Expand Down
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "minapp-vscode",
"displayName": "WXML - Language Services",
"description": "微信小程序.wxml文件代码高亮,标签、属性的智能补全(同时支持原生小程序、mpvue 和 wepy 框架,并提供code snippets)",
"version": "2.3.2",
"version": "2.3.3",
"publisher": "qiu8310",
"extensionKind": [
"workspace"
Expand Down Expand Up @@ -290,16 +290,14 @@
"@minapp/common": "^3.0.0",
"@minapp/wxml-parser": "^2.1.5",
"mora-scripts": "^1.6.28",
"prettier": "^1.19.1",
"read-pkg-up": "^7.0.1",
"resolve": "^1.20.0",
"tslib": "^2.3.1"
},
"optionalDependencies": {
"prettier": "^1.19.1"
},
"devDependencies": {
"@types/mocha": "^9.0.0",
"@types/prettier": "~1.19.0",
"@types/prettier": "^1.19.1",
"@types/resolve": "1.20.1",
"@types/sass": "~1.16.1",
"@types/vscode": "^1.59.0",
Expand Down
12 changes: 10 additions & 2 deletions src/plugin/lib/requirePackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import * as resolve from 'resolve'
import * as readPkgUp from 'read-pkg-up'
import { existsSync } from 'fs'

declare const __webpack_require__: typeof require;
declare const __non_webpack_require__: typeof require;

function findPkg(fspath: string, pkgName: string): string | undefined {
const res = readPkgUp.sync({ cwd: fspath, normalize: false })
const { root } = path.parse(fspath)
Expand Down Expand Up @@ -31,14 +34,19 @@ function findPkg(fspath: string, pkgName: string): string | undefined {
*/
export function requireLocalPkg<T>(fspath: string, pkgName: string): T {
let modulePath
// Source: https://github.com/microsoft/vscode-eslint/blob/master/server/src/eslintServer.ts
const r =
typeof __webpack_require__ === "function"
? __non_webpack_require__
: require;
try {
modulePath = findPkg(fspath, pkgName)
if (modulePath !== void 0) {
return require(modulePath)
return r(modulePath)
}
} catch (e) {
console.warn(`Failed to load ${pkgName} from ${modulePath}. Using bundled.`)
}

return require(pkgName)
return r(pkgName)
}

0 comments on commit 21a1989

Please sign in to comment.