openmrs 4.1.1-pre.508 → 4.1.1-pre.511

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 39f564a62b7a9d99
1
+ openmrs:build: cache hit, replaying output 5073aa7565b14358
package/dist/cli.js CHANGED
@@ -138,10 +138,7 @@ yargs_1.default.command("build", "Builds a new app shell.", (argv) => argv
138
138
  .describe("config-path", "The path to a frontend configuration file. Can be used multiple times. The file is copied directly into the build directory.")
139
139
  .string("importmap")
140
140
  .default("importmap", "importmap.json")
141
- .describe("importmap", "The import map to use. Can be a path to an import map to be taken literally, an URL, or a fixed JSON object.")
142
- .boolean("download-coreapps")
143
- .default("download-coreapps", false)
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* () {
141
+ .describe("importmap", "The import map to use. Can be a path to an import map to be taken literally, an URL, or a fixed JSON object."), (args) => __awaiter(void 0, void 0, void 0, function* () {
145
142
  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) }));
146
143
  }));
147
144
  yargs_1.default.command("assemble", "Assembles an import map incl. all required resources.", (argv) => argv
@@ -152,7 +149,8 @@ yargs_1.default.command("assemble", "Assembles an import map incl. all required
152
149
  coerce: (arg) => (0, path_1.resolve)(process.cwd(), arg),
153
150
  })
