A platform for community discussion. Free, open, simple.
DEV: Replace memfs with a in-repo fs helper (#39571)
Jarek Radoszc70b54729a6a
diff --git a/frontend/asset-processor/package.json b/frontend/asset-processor/package.jsonindex edec7685b10..2ffdb9652af 100644--- a/frontend/asset-processor/package.json+++ b/frontend/asset-processor/package.json@@ -28,7 +28,6 @@"ember-this-fallback": "^0.4.0","fastestsmallesttextencoderdecoder": "^1.0.22","magic-string": "^0.30.21",- "memfs": "^4.39.0","path-browserify": "^1.0.1","polyfill-crypto.getrandomvalues": "^1.0.0","postcss": "^8.5.10",diff --git a/frontend/asset-processor/theme-rollup.js b/frontend/asset-processor/theme-rollup.jsindex a4720ccb967..564bc6533ca 100644--- a/frontend/asset-processor/theme-rollup.js+++ b/frontend/asset-processor/theme-rollup.js@@ -6,7 +6,6 @@ import DecoratorTransforms from "decorator-transforms";import colocatedBabelPlugin from "ember-cli-htmlbars/lib/colocated-babel-plugin";import { precompile } from "ember-source/ember-template-compiler/index.js";import EmberThisFallback from "ember-this-fallback";-import { memfs } from "memfs";import { browsers } from "../discourse/config/targets";import babelTransformModuleRenames from "../discourse/lib/babel-transform-module-renames";import AddThemeGlobals from "./add-theme-globals";@@ -20,6 +19,7 @@ import discourseTerser from "./rollup-plugins/discourse-terser";import discourseVirtualLoader from "./rollup-plugins/discourse-virtual-loader";import buildEmberTemplateManipulatorPlugin from "./theme-hbs-ast-transforms";import transformActionSyntax from "./transform-action-syntax";+import createVirtualFs from "./virtual-fs";let lastRollupResult;let lastRollupError;@@ -37,14 +37,14 @@ async function performRollup(modules, opts) {inputConfig[key] = `virtual:entrypoint:${key}`;}- const { vol } = memfs(modules, basePath);+ const fs = createVirtualFs(modules, basePath);const cache = opts.pluginName ? caches.get(opts.pluginName) : false;const result = await rollup({input: inputConfig,logLevel: "info",- fs: vol.promises,+ fs,cache,onLog(level, message) {if (String(message).startsWith("Circular dependency")) {diff --git a/frontend/asset-processor/virtual-fs.js b/frontend/asset-processor/virtual-fs.jsnew file mode 100644index 00000000000..a0101bc7708--- /dev/null+++ b/frontend/asset-processor/virtual-fs.js@@ -0,0 +1,51 @@+// Minimal in-memory fs for `@rollup/browser`. Only implements what+// it actually needs for bundling.++const FILE_STATS = {+ isFile: () => true,+ isSymbolicLink: () => false,+};++export default function createVirtualFs(modules, basePath) {+ const files = new Map();+ const dirs = new Map();++ for (const [key, content] of Object.entries(modules)) {+ const path = basePath + key;+ files.set(path, content);++ const slash = path.lastIndexOf("/");+ const parent = path.slice(0, slash);+ let children = dirs.get(parent);+ if (!children) {+ children = [];+ dirs.set(parent, children);+ }+ children.push(path.slice(slash + 1));+ }++ return {+ async readFile(path) {+ const content = files.get(path);+ if (content === undefined) {+ throw new Error(`ENOENT: ${path}`);+ }+ return content;+ },++ async readdir(path) {+ const children = dirs.get(path);+ if (!children) {+ throw new Error(`ENOENT: ${path}`);+ }+ return children;+ },++ async lstat(path) {+ if (files.has(path)) {+ return FILE_STATS;+ }+ throw new Error(`ENOENT: ${path}`);+ },+ };+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 56a1eb3c15a..e09640748c0 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -176,9 +176,6 @@ importers:magic-string:specifier: ^0.30.21version: 0.30.21- memfs:- specifier: ^4.39.0- version: 4.39.0path-browserify:specifier: ^1.0.1version: 1.0.1@@ -2572,42 +2569,6 @@ packages:resolution: {integrity: sha512-vUQ7Oy+7VfNIzu6irtPz5qfHbMNTlQWUbHJ7eunxFza+SBwUXfq2Uh5QYD2d6hLDhF22sYh8DPpLWFixQrt1+Q==}engines: {node: '>= 0.8.0'}- '@jsonjoy.com/[email protected]':- resolution: {integrity: sha512-q6XAnWQDIMA3+FTiOYajoYqySkO+JSat0ytXGSuRdq9uXE7o92gzuQwQM14xaCRlBLGq3v5miDGC4vkVTn54xA==}- engines: {node: '>=10.0'}- peerDependencies:- tslib: '2'-- '@jsonjoy.com/[email protected]':- resolution: {integrity: sha512-NDigYR3PHqCnQLXYyoLbnEdzMMvzeiCWo1KOut7Q0CoIqg9tUAPKJ1iq/2nFhc5kZtexzutNY0LFjdwWL3Dw3Q==}- engines: {node: '>=10.0'}- peerDependencies:- tslib: '2'-- '@jsonjoy.com/[email protected]':- resolution: {integrity: sha512-E8Oy+08cmCf0EK/NMxpaJZmOxPqM+6iSe2S4nlSBrPZOORoDJILxtbSUEDKQyTamm/BVAhIGllOBNU79/dwf0g==}- engines: {node: '>=10.0'}- peerDependencies:- tslib: '2'-- '@jsonjoy.com/[email protected]':- resolution: {integrity: sha512-nLqSTAYwpk+5ZQIoVp7pfd/oSKNWlEdvTq2LzVA4r2wtWZg6v+5u0VgBOaDJuUfNOuw/4Ysq6glN5QKSrOCgrA==}- engines: {node: '>=10.0'}- peerDependencies:- tslib: '2'-- '@jsonjoy.com/[email protected]':- resolution: {integrity: sha512-Fsn6wM2zlDzY1U+v4Nc8bo3bVqgfNTGcn6dMgs6FjrEnt4ZCe60o6ByKRjOGlI2gow0aE/Q41QOigdTqkyK5fg==}- engines: {node: '>=10.0'}- peerDependencies:- tslib: '2'-- '@jsonjoy.com/[email protected]':- resolution: {integrity: sha512-pLuQo+VPRnN8hfPqUTLTHk126wuYdXVxE6aDmjSeV4NCAgyxWbiOIeNJVtID3h1Vzpoi9m4jXezf73I6LgabgQ==}- engines: {node: '>=10.0'}- peerDependencies:- tslib: '2'-'@jspreadsheet/[email protected]':resolution: {integrity: sha512-PDQYf9REQA53I7tVYkvkeyQxrd5jcjUeHgItYnRpjN2QiIQwawSqBDtGGEVQTSboTG+JwgGCuhvOpj7FxeKwew==}@@ -5737,12 +5698,6 @@ packages:resolution: {integrity: sha512-evR4kvr6s0Yo5t4CD4H171n4T8XcnPFznvsbeN8K9FPzc0Q0wYqcOWyGtck2qcvJSLXKnU6DnDyfmbDDabYvRQ==}engines: {node: '>=10.13.0'}- resolution: {integrity: sha512-CG/iEvgQqfzoVsMUbxSJcwbG2JwyZ3naEqPkeltwl0BSS8Bp83k3xlGms+0QdWFUAwV+uvo80wNswKF6FWEkKg==}- engines: {node: '>=10.0'}- peerDependencies:- tslib: '2'-resolution: {integrity: sha512-Iozmtbqv0noj0uDDqoL0zNq0VBEfK2YFoMAZoxJe4cwphvLR+JskfF30QhXHOR4m3KrE6NLRYw+U9MRXvifyig==}@@ -5990,10 +5945,6 @@ packages:resolution: {integrity: sha512-eKCa6bwnJhvxj14kZk5NCPc6Hb6BdsU9DZcOnmQKSnO1VKrfV0zCvtttPZUsBvjmNDn8rpcJfpwSYnHBjc95MQ==}engines: {node: '>=18.18.0'}- resolution: {integrity: sha512-Y93lCzHYgGWdrJ66yIktxiaGULYc6oGiABxhcO5AufBeOyoIdZF7bIfLaOrbM0iGIOXQQgxxRrFEnb+Y6w1n4A==}- engines: {node: '>=10.18'}-resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==}engines: {node: '>=0.10.0'}@@ -6838,10 +6789,6 @@ packages:resolution: {integrity: sha512-qFCFUDs7U3b8mBDPyz5EToEKoAkgCzqquIgi9nkkR9bixxOVOre+09lbuH7+9Kn2NFpm56M3GUWVbU2hQgdACA==}engines: {node: '>=10'}- resolution: {integrity: sha512-tFRr2IkSXl2B6IAJsxjHIMTOsfLt9W+8+t2uNxCeQcz4tFqgQR8DYk8hlLH2HsucTctLuoHq3U0G08atyBE3yw==}- engines: {node: '>= 4.0.0'}-resolution: {integrity: sha512-qVQ/CjkMyMInPaaRMrwWNDvf6boRZXaT/DbQeMYcCWuXPEBf1v8qChOc9OlEVQp2uOvRXa1Qu30fLmKhY6NipA==}@@ -8759,12 +8706,6 @@ packages:resolution: {integrity: sha512-49WtAWS+tcsy93dRt6P0P3AMD2m5PvXRhuEA0kaXos5ZLlujtYmpmFsB+QvWUSxE1ZsstmYXfQ7L40+EcQgpAQ==}engines: {node: '>=0.8'}- resolution: {integrity: sha512-s+2Bwztg6PhWUD7XMfeYm5qliDdSiZm7M7n8KjTkIsm3l/2lgVRc2/Gx/v+ZX8lT4FMA+i8aQvhcWylldc+ZNw==}- engines: {node: '>=10.18'}- peerDependencies:- tslib: ^2-resolution: {integrity: sha512-ByaL2TPb+m6yArpqQUZvP+5S1mZtXsEP7nWKKlAUTm7fCml8kB5s1uI3+eHRP2bk5mVYfRSBI7FFf+tWEyLZwA==}engines: {node: '>= 10.13.0'}@@ -8868,12 +8809,6 @@ packages:resolution: {integrity: sha512-IUWnUK7ADYR5Sl1fZlO1INDUhVhatWl7BtJWsIhwJ0UAK7ilzzIa8uIqOO/aYVWHZPJkKbEL+362wrzoeRF7bw==}engines: {node: '>=18'}- resolution: {integrity: sha512-rMuvhU4MCDbcbnleZTFezWsaZXRFemSqAM+7jPnzUl1fo9w3YEKOxAeui0fz3OI4EU4hf23iyA7uQRVko+UaBA==}- engines: {node: '>=10.0'}- peerDependencies:- tslib: '2'-resolution: {integrity: sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==}hasBin: true@@ -11399,41 +11334,6 @@ snapshots:dependencies:core-js: 3.49.0- '@jsonjoy.com/[email protected]([email protected])':- dependencies:- tslib: 2.8.1-- '@jsonjoy.com/[email protected]([email protected])':- dependencies:- tslib: 2.8.1-- '@jsonjoy.com/[email protected]([email protected])':- dependencies:- tslib: 2.8.1-- '@jsonjoy.com/[email protected]([email protected])':- dependencies:- '@jsonjoy.com/base64': 1.1.2([email protected])- '@jsonjoy.com/buffers': 1.0.0([email protected])- '@jsonjoy.com/codegen': 1.0.0([email protected])- '@jsonjoy.com/json-pointer': 1.0.2([email protected])- '@jsonjoy.com/util': 1.9.0([email protected])- hyperdyperid: 1.2.0- thingies: 2.5.0([email protected])- tslib: 2.8.1-- '@jsonjoy.com/[email protected]([email protected])':- dependencies:- '@jsonjoy.com/codegen': 1.0.0([email protected])- '@jsonjoy.com/util': 1.9.0([email protected])- tslib: 2.8.1-- '@jsonjoy.com/[email protected]([email protected])':- dependencies:- '@jsonjoy.com/buffers': 1.0.0([email protected])- '@jsonjoy.com/codegen': 1.0.0([email protected])- tslib: 2.8.1-'@jspreadsheet/[email protected]': {}'@jsquash/[email protected]': {}@@ -15538,10 +15438,6 @@ snapshots:to-absolute-glob: 2.0.2unique-stream: 2.3.1- dependencies:- tslib: 2.8.1-@@ -15823,8 +15719,6 @@ snapshots:- [email protected]: {}-dependencies:safer-buffer: 2.1.2@@ -16683,15 +16577,6 @@ snapshots:map-age-cleaner: 0.1.3mimic-fn: 3.1.0- dependencies:- '@jsonjoy.com/json-pack': 1.11.0([email protected])- '@jsonjoy.com/util': 1.9.0([email protected])- glob-to-regex.js: 1.0.1([email protected])- thingies: 2.5.0([email protected])- tree-dump: 1.1.0([email protected])- tslib: 2.8.1-dependencies:readable-stream: 1.0.34@@ -18974,10 +18859,6 @@ snapshots:- dependencies:- tslib: 2.8.1-dependencies:json-parse-better-errors: 1.0.2@@ -19092,10 +18973,6 @@ snapshots:dependencies:punycode: 2.3.1- dependencies:- tslib: 2.8.1-