openmrs 4.0.3-pre.437 → 4.0.3-pre.441

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- openmrs:build: cache hit, replaying output c2956d28125053a6
1
+ openmrs:build: cache hit, replaying output fd3954fc021fe48c
package/dist/cli.js CHANGED
@@ -1,24 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
- }) : (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- o[k2] = m[k];
9
- }));
10
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
11
- Object.defineProperty(o, "default", { enumerable: true, value: v });
12
- }) : function(o, v) {
13
- o["default"] = v;
14
- });
15
- var __importStar = (this && this.__importStar) || function (mod) {
16
- if (mod && mod.__esModule) return mod;
17
- var result = {};
18
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19
- __setModuleDefault(result, mod);
20
- return result;
21
- };
22
3
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
23
4
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
24
5
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -28,8 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
28
9
  step((generator = generator.apply(thisArg, _arguments || [])).next());
29
10
  });
30
11
  };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
31
15
  Object.defineProperty(exports, "__esModule", { value: true });
32
- const yargs = __importStar(require("yargs"));
16
+ const yargs_1 = __importDefault(require("yargs"));
33
17
  const child_process_1 = require("child_process");
34
18
  const path_1 = require("path");
35
19
  const utils_1 = require("./utils");
@@ -43,7 +27,7 @@ function runCommand(type, args) {
43
27
  });
44
28
  ps.on("exit", (code) => process.exit(code || 0));
45
29
  }
46
- yargs.command("debug", "Starts a new debugging session of the OpenMRS app shell. This uses Webpack as a debug server with proxy middleware.", (argv) => argv
30
+ yargs_1.default.command("debug", "Starts a new debugging session of the OpenMRS app shell. This uses Webpack as a debug server with proxy middleware.", (argv) => argv
47
31
  .number("port")
48
32
  .default("port", 8080)
49
33
  .describe("port", "The port where the dev server should run.")
@@ -86,7 +70,7 @@ yargs.command("debug", "Starts a new debugging session of the OpenMRS app shell.
86
70
  return runCommand("runDebug", Object.assign(Object.assign({ configUrls: args["config-url"] }, args), { importmap: (0, utils_1.proxyImportmap)(yield (0, utils_1.mergeImportmap)(yield (0, utils_1.getImportmap)(args.importmap, args.port), (args["run-project"] || args.runProject) &&
87
71
  (yield (0, utils_1.runProject)(args.port, args["shared-dependencies"], args.sources))), args.backend, args.host, args.port) }));
88
72
  }));
89
- yargs.command("develop", "Starts a new frontend module development session with the OpenMRS app shell.", (argv) => argv
73
+ yargs_1.default.command("develop", "Starts a new frontend module development session with the OpenMRS app shell.", (argv) => argv
90
74
  .number("port")
91
75
  .default("port", 8080)
92
76
  .describe("port", "The port where the dev server should run.")
@@ -123,7 +107,7 @@ yargs.command("develop", "Starts a new frontend module development session with
123
107
  return runCommand("runDevelop", Object.assign(Object.assign({ configUrls: args["config-url"] }, args), { importmap: (0, utils_1.proxyImportmap)(yield (0, utils_1.mergeImportmap)(yield (0, utils_1.getImportmap)(args.importmap, args.port), args.sources[0] !== false &&
124
108
  (yield (0, utils_1.runProject)(args.port, args["shared-dependencies"], args.sources)), args.backend, args.spaPath), args.backend, args.host, args.port) }));
125
109
  }));
