Skip to content

Commit d675ecc

Browse files
authored
Fix installing mount points (#105)
* Fix installing mount points * Iterate
1 parent 98d55cb commit d675ecc

File tree

4 files changed

+64
-13
lines changed

4 files changed

+64
-13
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"private": true,
66
"scripts": {
77
"build": "lerna run build",
8+
"lint": "yarn run eslint && yarn run prettier",
9+
"lint:check": "yarn run eslint:check && yarn run prettier:check",
810
"prettier": "prettier --list-different --write \"packages/**/*.ts\"",
911
"prettier:check": "prettier --check \"packages/**/*.ts\"",
1012
"eslint": "eslint --ext .ts --fix .",

packages/mambajs-core/src/helper.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ export interface IEmpackEnvMetaPkg {
3434
subdir: string;
3535
}
3636

37+
export interface IEmpackEnvMetaMountPoint {
38+
name: string;
39+
filename: string;
40+
}
41+
3742
export interface IEmpackEnvMeta {
3843
prefix: string;
3944
packages: IEmpackEnvMetaPkg[];
4045
specs?: string[];
46+
mounts?: IEmpackEnvMetaMountPoint[];
4147
}
4248

4349
/**

packages/mambajs-core/src/index.ts

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
getSharedLibs,
99
IBootstrapData,
1010
IEmpackEnvMeta,
11+
IEmpackEnvMetaMountPoint,
1112
IEmpackEnvMetaPkg,
1213
ILogger,
1314
ISolvedPackage,
@@ -86,11 +87,18 @@ export interface IBootstrapEmpackPackedEnvironmentOptions {
8687
* @param options
8788
* @returns The installed shared libraries as a TSharedLibs
8889
*/
89-
export const bootstrapEmpackPackedEnvironment = async (
90+
export async function bootstrapEmpackPackedEnvironment(
9091
options: IBootstrapEmpackPackedEnvironmentOptions
91-
): Promise<IBootstrapData> => {
92+
): Promise<IBootstrapData> {
9293
const { empackEnvMeta } = options;
9394

95+
if (empackEnvMeta.mounts) {
96+
await installMountPointToEmscriptenFS({
97+
mountPoints: empackEnvMeta.mounts,
98+
...options
99+
});
100+
}
101+
94102
const solvedPkgs: ISolvedPackages = {};
95103
for (const empackPkg of empackEnvMeta.packages) {
96104
solvedPkgs[empackPkg.filename] = empackPkg;
@@ -100,14 +108,9 @@ export const bootstrapEmpackPackedEnvironment = async (
100108
packages: solvedPkgs,
101109
...options
102110
});
103-
};
104-
105-
export interface IInstallPackagesToEnvOptions {
106-
/**
107-
* The packages to install
108-
*/
109-
packages: ISolvedPackages;
111+
}
110112

113+
export interface IInstallFilesToEnvOptions {
111114
/**
112115
* The URL (CDN or similar) from which to download packages
113116
*/
@@ -139,15 +142,31 @@ export interface IInstallPackagesToEnvOptions {
139142
logger?: ILogger;
140143
}
141144

145+
export interface IInstallPackagesToEnvOptions
146+
extends IInstallFilesToEnvOptions {
147+
/**
148+
* The packages to install
149+
*/
150+
packages: ISolvedPackages;
151+
}
152+
153+
export interface IInstallMountPointsToEnvOptions
154+
extends IInstallFilesToEnvOptions {
155+
/**
156+
* The mount points to install
157+
*/
158+
mountPoints: IEmpackEnvMetaMountPoint[];
159+
}
160+
142161
/**
143162
* Install packages into an emscripten FS.
144163
*
145164
* @param options
146165
* @returns The installed shared libraries as a TSharedLibs
147166
*/
148-
export const installPackagesToEmscriptenFS = async (
167+
export async function installPackagesToEmscriptenFS(
149168
options: IInstallPackagesToEnvOptions
150-
): Promise<IBootstrapData> => {
169+
): Promise<IBootstrapData> {
151170
const { packages, pkgRootUrl, Module, generateCondaMeta, logger } = options;
152171

153172
let untarjs: IUnpackJSAPI;
@@ -208,7 +227,31 @@ export const installPackagesToEmscriptenFS = async (
208227
await waitRunDependencies(Module);
209228

210229
return { sharedLibs: sharedLibsMap, paths: paths, untarjs };
211-
};
230+
}
231+
232+
export async function installMountPointToEmscriptenFS(
233+
options: IInstallMountPointsToEnvOptions
234+
): Promise<void> {
235+
const { mountPoints, pkgRootUrl, Module, logger } = options;
236+
237+
let untarjs: IUnpackJSAPI;
238+
if (options.untarjs) {
239+
untarjs = options.untarjs;
240+
} else {
241+
const untarjsReady = initUntarJS();
242+
untarjs = await untarjsReady;
243+
}
244+
245+
await Promise.all(
246+
mountPoints.map(async mountPoint => {
247+
const url = `${pkgRootUrl}/${mountPoint.filename}`;
248+
logger?.log(`Extracting ${mountPoint.filename}`);
249+
const extractedMountPoint = await untarjs.extract(url);
250+
251+
saveFilesIntoEmscriptenFS(Module.FS, extractedMountPoint, '');
252+
})
253+
);
254+
}
212255

213256
export interface IRemovePackagesFromEnvOptions {
214257
/**

packages/mambajs-core/src/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function getCondaRemoveCommandParameters(
185185
const env: string[] = [];
186186
const limits = ['-all', '--override-frozen', '--keep-env', '--dev'];
187187
let skip = false;
188-
let envFlags = ['-n', '--name', '-p', '--prefix'];
188+
const envFlags = ['-n', '--name', '-p', '--prefix'];
189189

190190
limits.map((options: string) => {
191191
if (input.includes(options)) {

0 commit comments

Comments
 (0)