Skip to content

Commit 5a1a4fc

Browse files
feat: In Memory File System (#154)
2 parents f7d0118 + 7de9a56 commit 5a1a4fc

File tree

10 files changed

+1115
-6
lines changed

10 files changed

+1115
-6
lines changed

lib/build/bundlers/esbuild/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ class Esbuild {
3636
config.plugins = [NodeModulesPolyfillPlugin(), ...config.plugins];
3737
}
3838

39+
// inject content in worker initial code.
40+
if (this.builderConfig.contentToInject) {
41+
const workerInitContent = this.builderConfig.contentToInject;
42+
43+
if (config.banner?.js) {
44+
config.banner.js = `${config.banner.js} ${workerInitContent}`;
45+
} else {
46+
config.banner = { js: workerInitContent };
47+
}
48+
}
49+
3950
try {
4051
await esbuild.build(config);
4152
} catch (error) {

lib/build/bundlers/webpack/index.js

+30
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,36 @@ class Webpack {
3131
config = merge(this.customConfigPreset, this.customConfigLocal, config);
3232
}
3333

34+
// inject content in worker initial code.
35+
if (this.builderConfig.contentToInject) {
36+
const workerInitContent = this.builderConfig.contentToInject;
37+
38+
const bannerPluginIndex = config.plugins.findIndex(
39+
(plugin) => plugin instanceof webpack.BannerPlugin,
40+
);
41+
42+
if (bannerPluginIndex !== -1) {
43+
const oldContent = config.plugins[bannerPluginIndex].options.banner;
44+
const pluginToRemove = config.plugins[bannerPluginIndex];
45+
config.plugins = config.plugins.filter(
46+
(plugin) => plugin !== pluginToRemove,
47+
);
48+
config.plugins.push(
49+
new webpack.BannerPlugin({
50+
banner: `${oldContent} ${workerInitContent}`,
51+
raw: true,
52+
}),
53+
);
54+
} else {
55+
config.plugins.push(
56+
new webpack.BannerPlugin({
57+
banner: workerInitContent,
58+
raw: true,
59+
}),
60+
);
61+
}
62+
}
63+
3464
try {
3565
const stats = await runWebpack(config);
3666

lib/build/dispatcher/dispatcher.js

+16
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
getPackageManager,
2020
getProjectJsonFile,
2121
relocateImportsAndRequires,
22+
injectFilesInMem,
2223
} from '#utils';
2324
import { Messages } from '#constants';
2425
import { vulcan } from '#env';
@@ -332,6 +333,21 @@ class Dispatcher {
332333
config.localCustom = this.custom;
333334

334335
const builderSelected = this.builder || config.builder;
336+
337+
const { injectionDirs, removePathPrefix } = this.memoryFS;
338+
if (injectionDirs && injectionDirs.length > 0) {
339+
const content = await injectFilesInMem(injectionDirs);
340+
341+
const prefix =
342+
removePathPrefix &&
343+
typeof removePathPrefix === 'string' &&
344+
removePathPrefix !== ''
345+
? `'${removePathPrefix}'`
346+
: `''`;
347+
348+
config.contentToInject = `globalThis.FS_PATH_PREFIX_TO_REMOVE = ${prefix};\n${content}`;
349+
}
350+
335351
let builder;
336352
switch (builderSelected) {
337353
case 'webpack':

0 commit comments

Comments
 (0)