126
- yargs.command("build", "Builds a new app shell.", (argv) => argv
110
+ yargs_1.default.command("build", "Builds a new app shell.", (argv) => argv
127
111
  .string("target")
128
112
  .default("target", "dist")
129
113
  .describe("target", "The target directory where the build artifacts will be stored.")
@@ -160,23 +144,42 @@ yargs.command("build", "Builds a new app shell.", (argv) => argv
160
144
  .describe("download-coreapps", "Downloads and bundles the core apps. For cases where the core apps are not in the import map."), (args) => __awaiter(void 0, void 0, void 0, function* () {
161
145
  return runCommand("runBuild", Object.assign(Object.assign({ configUrls: args["config-url"], configPaths: args["config-path"].map((p) => (0, path_1.resolve)(process.cwd(), p)) }, args), { importmap: args.importmap, buildConfig: args["build-config"] && (0, path_1.resolve)(process.cwd(), args["build-config"]), target: (0, path_1.resolve)(process.cwd(), args.target) }));
162
146
  }));
163
- yargs.command("assemble", "Assembles an import map incl. all required resources.", (argv) => argv
164
- .string("target")
165
- .default("target", "dist")
166
- .describe("target", "The target directory where the gathered artifacts will be stored.")
167
- .string("registry")
168
- .default("registry", "https://registry.npmjs.org/")
169
- .describe("registry", "The NPM registry used for getting the packages.")
170
- .string("config")
171
- .default("config", "spa-build-config.json")
172
- .describe("config", "Path to a SPA build config JSON.")
173
- .boolean("fresh")
174
- .describe("fresh", "Determines if the output directory should be cleaned before the run.")
175
- .default("fresh", false)
176
- .choices("mode", ["config", "survey"])
177
- .default("mode", "survey")
178
- .describe("mode", "The source of the frontend modules to assemble. `config` uses a configuration file specified via `--config`. `survey` starts an interactive command-line survey."), (args) => runCommand("runAssemble", Object.assign(Object.assign({}, args), { registry: (0, utils_1.trimEnd)(args.registry, "/"), config: (0, path_1.resolve)(process.cwd(), args.config), target: (0, path_1.resolve)(process.cwd(), args.target) })));
179
- yargs.command(["start", "$0"], "Starts the app shell using the provided configuration. This uses express for serving static files with some proxy middleware.", (argv) => argv
147
+ yargs_1.default.command("assemble", "Assembles an import map incl. all required resources.", (argv) => argv
148
+ .option("target", {
149
+ default: "dist",
150
+ description: "The target directory where the gathered artifacts will be stored.",
151
+ type: "string",
152
+ coerce: (arg) => (0, path_1.resolve)(process.cwd(), arg),
153
+ })
154
+ .option("registry", {
155
+ default: "https://registry.npmjs.org/",
156
+ description: "The NPM registry used for getting the packages.",
157
+ type: "string",
158
+ coerce: (arg) => (0, utils_1.trimEnd)(arg, "/"),
159
+ })
160
+ .option("config", {
161
+ default: "spa-build-config.json",
162
+ description: "Path to a SPA build config JSON.",
163
+ type: "string",
164
+ coerce: (arg) => (0, path_1.resolve)(process.cwd(), arg),
165
+ })
166
+ .option("fresh", {
167
+ default: false,
168
+ description: "Determines if the output directory should be cleaned before the run.",
169
+ type: "boolean",
170
+ })
171
+ .option("manifest", {
172
+ default: false,
173
+ description: "Whether to output a manifest",
174
+ type: "boolean",
175
+ })
176
+ .option("mode", {
177
+ choices: ["config", "survey"],
178
+ default: "survey",
179
+ description: "The source of the frontend modules to assemble. `config` uses a configuration file specified via `--config`. `survey` starts an interactive command-line survey.",
180
+ type: "string",
181
+ }), (args) => runCommand("runAssemble", args));
182
+ yargs_1.default.command(["start", "$0"], "Starts the app shell using the provided configuration. This uses express for serving static files with some proxy middleware.", (argv) => argv
180
183
  .number("port")
181
184
  .default("port", 8080)
182
185
  .describe("port", "The port where the dev server should run.")
@@ -192,7 +195,7 @@ yargs.command(["start", "$0"], "Starts the app shell using the provided configur
192
195
  .boolean("open")
193
196
  .default("open", false)
194
197
  .describe("open", "Immediately opens the SPA page URL in the browser."), (args) => runCommand("runStart", Object.assign({}, args)));
195
- yargs
198
+ yargs_1.default
196
199
  .epilog("The SPA build config JSON is a JSON file, typically `frontend.json`, which defines parameters for the `build` and `assemble` " +
197
200
  "commands. The keys used by `build` are:\n" +
198
201
  " `apiUrl`, `spaPath`, `configPaths`, `configUrls`, `importmap`, `pageTitle`, and `supportOffline`;\n" +
@@ -13,13 +13,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.runAssemble = void 0;
16
- const fs_1 = require("fs");
16
+ const promises_1 = require("fs/promises");
17
17
  const path_1 = require("path");
18
18
  const inquirer_1 = require("inquirer");
19
19
  const rimraf_1 = __importDefault(require("rimraf"));
20
20
  const axios_1 = __importDefault(require("axios"));
21
21
  const pacote_1 = __importDefault(require("pacote"));
22
22
  const utils_1 = require("../utils");
23
+ const fs_1 = require("fs");
23
24
  function readConfig(mode, config, registry) {
24
25
  return __awaiter(this, void 0, void 0, function* () {
25
26
  switch (mode) {
@@ -28,7 +29,7 @@ function readConfig(mode, config, registry) {
28
29
  throw new Error(`Could not find the config file "${config}".`);
29
30
  }
30
31
  (0, utils_1.logInfo)(`Reading configuration ...`);
31
- return Object.assign({ baseDir: (0, path_1.dirname)(config) }, JSON.parse((0, fs_1.readFileSync)(config, "utf8")));
32
+ return Object.assign({ baseDir: (0, path_1.dirname)(config) }, JSON.parse(yield (0, promises_1.readFile)(config, "utf8")));
32
33
  case "survey":
33
34
  (0, utils_1.logInfo)(`Loading available frontend modules ...`);
34
35
  const packages = yield axios_1.default
@@ -83,14 +84,14 @@ function downloadPackage(cacheDir, esmName, esmVersion, baseDir, registry) {
83
84
  const source = (0, path_1.resolve)(baseDir, esmVersion.substr(5));
84
85
  const file = (0, path_1.basename)(source);
85
86
  const target = (0, path_1.resolve)(cacheDir, file);
86
- (0, fs_1.copyFileSync)(source, target);
87
+ yield (0, promises_1.copyFile)(source, target);
87
88
  return file;
88
89
  }
89
90
  else if (/^https?:\/\//.test(esmVersion)) {
90
91
  const response = yield axios_1.default.get(esmVersion);
91
92
  const content = response.data;
92
93
  const file = esmName.replace("@", "").replace(/\//g, "-") + ".tgz";
93
- (0, fs_1.writeFileSync)((0, path_1.resolve)(cacheDir, file), content);
94
+ yield (0, promises_1.writeFile)((0, path_1.resolve)(cacheDir, file), content);
94
95
  return file;
95
96
  }
96
97
  else {
@@ -103,35 +104,36 @@ function downloadPackage(cacheDir, esmName, esmVersion, baseDir, registry) {
103
104
  const filename = `${tarManifest.name}-${tarManifest.version}.tgz`
104
105
  .replace(/^@/, "")
105
106
  .replace(/\//, "-");
106
- (0, fs_1.mkdirSync)(cacheDir, { recursive: true });
107
- (0, fs_1.writeFileSync)((0, path_1.resolve)(cacheDir, filename), tarball);
107
+ yield (0, promises_1.mkdir)(cacheDir, { recursive: true });
108
+ yield (0, promises_1.writeFile)((0, path_1.resolve)(cacheDir, filename), tarball);
108
109
  return filename;
109
110
  }
110
111
  });
111
112
  }
112
113
  function extractFiles(sourceFile, targetDir) {
113
- var _a, _b;
114
+ var _a, _b, _c;
114
115
  return __awaiter(this, void 0, void 0, function* () {
115
- (0, fs_1.mkdirSync)(targetDir, { recursive: true });
116
+ yield (0, promises_1.mkdir)(targetDir, { recursive: true });
116
117
  const packageRoot = "package";
117
118
  const rs = (0, fs_1.createReadStream)(sourceFile);
118
119
  const files = yield (0, utils_1.untar)(rs);
119
120
  const packageJson = JSON.parse(files[`${packageRoot}/package.json`].toString("utf8"));
120
- const entryModule = (_b = (_a = packageJson.browser) !== null && _a !== void 0 ? _a : packageJson.module) !== null && _b !== void 0 ? _b : packageJson.main;
121
+ const version = (_a = packageJson.version) !== null && _a !== void 0 ? _a : "0.0.0";
122
+ const entryModule = (_c = (_b = packageJson.browser) !== null && _b !== void 0 ? _b : packageJson.module) !== null && _c !== void 0 ? _c : packageJson.main;
121
123
  const fileName = (0, path_1.basename)(entryModule);
122
124
  const sourceDir = (0, path_1.dirname)(entryModule);
123
125
  Object.keys(files)
124
126
  .filter((m) => m.startsWith(`${packageRoot}/${sourceDir}`))
125
127
  .filter((m) => !m.endsWith(".map"))
126
- .forEach((m) => {
128
+ .forEach((m) => __awaiter(this, void 0, void 0, function* () {
127
129
  const content = files[m];
128
130
  const fileName = m.replace(`${packageRoot}/${sourceDir}/`, "");
129
131
  const targetFile = (0, path_1.resolve)(targetDir, fileName);
130
- (0, fs_1.mkdirSync)((0, path_1.dirname)(targetFile), { recursive: true });
131
- (0, fs_1.writeFileSync)(targetFile, content);
132
- });
133
- (0, fs_1.unlinkSync)(sourceFile);
134
- return fileName;
132
+ yield (0, promises_1.mkdir)((0, path_1.dirname)(targetFile), { recursive: true });
133
+ yield (0, promises_1.writeFile)(targetFile, content);
134
+ }));
135
+ yield (0, promises_1.unlink)(sourceFile);
136
+ return [fileName, version];
135
137
  });
136
138
  }
137
139
  function runAssemble(args) {
@@ -140,21 +142,28 @@ function runAssemble(args) {
140
142
  const importmap = {
141
143
  imports: {},
142
144
  };
145
+ const versionManifest = {
146
+ frontendModules: {},
147
+ };
143
148
  (0, utils_1.logInfo)(`Assembling the importmap ...`);
144
149
  const { frontendModules = {}, publicUrl = "." } = config;
145
150
  const cacheDir = (0, path_1.resolve)(process.cwd(), ".cache");
146
151
  if (args.fresh && (0, fs_1.existsSync)(args.target)) {
147
152
  yield new Promise((resolve) => (0, rimraf_1.default)(args.target, resolve));
148
153
  }
149
- (0, fs_1.mkdirSync)(args.target, { recursive: true });
154
+ yield (0, promises_1.mkdir)(args.target, { recursive: true });
150
155
  yield Promise.all(Object.keys(frontendModules).map((esmName) => __awaiter(this, void 0, void 0, function* () {
151
156
  const esmVersion = frontendModules[esmName];
152
157
  const tgzFileName = yield downloadPackage(cacheDir, esmName, esmVersion, config.baseDir, args.registry);
153
158
  const dirName = tgzFileName.replace(".tgz", "");
154
- const fileName = yield extractFiles((0, path_1.resolve)(cacheDir, tgzFileName), (0, path_1.resolve)(args.target, dirName));
159
+ const [fileName, version] = yield extractFiles((0, path_1.resolve)(cacheDir, tgzFileName), (0, path_1.resolve)(args.target, dirName));
155
160
  importmap.imports[esmName] = `${publicUrl}/${dirName}/${fileName}`;
161
+ versionManifest.frontendModules[esmName] = version;
156
162
  })));
157
- (0, fs_1.writeFileSync)((0, path_1.resolve)(args.target, "importmap.json"), JSON.stringify(importmap, undefined, 2), "utf8");
163
+ yield (0, promises_1.writeFile)((0, path_1.resolve)(args.target, "importmap.json"), JSON.stringify(importmap, undefined, 2), "utf8");
164
+ if (args.manifest) {
165
+ yield (0, promises_1.writeFile)((0, path_1.resolve)(args.target, "spa-module-versions.json"), JSON.stringify(versionManifest, undefined, 2), "utf8");
166
+ }
158
167
  });
159
168
  }
160
169
  exports.runAssemble = runAssemble;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmrs",
3
- "version": "4.0.3-pre.437",
3
+ "version": "4.0.3-pre.441",
4
4
  "license": "MPL-2.0",
5
5
  "main": "dist/index.js",
6
6
  "bin": "./dist/cli.js",
@@ -30,8 +30,8 @@
30
30
  ],
31
31
  "homepage": "https://github.com/openmrs/openmrs-esm-core#readme",
32
32
  "dependencies": {
33
- "@openmrs/esm-app-shell": "4.0.3-pre.437",
34
- "@openmrs/webpack-config": "4.0.3-pre.437",
33
+ "@openmrs/esm-app-shell": "4.0.3-pre.441",
34
+ "@openmrs/webpack-config": "4.0.3-pre.441",
35
35
  "autoprefixer": "^10.4.2",
36
36
  "axios": "^0.21.1",
37
37
  "browserslist-config-openmrs": "^1.0.1",
@@ -54,18 +54,18 @@
54
54
  "webpack-dev-server": "^4.10.1",
55
55
  "webpack-pwa-manifest": "^4.3.0",
56
56
  "workbox-webpack-plugin": "^6.4.1",
57
- "yargs": "16.0.3"
57
+ "yargs": "^17.6.2"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/express": "^4.11.1",
61
61
  "@types/glob": "^7.1.1",
62
62
  "@types/inquirer": "^6.5.0",
63
- "@types/node": "12.12.2",
63
+ "@types/node": "^18.11.11",
64
64
  "@types/pacote": "^11.1.5",
65
65
  "@types/react": "^18.0.9",
66
66
  "@types/rimraf": "^2.0.2",
67
67
  "@types/systemjs": "^6.1.0",
68
68
  "@types/tar": "^4.0.3"
69
69
  },
70
- "gitHead": "543a8601b8daeb1394471de7bea0c4464962ddb5"
70
+ "gitHead": "30b34792c0de257200a36e19c6ae032dc61fb171"
71
71
  }
package/src/cli.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import * as yargs from "yargs";
3
+ import yargs from "yargs";
4
4
  import { fork } from "child_process";
5
5
  import { resolve } from "path";
6
6
  import {
@@ -281,37 +281,44 @@ yargs.command(
281
281
  "Assembles an import map incl. all required resources.",
282
282
  (argv) =>
283
283
  argv
284
- .string("target")
285
- .default("target", "dist")
286
- .describe(
287
- "target",
288
- "The target directory where the gathered artifacts will be stored."
289
- )
290
- .string("registry")
291
- .default("registry", "https://registry.npmjs.org/")
292
- .describe("registry", "The NPM registry used for getting the packages.")
293
- .string("config")
294
- .default("config", "spa-build-config.json")
295
- .describe("config", "Path to a SPA build config JSON.")
296
- .boolean("fresh")
297
- .describe(
298
- "fresh",
299
- "Determines if the output directory should be cleaned before the run."
300
- )
301
- .default("fresh", false)
302
- .choices("mode", ["config", "survey"])
303
- .default("mode", "survey")
304
- .describe(
305
- "mode",
306
- "The source of the frontend modules to assemble. `config` uses a configuration file specified via `--config`. `survey` starts an interactive command-line survey."
307
- ),
308
- (args) =>
309
- runCommand("runAssemble", {
310
- ...args,
311
- registry: trimEnd(args.registry, "/"),
312
- config: resolve(process.cwd(), args.config),
313
- target: resolve(process.cwd(), args.target),
314
- })
284
+ .option("target", {
285
+ default: "dist",
286
+ description:
287
+ "The target directory where the gathered artifacts will be stored.",
288
+ type: "string",
289
+ coerce: (arg) => resolve(process.cwd(), arg),
290
+ })
291
+ .option("registry", {
292
+ default: "https://registry.npmjs.org/",
293
+ description: "The NPM registry used for getting the packages.",
294
+ type: "string",
295
+ coerce: (arg) => trimEnd(arg, "/"),
296
+ })
297
+ .option("config", {
298
+ default: "spa-build-config.json",
299
+ description: "Path to a SPA build config JSON.",
300
+ type: "string",
301
+ coerce: (arg) => resolve(process.cwd(), arg),
302
+ })
303
+ .option("fresh", {
304
+ default: false,
305
+ description:
306
+ "Determines if the output directory should be cleaned before the run.",
307
+ type: "boolean",
308
+ })
309
+ .option("manifest", {
310
+ default: false,
311
+ description: "Whether to output a manifest",
312
+ type: "boolean",
313
+ })
314
+ .option("mode", {
315
+ choices: ["config", "survey"],
316
+ default: "survey",
317
+ description:
318
+ "The source of the frontend modules to assemble. `config` uses a configuration file specified via `--config`. `survey` starts an interactive command-line survey.",
319
+ type: "string",
320
+ }),
321
+ (args) => runCommand("runAssemble", args)
315
322
  );
316
323
 
317
324
  yargs.command(
@@ -1,18 +1,11 @@
1
- import {
2
- readFileSync,
3
- writeFileSync,
4
- unlinkSync,
5
- existsSync,
6
- mkdirSync,
7
- createReadStream,
8
- copyFileSync,
9
- } from "fs";
1
+ import { copyFile, mkdir, readFile, unlink, writeFile } from "fs/promises";
10
2
  import { resolve, dirname, basename } from "path";
11
3
  import { prompt, Question } from "inquirer";
12
4
  import rimraf from "rimraf";
13
5
  import axios from "axios";
14
6
  import pacote from "pacote";
15
7
  import { logInfo, untar } from "../utils";
8
+ import { createReadStream, existsSync } from "fs";
16
9
 
17
10
  export interface AssembleArgs {
18
11
  target: string;
@@ -20,6 +13,7 @@ export interface AssembleArgs {
20
13
  config: string;
21
14
  registry: string;
22
15
  fresh: boolean;
16
+ manifest: boolean;
23
17
  }
24
18
 
25
19
  interface NpmSearchResult {
@@ -52,7 +46,7 @@ async function readConfig(
52
46
 
53
47
  return {
54
48
  baseDir: dirname(config),
55
- ...JSON.parse(readFileSync(config, "utf8")),
49
+ ...JSON.parse(await readFile(config, "utf8")),
56
50
  };
57
51
  case "survey":
58
52
  logInfo(`Loading available frontend modules ...`);
@@ -125,13 +119,13 @@ async function downloadPackage(
125
119
  const source = resolve(baseDir, esmVersion.substr(5));
126
120
  const file = basename(source);
127
121
  const target = resolve(cacheDir, file);
128
- copyFileSync(source, target);
122
+ await copyFile(source, target);
129
123
  return file;
130
124
  } else if (/^https?:\/\//.test(esmVersion)) {
131
125
  const response = await axios.get<Buffer>(esmVersion);
132
126
  const content = response.data;
133
127
  const file = esmName.replace("@", "").replace(/\//g, "-") + ".tgz";
134
- writeFileSync(resolve(cacheDir, file), content);
128
+ await writeFile(resolve(cacheDir, file), content);
135
129
  return file;
136
130
  } else {
137
131
  const packageName = `${esmName}@${esmVersion}`;
@@ -145,21 +139,22 @@ async function downloadPackage(
145
139
  .replace(/^@/, "")
146
140
  .replace(/\//, "-");
147
141
 
148
- mkdirSync(cacheDir, { recursive: true });
149
- writeFileSync(resolve(cacheDir, filename), tarball);
142
+ await mkdir(cacheDir, { recursive: true });
143
+ await writeFile(resolve(cacheDir, filename), tarball);
150
144
 
151
145
  return filename;
152
146
  }
153
147
  }
154
148
 
155
149
  async function extractFiles(sourceFile: string, targetDir: string) {
156
- mkdirSync(targetDir, { recursive: true });
150
+ await mkdir(targetDir, { recursive: true });
157
151
  const packageRoot = "package";
158
152
  const rs = createReadStream(sourceFile);
159
153
  const files = await untar(rs);
160
154
  const packageJson = JSON.parse(
161
155
  files[`${packageRoot}/package.json`].toString("utf8")
162
156
  );
157
+ const version = packageJson.version ?? "0.0.0";
163
158
  const entryModule =
164
159
  packageJson.browser ?? packageJson.module ?? packageJson.main;
165
160
  const fileName = basename(entryModule);
@@ -168,16 +163,16 @@ async function extractFiles(sourceFile: string, targetDir: string) {
168
163
  Object.keys(files)
169
164
  .filter((m) => m.startsWith(`${packageRoot}/${sourceDir}`))
170
165
  .filter((m) => !m.endsWith(".map"))
171
- .forEach((m) => {
166
+ .forEach(async (m) => {
172
167
  const content = files[m];
173
168
  const fileName = m.replace(`${packageRoot}/${sourceDir}/`, "");
174
169
  const targetFile = resolve(targetDir, fileName);
175
- mkdirSync(dirname(targetFile), { recursive: true });
176
- writeFileSync(targetFile, content);
170
+ await mkdir(dirname(targetFile), { recursive: true });
171
+ await writeFile(targetFile, content);
177
172
  });
178
173
 
179
- unlinkSync(sourceFile);
180
- return fileName;
174
+ await unlink(sourceFile);
175
+ return [fileName, version];
181
176
  }
182
177
 
183
178
  export async function runAssemble(args: AssembleArgs) {
@@ -185,6 +180,9 @@ export async function runAssemble(args: AssembleArgs) {
185
180
  const importmap = {
186
181
  imports: {},
187
182
  };
183
+ const versionManifest = {
184
+ frontendModules: {},
185
+ };
188
186
 
189
187
  logInfo(`Assembling the importmap ...`);
190
188
 
@@ -195,7 +193,7 @@ export async function runAssemble(args: AssembleArgs) {
195
193
  await new Promise((resolve) => rimraf(args.target, resolve));
196
194
  }
197
195
 
198
- mkdirSync(args.target, { recursive: true });
196
+ await mkdir(args.target, { recursive: true });
199
197
 
200
198
  await Promise.all(
201
199
  Object.keys(frontendModules).map(async (esmName) => {
@@ -208,17 +206,26 @@ export async function runAssemble(args: AssembleArgs) {
208
206
  args.registry
209
207
  );
210
208
  const dirName = tgzFileName.replace(".tgz", "");
211
- const fileName = await extractFiles(
209
+ const [fileName, version] = await extractFiles(
212
210
  resolve(cacheDir, tgzFileName),
213
211
  resolve(args.target, dirName)
214
212
  );
215
213
  importmap.imports[esmName] = `${publicUrl}/${dirName}/${fileName}`;
214
+ versionManifest.frontendModules[esmName] = version;
216
215
  })
217
216
  );
218
217
 
219
- writeFileSync(
218
+ await writeFile(
220
219
  resolve(args.target, "importmap.json"),
221
220
  JSON.stringify(importmap, undefined, 2),
222
221
  "utf8"
223
222
  );
223
+
224
+ if (args.manifest) {
225
+ await writeFile(
226
+ resolve(args.target, "spa-module-versions.json"),
227
+ JSON.stringify(versionManifest, undefined, 2),
228
+ "utf8"
229
+ );
230
+ }
224
231
  }