154
151
  .option("registry", {
155
- default: "https://registry.npmjs.org/",
152
+ alias: "reg",
153
+ default: "",
156
154
  description: "The NPM registry used for getting the packages.",
157
155
  type: "string",
158
156
  coerce: (arg) => (0, utils_1.trimEnd)(arg, "/"),
@@ -18,10 +18,12 @@ 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
+ const npm_registry_fetch_1 = __importDefault(require("npm-registry-fetch"));
21
22
  const pacote_1 = __importDefault(require("pacote"));
22
23
  const utils_1 = require("../utils");
23
24
  const fs_1 = require("fs");
24
- function readConfig(mode, config, registry) {
25
+ const npmConfig_1 = require("../utils/npmConfig");
26
+ function readConfig(mode, config, fetchOptions) {
25
27
  return __awaiter(this, void 0, void 0, function* () {
26
28
  switch (mode) {
27
29
  case "config":
@@ -32,9 +34,9 @@ function readConfig(mode, config, registry) {
32
34
  return Object.assign({ baseDir: (0, path_1.dirname)(config) }, JSON.parse(yield (0, promises_1.readFile)(config, "utf8")));
33
35
  case "survey":
34
36
  (0, utils_1.logInfo)(`Loading available frontend modules ...`);
35
- const packages = yield axios_1.default
36
- .get(`${registry}/-/v1/search?text=keywords:openmrs&size=250`)
37
- .then((res) => res.data)
37
+ const packages = yield npm_registry_fetch_1.default
38
+ .json("/-/v1/search?text=keywords:openmrs&size=500", fetchOptions)
39
+ .then((res) => res)
38
40
  .then((res) => res.objects
39
41
  .map((m) => ({
40
42
  name: m.package.name,
@@ -78,7 +80,7 @@ function readConfig(mode, config, registry) {
78
80
  };
79
81
  });
80
82
  }
81
- function downloadPackage(cacheDir, esmName, esmVersion, baseDir, registry) {
83
+ function downloadPackage(cacheDir, esmName, esmVersion, baseDir, fetchOptions) {
82
84
  return __awaiter(this, void 0, void 0, function* () {
83
85
  if (esmVersion.startsWith("file:")) {
84
86
  const source = (0, path_1.resolve)(baseDir, esmVersion.substr(5));
@@ -96,11 +98,13 @@ function downloadPackage(cacheDir, esmName, esmVersion, baseDir, registry) {
96
98
  }
97
99
  else {
98
100
  const packageName = `${esmName}@${esmVersion}`;
99
- const tarManifest = yield pacote_1.default.manifest(packageName, { registry });
100
- const tarball = yield pacote_1.default.tarball(tarManifest._resolved, {
101
- registry,
102
- integrity: tarManifest._integrity,
103
- });
101
+ const tarManifest = yield pacote_1.default.manifest(packageName, fetchOptions);
102
+ if (!Boolean(tarManifest) ||
103
+ !Boolean(tarManifest._resolved) ||
104
+ !Boolean(tarManifest._integrity)) {
105
+ throw new Error(`Failed to load manifest for ${packageName} from registry ${fetchOptions.registry}`);
106
+ }
107
+ const tarball = yield pacote_1.default.tarball(tarManifest._resolved, Object.assign(Object.assign({}, fetchOptions), { integrity: tarManifest._integrity }));
104
108
  const filename = `${tarManifest.name}-${tarManifest.version}.tgz`
105
109
  .replace(/^@/, "")
106
110
  .replace(/\//, "-");
@@ -138,7 +142,8 @@ function extractFiles(sourceFile, targetDir) {
138
142
  }
139
143
  function runAssemble(args) {
140
144
  return __awaiter(this, void 0, void 0, function* () {
141
- const config = yield readConfig(args.mode, args.config, args.registry);
145
+ const npmConf = (0, npmConfig_1.getNpmRegistryConfiguration)(args.registry);
146
+ const config = yield readConfig(args.mode, args.config, npmConf);
142
147
  const importmap = {
143
148
  imports: {},
144
149
  };
@@ -154,7 +159,7 @@ function runAssemble(args) {
154
159
  yield (0, promises_1.mkdir)(args.target, { recursive: true });
155
160
  yield Promise.all(Object.keys(frontendModules).map((esmName) => __awaiter(this, void 0, void 0, function* () {
156
161
  const esmVersion = frontendModules[esmName];
157
- const tgzFileName = yield downloadPackage(cacheDir, esmName, esmVersion, config.baseDir, args.registry);
162
+ const tgzFileName = yield downloadPackage(cacheDir, esmName, esmVersion, config.baseDir, npmConf);
158
163
  const dirName = tgzFileName.replace(".tgz", "");
159
164
  const [fileName, version] = yield extractFiles((0, path_1.resolve)(cacheDir, tgzFileName), (0, path_1.resolve)(args.target, dirName));
160
165
  importmap.imports[esmName] = `${publicUrl}/${dirName}/${fileName}`;
@@ -17,7 +17,6 @@ const fs_1 = require("fs");
17
17
  const utils_1 = require("../utils");
18
18
  const rimraf_1 = __importDefault(require("rimraf"));
19
19
  const path_1 = require("path");
20
- const child_process_1 = require("child_process");
21
20
  function loadBuildConfig(buildConfigPath) {
22
21
  if (buildConfigPath) {
23
22
  return JSON.parse((0, fs_1.readFileSync)(buildConfigPath, "utf8"));
@@ -26,80 +25,10 @@ function loadBuildConfig(buildConfigPath) {
26
25
  return {};
27
26
  }
28
27
  }
29
- function extractFiles(sourceFile, targetDir) {
30
- var _a, _b;
31
- return __awaiter(this, void 0, void 0, function* () {
32
- const packageRoot = "package/";
33
- const rs = (0, fs_1.createReadStream)(sourceFile);
34
- const files = yield (0, utils_1.untar)(rs);
35
- const packageJson = JSON.parse(files[`${packageRoot}package.json`].toString("utf8"));
36
- const entryModule = (_b = (_a = packageJson.browser) !== null && _a !== void 0 ? _a : packageJson.module) !== null && _b !== void 0 ? _b : packageJson.main;
37
- Object.keys(files)
38
- .filter((f) => f === "package/package.json" ||
39
- f.substr(packageRoot.length) === entryModule)
40
- .forEach((f) => {
41
- const content = files[f];
42
- const fileName = f.replace(packageRoot, "");
43
- const targetFile = (0, path_1.resolve)(targetDir, fileName);
44
- (0, fs_1.writeFileSync)(targetFile, content);
45
- });
46
- (0, fs_1.unlinkSync)(sourceFile);
47
- });
48
- }
49
- function loadCoreApps(registry) {
50
- var _a, _b;
51
- /*
52
- * if the user specified a OMRS_ESM_CORE_APPS_DIR, we assume this has
53
- * the necessary coreapps; otherwise, we check if there are any coreapps
54
- * available in the places the webpack configuration will check; if there
55
- * aren't, we download the apps specified in the app-shell devDependencies
56
- */
57
- const appsPath = (_a = process.env.OMRS_ESM_CORE_APPS_DIR) !== null && _a !== void 0 ? _a : (0, path_1.resolve)(require.resolve("@openmrs/esm-app-shell"), "..", "..", "apps");
58
- let hasApp = false;
59
- if ((0, fs_1.existsSync)(appsPath) && (0, fs_1.statSync)(appsPath).isDirectory()) {
60
- hasApp = (0, fs_1.readdirSync)(appsPath).some((entry) => {
61
- var _a;
62
- if ((0, fs_1.statSync)(entry).isDirectory()) {
63
- const packageJson = (0, path_1.resolve)(entry, "package.json");
64
- if ((0, fs_1.existsSync)(packageJson) && (0, fs_1.statSync)(packageJson).isFile()) {
65
- return (_a = require(packageJson).name) === null || _a === void 0 ? void 0 : _a.endsWith("-app");
66
- }
67
- }
68
- });
69
- }
70
- if (!hasApp) {
71
- (0, utils_1.logInfo)("Fetching core apps...");
72
- const devDependencies = require("@openmrs/esm-app-shell/package.json").devDependencies;
73
- const apps = Object.keys(devDependencies)
74
- .filter((dep) => dep.endsWith("-app"))
75
- .map((dep) => [dep, devDependencies[dep]]);
76
- if (apps.length > 0) {
77
- const cacheDir = (0, path_1.resolve)(process.cwd(), ".cache");
78
- if (!(0, fs_1.existsSync)(cacheDir)) {
79
- (0, fs_1.mkdirSync)(cacheDir, { recursive: true });
80
- }
81
- const coreAppsDir = (_b = process.env.OMRS_ESM_CORE_APPS_DIR) !== null && _b !== void 0 ? _b : (0, path_1.resolve)(process.cwd(), ".cache", "apps");
82
- rimraf_1.default.sync(coreAppsDir);
83
- (0, fs_1.mkdirSync)(coreAppsDir, { recursive: true });
84
- apps.forEach(([name, version]) => __awaiter(this, void 0, void 0, function* () {
85
- var _c;
86
- const packageName = `${name}@${version}`;
87
- const command = `npm pack ${packageName} --registry ${registry}`;
88
- const result = (0, child_process_1.execSync)(command, {
89
- cwd: cacheDir,
90
- });
91
- const tgzFile = (_c = result.toString("utf8").split("\n").filter(Boolean).pop()) !== null && _c !== void 0 ? _c : "";
92
- const appDirName = tgzFile.replace(".tgz", "");
93
- yield extractFiles((0, path_1.resolve)(cacheDir, tgzFile), (0, path_1.resolve)(coreAppsDir, appDirName));
94
- }));
95
- return coreAppsDir;
96
- }
97
- }
98
- }
99
28
  function addConfigFilesFromPaths(configPaths, targetDir) {
100
29
  for (let configPath of configPaths) {
101
30
  const realPath = (0, path_1.resolve)(configPath);
102
- (0, fs_1.copyFileSync)(realPath, targetDir + "/" + (0, path_1.basename)(configPath));
31
+ (0, fs_1.copyFileSync)(realPath, (0, path_1.join)(targetDir, (0, path_1.basename)(configPath)));
103
32
  }
104
33
  }
105
34
  function runBuild(args) {
@@ -111,9 +40,6 @@ function runBuild(args) {
111
40
  for (let configPath of buildConfig.configPaths || args.configPaths) {
112
41
  configUrls.push((0, path_1.basename)(configPath));
113
42
  }
114
- const coreAppsDir = args.downloadCoreapps
115
- ? loadCoreApps(args.registry)
116
- : undefined;
117
43
  const config = (0, utils_1.loadWebpackConfig)({
118
44
  importmap: yield (0, utils_1.getImportmap)(buildConfig.importmap || args.importmap),
119
45
  env: "production",
@@ -122,7 +48,6 @@ function runBuild(args) {
122
48
  pageTitle: buildConfig.pageTitle || args.pageTitle,
123
49
  supportOffline: (_a = buildConfig.supportOffline) !== null && _a !== void 0 ? _a : args.supportOffline,
124
50
  spaPath: buildConfig.spaPath || args.spaPath,
125
- coreAppsDir,
126
51
  });
127
52
  (0, utils_1.logInfo)(`Running build process ...`);
128
53
  if (args.fresh && (0, fs_1.existsSync)(args.target)) {
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getNpmRegistryConfiguration = void 0;
7
+ const npm_conf_1 = __importDefault(require("@pnpm/npm-conf"));
8
+ /**
9
+ * Utility function to load the appropriate configuration for npmRegistryFetch
10
+ * from the .npmrc configuration chain. Essentially, this allows us to use .npmrc
11
+ * files to configure reading from the NPM registry, which is useful when using
12
+ * a custom registry, especially for private packages.
13
+ *
14
+ * This uses the @pnpm/npm-conf library for reading .npmrc files as its both
15
+ * maintained and sane to work with.
16
+ *
17
+ * @param registry The NPM registry to use, if any
18
+ */
19
+ function getNpmRegistryConfiguration(registry) {
20
+ var _a;
21
+ const conf = (0, npm_conf_1.default)();
22
+ if (!conf) {
23
+ return {};
24
+ }
25
+ if (conf.warnings.length >= 1) {
26
+ throw new Error(`Warnings while loading .npmrc:\n ${conf.warnings.join("\n ")}`);
27
+ }
28
+ if (!conf.config) {
29
+ return {};
30
+ }
31
+ // the returned config object uses getters with no list of keys
32
+ // so to convert this to a "normal" object, we combine all the settings
33
+ // found; note this relies on the internal structure of the config
34
+ // object and may not be stable
35
+ const configuration = Object.assign({}, ...((_a = conf.config.list.slice().reverse()) !== null && _a !== void 0 ? _a : []));
36
+ if (configuration.__source__) {
37
+ delete configuration.__source__;
38
+ }
39
+ if ("strict-ssl" in configuration) {
40
+ configuration.strictSSL = configuration["strict-ssl"];
41
+ delete configuration["strict-ssl"];
42
+ }
43
+ if (registry) {
44
+ configuration.registry = registry;
45
+ }
46
+ return configuration;
47
+ }
48
+ exports.getNpmRegistryConfiguration = getNpmRegistryConfiguration;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmrs",
3
- "version": "4.1.1-pre.508",
3
+ "version": "4.1.1-pre.511",
4
4
  "license": "MPL-2.0",
5
5
  "main": "dist/index.js",
6
6
  "bin": "./dist/cli.js",
@@ -30,8 +30,9 @@
30
30
  ],
31
31
  "homepage": "https://github.com/openmrs/openmrs-esm-core#readme",
32
32
  "dependencies": {
33
- "@openmrs/esm-app-shell": "4.1.1-pre.508",
34
- "@openmrs/webpack-config": "4.1.1-pre.508",
33
+ "@openmrs/esm-app-shell": "4.1.1-pre.511",
34
+ "@openmrs/webpack-config": "4.1.1-pre.511",
35
+ "@pnpm/npm-conf": "^2.1.0",
35
36
  "autoprefixer": "^10.4.2",
36
37
  "axios": "^0.21.1",
37
38
  "browserslist-config-openmrs": "^1.0.1",
@@ -43,6 +44,7 @@
43
44
  "html-webpack-plugin": "^5.5.0",
44
45
  "inquirer": "^7.3.3",
45
46
  "mini-css-extract-plugin": "^2.4.5",
47
+ "npm-registry-fetch": "^14.0.3",
46
48
  "pacote": "^15.0.0",
47
49
  "postcss": "^8.4.6",
48
50
  "postcss-loader": "^6.2.1",
@@ -67,5 +69,5 @@
67
69
  "@types/systemjs": "^6.1.0",
68
70
  "@types/tar": "^4.0.3"
69
71
  },
70
- "gitHead": "c19414d03b7547e0d286d04b8e104823095e99f2"
72
+ "gitHead": "fd322852e4ce136d34faaf2d89ddfb0c7a83a947"
71
73
  }
package/src/cli.ts CHANGED
@@ -257,12 +257,6 @@ yargs.command(
257
257
  .describe(
258
258
  "importmap",
259
259
  "The import map to use. Can be a path to an import map to be taken literally, an URL, or a fixed JSON object."
260
- )
261
- .boolean("download-coreapps")
262
- .default("download-coreapps", false)
263
- .describe(
264
- "download-coreapps",
265
- "Downloads and bundles the core apps. For cases where the core apps are not in the import map."
266
260
  ),
267
261
  async (args) =>
268
262
  runCommand("runBuild", {
@@ -289,7 +283,8 @@ yargs.command(
289
283
  coerce: (arg) => resolve(process.cwd(), arg),
290
284
  })
291
285
  .option("registry", {
292
- default: "https://registry.npmjs.org/",
286
+ alias: "reg",
287
+ default: "",
293
288
  description: "The NPM registry used for getting the packages.",
294
289
  type: "string",
295
290
  coerce: (arg) => trimEnd(arg, "/"),
@@ -3,15 +3,19 @@ import { resolve, dirname, basename } from "path";
3
3
  import { prompt, Question } from "inquirer";
4
4
  import rimraf from "rimraf";
5
5
  import axios from "axios";
6
+ import npmRegistryFetch from "npm-registry-fetch";
6
7
  import pacote from "pacote";
7
8
  import { logInfo, untar } from "../utils";
8
9
  import { createReadStream, existsSync } from "fs";
10
+ import { getNpmRegistryConfiguration } from "../utils/npmConfig";
11
+
12
+ /* eslint-disable no-console */
9
13
 
10
14
  export interface AssembleArgs {
11
15
  target: string;
12
16
  mode: string;
13
17
  config: string;
14
- registry: string;
18
+ registry?: string;
15
19
  fresh: boolean;
16
20
  manifest: boolean;
17
21
  }
@@ -34,7 +38,7 @@ interface AssembleConfig {
34
38
  async function readConfig(
35
39
  mode: string,
36
40
  config: string,
37
- registry: string
41
+ fetchOptions: npmRegistryFetch.Options
38
42
  ): Promise<AssembleConfig> {
39
43
  switch (mode) {
40
44
  case "config":
@@ -51,11 +55,9 @@ async function readConfig(
51
55
  case "survey":
52
56
  logInfo(`Loading available frontend modules ...`);
53
57
 
54
- const packages = await axios
55
- .get<NpmSearchResult>(
56
- `${registry}/-/v1/search?text=keywords:openmrs&size=250`
57
- )
58
- .then((res) => res.data)
58
+ const packages = await npmRegistryFetch
59
+ .json("/-/v1/search?text=keywords:openmrs&size=500", fetchOptions)
60
+ .then((res) => res as unknown as NpmSearchResult)
59
61
  .then((res) =>
60
62
  res.objects
61
63
  .map((m) => ({
@@ -113,7 +115,7 @@ async function downloadPackage(
113
115
  esmName: string,
114
116
  esmVersion: string,
115
117
  baseDir: string,
116
- registry: string
118
+ fetchOptions: npmRegistryFetch.Options
117
119
  ) {
118
120
  if (esmVersion.startsWith("file:")) {
119
121
  const source = resolve(baseDir, esmVersion.substr(5));
@@ -129,9 +131,20 @@ async function downloadPackage(
129
131
  return file;
130
132
  } else {
131
133
  const packageName = `${esmName}@${esmVersion}`;
132
- const tarManifest = await pacote.manifest(packageName, { registry });
134
+ const tarManifest = await pacote.manifest(packageName, fetchOptions);
135
+
136
+ if (
137
+ !Boolean(tarManifest) ||
138
+ !Boolean(tarManifest._resolved) ||
139
+ !Boolean(tarManifest._integrity)
140
+ ) {
141
+ throw new Error(
142
+ `Failed to load manifest for ${packageName} from registry ${fetchOptions.registry}`
143
+ );
144
+ }
145
+
133
146
  const tarball = await pacote.tarball(tarManifest._resolved, {
134
- registry,
147
+ ...fetchOptions,
135
148
  integrity: tarManifest._integrity,
136
149
  });
137
150
 
@@ -176,7 +189,9 @@ async function extractFiles(sourceFile: string, targetDir: string) {
176
189
  }
177
190
 
178
191
  export async function runAssemble(args: AssembleArgs) {
179
- const config = await readConfig(args.mode, args.config, args.registry);
192
+ const npmConf = getNpmRegistryConfiguration(args.registry);
193
+ const config = await readConfig(args.mode, args.config, npmConf);
194
+
180
195
  const importmap = {
181
196
  imports: {},
182
197
  };
@@ -203,8 +218,9 @@ export async function runAssemble(args: AssembleArgs) {
203
218
  esmName,
204
219
  esmVersion,
205
220
  config.baseDir,
206
- args.registry
221
+ npmConf
207
222
  );
223
+
208
224
  const dirName = tgzFileName.replace(".tgz", "");
209
225
  const [fileName, version] = await extractFiles(
210
226
  resolve(cacheDir, tgzFileName),
@@ -1,18 +1,7 @@
1
- import {
2
- copyFileSync,
3
- createReadStream,
4
- existsSync,
5
- mkdirSync,
6
- readdirSync,
7
- readFileSync,
8
- statSync,
9
- unlinkSync,
10
- writeFileSync,
11
- } from "fs";
12
- import { getImportmap, loadWebpackConfig, logInfo, untar } from "../utils";
1
+ import { copyFileSync, existsSync, readFileSync } from "fs";
2
+ import { getImportmap, loadWebpackConfig, logInfo } from "../utils";
13
3
  import rimraf from "rimraf";
14
- import { basename, resolve } from "path";
15
- import { execSync } from "child_process";
4
+ import { basename, join, resolve } from "path";
16
5
 
17
6
  /* eslint-disable no-console */
18
7
 
@@ -25,7 +14,6 @@ export interface BuildArgs {
25
14
  apiUrl: string;
26
15
  pageTitle: string;
27
16
  supportOffline?: boolean;
28
- downloadCoreapps: boolean;
29
17
  configUrls: Array<string>;
30
18
  configPaths: Array<string>;
31
19
  buildConfig?: string;
@@ -49,103 +37,13 @@ function loadBuildConfig(buildConfigPath?: string): BuildConfig {
49
37
  }
50
38
  }
51
39
 
52
- async function extractFiles(sourceFile: string, targetDir: string) {
53
- const packageRoot = "package/";
54
- const rs = createReadStream(sourceFile);
55
- const files = await untar(rs);
56
- const packageJson = JSON.parse(
57
- files[`${packageRoot}package.json`].toString("utf8")
58
- );
59
- const entryModule =
60
- packageJson.browser ?? packageJson.module ?? packageJson.main;
61
-
62
- Object.keys(files)
63
- .filter(
64
- (f) =>
65
- f === "package/package.json" ||
66
- f.substr(packageRoot.length) === entryModule
67
- )
68
- .forEach((f) => {
69
- const content = files[f];
70
- const fileName = f.replace(packageRoot, "");
71
- const targetFile = resolve(targetDir, fileName);
72
- writeFileSync(targetFile, content);
73
- });
74
-
75
- unlinkSync(sourceFile);
76
- }
77
-
78
- function loadCoreApps(registry: string) {
79
- /*
80
- * if the user specified a OMRS_ESM_CORE_APPS_DIR, we assume this has
81
- * the necessary coreapps; otherwise, we check if there are any coreapps
82
- * available in the places the webpack configuration will check; if there
83
- * aren't, we download the apps specified in the app-shell devDependencies
84
- */
85
- const appsPath =
86
- process.env.OMRS_ESM_CORE_APPS_DIR ??
87
- resolve(require.resolve("@openmrs/esm-app-shell"), "..", "..", "apps");
88
-
89
- let hasApp = false;
90
- if (existsSync(appsPath) && statSync(appsPath).isDirectory()) {
91
- hasApp = readdirSync(appsPath).some((entry) => {
92
- if (statSync(entry).isDirectory()) {
93
- const packageJson = resolve(entry, "package.json");
94
- if (existsSync(packageJson) && statSync(packageJson).isFile()) {
95
- return require(packageJson).name?.endsWith("-app");
96
- }
97
- }
98
- });
99
- }
100
-
101
- if (!hasApp) {
102
- logInfo("Fetching core apps...");
103
- const devDependencies: Record<string, string> =
104
- require("@openmrs/esm-app-shell/package.json").devDependencies;
105
-
106
- const apps = Object.keys(devDependencies)
107
- .filter((dep) => dep.endsWith("-app"))
108
- .map((dep) => [dep, devDependencies[dep]]);
109
-
110
- if (apps.length > 0) {
111
- const cacheDir = resolve(process.cwd(), ".cache");
112
- if (!existsSync(cacheDir)) {
113
- mkdirSync(cacheDir, { recursive: true });
114
- }
115
- const coreAppsDir =
116
- process.env.OMRS_ESM_CORE_APPS_DIR ??
117
- resolve(process.cwd(), ".cache", "apps");
118
- rimraf.sync(coreAppsDir);
119
- mkdirSync(coreAppsDir, { recursive: true });
120
-
121
- apps.forEach(async ([name, version]) => {
122
- const packageName = `${name}@${version}`;
123
- const command = `npm pack ${packageName} --registry ${registry}`;
124
- const result = execSync(command, {
125
- cwd: cacheDir,
126
- });
127
-
128
- const tgzFile =
129
- result.toString("utf8").split("\n").filter(Boolean).pop() ?? "";
130
- const appDirName = tgzFile.replace(".tgz", "");
131
- await extractFiles(
132
- resolve(cacheDir, tgzFile),
133
- resolve(coreAppsDir, appDirName)
134
- );
135
- });
136
-
137
- return coreAppsDir;
138
- }
139
- }
140
- }
141
-
142
40
  function addConfigFilesFromPaths(
143
41
  configPaths: Array<string>,
144
42
  targetDir: string
145
43
  ) {
146
44
  for (let configPath of configPaths) {
147
45
  const realPath = resolve(configPath);
148
- copyFileSync(realPath, targetDir + "/" + basename(configPath));
46
+ copyFileSync(realPath, join(targetDir, basename(configPath)));
149
47
  }
150
48
  }
151
49
 
@@ -156,9 +54,7 @@ export async function runBuild(args: BuildArgs) {
156
54
  for (let configPath of buildConfig.configPaths || args.configPaths) {
157
55
  configUrls.push(basename(configPath));
158
56
  }
159
- const coreAppsDir = args.downloadCoreapps
160
- ? loadCoreApps(args.registry)
161
- : undefined;
57
+
162
58
  const config = loadWebpackConfig({
163
59
  importmap: await getImportmap(buildConfig.importmap || args.importmap),
164
60
  env: "production",
@@ -167,7 +63,6 @@ export async function runBuild(args: BuildArgs) {
167
63
  pageTitle: buildConfig.pageTitle || args.pageTitle,
168
64
  supportOffline: buildConfig.supportOffline ?? args.supportOffline,
169
65
  spaPath: buildConfig.spaPath || args.spaPath,
170
- coreAppsDir,
171
66
  });
172
67
 
173
68
  logInfo(`Running build process ...`);
@@ -54,5 +54,5 @@ export function runDebug(args: DebugArgs) {
54
54
  }
55
55
  });
56
56
 
57
- return new Promise(() => {});
57
+ return new Promise<void>(() => {});
58
58
  }
@@ -129,5 +129,5 @@ export function runDevelop(args: DevelopArgs) {
129
129
  }
130
130
  });
131
131
 
132
- return new Promise(() => {});
132
+ return new Promise<void>(() => {});
133
133
  }
@@ -57,5 +57,5 @@ export function runStart(args: StartArgs) {
57
57
  }
58
58
  });
59
59
 
60
- return new Promise(() => {});
60
+ return new Promise<void>(() => {});
61
61
  }
package/src/runner.ts CHANGED
@@ -1,16 +1,26 @@
1
1
  import * as commands from "./commands";
2
2
  import { logFail } from "./utils";
3
3
 
4
- process.on("message", async ({ type, args }) => {
5
- const command = commands[type];
4
+ type Commands = typeof commands;
5
+ type CommandNames = keyof Commands;
6
+ interface HandleMessageArgs<T extends CommandNames> {
7
+ type: T;
8
+ args: Parameters<Commands[T]>[0];
9
+ }
6
10
 
7
- if (typeof command === "function") {
8
- try {
9
- await command(args);
10
- process.exit(0);
11
- } catch (err) {
12
- logFail(err.message);
13
- process.exit(1);
11
+ process.on(
12
+ "message",
13
+ async <T extends CommandNames>({ type, args }: HandleMessageArgs<T>) => {
14
+ const command: (a: typeof args) => Promise<unknown> = commands[type];
15
+
16
+ if (typeof command === "function") {
17
+ try {
18
+ await command(args);
19
+ process.exit(0);
20
+ } catch (err) {
21
+ logFail(err.message);
22
+ process.exit(1);
23
+ }
14
24
  }
15
25
  }
16
- });
26
+ );
@@ -0,0 +1,57 @@
1
+ import npmRegistryFetch from "npm-registry-fetch";
2
+ import npmConfig from "@pnpm/npm-conf";
3
+
4
+ /**
5
+ * Utility function to load the appropriate configuration for npmRegistryFetch
6
+ * from the .npmrc configuration chain. Essentially, this allows us to use .npmrc
7
+ * files to configure reading from the NPM registry, which is useful when using
8
+ * a custom registry, especially for private packages.
9
+ *
10
+ * This uses the @pnpm/npm-conf library for reading .npmrc files as its both
11
+ * maintained and sane to work with.
12
+ *
13
+ * @param registry The NPM registry to use, if any
14
+ */
15
+ export function getNpmRegistryConfiguration(
16
+ registry?: string | null | undefined
17
+ ): npmRegistryFetch.Options {
18
+ const conf = npmConfig();
19
+
20
+ if (!conf) {
21
+ return {};
22
+ }
23
+
24
+ if (conf.warnings.length >= 1) {
25
+ throw new Error(
26
+ `Warnings while loading .npmrc:\n ${conf.warnings.join("\n ")}`
27
+ );
28
+ }
29
+
30
+ if (!conf.config) {
31
+ return {};
32
+ }
33
+
34
+ // the returned config object uses getters with no list of keys
35
+ // so to convert this to a "normal" object, we combine all the settings
36
+ // found; note this relies on the internal structure of the config
37
+ // object and may not be stable
38
+ const configuration: npmRegistryFetch.Options = Object.assign(
39
+ {},
40
+ ...(conf.config.list.slice().reverse() ?? [])
41
+ );
42
+
43
+ if (configuration.__source__) {
44
+ delete configuration.__source__;
45
+ }
46
+
47
+ if ("strict-ssl" in configuration) {
48
+ configuration.strictSSL = configuration["strict-ssl"];
49
+ delete configuration["strict-ssl"];
50
+ }
51
+
52
+ if (registry) {
53
+ configuration.registry = registry;
54
+ }
55
+
56
+ return configuration;
57
+ }