brillout / telefunc

Remote Functions. Instead of API.
https://telefunc.com
MIT License
672 stars 30 forks source link

Support Yarn PnP #77

Open ezracelli opened 1 year ago

ezracelli commented 1 year ago

PnP (a module installation strategy used by Yarn Berry) stores modules in .zip files. When a package is imported, the package manager creates an isolated, read-only virtual filesystem. More info: https://yarnpkg.com/features/pnp

telefunc/vite#plugin has a side-effect that attempts to write to one of telefunc's own files. Due to the read-only nature of the virtual filesystem created by PnP, this write fails.

https://github.com/brillout/telefunc/blob/132764550bd18286f3fa321641b66145ee0d4ed6/telefunc/node/vite/index.ts#L20-L21

https://github.com/brillout/telefunc/blob/132764550bd18286f3fa321641b66145ee0d4ed6/telefunc/node/vite/importGlob/toggle.ts#L21-L22

Workaround

I patched the module manually. ```patch diff --git a/dist/cjs/node/vite/importGlob/telefuncFilesGlob.js b/dist/cjs/node/vite/importGlob/telefuncFilesGlob.js index 12d2beb0902533d560a37205d5c1779a41192d46..a9369b2a79929fd8dc53f02a50bc5d6cf000ae84 100644 --- a/dist/cjs/node/vite/importGlob/telefuncFilesGlob.js +++ b/dist/cjs/node/vite/importGlob/telefuncFilesGlob.js @@ -1,4 +1 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.importGlobUnset = void 0; -exports.importGlobUnset = true; +export const telefuncFilesGlob = import.meta.glob("/**/*.telefunc.(js|cjs|mjs|ts|cts|mts|jsx|cjsx|mjsx|tsx|ctsx|mtsx)"); diff --git a/dist/cjs/node/vite/index.js b/dist/cjs/node/vite/index.js index dd988d6ee4dd2dd361d5461df11d9742ab18b940..83523a7ccfadf5486f2899699dcd4ac3ba55c1e3 100644 --- a/dist/cjs/node/vite/index.js +++ b/dist/cjs/node/vite/index.js @@ -12,10 +12,8 @@ const importBuild_1 = require("./plugins/importBuild"); const previewConfig_1 = require("./plugins/previewConfig"); const printShieldGenResult_1 = require("./plugins/printShieldGenResult"); const manifest_1 = require("./plugins/manifest"); -const toggle_1 = require("./importGlob/toggle"); // Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed function plugin(config) { - (0, toggle_1.importGlobOn)(); const plugins = [ (0, transform_1.transform)(), (0, commonConfig_1.commonConfig)(), ```
brillout commented 1 year ago

Indeed. FYI the side-effect will be removed soon. In the meantime use pnpm (recommended) or npm instead.